|
@@ -0,0 +1,265 @@
|
|
|
+<template>
|
|
|
+ <div class="createPost-container">
|
|
|
+ <el-form ref="postForm" :model="postForm" :rules="rules" class="form-container">
|
|
|
+ <div class="createPost-main-container">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24">
|
|
|
+ <div class="postInfo-container">
|
|
|
+ <div style="margin-bottom: 10px;">banner图</div>
|
|
|
+ <el-form-item prop="url" style="margin-bottom: 30px;" label="">
|
|
|
+ <Upload v-model="postForm.url" />
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <div class="postInfo-container">
|
|
|
+ <div style="margin-bottom: 10px;">跳转路劲</div>
|
|
|
+ <el-form-item prop="redirect" style="margin-bottom: 30px;" label="">
|
|
|
+ <el-input v-model="postForm.redirect" placeholder="请输入路径" style="width: 300px;" />
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <div class="postInfo-container">
|
|
|
+ <div style="margin-bottom: 10px;">排序</div>
|
|
|
+ <el-form-item prop="sort" style="margin-bottom: 30px;" label="">
|
|
|
+ <el-input v-model="postForm.sort" placeholder="排序(倒序)" style="width: 100px;" />
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <div class="postInfo-container">
|
|
|
+ <div style="margin-bottom: 10px;">所属位置</div>
|
|
|
+ <el-form-item prop="position" style="margin-bottom: 30px;" label="">
|
|
|
+ <template>
|
|
|
+ <el-radio-group v-model="postForm.position">
|
|
|
+ <el-radio :label="1">首页</el-radio>
|
|
|
+ <el-radio :label="2">活动页</el-radio>
|
|
|
+ <el-radio :label="3">备选项</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </template>
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <div class="postInfo-container">
|
|
|
+ <div style="margin-bottom: 10px;">状态</div>
|
|
|
+ <el-form-item prop="status" style="margin-bottom: 30px;" label="">
|
|
|
+ <el-switch v-model="postForm.status" active-text="激活" inactive-text="隐藏" />
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <el-button v-if="!isEdit" v-loading="loading" type="success" @click="submitForm">
|
|
|
+ 提交
|
|
|
+ </el-button>
|
|
|
+ <el-button v-if="isEdit" v-loading="loading" type="success" @click="updateArticle">
|
|
|
+ 修改
|
|
|
+ </el-button>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+
|
|
|
+import Upload from '@/components/Upload/SingleImage3'
|
|
|
+
|
|
|
+// import Sticky from '@/components/Sticky' // 粘性header组件
|
|
|
+// import { validURL } from '@/utils/validate'
|
|
|
+import { fetchBanner, createBanner, updateBanner } from '@/api/banner'
|
|
|
+// import Warning from './Warning'
|
|
|
+// import { CommentDropdown, PlatformDropdown, SourceUrlDropdown } from './Dropdown'
|
|
|
+
|
|
|
+const defaultForm = {
|
|
|
+ // status: 'draft',
|
|
|
+ redirect: '', // 文章题目
|
|
|
+ status: true, // 文章内容
|
|
|
+ position: 1, // 文章摘要
|
|
|
+ url: '', // 文章外链
|
|
|
+ cover_img: '', // 文章图片
|
|
|
+ display_time: undefined, // 前台展示时间
|
|
|
+ id: undefined,
|
|
|
+ platforms: ['a-platform'],
|
|
|
+ comment_disabled: false,
|
|
|
+ importance: 0
|
|
|
+}
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'ArticleDetail',
|
|
|
+ components: { Upload },
|
|
|
+ props: {
|
|
|
+ isEdit: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ const validateRequire = (rule, value, callback) => {
|
|
|
+ if (value === '') {
|
|
|
+ this.$message({
|
|
|
+ message: rule.field + '为必传项',
|
|
|
+ type: 'error'
|
|
|
+ })
|
|
|
+ callback(new Error(rule.field + '为必传项'))
|
|
|
+ } else {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ postForm: Object.assign({}, defaultForm),
|
|
|
+ loading: false,
|
|
|
+ userListOptions: [],
|
|
|
+ rules: {
|
|
|
+ url: [{ message: 'banner图不为空', validator: validateRequire }]
|
|
|
+ },
|
|
|
+ tempRoute: {}
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ },
|
|
|
+ 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) {
|
|
|
+ fetchBanner(id).then(response => {
|
|
|
+ this.postForm = response.data.info
|
|
|
+ this.postForm.status = this.postForm.status === 1
|
|
|
+ this.postForm.position = this.editPosition(this.postForm.position)
|
|
|
+ // 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}`
|
|
|
+ },
|
|
|
+ submitForm() {
|
|
|
+ this.$refs.postForm.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ this.loading = true
|
|
|
+ console.log(this.postForm)
|
|
|
+ if (this.postForm.status || this.postForm.status === '') {
|
|
|
+ this.postForm.status = 1
|
|
|
+ }
|
|
|
+ this.postForm.createPosition = this.formatCreatePosition(this.postForm.position)
|
|
|
+ createBanner(this.postForm).then(response => {
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: 'banner创建成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ this.loading = false
|
|
|
+ this.listLoading = false
|
|
|
+ this.$router.push(`/banner/list`)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ console.log('error submit!!')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ updateArticle() {
|
|
|
+ console.log(this.postForm)
|
|
|
+ updateBanner(this.postForm).then(response => {
|
|
|
+ this.$notify({
|
|
|
+ title: '修改',
|
|
|
+ message: '修改成功',
|
|
|
+ type: 'success',
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ this.postForm.status = 'published'
|
|
|
+ this.loading = false
|
|
|
+ this.listLoading = false
|
|
|
+ this.$router.push(`/banner/list`)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ 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'
|
|
|
+ },
|
|
|
+ formatCreatePosition(position) {
|
|
|
+ switch (position) {
|
|
|
+ case 1:
|
|
|
+ return 'HOME'
|
|
|
+ case 2:
|
|
|
+ return 'ACTIVITY'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ editPosition(position) {
|
|
|
+ switch (position) {
|
|
|
+ case 'HOME':
|
|
|
+ return 1
|
|
|
+ case 'ACTIVITY':
|
|
|
+ return 2
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</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>
|