index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <a-card :bordered="false">
  3. <s-table
  4. ref="table"
  5. :columns="columns"
  6. :data="loadData"
  7. :alert="options.alert.show"
  8. bordered
  9. :row-key="(record) => record.postId"
  10. :tool-config="toolConfig"
  11. :row-selection="options.rowSelection"
  12. >
  13. <template #operator class="table-operator">
  14. <a-space>
  15. <a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('forumPostInfoAdd')">
  16. <template #icon><plus-outlined /></template>
  17. 新增
  18. </a-button>
  19. <xn-batch-delete
  20. v-if="hasPerm('forumPostInfoBatchDelete')"
  21. :selectedRowKeys="selectedRowKeys"
  22. @batchDelete="deleteBatchForumPostInfo"
  23. />
  24. </a-space>
  25. </template>
  26. <template #bodyCell="{ column, record }">
  27. <template v-if="column.dataIndex === 'action'">
  28. <a-space>
  29. <a @click="formRef.onOpen(record)" v-if="hasPerm('forumPostInfoEdit')">编辑</a>
  30. <a-divider type="vertical" v-if="hasPerm(['forumPostInfoEdit', 'forumPostInfoDelete'], 'and')" />
  31. <a-popconfirm title="确定要删除吗?" @confirm="deleteForumPostInfo(record)">
  32. <a-button type="link" danger size="small" v-if="hasPerm('forumPostInfoDelete')">删除</a-button>
  33. </a-popconfirm>
  34. </a-space>
  35. </template>
  36. <template v-if="column.dataIndex === 'postContent'">
  37. <a-tooltip>
  38. <template #title>
  39. <div class="htmlContent" v-html="record.postContent"></div>
  40. </template>
  41. <div class="one-line" v-html="record.postContent"></div>
  42. </a-tooltip>
  43. </template>
  44. <template v-if="column.dataIndex === 'lastReplyTime'">
  45. <div>{{ formatDateTime(record.lastReplyTime) }}</div>
  46. </template>
  47. <template v-if="column.dataIndex === 'postType'">
  48. <div v-if="record.postType == 0">普通帖子</div>
  49. <div v-if="record.postType == 1">技术支持</div>
  50. <div v-if="record.postType == 2">内容纠错</div>
  51. </template>
  52. <template v-if="column.dataIndex === 'postStatus'">
  53. <a-switch
  54. v-model:checked="record.postStatus"
  55. :checkedValue="0"
  56. :unCheckedValue="1"
  57. checked-children="开"
  58. un-checked-children="关"
  59. @change="closeItem($event, record)"
  60. />
  61. </template>
  62. <template v-if="column.dataIndex === 'isTop'">
  63. <a-switch
  64. v-model:checked="record.isTop"
  65. :checkedValue="1"
  66. :unCheckedValue="0"
  67. checked-children="是"
  68. un-checked-children="否"
  69. @change="topItem($event, record)"
  70. />
  71. </template>
  72. <template v-if="column.dataIndex === 'appointUser'">
  73. <span v-for="(item, idx) in seltUserList(record.appointUser)">{{ item.name }},</span>
  74. </template>
  75. </template>
  76. </s-table>
  77. </a-card>
  78. <Form ref="formRef" @successful="table.refresh(true)" />
  79. </template>
  80. <script setup name="postinfo">
  81. import Form from './form.vue'
  82. import forumPostInfoApi from '@/api/forum/forumPostInfoApi'
  83. import forumApi from '@/api/forum/forumApi'
  84. import { parseTime } from '@/utils/exam'
  85. const table = ref()
  86. const formRef = ref()
  87. const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
  88. const columns = [
  89. {
  90. title: '用户',
  91. dataIndex: 'userNickName'
  92. },
  93. {
  94. title: '帖子标题',
  95. dataIndex: 'postTitle',
  96. width: 120
  97. },
  98. {
  99. title: '帖子内容',
  100. dataIndex: 'postContent',
  101. width: 300,
  102. ellipsis: true
  103. },
  104. {
  105. title: '状态',
  106. dataIndex: 'postStatus'
  107. },
  108. {
  109. title: '是否置顶',
  110. dataIndex: 'isTop'
  111. },
  112. {
  113. title: '浏览次数',
  114. dataIndex: 'viewCount'
  115. },
  116. {
  117. title: '回复次数',
  118. dataIndex: 'replyCount'
  119. },
  120. {
  121. title: '点赞次数',
  122. dataIndex: 'likeCount'
  123. },
  124. {
  125. title: '最后回复用户',
  126. dataIndex: 'lastReplyUserNickName',
  127. width: 120
  128. },
  129. {
  130. title: '最后回复时间',
  131. dataIndex: 'lastReplyTime',
  132. width: 120
  133. },
  134. {
  135. title: '帖子类型',
  136. dataIndex: 'postType'
  137. },
  138. {
  139. title: '定向用户',
  140. dataIndex: 'appointUser'
  141. }
  142. ]
  143. function formatDateTime(val) {
  144. if (!val) return ''
  145. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  146. }
  147. //用户
  148. const usertypeOptions = ref([])
  149. // 操作栏通过权限判断是否显示
  150. if (hasPerm(['forumPostInfoEdit', 'forumPostInfoDelete'])) {
  151. columns.push({
  152. title: '操作',
  153. dataIndex: 'action',
  154. align: 'center',
  155. width: '150px'
  156. })
  157. }
  158. const selectedRowKeys = ref([])
  159. // 列表选择配置
  160. const options = {
  161. // columns数字类型字段加入 needTotal: true 可以勾选自动算账
  162. alert: {
  163. show: true,
  164. clear: () => {
  165. selectedRowKeys.value = ref([])
  166. }
  167. },
  168. rowSelection: {
  169. onChange: (selectedRowKey, selectedRows) => {
  170. selectedRowKeys.value = selectedRowKey
  171. }
  172. }
  173. }
  174. const loadData = (parameter) => {
  175. return forumPostInfoApi.forumPostInfoPage(parameter).then((data) => {
  176. return data
  177. })
  178. }
  179. // 重置
  180. const reset = () => {
  181. searchFormRef.value.resetFields()
  182. table.value.refresh(true)
  183. }
  184. // 删除
  185. const deleteForumPostInfo = (record) => {
  186. let params = [
  187. {
  188. postId: record.postId
  189. }
  190. ]
  191. forumPostInfoApi.forumPostInfoDelete(params).then(() => {
  192. table.value.refresh(true)
  193. })
  194. }
  195. // 批量删除
  196. const deleteBatchForumPostInfo = (params) => {
  197. params = params.map((r) => {
  198. return {
  199. postId: r.id
  200. }
  201. })
  202. forumPostInfoApi.forumPostInfoDelete(params).then(() => {
  203. table.value.clearRefreshSelected()
  204. })
  205. }
  206. const closeItem = (event, params) => {
  207. forumApi
  208. .postinfoStatus({
  209. postId: params.postId,
  210. postStatus: event
  211. })
  212. .then((data) => {
  213. table.value.refresh(true)
  214. })
  215. }
  216. const topItem = (event, params) => {
  217. forumApi
  218. .postinfoTop({
  219. postId: params.postId,
  220. postStatus: event
  221. })
  222. .then((data) => {
  223. table.value.refresh(true)
  224. })
  225. }
  226. const getUserList = () => {
  227. forumApi.allUserList().then((data) => {
  228. usertypeOptions.value = data.map((r) => {
  229. return {
  230. label: r.name,
  231. value: r.id,
  232. ...r
  233. }
  234. })
  235. })
  236. }
  237. getUserList()
  238. const seltUserList = (str) => {
  239. return usertypeOptions.value.filter((r) => {
  240. if (str && str.includes(r.id)) {
  241. return r
  242. }
  243. })
  244. }
  245. </script>
  246. <style scoped lang="less">
  247. .htmlContent {
  248. max-height: 400px;
  249. overflow-x: auto;
  250. :deep(img) {
  251. max-width: 100% !important;
  252. }
  253. }
  254. .one-line {
  255. display: -webkit-box;
  256. -webkit-box-orient: vertical;
  257. -webkit-line-clamp: 1;
  258. overflow: hidden;
  259. }
  260. </style>