messageNotify.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="message-notify-container">
  3. <el-table
  4. style="width: 100%; margin-top: 20px"
  5. border
  6. :data="localFormData"
  7. >
  8. <el-table-column prop="id" label="序号" width="120" align="center">
  9. <template slot-scope="scope">
  10. {{ scope.$index + 1 }}
  11. </template>
  12. </el-table-column>
  13. <el-table-column
  14. prop="noticeTitle"
  15. label="消息主题"
  16. width="200"
  17. align="center"
  18. ></el-table-column>
  19. <el-table-column
  20. prop="noticeSource"
  21. label="消息来源"
  22. width="220"
  23. align="center"
  24. show-overflow-tooltip
  25. ></el-table-column>
  26. <el-table-column
  27. prop="noticeContent"
  28. label="消息内容"
  29. min-width="350"
  30. header-align="center"
  31. align="left"
  32. show-overflow-tooltip
  33. ></el-table-column>
  34. <el-table-column
  35. prop="createTime"
  36. label="发送时间"
  37. width="100"
  38. align="center"
  39. ></el-table-column>
  40. </el-table>
  41. <el-pagination
  42. background
  43. layout="total, sizes, prev, pager, next"
  44. :current-page="internalPagination.currentPage"
  45. :page-sizes="[10, 20, 30, 50]"
  46. :page-size="internalPagination.pageSize"
  47. :total="internalPagination.total"
  48. style="margin-top: 20px; text-align: right"
  49. @current-change="handleCurrentChange"
  50. @size-change="handleSizeChange"
  51. />
  52. </div>
  53. </template>
  54. <script>
  55. import { sendMessage } from '@/api/auditTaskProcessing'
  56. export default {
  57. name: 'MessageNoticeTab',
  58. props: {
  59. id: {
  60. type: String,
  61. default: '',
  62. },
  63. formData: {
  64. type: Array,
  65. default: () => [],
  66. },
  67. pagination: {
  68. type: Object,
  69. default: () => ({ currentPage: 1, pageSize: 10, total: 0 }),
  70. },
  71. },
  72. data() {
  73. return {
  74. internalPagination: {
  75. currentPage: 1,
  76. pageSize: 10,
  77. total: 0,
  78. },
  79. localFormData: [],
  80. }
  81. },
  82. watch: {
  83. pagination: {
  84. handler(newVal) {
  85. if (newVal) {
  86. this.internalPagination = {
  87. currentPage: newVal.currentPage || 1,
  88. pageSize: newVal.pageSize || 10,
  89. total: newVal.total || 0,
  90. }
  91. }
  92. },
  93. immediate: true,
  94. deep: true,
  95. },
  96. formData: {
  97. handler(newVal) {
  98. this.localFormData = newVal || []
  99. },
  100. immediate: true,
  101. deep: true,
  102. },
  103. // id: {
  104. // handler(newVal) {
  105. // if (newVal) {
  106. // // 重置到第一页并重新加载
  107. // this.internalPagination.currentPage = 1
  108. // this.getNoticeList()
  109. // }
  110. // },
  111. // immediate: false,
  112. // },
  113. },
  114. mounted() {
  115. // 初始化分页数据
  116. // if (this.pagination) {
  117. // this.internalPagination = {
  118. // currentPage: this.pagination.currentPage || 1,
  119. // pageSize: this.pagination.pageSize || 10,
  120. // total: this.pagination.total || 0,
  121. // }
  122. // }
  123. // if (this.formData) {
  124. // this.localFormData = this.formData
  125. // }
  126. // this.getNoticeList()
  127. },
  128. methods: {
  129. // 处理页码变化
  130. handleCurrentChange(page) {
  131. this.internalPagination.currentPage = page
  132. this.getNoticeList()
  133. },
  134. // 处理每页条数变化
  135. handleSizeChange(size) {
  136. this.internalPagination.pageSize = size
  137. this.internalPagination.currentPage = 1 // 重置到第一页
  138. this.getNoticeList()
  139. },
  140. // 获取消息通知列表
  141. async getNoticeList() {
  142. if (!this.id) {
  143. return
  144. }
  145. this.$emit('update:loading', true)
  146. const params = {
  147. taskId: this.id,
  148. pageNum: this.internalPagination.currentPage,
  149. pageSize: this.internalPagination.pageSize,
  150. }
  151. try {
  152. const res = await sendMessage(params)
  153. console.log('消息通知123', res)
  154. if (res && res.code === 200 && res.value) {
  155. this.localFormData = res.value.records || []
  156. this.internalPagination.total = res.value.total || 0
  157. // 同步更新到父组件
  158. this.$emit('update:formData', res.value.records || [])
  159. this.$emit('update:pagination', {
  160. currentPage: this.internalPagination.currentPage,
  161. pageSize: this.internalPagination.pageSize,
  162. total: this.internalPagination.total,
  163. })
  164. } else {
  165. this.localFormData = []
  166. this.internalPagination.total = 0
  167. this.$emit('update:formData', [])
  168. this.$emit('update:pagination', {
  169. currentPage: this.internalPagination.currentPage,
  170. pageSize: this.internalPagination.pageSize,
  171. total: 0,
  172. })
  173. }
  174. } catch (err) {
  175. console.error('获取消息通知失败', err)
  176. this.localFormData = []
  177. this.internalPagination.total = 0
  178. this.$emit('update:formData', [])
  179. this.$emit('update:pagination', {
  180. currentPage: this.internalPagination.currentPage,
  181. pageSize: this.internalPagination.pageSize,
  182. total: 0,
  183. })
  184. } finally {
  185. this.$emit('update:loading', false)
  186. }
  187. },
  188. },
  189. }
  190. </script>
  191. <style scoped>
  192. /* 移除最外层容器的 padding */
  193. div {
  194. padding: 0;
  195. }
  196. </style>