index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <ContentWrap>
  3. <el-form ref="searchForm" :model="queryParms" :inline="true">
  4. <el-form-item label="公告标题">
  5. <el-input v-model="queryParms.title" />
  6. </el-form-item>
  7. <el-form-item label="状态">
  8. <el-select v-model="queryParms.status">
  9. <el-option label="全部" value="" />
  10. <el-option label="开启" :value="1" />
  11. <el-option label="关闭" :value="0" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" @click="getList">Query</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <div style="width: 100%; height: 600px">
  19. <el-auto-resizer>
  20. <template #default="{ height, width }">
  21. <el-table-v2
  22. :columns="columns"
  23. :data="tableData"
  24. :width="width"
  25. :height="height - 50"
  26. fixed
  27. />
  28. </template>
  29. </el-auto-resizer>
  30. </div>
  31. <div class="mt-2">
  32. <el-pagination
  33. :current-page="queryParms.pageNo"
  34. :page-size="queryParms.pageSize"
  35. layout="total, prev, pager, next"
  36. :total="tableTotal"
  37. @size-change="getList"
  38. @current-change="getList"
  39. />
  40. </div>
  41. </ContentWrap>
  42. </template>
  43. <script setup lang="tsx">
  44. import dayjs from 'dayjs'
  45. import { Column, ElPagination, ElTableV2, TableV2FixedDir } from 'element-plus'
  46. import * as NoticeApi from '@/api/system/notice'
  47. import { XTextButton } from '@/components/XButton'
  48. import { DictTag } from '@/components/DictTag'
  49. const { t } = useI18n() // 国际化
  50. const columns: Column<any>[] = [
  51. {
  52. key: 'id',
  53. dataKey: 'id', //需要渲染当前列的数据字段,如{id:9527,name:'Mike'},则填id
  54. title: 'id', //显示在单元格表头的文本
  55. width: 80, //当前列的宽度,必须设置
  56. fixed: true //是否固定列
  57. },
  58. {
  59. key: 'title',
  60. dataKey: 'title',
  61. title: '公告标题',
  62. width: 180
  63. },
  64. {
  65. key: 'type',
  66. dataKey: 'type',
  67. title: '公告类型',
  68. width: 180,
  69. cellRenderer: ({ cellData: type }) => (
  70. <DictTag type={DICT_TYPE.SYSTEM_NOTICE_TYPE} value={type}></DictTag>
  71. )
  72. },
  73. {
  74. key: 'status',
  75. dataKey: 'status',
  76. title: t('common.status'),
  77. width: 180,
  78. cellRenderer: ({ cellData: status }) => (
  79. <DictTag type={DICT_TYPE.COMMON_STATUS} value={status}></DictTag>
  80. )
  81. },
  82. {
  83. key: 'content',
  84. dataKey: 'content',
  85. title: '公告内容',
  86. width: 400,
  87. cellRenderer: ({ cellData: content }) => <span v-html={content}></span>
  88. },
  89. {
  90. key: 'createTime',
  91. dataKey: 'createTime',
  92. title: t('common.createTime'),
  93. width: 180,
  94. cellRenderer: ({ cellData: createTime }) => (
  95. <>{dayjs(createTime).format('YYYY-MM-DD HH:mm:ss')}</>
  96. )
  97. },
  98. {
  99. key: 'actionbtns',
  100. dataKey: 'actionbtns', //需要渲染当前列的数据字段,如{id:9527,name:'Mike'},则填id
  101. title: '操作', //显示在单元格表头的文本
  102. width: 160, //当前列的宽度,必须设置
  103. fixed: TableV2FixedDir.RIGHT, //是否固定列
  104. align: 'center',
  105. cellRenderer: ({ cellData: id }) => (
  106. <>
  107. <XTextButton
  108. preIcon="ep:delete"
  109. title={t('action.edit')}
  110. onClick={handleUpdate.bind(this, id)}
  111. ></XTextButton>
  112. <XTextButton
  113. preIcon="ep:delete"
  114. title={t('action.del')}
  115. onClick={handleDelete.bind(this, id)}
  116. ></XTextButton>
  117. </>
  118. )
  119. }
  120. ]
  121. const tableData = ref([])
  122. const tableTotal = ref(0)
  123. const queryParms = reactive({
  124. title: '',
  125. status: undefined,
  126. pageNo: 1,
  127. pageSize: 100
  128. })
  129. const getList = async () => {
  130. const res = await NoticeApi.getNoticePageApi(queryParms)
  131. tableData.value = res.list
  132. tableTotal.value = res.total
  133. }
  134. const handleUpdate = (id) => {
  135. console.info(id)
  136. }
  137. const handleDelete = (id) => {
  138. console.info(id)
  139. }
  140. getList()
  141. </script>