my.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="pageWrap bgc flex-column-page-wrap">
  3. <div class="flex-column-page-wrap">
  4. <!-- 公用搜索组件 -->
  5. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"></LeSearchForm>
  6. <!-- LeTable 组件使用 -->
  7. <LeTable
  8. ref="tableRef"
  9. v-model:searchParams="tableOpts.searchParams"
  10. v-bind="tableOpts"
  11. v-model:curRow="tableOpts.curRow"
  12. v-model:checked-options="checkedColumns"
  13. :columns="activeColumns"
  14. >
  15. <template #toolLeft>
  16. <el-button type="primary">全部标记已读</el-button>
  17. <el-button type="danger" :disabled="curSelectionRows.length === 0" @click="batch_del">
  18. <el-icon class="btn-icon">
  19. <Delete />
  20. </el-icon>
  21. </el-button>
  22. </template>
  23. <template #categorySlot="scope">
  24. <el-tag v-if="scope.row.category === 0" size="small" effect="plain">通知公告</el-tag>
  25. <el-tag v-if="scope.row.category === 1" size="small" type="info" effect="plain">系统消息</el-tag>
  26. <el-tag v-if="scope.row.category === 2" size="small" type="warning" effect="plain">待办通知</el-tag>
  27. </template>
  28. <template #actionSlot="{ row }">
  29. <div class="flex flex-align-pack-center">
  30. <LeIcon class="text-lg text-icon-color" icon-class="icon-processInfo-icons--view-light" @click="openDetail(row)" />
  31. <LeIcon class="text-lg ml-2 text-rose-700" icon-class="icon-processInfo-iconoir--trash" @click="table_del(row)" />
  32. </div>
  33. </template>
  34. </LeTable>
  35. </div>
  36. <message-detail v-if="visibleDetail" v-model="visibleDetail" :message-id="currentId" @closed="visibleDetail = false"></message-detail>
  37. </div>
  38. </template>
  39. <script lang="tsx" setup>
  40. import message from '@/api/system/message'
  41. import { nextTick, ref, watch } from 'vue'
  42. import { useTablePage } from '@/hooks/useTablePage'
  43. import MessageDetail from './detail.vue'
  44. import { useRoute } from 'vue-router'
  45. import { Delete } from '@element-plus/icons-vue'
  46. import { ElMessage, ElMessageBox } from 'element-plus'
  47. const route = useRoute()
  48. const visibleDetail = ref(false) // 权限设置弹窗显示隐藏
  49. const currentId = ref(null)
  50. // 表格搜索条件
  51. const forms = ref([
  52. {
  53. prop: 'title',
  54. label: '标题:',
  55. itemType: 'input',
  56. placeholder: '请输入标题'
  57. },
  58. {
  59. prop: 'createBy',
  60. label: '发布人:',
  61. itemType: 'input',
  62. placeholder: '请输入发布人'
  63. }
  64. ])
  65. // table列表数据请求
  66. const queryList = async () => {
  67. const { options, searchParams } = tableOpts
  68. options.loading = true
  69. try {
  70. const { records: list, total } = await message.getMessageInfo(searchParams)
  71. tableOpts.total = total
  72. tableOpts.list = list
  73. } catch {
  74. console.log('获取列表数据失败')
  75. tableOpts.total = 0
  76. tableOpts.list = []
  77. options.loading = false // 更改加载中的 loading值
  78. } finally {
  79. options.loading = false
  80. }
  81. }
  82. // table 参数
  83. const columns = [
  84. {
  85. prop: 'title',
  86. label: '标题',
  87. minWidth: 80
  88. },
  89. {
  90. prop: 'category',
  91. label: '消息类型',
  92. minWidth: 100,
  93. slots: {
  94. default: 'categorySlot'
  95. }
  96. },
  97. {
  98. prop: 'createBy',
  99. label: '发布人',
  100. minWidth: 100
  101. },
  102. {
  103. prop: 'createTime',
  104. label: '发布时间',
  105. minWidth: 150
  106. },
  107. {
  108. prop: 'action',
  109. label: '操作',
  110. width: 100,
  111. align: 'center',
  112. fixed: 'right',
  113. slots: {
  114. default: 'actionSlot'
  115. }
  116. }
  117. ]
  118. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  119. {
  120. options: {
  121. showIndex: false
  122. },
  123. // 需要展示的列
  124. columns,
  125. // 控制列配置
  126. columnsConfig: {
  127. columns
  128. }
  129. },
  130. {
  131. queryList,
  132. fetchImmediate: false
  133. }
  134. )
  135. // 删除
  136. const deleteItem = async ids => {
  137. // try {
  138. await message.messageDeleteApi(ids)
  139. updateParams()
  140. ElMessage.success(`删除成功~`)
  141. // } catch (e) {
  142. // console.log('删除失败')
  143. // ElMessage.error(`删除失败~`)
  144. // }
  145. }
  146. // 单个删除
  147. const table_del = (row: any) => {
  148. ElMessageBox.confirm(`确认删除「${row.title}」这条数据?`, '提示', {
  149. confirmButtonText: '确认',
  150. cancelButtonText: '取消',
  151. type: 'error'
  152. }).then(async () => {
  153. deleteItem([row.id])
  154. })
  155. }
  156. //批量删除
  157. const batch_del = () => {
  158. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  159. ElMessageBox.confirm('是否删除选中数据?', '提示', {
  160. confirmButtonText: '确认',
  161. cancelButtonText: '取消',
  162. type: 'error',
  163. buttonSize: 'default'
  164. }).then(() => {
  165. deleteItem(ids)
  166. })
  167. }
  168. const openDetail = (row: any) => {
  169. currentId.value = row.id
  170. visibleDetail.value = true
  171. }
  172. nextTick(() => {
  173. queryList()
  174. })
  175. watch(
  176. () => route.query,
  177. (newPath, oldPath) => {
  178. if (JSON.stringify(newPath) !== '{}') {
  179. nextTick(() => {
  180. openDetail(newPath)
  181. })
  182. }
  183. },
  184. { immediate: true }
  185. )
  186. </script>
  187. <style scoped lang="scss"></style>