2020-09-08 07:59:55 +08:00
|
|
|
<template>
|
2021-02-23 16:36:52 +08:00
|
|
|
<el-row style="margin-top: 20px;">
|
2020-09-08 09:48:52 +08:00
|
|
|
<el-col style="margin-bottom: 1rem;">
|
|
|
|
<el-breadcrumb separator-class="el-icon-arrow-right">
|
2024-03-20 21:44:26 +08:00
|
|
|
<el-breadcrumb-item :to="{ path: '/admin/dashboard' }">首页</el-breadcrumb-item>
|
2020-09-08 09:48:52 +08:00
|
|
|
<el-breadcrumb-item :to="{ path: '/admin/topics' }">专题管理</el-breadcrumb-item>
|
|
|
|
<el-breadcrumb-item v-if="topic.idTopic" :to="{ path: '/admin/topic/' + topic.topicUri }">{{
|
|
|
|
topic.topicTitle
|
|
|
|
}}
|
|
|
|
</el-breadcrumb-item>
|
|
|
|
<el-breadcrumb-item v-if="topic.idTopic">编辑</el-breadcrumb-item>
|
|
|
|
<el-breadcrumb-item v-else>创建</el-breadcrumb-item>
|
|
|
|
</el-breadcrumb>
|
|
|
|
</el-col>
|
|
|
|
<el-col>
|
|
|
|
<el-form :model="topic" :rules="rules" ref="topic" label-width="100px" class="demo-ruleForm">
|
|
|
|
<el-form-item label="主题名称" prop="topicTitle">
|
|
|
|
<el-input v-model="topic.topicTitle"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="URI" prop="topicUri">
|
|
|
|
<el-input v-model="topic.topicUri"></el-input>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="图标">
|
2021-06-28 08:08:24 +08:00
|
|
|
<el-row>
|
|
|
|
<el-col :span="24">
|
2024-03-22 22:40:55 +08:00
|
|
|
<img @click="cropperVisible = true" :src="topic.topicIconPath" style="width: 80px;height: 80px"/>
|
2021-06-28 08:08:24 +08:00
|
|
|
</el-col>
|
|
|
|
</el-row>
|
2020-09-08 09:48:52 +08:00
|
|
|
</el-form-item>
|
2024-02-20 14:03:01 +08:00
|
|
|
<el-form-item label="描述">
|
2024-03-22 22:40:55 +08:00
|
|
|
<div id="contentEditor"></div>
|
2024-02-20 14:03:01 +08:00
|
|
|
</el-form-item>
|
2020-09-08 09:48:52 +08:00
|
|
|
<el-form-item label="导航主题">
|
|
|
|
<el-switch
|
|
|
|
v-model="topic.topicNva"
|
|
|
|
active-text="启用"
|
|
|
|
inactive-text="禁用"
|
|
|
|
active-value="0"
|
|
|
|
inactive-value="1">
|
|
|
|
</el-switch>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="状态">
|
|
|
|
<el-switch
|
|
|
|
v-model="topic.topicStatus"
|
|
|
|
active-text="启用"
|
|
|
|
inactive-text="禁用"
|
|
|
|
active-value="0"
|
|
|
|
inactive-value="1">
|
|
|
|
</el-switch>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="排序">
|
|
|
|
<el-input-number v-model="topic.topicSort" :min="1"></el-input-number>
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="标签数">
|
|
|
|
<el-input v-model="topic.topicTagCount" :disabled="true"></el-input>
|
|
|
|
</el-form-item>
|
2024-02-20 14:03:01 +08:00
|
|
|
|
2020-09-08 09:48:52 +08:00
|
|
|
<el-form-item class="text-right">
|
2020-09-28 00:37:14 +08:00
|
|
|
<el-button @click="updateTopic" :loading="loading" plain>提交</el-button>
|
2020-09-08 09:48:52 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</el-col>
|
2024-03-22 22:40:55 +08:00
|
|
|
<ImgCropper @onSubmit="updateTopicIcon" :visible.sync='cropperVisible' :avatarUrl="topicIconPath||''"></ImgCropper>
|
2024-02-20 14:03:01 +08:00
|
|
|
|
2020-09-08 09:48:52 +08:00
|
|
|
</el-row>
|
2020-09-08 07:59:55 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-08 09:48:52 +08:00
|
|
|
import Vue from 'vue';
|
2021-06-28 08:08:24 +08:00
|
|
|
import {mapState} from 'vuex';
|
2023-09-08 18:15:07 +08:00
|
|
|
import VueCropper from 'vue-cropper';
|
2022-05-24 11:07:05 +08:00
|
|
|
import apiConfig from '~/config/api.config';
|
2024-02-20 14:03:01 +08:00
|
|
|
import ImgCropper from "~/components/ImgCropper.vue";
|
2020-09-08 09:48:52 +08:00
|
|
|
|
2020-09-08 07:59:55 +08:00
|
|
|
export default {
|
2020-09-08 09:48:52 +08:00
|
|
|
name: "adminTopicPost",
|
2022-10-27 23:22:46 +08:00
|
|
|
middleware: 'auth',
|
2021-06-28 08:08:24 +08:00
|
|
|
components: {
|
2024-02-20 14:03:01 +08:00
|
|
|
VueCropper, ImgCropper
|
2021-06-28 08:08:24 +08:00
|
|
|
},
|
2024-03-22 22:40:55 +08:00
|
|
|
validate({params}) {
|
|
|
|
if (typeof params.topic_id === 'undefined') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return params.topic_id && !isNaN(Number(params.topic_id))
|
|
|
|
},
|
|
|
|
asyncData({store, params, error}) {
|
|
|
|
return Promise.all([
|
|
|
|
store.dispatch('topic/fetchPostDetail', params)
|
|
|
|
.catch(err => error({statusCode: 404}))
|
|
|
|
])
|
|
|
|
},
|
2020-09-08 09:48:52 +08:00
|
|
|
computed: {
|
2021-06-28 08:08:24 +08:00
|
|
|
...mapState({
|
|
|
|
uploadHeaders: state => {
|
|
|
|
return {'X-Upload-Token': state.uploadHeaders}
|
2024-03-22 22:40:55 +08:00
|
|
|
},
|
|
|
|
topicInfo: state => state.topic.detail.data
|
2021-06-28 08:08:24 +08:00
|
|
|
})
|
2020-09-08 09:48:52 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
topic: {
|
|
|
|
topicTitle: '',
|
|
|
|
topicIconPath: '',
|
|
|
|
topicDescription: '',
|
|
|
|
topicNva: '0',
|
|
|
|
topicStatus: '0',
|
|
|
|
topicTagCount: 0,
|
|
|
|
topicSort: 10
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
topicTitle: [
|
|
|
|
{required: true, message: '请输入主题名称', trigger: 'blur'}
|
|
|
|
],
|
|
|
|
topicUri: [
|
|
|
|
{required: true, message: '请输入主题uri', trigger: 'blur'}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
loading: false,
|
|
|
|
tokenURL: {
|
|
|
|
URL: '',
|
2020-10-18 14:43:02 +08:00
|
|
|
linkToImageURL: '',
|
2020-09-08 09:48:52 +08:00
|
|
|
token: ''
|
|
|
|
},
|
|
|
|
topicIconPath: '',
|
2021-03-25 21:48:05 +08:00
|
|
|
isEdit: false,
|
2021-06-28 08:08:24 +08:00
|
|
|
autoCrop: true,
|
2024-02-20 14:03:01 +08:00
|
|
|
notificationFlag: true,
|
|
|
|
cropperVisible: false,
|
2024-03-22 22:40:55 +08:00
|
|
|
contentEditor: {}
|
2024-02-20 14:03:01 +08:00
|
|
|
|
2020-09-08 09:48:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-03-22 22:40:55 +08:00
|
|
|
updateTopicIcon(data) {
|
2024-02-20 14:03:01 +08:00
|
|
|
this.topic.topicIconPath = data
|
|
|
|
this.topicIconPath = data
|
2024-03-22 22:40:55 +08:00
|
|
|
this.topic.topicImageType = '1'
|
2024-02-20 14:03:01 +08:00
|
|
|
this.cropperVisible = false
|
|
|
|
|
|
|
|
},
|
2020-09-08 09:48:52 +08:00
|
|
|
_initEditor(data) {
|
|
|
|
let _ts = this;
|
2021-06-28 08:08:24 +08:00
|
|
|
let toolbar = [
|
|
|
|
'emoji',
|
|
|
|
'headings',
|
|
|
|
'bold',
|
|
|
|
'italic',
|
|
|
|
'strike',
|
|
|
|
'link',
|
|
|
|
'|',
|
|
|
|
'list',
|
|
|
|
'ordered-list',
|
|
|
|
'check',
|
|
|
|
'outdent',
|
|
|
|
'indent',
|
|
|
|
'|',
|
|
|
|
'quote',
|
|
|
|
'line',
|
|
|
|
'code',
|
|
|
|
'inline-code',
|
|
|
|
'insert-before',
|
|
|
|
'insert-after',
|
|
|
|
'|',
|
2022-01-17 10:36:35 +08:00
|
|
|
// 'upload',
|
2021-06-28 08:08:24 +08:00
|
|
|
// 'record',
|
|
|
|
'table',
|
|
|
|
'|',
|
|
|
|
'undo',
|
|
|
|
'redo',
|
|
|
|
'|',
|
|
|
|
'edit-mode',
|
|
|
|
{
|
|
|
|
name: 'more',
|
|
|
|
toolbar: [
|
|
|
|
'fullscreen',
|
|
|
|
'both',
|
|
|
|
'preview',
|
|
|
|
'info'
|
|
|
|
],
|
|
|
|
}]
|
2020-09-08 09:48:52 +08:00
|
|
|
return new Vue.Vditor(data.id, {
|
|
|
|
toolbar,
|
|
|
|
mode: 'sv',
|
|
|
|
tab: '\t',
|
2022-05-24 11:07:05 +08:00
|
|
|
cdn: apiConfig.VDITOR,
|
2020-09-08 09:48:52 +08:00
|
|
|
cache: {
|
|
|
|
enable: this.$route.params.topic_id ? false : true,
|
|
|
|
id: this.$route.params.topic_id ? this.$route.params.topic_id : '',
|
|
|
|
},
|
|
|
|
after() {
|
|
|
|
_ts.contentEditor.setValue(data.value ? data.value : '');
|
|
|
|
},
|
2021-12-22 11:50:20 +08:00
|
|
|
hint: {
|
|
|
|
emoji: Vue.emoji
|
|
|
|
},
|
2020-09-08 09:48:52 +08:00
|
|
|
preview: {
|
|
|
|
hljs: {
|
|
|
|
enable: true,
|
|
|
|
lineNumber: true,
|
|
|
|
style: 'github'
|
|
|
|
},
|
|
|
|
markdown: {
|
|
|
|
toc: true,
|
|
|
|
},
|
|
|
|
math: {
|
|
|
|
inlineDigit: true
|
|
|
|
},
|
|
|
|
delay: 500,
|
|
|
|
mode: data.mode,
|
|
|
|
/*url: `${process.env.Server}/api/console/markdown`,*/
|
|
|
|
parse: (element) => {
|
|
|
|
if (element.style.display === 'none') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// LazyLoadImage();
|
|
|
|
// Vue.Vditor.highlightRender({style: 'github'}, element, this.contentEditor);
|
2022-05-24 11:07:05 +08:00
|
|
|
},
|
|
|
|
theme: {
|
|
|
|
cdn: apiConfig.VDITOR_CSS
|
2020-09-08 09:48:52 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
height: data.height,
|
|
|
|
counter: 102400,
|
|
|
|
resize: {
|
|
|
|
enable: data.resize,
|
|
|
|
},
|
|
|
|
lang: this.$store.state.locale,
|
|
|
|
placeholder: data.placeholder,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
async updateTopic() {
|
|
|
|
let _ts = this;
|
|
|
|
_ts.$set(_ts, 'loading', true);
|
|
|
|
let id = _ts.topic.idTopic;
|
|
|
|
let topicDescription = _ts.contentEditor.getValue();
|
|
|
|
let topicDescriptionHtml = await _ts.contentEditor.getHTML();
|
|
|
|
let data = _ts.topic;
|
|
|
|
data.topicDescription = topicDescription;
|
|
|
|
data.topicDescriptionHtml = topicDescriptionHtml;
|
|
|
|
let title = id ? '更新' : '添加';
|
|
|
|
_ts.$axios[id ? '$put' : '$post']('/api/admin/topic/post', data).then(function (res) {
|
|
|
|
if (res && res.message) {
|
|
|
|
_ts.$message.error(res.message);
|
2024-03-22 22:40:55 +08:00
|
|
|
_ts.$set(_ts, 'loading', false);
|
2020-09-08 09:48:52 +08:00
|
|
|
} else {
|
|
|
|
_ts.$message({
|
|
|
|
type: 'success',
|
|
|
|
message: title + '成功!'
|
|
|
|
});
|
|
|
|
_ts.$set(_ts, 'loading', false);
|
2021-03-25 21:48:05 +08:00
|
|
|
_ts.$set(_ts, 'notificationFlag', false);
|
2020-09-08 09:48:52 +08:00
|
|
|
}
|
|
|
|
})
|
2021-06-28 08:08:24 +08:00
|
|
|
},
|
|
|
|
reset() {
|
|
|
|
this.$refs.cropper.reset();
|
2020-09-08 09:48:52 +08:00
|
|
|
}
|
|
|
|
},
|
2021-03-19 12:10:43 +08:00
|
|
|
beforeRouteLeave(to, from, next) {
|
2021-03-25 21:48:05 +08:00
|
|
|
let _ts = this;
|
|
|
|
if (_ts.notificationFlag) {
|
|
|
|
_ts.$confirm('系统可能不会保存您所做的更改。', '离开此网站?', {
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning'
|
|
|
|
}).then(() => {
|
|
|
|
next();
|
|
|
|
}).catch(() => {
|
|
|
|
return false
|
|
|
|
});
|
|
|
|
} else {
|
2021-03-19 12:10:43 +08:00
|
|
|
next();
|
2021-03-25 21:48:05 +08:00
|
|
|
}
|
2021-03-19 12:10:43 +08:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
},
|
2024-03-22 22:40:55 +08:00
|
|
|
mounted() {
|
2021-03-18 22:37:30 +08:00
|
|
|
window.addEventListener('beforeunload', e => {
|
|
|
|
e = e || window.event;
|
|
|
|
|
|
|
|
// 兼容IE8和Firefox 4之前的版本
|
|
|
|
if (e) {
|
|
|
|
e.returnValue = '关闭提示';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
|
|
|
|
return '关闭提示';
|
|
|
|
});
|
2020-09-08 09:48:52 +08:00
|
|
|
let _ts = this;
|
|
|
|
_ts.$axios.$get('/api/upload/simple/token').then(function (res) {
|
|
|
|
if (res) {
|
|
|
|
_ts.$store.commit('setUploadHeaders', res.uploadToken);
|
|
|
|
_ts.$set(_ts, 'tokenURL', {
|
|
|
|
token: res.uploadToken || '',
|
|
|
|
URL: res.uploadURL || '',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-22 22:40:55 +08:00
|
|
|
Vue.nextTick(() => {
|
|
|
|
let topicDescription = '';
|
|
|
|
if (_ts.$route.params.topic_id) {
|
|
|
|
let topic = _ts.topicInfo
|
|
|
|
_ts.$set(_ts, 'topic', JSON.parse(JSON.stringify(topic)));
|
|
|
|
_ts.$set(_ts, 'isEdit', true);
|
|
|
|
topicDescription = _ts.topic.topicDescription;
|
|
|
|
} else {
|
|
|
|
_ts.$set(_ts, 'isEdit', false);
|
2020-09-08 09:48:52 +08:00
|
|
|
}
|
2024-03-22 22:40:55 +08:00
|
|
|
_ts.contentEditor = _ts._initEditor({
|
|
|
|
id: 'contentEditor',
|
|
|
|
mode: 'both',
|
|
|
|
height: 300,
|
|
|
|
placeholder: '', //this.$t('inputContent', this.$store.state.locale)
|
|
|
|
resize: false,
|
|
|
|
value: topicDescription,
|
|
|
|
});
|
2024-02-20 14:03:01 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-09-08 07:59:55 +08:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-05-23 12:56:16 +08:00
|
|
|
<style lang="less">
|
2024-03-22 22:40:55 +08:00
|
|
|
@import "~vditor/src/assets/less/index.less";
|
2021-06-28 08:08:24 +08:00
|
|
|
|
|
|
|
.preview-area {
|
|
|
|
width: 16rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.preview-area p {
|
|
|
|
font-size: 1.25rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.preview-area p:last-of-type {
|
|
|
|
margin-top: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.crop-placeholder {
|
|
|
|
width: 36px;
|
|
|
|
height: 36px;
|
|
|
|
background: #ccc;
|
|
|
|
}
|
|
|
|
|
|
|
|
.cropped-image img {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.img-cropper {
|
|
|
|
width: 480px;
|
|
|
|
min-height: 480px;
|
|
|
|
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC);
|
|
|
|
}
|
|
|
|
|
|
|
|
.preview-large {
|
|
|
|
width: 100%;
|
|
|
|
height: 144px;
|
|
|
|
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
|
|
|
|
background-color: #ffffff;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2020-09-08 07:59:55 +08:00
|
|
|
</style>
|