zyf-model-engine 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/build/getEnv.d.ts +13 -0
  2. package/build/plugins.d.ts +7 -0
  3. package/build/proxy.d.ts +11 -0
  4. package/index.html +2 -100
  5. package/manifest.webmanifest +1 -0
  6. package/package.json +3 -94
  7. package/registerSW.js +1 -0
  8. package/src/api/config/servicePort.d.ts +2 -0
  9. package/src/api/enums/httpEnum.d.ts +29 -0
  10. package/src/api/helper/axiosCancel.d.ts +21 -0
  11. package/src/api/helper/axiosFileCancel.d.ts +27 -0
  12. package/src/api/helper/checkStatus.d.ts +6 -0
  13. package/src/api/index.d.ts +26 -0
  14. package/src/api/interface/index.d.ts +18 -0
  15. package/src/components/CTree/interface/index.d.ts +6 -0
  16. package/src/components/Grid/interface/index.d.ts +5 -0
  17. package/src/components/ProTable/interface/index.d.ts +66 -0
  18. package/src/config/index.d.ts +5 -0
  19. package/src/config/nprogress.d.ts +3 -0
  20. package/src/config/piniaPersist.d.ts +10 -0
  21. package/src/config/serviceLoading.d.ts +5 -0
  22. package/src/enums/httpEnum.d.ts +19 -0
  23. package/src/hooks/interface/index.d.ts +30 -0
  24. package/src/hooks/useOnline.d.ts +6 -0
  25. package/src/hooks/useTable.d.ts +47 -0
  26. package/src/main.d.ts +1 -0
  27. package/src/stores/commonStore.d.ts +2 -0
  28. package/src/stores/index.d.ts +2 -0
  29. package/src/stores/interface/index.d.ts +1 -0
  30. package/src/utils/color.d.ts +28 -0
  31. package/src/utils/commonUtils.d.ts +63 -0
  32. package/src/utils/errorHandler.d.ts +5 -0
  33. package/src/utils/is.d.ts +82 -0
  34. package/src/utils/layoutUtils.d.ts +44 -0
  35. package/src/utils/localUtils.d.ts +24 -0
  36. package/src/utils/serviceDict.d.ts +7 -0
  37. package/style.css +1 -0
  38. package/sw.js +1 -0
  39. package/vite.config.d.ts +2 -0
  40. package/workbox-3e911b1d.js +1 -0
  41. package/zyf-model-engine.mjs +45118 -0
  42. package/zyf-model-engine.umd.js +81 -0
  43. package/.editorconfig +0 -15
  44. package/.env +0 -13
  45. package/.env.development +0 -20
  46. package/.env.production +0 -25
  47. package/.env.test +0 -25
  48. package/.eslintignore +0 -15
  49. package/.eslintrc-auto-import.json +0 -65
  50. package/.eslintrc.cjs +0 -66
  51. package/.husky/commit-msg +0 -4
  52. package/.husky/pre-commit +0 -5
  53. package/.prettierignore +0 -9
  54. package/.prettierrc.cjs +0 -41
  55. package/.stylelintignore +0 -4
  56. package/.stylelintrc.cjs +0 -40
  57. package/.vscode/extensions.json +0 -14
  58. package/.vscode/settings.json +0 -92
  59. package/CHANGELOG.md +0 -246
  60. package/LICENSE +0 -21
  61. package/README.md +0 -205
  62. package/auto-imports.d.ts +0 -132
  63. package/build/getEnv.ts +0 -46
  64. package/build/plugins.ts +0 -138
  65. package/build/proxy.ts +0 -28
  66. package/commitlint.config.cjs +0 -84
  67. package/components.d.ts +0 -28
  68. package/lint-staged.config.cjs +0 -8
  69. package/postcss.config.cjs +0 -5
  70. package/src/App.vue +0 -16
  71. package/src/api/config/servicePort.ts +0 -3
  72. package/src/api/enums/httpEnum.ts +0 -35
  73. package/src/api/helper/axiosCancel.ts +0 -50
  74. package/src/api/helper/axiosFileCancel.ts +0 -62
  75. package/src/api/helper/checkStatus.ts +0 -97
  76. package/src/api/index.ts +0 -142
  77. package/src/api/interface/index.ts +0 -27
  78. package/src/assets/global-icons/icon-demo.svg +0 -1
  79. package/src/assets/iconfont/iconfont.scss +0 -44
  80. package/src/assets/iconfont/iconfont.ttf +0 -0
  81. package/src/assets/images/empty-img.png +0 -0
  82. package/src/assets/option-icons/add.svg +0 -1
  83. package/src/assets/option-icons/check.svg +0 -1
  84. package/src/assets/option-icons/config.svg +0 -1
  85. package/src/assets/option-icons/del.svg +0 -1
  86. package/src/assets/option-icons/detail.svg +0 -1
  87. package/src/assets/option-icons/edit.svg +0 -2
  88. package/src/assets/option-icons/export.svg +0 -1
  89. package/src/assets/option-icons/folder.svg +0 -1
  90. package/src/assets/option-icons/full-screen.svg +0 -1
  91. package/src/assets/option-icons/more.svg +0 -1
  92. package/src/assets/option-icons/return.svg +0 -1
  93. package/src/assets/option-icons/search.svg +0 -1
  94. package/src/components/CSvgIcon/index.scss +0 -23
  95. package/src/components/CSvgIcon/index.vue +0 -74
  96. package/src/components/CTree/index.scss +0 -48
  97. package/src/components/CTree/index.vue +0 -176
  98. package/src/components/CTree/interface/index.ts +0 -6
  99. package/src/components/Dialog/index.scss +0 -74
  100. package/src/components/Dialog/index.vue +0 -87
  101. package/src/components/Empty/index.scss +0 -16
  102. package/src/components/Empty/index.vue +0 -43
  103. package/src/components/Grid/components/GridItem.vue +0 -68
  104. package/src/components/Grid/index.vue +0 -167
  105. package/src/components/Grid/interface/index.ts +0 -6
  106. package/src/components/Loading/index.scss +0 -67
  107. package/src/components/Loading/index.vue +0 -13
  108. package/src/components/Overflow/index.vue +0 -76
  109. package/src/components/ProTable/components/ColSetting.vue +0 -45
  110. package/src/components/ProTable/components/Pagination.vue +0 -29
  111. package/src/components/ProTable/components/SearchForm/components/SearchFormItem.vue +0 -93
  112. package/src/components/ProTable/components/SearchForm/index.scss +0 -12
  113. package/src/components/ProTable/components/SearchForm/index.vue +0 -91
  114. package/src/components/ProTable/components/TableColumn.vue +0 -56
  115. package/src/components/ProTable/index.scss +0 -14
  116. package/src/components/ProTable/index.vue +0 -274
  117. package/src/components/ProTable/interface/index.ts +0 -86
  118. package/src/components/ScrollBox/index.vue +0 -44
  119. package/src/components/SvgIcon/index.vue +0 -20
  120. package/src/components/Tabs/index.vue +0 -142
  121. package/src/config/index.ts +0 -12
  122. package/src/config/nprogress.ts +0 -12
  123. package/src/config/piniaPersist.ts +0 -19
  124. package/src/config/serviceLoading.ts +0 -45
  125. package/src/enums/httpEnum.ts +0 -24
  126. package/src/hooks/interface/index.ts +0 -32
  127. package/src/hooks/useOnline.ts +0 -27
  128. package/src/hooks/useTable.ts +0 -167
  129. package/src/main.ts +0 -35
  130. package/src/plugins/button/button.vue +0 -56
  131. package/src/plugins/index.js +0 -26
  132. package/src/plugins/index.vue +0 -24
  133. package/src/plugins/msg/msg.vue +0 -56
  134. package/src/stores/commonStore.ts +0 -9
  135. package/src/stores/index.ts +0 -8
  136. package/src/stores/interface/index.ts +0 -1
  137. package/src/styles/common.scss +0 -87
  138. package/src/styles/element.scss +0 -233
  139. package/src/styles/reset.scss +0 -20
  140. package/src/styles/var.scss +0 -2
  141. package/src/typings/global.d.ts +0 -37
  142. package/src/typings/window.d.ts +0 -8
  143. package/src/utils/color.ts +0 -59
  144. package/src/utils/commonUtils.ts +0 -175
  145. package/src/utils/errorHandler.ts +0 -28
  146. package/src/utils/is.ts +0 -147
  147. package/src/utils/layoutUtils.ts +0 -83
  148. package/src/utils/localUtils.ts +0 -42
  149. package/src/utils/serviceDict.ts +0 -9
  150. package/src/vite-env.d.ts +0 -6
  151. package/tsconfig.json +0 -50
  152. package/vite.config.ts +0 -76
  153. /package/{public/logo.png → logo.png} +0 -0
@@ -1,93 +0,0 @@
1
- <template>
2
- <component
3
- :is="_column.search?.render ?? `el-${_column.search?.el}`"
4
- v-bind="{ ...handleSearchProps, ...placeholder, searchParam: _searchParam, clearable }"
5
- v-model.trim="_searchParam[_column.search?.key ?? handleProp(_column.prop!)]"
6
- :data="_column.search?.el === 'tree-select' ? columnEnum : []"
7
- :options="['cascader', 'select-v2'].includes(_column.search?.el!) ? columnEnum : []"
8
- >
9
- <template v-if="_column.search?.el === 'cascader'" #default="{ data }">
10
- <span>{{ data[fieldNames.label] }}</span>
11
- </template>
12
- <template v-if="_column.search?.el === 'select'">
13
- <component
14
- :is="`el-option`"
15
- v-for="(col, index) in columnEnum"
16
- :key="index"
17
- :label="col[fieldNames.label]"
18
- :value="col[fieldNames.value]"
19
- ></component>
20
- </template>
21
- <slot v-else></slot>
22
- </component>
23
- </template>
24
-
25
- <script setup lang="ts" name="SearchFormItem">
26
- import { computed, inject, ref } from "vue";
27
- import { handleProp } from "@/utils/layoutUtils";
28
- import { ColumnProps } from "@/components/ProTable/interface";
29
-
30
- interface SearchFormItem {
31
- column: ColumnProps;
32
- searchParam: { [key: string]: any };
33
- }
34
- const props = defineProps<SearchFormItem>();
35
-
36
- // Re receive SearchParam
37
- const _searchParam = computed(() => props.searchParam);
38
- const _column = computed(() => props.column);
39
-
40
- // 判断 fieldNames 设置 label && value && children 的 key 值
41
- const fieldNames = computed(() => {
42
- return {
43
- label: props.column.fieldNames?.label ?? "name",
44
- value: props.column.fieldNames?.value ?? "id",
45
- children: props.column.fieldNames?.children ?? "children"
46
- };
47
- });
48
-
49
- // 接收 enumMap (el 为 select-v2 需单独处理 enumData)
50
- const enumMap = inject("enumMap", ref(new Map()));
51
- const columnEnum = computed(() => {
52
- let enumData = enumMap.value.get(props.column.prop);
53
- if (!enumData) return [];
54
- if (props.column.search?.el === "select-v2" && props.column.fieldNames) {
55
- enumData = enumData.map((item: { [key: string]: any }) => {
56
- return { ...item, label: item[fieldNames.value.label], value: item[fieldNames.value.value] };
57
- });
58
- }
59
- return enumData;
60
- });
61
-
62
- // 处理透传的 searchProps (el 为 tree-select、cascader 的时候需要给下默认 label && value && children)
63
- const handleSearchProps = computed(() => {
64
- const label = fieldNames.value.label;
65
- const value = fieldNames.value.value;
66
- const children = fieldNames.value.children;
67
- const searchEl = props.column.search?.el;
68
- let searchProps = props.column.search?.props ?? {};
69
- if (searchEl === "tree-select") {
70
- searchProps = { ...searchProps, props: { ...searchProps.props, label, children }, nodeKey: value };
71
- }
72
- if (searchEl === "cascader") {
73
- searchProps = { ...searchProps, props: { ...searchProps.props, label, value, children } };
74
- }
75
- return searchProps;
76
- });
77
-
78
- // 处理默认 placeholder
79
- const placeholder = computed(() => {
80
- const search = props.column.search;
81
- if (["datetimerange", "daterange", "monthrange"].includes(search?.props?.type) || search?.props?.isRange) {
82
- return { rangeSeparator: "至", startPlaceholder: "开始时间", endPlaceholder: "结束时间" };
83
- }
84
- const placeholder = search?.props?.placeholder ?? (search?.el?.includes("input") ? "请输入" : "请选择") + props.column.label;
85
- return { placeholder };
86
- });
87
-
88
- // 是否有清除按钮 (当搜索项有默认值时,清除按钮不显示)
89
- const clearable = computed(() => {
90
- const search = props.column.search;
91
- return search?.props?.clearable ?? (search?.defaultValue == null || search?.defaultValue == undefined);
92
- });
93
- </script>
@@ -1,12 +0,0 @@
1
- .table-search {
2
- margin-bottom: 13px;
3
- :deep(.el-form) {
4
- .el-form-item {
5
- margin: 0;
6
- }
7
- .operation {
8
- display: flex;
9
- justify-content: flex-end;
10
- }
11
- }
12
- }
@@ -1,91 +0,0 @@
1
- <template>
2
- <div v-if="columns.length" class="table-search" :class="{ card: useCard }">
3
- <el-form ref="formRef" :model="searchParam">
4
- <Grid ref="gridRef" :collapsed="collapsed" :gap="[20, 20]" :cols="searchCol">
5
- <GridItem v-for="(item, index) in columns" :key="item.prop" v-bind="getResponsive(item)" :index="index">
6
- <!-- :label="`${item.label} :`" -->
7
- <el-form-item>
8
- <SearchFormItem :column="item" :search-param="searchParam" />
9
- </el-form-item>
10
- </GridItem>
11
- <GridItem suffix>
12
- <div class="operation">
13
- <el-button type="primary" :icon="Search" @click="search"> 搜索 </el-button>
14
- <el-button :icon="Delete" @click="reset"> 重置 </el-button>
15
- <el-button v-if="showCollapse" type="primary" link class="search-isOpen" @click="collapsed = !collapsed">
16
- {{ collapsed ? "展开" : "合并" }}
17
- <el-icon class="el-icon--right">
18
- <component :is="collapsed ? ArrowDown : ArrowUp"></component>
19
- </el-icon>
20
- </el-button>
21
- </div>
22
- </GridItem>
23
- </Grid>
24
- </el-form>
25
- </div>
26
- </template>
27
- <script setup lang="ts" name="SearchForm">
28
- import { computed, ref } from "vue";
29
- import { ColumnProps } from "@/components/ProTable/interface";
30
- import { BreakPoint } from "@/components/Grid/interface";
31
- import { Delete, Search, ArrowDown, ArrowUp } from "@element-plus/icons-vue";
32
- import SearchFormItem from "./components/SearchFormItem.vue";
33
- import Grid from "@/components/Grid/index.vue";
34
- import GridItem from "@/components/Grid/components/GridItem.vue";
35
-
36
- interface ProTableProps {
37
- useCard?: boolean; // 是否启用卡片样式
38
- columns?: ColumnProps[]; // 搜索配置列
39
- searchParam?: { [key: string]: any }; // 搜索参数
40
- searchCol: number | Record<BreakPoint, number>;
41
- search: (params: any) => void; // 搜索方法
42
- reset: (params: any) => void; // 重置方法
43
- }
44
-
45
- // 默认值
46
- const props = withDefaults(defineProps<ProTableProps>(), {
47
- useCard: true,
48
- columns: () => [],
49
- searchParam: () => ({})
50
- });
51
-
52
- // 获取响应式设置
53
- const getResponsive = (item: ColumnProps) => {
54
- return {
55
- span: item.search?.span,
56
- offset: item.search?.offset ?? 0,
57
- xs: item.search?.xs,
58
- sm: item.search?.sm,
59
- md: item.search?.md,
60
- lg: item.search?.lg,
61
- xl: item.search?.xl
62
- };
63
- };
64
-
65
- // 是否默认折叠搜索项
66
- const collapsed = ref(true);
67
-
68
- // 获取响应式断点
69
- const gridRef = ref();
70
- const breakPoint = computed<BreakPoint>(() => gridRef.value?.breakPoint);
71
-
72
- // 判断是否显示 展开/合并 按钮
73
- const showCollapse = computed(() => {
74
- let show = false;
75
- props.columns.reduce((prev, current) => {
76
- prev +=
77
- (current.search![breakPoint.value]?.span ?? current.search?.span ?? 1) +
78
- (current.search![breakPoint.value]?.offset ?? current.search?.offset ?? 0);
79
- if (typeof props.searchCol !== "number") {
80
- if (prev >= props.searchCol[breakPoint.value]) show = true;
81
- } else {
82
- if (prev >= props.searchCol) show = true;
83
- }
84
- return prev;
85
- }, 0);
86
- return show;
87
- });
88
- </script>
89
- <style lang="scss" scoped>
90
- @import "./index.scss";
91
- </style>
@@ -1,56 +0,0 @@
1
- <template>
2
- <RenderTableColumn v-bind="{ ..._column }" />
3
- </template>
4
-
5
- <script setup lang="tsx" name="TableColumn">
6
- import { inject, ref, useSlots } from "vue";
7
- import { ColumnProps, RenderScope, HeaderRenderScope } from "@/components/ProTable/interface";
8
- import { filterEnum, formatValue, handleProp, handleRowAccordingToProp } from "@/utils/layoutUtils";
9
-
10
- const props = defineProps<{ column: ColumnProps }>();
11
- const _column = computed(() => props.column);
12
- const slots = useSlots();
13
-
14
- const enumMap = inject("enumMap", ref(new Map()));
15
-
16
- // 渲染表格数据
17
- const renderCellData = (item: ColumnProps, scope: RenderScope<any>) => {
18
- return enumMap.value.get(item.prop) && item.isFilterEnum
19
- ? filterEnum(handleRowAccordingToProp(scope.row, item.prop!), enumMap.value.get(item.prop)!, item.fieldNames)
20
- : formatValue(handleRowAccordingToProp(scope.row, item.prop!));
21
- };
22
-
23
- // 获取 tag 类型
24
- const getTagType = (item: ColumnProps, scope: RenderScope<any>) => {
25
- return filterEnum(handleRowAccordingToProp(scope.row, item.prop!), enumMap.value.get(item.prop), item.fieldNames, "tag");
26
- };
27
- // 渲染表格行
28
- const RenderTableColumn = (item: ColumnProps) => {
29
- return (
30
- <>
31
- {item.isShow && (
32
- <el-table-column
33
- {...item}
34
- align={item.align ?? "center"}
35
- showOverflowTooltip={item.showOverflowTooltip ?? item.prop !== "operation"}
36
- >
37
- {{
38
- default: (scope: RenderScope<any>) => {
39
- if (item._children) return item._children.map(child => RenderTableColumn(child));
40
- if (item.render) return item.render(scope);
41
- if (slots[handleProp(item.prop!)]) return slots[handleProp(item.prop!)]!(scope);
42
- if (item.tag) return <el-tag type={getTagType(item, scope)}>{renderCellData(item, scope)}</el-tag>;
43
- return renderCellData(item, scope);
44
- },
45
- header: (scope: HeaderRenderScope<any>) => {
46
- if (item.headerRender) return item.headerRender(scope);
47
- if (slots[`${handleProp(item.prop!)}Header`]) return slots[`${handleProp(item.prop!)}Header`]!(scope);
48
- return item.label;
49
- }
50
- }}
51
- </el-table-column>
52
- )}
53
- </>
54
- );
55
- };
56
- </script>
@@ -1,14 +0,0 @@
1
- .pro-table-box {
2
- display: flex;
3
- flex-direction: column;
4
- width: 100%;
5
- height: 100%;
6
- overflow: hidden;
7
- :deep(.table-main) {
8
- flex: 1;
9
- overflow: hidden;
10
- .el-scrollbar__view {
11
- display: block !important;
12
- }
13
- }
14
- }
@@ -1,274 +0,0 @@
1
- <!-- 📚📚📚 Pro-Table 文档: https://juejin.cn/post/7166068828202336263 -->
2
-
3
- <template>
4
- <div class="pro-table-box">
5
- <!-- 查询表单 card -->
6
- <SearchForm
7
- v-show="isShowSearch"
8
- :search="search"
9
- :reset="reset"
10
- :columns="searchColumns"
11
- :search-param="searchParam"
12
- :search-col="searchCol"
13
- :use-card="useCard"
14
- />
15
-
16
- <!-- 表格内容 card -->
17
- <div class="table-main" :class="{ card: useCard }">
18
- <!-- 表格头部 操作按钮 -->
19
- <div class="table-header">
20
- <div class="header-button-lf">
21
- <slot name="tableHeader" :selected-list-ids="selectedListIds" :selected-list="selectedList" :is-selected="isSelected" />
22
- </div>
23
- <div v-if="toolButton && !useCustomTable" class="header-button-ri">
24
- <slot name="toolButton">
25
- <el-button :icon="Refresh" circle @click="getTableList" />
26
- <el-button v-if="columns.length" :icon="Operation" circle @click="openColSetting" />
27
- <el-button v-if="searchColumns.length" :icon="Search" circle @click="isShowSearch = !isShowSearch" />
28
- </slot>
29
- </div>
30
- </div>
31
-
32
- <!-- 表格主体 -->
33
- <el-table
34
- v-if="!useCustomTable"
35
- ref="tableRef"
36
- v-bind="$attrs"
37
- :data="data ?? tableData"
38
- :border="border"
39
- :row-key="rowKey"
40
- :tree-props="treeProps"
41
- @row-click="rowClick"
42
- @selection-change="selectionChange"
43
- :highlight-current-row="highlightCurrentRow || typeof currentChange === 'function'"
44
- @current-change="currentChange"
45
- >
46
- <!-- 默认插槽 -->
47
- <slot></slot>
48
- <template v-for="item in tableColumns" :key="item">
49
- <!-- selection || index || expand -->
50
- <el-table-column
51
- v-if="item.type && ['selection', 'index', 'expand'].includes(item.type) && item.isShow"
52
- v-bind="item"
53
- :align="item.align ?? 'center'"
54
- :reserve-selection="item.type == 'selection'"
55
- >
56
- <!-- 拓展插槽 -->
57
- <template v-if="item.type == 'expand'" #default="scope">
58
- <component :is="item.render" v-bind="scope" v-if="item.render"> </component>
59
- <slot v-else :name="item.type" v-bind="scope"></slot>
60
- </template>
61
- </el-table-column>
62
- <!-- 其他插槽 -->
63
- <TableColumn v-if="!item.type && item.prop && item.isShow" :column="item">
64
- <template v-for="slot in Object.keys($slots)" #[slot]="scope">
65
- <slot :name="slot" v-bind="scope"></slot>
66
- </template>
67
- </TableColumn>
68
- </template>
69
- <!-- 插入表格最后一行之后的插槽 -->
70
- <template #append>
71
- <slot name="append"> </slot>
72
- </template>
73
- <!-- 无数据 -->
74
- <template #empty>
75
- <div class="table-empty">
76
- <empty />
77
- </div>
78
- </template>
79
- </el-table>
80
- <!-- 自定义表格 -->
81
- <div v-else class="el-table">
82
- <el-scrollbar v-if="data?.length ?? tableData?.length">
83
- <slot :data="data ?? tableData" />
84
- </el-scrollbar>
85
- <empty v-else />
86
- </div>
87
- <!-- 分页组件 -->
88
- <slot name="pagination">
89
- <Pagination
90
- v-if="pagination"
91
- :pageable="pageable"
92
- :handle-size-change="handleSizeChange"
93
- :handle-current-change="handleCurrentChange"
94
- />
95
- </slot>
96
- </div>
97
- <!-- 列设置 -->
98
- <ColSetting v-if="toolButton" ref="colRef" v-model:col-setting="colSetting" />
99
- </div>
100
- </template>
101
-
102
- <script setup lang="ts" name="ProTable">
103
- import { ref, watch, computed, provide, onMounted } from "vue";
104
- import { ElTable } from "element-plus";
105
- import { useTable } from "@/hooks/useTable";
106
- import { useSelection } from "@/hooks/useSelection";
107
- import { BreakPoint } from "@/components/Grid/interface";
108
- import { ColumnProps, tableTreeProps } from "@/components/ProTable/interface";
109
- import { fetchType as myFetchType } from "@/api/interface/index";
110
- import { Refresh, Operation, Search } from "@element-plus/icons-vue";
111
- import { filterEnum, formatValue, handleProp, handleRowAccordingToProp } from "@/utils/layoutUtils";
112
- import SearchForm from "./components/SearchForm/index.vue";
113
- import Pagination from "./components/Pagination.vue";
114
- import ColSetting from "./components/ColSetting.vue";
115
- import TableColumn from "./components/TableColumn.vue";
116
-
117
- export interface ProTableProps {
118
- useCustomTable?: boolean; // 是否使用表格 如果为true 则使用插槽的方式传入自定义表格渲染方式
119
- useCard?: boolean; // 是否启用卡片样式
120
- columns: ColumnProps[]; // 列配置项 ==> 必传
121
- data?: any[]; // 静态 table data 数据,若存在则不会使用 requestApi 返回的 data ==> 非必传
122
- requestApi?: string | ((params: any) => Promise<any>); // 请求表格数据的 api ==> 非必传
123
- requestAuto?: boolean; // 是否自动执行请求 api ==> 非必传(默认为true)
124
- requestError?: (params: any) => void; // 表格 api 请求错误监听 ==> 非必传
125
- dataCallback?: (data: any) => any; // 返回数据的回调函数,可以对数据进行处理 ==> 非必传
126
- rowClick?: (data: any) => any; // 当某一行被点击时会触发该事件 ==> 非必传
127
- highlightCurrentRow?: boolean; // 是否高亮当前行 ==> 非必传
128
- currentChange?: (data: any) => any; // 当表格的当前行发生变化的时候会触发该事件 ==> 非必传
129
- title?: string; // 表格标题,目前只在打印的时候用到 ==> 非必传
130
- pagination?: boolean; // 是否需要分页组件 ==> 非必传(默认为true)
131
- tableLimit?: number; //数据每页个数
132
- initParam?: any; // 初始化请求参数 ==> 非必传(默认为{})
133
- border?: boolean; // 是否带有纵向边框 ==> 非必传(默认为true)
134
- toolButton?: boolean; // 是否显示表格功能按钮 ==> 非必传(默认为true)
135
- rowKey?: string; // 行数据的 Key,用来优化 Table 的渲染,当表格数据多选时,所指定的 id ==> 非必传(默认为 id)
136
- searchCol?: number | Record<BreakPoint, number>; // 表格搜索项 每列占比配置 ==> 非必传 { xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }
137
- treeProps?: tableTreeProps; //渲染嵌套数据的配置选项
138
- fetchType?: myFetchType;
139
- }
140
-
141
- // 接受父组件参数,配置默认值
142
- const props = withDefaults(defineProps<ProTableProps>(), {
143
- useCustomTable: false,
144
- useCard: true,
145
- columns: () => [],
146
- requestAuto: true,
147
- pagination: true,
148
- tableLimit: 10,
149
- initParam: {},
150
- border: false,
151
- toolButton: true,
152
- rowKey: "id",
153
- searchCol: () => ({ xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }),
154
- treeProps: () => ({ hasChildren: "hasChildren", children: "children" }),
155
- fetchType: "post"
156
- });
157
-
158
- // 是否显示搜索模块
159
- const isShowSearch = ref(true);
160
-
161
- // 表格 DOM 元素
162
- const tableRef = ref<InstanceType<typeof ElTable>>();
163
-
164
- // 表格多选 Hooks 多选框
165
- const { selectionChange, selectedList, selectedListIds, isSelected } = useSelection(props.rowKey);
166
-
167
- // 清空选中数据列表
168
- const clearSelection = () => tableRef.value!.clearSelection();
169
-
170
- // 初始化请求
171
- onMounted(() => props.requestAuto && getTableList());
172
-
173
- // 接收 columns 并设置为响应式
174
- const tableColumns = ref<ColumnProps[]>(props.columns);
175
-
176
- // 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)
177
- const enumMap = ref(new Map<string, { [key: string]: any }[]>());
178
- provide("enumMap", enumMap);
179
- const setEnumMap = async (col: ColumnProps) => {
180
- if (!col.enum) return;
181
- // 如果当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap
182
- if (typeof col.enum !== "function") return enumMap.value.set(col.prop!, col.enum!);
183
- const res = await col.enum();
184
- enumMap.value.set(col.prop!, res);
185
- };
186
-
187
- // 扁平化 columns
188
- const flatColumnsFunc = (columns: ColumnProps[], flatArr: ColumnProps[] = []) => {
189
- columns.forEach(async col => {
190
- if (col._children?.length) flatArr.push(...flatColumnsFunc(col._children));
191
- flatArr.push(col);
192
- // 给每一项 column 添加 isShow && isFilterEnum 默认属性
193
- col.isShow = col.isShow ?? true;
194
- col.isFilterEnum = col.isFilterEnum ?? true;
195
- // 设置 enumMap
196
- setEnumMap(col);
197
- });
198
- return flatArr.filter(item => !item._children?.length);
199
- };
200
-
201
- // flatColumns
202
- const flatColumns = ref<ColumnProps[]>();
203
- flatColumns.value = flatColumnsFunc(tableColumns.value);
204
-
205
- // 过滤需要搜索的配置项
206
- const searchColumns = flatColumns.value.filter(item => item.search?.el || item.search?.render);
207
-
208
- // 设置搜索表单排序默认值 && 设置搜索表单项的默认值
209
- searchColumns.forEach((column, index) => {
210
- column.search!.order = column.search!.order ?? index + 2;
211
- if (column.search?.defaultValue !== undefined && column.search?.defaultValue !== null) {
212
- searchInitParam.value[column.search.key ?? handleProp(column.prop!)] = column.search?.defaultValue;
213
- searchParam.value[column.search.key ?? handleProp(column.prop!)] = column.search?.defaultValue;
214
- }
215
- });
216
-
217
- // 排序搜索表单项
218
- searchColumns.sort((a, b) => a.search!.order! - b.search!.order!);
219
-
220
- // 列设置 ==> 过滤掉不需要设置的列
221
- const colRef = ref();
222
- const colSetting = tableColumns.value!.filter(
223
- item => !["selection", "index", "expand"].includes(item.type!) && item.prop !== "operation" && item.isShow
224
- );
225
- const openColSetting = () => colRef.value.openColSetting();
226
-
227
- // 表格操作 Hooks
228
- const {
229
- tableData,
230
- pageable,
231
- searchParam,
232
- searchInitParam,
233
- getTableList,
234
- search,
235
- reset,
236
- handleSizeChange,
237
- handleCurrentChange,
238
- totalParam
239
- } = useTable(
240
- props.initParam,
241
- props.pagination,
242
- props.fetchType,
243
- props.tableLimit,
244
- props.requestApi,
245
- props.dataCallback,
246
- props.requestError
247
- );
248
-
249
- // 监听页面 initParam 改化,重新获取表格数据
250
- watch([() => props.initParam], getTableList, { deep: true });
251
-
252
- // 暴露给父组件的参数和方法(外部需要什么,都可以从这里暴露出去)
253
- defineExpose({
254
- element: tableRef,
255
- tableData,
256
- pageable,
257
- searchParam,
258
- searchInitParam,
259
- getTableList,
260
- search,
261
- reset,
262
- handleSizeChange,
263
- handleCurrentChange,
264
- clearSelection,
265
- enumMap,
266
- isSelected,
267
- selectedList,
268
- selectedListIds,
269
- totalParam
270
- });
271
- </script>
272
- <style lang="scss" scoped>
273
- @import "./index.scss";
274
- </style>
@@ -1,86 +0,0 @@
1
- import { VNode, ComponentPublicInstance } from "vue";
2
- import { BreakPoint, Responsive } from "@/components/Grid/interface";
3
- import { TableColumnCtx } from "element-plus/es/components/table/src/table-column/defaults";
4
- import { ProTableProps } from "@/components/ProTable/index.vue";
5
- import ProTable from "@/components/ProTable/index.vue";
6
-
7
- export interface tableTreeProps {
8
- hasChildren: string;
9
- children: string;
10
- }
11
-
12
- export interface EnumProps {
13
- label?: string; // 选项框显示的文字
14
- value?: string | number | boolean | any[]; // 选项框值
15
- disabled?: boolean; // 是否禁用此选项
16
- tagType?: string; // 当 tag 为 true 时,此选择会指定 tag 显示类型
17
- children?: EnumProps[]; // 为树形选择时,可以通过 children 属性指定子选项
18
- [key: string]: any;
19
- }
20
-
21
- export type TypeProps = "index" | "selection" | "expand";
22
-
23
- export type SearchType =
24
- | "input"
25
- | "input-number"
26
- | "select"
27
- | "select-v2"
28
- | "tree-select"
29
- | "cascader"
30
- | "date-picker"
31
- | "time-picker"
32
- | "time-select"
33
- | "switch"
34
- | "slider";
35
-
36
- export type SearchRenderScope = {
37
- searchParam: { [key: string]: any };
38
- placeholder: string;
39
- clearable: boolean;
40
- options: EnumProps[];
41
- data: EnumProps[];
42
- };
43
-
44
- export type SearchProps = {
45
- el?: SearchType; // 当前项搜索框的类型
46
- props?: any; // 搜索项参数,根据 element plus 官方文档来传递,该属性所有值会透传到组件
47
- key?: string; // 当搜索项 key 不为 prop 属性时,可通过 key 指定
48
- order?: number; // 搜索项排序(从大到小)
49
- span?: number; // 搜索项所占用的列数,默认为1列
50
- offset?: number; // 搜索字段左侧偏移列数
51
- defaultValue?: string | number | boolean | any[]; // 搜索项默认值
52
- render?: (scope: SearchRenderScope) => VNode; // 自定义搜索内容渲染(tsx语法)
53
- } & Partial<Record<BreakPoint, Responsive>>;
54
-
55
- export type FieldNamesProps = {
56
- label: string;
57
- value: string;
58
- children?: string;
59
- };
60
-
61
- export type RenderScope<T> = {
62
- row: T;
63
- $index: number;
64
- column: TableColumnCtx<T>;
65
- [key: string]: any;
66
- };
67
-
68
- export type HeaderRenderScope<T> = {
69
- $index: number;
70
- column: TableColumnCtx<T>;
71
- [key: string]: any;
72
- };
73
-
74
- export interface ColumnProps<T = any> extends Partial<Omit<TableColumnCtx<T>, "children" | "renderCell" | "renderHeader">> {
75
- tag?: boolean; // 是否是标签展示
76
- isShow?: boolean; // 是否显示在表格当中
77
- search?: SearchProps | undefined; // 搜索项配置
78
- enum?: EnumProps[] | ((params?: any) => Promise<any>); // 枚举类型(字典)
79
- isFilterEnum?: boolean; // 当前单元格值是否根据 enum 格式化(示例:enum 只作为搜索项数据)
80
- fieldNames?: FieldNamesProps; // 指定 label && value && children 的 key 值
81
- headerRender?: (scope: HeaderRenderScope<T>) => VNode; // 自定义表头内容渲染(tsx语法)
82
- render?: (scope: RenderScope<T>) => VNode | string; // 自定义单元格内容渲染(tsx语法)
83
- _children?: ColumnProps<T>[]; // 多级表头
84
- }
85
-
86
- export type ProTableInstance = Omit<InstanceType<typeof ProTable>, keyof ComponentPublicInstance | keyof ProTableProps>;
@@ -1,44 +0,0 @@
1
- <template>
2
- <div class="scroll-box" :style="{ width: `calc(100% + ${rightDistance})` }">
3
- <el-scrollbar
4
- ref="scrollRef"
5
- :view-style="{
6
- paddingRight: rightDistance
7
- }"
8
- :height="height"
9
- :always="always"
10
- >
11
- <slot />
12
- </el-scrollbar>
13
- </div>
14
- </template>
15
-
16
- <script setup>
17
- const props = defineProps({
18
- height: {
19
- type: String,
20
- default: () => "100%"
21
- },
22
- maxHeight: {
23
- type: String,
24
- default: () => "100%"
25
- },
26
- rightDistance: {
27
- type: String,
28
- default: () => "0px"
29
- },
30
- always: {
31
- type: Boolean,
32
- default: () => false
33
- }
34
- });
35
- const scrollRef = ref();
36
- </script>
37
-
38
- <style lang="scss" scoped>
39
- .scroll-box {
40
- position: relative;
41
- width: 100%;
42
- height: 100%;
43
- }
44
- </style>