edit.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-form ref="form" :model="form" label-width="100px">
  5. <el-form-item label="Title" style="width: 500px;"><!--标题-->
  6. <el-input v-model="form.title" />
  7. </el-form-item>
  8. <el-form-item label="Category"><!--分类-->
  9. <el-select v-model="form.cid" placeholder="please select category"><!--请选择分类-->
  10. <el-option v-for="item in allCategory" :key="item.ID" :label="item.CATE_NAME" :value="item.ID" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="Order" style="width: 500px;"><!--排序值-->
  14. <el-input v-model="form.sort" />
  15. </el-form-item>
  16. <el-form-item label="Content"><!--内容-->
  17. <div class="components-container" style="margin:0">
  18. <!-- <aside>
  19. {{ $t('components.tinymceTips') }}
  20. <a target="_blank" class="link-type" href="https://panjiachen.github.io/vue-element-admin-site/feature/component/rich-editor.html"> {{ $t('components.documentation') }}</a>
  21. </aside> -->
  22. <div>
  23. <tinymce v-model="form.content" :request-route="'v1/ad/upload'" :height="300" />
  24. </div>
  25. <!-- <div class="editor-content" v-html="form.content" /> -->
  26. </div>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" :loading="submitButtonStat" @click="onSubmit">Confirm<!-- 提交 --></el-button>
  30. </el-form-item>
  31. </el-form>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import Tinymce from '@/components/Tinymce'
  37. import { fetchArticleDetail, fetchArticleAdd, fetchArticleAddList, fetchArticleEdit } from '@/api/article'
  38. export default {
  39. name: 'ArticleEdit',
  40. components: { Tinymce },
  41. data() {
  42. return {
  43. form: {
  44. title: '',
  45. cid: null,
  46. content: '',
  47. sort: 1
  48. },
  49. content: '',
  50. allCategory: null,
  51. loading: false,
  52. submitButtonStat: false,
  53. isEdit: false
  54. }
  55. },
  56. mounted() {
  57. if (this.$route.name === 'edit') {
  58. fetchArticleDetail(this.$route.params.ID).then(response => {
  59. console.log(response)
  60. this.form.title = response.data.oneData.TITLE
  61. this.form.cid = response.data.oneData.CID
  62. this.form.content = response.data.oneData.CONTENT
  63. this.form.sort = response.data.oneData.SORT
  64. this.allCategory = response.allCategory
  65. this.loading = false
  66. this.isEdit = true
  67. })
  68. } else {
  69. fetchArticleAddList().then(response => {
  70. this.allCategory = response.data.allCategory
  71. this.loading = false
  72. })
  73. }
  74. },
  75. methods: {
  76. onSubmit() {
  77. this.submitButtonStat = true
  78. if (this.$route.name === 'edit') {
  79. // const path = 'article/edit/' + this.$route.params.id
  80. fetchArticleEdit(this.form, this.$route.params.ID).then(response => {
  81. this.submitButtonStat = false
  82. this.$message({
  83. message: response.data,
  84. type: 'success'
  85. })
  86. this.$router.go(-1)
  87. }).catch(() => {
  88. this.submitButtonStat = false
  89. })
  90. } else {
  91. fetchArticleAdd(this.form).then(response => {
  92. this.submitButtonStat = false
  93. this.$message({
  94. message: response.data,
  95. type: 'success'
  96. })
  97. this.$router.go(-1)
  98. }).catch(() => {
  99. this.submitButtonStat = false
  100. })
  101. }
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. </style>