修改:文章管理页面

This commit is contained in:
jmal 2020-11-16 18:03:16 +08:00
parent 8cd2473a27
commit 4a34836e45
5 changed files with 55 additions and 86 deletions

View File

@ -1851,6 +1851,7 @@ footer .copyright {
.l_body { .l_body {
position: relative; position: relative;
margin: 16px 16px 0 16px; margin: 16px 16px 0 16px;
min-height: calc(100vh - 70vh);
} }
.l_body.nocover { .l_body.nocover {

View File

@ -567,7 +567,7 @@
box-shadow: rgba(0, 0, 0, 0.1) 0px 2px 12px 0px; box-shadow: rgba(0, 0, 0, 0.1) 0px 2px 12px 0px;
} }
/deep/ .markdown-body { /deep/ .article-body {
border-radius: 0.5rem; border-radius: 0.5rem;
blockquote { blockquote {
padding: 0.8em 1em; padding: 0.8em 1em;
@ -623,48 +623,15 @@
} }
} }
} }
i.code-copy{
position: absolute;
top:0;
right: 0;
background-color: #464d5e;
padding: 3px;
margin: 3px 3px 0 0;
font-size: 11px;
border-radius: inherit;
color: #f1f1f1;
cursor: pointer;
display: none;
}
&:hover i.code-copy{
display: block;
}
} }
} }
code { code {
background-size: unset!important;
background: linear-gradient(to right, #5d9eea, #afcafd); background: linear-gradient(to right, #5d9eea, #afcafd);
color: #000;
overflow-wrap: break-word;
word-wrap: break-word;
padding: 0.1rem 0.3rem 0.2rem;
border-radius: 8px;
opacity: 0.9;
} }
pre code { pre code {
background: unset; background: unset;
color: unset;
opacity: unset;
padding: unset;
} }
.hljs code {
background: unset;
color: unset;
opacity: unset;
padding: unset;
}
}
.pre-numbering {
} }
#toggle-nav { #toggle-nav {

View File

@ -4,6 +4,9 @@ export default {
previewUrl: function(username, file) { previewUrl: function(username, file) {
return `${this.baseUrl}/file/${username}${file.path}${file.name}` return `${this.baseUrl}/file/${username}${file.path}${file.name}`
}, },
mardownPreviewUrl: function (path){
return `${this.baseUrl}${path}`
},
publicPreviewUrl: function(fileIds) { publicPreviewUrl: function(fileIds) {
return `${this.baseUrl}/public/preview/${fileIds}` return `${this.baseUrl}/public/preview/${fileIds}`
}, },

View File

@ -24,7 +24,7 @@
</div> </div>
<div class="editor-right"> <div class="editor-right">
<div class="operation"> <div class="operation">
<el-button class="release-button" type="warning" size="small" @click="add" :loading="updating">保存草稿</el-button> <el-button class="release-button" type="warning" size="small" @click="update" :loading="updating">保存草稿</el-button>
<el-button class="release-button" type="primary" size="small" @click="update" :loading="updating">{{ editStatus?'发布文章':'更新文章' }}</el-button> <el-button class="release-button" type="primary" size="small" @click="update" :loading="updating">{{ editStatus?'发布文章':'更新文章' }}</el-button>
</div> </div>
<div class="more-setting"> <div class="more-setting">
@ -238,45 +238,45 @@
}, },
input: (val) => { input: (val) => {
this.valueHasChanged() this.valueHasChanged()
} },
upload: this.markdownImageUplaod()
}) })
}, },
$imgAdd(pos, $file) {
const maxSize = 1024 * 1024 * 5
if($file.size > maxSize){
this.$message({
message: '请选择小于5M的图片! 大于5M的图片将无法上传',
type: 'warning',
duration: 3000,
});
return
}
// 第一步.将图片上传到服务器.
let data = new FormData();
data.append('filename', this.filename)
data.append('username', this.$store.state.user.name)
data.append('userId', this.$store.state.user.userId);
data.append('file', $file);
uploadApi.uploadImage(data).then((res) => {
// 第二步.将返回的url替换到文本原位置![...](0) -> ![...](url)
/**
* $vm 指为mavonEditor实例,可以通过如下两种方式获取
* 1. 通过引入对象获取: `import {mavonEditor} from ...` 等方式引入后,`$vm`为`mavonEditor`
* 2. 通过$refs获取: html声明ref : `<mavon-editor ref=md ></mavon-editor>,`$vm`为 `this.$refs.md`
*/
// const url = process.env.VUE_APP_BASE_FILE_API + '/public/image/' + res.data
const url = fileConfig.publicPreviewUrl(res.data);
console.log(url)
this.$refs.md.$img2Url(pos, url);
})
},
$imgDel(pos, $file) {
},
// 所有操作都会被解析重新渲染 // 所有操作都会被解析重新渲染
change(value, render){ change(value, render){
// render 为 markdown 解析后的结果[html] // render 为 markdown 解析后的结果[html]
this.html = render; this.html = render;
}, },
markdownImageUplaod(){
return {
accept: 'image/*,.mp3, .wav, .rar',
headers: {
'jmal-token': this.$store.state.user.token
},
url: '/api/upload-markdown-image',
extraData: {
'filename': this.filename,
'username': this.$store.state.user.name,
'userId': this.$store.state.user.userId
},
fieldName: 'files',
filename (name) {
return name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').
replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').
replace('/\\s/g', '')
},
format(files, responseText) {
let response = JSON.parse(responseText)
let succMap = {}
response.data.forEach(map => {
succMap[map.filename] = fileConfig.mardownPreviewUrl(map.filepath)
})
response.data = {}
response.data['succMap'] = succMap
return JSON.stringify(response)
}
}
},
fullScreen(status) { fullScreen(status) {
this.isFullScreen = status this.isFullScreen = status
this.reHeight() this.reHeight()
@ -334,6 +334,7 @@
currentDirectory: this.storageLocation, currentDirectory: this.storageLocation,
contentText: this.contentEditor.getValue() contentText: this.contentEditor.getValue()
}).then(() => { }).then(() => {
this.$emit('update:hasChange', false)
this.updating = false this.updating = false
this.$message({ this.$message({
message: "发布成功", message: "发布成功",

View File

@ -57,19 +57,15 @@
<el-table-column <el-table-column
prop="name" prop="name"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
min-width="250" min-width="200"
label="标题"> label="标题">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tooltip :content="'编辑 '+scope.row.name" placement="top"> <router-link :title="'编辑 '+scope.row.name" :to="'/setting/website/manager-articles?operation=editor&id='+scope.row.id" target="_blank">{{scope.row.name}}<svg-icon icon-class="bianji-"></svg-icon></router-link>
<router-link :to="'/setting/website/manager-articles?operation=editor&id='+scope.row.id" target="_blank">{{scope.row.name}}<svg-icon icon-class="bianji-"></svg-icon></router-link> <router-link :title="'浏览 '+scope.row.name" :to="'/articles/article?mark='+scope.row.id" target="_blank"><svg-icon class="wailian" icon-class="wailian"></svg-icon></router-link>
</el-tooltip>
<el-tooltip :content="'浏览 '+scope.row.name" placement="top">
<router-link :to="'/articles/article?mark='+scope.row.id" target="_blank"><svg-icon class="wailian" icon-class="wailian"></svg-icon></router-link>
</el-tooltip>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
width="100" width="150"
label="状态"> label="状态">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag size="medium" type="success">{{ scope.row.release?'已发布':'未发布' }}</el-tag> <el-tag size="medium" type="success">{{ scope.row.release?'已发布':'未发布' }}</el-tag>
@ -88,8 +84,8 @@
label="分类"> label="分类">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-for="(category,i) in scope.row.categories"> <span v-for="(category,i) in scope.row.categories">
{{i>0?' ,':''}}
<router-link to="#">{{category.name}}</router-link> <router-link to="#">{{category.name}}</router-link>
{{i===0?' ,':''}}
</span> </span>
</template> </template>
</el-table-column> </el-table-column>
@ -133,8 +129,8 @@ export default {
hasChange: false, hasChange: false,
articleList: [], articleList: [],
pagination: { pagination: {
pageIndex: 1, pageIndex: this.$route.query.page ? parseInt(decodeURI(this.$route.query.page)) : 1,
pageSize: 15, pageSize: 12,
total: 0, total: 0,
}, },
categories: [], categories: [],
@ -163,6 +159,8 @@ export default {
window.onbeforeunload = function() { window.onbeforeunload = function() {
return "还有文件正在上传, 确定退出吗?" return "还有文件正在上传, 确定退出吗?"
} }
}else {
window.onbeforeunload = null
} }
} }
}, },
@ -173,7 +171,6 @@ export default {
}, },
goBack() { goBack() {
const operation = this.$route.query.operation const operation = this.$route.query.operation
console.log(operation)
if(operation){ if(operation){
this.newArticleDialogVisible = true this.newArticleDialogVisible = true
if(operation === 'new') { if(operation === 'new') {
@ -192,16 +189,16 @@ export default {
this.pagination.total = res.count this.pagination.total = res.count
this.$nextTick(() => { this.$nextTick(() => {
this.isLoading = false this.isLoading = false
this.pagination.pageIndex = parseInt(decodeURI(this.$route.query.page))
}) })
}) })
}, },
currentChange() { currentChange() {
this.getMarkDown() this.$router.push({query: {page : this.pagination.pageIndex}})
this.getArticleList()
}, },
newArticle() { newArticle() {
this.newArticleDialogVisible = true this.newArticleDialogVisible = true
this.$router.push({path: this.$route.path, query: {operation: 'new'}}) this.$router.push({query: {operation: 'new'}})
}, },
categoryTree() { categoryTree() {
categoryApi.categoryTree({userId: this.$store.state.user.userId}).then(res => { categoryApi.categoryTree({userId: this.$store.state.user.userId}).then(res => {
@ -209,7 +206,6 @@ export default {
}) })
}, },
handleClose(done) { handleClose(done) {
console.log(this.hasChange)
if(this.hasChange){ if(this.hasChange){
this.$confirm('还有未保存的内容,确定要离开吗?', '提示', { this.$confirm('还有未保存的内容,确定要离开吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
@ -233,10 +229,8 @@ export default {
}, },
openDialog() { openDialog() {
this.pageTitle = '撰写新文章' this.pageTitle = '撰写新文章'
console.log('pageTitle')
}, },
closeDialog(){ closeDialog(){
console.log('closeDialog')
this.$router.replace({path: this.$route.path}) this.$router.replace({path: this.$route.path})
window.onbeforeunload = null window.onbeforeunload = null
this.pageTitle = '文章管理' this.pageTitle = '文章管理'
@ -253,4 +247,7 @@ export default {
.wailian { .wailian {
margin-left: 8px; margin-left: 8px;
} }
/deep/.el-card__body {
min-width: 1080px;
}
</style> </style>