index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <content-wrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="是否已读" prop="readStatus">
  12. <el-select
  13. v-model="queryParams.readStatus"
  14. placeholder="请选择状态"
  15. clearable
  16. class="!w-240px"
  17. >
  18. <el-option
  19. v-for="dict in getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
  20. :key="dict.value"
  21. :label="dict.label"
  22. :value="dict.value"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="发送时间" prop="createTime">
  27. <el-date-picker
  28. v-model="queryParams.createTime"
  29. value-format="YYYY-MM-DD HH:mm:ss"
  30. type="daterange"
  31. start-placeholder="开始日期"
  32. end-placeholder="结束日期"
  33. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  34. class="!w-240px"
  35. />
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  39. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  40. <el-button @click="handleUpdateList"
  41. ><Icon icon="ep:reading" class="mr-5px" /> 标记已读</el-button
  42. >
  43. <el-button @click="handleUpdateAll"
  44. ><Icon icon="ep:reading" class="mr-5px" /> 全部已读</el-button
  45. >
  46. </el-form-item>
  47. </el-form>
  48. <!-- <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button @click="handleUpdateList"
  51. ><Icon icon="ep:refresh" class="mr-5px" /> 标记已读</el-button
  52. >
  53. </el-col>
  54. <el-col :span="1.5">
  55. <el-button @click="handleUpdateAll"
  56. ><Icon icon="ep:refresh" class="mr-5px" /> 全部已读</el-button
  57. >
  58. </el-col>
  59. </el-row> -->
  60. </content-wrap>
  61. <content-wrap>
  62. <!-- 列表 -->
  63. <el-table
  64. ref="tableRef"
  65. v-loading="loading"
  66. :data="list"
  67. :height="tableHeight"
  68. :row-key="getRowKeys"
  69. @selection-change="handleSelectionChange"
  70. >
  71. <el-table-column type="selection" :selectable="selectable" :reserve-selection="true" />
  72. <!-- <el-table-column label="编号" align="center" prop="id" /> -->
  73. <el-table-column label="发送人" align="center" prop="templateNickname" width="180" />
  74. <el-table-column
  75. label="发送时间"
  76. align="center"
  77. prop="createTime"
  78. width="200"
  79. :formatter="dateFormatter"
  80. />
  81. <el-table-column label="类型" align="center" prop="templateType" width="180">
  82. <template #default="scope">
  83. <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="scope.row.templateType" />
  84. </template>
  85. </el-table-column>
  86. <el-table-column
  87. label="消息内容"
  88. align="center"
  89. prop="templateContent"
  90. show-overflow-tooltip
  91. />
  92. <el-table-column label="是否已读" align="center" prop="readStatus" width="160">
  93. <template #default="scope">
  94. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.readStatus" />
  95. </template>
  96. </el-table-column>
  97. <el-table-column
  98. label="阅读时间"
  99. align="center"
  100. prop="readTime"
  101. width="200"
  102. :formatter="dateFormatter"
  103. />
  104. <el-table-column label="操作" align="center" width="160">
  105. <template #default="scope">
  106. <el-button
  107. link
  108. :type="scope.row.readStatus ? 'primary' : 'warning'"
  109. @click="openModal(scope.row)"
  110. >
  111. {{ scope.row.readStatus ? '详情' : '查阅' }}
  112. </el-button>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <!-- 分页 -->
  117. <Pagination
  118. :total="total"
  119. v-model:page="queryParams.pageNo"
  120. v-model:limit="queryParams.pageSize"
  121. @pagination="getList"
  122. />
  123. </content-wrap>
  124. <!-- 表单弹窗:详情 -->
  125. <my-notify-message-detail ref="modalRef" />
  126. </template>
  127. <script setup lang="ts" name="MyNotifyMessage">
  128. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  129. import { dateFormatter } from '@/utils/formatTime'
  130. import * as NotifyMessageApi from '@/api/system/notify/message'
  131. import MyNotifyMessageDetail from './detail.vue'
  132. const message = useMessage() // 消息
  133. const loading = ref(true) // 列表的加载中
  134. const total = ref(0) // 列表的总页数
  135. const list = ref([]) // 列表的数据
  136. const queryParams = reactive({
  137. pageNo: 1,
  138. pageSize: 10,
  139. readStatus: undefined,
  140. createTime: []
  141. })
  142. const queryFormRef = ref() // 搜索的表单
  143. const tableRef = ref()
  144. const tableHeight = ref() // table高度
  145. const selectedNum = ref(0) //表格select选中的条数
  146. const selectedIds = ref([] as any[]) //表格select复选框选中的id
  147. const multipleSelection = ref([])
  148. /** 查询参数列表 */
  149. const getList = async () => {
  150. loading.value = true
  151. try {
  152. const data = await NotifyMessageApi.getMyNotifyMessagePage(queryParams)
  153. list.value = data.list
  154. total.value = data.total
  155. } finally {
  156. loading.value = false
  157. }
  158. }
  159. /** 详情操作 */
  160. const modalRef = ref()
  161. const openModal = (data: NotifyMessageApi.NotifyMessageVO) => {
  162. if (!data.readStatus) {
  163. handleUpdate(data.id)
  164. }
  165. modalRef.value.openModal(data)
  166. }
  167. // 标记指定 id 已读
  168. const handleUpdate = async (ids) => {
  169. await NotifyMessageApi.updateNotifyMessageRead(ids)
  170. //message.success('标记已读成功!')
  171. handleQuery()
  172. }
  173. // 标记全部已读
  174. const handleUpdateAll = async () => {
  175. await NotifyMessageApi.updateAllNotifyMessageRead()
  176. message.success('全部已读成功!')
  177. handleQuery()
  178. }
  179. // 标记勾选 ids 已读
  180. const handleUpdateList = async () => {
  181. if (selectedIds.value.length === 0) {
  182. return
  183. }
  184. await NotifyMessageApi.updateNotifyMessageRead(selectedIds.value)
  185. message.success('批量已读成功!')
  186. tableRef.value.clearSelection()
  187. handleQuery()
  188. }
  189. /** 搜索按钮操作 */
  190. const handleQuery = () => {
  191. queryParams.pageNo = 1
  192. getList()
  193. }
  194. /** 重置按钮操作 */
  195. const resetQuery = () => {
  196. queryFormRef.value.resetFields()
  197. tableRef.value.clearSelection()
  198. handleQuery()
  199. }
  200. /** 初始化 **/
  201. onMounted(() => {
  202. getList()
  203. // TODO 感觉表格自适应高度体验好些,目前简单实现 需要进一步优化
  204. tableHeight.value = window.innerHeight - tableRef.value.$el.offsetTop - 85 - 155
  205. // 监听浏览器高度变化
  206. window.onresize = () => {
  207. tableHeight.value = window.innerHeight - tableRef.value.$el.offsetTop - 85 - 155
  208. }
  209. })
  210. // 禁用某行复选框
  211. const selectable = (row) => {
  212. return !row.readStatus
  213. }
  214. //选中的list
  215. const getRowKeys = (row) => {
  216. return row.id
  217. }
  218. //当表格选择项发生变化时会触发该事件
  219. const handleSelectionChange = (val) => {
  220. // 解决来回切换页面,也无法清除上次选中情况
  221. multipleSelection.value = val
  222. selectedNum.value = multipleSelection.value.length
  223. selectedIds.value = []
  224. if (val) {
  225. undefined
  226. val.forEach((row) => {
  227. undefined
  228. if (row) {
  229. undefined
  230. selectedIds.value.push(row.id)
  231. }
  232. })
  233. }
  234. }
  235. </script>