notice.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('News.Notice')" />
  4. <view class="info-card">
  5. <view class="search-bar">
  6. <cwg-combox v-model:value="search.read" :options="readOptions"
  7. :placeholder="t('Custom.PaymentHistory.StatusPlaceholder')" />
  8. </view>
  9. <cwg-tabel ref="tableRef" :columns="columns" :mobilePrimaryFields="mobilePrimaryFields"
  10. :queryParams="search" :api="listApi" @go-pages="goPages" :isPages="true" :immediate="true">
  11. <template #status="{ row }">
  12. <text class="status-tag" :class="getStatusColor(row.read)">{{readOptions.find(item => item.value === row.read)?.text}}</text>
  13. </template>
  14. </cwg-tabel>
  15. </view>
  16. </cwg-page-wrapper>
  17. </template>
  18. <script setup lang="ts">
  19. import { computed, ref, watch } from 'vue';
  20. import { useI18n } from 'vue-i18n';
  21. const { t, locale } = useI18n();
  22. import { newsApi } from '@/service/news';
  23. import {
  24. onShow,
  25. onHide
  26. } from '@dcloudio/uni-app'
  27. import useRouter from "@/hooks/useRouter";
  28. const router = useRouter();
  29. const search = ref({
  30. read: null,
  31. lang: locale.value
  32. })
  33. const readOptions = computed(() => [
  34. { value: null, text: t('State.All') },
  35. { value: 0, text: t('News.Unread') },
  36. { value: 1, text: t('News.Read') }
  37. ]);
  38. const tableRef = ref(null)
  39. watch(locale, () => {
  40. search.value.lang = locale.value
  41. tableRef.value?.reload()
  42. })
  43. watch(search, (newVal) => {
  44. tableRef.value?.reload()
  45. }, { immediate: true, deep: true })
  46. onShow(()=>{
  47. // console.log('show')
  48. // console.log(tableRef.value)
  49. tableRef.value?.reload()
  50. })
  51. // 表格列配置(支持插槽和格式化)
  52. const columns = computed(() => [
  53. {
  54. prop: 'subject',
  55. label: t('News.Title'),
  56. align: 'left',
  57. slot: 'subject' // 使用插槽自定义标题点击
  58. },
  59. {
  60. prop: 'addTime',
  61. label: t('Drawer.Label.Date'),
  62. align: 'center',
  63. formatter: ({ row }) => row.addTime || '--'
  64. },
  65. {
  66. prop: 'read',
  67. label: t('Custom.Recording.Status'),
  68. align: 'center',
  69. slot: 'status' // 使用插槽显示未读/已读状态
  70. },
  71. // {
  72. // prop: 'more',
  73. // type: 'more',
  74. // width: 20,
  75. // align: 'right'
  76. // },
  77. ])
  78. const mobilePrimaryFields = ref([
  79. {
  80. prop: 'subject',
  81. label: t('News.Title'),
  82. align: 'left',
  83. slot: 'subject' // 使用插槽自定义标题点击
  84. },
  85. {
  86. prop: 'addTime',
  87. label: t('Drawer.Label.Date'),
  88. align: 'center',
  89. formatter: ({ row }) => row.addTime || '--'
  90. },
  91. {
  92. prop: 'read',
  93. label: t('Custom.Recording.Status'),
  94. align: 'right',
  95. slot: 'status' // 使用插槽显示未读/已读状态
  96. },
  97. {
  98. prop: 'more',
  99. type: 'more',
  100. width: 20,
  101. align: 'right'
  102. },
  103. ])
  104. const getStatusColor = (value) => {
  105. const classMap= {
  106. 0: 'status-pending',
  107. 1: 'status-cancelled',
  108. }
  109. return classMap[value] || ''
  110. }
  111. const goPages = (e) => {
  112. // tableRef.value?.refreshTable()
  113. router.push({
  114. path: '/pages/analytics/detail',
  115. query: {
  116. id: e.id,
  117. type: 7
  118. }
  119. })
  120. }
  121. const listApi = ref(null)
  122. listApi.value = newsApi.newsNoticeList
  123. </script>
  124. <style scoped lang="scss">
  125. @import "@/uni.scss";
  126. .avatar {
  127. width: px2rpx(60);
  128. height: px2rpx(60);
  129. border-radius: 4px;
  130. }
  131. .content-title {
  132. display: flex;
  133. justify-content: space-between;
  134. align-items: center;
  135. font-size: px2rpx(20);
  136. font-weight: 500;
  137. .content-title-btns {
  138. margin: px2rpx(8) 0;
  139. display: flex;
  140. align-items: center;
  141. justify-content: center;
  142. gap: px2rpx(12);
  143. .btn-primary {
  144. min-width: px2rpx(120);
  145. background-color: var(--color-error);
  146. color: white;
  147. padding: 0 px2rpx(12);
  148. border: none;
  149. font-size: px2rpx(14);
  150. text-align: center;
  151. cursor: pointer;
  152. display: flex;
  153. align-items: center;
  154. justify-content: center;
  155. gap: px2rpx(8);
  156. }
  157. .btn-primary:active {
  158. background-color: #cf1322;
  159. ;
  160. }
  161. }
  162. }
  163. .operation-btn {
  164. :deep(span) {
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. gap: px2rpx(4);
  169. cursor: pointer;
  170. background-color: var(--color-slate-150);
  171. padding: px2rpx(8) 0;
  172. }
  173. }
  174. .operation-btn.disabled {
  175. cursor: not-allowed;
  176. opacity: 0.5;
  177. }
  178. .search-bar {
  179. display: flex;
  180. align-items: center;
  181. justify-content: flex-start;
  182. flex-wrap: wrap;
  183. gap: px2rpx(16);
  184. margin: px2rpx(16) 0;
  185. .cwg-combox,
  186. .uni-easyinput,
  187. .uni-date {
  188. width: px2rpx(240) !important;
  189. flex: none;
  190. }
  191. }
  192. </style>