|
@@ -0,0 +1,181 @@
|
|
|
+<template>
|
|
|
+ <div class="createPost-container">
|
|
|
+ <el-form ref="postForm" :label-position="labelPosition" :model="postForm" :rules="rules" class="form-container">
|
|
|
+ <div class="createPost-main-container">
|
|
|
+ <el-form-item prop="content" style="" label="服务协议">
|
|
|
+ <Tinymce ref="editor" v-model="postForm.content" :height="400" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-row>
|
|
|
+ <el-button v-loading="loading" type="success" @click="updateArticle">
|
|
|
+ 修改
|
|
|
+ </el-button>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import Tinymce from '@/components/Tinymce'
|
|
|
+// import Sticky from '@/components/Sticky' // 粘性header组件
|
|
|
+// import { validURL } from '@/utils/validate'
|
|
|
+import { fetchSetting, updateSetting } from '@/api/setting'
|
|
|
+import { searchUser } from '@/api/remote-search'
|
|
|
+// import { CommentDropdown, PlatformDropdown, SourceUrlDropdown } from './Dropdown'
|
|
|
+
|
|
|
+const defaultForm = {
|
|
|
+ status: 'draft',
|
|
|
+ title: '', // 文章题目
|
|
|
+ content: '', // 文章内容
|
|
|
+ content_short: '', // 文章摘要
|
|
|
+ video_url: '', // 文章外链
|
|
|
+ cover_img: '', // 文章图片
|
|
|
+ display_time: undefined, // 前台展示时间
|
|
|
+ id: undefined,
|
|
|
+ platforms: ['a-platform'],
|
|
|
+ comment_disabled: false,
|
|
|
+ importance: 0
|
|
|
+}
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'ArticleDetail',
|
|
|
+ components: { Tinymce },
|
|
|
+ props: {
|
|
|
+ isEdit: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ postForm: Object.assign({}, defaultForm),
|
|
|
+ loading: false,
|
|
|
+ userListOptions: [],
|
|
|
+ rules: {
|
|
|
+ },
|
|
|
+ tempRoute: {},
|
|
|
+ labelPosition: 'top'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ contentShortLength() {
|
|
|
+ return this.postForm.content_short.length
|
|
|
+ },
|
|
|
+ displayTime: {
|
|
|
+ // set and get is useful when the data
|
|
|
+ // returned by the back end api is different from the front end
|
|
|
+ // back end return => "2013-06-25 06:59:25"
|
|
|
+ // front end need timestamp => 1372114765000
|
|
|
+ get() {
|
|
|
+ return (+new Date(this.postForm.display_time))
|
|
|
+ },
|
|
|
+ set(val) {
|
|
|
+ this.postForm.display_time = new Date(val)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ if (this.isEdit) {
|
|
|
+ const id = this.$route.params && this.$route.params.id
|
|
|
+ this.fetchData(id)
|
|
|
+ }
|
|
|
+ // Why need to make a copy of this.$route here?
|
|
|
+ // Because if you enter this page and quickly switch tag, may be in the execution of the setTagsViewTitle function, this.$route is no longer pointing to the current page
|
|
|
+ // https://github.com/PanJiaChen/vue-element-admin/issues/1221
|
|
|
+ this.tempRoute = Object.assign({}, this.$route)
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ fetchData(id) {
|
|
|
+ const type = 'server'
|
|
|
+ fetchSetting(type).then(response => {
|
|
|
+ this.postForm = response.data.info
|
|
|
+ // set tags view title
|
|
|
+ // this.setTagsViewTitle()
|
|
|
+ // set page title
|
|
|
+ // this.setPageTitle()
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ setPageTitle() {
|
|
|
+ const title = 'Edit Article'
|
|
|
+ document.title = `${title} - ${this.postForm.id}`
|
|
|
+ },
|
|
|
+ updateArticle() {
|
|
|
+ this.postForm.type = 'server'
|
|
|
+ updateSetting(this.postForm, 'server').then(response => {
|
|
|
+ this.$notify({
|
|
|
+ title: '修改',
|
|
|
+ message: '修改成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ this.postForm.status = 'published'
|
|
|
+ this.loading = false
|
|
|
+ this.listLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ draftForm() {
|
|
|
+ if (this.postForm.content.length === 0 || this.postForm.title.length === 0) {
|
|
|
+ this.$message({
|
|
|
+ message: '请填写必要的标题和内容',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.$message({
|
|
|
+ message: '保存成功',
|
|
|
+ type: 'success',
|
|
|
+ showClose: true,
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ this.postForm.status = 'draft'
|
|
|
+ },
|
|
|
+ getRemoteUserList(query) {
|
|
|
+ searchUser(query).then(response => {
|
|
|
+ if (!response.data.items) return
|
|
|
+ this.userListOptions = response.data.items.map(v => v.name)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+@import "~@/styles/mixin.scss";
|
|
|
+
|
|
|
+.createPost-container {
|
|
|
+ position: relative;
|
|
|
+
|
|
|
+ .createPost-main-container {
|
|
|
+ padding: 40px 45px 20px 50px;
|
|
|
+
|
|
|
+ .postInfo-container {
|
|
|
+ position: relative;
|
|
|
+ @include clearfix;
|
|
|
+ margin-bottom: 10px;
|
|
|
+
|
|
|
+ .postInfo-container-item {
|
|
|
+ float: left;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .word-counter {
|
|
|
+ width: 40px;
|
|
|
+ position: absolute;
|
|
|
+ right: 10px;
|
|
|
+ top: 0px;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.article-textarea ::v-deep {
|
|
|
+ textarea {
|
|
|
+ padding-right: 40px;
|
|
|
+ resize: none;
|
|
|
+ border: none;
|
|
|
+ border-radius: 0px;
|
|
|
+ border-bottom: 1px solid #bfcbd9;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|