my.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div class="pageWrap 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="scope">
  29. <el-tooltip content="查看" placement="bottom" effect="light">
  30. <el-icon class="ibt0" @click="openDetail(scope.row)">
  31. <View />
  32. </el-icon>
  33. </el-tooltip>
  34. <el-divider direction="vertical"></el-divider>
  35. <el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row)">
  36. <template #reference>
  37. <el-icon class="ibt0">
  38. <Delete />
  39. </el-icon>
  40. </template>
  41. </el-popconfirm>
  42. </template>
  43. </LeTable>
  44. </div>
  45. <message-detail v-if="visibleDetail" v-model="visibleDetail" :message-id="currentId" @closed="visibleDetail = false"> </message-detail>
  46. </div>
  47. </template>
  48. <script lang="tsx" setup>
  49. import message from '@/api/system/message'
  50. import {nextTick, ref, watch} from 'vue'
  51. import {useTablePage} from '@/hooks/useTablePage'
  52. import MessageDetail from './detail.vue'
  53. import {useRoute} from 'vue-router'
  54. import {Delete} from "@element-plus/icons-vue";
  55. import {ElMessage} from "element-plus";
  56. const route = useRoute()
  57. const visibleDetail = ref(false) // 权限设置弹窗显示隐藏
  58. const currentId = ref(null)
  59. // 表格搜索条件
  60. const forms = ref([
  61. {
  62. prop: 'title',
  63. label: '标题:',
  64. itemType: 'input',
  65. placeholder: '请输入标题'
  66. },
  67. {
  68. prop: 'createBy',
  69. label: '发布人:',
  70. itemType: 'input',
  71. placeholder: '请输入发布人'
  72. }
  73. ])
  74. // table列表数据请求
  75. const queryList = async () => {
  76. const {options, searchParams} = tableOpts
  77. options.loading = true
  78. try {
  79. const {records: list, total} = await message.getMessageInfo(searchParams)
  80. tableOpts.total = total
  81. tableOpts.list = list
  82. } catch {
  83. console.log('获取列表数据失败')
  84. tableOpts.total = 0
  85. tableOpts.list = []
  86. options.loading = false // 更改加载中的 loading值
  87. } finally {
  88. options.loading = false
  89. }
  90. }
  91. // table 参数
  92. const columns = [
  93. {
  94. prop: 'title',
  95. label: '标题',
  96. minWidth: 80
  97. },
  98. {
  99. prop: 'category',
  100. label: '消息类型',
  101. minWidth: 100,
  102. slots: {
  103. default: 'categorySlot'
  104. }
  105. },
  106. {
  107. prop: 'createBy',
  108. label: '发布人',
  109. minWidth: 100
  110. },
  111. {
  112. prop: 'createTime',
  113. label: '发布时间',
  114. minWidth: 150
  115. },
  116. {
  117. prop: 'action',
  118. label: '操作',
  119. width: 100,
  120. fixed: 'right',
  121. slots: {
  122. default: 'actionSlot'
  123. }
  124. }
  125. ]
  126. const {searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams} = useTablePage(
  127. {
  128. options: {
  129. showIndex: false
  130. },
  131. // 需要展示的列
  132. columns,
  133. // 控制列配置
  134. columnsConfig: {
  135. columns
  136. }
  137. },
  138. {
  139. queryList,
  140. fetchImmediate: false
  141. }
  142. )
  143. // 删除
  144. const deleteItem = async ids => {
  145. try {
  146. await message.messageDeleteApi(ids)
  147. updateParams()
  148. } catch (e) {
  149. console.log('删除失败')
  150. ElMessage.error(`删除失败~`)
  151. }
  152. }
  153. // 单个删除
  154. const table_del = row => {
  155. deleteItem([row.id])
  156. }
  157. //批量删除
  158. const batch_del = () => {
  159. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  160. deleteItem(ids)
  161. }
  162. const openDetail = (row: any) => {
  163. currentId.value = row.id
  164. visibleDetail.value = true
  165. }
  166. nextTick(() => {
  167. queryList()
  168. })
  169. watch(
  170. () => route.query,
  171. (newPath, oldPath) => {
  172. if (JSON.stringify(newPath) !== '{}') {
  173. nextTick(() => {
  174. openDetail(newPath)
  175. })
  176. }
  177. },
  178. {immediate: true}
  179. )
  180. </script>
  181. <style scoped lang="scss">
  182. .pageWrap {
  183. flex: 1;
  184. display: flex;
  185. height: 100%;
  186. min-height: 0;
  187. //background-color: #fafafa;
  188. background-color: var(--el-fill-color-lighter);
  189. //background: #fff;
  190. }
  191. .content-warp {
  192. flex: 1;
  193. width: calc(100% - 210px);
  194. }
  195. // 应用的树结构样式
  196. :deep(.menu-tree) {
  197. .el-tree-node__content {
  198. height: 36px;
  199. }
  200. .el-tree-node__content .el-tree-node__label .icon {
  201. margin-right: 5px;
  202. }
  203. }
  204. .nopadding {
  205. padding: 0px;
  206. }
  207. </style>