修改:文章编辑界面

This commit is contained in:
jmal 2020-12-09 18:12:27 +08:00
parent be11879c27
commit 2cb2a57012
3 changed files with 45 additions and 28 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="edit-div" <div id="edit-div"
v-html="innerText" v-html="innerText"
:contenteditable="canEdit" :contenteditable="canEdit"
@focus="isLocked = true" @focus="isLocked = true"
@ -22,39 +22,41 @@ export default{
}, },
data(){ data(){
return { return {
innerText: this.value, innerText: '',
isLocked: false isLocked: false,
} }
}, },
watch: { watch: {
'value'(){ value(value){
if (!this.isLocked || !this.innerText) { if (!this.isLocked || !this.innerText) {
this.innerText = this.value; console.log('value', value)
this.innerText = value
document.getElementById('edit-div').innerHTML = value
} }
} }
}, },
methods: { methods: {
changeText(){ changeText(){
this.$emit('input', this.$el.innerHTML); this.$emit('input', this.$el.innerHTML)
} }
} }
} }
</script> </script>
<style lang="scss" rel="stylesheet/scss"> <style lang="scss" rel="stylesheet/scss">
.edit-div { .edit-div {
//overflow: auto; overflow: auto;
//word-break: break-all; word-break: break-all;
//outline: none; outline: none;
//user-select: text; user-select: text;
//white-space: pre-wrap; white-space: pre-wrap;
//text-align: left; text-align: left;
//&[contenteditable=true]{ &[contenteditable=true]{
// user-modify: read-write-plaintext-only; user-modify: read-write-plaintext-only;
// &:empty:before { &:empty:before {
// content: attr(placeholder); content: attr(placeholder);
// display: block; display: block;
// color: #ccc; color: #ccc;
// } }
//} }
} }
</style> </style>

View File

@ -10,6 +10,7 @@
<div class="url-slug"> <div class="url-slug">
<div>{{ articleLink }}</div> <div>{{ articleLink }}</div>
<edit-element <edit-element
ref="editElement"
class="mark-setting-input" class="mark-setting-input"
v-model="file.slug" v-model="file.slug"
placeholder="缩略名" placeholder="缩略名"
@ -31,9 +32,9 @@
<el-date-picker <el-date-picker
v-model="file.uploadDate" v-model="file.uploadDate"
type="datetime" type="datetime"
size="small"
value-format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss">
placeholder="____-__-__ __:__">
</el-date-picker> </el-date-picker>
<p class="mark-setting-label">分类:</p> <p class="mark-setting-label">分类:</p>
<el-tree <el-tree
@ -156,6 +157,7 @@
}] }]
export default { export default {
inject: ['appReload'],
name: 'MarkdownEditor', name: 'MarkdownEditor',
components: { components: {
EditElement, EditElement,
@ -195,7 +197,7 @@
treeProps: { treeProps: {
label: 'name', label: 'name',
}, },
releaseTime: undefined releaseTime: undefined,
} }
}, },
mounted() { mounted() {
@ -240,6 +242,7 @@
this.$emit('update:hasChange', true) this.$emit('update:hasChange', true)
}, },
getMarkdown(isReload){ getMarkdown(isReload){
this.draft = false
if(this.$route.query.id){ if(this.$route.query.id){
this.editStatus = true this.editStatus = true
markdownApi.getMarkdown({ markdownApi.getMarkdown({
@ -251,6 +254,7 @@
this.currentDarft = true this.currentDarft = true
} }
} else { } else {
this.currentDarft = false
this.file = res.data this.file = res.data
} }
// 初始化编辑器 // 初始化编辑器
@ -414,7 +418,6 @@
saveDraft() { saveDraft() {
this.draft = true this.draft = true
this.update('保存草稿成功') this.update('保存草稿成功')
this.getMarkdown(true)
}, },
release() { release() {
this.draft = false this.draft = false
@ -433,12 +436,12 @@
fileId: this.$route.query.id, fileId: this.$route.query.id,
username: this.$store.state.user.name username: this.$store.state.user.name
}).then(() => { }).then(() => {
this.reload()
this.$message({ this.$message({
message: "草稿已被删除", message: "草稿已被删除",
type: 'success', type: 'success',
duration : 1000 duration : 1000
}) })
this.reload()
}) })
}) })
}, },
@ -464,14 +467,21 @@
currentDirectory: this.storageLocation, currentDirectory: this.storageLocation,
contentText: this.contentEditor.getValue(), contentText: this.contentEditor.getValue(),
uploadDate: this.file.uploadDate, uploadDate: this.file.uploadDate,
}).then(() => { }).then((res) => {
this.$emit('update:hasChange', false) this.$emit('update:hasChange', false)
this.updating = false this.updating = false
this.$message({ this.$message({
message: message ? message : "发布成功", message: message ? message : "发布成功",
type: 'success', type: 'success',
duration : 1000 duration : 1000
}); })
if(this.draft){
this.$router.push({path: this.$route.path, query: {operation: 'editor', id: res.data}})
this.$emit('onTitle', this.filename)
this.reload()
} else {
this.$emit('onRelease')
}
}).catch(()=> { }).catch(()=> {
this.updating = false this.updating = false
}) })
@ -639,6 +649,7 @@
border-radius: 2px; border-radius: 2px;
color: #666; color: #666;
width: fit-content; width: fit-content;
min-width: 35px;
background-color: #ecf5ff; background-color: #ecf5ff;
&:focus { &:focus {
outline: none; outline: none;

View File

@ -9,7 +9,7 @@
@open="openDialog" @open="openDialog"
@close="closeDialog" @close="closeDialog"
> >
<markdown-editor ref="editor" :has-change.sync="hasChange" @onTitle="onTitle"></markdown-editor> <markdown-editor ref="editor" :has-change.sync="hasChange" @onTitle="onTitle" @onRelease="onRelease"></markdown-editor>
</el-dialog> </el-dialog>
<el-card class="box-card"> <el-card class="box-card">
<div slot="header"> <div slot="header">
@ -368,6 +368,10 @@ export default {
openDialog() { openDialog() {
this.pageTitle = '撰写新文章' this.pageTitle = '撰写新文章'
}, },
onRelease() {
this.newArticleDialogVisible = false
this.closeDialog()
},
closeDialog(){ closeDialog(){
this.$router.replace({path: this.$route.path}) this.$router.replace({path: this.$route.path})
window.onbeforeunload = null window.onbeforeunload = null