ArticlePost.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <el-container>
  3. <el-header height="220">
  4. <el-row style="margin-top: 10px">
  5. <el-button type="plain" icon="el-icon-plus" @click="goToArticlePublish">发布文章</el-button>
  6. </el-row>
  7. </el-header>
  8. <el-main :md="6" :sm="12" :xs="12">
  9. <el-table
  10. :data="dataList"
  11. height="480"
  12. style="width: 100%"
  13. >
  14. <el-table-column
  15. type="index"
  16. />
  17. <el-table-column
  18. prop="createAt"
  19. label="发布时间"
  20. />
  21. <el-table-column
  22. prop="title"
  23. label="文章标题"
  24. >
  25. <template slot-scope="scope">
  26. <router-link target="_blank" :to="`/article/${scope.row.articleId}`">
  27. <span>{{ scope.row.title }}</span>
  28. </router-link>
  29. </template>
  30. </el-table-column>
  31. <el-table-column
  32. prop="scope"
  33. label="可见范围"
  34. >
  35. <template slot-scope="scope">
  36. <el-tooltip class="item" effect="dark" content="点击修改可见范围" placement="top-end">
  37. <el-button
  38. v-if="scope.row.scope === 1"
  39. size="mini"
  40. @click="handleScope(scope.$index, scope.row)"
  41. >本人可见</el-button>
  42. <el-button
  43. v-else-if="scope.row.scope === 2"
  44. size="mini"
  45. type="success"
  46. @click="handleScope(scope.$index, scope.row)"
  47. >所有人可见</el-button>
  48. <el-button
  49. v-else-if="scope.row.scope === 3"
  50. size="mini"
  51. type="warning"
  52. @click="handleScope(scope.$index, scope.row)"
  53. >VIP 可见</el-button>
  54. </el-tooltip>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="操作">
  58. <template slot-scope="scope">
  59. <el-button
  60. size="mini"
  61. @click="handleEdit(scope.$index, scope.row)"
  62. >编辑</el-button>
  63. <el-button
  64. size="mini"
  65. type="danger"
  66. @click="handleDelete(scope.$index, scope.row)"
  67. >删除</el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <!-- 修改可见范围对话框 -->
  72. <el-dialog
  73. append-to-body
  74. :visible.sync="showEditScopeDialog"
  75. width="30%"
  76. center
  77. >
  78. <el-card class="box-card">
  79. <div slot="header" class="clearfix">
  80. <span>修改可见范围</span>
  81. <el-button style="float: right; padding: 3px 0" type="text" @click="onUpdateScope">更新</el-button>
  82. </div>
  83. <div class="text item">
  84. <el-select v-model="form.scope" placeholder="选择可见范围">
  85. <el-option label="本人可见" value="1" />
  86. <el-option label="所有人可见" value="2" />
  87. <el-option label="VIP 可见" value="3" />
  88. </el-select>
  89. </div>
  90. </el-card>
  91. </el-dialog>
  92. </el-main>
  93. <el-row>
  94. <el-pagination
  95. background
  96. :small="screenWidth <= 768"
  97. layout="prev, pager, next"
  98. :page-size="pageSize"
  99. :current-page="currentPage"
  100. :total="totalSize"
  101. @current-change="handleCurrentChange"
  102. @prev-click="handleCurrentChange"
  103. @next-click="handleCurrentChange"
  104. />
  105. </el-row>
  106. </el-container>
  107. </template>
  108. <script>
  109. import { updateArticleScope, deleteArticle, getArticlePosts } from '@/api/article'
  110. export default {
  111. name: 'ArticlePost',
  112. data() {
  113. return {
  114. // 屏幕宽度, 为了控制分页条的大小
  115. screenWidth: document.body.clientWidth,
  116. currentPage: 1,
  117. pageSize: 20,
  118. totalSize: 0,
  119. dataList: [],
  120. // **********************************************************************
  121. showEditScopeDialog: false,
  122. form: {
  123. articleId: null,
  124. scope: 1
  125. }
  126. }
  127. },
  128. created() {
  129. document.title = '文章稿件'
  130. this.getData()
  131. },
  132. methods: {
  133. handleCurrentChange(pageNumber) {
  134. this.currentPage = pageNumber
  135. this.getData()
  136. // 回到顶部
  137. scrollTo(0, 0)
  138. },
  139. getData() {
  140. getArticlePosts(this.currentPage).then(resp => {
  141. if (resp.code === 0) {
  142. this.dataList = resp.data.list
  143. this.totalSize = resp.data.totalSize
  144. } else {
  145. this.$notify({
  146. title: '提示',
  147. message: resp.msg,
  148. type: 'warning',
  149. duration: 3000
  150. })
  151. }
  152. })
  153. },
  154. handleScope(index, row) {
  155. this.form.articleId = row.articleId
  156. this.form.scope = '' + row.scope
  157. this.showEditScopeDialog = true
  158. },
  159. handleEdit(index, row) {
  160. const path = '/bg/post/article/edit/' + row.articleId
  161. this.$router.push(path)
  162. },
  163. handleDelete(index, row) {
  164. this.$confirm('确定要删除 ' + row.title + '?', '提示', {
  165. confirmButtonText: '确定',
  166. cancelButtonText: '取消',
  167. type: 'warning'
  168. }).then(() => {
  169. deleteArticle(row.articleId).then(res => {
  170. if (res.code === 0) {
  171. this.$notify({
  172. title: '提示',
  173. message: '稿件已删除',
  174. type: 'warning',
  175. duration: 3000
  176. })
  177. // this.$router.go(0)
  178. }
  179. })
  180. }).catch(() => {
  181. this.$message({
  182. type: 'info',
  183. message: '已取消'
  184. })
  185. })
  186. },
  187. onUpdateScope() {
  188. this.showEditScopeDialog = false
  189. updateArticleScope(this.form).then(res => {
  190. if (res.code === 0) {
  191. this.$notify({
  192. title: '提示',
  193. message: '可见范围已更新',
  194. type: 'warning',
  195. duration: 3000
  196. })
  197. }
  198. }).catch(error => {
  199. this.$notify({
  200. title: '提示',
  201. message: error.message,
  202. type: 'warning',
  203. duration: 3000
  204. })
  205. })
  206. },
  207. goToArticlePublish() {
  208. this.$message.info('publish article')
  209. this.$router.push('/post/article/publish')
  210. }
  211. }
  212. }
  213. </script>
  214. <style>
  215. </style>