index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!-- 通知公告-资讯管理 -->
  2. <template>
  3. <app-view>
  4. <template #header>
  5. <app-filter :option="filterOption">
  6. <template #userid="{ item }">
  7. <el-form-item :label="item.label">
  8. <app-select-investor v-model="item.value" />
  9. </el-form-item>
  10. </template>
  11. </app-filter>
  12. </template>
  13. <app-table :data="dataList" :columns="tableColumns" :loading="loading">
  14. <template #headerLeft>
  15. <app-operation :data-list="getActionButtons(['notice_news_add'])"
  16. @click="(code: string) => openComponent(code)" />
  17. </template>
  18. <!-- 操作 -->
  19. <template #operate="{ row }">
  20. <app-operation size="small" :data-list="handleOperateButtons(row)"
  21. @click="(code: string) => openComponent(code, row)" circle />
  22. </template>
  23. <template #footer>
  24. <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
  25. @change="onSearch" />
  26. </template>
  27. </app-table>
  28. <component :is="componentMap.get(componentId)" v-bind="{ record }" @closed="closeComponent"
  29. v-if="componentId" />
  30. </app-view>
  31. </template>
  32. <script lang="ts" setup>
  33. import { shallowRef } from 'vue'
  34. import { ElMessage } from 'element-plus'
  35. import { formatDate } from '@/filters'
  36. import { Language } from '@/constants/language'
  37. import { useDataFilter } from '@/hooks/datatable-v2'
  38. import { useRequest } from '@/hooks/request'
  39. import { useOperation } from '@/hooks/operation'
  40. import { useEnum } from '@/hooks/enum'
  41. import { informManquery, informManinit } from '@/services/api/notice'
  42. import { i18n } from '@/stores'
  43. import AppTable from '@pc/components/base/table/index.vue'
  44. import AppPagination from '@pc/components/base/pagination/index.vue'
  45. import AppOperation from '@pc/components/base/operation/index.vue'
  46. import AppFilter from '@pc/components/base/table-filter-v2/index.vue'
  47. import AppSelectInvestor from '@pc/components/modules/select-investor/index.vue'
  48. const { global: { t } } = i18n
  49. const flagEnum = useEnum('flag')
  50. const columnDetailStatusEnum = useEnum('columndetail_status') // 状态
  51. const { componentMap, componentId, record, openComponent, closeComponent, getActionButtons } = useOperation<Notice.InformManqueryRsp>({
  52. onClose: () => onSearch()
  53. })
  54. const { data } = useRequest(informManinit)
  55. const { dataList, total, pageSize, pageIndex, loading, run } = useRequest(informManquery, {
  56. defaultParams: {
  57. pageNum: 1,
  58. pageSize: 20
  59. },
  60. onSuccess: (res) => {
  61. dataList.value = res.data.map((e) => {
  62. const localizedProperties = {
  63. [Language.Simplified]: { title: e.title, author: e.author, columnname: e.columnname, srcname: e.srcname },
  64. [Language.English]: { title: e.titleen, author: e.authoren, columnname: e.columnnameen, srcname: e.srcnameen },
  65. [Language.Thai]: { title: e.titleth, author: e.authorth, columnname: e.columnnameth, srcname: e.srcnameth },
  66. [Language.Traditional]: { title: e.titletw, author: e.authortw, columnname: e.columnnametw, srcname: e.srcnametw },
  67. [Language.Vietnamese]: { title: e.titlevi, author: e.authorvi, columnname: e.columnnamevi, srcname: e.srcnamevi },
  68. }
  69. return {
  70. ...e,
  71. ...localizedProperties[i18n.global.locale] // 本地化语言
  72. }
  73. })
  74. },
  75. onError: (err) => {
  76. ElMessage.error(err)
  77. }
  78. })
  79. const tableColumns = shallowRef<Model.TableColumn[]>([
  80. { field: 'columnname', label: 'notice.news.columnname' },
  81. { field: 'title', label: 'notice.news.title' },
  82. { field: 'srcname', label: 'notice.news.srcname' },
  83. { field: 'author', label: 'notice.news.author' },
  84. { field: 'istop', label: 'notice.news.istop', formatValue: (val) => flagEnum.getEnumTypeName(val) },
  85. { field: 'isshow', label: 'notice.news.isshow', formatValue: (val) => flagEnum.getEnumTypeName(val) },
  86. { field: 'publishdate', label: 'notice.news.publishdate', formatValue: (val) => formatDate(val, 'YYYY-MM-DD') },
  87. { field: 'status', label: 'notice.news.status', formatValue: (val) => columnDetailStatusEnum.getEnumTypeName(val) },
  88. { field: 'creatoruser', label: 'notice.news.creatoruser' },
  89. { field: 'creaedate', label: 'notice.news.creaedate', formatValue: (val) => formatDate(val) },
  90. { field: 'operate', label: 'common.operate', fixed: 'right', width: 180 }
  91. ])
  92. const { filterOption, getQueryParams, resetFilters } = useDataFilter<Notice.InformManqueryReq>({
  93. filters: [
  94. {
  95. field: 'columnid',
  96. label: t('notice.news.columnid'),
  97. options: () => data.value?.siteColumnconfig.map((e) => ({
  98. label: e.columnname,
  99. value: e.id
  100. })) ?? []
  101. },
  102. {
  103. field: 'status',
  104. label: t('notice.news.status'),
  105. options: () => columnDetailStatusEnum.getEnumOptions()
  106. },
  107. {
  108. field: 'title',
  109. label: t('notice.news.title')
  110. },
  111. {
  112. field: 'isshow',
  113. label: t('notice.news.isshow'),
  114. options: () => flagEnum.getEnumOptions()
  115. },
  116. ],
  117. buttons: [
  118. { label: t('operation.search'), className: 'el-button--primary', onClick: () => onSearch() },
  119. { label: t('operation.reset'), className: 'el-button--primary', validateEvent: false, onClick: () => resetFilters() }
  120. ]
  121. })
  122. // 处理操作按钮
  123. const handleOperateButtons = (row: Notice.InformManqueryRsp) => {
  124. const buttons = ['notice_news_details', 'notice_news_delete']
  125. if (row.status === 10) {
  126. buttons.push('notice_news_audit')
  127. } else {
  128. buttons.push('notice_news_modify')
  129. if (row.status !== 1) {
  130. if (row.isshow) {
  131. buttons.push('notice_news_show')
  132. } else {
  133. buttons.push('notice_news_hide')
  134. }
  135. }
  136. }
  137. return getActionButtons(buttons)
  138. }
  139. const onSearch = () => {
  140. const qs = getQueryParams()
  141. run(qs)
  142. }
  143. </script>