From 9a42d070eb82053a57e9a48f5928964061c4058a Mon Sep 17 00:00:00 2001 From: JimQing Date: Sat, 2 May 2020 11:50:26 +0800 Subject: [PATCH] split component and bug fix --- src/api/fetch.js | 1 - src/components/CodemirrorEditor.vue | 369 ++++------------------ src/components/codeMirror/aboutDialog.vue | 34 ++ src/components/codeMirror/header.vue | 245 ++++++++++++-- src/components/codeMirror/insertForm.vue | 71 +++++ src/scripts/util.js | 2 +- src/store/index.js | 16 +- 7 files changed, 393 insertions(+), 345 deletions(-) create mode 100644 src/components/codeMirror/aboutDialog.vue create mode 100644 src/components/codeMirror/insertForm.vue diff --git a/src/api/fetch.js b/src/api/fetch.js index 206de7f..eae069c 100644 --- a/src/api/fetch.js +++ b/src/api/fetch.js @@ -11,7 +11,6 @@ service.interceptors.request.use( if (/^(post)|(put)|(delete)$/i.test(config.method)) { if (config.data && config.data.upload) { config.headers['Content-Type'] = 'multipart/form-data'; - config.headers['Access-Control-Allow-Origin'] = 'http://192.168.0.106:8080'; } } return config; diff --git a/src/components/CodemirrorEditor.vue b/src/components/CodemirrorEditor.vue index b283473..2533475 100644 --- a/src/components/CodemirrorEditor.vue +++ b/src/components/CodemirrorEditor.vue @@ -1,123 +1,41 @@ diff --git a/src/components/codeMirror/aboutDialog.vue b/src/components/codeMirror/aboutDialog.vue new file mode 100644 index 0000000..d7927a2 --- /dev/null +++ b/src/components/codeMirror/aboutDialog.vue @@ -0,0 +1,34 @@ + + + + + \ No newline at end of file diff --git a/src/components/codeMirror/header.vue b/src/components/codeMirror/header.vue index 6f83a02..c590940 100644 --- a/src/components/codeMirror/header.vue +++ b/src/components/codeMirror/header.vue @@ -1,29 +1,29 @@ \ No newline at end of file diff --git a/src/components/codeMirror/insertForm.vue b/src/components/codeMirror/insertForm.vue new file mode 100644 index 0000000..8f9b784 --- /dev/null +++ b/src/components/codeMirror/insertForm.vue @@ -0,0 +1,71 @@ + + + + + \ No newline at end of file diff --git a/src/scripts/util.js b/src/scripts/util.js index d7f8893..aa9f968 100644 --- a/src/scripts/util.js +++ b/src/scripts/util.js @@ -184,7 +184,7 @@ export function saveEditorContent(editor, name) { } } -export function checkImage(file) { +export function isImageIllegal(file) { if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name)) { return '请上传 JPG/PNG/GIF 格式的图片'; } diff --git a/src/store/index.js b/src/store/index.js index bb88250..c82f7ab 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -20,7 +20,8 @@ const state = { html: '', currentFont: '', currentSize: '', - currentColor: '' + currentColor: '', + citeStatus: 0 }; const mutations = { setEditorValue(state, data) { @@ -32,6 +33,10 @@ const mutations = { setWxRendererOptions(state, data) { state.wxRenderer.setOptions(data); }, + setCiteStatus(state, data) { + state.citeStatus = data; + localStorage.setItem('citeStatus', data) + }, setCurrentFont(state, data) { state.currentFont = data; localStorage.setItem('fonts', data) @@ -48,12 +53,12 @@ const mutations = { state.currentFont = localStorage.getItem('fonts') || config.builtinFonts[0].value state.currentColor = localStorage.getItem('color') || config.colorOption[1].value state.currentSize = localStorage.getItem('size') || config.sizeOption[2].value - state.status = localStorage.getItem('status') === 'true' + state.citeStatus = localStorage.getItem('citeStatus') === 'true' state.wxRenderer = new WxRenderer({ theme: setColor(state.currentColor), fonts: state.currentFont, size: state.currentSize, - status: state.status + status: state.citeStatus }) }, initEditorEntity(state) { @@ -89,6 +94,7 @@ const mutations = { extraKeys: { 'Ctrl-F': function autoFormat(editor) { const totalLines = editor.lineCount() + editor.autoFormatRange({ line: 0, ch: 0 @@ -109,11 +115,11 @@ const mutations = { }, editorRefresh(state) { let output = marked(state.editor.getValue(0), { - renderer: state.wxRenderer.getRenderer(state.status) + renderer: state.wxRenderer.getRenderer(state.citeStatus) }) // 去除第一行的 margin-top output = output.replace(/(style=".*?)"/, '$1;margin-top: 0"') - if (state.status) { + if (state.citeStatus) { // 引用脚注 output += state.wxRenderer.buildFootnotes() // 附加的一些 style