| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <template>
- <div v-loading="loading">
- <div class="white-box">
- <el-form ref="form" :model="form" label-width="100px">
- <el-form-item label="Title" style="width: 500px;"><!--标题-->
- <el-input v-model="form.title" />
- </el-form-item>
- <el-form-item label="Category"><!--分类-->
- <el-select v-model="form.cid" placeholder="please select category"><!--请选择分类-->
- <el-option v-for="item in allCategory" :key="item.ID" :label="item.CATE_NAME" :value="item.ID" />
- </el-select>
- </el-form-item>
- <el-form-item label="Order" style="width: 500px;"><!--排序值-->
- <el-input v-model="form.sort" />
- </el-form-item>
- <el-form-item label="Content"><!--内容-->
- <div class="components-container" style="margin:0">
- <!-- <aside>
- {{ $t('components.tinymceTips') }}
- <a target="_blank" class="link-type" href="https://panjiachen.github.io/vue-element-admin-site/feature/component/rich-editor.html"> {{ $t('components.documentation') }}</a>
- </aside> -->
- <div>
- <tinymce v-model="form.content" :request-route="'v1/ad/upload'" :height="300" />
- </div>
- <!-- <div class="editor-content" v-html="form.content" /> -->
- </div>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" :loading="submitButtonStat" @click="onSubmit">Confirm<!-- 提交 --></el-button>
- </el-form-item>
- </el-form>
- </div>
- </div>
- </template>
- <script>
- import Tinymce from '@/components/Tinymce'
- import { fetchArticleDetail, fetchArticleAdd, fetchArticleAddList, fetchArticleEdit } from '@/api/article'
- export default {
- name: 'ArticleEdit',
- components: { Tinymce },
- data() {
- return {
- form: {
- title: '',
- cid: null,
- content: '',
- sort: 1
- },
- content: '',
- allCategory: null,
- loading: false,
- submitButtonStat: false,
- isEdit: false
- }
- },
- mounted() {
- if (this.$route.name === 'edit') {
- fetchArticleDetail(this.$route.params.ID).then(response => {
- console.log(response)
- this.form.title = response.data.oneData.TITLE
- this.form.cid = response.data.oneData.CID
- this.form.content = response.data.oneData.CONTENT
- this.form.sort = response.data.oneData.SORT
- this.allCategory = response.allCategory
- this.loading = false
- this.isEdit = true
- })
- } else {
- fetchArticleAddList().then(response => {
- this.allCategory = response.data.allCategory
- this.loading = false
- })
- }
- },
- methods: {
- onSubmit() {
- this.submitButtonStat = true
- if (this.$route.name === 'edit') {
- // const path = 'article/edit/' + this.$route.params.id
- fetchArticleEdit(this.form, this.$route.params.ID).then(response => {
- this.submitButtonStat = false
- this.$message({
- message: response.data,
- type: 'success'
- })
- this.$router.go(-1)
- }).catch(() => {
- this.submitButtonStat = false
- })
- } else {
- fetchArticleAdd(this.form).then(response => {
- this.submitButtonStat = false
- this.$message({
- message: response.data,
- type: 'success'
- })
- this.$router.go(-1)
- }).catch(() => {
- this.submitButtonStat = false
- })
- }
- }
- }
- }
- </script>
- <style scoped>
- </style>
|