MenuTable.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <script setup lang="ts">
  2. import type { BaseMenu } from '@/types/Promotion/Menu'
  3. import type { CustomIndicatorScheme } from '@/types/Tables/table'
  4. import type { BaseTableInfo } from '@/types/Tables/tablePageData'
  5. import type { MenuTableReq } from '@/types/Tables/MenuTable/menuTableReq'
  6. import type { TablePaginationProps } from '@/types/Tables/pagination'
  7. import Menu from '../navigation/Menu.vue'
  8. import Table from '../table/Table.vue'
  9. import { useMenuTable } from '@/hooks/useMenuTable'
  10. import { computed, onMounted, ref } from 'vue'
  11. import { useDate } from '@/hooks/useDate'
  12. import TableCustomIndicatorController from '@/utils/localStorage/tableCustomIndicatorController'
  13. import type { Operations } from '@/types/Tables/Operations/operations'
  14. // 自定义表格的类型
  15. type TableType = InstanceType<typeof Table>
  16. interface MenuTableProps {
  17. saveTableName: string // 保存的表格的名称,后面会拼接上每个菜单的名,这个主要用于保存自定义指标方案
  18. menuList: BaseMenu[] // 菜单列表
  19. menuDefaultActive: string // 菜单默认选中
  20. tableInfo: BaseTableInfo // 表格信息
  21. tableReqInfo: MenuTableReq // 每个菜单的数据请求格式
  22. tablePaginationConfig: TablePaginationProps // 表格分页配置
  23. operations: Operations // 表格中需要进行的操作,会被直接添加到操作列,作为按钮存在
  24. excludeFields?: {
  25. [key: string]: string[]
  26. } // 排除的字段
  27. }
  28. const { disableDate, shortcuts } = useDate()
  29. // props
  30. const props = withDefaults(defineProps<MenuTableProps>(), {
  31. excludeFields: () => ({}),
  32. })
  33. // 表格ref
  34. const tableRef = ref<TableType | null>(null)
  35. // 当前菜单选中
  36. const activeMenu = ref(props.menuDefaultActive)
  37. // 自定义指标保存的方案
  38. const customIndicatorScheme = ref<Array<CustomIndicatorScheme>>([])
  39. // 每个表格的自定义方案的IO控制器
  40. const tableControllers: {
  41. [key: string]: TableCustomIndicatorController
  42. } = {}
  43. // 选择的日期
  44. const selectDate = ref<Array<Date>>(shortcuts[0].value)
  45. // 修改或新增的弹窗控制
  46. const operationDialog = ref<boolean>(false)
  47. /**
  48. * @description: 保存的文件名
  49. * @return {*}
  50. */
  51. const fileName = computed(() => {
  52. return `${props.saveTableName}-${activeMenu.value}`
  53. })
  54. /**
  55. * @description: 日期改变
  56. * @param {*} newDate 新的日期
  57. * @return {*}
  58. */
  59. const dateChange = (newDate: Array<Date>) => {
  60. emits('changeDate', newDate)
  61. }
  62. /**
  63. * @description: 打开操作弹窗
  64. * @return {*}
  65. */
  66. const openOperationDialog = () => {
  67. operationDialog.value = true
  68. }
  69. /**
  70. * @description: 查询表格
  71. * @param {*} params 请求参数
  72. * @return {*}
  73. */
  74. const queryTable = (params: any) => {
  75. props.tableReqInfo[activeMenu.value].config.params = params
  76. updateTableData()
  77. }
  78. const {
  79. menuActiveChange,
  80. changeScheme,
  81. updateCustomIndicator,
  82. initData,
  83. updateTableData,
  84. } = useMenuTable(
  85. props.saveTableName,
  86. fileName,
  87. activeMenu,
  88. customIndicatorScheme,
  89. tableControllers,
  90. props.tableInfo,
  91. props.tableReqInfo,
  92. props.tablePaginationConfig,
  93. tableRef,
  94. props.menuList,
  95. )
  96. const emits = defineEmits(['changeDate'])
  97. onMounted(() => {
  98. initData()
  99. })
  100. </script>
  101. <template>
  102. <div class="menuTableContainer">
  103. <div class="menuTableHeader">
  104. <Menu
  105. :default-active="'account'"
  106. :menu-list="menuList"
  107. :menu-item-style="'margin-right:30px;'"
  108. mode="horizontal"
  109. @active-change="menuActiveChange"
  110. ></Menu>
  111. <div class="datePickerBox">
  112. <el-date-picker
  113. class="datePicker"
  114. v-model="selectDate"
  115. :disabled-date="disableDate"
  116. :unlink-panels="false"
  117. @change="dateChange"
  118. type="daterange"
  119. range-separator="至"
  120. start-placeholder="Start date"
  121. end-placeholder="End date"
  122. :shortcuts="shortcuts"
  123. :size="'small'"
  124. :clearable="false"
  125. >
  126. </el-date-picker>
  127. </div>
  128. </div>
  129. <div class="menuTableContent">
  130. <Table
  131. ref="tableRef"
  132. :active-menu="activeMenu"
  133. :pagination-config="tablePaginationConfig"
  134. :table-fields="tableInfo[activeMenu].fields"
  135. :sorted-table-fields="tableInfo[activeMenu].tableSortedFields"
  136. :table-data="tableInfo[activeMenu].data"
  137. :fixed-fields="tableInfo[activeMenu].fixedFields"
  138. :filters-info="tableInfo[activeMenu].filters"
  139. :scheme-list="customIndicatorScheme"
  140. :exclude-export-fields="props.excludeFields[activeMenu]"
  141. @update-custom-indicator="updateCustomIndicator"
  142. @change-scheme="changeScheme"
  143. @query-table="queryTable"
  144. >
  145. <template #operations>
  146. <div>
  147. <el-button
  148. text
  149. :type="item.type"
  150. v-for="item in operations[activeMenu]"
  151. @click="openOperationDialog"
  152. >
  153. {{ item.label }}
  154. </el-button>
  155. </div>
  156. </template>
  157. </Table>
  158. </div>
  159. <el-dialog
  160. v-model="operationDialog"
  161. :align-center="true"
  162. title="Tips"
  163. width="500"
  164. >
  165. <slot name="operationDialog">
  166. <span>This is a message</span>
  167. </slot>
  168. </el-dialog>
  169. </div>
  170. </template>
  171. <style scoped>
  172. .menuTableContainer {
  173. width: 100%;
  174. height: 100%;
  175. overflow: hidden;
  176. }
  177. .menuTableHeader {
  178. width: 100%;
  179. border-bottom: 1px solid #e0e0e0;
  180. background-color: white;
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: center;
  184. }
  185. .menuTableContent {
  186. width: 100%;
  187. height: 100%;
  188. background-color: white;
  189. margin: 0 auto;
  190. overflow: hidden;
  191. }
  192. .datePickerBox {
  193. /* width: 100px !important; */
  194. margin-left: auto;
  195. margin-right: 5%;
  196. }
  197. </style>