ArticleDetail.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="createPost-container">
  3. <el-form ref="postForm" :label-position="labelPosition" :model="postForm" :rules="rules" class="form-container" label-width="60px">
  4. <div class="createPost-main-container">
  5. <el-row>
  6. <el-form-item prop="head_img" style="margin-bottom: 30px;" label="头像">
  7. <el-image :src="postForm.head_img" />
  8. </el-form-item>
  9. </el-row>
  10. <el-row>
  11. <el-form-item prop="user_name" style="margin-bottom: 30px;" label="姓名">
  12. <el-input v-model="postForm.user_name" placeholder="" style="width: 300px;" />
  13. </el-form-item>
  14. </el-row>
  15. <el-row>
  16. <el-form-item prop="mobile" style="margin-bottom: 30px;" label="手机号">
  17. <el-input v-model="postForm.mobile" placeholder="" style="width: 200px;" />
  18. </el-form-item>
  19. </el-row>
  20. <el-row>
  21. <el-form-item prop="open_id" style="margin-bottom: 30px;" label="openid">
  22. <el-input v-model="postForm.open_id" placeholder="" style="width: 200px;" :disabled="true" />
  23. </el-form-item>
  24. </el-row>
  25. <el-row>
  26. <el-button v-if="!isEdit" v-loading="loading" type="success" @click="submitForm">
  27. 提交
  28. </el-button>
  29. <el-button v-if="isEdit" v-loading="loading" type="success" @click="updateArticle">
  30. 修改
  31. </el-button>
  32. </el-row>
  33. </div>
  34. </el-form>
  35. </div>
  36. </template>
  37. <script>
  38. // import Upload from '@/components/Upload/SingleImage3'
  39. // import Sticky from '@/components/Sticky' // 粘性header组件
  40. // import { validURL } from '@/utils/validate'
  41. import { fetchUser, updateUser } from '@/api/user'
  42. // import Warning from './Warning'
  43. // import { CommentDropdown, PlatformDropdown, SourceUrlDropdown } from './Dropdown'
  44. const defaultForm = {
  45. // status: 'draft',
  46. user_name: '', // 文章题目
  47. status: true, // 文章内容
  48. head_img: '', // 文章摘要
  49. mobile: '', // 文章外链
  50. open_id: '', // 文章图片
  51. display_time: undefined, // 前台展示时间
  52. id: undefined,
  53. platforms: ['a-platform'],
  54. comment_disabled: false,
  55. importance: 0
  56. }
  57. export default {
  58. name: 'ArticleDetail',
  59. components: { },
  60. props: {
  61. isEdit: {
  62. type: Boolean,
  63. default: false
  64. }
  65. },
  66. data() {
  67. return {
  68. postForm: Object.assign({}, defaultForm),
  69. loading: false,
  70. userListOptions: [],
  71. rules: {
  72. },
  73. tempRoute: {},
  74. labelPosition: 'left'
  75. }
  76. },
  77. computed: {
  78. },
  79. created() {
  80. if (this.isEdit) {
  81. const id = this.$route.params && this.$route.params.id
  82. this.fetchData(id)
  83. }
  84. // Why need to make a copy of this.$route here?
  85. // 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
  86. // https://github.com/PanJiaChen/vue-element-admin/issues/1221
  87. this.tempRoute = Object.assign({}, this.$route)
  88. },
  89. methods: {
  90. fetchData(id) {
  91. fetchUser(id).then(response => {
  92. this.postForm = response.data
  93. // set tags view title
  94. // this.setTagsViewTitle()
  95. // set page title
  96. // this.setPageTitle()
  97. }).catch(err => {
  98. console.log(err)
  99. })
  100. },
  101. setPageTitle() {
  102. const title = 'Edit Article'
  103. document.title = `${title} - ${this.postForm.id}`
  104. },
  105. submitForm() {
  106. this.$refs.postForm.validate(valid => {
  107. if (valid) {
  108. this.loading = true
  109. } else {
  110. console.log('error submit!!')
  111. return false
  112. }
  113. })
  114. },
  115. updateArticle() {
  116. console.log(this.postForm)
  117. updateUser(this.postForm).then(response => {
  118. this.$notify({
  119. title: '修改',
  120. message: '修改成功',
  121. type: 'success',
  122. duration: 2000
  123. })
  124. this.postForm.status = 'published'
  125. this.loading = false
  126. this.listLoading = false
  127. this.$router.push(`/user/list`)
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. @import "~@/styles/mixin.scss";
  135. .createPost-container {
  136. position: relative;
  137. .createPost-main-container {
  138. padding: 40px 45px 20px 50px;
  139. .postInfo-container {
  140. position: relative;
  141. @include clearfix;
  142. margin-bottom: 10px;
  143. .postInfo-container-item {
  144. float: left;
  145. }
  146. }
  147. }
  148. .word-counter {
  149. width: 40px;
  150. position: absolute;
  151. right: 10px;
  152. top: 0px;
  153. }
  154. }
  155. .article-textarea ::v-deep {
  156. textarea {
  157. padding-right: 40px;
  158. resize: none;
  159. border: none;
  160. border-radius: 0px;
  161. border-bottom: 1px solid #bfcbd9;
  162. }
  163. }
  164. </style>