ArticlePostPublish.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div>
  3. <el-row style="position: center">
  4. <h2>发布文章</h2>
  5. <el-form ref="form" :model="form" label-width="60px">
  6. <el-form-item label="标题">
  7. <el-input v-model="form.title" style="width: 70%; padding-right: 2px" />
  8. </el-form-item>
  9. <el-form-item label="摘要" style="width: 70%; padding-right: 2px">
  10. <el-input v-model="form.excerpt" type="textarea" autosize style="padding-right: 1px;" />
  11. </el-form-item>
  12. <el-form-item label="内容">
  13. <rich-text style="width: 80%; padding-right: 2px" @content="processContent" />
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" @click="onSubmit">发布</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </el-row>
  20. </div>
  21. </template>
  22. <script>
  23. import RichText from '@/components/RichText'
  24. import { submitArticle } from '@/api/article'
  25. export default {
  26. name: 'ArticlePostPublish',
  27. components: { RichText },
  28. data() {
  29. return {
  30. content: '',
  31. form: {
  32. title: '',
  33. excerpt: '',
  34. content: ''
  35. }
  36. }
  37. },
  38. created() {
  39. },
  40. methods: {
  41. processContent(value) {
  42. this.form.content = value
  43. },
  44. onSubmit() {
  45. console.log(this.form)
  46. submitArticle(this.form).then(res => {
  47. if (res.code === 0) {
  48. this.$notify({
  49. title: '提示',
  50. message: '投稿成功',
  51. type: 'warning',
  52. duration: 3000
  53. })
  54. this.$router.push('/bg/post/article')
  55. } else {
  56. this.$notify({
  57. title: '提示',
  58. message: res.msg,
  59. type: 'warning',
  60. duration: 3000
  61. })
  62. }
  63. }).catch(error => {
  64. this.$notify({
  65. title: '提示',
  66. message: error.message,
  67. type: 'warning',
  68. duration: 3000
  69. })
  70. })
  71. }
  72. }
  73. }
  74. </script>
  75. <style>
  76. </style>