提交 44c32ed7 编写于 作者: 璃白.'s avatar 璃白. 🌻

fix

上级 fbad4ffc
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"scripts": { "scripts": {
"start": "webpack serve --mode=development", "start": "webpack serve --mode=development",
"build": "webpack --mode=production", "build": "webpack --mode=production",
"p": "npm run build && ssh -t root@45.76.193.214 rm -rf /test/markdown-editor.js exit && scp -r dist/markdown-editor.js root@45.76.193.214:/test/" "p": "npm run build && ssh -t root@45.76.193.214 rm -rf /test/* exit && scp -r dist/* root@45.76.193.214:/test/"
}, },
"devDependencies": { "devDependencies": {
"chalk": "^4.1.1", "chalk": "^4.1.1",
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
:fullScreen.sync="fullScreen" :fullScreen.sync="fullScreen"
:text="text" :text="text"
:html.sync="html" :html.sync="html"
v-show="showPreview" :htmlMinHeight="htmlMinHeight"
v-if="showPreview"
/> />
<markdown-editor <markdown-editor
:selectionInfo.sync="selectionInfo" :selectionInfo.sync="selectionInfo"
...@@ -40,14 +41,16 @@ ...@@ -40,14 +41,16 @@
:placeholder="placeholder" :placeholder="placeholder"
:isFocus.sync="isFocus" :isFocus.sync="isFocus"
:throttleTime="throttle" :throttleTime="throttle"
:htmlMinHeight.sync="htmlMinHeight"
:fullScreen.sync="fullScreen" :fullScreen.sync="fullScreen"
:maxLength="maxLength" :maxLength="maxLength"
:textLength.sync="textLength" :textLength.sync="textLength"
:rows="rows" :rows="rows"
:html.sync="html"
:id="textareaId" :id="textareaId"
@tab="$refs['md_header' + id].tab()" @tab="$refs['md_header' + id].tab()"
@submit="submit" @submit="submit"
v-show="!showPreview" v-else
/> />
<div v-if="maxLength && showWordLimit && !showPreview" class="word_limit"> <div v-if="maxLength && showWordLimit && !showPreview" class="word_limit">
<span>{{ textLength }}</span <span>{{ textLength }}</span
...@@ -103,8 +106,12 @@ export default { ...@@ -103,8 +106,12 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
preview: { setPreview: {
type: String, type: Boolean,
default: false
},
setFullScreen: {
// type: Boolean,
default: "" default: ""
}, },
// 是否可以预览 // 是否可以预览
...@@ -160,6 +167,7 @@ export default { ...@@ -160,6 +167,7 @@ export default {
fileList: [], fileList: [],
text: "", text: "",
html: "", html: "",
htmlMinHeight: 150,
textLength: "", textLength: "",
selectionInfo: { selectionInfo: {
selectorId: "", selectorId: "",
...@@ -179,17 +187,34 @@ export default { ...@@ -179,17 +187,34 @@ export default {
watch: { watch: {
focus: { focus: {
handler: function(val) { handler: function(val) {
const textEl = document.getElementById(this.textareaId); setTimeout(() => {
if (val) { const textEl = document.getElementById(this.textareaId);
textEl.focus(); if (val) {
} else { textEl.focus();
textEl.blur(); } else {
} textEl.blur();
}
});
} }
}, },
preview: { showPreview: {
handler: function(val) { handler: function(val) {
this.showPreview = val === "preview"; this.$emit("changeTab", val);
}
},
setPreview: {
handler: function(val) {
this.showPreview = val;
}
},
setFullScreen: {
handler: function(val) {
this.fullScreen = val;
}
},
fullScreen: {
handler: function(val) {
this.$emit("changeFullScreen", val);
} }
}, },
text: { text: {
...@@ -199,7 +224,7 @@ export default { ...@@ -199,7 +224,7 @@ export default {
} }
}, },
html: { html: {
immediate: true, immediate: false,
handler: function(val) { handler: function(val) {
const emitContent = { const emitContent = {
text: this.text, text: this.text,
......
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
import marked from "marked"; import marked from "marked";
export default { export default {
data() { data() {
return { return {};
htmlMinHeight: 150
};
}, },
props: { props: {
id: { id: {
...@@ -20,6 +18,9 @@ export default { ...@@ -20,6 +18,9 @@ export default {
type: [String, Number], type: [String, Number],
default: "" default: ""
}, },
htmlMinHeight: {
default: ""
},
html: { html: {
type: String, type: String,
default: "" default: ""
...@@ -31,8 +32,8 @@ export default { ...@@ -31,8 +32,8 @@ export default {
}, },
mounted() { mounted() {
setTimeout(() => { setTimeout(() => {
this.resetMinHeight(); // this.resetMinHeight();
}, 0) }, 0);
this.addClass(); this.addClass();
}, },
updated() { updated() {
...@@ -59,9 +60,13 @@ export default { ...@@ -59,9 +60,13 @@ export default {
this.$emit("update:html", html); this.$emit("update:html", html);
}, },
resetMinHeight() { resetMinHeight() {
console.log("resetHeight");
const textEl = document.getElementById(this.id); const textEl = document.getElementById(this.id);
if (!textEl) return; if (!textEl) return;
const height = textEl.offsetHeight; const height = textEl.offsetHeight;
console.log("编辑区高度", height);
this.htmlMinHeight = height; this.htmlMinHeight = height;
} }
}, },
...@@ -69,8 +74,10 @@ export default { ...@@ -69,8 +74,10 @@ export default {
text: { text: {
immediate: true, immediate: true,
handler: function(val) { handler: function(val) {
this.resetMinHeight(); setTimeout(() => {
this.transferMarkdown(val); // this.resetMinHeight();
}, 0);
// this.transferMarkdown(val);
} }
} }
} }
......
...@@ -25,12 +25,20 @@ import { ...@@ -25,12 +25,20 @@ import {
getPosition, getPosition,
throttle as throttleFn throttle as throttleFn
} from "@/assets/js/utils"; } from "@/assets/js/utils";
import marked from "marked";
export default { export default {
props: { props: {
id: { id: {
type: String, type: String,
default: "" default: ""
}, },
html: {
type: String,
default: ""
},
htmlMinHeight: {
default: ""
},
fullScreen: { fullScreen: {
type: Boolean, type: Boolean,
default: false default: false
...@@ -79,6 +87,11 @@ export default { ...@@ -79,6 +87,11 @@ export default {
created() { created() {
document.addEventListener("mouseup", this.checkSelection); document.addEventListener("mouseup", this.checkSelection);
}, },
mounted() {
setTimeout(() => {
this.resetMinHeight();
}, 0);
},
watch: { watch: {
text: { text: {
immediate: true, immediate: true,
...@@ -86,6 +99,7 @@ export default { ...@@ -86,6 +99,7 @@ export default {
const cursorPoint = getPosition(this.id); const cursorPoint = getPosition(this.id);
console.log(cursorPoint); console.log(cursorPoint);
this.textContent = val; this.textContent = val;
this.transferMarkdown(val);
} }
}, },
fullScreen: { fullScreen: {
...@@ -125,6 +139,28 @@ export default { ...@@ -125,6 +139,28 @@ export default {
} }
}, },
methods: { methods: {
resetMinHeight() {
console.log("resetHeight");
const textEl = document.getElementById(this.id);
if (!textEl) return;
const height = textEl.offsetHeight;
console.log("编辑区高度", height);
this.$emit("update:htmlMinHeight", height);
// this.htmlMinHeight = height;
},
transferMarkdown(val) {
marked.setOptions({
highlight: function(code, lang, callback) {
const html = require("highlight.js").highlightAuto(code).value;
return html;
}
});
const str = val + "";
// if (!str.trim()) return;
const html = marked(str);
this.$emit("update:html", html);
},
input() { input() {
this.$emit("update:textLength", this.textContent.length); this.$emit("update:textLength", this.textContent.length);
this.emitText(); this.emitText();
......
...@@ -111,8 +111,10 @@ export default { ...@@ -111,8 +111,10 @@ export default {
font-size: 18px; font-size: 18px;
color: var(--md-editor-text-color); color: var(--md-editor-text-color);
cursor: pointer; cursor: pointer;
&:hover { @media (any-hover: hover) {
color: var(--md-editor-text-color-active); &:hover {
color: var(--md-editor-text-color-active);
}
} }
&.icon-quxiaoquanping_o { &.icon-quxiaoquanping_o {
font-size: 24px; font-size: 24px;
......
...@@ -29,7 +29,7 @@ function initMdEditor(obj) { ...@@ -29,7 +29,7 @@ function initMdEditor(obj) {
rows = 6, rows = 6,
maxLength, maxLength,
showWordLimit, showWordLimit,
throttle = 1000, throttle = 600,
canPreview, canPreview,
canAttachFile, canAttachFile,
themeOptions, themeOptions,
...@@ -53,15 +53,26 @@ function initMdEditor(obj) { ...@@ -53,15 +53,26 @@ function initMdEditor(obj) {
placeholder, placeholder,
maxLength, maxLength,
zIndex, zIndex,
preview: "", setPreview: false,
setFullScreen: false,
focus: false, focus: false,
showWordLimit showWordLimit
}; };
const listeners = { const listeners = {
changeTab(val) {
props.setPreview = val;
props.focus = !val;
_this.vEl.$forceUpdate();
},
changeFullScreen(val) {
props.setFullScreen = val;
_this.vEl.$forceUpdate();
},
change(val) { change(val) {
onChange(val); onChange(val);
_this.value = val; _this.value = val;
props.value = val.text; props.value = val.text;
_this.vEl.$forceUpdate();
}, },
input(val) { input(val) {
onInput(val); onInput(val);
...@@ -85,8 +96,6 @@ function initMdEditor(obj) { ...@@ -85,8 +96,6 @@ function initMdEditor(obj) {
}, },
submit(val) { submit(val) {
onSubmit(val); onSubmit(val);
_this.value = val;
props.value = val.text;
}, },
upload({ val, callback }) { upload({ val, callback }) {
onUpload(val, function(res) { onUpload(val, function(res) {
...@@ -124,11 +133,21 @@ function initMdEditor(obj) { ...@@ -124,11 +133,21 @@ function initMdEditor(obj) {
this.vEl.$forceUpdate(); this.vEl.$forceUpdate();
}; };
this.toggleTab = function(tabName) { this.toggleTab = function(setPreview) {
if (!tabName) { if (setPreview !== "edit" && setPreview !== "preview") {
props.preview = props.preview === "edit" ? "preview" : "edit"; props.setPreview = !props.preview;
} else {
props.setPreview = setPreview === "preview";
}
props.focus = !props.setPreview;
this.vEl.$forceUpdate();
};
this.toggleFullScreen = function(setFullScreen) {
if (setFullScreen === undefined) {
props.setFullScreen = !props.setFullScreen;
} else { } else {
props.preview = tabName; props.setFullScreen = setFullScreen;
} }
this.vEl.$forceUpdate(); this.vEl.$forceUpdate();
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册