messageNotify.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="message-notify-container">
  3. <el-table
  4. style="width: 100%; margin-top: 20px"
  5. border
  6. :data="localFormData"
  7. :default-sort="{ prop: 'createTime', order: 'descending' }"
  8. >
  9. <el-table-column prop="id" label="序号" width="80" align="center">
  10. <template slot-scope="scope">
  11. {{ scope.$index + 1 }}
  12. </template>
  13. </el-table-column>
  14. <el-table-column
  15. prop="noticeTitle"
  16. label="消息主题"
  17. width="200"
  18. align="center"
  19. ></el-table-column>
  20. <el-table-column
  21. prop="noticeSource"
  22. label="消息来源"
  23. width="220"
  24. align="center"
  25. show-overflow-tooltip
  26. ></el-table-column>
  27. <el-table-column
  28. prop="auditObject"
  29. label="发送对象"
  30. width="150"
  31. align="center"
  32. show-overflow-tooltip
  33. ></el-table-column>
  34. <el-table-column
  35. prop="noticeContent"
  36. label="消息内容"
  37. min-width="350"
  38. header-align="center"
  39. align="left"
  40. show-overflow-tooltip
  41. ></el-table-column>
  42. <el-table-column
  43. prop="createTime"
  44. label="发送时间"
  45. width="120"
  46. align="center"
  47. sortable
  48. >
  49. <template slot-scope="scope">
  50. <div>{{ scope.row.createTime.split(' ')[0] }}</div>
  51. <div>{{ scope.row.createTime.split(' ')[1] }}</div>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <el-pagination
  56. background
  57. layout="total, sizes, prev, pager, next"
  58. :current-page="internalPagination.currentPage"
  59. :page-sizes="[10, 20, 30, 50]"
  60. :page-size="internalPagination.pageSize"
  61. :total="internalPagination.total"
  62. style="margin-top: 20px; text-align: right"
  63. @current-change="handleCurrentChange"
  64. @size-change="handleSizeChange"
  65. />
  66. </div>
  67. </template>
  68. <script>
  69. import { sendMessage } from '@/api/auditTaskProcessing'
  70. export default {
  71. name: 'MessageNoticeTab',
  72. props: {
  73. id: {
  74. type: String,
  75. default: '',
  76. },
  77. formData: {
  78. type: Array,
  79. default: () => [],
  80. },
  81. pagination: {
  82. type: Object,
  83. default: () => ({ currentPage: 1, pageSize: 10, total: 0 }),
  84. },
  85. selectedProject: {
  86. type: Object,
  87. default: () => ({}),
  88. },
  89. },
  90. data() {
  91. return {
  92. internalPagination: {
  93. currentPage: 1,
  94. pageSize: 10,
  95. total: 0,
  96. },
  97. localFormData: [],
  98. }
  99. },
  100. watch: {
  101. pagination: {
  102. handler(newVal) {
  103. if (newVal) {
  104. this.internalPagination = {
  105. currentPage: newVal.currentPage || 1,
  106. pageSize: newVal.pageSize || 10,
  107. total: newVal.total || 0,
  108. }
  109. }
  110. },
  111. immediate: true,
  112. deep: true,
  113. },
  114. formData: {
  115. handler(newVal) {
  116. this.localFormData = newVal || []
  117. },
  118. immediate: true,
  119. deep: true,
  120. },
  121. // id: {
  122. // handler(newVal) {
  123. // if (newVal) {
  124. // // 重置到第一页并重新加载
  125. // this.internalPagination.currentPage = 1
  126. // this.getNoticeList()
  127. // }
  128. // },
  129. // immediate: false,
  130. // },
  131. },
  132. mounted() {
  133. // 初始化分页数据
  134. // if (this.pagination) {
  135. // this.internalPagination = {
  136. // currentPage: this.pagination.currentPage || 1,
  137. // pageSize: this.pagination.pageSize || 10,
  138. // total: this.pagination.total || 0,
  139. // }
  140. // }
  141. // if (this.formData) {
  142. // this.localFormData = this.formData
  143. // }
  144. // this.getNoticeList()
  145. },
  146. methods: {
  147. // 处理页码变化
  148. handleCurrentChange(page) {
  149. this.internalPagination.currentPage = page
  150. this.getNoticeList()
  151. },
  152. // 处理每页条数变化
  153. handleSizeChange(size) {
  154. this.internalPagination.pageSize = size
  155. this.internalPagination.currentPage = 1 // 重置到第一页
  156. this.getNoticeList()
  157. },
  158. // 获取消息通知列表
  159. async getNoticeList() {
  160. // 检查是否有子项目
  161. if (
  162. !this.selectedProject ||
  163. !this.selectedProject.children ||
  164. !Array.isArray(this.selectedProject.children) ||
  165. this.selectedProject.children.length === 0
  166. ) {
  167. this.localFormData = []
  168. this.internalPagination.total = 0
  169. return
  170. }
  171. try {
  172. // 获取所有子项目(包含id和auditObject)
  173. const children = this.selectedProject.children.filter(
  174. (child) => child.id
  175. )
  176. // 为每个子项目发送请求,并保存对应的auditObject
  177. const promises = children.map((child) => {
  178. const params = {
  179. taskId: child.id,
  180. pageNum: this.internalPagination.currentPage,
  181. pageSize: this.internalPagination.pageSize,
  182. }
  183. // 发送请求并返回结果和对应的auditObject
  184. return sendMessage(params).then((res) => ({
  185. res,
  186. auditObject: child.auditObject,
  187. }))
  188. })
  189. // 并行处理所有请求
  190. const results = await Promise.all(promises)
  191. // 合并所有结果,并为每条记录添加auditObject
  192. let allRecords = []
  193. let totalCount = 0
  194. results.forEach(({ res, auditObject }) => {
  195. if (res && res.code === 200 && res.value) {
  196. // 为每条记录添加auditObject
  197. const recordsWithAuditObject = (res.value.records || []).map(
  198. (record) => ({
  199. ...record,
  200. auditObject,
  201. })
  202. )
  203. allRecords = allRecords.concat(recordsWithAuditObject)
  204. totalCount += res.value.total || 0
  205. }
  206. })
  207. // 更新表格数据
  208. this.localFormData = allRecords
  209. this.internalPagination.total = totalCount
  210. } catch (err) {
  211. console.error('获取消息通知失败', err)
  212. this.localFormData = []
  213. this.internalPagination.total = 0
  214. } finally {
  215. }
  216. },
  217. },
  218. }
  219. </script>
  220. <style scoped>
  221. /* 移除最外层容器的 padding */
  222. div {
  223. padding: 0;
  224. }
  225. </style>