index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 getBoolDictOptions(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" /> 标记已读
  42. </el-button>
  43. <el-button @click="handleUpdateAll">
  44. <Icon icon="ep:reading" class="mr-5px" /> 全部已读
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </content-wrap>
  49. <content-wrap>
  50. <!-- 列表 -->
  51. <el-table
  52. v-loading="loading"
  53. :data="list"
  54. ref="tableRef"
  55. row-key="id"
  56. @selection-change="handleSelectionChange"
  57. >
  58. <el-table-column type="selection" :selectable="selectable" :reserve-selection="true" />
  59. <el-table-column label="发送人" align="center" prop="templateNickname" width="180" />
  60. <el-table-column
  61. label="发送时间"
  62. align="center"
  63. prop="createTime"
  64. width="200"
  65. :formatter="dateFormatter"
  66. />
  67. <el-table-column label="类型" align="center" prop="templateType" width="180">
  68. <template #default="scope">
  69. <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="scope.row.templateType" />
  70. </template>
  71. </el-table-column>
  72. <el-table-column
  73. label="消息内容"
  74. align="center"
  75. prop="templateContent"
  76. show-overflow-tooltip
  77. />
  78. <el-table-column label="是否已读" align="center" prop="readStatus" width="160">
  79. <template #default="scope">
  80. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.readStatus" />
  81. </template>
  82. </el-table-column>
  83. <el-table-column
  84. label="阅读时间"
  85. align="center"
  86. prop="readTime"
  87. width="200"
  88. :formatter="dateFormatter"
  89. />
  90. <el-table-column label="操作" align="center" width="160">
  91. <template #default="scope">
  92. <el-button
  93. link
  94. :type="scope.row.readStatus ? 'primary' : 'warning'"
  95. @click="openDetail(scope.row)"
  96. >
  97. {{ scope.row.readStatus ? '详情' : '已读' }}
  98. </el-button>
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <!-- 分页 -->
  103. <Pagination
  104. :total="total"
  105. v-model:page="queryParams.pageNo"
  106. v-model:limit="queryParams.pageSize"
  107. @pagination="getList"
  108. />
  109. </content-wrap>
  110. <!-- 表单弹窗:详情 -->
  111. <MyNotifyMessageDetail ref="detailRef" />
  112. </template>
  113. <script setup lang="ts" name="MyNotifyMessage">
  114. import { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
  115. import { dateFormatter } from '@/utils/formatTime'
  116. import * as NotifyMessageApi from '@/api/system/notify/message'
  117. import MyNotifyMessageDetail from './MyNotifyMessageDetail.vue'
  118. const message = useMessage() // 消息
  119. const loading = ref(true) // 列表的加载中
  120. const total = ref(0) // 列表的总页数
  121. const list = ref([]) // 列表的数据
  122. const queryParams = reactive({
  123. pageNo: 1,
  124. pageSize: 10,
  125. readStatus: undefined,
  126. createTime: []
  127. })
  128. const queryFormRef = ref() // 搜索的表单
  129. const tableRef = ref() // 表格的 Ref
  130. const selectedIds = ref<number[]>([]) // 表格的选中 ID 数组
  131. /** 查询列表 */
  132. const getList = async () => {
  133. loading.value = true
  134. try {
  135. const data = await NotifyMessageApi.getMyNotifyMessagePage(queryParams)
  136. list.value = data.list
  137. total.value = data.total
  138. } finally {
  139. loading.value = false
  140. }
  141. }
  142. /** 搜索按钮操作 */
  143. const handleQuery = () => {
  144. queryParams.pageNo = 1
  145. getList()
  146. }
  147. /** 重置按钮操作 */
  148. const resetQuery = () => {
  149. queryFormRef.value.resetFields()
  150. tableRef.value.clearSelection()
  151. handleQuery()
  152. }
  153. /** 详情操作 */
  154. const detailRef = ref()
  155. const openDetail = (data: NotifyMessageApi.NotifyMessageVO) => {
  156. if (!data.readStatus) {
  157. handleReadOne(data.id)
  158. }
  159. detailRef.value.open(data)
  160. }
  161. /** 标记一条站内信已读 */
  162. const handleReadOne = async (id) => {
  163. await NotifyMessageApi.updateNotifyMessageRead(id)
  164. await getList()
  165. }
  166. /** 标记全部站内信已读 **/
  167. const handleUpdateAll = async () => {
  168. await NotifyMessageApi.updateAllNotifyMessageRead()
  169. message.success('全部已读成功!')
  170. tableRef.value.clearSelection()
  171. await getList()
  172. }
  173. /** 标记一些站内信已读 **/
  174. const handleUpdateList = async () => {
  175. if (selectedIds.value.length === 0) {
  176. return
  177. }
  178. await NotifyMessageApi.updateNotifyMessageRead(selectedIds.value)
  179. message.success('批量已读成功!')
  180. tableRef.value.clearSelection()
  181. await getList()
  182. }
  183. /** 某一行,是否允许选中 */
  184. const selectable = (row) => {
  185. return !row.readStatus
  186. }
  187. /** 当表格选择项发生变化时会触发该事件 */
  188. const handleSelectionChange = (array: NotifyMessageApi.NotifyMessageVO[]) => {
  189. selectedIds.value = []
  190. if (!array) {
  191. return
  192. }
  193. array.forEach((row) => selectedIds.value.push(row.id))
  194. }
  195. /** 初始化 **/
  196. onMounted(() => {
  197. getList()
  198. })
  199. </script>