index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 }"> <el-image style="width: 50px; height: 50px" :src="row.articleImage" /></template>
  48. </el-table-column>
  49. <el-table-column label="审核状态" width="120px" align="center">
  50. <template slot-scope="{ row }">
  51. <el-tag v-if="row.auditStatus === 2" size="small" type="warning">待审核</el-tag>
  52. <el-tag v-if="row.auditStatus === 1" size="small" type="success">审核通过</el-tag>
  53. <!-- 未通过原因展示 -->
  54. <template v-if="row.auditStatus === 0">
  55. <!-- <span class="status danger">审核未通过&nbsp;</span> -->
  56. <el-popover placement="top-start" title="审核说明" width="400" trigger="hover" :content="row.invalidReason">
  57. <el-tag slot="reference" size="small" type="danger" class="reason">
  58. <span>审核未通过</span>
  59. <span class="el-icon-question status danger " />
  60. </el-tag>
  61. </el-popover>
  62. <!-- 未通过原因展示END -->
  63. </template>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="上线状态" width="160px" align="center">
  67. <template slot-scope="{ row }">
  68. <!-- 只有审核通过了才能操作上下线 auditStatus :审核状态 -->
  69. <template v-if="row.auditStatus === 1">
  70. <template v-if="row.status === 0">
  71. <span style="margin-right:10px;" class="status danger">已下线</span>
  72. <permission-button type="primary" size="mini" @click="handleChangeStatus(row)">上线</permission-button>
  73. </template>
  74. <template v-else>
  75. <span style="margin-right:10px;" class="status success ">已上线</span>
  76. <permission-button type="info" size="mini" plain @click="handleChangeStatus(row)">下线</permission-button>
  77. </template>
  78. </template>
  79. <template v-else>
  80. <!-- <el-tag type="warning">待上线</el-tag> -->
  81. <span style="margin-right:10px;" class="status warning">待上线</span>
  82. </template>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="创建时间" width="160px" align="center">
  86. <template slot-scope="{ row }">
  87. {{ row.createTime | formatTime }}
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="操作" width="180px" align="center">
  91. <template slot-scope="{ row }">
  92. <permission-button
  93. type="primary"
  94. size="mini"
  95. style="margin-right:12px"
  96. @click="$_navigationTo(`article-edit?articleId=${row.articleId}`)"
  97. >编辑</permission-button>
  98. <permission-button
  99. type="danger"
  100. size="mini"
  101. style="margin-right:12px"
  102. @click="handleRemoveArticle(row)"
  103. >删除</permission-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <!-- 表格区域END -->
  108. <pagination
  109. :total="total"
  110. :page.sync="listQuery.pageNum"
  111. :limit.sync="listQuery.pageSize"
  112. @pagination="getList(listQuery)"
  113. />
  114. </div>
  115. </template>
  116. <script>
  117. import PermissionButton from '@/views/components/PermissionButton'
  118. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  119. import { mapGetters } from 'vuex'
  120. import { changeArticleStatus, getArticleList, removeArticle } from '@/api/doc'
  121. export default {
  122. components: { Pagination, PermissionButton },
  123. data() {
  124. return {
  125. listLoading: false,
  126. total: 0,
  127. listQuery: {
  128. authUserId: '', // 机构id
  129. auditStatus: '', // 审核状态
  130. articleTitle: '', // 文章标题
  131. listType: 1, // 列表类型:1文章列表,2文章审核列表
  132. pageNum: 1, // 页码
  133. pageSize: 10, // 分页大小
  134. status: '' // 文章状态:0已下线,1已上线,2待上线
  135. },
  136. list: []
  137. }
  138. },
  139. computed: {
  140. ...mapGetters(['authUserId', 'userIdentity'])
  141. },
  142. created() {
  143. this.getList()
  144. },
  145. methods: {
  146. // 获取列表数据
  147. getList() {
  148. this.listLoading = true
  149. this.listQuery.authUserId = this.authUserId
  150. getArticleList(this.listQuery)
  151. .then(res => {
  152. if (res.code !== 0) return
  153. this.list = res.data.list
  154. console.log(res)
  155. this.total = res.data.total
  156. })
  157. .finally(() => {
  158. this.listLoading = false
  159. })
  160. },
  161. // 删除文章
  162. async handleRemoveArticle(row) {
  163. const text = await this.$confirm('确认删除该文章吗?', '提示', {
  164. confirmButtonText: '确定',
  165. cancelButtonText: '取消',
  166. type: 'warning'
  167. }).catch(() => {
  168. this.$message.info('已取消操作')
  169. })
  170. if (text !== 'confirm') return
  171. removeArticle({ articleId: row.articleId }).then(res => {
  172. if (res.code !== 0) return
  173. this.$message.success(res.data)
  174. this.getList(this.listQuery)
  175. })
  176. },
  177. // 状态改变
  178. handleChangeStatus(item) {
  179. this.listLoading = true
  180. // const params = {
  181. // authId: item.authId,
  182. // status: item.status ? 1 : 0
  183. // }
  184. console.log(item)
  185. const params = {
  186. articleId: item.articleId,
  187. status: item.status === 1 ? 0 : 1
  188. }
  189. changeArticleStatus(params)
  190. .then(res => {
  191. // this.$message.success(res.data)
  192. this.$message({
  193. message: res.data,
  194. duration: 500,
  195. type: 'success'
  196. })
  197. this.getList()
  198. })
  199. .catch(err => {
  200. console.log(err)
  201. })
  202. .finally(() => {
  203. this.listLoading = false
  204. })
  205. },
  206. indexMethod(index) {
  207. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .el-table .cell {
  214. overflow: visible;
  215. }
  216. .el-badge {
  217. margin: 0 6px;
  218. }
  219. </style>