index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索区域 -->
  4. <div class="filter-container">
  5. <div class="filter-control">
  6. <span>文章标题:</span>
  7. <el-input v-model="listQuery.articleTitle" placeholder="文章标题" @keyup.enter.native="getList" />
  8. </div>
  9. <div class="filter-control">
  10. <span>审核状态:</span>
  11. <el-select v-model="listQuery.auditStatus" placeholder="审核状态" clearable @change="getList">
  12. <el-option label="全部" value="" />
  13. <el-option label="待审核" :value="2" />
  14. <el-option label="审核通过" :value="1" />
  15. <el-option label="审核未通过" :value="0" />
  16. </el-select>
  17. </div>
  18. <div class="filter-control">
  19. <span>上线状态:</span>
  20. <el-select v-model="listQuery.status" placeholder="上线状态" clearable @change="getList">
  21. <el-option label="全部" value="" />
  22. <el-option label="已上线" :value="1" />
  23. <el-option label="待上线" :value="2" />
  24. <el-option label="未上线" :value="0" />
  25. </el-select>
  26. </div>
  27. <div class="filter-control">
  28. <permission-button type="primary" @click="getList">查询</permission-button>
  29. <permission-button type="primary" @click="navigationTo(`article-edit`)">添加文章</permission-button>
  30. </div>
  31. </div>
  32. <!-- 搜索区域END -->
  33. <!-- 表格区域 -->
  34. <el-table
  35. v-loading="listLoading"
  36. :data="list"
  37. style="width: 100%"
  38. border
  39. fit
  40. highlight-current-row
  41. cell-class-name="table-cell"
  42. header-row-class-name="tableHeader"
  43. >
  44. <el-table-column label="序号" :index="indexMethod" type="index" width="80" align="center" />
  45. <el-table-column label="文章标题" prop="articleTitle" align="center" />
  46. <el-table-column label="文章头图" width="100px" align="center">
  47. <template slot-scope="{ row }">
  48. <el-image
  49. v-if="row.articleImage"
  50. style="width: 50px; height: 50px"
  51. :src="row.articleImage"
  52. /></template>
  53. </el-table-column>
  54. <el-table-column label="审核状态" width="120px" align="center">
  55. <template slot-scope="{ row }">
  56. <audit-status :status="row.auditStatus" :reason="row.invalidReason" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="上线状态" width="160px" align="center">
  60. <template slot-scope="{ row }">
  61. <!-- 只有审核通过了才能操作上下线 auditStatus :审核状态 -->
  62. <template v-if="row.auditStatus === 1">
  63. <template v-if="row.status === 0">
  64. <span style="margin-right: 10px" class="status danger">已下线</span>
  65. <permission-button type="primary" size="mini" @click="handleChangeStatus(row)">上线</permission-button>
  66. </template>
  67. <template v-else>
  68. <span style="margin-right: 10px" class="status success">已上线</span>
  69. <permission-button type="info" size="mini" @click="handleChangeStatus(row)">下线</permission-button>
  70. </template>
  71. </template>
  72. <template v-else>
  73. <!-- <el-tag type="warning">待上线</el-tag> -->
  74. <span style="margin-right: 10px" class="status warning">待上线</span>
  75. </template>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="创建时间" width="160px" align="center">
  79. <template slot-scope="{ row }">
  80. {{ row.createTime | formatTime }}
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="操作" width="180px" align="center">
  84. <template slot-scope="{ row }">
  85. <permission-button
  86. type="primary"
  87. size="mini"
  88. style="margin-right: 12px"
  89. @click="navigationTo(`article-edit?articleId=${row.articleId}`)"
  90. >编辑</permission-button>
  91. <permission-button
  92. type="danger"
  93. size="mini"
  94. style="margin-right: 12px"
  95. @click="handleRemoveArticle(row)"
  96. >删除</permission-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <!-- 表格区域END -->
  101. <pagination
  102. :total="total"
  103. :page.sync="listQuery.pageNum"
  104. :limit.sync="listQuery.pageSize"
  105. @pagination="getList(listQuery)"
  106. />
  107. </div>
  108. </template>
  109. <script>
  110. import { mapGetters } from 'vuex'
  111. import { changeArticleStatus, getArticleList, removeArticle } from '@/api/doc'
  112. export default {
  113. data() {
  114. return {
  115. listLoading: false,
  116. total: 0,
  117. listQuery: {
  118. authUserId: '', // 机构id
  119. auditStatus: '', // 审核状态
  120. articleTitle: '', // 文章标题
  121. listType: 1, // 列表类型:1文章列表,2文章审核列表
  122. pageNum: 1, // 页码
  123. pageSize: 10, // 分页大小
  124. status: '' // 文章状态:0已下线,1已上线,2待上线
  125. },
  126. list: []
  127. }
  128. },
  129. computed: {
  130. ...mapGetters(['authUserId', 'userIdentity'])
  131. },
  132. created() {
  133. this.getList()
  134. },
  135. methods: {
  136. // 获取列表数据
  137. getList() {
  138. this.listLoading = true
  139. this.listQuery.authUserId = this.authUserId
  140. getArticleList(this.listQuery)
  141. .then((res) => {
  142. if (res.code !== 0) return
  143. this.list = res.data.list
  144. console.log(res)
  145. this.total = res.data.total
  146. })
  147. .finally(() => {
  148. this.listLoading = false
  149. })
  150. },
  151. // 删除文章
  152. async handleRemoveArticle(row) {
  153. const text = await this.$confirm('确认删除该文章吗?', '提示', {
  154. confirmButtonText: '确定',
  155. cancelButtonText: '取消',
  156. type: 'warning'
  157. }).catch(() => {
  158. this.$message.info('已取消操作')
  159. })
  160. if (text !== 'confirm') return
  161. removeArticle({ articleId: row.articleId }).then((res) => {
  162. if (res.code !== 0) return
  163. this.$message.success(res.data)
  164. this.getList(this.listQuery)
  165. })
  166. },
  167. // 状态改变
  168. handleChangeStatus(item) {
  169. this.listLoading = true
  170. // const params = {
  171. // authId: item.authId,
  172. // status: item.status ? 1 : 0
  173. // }
  174. console.log(item)
  175. const params = {
  176. articleId: item.articleId,
  177. status: item.status === 1 ? 0 : 1
  178. }
  179. changeArticleStatus(params)
  180. .then((res) => {
  181. // this.$message.success(res.data)
  182. this.$message({
  183. message: res.data,
  184. duration: 500,
  185. type: 'success'
  186. })
  187. this.getList()
  188. })
  189. .catch((err) => {
  190. console.log(err)
  191. })
  192. .finally(() => {
  193. this.listLoading = false
  194. })
  195. },
  196. indexMethod(index) {
  197. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .el-table .cell {
  204. overflow: visible;
  205. }
  206. .el-badge {
  207. margin: 0 6px;
  208. }
  209. </style>