index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class="ma-content-block">
  3. <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm" @search="handleRequestData">
  4. <!-- 搜索区 tableSearch -->
  5. <template #tableSearch>
  6. <a-col :sm="8" :xs="24">
  7. <a-form-item label="游戏" field="game_id">
  8. <game-select v-model="searchForm.game_id" multiple />
  9. </a-form-item>
  10. </a-col>
  11. <a-col :sm="8" :xs="24">
  12. <a-form-item label="注册日期" field="reg_date">
  13. <a-range-picker class="w-full" v-model="searchForm.reg_date" :show-time="false" mode="date" />
  14. </a-form-item>
  15. </a-col>
  16. </template>
  17. <!-- Table 自定义渲染 -->
  18. </sa-table>
  19. </div>
  20. </template>
  21. <script setup>
  22. import { onMounted, ref, reactive, nextTick } from 'vue'
  23. import api from '../../api/gameLog/analyse'
  24. import dayjs from 'dayjs'
  25. import commonApi from '../../api/common'
  26. import GameSelect from '@/components/game-select/index.vue'
  27. // 引用定义
  28. const crudRef = ref()
  29. const gameList = ref([])
  30. // 搜索表单
  31. const searchForm = ref({
  32. game_id: '',
  33. media_id: '',
  34. auth_id: '',
  35. agent_id: '',
  36. site_id: '',
  37. reg_date: [],
  38. })
  39. // SaTable 基础配置
  40. const options = reactive({
  41. api: api.getRegDayDataList,
  42. pk: 'id',
  43. rowSelection: { showCheckedAll: true },
  44. showSummary: true,
  45. operationColumn: false,
  46. showSort: false,
  47. summary: [],
  48. })
  49. // SaTable 列配置
  50. const columns = ref([])
  51. // 页面数据初始化
  52. const initPage = async () => {
  53. searchForm.value.reg_date = [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
  54. await getGameList()
  55. }
  56. // 获取游戏列表
  57. const getGameList = async () => {
  58. const res = await commonApi.getGameListTreeApi()
  59. if (res.code === 200) {
  60. gameList.value = res.data
  61. }
  62. }
  63. // SaTable 数据请求
  64. const refresh = async () => {
  65. crudRef.value?.refresh()
  66. }
  67. const handleRequestData = () => {
  68. // 使用 nextTick 确保在 DOM 更新后再获取数据
  69. nextTick(() => {
  70. const res = crudRef.value.getResponseData()
  71. console.log('完整的响应数据:', res)
  72. console.log('totalRow 数据:', res?.totalRow)
  73. // 重新添加动态列,并为每一列添加合计配置
  74. if (res && res.columns && Array.isArray(res.columns)) {
  75. columns.value = res.columns
  76. console.log('columns updated:', columns.value)
  77. // 动态生成 summary 配置,dataIndex 与 columns 保持一致
  78. if (Array.isArray(res.columns)) {
  79. // 只对数值类型的列添加合计
  80. const numericColumns = res.columns.filter((col) => {
  81. // 排除日期、文本等非数值列
  82. const excludeFields = ['reg_date', 'date', 'time', 'name', 'title', 'description', 'game_id', 'game_name']
  83. return !excludeFields.includes(col.dataIndex)
  84. })
  85. // 清空并重新设置 summary 配置
  86. options.summary.length = 0
  87. numericColumns.forEach((col) => {
  88. options.summary.push({
  89. action: 'totalRow',
  90. dataIndex: col.dataIndex,
  91. })
  92. })
  93. console.log('summary config:', options.summary)
  94. console.log(
  95. 'numeric columns:',
  96. numericColumns.map((col) => col.dataIndex)
  97. )
  98. console.log('options.summary length:', options.summary.length)
  99. }
  100. }
  101. })
  102. }
  103. // 页面加载完成执行
  104. onMounted(async () => {
  105. await initPage()
  106. // 设置一些默认列,以防API没有返回列信息
  107. if (columns.value.length === 0) {
  108. columns.value = [
  109. { title: '注册日期', dataIndex: 'reg_date', width: 120 },
  110. { title: '注册数', dataIndex: 'reg_count', width: 100 },
  111. ]
  112. }
  113. refresh()
  114. })
  115. </script>