fast-element-plus 2.0.15 → 2.0.17
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.
- package/CHANGELOG.md +28 -0
- package/dist/component.d.ts +6570 -2
- package/dist/component.mjs.map +1 -1
- package/dist/components/avatar/src/avatar.d.ts +19 -7
- package/dist/components/avatar/src/avatar.mjs +5 -0
- package/dist/components/avatar/src/avatar.mjs.map +1 -1
- package/dist/components/button/src/button.d.ts +4 -4
- package/dist/components/button/src/button.mjs +3 -4
- package/dist/components/button/src/button.mjs.map +1 -1
- package/dist/components/carNumber/src/carNumber.mjs +7 -9
- package/dist/components/carNumber/src/carNumber.mjs.map +1 -1
- package/dist/components/contextMenu/index.d.ts +1 -1
- package/dist/components/contextMenu/index.mjs.map +1 -1
- package/dist/components/contextMenu/src/contextMenu.d.ts +2 -2
- package/dist/components/contextMenu/src/contextMenu.mjs +10 -9
- package/dist/components/contextMenu/src/contextMenu.mjs.map +1 -1
- package/dist/components/dialog/src/dialog.d.ts +7 -4
- package/dist/components/dialog/src/dialog.mjs +10 -11
- package/dist/components/dialog/src/dialog.mjs.map +1 -1
- package/dist/components/drawer/src/drawer.d.ts +2 -2
- package/dist/components/drawer/src/drawer.mjs +18 -18
- package/dist/components/drawer/src/drawer.mjs.map +1 -1
- package/dist/components/form/src/form.d.ts +34 -16
- package/dist/components/form/src/form.mjs +8 -9
- package/dist/components/form/src/form.mjs.map +1 -1
- package/dist/components/form/src/formItem.d.ts +4 -4
- package/dist/components/form/src/formItem.mjs +18 -17
- package/dist/components/form/src/formItem.mjs.map +1 -1
- package/dist/components/form/utils/form.d.ts +3 -3
- package/dist/components/form/utils/form.mjs +6 -10
- package/dist/components/form/utils/form.mjs.map +1 -1
- package/dist/components/icon/src/icon.mjs.map +1 -1
- package/dist/components/iconSelector/src/iconSelector.d.ts +2 -2
- package/dist/components/iconSelector/src/iconSelector.mjs +4 -5
- package/dist/components/iconSelector/src/iconSelector.mjs.map +1 -1
- package/dist/components/image/src/image.d.ts +1 -1
- package/dist/components/image/src/image.mjs +3 -3
- package/dist/components/image/src/image.mjs.map +1 -1
- package/dist/components/inputDialogPage/src/inputDialogPage.d.ts +4 -4
- package/dist/components/inputDialogPage/src/inputDialogPage.mjs +11 -15
- package/dist/components/inputDialogPage/src/inputDialogPage.mjs.map +1 -1
- package/dist/components/layoutGrid/index.d.ts +1 -1
- package/dist/components/layoutGrid/index.mjs.map +1 -1
- package/dist/components/layoutGrid/src/layoutGrid.d.ts +23 -11
- package/dist/components/layoutGrid/src/layoutGrid.mjs +44 -45
- package/dist/components/layoutGrid/src/layoutGrid.mjs.map +1 -1
- package/dist/components/layoutGrid/src/layoutGrid.type.d.ts +1 -1
- package/dist/components/layoutGrid/src/layoutGridItem.mjs +13 -14
- package/dist/components/layoutGrid/src/layoutGridItem.mjs.map +1 -1
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/index.mjs.map +1 -1
- package/dist/components/select/src/select.d.ts +29 -14
- package/dist/components/select/src/select.mjs +47 -45
- package/dist/components/select/src/select.mjs.map +1 -1
- package/dist/components/select/src/selectOption.mjs +4 -5
- package/dist/components/select/src/selectOption.mjs.map +1 -1
- package/dist/components/selectPage/src/selectPage.d.ts +29 -14
- package/dist/components/selectPage/src/selectPage.mjs +45 -52
- package/dist/components/selectPage/src/selectPage.mjs.map +1 -1
- package/dist/components/selectV2/src/selectV2.d.ts +51 -31
- package/dist/components/selectV2/src/selectV2.mjs +66 -64
- package/dist/components/selectV2/src/selectV2.mjs.map +1 -1
- package/dist/components/table/index.d.ts +3 -3
- package/dist/components/table/index.mjs +1 -3
- package/dist/components/table/index.mjs.map +1 -1
- package/dist/components/table/src/table.d.ts +72 -38
- package/dist/components/table/src/table.mjs +98 -104
- package/dist/components/table/src/table.mjs.map +1 -1
- package/dist/components/table/src/table.type.d.ts +2 -2
- package/dist/components/table/src/table.type.mjs.map +1 -1
- package/dist/components/table/src/tableColumn.d.ts +7 -7
- package/dist/components/table/src/tableColumn.mjs +25 -45
- package/dist/components/table/src/tableColumn.mjs.map +1 -1
- package/dist/components/table/src/tableColumnSettingDialog.mjs +32 -22
- package/dist/components/table/src/tableColumnSettingDialog.mjs.map +1 -1
- package/dist/components/table/src/tablePagination.mjs +2 -3
- package/dist/components/table/src/tablePagination.mjs.map +1 -1
- package/dist/components/table/src/tableSearchForm.d.ts +4 -4
- package/dist/components/table/src/tableSearchForm.mjs +35 -44
- package/dist/components/table/src/tableSearchForm.mjs.map +1 -1
- package/dist/components/table/src/tableSearchFormItem.d.ts +1 -7
- package/dist/components/table/src/tableSearchFormItem.mjs +3 -6
- package/dist/components/table/src/tableSearchFormItem.mjs.map +1 -1
- package/dist/components/table/src/useTable.d.ts +4 -4
- package/dist/components/table/src/useTable.mjs +19 -20
- package/dist/components/table/src/useTable.mjs.map +1 -1
- package/dist/components/table/utils/table.mjs +6 -8
- package/dist/components/table/utils/table.mjs.map +1 -1
- package/dist/components/tree/index.d.ts +1 -1
- package/dist/components/tree/index.mjs.map +1 -1
- package/dist/components/tree/src/tree.d.ts +9 -9
- package/dist/components/tree/src/tree.mjs +29 -27
- package/dist/components/tree/src/tree.mjs.map +1 -1
- package/dist/components/treeSelect/src/treeSelect.d.ts +38 -35
- package/dist/components/treeSelect/src/treeSelect.mjs +47 -45
- package/dist/components/treeSelect/src/treeSelect.mjs.map +1 -1
- package/dist/components/upload/src/upload.d.ts +1 -1
- package/dist/components/upload/src/upload.mjs +5 -6
- package/dist/components/upload/src/upload.mjs.map +1 -1
- package/dist/components/upload/src/useUpload.mjs +8 -10
- package/dist/components/upload/src/useUpload.mjs.map +1 -1
- package/dist/components/upload/utils/upload.d.ts +1 -1
- package/dist/components/upload/utils/upload.mjs +1 -1
- package/dist/components/upload/utils/upload.mjs.map +1 -1
- package/dist/components/uploadImage/src/uploadImage.d.ts +8 -5
- package/dist/components/uploadImage/src/uploadImage.mjs +18 -13
- package/dist/components/uploadImage/src/uploadImage.mjs.map +1 -1
- package/dist/components/uploadImages/src/uploadImages.d.ts +8 -5
- package/dist/components/uploadImages/src/uploadImages.mjs +16 -11
- package/dist/components/uploadImages/src/uploadImages.mjs.map +1 -1
- package/dist/directives/click-copy/index.d.ts +1 -1
- package/dist/directives/click-copy/index.mjs +5 -9
- package/dist/directives/click-copy/index.mjs.map +1 -1
- package/dist/directives/click-debounce/index.d.ts +1 -1
- package/dist/directives/click-draggable/index.d.ts +1 -1
- package/dist/directives/click-icon-copy/index.d.ts +1 -1
- package/dist/directives/click-icon-copy/index.mjs.map +1 -1
- package/dist/directives/click-longpress/index.d.ts +1 -1
- package/dist/directives/click-throttle/index.d.ts +1 -1
- package/dist/element-plus.mjs +5 -6
- package/dist/element-plus.mjs.map +1 -1
- package/dist/hooks/use-screenFull/index.mjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.global.min.js +4 -4
- package/dist/index.global.min.js.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/utils/async/index.mjs +6 -4
- package/dist/utils/async/index.mjs.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/object/index.d.ts +8 -0
- package/dist/utils/object/index.mjs +113 -0
- package/dist/utils/object/index.mjs.map +1 -0
- package/dist/utils/string/index.mjs +19 -11
- package/dist/utils/string/index.mjs.map +1 -1
- package/dist/utils/vue/emits.mjs.map +1 -1
- package/dist/utils/vue/install.mjs.map +1 -1
- package/dist/utils/vue/render.mjs.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +5 -10
- package/dist/components/table/src/page.type.mjs +0 -45
- package/dist/components/table/src/page.type.mjs.map +0 -1
|
@@ -2,9 +2,8 @@ import { debounce } from "../../../utils/async/index.mjs";
|
|
|
2
2
|
import { callOptionalFunction } from "../../../utils/vue/func.mjs";
|
|
3
3
|
import { tableUtil } from "../utils/table.mjs";
|
|
4
4
|
import { getTableDefaultSlots } from "./table.type.mjs";
|
|
5
|
-
import { computed, nextTick, provide, reactive,
|
|
5
|
+
import { computed, nextTick, provide, reactive, shallowRef, watch } from "vue";
|
|
6
6
|
import { dayjs, useGlobalSize } from "element-plus";
|
|
7
|
-
import { isArray, isFunction } from "lodash-unified";
|
|
8
7
|
//#region src/components/table/src/useTable.ts
|
|
9
8
|
/** FaTable 状态的依赖注入键。 */
|
|
10
9
|
const tableStateKey = Symbol("tableState");
|
|
@@ -19,9 +18,9 @@ const enumMapKey = Symbol("enumMap");
|
|
|
19
18
|
* @returns FaTable 的状态、引用和操作方法。
|
|
20
19
|
*/
|
|
21
20
|
const useTable = (props, slots, emit) => {
|
|
22
|
-
const
|
|
23
|
-
const elementRef =
|
|
24
|
-
const tableRef =
|
|
21
|
+
const globalSize = useGlobalSize();
|
|
22
|
+
const elementRef = shallowRef(null);
|
|
23
|
+
const tableRef = shallowRef(null);
|
|
25
24
|
/**
|
|
26
25
|
* 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)
|
|
27
26
|
*/
|
|
@@ -54,7 +53,7 @@ const useTable = (props, slots, emit) => {
|
|
|
54
53
|
] : []]),
|
|
55
54
|
tableData: [],
|
|
56
55
|
tableSpanData: computed(() => {
|
|
57
|
-
if (state.spanColumns
|
|
56
|
+
if (state.spanColumns.length > 0 && state.tableData.length > 0) {
|
|
58
57
|
const result = {};
|
|
59
58
|
const spanIndexes = {};
|
|
60
59
|
state.spanColumns.forEach((item) => {
|
|
@@ -89,14 +88,14 @@ const useTable = (props, slots, emit) => {
|
|
|
89
88
|
selected: false,
|
|
90
89
|
selectedList: [],
|
|
91
90
|
selectedListIds: computed(() => state.selectedList.flatMap((item) => {
|
|
92
|
-
const rowKey =
|
|
91
|
+
const rowKey = typeof props.rowKey === "function" ? props.rowKey(item) : tableUtil.handleRowAccordingToProp(item, props.rowKey);
|
|
93
92
|
return typeof rowKey === "string" || typeof rowKey === "number" ? [rowKey] : [];
|
|
94
93
|
})),
|
|
95
94
|
indeterminateSelectedListIds: [],
|
|
96
95
|
operationColumnWidth: computed(() => {
|
|
97
96
|
const findAutoCol = state.autoColumnWidth.find((f) => f.prop === "__table-operation");
|
|
98
97
|
if (findAutoCol) return `${findAutoCol.width}px`;
|
|
99
|
-
switch (
|
|
98
|
+
switch (globalSize.value) {
|
|
100
99
|
case "large":
|
|
101
100
|
case "default": return "54px";
|
|
102
101
|
case "small": return "42px";
|
|
@@ -116,25 +115,25 @@ const useTable = (props, slots, emit) => {
|
|
|
116
115
|
state.loadingText = "加载中...";
|
|
117
116
|
state.autoColumnWidth = [];
|
|
118
117
|
const autoWidthColumns = state.tableColumns.filter((f) => f.autoWidth);
|
|
119
|
-
if (slots
|
|
118
|
+
if (slots.operation) autoWidthColumns.push({ prop: "__table-operation" });
|
|
120
119
|
if (autoWidthColumns.length > 0) {
|
|
121
|
-
const otherWidth =
|
|
120
|
+
const otherWidth = globalSize.value === "default" ? 25 : 17;
|
|
122
121
|
nextTick(() => {
|
|
123
122
|
const tableDom = document.querySelector(`.fa-table__${props.tableKey}`);
|
|
124
123
|
if (tableDom) autoWidthColumns.forEach((item) => {
|
|
125
|
-
const headerColumnDom = tableDom.querySelector(`.__fa-table__auto-width-column__cell-header__${item
|
|
126
|
-
const cellColumnDoms = tableDom.querySelectorAll(`.__fa-table__auto-width-column__cell__${item
|
|
124
|
+
const headerColumnDom = tableDom.querySelector(`.__fa-table__auto-width-column__cell-header__${item.prop}`);
|
|
125
|
+
const cellColumnDoms = tableDom.querySelectorAll(`.__fa-table__auto-width-column__cell__${item.prop}`);
|
|
127
126
|
let maxWidth = 0;
|
|
128
127
|
if (headerColumnDom) {
|
|
129
128
|
maxWidth = Math.ceil(headerColumnDom.scrollWidth) + otherWidth;
|
|
130
|
-
if (item
|
|
129
|
+
if (item.sortable) maxWidth += 24;
|
|
131
130
|
}
|
|
132
131
|
cellColumnDoms.forEach((cellDom) => {
|
|
133
132
|
const curWidth = Math.ceil(cellDom.scrollWidth) + otherWidth;
|
|
134
133
|
if (curWidth > maxWidth) maxWidth = curWidth;
|
|
135
134
|
});
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
135
|
+
const autoWidthEntry = state.autoColumnWidth.find((f) => f.prop === item.prop);
|
|
136
|
+
if (autoWidthEntry) autoWidthEntry.width = Math.max(autoWidthEntry.width, maxWidth);
|
|
138
137
|
else if (item.prop) state.autoColumnWidth.push({
|
|
139
138
|
prop: item.prop,
|
|
140
139
|
width: maxWidth
|
|
@@ -152,7 +151,7 @@ const useTable = (props, slots, emit) => {
|
|
|
152
151
|
const result = [];
|
|
153
152
|
data.forEach((row) => {
|
|
154
153
|
const rowList = row[props.props.children ?? "children"];
|
|
155
|
-
if (isArray(rowList)) rowList.forEach((childRow) => {
|
|
154
|
+
if (Array.isArray(rowList)) rowList.forEach((childRow) => {
|
|
156
155
|
result.push(typeof childRow === "object" && childRow !== null ? {
|
|
157
156
|
...row,
|
|
158
157
|
...childRow
|
|
@@ -187,7 +186,7 @@ const useTable = (props, slots, emit) => {
|
|
|
187
186
|
if (currentRequestVersion !== requestVersion) return;
|
|
188
187
|
props.dataCallback?.(resData);
|
|
189
188
|
if (props.pagination) {
|
|
190
|
-
if (isArray(resData)) {
|
|
189
|
+
if (Array.isArray(resData)) {
|
|
191
190
|
pageData = resData;
|
|
192
191
|
state.tablePagination.totalRows = resData.length;
|
|
193
192
|
} else {
|
|
@@ -226,7 +225,7 @@ const useTable = (props, slots, emit) => {
|
|
|
226
225
|
return (typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" ? String(value) : "").toLowerCase().includes(searchValue.toLowerCase());
|
|
227
226
|
});
|
|
228
227
|
});
|
|
229
|
-
if (isArray(state.searchParam.sortList) && state.searchParam.sortList.length > 0) _value = _value.sort(tableUtil.arrayDynamicSort(state.searchParam.sortList));
|
|
228
|
+
if (Array.isArray(state.searchParam.sortList) && state.searchParam.sortList.length > 0) _value = _value.sort(tableUtil.arrayDynamicSort(state.searchParam.sortList));
|
|
230
229
|
if (props.pagination) {
|
|
231
230
|
Object.assign(state.tablePagination, { totalRows: _value.length });
|
|
232
231
|
const pageStart = (state.tablePagination.pageIndex - 1) * state.tablePagination.pageSize;
|
|
@@ -354,7 +353,7 @@ const useTable = (props, slots, emit) => {
|
|
|
354
353
|
state.tablePagination.pageIndex = 1;
|
|
355
354
|
state.searchParam = {};
|
|
356
355
|
defaultSearchTime();
|
|
357
|
-
|
|
356
|
+
Object.assign(state.searchParam, state.initParam);
|
|
358
357
|
emit("reset", state.searchParam);
|
|
359
358
|
await loadData();
|
|
360
359
|
};
|
|
@@ -386,7 +385,7 @@ const useTable = (props, slots, emit) => {
|
|
|
386
385
|
state.searchForm = newValue;
|
|
387
386
|
});
|
|
388
387
|
return {
|
|
389
|
-
|
|
388
|
+
globalSize,
|
|
390
389
|
state,
|
|
391
390
|
elementRef,
|
|
392
391
|
tableRef,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.mjs","names":[],"sources":["../../../../src/components/table/src/useTable.ts"],"sourcesContent":["import { computed, nextTick, provide, reactive, ref, watch } from \"vue\";\nimport { dayjs, useGlobalSize } from \"element-plus\";\nimport { isArray, isFunction } from \"lodash-unified\";\nimport { callOptionalFunction, debounce } from \"../../../utils\";\nimport { tableUtil } from \"../utils/table\";\nimport { getTableDefaultSlots } from \"./table.type\";\nimport type { TableInstance } from \"element-plus\";\nimport type { ExtractPropTypes, InjectionKey, Ref, SetupContext } from \"vue\";\nimport type { makeSlots } from \"../../../utils\";\nimport type { PagedInput, PagedResult } from \"./page.type\";\nimport type { FaTableSlots, faTableEmits, faTableProps } from \"./table\";\nimport type { DefaultRow, FaTableState } from \"./table.state\";\nimport type { FaTableColumnCtx, FaTableEnumColumnCtx } from \"./table.type\";\n\n/** FaTable 状态的依赖注入键。 */\nexport const tableStateKey: InjectionKey<FaTableState> = Symbol(\"tableState\");\n/** FaTable 枚举映射的依赖注入键。 */\nexport const enumMapKey: InjectionKey<Map<string, FaTableEnumColumnCtx[]>> = Symbol(\"enumMap\");\n\ntype TableSetupContext = SetupContext<typeof faTableEmits, ReturnType<typeof makeSlots<FaTableSlots>>>;\n\ninterface TableComposable {\n\t_globalSize: ReturnType<typeof useGlobalSize>;\n\tstate: FaTableState;\n\telementRef: Ref<HTMLElement | undefined>;\n\ttableRef: Ref<TableInstance | undefined>;\n\thandleTableColumnAutoWidth: () => void;\n\tgetRequestParam: () => PagedInput;\n\tloadTableColumns: () => void;\n\thandleSizeChange: (pageSize: number) => void;\n\thandlePaginationChange: (value: number) => void;\n\tdefaultSearchTime: () => void;\n\ttableSearch: () => Promise<void>;\n\ttableReset: () => Promise<void>;\n\tdoRender: () => Promise<void>;\n\tdoLoading: (loadingFunction: () => void | Promise<void>, loadingText?: string) => Promise<void>;\n\thandleCustomCellClick: (emitName: string, context: { row: DefaultRow; column: FaTableColumnCtx; $index: number }) => void;\n}\n\n/**\n * 创建 FaTable 的状态和操作方法。\n *\n * @param props - FaTable 的 Props。\n * @param slots - FaTable 的插槽。\n * @param emit - FaTable 的事件触发器。\n * @returns FaTable 的状态、引用和操作方法。\n */\nexport const useTable = (\n\tprops: ExtractPropTypes<typeof faTableProps>,\n\tslots: TableSetupContext[\"slots\"],\n\temit: TableSetupContext[\"emit\"]\n): TableComposable => {\n\tconst _globalSize = useGlobalSize();\n\n\tconst elementRef = ref<HTMLElement>();\n\tconst tableRef = ref<TableInstance>();\n\n\t/**\n\t * 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)\n\t */\n\tconst enumMap = reactive(new Map<string, FaTableEnumColumnCtx[]>());\n\tprovide(enumMapKey, enumMap);\n\n\tconst state: FaTableState = reactive({\n\t\tloading: false,\n\t\tloadingText: \"加载中...\",\n\t\torgColumns: [],\n\t\ttableColumns: computed(() => state.orgColumns.filter((f) => f.prop && !f.pureSearch)),\n\t\tsearchColumns: computed(() =>\n\t\t\tstate.orgColumns\n\t\t\t\t.filter((item) => item.pureSearch === true || item.search !== undefined)\n\t\t\t\t.sort((a, b) => {\n\t\t\t\t\treturn (a.search?.order ?? 0) - (b.search?.order ?? 0);\n\t\t\t\t})\n\t\t),\n\t\tspanColumns: computed(() => [\n\t\t\t...state.orgColumns.flatMap((column) => (column.spanProp ? [{ prop: column.prop ?? \"\", spanProp: column.spanProp }] : [])),\n\t\t\t...(props.props.span\n\t\t\t\t? [\n\t\t\t\t\t\t{ prop: \"__table-index\", spanProp: props.props.span },\n\t\t\t\t\t\t{ prop: \"__table-selection\", spanProp: props.props.span },\n\t\t\t\t\t\t{ prop: \"__table-operation\", spanProp: props.props.span },\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t]),\n\t\ttableData: [],\n\t\ttableSpanData: computed(() => {\n\t\t\tif (state.spanColumns?.length > 0 && state.tableData?.length > 0) {\n\t\t\t\tconst result: Record<string, number[]> = {};\n\t\t\t\tconst spanIndexes: Record<string, number> = {};\n\t\t\t\tstate.spanColumns.forEach((item) => {\n\t\t\t\t\tresult[item.prop] = new Array<number>(state.tableData.length).fill(1, 0, 1).fill(0, 1);\n\t\t\t\t\tspanIndexes[item.prop] = 0;\n\t\t\t\t});\n\t\t\t\tfor (let i = 1; i < state.tableData.length; i++) {\n\t\t\t\t\tstate.spanColumns.forEach((item) => {\n\t\t\t\t\t\tconst currentRow = state.tableData[i];\n\t\t\t\t\t\tconst previousRow = state.tableData[i - 1];\n\t\t\t\t\t\tconst spanValues = result[item.prop];\n\t\t\t\t\t\tconst spanIndex = spanIndexes[item.prop];\n\t\t\t\t\t\tif (currentRow === undefined || previousRow === undefined || spanValues === undefined || spanIndex === undefined) return;\n\t\t\t\t\t\tif (currentRow[item.spanProp] === previousRow[item.spanProp]) {\n\t\t\t\t\t\t\tspanValues[spanIndex] = (spanValues[spanIndex] ?? 0) + 1;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tspanIndexes[item.prop] = i;\n\t\t\t\t\t\t\tspanValues[i] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\treturn {};\n\t\t}),\n\t\ttablePagination: {\n\t\t\tpageIndex: 1,\n\t\t\tpageSize: 20,\n\t\t\ttotalRows: 0,\n\t\t},\n\t\tinitParam: {},\n\t\tsearchParam: {},\n\t\tsearchValueUpdate: \"\",\n\t\tsearchForm: props.searchForm,\n\t\tselected: false,\n\t\tselectedList: [],\n\t\tselectedListIds: computed(() =>\n\t\t\tstate.selectedList.flatMap((item) => {\n\t\t\t\tconst rowKey: unknown = isFunction(props.rowKey) ? props.rowKey(item) : tableUtil.handleRowAccordingToProp(item, props.rowKey);\n\t\t\t\treturn typeof rowKey === \"string\" || typeof rowKey === \"number\" ? [rowKey] : [];\n\t\t\t})\n\t\t),\n\t\tindeterminateSelectedListIds: [],\n\t\toperationColumnWidth: computed(() => {\n\t\t\tconst findAutoCol = state.autoColumnWidth.find((f) => f.prop === \"__table-operation\");\n\t\t\tif (findAutoCol) {\n\t\t\t\treturn `${findAutoCol.width}px`;\n\t\t\t}\n\t\t\tswitch (_globalSize.value) {\n\t\t\t\tcase \"large\":\n\t\t\t\tcase \"default\":\n\t\t\t\t\treturn \"54px\";\n\t\t\t\tcase \"small\":\n\t\t\t\t\treturn \"42px\";\n\t\t\t\tdefault:\n\t\t\t\t\treturn \"auto\";\n\t\t\t}\n\t\t}),\n\t\timagePreview: false,\n\t\tpreviewList: [],\n\t\ttableWidth: 0,\n\t\ttableHeight: 0,\n\t\tautoColumnWidth: [],\n\t});\n\tlet requestVersion = 0;\n\n\tprovide(tableStateKey, state);\n\n\tconst handleTableColumnAutoWidth = (): void => {\n\t\tstate.loading = true;\n\t\tstate.loadingText = \"加载中...\";\n\t\tstate.autoColumnWidth = [];\n\t\tconst autoWidthColumns = state.tableColumns.filter((f) => f.autoWidth);\n\t\tif (slots?.operation) {\n\t\t\t// 操作列自动宽度\n\t\t\tautoWidthColumns.push({\n\t\t\t\tprop: \"__table-operation\",\n\t\t\t});\n\t\t}\n\t\tif (autoWidthColumns.length > 0) {\n\t\t\t// padding24/16 + border1\n\t\t\tconst otherWidth = _globalSize.value === \"default\" ? 25 : 17;\n\t\t\tvoid nextTick(() => {\n\t\t\t\tconst tableDom = document.querySelector(`.fa-table__${props.tableKey}`);\n\t\t\t\tif (tableDom) {\n\t\t\t\t\tautoWidthColumns.forEach((item) => {\n\t\t\t\t\t\tconst headerColumnDom = tableDom.querySelector(`.__fa-table__auto-width-column__cell-header__${item?.prop}`);\n\t\t\t\t\t\tconst cellColumnDoms = tableDom.querySelectorAll(`.__fa-table__auto-width-column__cell__${item?.prop}`);\n\t\t\t\t\t\tlet maxWidth = 0;\n\t\t\t\t\t\tif (headerColumnDom) {\n\t\t\t\t\t\t\tmaxWidth = Math.ceil(headerColumnDom.scrollWidth) + otherWidth;\n\t\t\t\t\t\t\tif (item?.sortable) {\n\t\t\t\t\t\t\t\tmaxWidth += 24;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcellColumnDoms.forEach((cellDom) => {\n\t\t\t\t\t\t\tconst curWidth = Math.ceil(cellDom.scrollWidth) + otherWidth;\n\t\t\t\t\t\t\tif (curWidth > maxWidth) {\n\t\t\t\t\t\t\t\tmaxWidth = curWidth;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst findInfo = state.autoColumnWidth.find((f) => f.prop === item?.prop);\n\t\t\t\t\t\tif (findInfo) {\n\t\t\t\t\t\t\tfindInfo.width = Math.max(findInfo.width, maxWidth);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (item.prop) {\n\t\t\t\t\t\t\t\tstate.autoColumnWidth.push({\n\t\t\t\t\t\t\t\t\tprop: item.prop,\n\t\t\t\t\t\t\t\t\twidth: maxWidth,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}).finally(() => {\n\t\t\t\tstate.loading = false;\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tstate.loading = false;\n\t};\n\n\tconst handleTableData = (data: DefaultRow[]): DefaultRow[] => {\n\t\tif (props.treeData) {\n\t\t\tconst result: DefaultRow[] = [];\n\t\t\tdata.forEach((row) => {\n\t\t\t\tconst rowList: unknown = row[props.props.children ?? \"children\"];\n\t\t\t\tif (isArray(rowList)) {\n\t\t\t\t\t// 如果 rowList 是数组,遍历并合并每个子项\n\t\t\t\t\tconst childRows: unknown[] = rowList;\n\t\t\t\t\tchildRows.forEach((childRow) => {\n\t\t\t\t\t\tresult.push(typeof childRow === \"object\" && childRow !== null ? { ...row, ...childRow } : row);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tresult.push(typeof rowList === \"object\" && rowList !== null ? { ...row, ...rowList } : row);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn result;\n\t\t} else {\n\t\t\treturn data;\n\t\t}\n\t};\n\n\tconst getRequestParam = (): PagedInput => {\n\t\tconst params = { ...state.searchParam, ...(props.pagination ? state.tablePagination : {}) };\n\t\t// 删除总条数\n\t\tdelete params.totalRows;\n\t\treturn params;\n\t};\n\n\tconst loadData = async (): Promise<void> => {\n\t\tconst currentRequestVersion = ++requestVersion;\n\t\tstate.loading = true;\n\t\tstate.loadingText = \"加载中...\";\n\t\tif (props.requestApi) {\n\t\t\tconst params = getRequestParam();\n\t\t\temit(\"refresh\", params);\n\t\t\tlet pageData: DefaultRow[];\n\t\t\ttry {\n\t\t\t\tconst resData = await props.requestApi(params);\n\t\t\t\tif (currentRequestVersion !== requestVersion) return;\n\t\t\t\t// 数据回调\n\t\t\t\tprops.dataCallback?.(resData);\n\t\t\t\t// 解析 API 接口返回的分页数据(如果有分页更新分页信息)\n\t\t\t\tif (props.pagination) {\n\t\t\t\t\tif (isArray(resData)) {\n\t\t\t\t\t\tpageData = resData;\n\t\t\t\t\t\tstate.tablePagination.totalRows = resData.length;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst pageRes = resData as PagedResult;\n\t\t\t\t\t\tpageData = pageRes.rows ?? [];\n\t\t\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\t\t\tpageIndex: pageRes.pageIndex ?? state.tablePagination.pageIndex,\n\t\t\t\t\t\t\tpageSize: pageRes.pageSize ?? state.tablePagination.pageSize,\n\t\t\t\t\t\t\ttotalRows: pageRes.totalRows ?? pageData.length,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tpageData = resData as DefaultRow[];\n\t\t\t\t\t// 更新分页信息\n\t\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\t\tpageIndex: 1,\n\t\t\t\t\t\tpageSize: 0,\n\t\t\t\t\t\ttotalRows: pageData.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tstate.tableData = handleTableData(pageData);\n\t\t\t} catch (error) {\n\t\t\t\tif (currentRequestVersion !== requestVersion) return;\n\t\t\t\tstate.tableData = [];\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\tif (currentRequestVersion === requestVersion) state.loading = false;\n\t\t\t}\n\t\t} else {\n\t\t\temit(\"refresh\", { searchValue: state.searchParam.searchValue });\n\t\t\tlet _value = handleTableData([...props.data]);\n\t\t\t_value = _value.filter((f) => {\n\t\t\t\tconst searchValue = state.searchParam.searchValue;\n\t\t\t\tif (typeof searchValue !== \"string\" || searchValue.length === 0) return true;\n\t\t\t\treturn state.tableColumns.some((col) => {\n\t\t\t\t\tconst value: unknown = tableUtil.handleRowAccordingToProp(f, col.prop ?? \"\");\n\t\t\t\t\tconst text =\n\t\t\t\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"bigint\" || typeof value === \"boolean\"\n\t\t\t\t\t\t\t? String(value)\n\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\treturn text.toLowerCase().includes(searchValue.toLowerCase());\n\t\t\t\t});\n\t\t\t});\n\t\t\tif (isArray(state.searchParam.sortList) && state.searchParam.sortList.length > 0) {\n\t\t\t\t_value = _value.sort(tableUtil.arrayDynamicSort(state.searchParam.sortList));\n\t\t\t}\n\t\t\tif (props.pagination) {\n\t\t\t\t// 更新分页信息\n\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\ttotalRows: _value.length,\n\t\t\t\t});\n\t\t\t\tconst pageStart = (state.tablePagination.pageIndex - 1) * state.tablePagination.pageSize;\n\t\t\t\tconst pageEnd = pageStart + state.tablePagination.pageSize;\n\t\t\t\tstate.tableData = _value.slice(pageStart, pageEnd);\n\t\t\t} else {\n\t\t\t\tstate.tableData = _value;\n\t\t\t\t// 更新分页信息\n\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\tpageIndex: 1,\n\t\t\t\t\tpageSize: 0,\n\t\t\t\t\ttotalRows: _value.length,\n\t\t\t\t});\n\t\t\t}\n\t\t\tstate.loading = false;\n\t\t}\n\t\thandleTableColumnAutoWidth();\n\t};\n\n\tconst cloneColumns = (columns: FaTableColumnCtx[]): FaTableColumnCtx[] =>\n\t\tcolumns.map((column) => ({\n\t\t\t...column,\n\t\t\t...(column.search && { search: { ...column.search, ...(column.search.props && { props: { ...column.search.props } }) } }),\n\t\t\t...(column._children && { _children: cloneColumns(column._children) }),\n\t\t}));\n\n\tconst loadTableColumns = (): void => {\n\t\tlet columns: FaTableColumnCtx[] = props.columns ? cloneColumns(props.columns) : [];\n\t\t// 默认值处理\n\t\tcolumns.forEach((col) => {\n\t\t\t// 处理搜索项的 key 和 label\n\t\t\tif (col.pureSearch || col.search) {\n\t\t\t\tcol.search ??= { el: \"\" };\n\t\t\t\tcol.search.key ??= col.prop;\n\t\t\t\tcol.search.label ??= col.label;\n\t\t\t\t// 处理默认值\n\t\t\t\tif (col.search.key && col.search.defaultValue !== undefined) {\n\t\t\t\t\tstate.searchParam[col.search.key] = col.search.defaultValue;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// 排序\n\t\tcolumns = columns.sort((a, b) => {\n\t\t\treturn (a.order ?? 0) - (b.order ?? 0);\n\t\t});\n\n\t\t// TODO:这里的扁平化暂时没用到\n\t\tstate.orgColumns = tableUtil.flatColumns(columns, enumMap);\n\t};\n\n\tconst handleSizeChange = (pageSize: number): void => {\n\t\tstate.tablePagination.pageIndex = 1;\n\t\tstate.tablePagination.pageSize = pageSize;\n\t\temit(\"sizeChange\", pageSize);\n\t\temit(\"paginationChange\", 1, pageSize);\n\t\tvoid loadData();\n\t};\n\tconst handlePaginationChange = (val: number): void => {\n\t\tstate.tablePagination.pageIndex = val;\n\t\temit(\"paginationChange\", val, state.tablePagination.pageSize);\n\t\tvoid loadData();\n\t};\n\n\tconst updatedTotalParam = (): void => {\n\t\t// 处理查询参数,可以给查询参数加自定义前缀操作\n\t\tconst newSearchParam: Record<string, unknown> = {};\n\t\t// 防止手动清空输入框携带参数(这里可以自定义查询参数前缀)\n\t\tfor (const key in state.searchParam) {\n\t\t\t// * 某些情况下参数为 false/0 也应该携带参数\n\t\t\tif (state.searchParam[key] || state.searchParam[key] === false || state.searchParam[key] === 0) {\n\t\t\t\tnewSearchParam[key] = state.searchParam[key];\n\t\t\t}\n\t\t\t// 处理某些情况下如果为空字符串,其实是不需要传到后端的\n\t\t\telse if (!state.searchParam[key]) {\n\t\t\t\tdelete state.searchParam[key];\n\t\t\t}\n\t\t}\n\t\tObject.assign(state.searchParam, newSearchParam);\n\t};\n\n\tconst defaultSearchTime = (): void => {\n\t\tif (props.hideSearchTime) {\n\t\t\tstate.searchParam.searchTimeList = undefined;\n\t\t} else {\n\t\t\tconst end = new Date();\n\t\t\tconst start = new Date();\n\t\t\tif (props.futureSearchTime) {\n\t\t\t\tswitch (props.dataSearchRange) {\n\t\t\t\t\tcase \"Past1D\":\n\t\t\t\t\t\tend.setDate(end.getDate() + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3D\":\n\t\t\t\t\t\tend.setDate(end.getDate() + 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1W\":\n\t\t\t\t\t\tend.setDate(end.getDate() + 7);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1M\":\n\t\t\t\t\t\tend.setMonth(end.getMonth() + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3M\":\n\t\t\t\t\t\tend.setMonth(end.getMonth() + 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past6M\":\n\t\t\t\t\t\tend.setMonth(end.getMonth() + 6);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1Y\":\n\t\t\t\t\t\tend.setFullYear(end.getFullYear() + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3Y\":\n\t\t\t\t\t\tend.setFullYear(end.getFullYear() + 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tswitch (props.dataSearchRange) {\n\t\t\t\t\tcase \"Past1D\":\n\t\t\t\t\t\tstart.setDate(start.getDate() - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3D\":\n\t\t\t\t\t\tstart.setDate(start.getDate() - 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1W\":\n\t\t\t\t\t\tstart.setDate(start.getDate() - 7);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1M\":\n\t\t\t\t\t\tstart.setMonth(start.getMonth() - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3M\":\n\t\t\t\t\t\tstart.setMonth(start.getMonth() - 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past6M\":\n\t\t\t\t\t\tstart.setMonth(start.getMonth() - 6);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1Y\":\n\t\t\t\t\t\tstart.setFullYear(start.getFullYear() - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3Y\":\n\t\t\t\t\t\tstart.setFullYear(start.getFullYear() - 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tstate.searchParam.searchTimeList = [dayjs(start).format(\"YYYY-MM-DD 00:00:00\"), dayjs(end).format(\"YYYY-MM-DD 23:59:59\")];\n\t\t}\n\t};\n\n\tconst tableSearch = async (): Promise<void> => {\n\t\t// 重置到第一页\n\t\tstate.tablePagination.pageIndex = 1;\n\t\tupdatedTotalParam();\n\t\tawait loadData();\n\t};\n\tconst renderTable = debounce((): Promise<void> => {\n\t\tloadTableColumns();\n\t\treturn tableSearch();\n\t}, 300);\n\n\tconst tableReset = async (): Promise<void> => {\n\t\t// 重置到第一页\n\t\tstate.tablePagination.pageIndex = 1;\n\t\t// 清除搜索条件\n\t\tstate.searchParam = {};\n\t\tdefaultSearchTime();\n\t\t// 重置搜索表单的时候,如果有默认搜索参数,则重置默认的搜索参数\n\t\tif (typeof state.initParam === \"object\" && state.initParam !== null) {\n\t\t\tObject.assign(state.searchParam, state.initParam);\n\t\t}\n\t\temit(\"reset\", state.searchParam);\n\t\tawait loadData();\n\t};\n\n\tconst doRender = async (): Promise<void> => {\n\t\tstate.orgColumns = [];\n\t\tstate.autoColumnWidth = [];\n\t\tstate.tableData = [];\n\t\tawait renderTable();\n\t};\n\n\tconst doLoading = async (loadingFunction: () => void | Promise<void>, loadingText = \"加载中...\"): Promise<void> => {\n\t\tstate.loading = true;\n\t\tstate.loadingText = loadingText;\n\t\ttry {\n\t\t\tawait callOptionalFunction(loadingFunction);\n\t\t} finally {\n\t\t\tstate.loading = false;\n\t\t}\n\t};\n\n\tconst handleCustomCellClick = (\n\t\temitName: string,\n\t\t{ row, column, $index }: { row: DefaultRow; column: FaTableColumnCtx; $index: number }\n\t): void => {\n\t\temit(\"customCellClick\", emitName, { row, column, $index, ...getTableDefaultSlots(state) });\n\t};\n\n\twatch(\n\t\t() => props.tableKey,\n\t\t() => doRender()\n\t);\n\n\twatch(\n\t\t() => props.searchForm,\n\t\t(newValue) => {\n\t\t\tstate.searchForm = newValue;\n\t\t}\n\t);\n\n\treturn {\n\t\t_globalSize,\n\t\tstate,\n\t\telementRef,\n\t\ttableRef,\n\t\thandleTableColumnAutoWidth,\n\t\tgetRequestParam,\n\t\tloadTableColumns,\n\t\thandleSizeChange,\n\t\thandlePaginationChange,\n\t\tdefaultSearchTime,\n\t\ttableSearch,\n\t\ttableReset,\n\t\tdoRender,\n\t\tdoLoading,\n\t\thandleCustomCellClick,\n\t};\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,gBAA4C,OAAO,YAAY;;AAE5E,MAAa,aAAgE,OAAO,SAAS;;;;;;;;;AA8B7F,MAAa,YACZ,OACA,OACA,SACqB;CACrB,MAAM,cAAc,cAAc;CAElC,MAAM,aAAa,IAAiB;CACpC,MAAM,WAAW,IAAmB;;;;CAKpC,MAAM,UAAU,yBAAS,IAAI,IAAoC,CAAC;CAClE,QAAQ,YAAY,OAAO;CAE3B,MAAM,QAAsB,SAAS;EACpC,SAAS;EACT,aAAa;EACb,YAAY,CAAC;EACb,cAAc,eAAe,MAAM,WAAW,QAAQ,MAAM,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC;EACpF,eAAe,eACd,MAAM,WACJ,QAAQ,SAAS,KAAK,eAAe,QAAQ,KAAK,WAAW,KAAA,CAAS,CAAC,CACvE,MAAM,GAAG,MAAM;GACf,QAAQ,EAAE,QAAQ,SAAS,MAAM,EAAE,QAAQ,SAAS;EACrD,CAAC,CACH;EACA,aAAa,eAAe,CAC3B,GAAG,MAAM,WAAW,SAAS,WAAY,OAAO,WAAW,CAAC;GAAE,MAAM,OAAO,QAAQ;GAAI,UAAU,OAAO;EAAS,CAAC,IAAI,CAAC,CAAE,GACzH,GAAI,MAAM,MAAM,OACb;GACA;IAAE,MAAM;IAAiB,UAAU,MAAM,MAAM;GAAK;GACpD;IAAE,MAAM;IAAqB,UAAU,MAAM,MAAM;GAAK;GACxD;IAAE,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BAAmB,UAAU;GAAE;GAAK;GAAQ;GAAQ,GAAG,qBAAqB,KAAK;EAAE,CAAC;CAC1F;CAEA,YACO,MAAM,gBACN,SAAS,CAChB;CAEA,YACO,MAAM,aACX,aAAa;EACb,MAAM,aAAa;CACpB,CACD;CAEA,OAAO;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"useTable.mjs","names":[],"sources":["../../../../src/components/table/src/useTable.ts"],"sourcesContent":["import { computed, nextTick, provide, reactive, shallowRef, watch } from \"vue\";\nimport { dayjs, useGlobalSize } from \"element-plus\";\nimport { callOptionalFunction, debounce } from \"../../../utils\";\nimport { tableUtil } from \"../utils/table\";\nimport { getTableDefaultSlots } from \"./table.type\";\nimport type { TableInstance } from \"element-plus\";\nimport type { ExtractPropTypes, InjectionKey, SetupContext, ShallowRef } from \"vue\";\nimport type { makeSlots } from \"../../../utils\";\nimport type { PagedInput, PagedResult } from \"./page.type\";\nimport type { FaTableSlots, faTableEmits, faTableProps } from \"./table\";\nimport type { DefaultRow, FaTableState } from \"./table.state\";\nimport type { FaTableColumnCtx, FaTableEnumColumnCtx } from \"./table.type\";\n\n/** FaTable 状态的依赖注入键。 */\nexport const tableStateKey: InjectionKey<FaTableState> = Symbol(\"tableState\");\n/** FaTable 枚举映射的依赖注入键。 */\nexport const enumMapKey: InjectionKey<Map<string, FaTableEnumColumnCtx[]>> = Symbol(\"enumMap\");\n\ntype TableSetupContext = SetupContext<typeof faTableEmits, ReturnType<typeof makeSlots<FaTableSlots>>>;\n\ninterface TableComposable {\n\tglobalSize: ReturnType<typeof useGlobalSize>;\n\tstate: FaTableState;\n\telementRef: Readonly<ShallowRef<HTMLElement | null>>;\n\ttableRef: Readonly<ShallowRef<TableInstance | null>>;\n\thandleTableColumnAutoWidth: () => void;\n\tgetRequestParam: () => PagedInput;\n\tloadTableColumns: () => void;\n\thandleSizeChange: (pageSize: number) => void;\n\thandlePaginationChange: (value: number) => void;\n\tdefaultSearchTime: () => void;\n\ttableSearch: () => Promise<void>;\n\ttableReset: () => Promise<void>;\n\tdoRender: () => Promise<void>;\n\tdoLoading: (loadingFunction: () => void | Promise<void>, loadingText?: string) => Promise<void>;\n\thandleCustomCellClick: (emitName: string, context: { row: DefaultRow; column: FaTableColumnCtx; $index: number }) => void;\n}\n\n/**\n * 创建 FaTable 的状态和操作方法。\n *\n * @param props - FaTable 的 Props。\n * @param slots - FaTable 的插槽。\n * @param emit - FaTable 的事件触发器。\n * @returns FaTable 的状态、引用和操作方法。\n */\nexport const useTable = (\n\tprops: ExtractPropTypes<typeof faTableProps>,\n\tslots: TableSetupContext[\"slots\"],\n\temit: TableSetupContext[\"emit\"]\n): TableComposable => {\n\tconst globalSize = useGlobalSize();\n\n\tconst elementRef = shallowRef<HTMLElement | null>(null);\n\tconst tableRef = shallowRef<TableInstance | null>(null);\n\n\t/**\n\t * 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)\n\t */\n\tconst enumMap = reactive(new Map<string, FaTableEnumColumnCtx[]>());\n\tprovide(enumMapKey, enumMap);\n\n\tconst state: FaTableState = reactive({\n\t\tloading: false,\n\t\tloadingText: \"加载中...\",\n\t\torgColumns: [],\n\t\ttableColumns: computed(() => state.orgColumns.filter((f) => f.prop && !f.pureSearch)),\n\t\tsearchColumns: computed(() =>\n\t\t\tstate.orgColumns\n\t\t\t\t.filter((item) => item.pureSearch === true || item.search !== undefined)\n\t\t\t\t.sort((a, b) => {\n\t\t\t\t\treturn (a.search?.order ?? 0) - (b.search?.order ?? 0);\n\t\t\t\t})\n\t\t),\n\t\tspanColumns: computed(() => [\n\t\t\t...state.orgColumns.flatMap((column) => (column.spanProp ? [{ prop: column.prop ?? \"\", spanProp: column.spanProp }] : [])),\n\t\t\t...(props.props.span\n\t\t\t\t? [\n\t\t\t\t\t\t{ prop: \"__table-index\", spanProp: props.props.span },\n\t\t\t\t\t\t{ prop: \"__table-selection\", spanProp: props.props.span },\n\t\t\t\t\t\t{ prop: \"__table-operation\", spanProp: props.props.span },\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t]),\n\t\ttableData: [],\n\t\ttableSpanData: computed(() => {\n\t\t\tif (state.spanColumns.length > 0 && state.tableData.length > 0) {\n\t\t\t\tconst result: Record<string, number[]> = {};\n\t\t\t\tconst spanIndexes: Record<string, number> = {};\n\t\t\t\tstate.spanColumns.forEach((item) => {\n\t\t\t\t\tresult[item.prop] = new Array<number>(state.tableData.length).fill(1, 0, 1).fill(0, 1);\n\t\t\t\t\tspanIndexes[item.prop] = 0;\n\t\t\t\t});\n\t\t\t\tfor (let i = 1; i < state.tableData.length; i++) {\n\t\t\t\t\tstate.spanColumns.forEach((item) => {\n\t\t\t\t\t\tconst currentRow = state.tableData[i];\n\t\t\t\t\t\tconst previousRow = state.tableData[i - 1];\n\t\t\t\t\t\tconst spanValues = result[item.prop];\n\t\t\t\t\t\tconst spanIndex = spanIndexes[item.prop];\n\t\t\t\t\t\tif (currentRow === undefined || previousRow === undefined || spanValues === undefined || spanIndex === undefined) return;\n\t\t\t\t\t\tif (currentRow[item.spanProp] === previousRow[item.spanProp]) {\n\t\t\t\t\t\t\tspanValues[spanIndex] = (spanValues[spanIndex] ?? 0) + 1;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tspanIndexes[item.prop] = i;\n\t\t\t\t\t\t\tspanValues[i] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\treturn {};\n\t\t}),\n\t\ttablePagination: {\n\t\t\tpageIndex: 1,\n\t\t\tpageSize: 20,\n\t\t\ttotalRows: 0,\n\t\t},\n\t\tinitParam: {},\n\t\tsearchParam: {},\n\t\tsearchValueUpdate: \"\",\n\t\tsearchForm: props.searchForm,\n\t\tselected: false,\n\t\tselectedList: [],\n\t\tselectedListIds: computed(() =>\n\t\t\tstate.selectedList.flatMap((item) => {\n\t\t\t\tconst rowKey: unknown =\n\t\t\t\t\ttypeof props.rowKey === \"function\" ? props.rowKey(item) : tableUtil.handleRowAccordingToProp(item, props.rowKey);\n\t\t\t\treturn typeof rowKey === \"string\" || typeof rowKey === \"number\" ? [rowKey] : [];\n\t\t\t})\n\t\t),\n\t\tindeterminateSelectedListIds: [],\n\t\toperationColumnWidth: computed(() => {\n\t\t\tconst findAutoCol = state.autoColumnWidth.find((f) => f.prop === \"__table-operation\");\n\t\t\tif (findAutoCol) {\n\t\t\t\treturn `${findAutoCol.width}px`;\n\t\t\t}\n\t\t\tswitch (globalSize.value) {\n\t\t\t\tcase \"large\":\n\t\t\t\tcase \"default\":\n\t\t\t\t\treturn \"54px\";\n\t\t\t\tcase \"small\":\n\t\t\t\t\treturn \"42px\";\n\t\t\t\tcase \"\":\n\t\t\t\tdefault:\n\t\t\t\t\treturn \"auto\";\n\t\t\t}\n\t\t}),\n\t\timagePreview: false,\n\t\tpreviewList: [],\n\t\ttableWidth: 0,\n\t\ttableHeight: 0,\n\t\tautoColumnWidth: [],\n\t});\n\tlet requestVersion = 0;\n\n\tprovide(tableStateKey, state);\n\n\tconst handleTableColumnAutoWidth = (): void => {\n\t\tstate.loading = true;\n\t\tstate.loadingText = \"加载中...\";\n\t\tstate.autoColumnWidth = [];\n\t\tconst autoWidthColumns = state.tableColumns.filter((f) => f.autoWidth);\n\t\tif (slots.operation) {\n\t\t\t// 操作列自动宽度\n\t\t\tautoWidthColumns.push({\n\t\t\t\tprop: \"__table-operation\",\n\t\t\t});\n\t\t}\n\t\tif (autoWidthColumns.length > 0) {\n\t\t\t// padding24/16 + border1\n\t\t\tconst otherWidth = globalSize.value === \"default\" ? 25 : 17;\n\t\t\tnextTick(() => {\n\t\t\t\tconst tableDom = document.querySelector(`.fa-table__${props.tableKey}`);\n\t\t\t\tif (tableDom) {\n\t\t\t\t\tautoWidthColumns.forEach((item) => {\n\t\t\t\t\t\tconst headerColumnDom = tableDom.querySelector(`.__fa-table__auto-width-column__cell-header__${item.prop}`);\n\t\t\t\t\t\tconst cellColumnDoms = tableDom.querySelectorAll(`.__fa-table__auto-width-column__cell__${item.prop}`);\n\t\t\t\t\t\tlet maxWidth = 0;\n\t\t\t\t\t\tif (headerColumnDom) {\n\t\t\t\t\t\t\tmaxWidth = Math.ceil(headerColumnDom.scrollWidth) + otherWidth;\n\t\t\t\t\t\t\tif (item.sortable) {\n\t\t\t\t\t\t\t\tmaxWidth += 24;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcellColumnDoms.forEach((cellDom) => {\n\t\t\t\t\t\t\tconst curWidth = Math.ceil(cellDom.scrollWidth) + otherWidth;\n\t\t\t\t\t\t\tif (curWidth > maxWidth) {\n\t\t\t\t\t\t\t\tmaxWidth = curWidth;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst autoWidthEntry = state.autoColumnWidth.find((f) => f.prop === item.prop);\n\t\t\t\t\t\tif (autoWidthEntry) {\n\t\t\t\t\t\t\tautoWidthEntry.width = Math.max(autoWidthEntry.width, maxWidth);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (item.prop) {\n\t\t\t\t\t\t\t\tstate.autoColumnWidth.push({\n\t\t\t\t\t\t\t\t\tprop: item.prop,\n\t\t\t\t\t\t\t\t\twidth: maxWidth,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}).finally(() => {\n\t\t\t\tstate.loading = false;\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tstate.loading = false;\n\t};\n\n\tconst handleTableData = (data: DefaultRow[]): DefaultRow[] => {\n\t\tif (props.treeData) {\n\t\t\tconst result: DefaultRow[] = [];\n\t\t\tdata.forEach((row) => {\n\t\t\t\tconst rowList: unknown = row[props.props.children ?? \"children\"];\n\t\t\t\tif (Array.isArray(rowList)) {\n\t\t\t\t\t// 如果 rowList 是数组,遍历并合并每个子项\n\t\t\t\t\tconst childRows: unknown[] = rowList;\n\t\t\t\t\tchildRows.forEach((childRow) => {\n\t\t\t\t\t\tresult.push(typeof childRow === \"object\" && childRow !== null ? { ...row, ...childRow } : row);\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tresult.push(typeof rowList === \"object\" && rowList !== null ? { ...row, ...rowList } : row);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn result;\n\t\t} else {\n\t\t\treturn data;\n\t\t}\n\t};\n\n\tconst getRequestParam = (): PagedInput => {\n\t\tconst params = { ...state.searchParam, ...(props.pagination ? state.tablePagination : {}) };\n\t\t// 删除总条数\n\t\tdelete params.totalRows;\n\t\treturn params;\n\t};\n\n\tconst loadData = async (): Promise<void> => {\n\t\tconst currentRequestVersion = ++requestVersion;\n\t\tstate.loading = true;\n\t\tstate.loadingText = \"加载中...\";\n\t\tif (props.requestApi) {\n\t\t\tconst params = getRequestParam();\n\t\t\temit(\"refresh\", params);\n\t\t\tlet pageData: DefaultRow[];\n\t\t\ttry {\n\t\t\t\tconst resData = await props.requestApi(params);\n\t\t\t\tif (currentRequestVersion !== requestVersion) return;\n\t\t\t\t// 数据回调\n\t\t\t\tprops.dataCallback?.(resData);\n\t\t\t\t// 解析 API 接口返回的分页数据(如果有分页更新分页信息)\n\t\t\t\tif (props.pagination) {\n\t\t\t\t\tif (Array.isArray(resData)) {\n\t\t\t\t\t\tpageData = resData;\n\t\t\t\t\t\tstate.tablePagination.totalRows = resData.length;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst pageRes = resData as PagedResult;\n\t\t\t\t\t\tpageData = pageRes.rows ?? [];\n\t\t\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\t\t\tpageIndex: pageRes.pageIndex ?? state.tablePagination.pageIndex,\n\t\t\t\t\t\t\tpageSize: pageRes.pageSize ?? state.tablePagination.pageSize,\n\t\t\t\t\t\t\ttotalRows: pageRes.totalRows ?? pageData.length,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tpageData = resData as DefaultRow[];\n\t\t\t\t\t// 更新分页信息\n\t\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\t\tpageIndex: 1,\n\t\t\t\t\t\tpageSize: 0,\n\t\t\t\t\t\ttotalRows: pageData.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tstate.tableData = handleTableData(pageData);\n\t\t\t} catch (error) {\n\t\t\t\tif (currentRequestVersion !== requestVersion) return;\n\t\t\t\tstate.tableData = [];\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\tif (currentRequestVersion === requestVersion) state.loading = false;\n\t\t\t}\n\t\t} else {\n\t\t\temit(\"refresh\", { searchValue: state.searchParam.searchValue });\n\t\t\tlet _value = handleTableData([...props.data]);\n\t\t\t_value = _value.filter((f) => {\n\t\t\t\tconst searchValue = state.searchParam.searchValue;\n\t\t\t\tif (typeof searchValue !== \"string\" || searchValue.length === 0) return true;\n\t\t\t\treturn state.tableColumns.some((col) => {\n\t\t\t\t\tconst value: unknown = tableUtil.handleRowAccordingToProp(f, col.prop ?? \"\");\n\t\t\t\t\tconst text =\n\t\t\t\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"bigint\" || typeof value === \"boolean\"\n\t\t\t\t\t\t\t? String(value)\n\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\treturn text.toLowerCase().includes(searchValue.toLowerCase());\n\t\t\t\t});\n\t\t\t});\n\t\t\tif (Array.isArray(state.searchParam.sortList) && state.searchParam.sortList.length > 0) {\n\t\t\t\t_value = _value.sort(tableUtil.arrayDynamicSort(state.searchParam.sortList));\n\t\t\t}\n\t\t\tif (props.pagination) {\n\t\t\t\t// 更新分页信息\n\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\ttotalRows: _value.length,\n\t\t\t\t});\n\t\t\t\tconst pageStart = (state.tablePagination.pageIndex - 1) * state.tablePagination.pageSize;\n\t\t\t\tconst pageEnd = pageStart + state.tablePagination.pageSize;\n\t\t\t\tstate.tableData = _value.slice(pageStart, pageEnd);\n\t\t\t} else {\n\t\t\t\tstate.tableData = _value;\n\t\t\t\t// 更新分页信息\n\t\t\t\tObject.assign(state.tablePagination, {\n\t\t\t\t\tpageIndex: 1,\n\t\t\t\t\tpageSize: 0,\n\t\t\t\t\ttotalRows: _value.length,\n\t\t\t\t});\n\t\t\t}\n\t\t\tstate.loading = false;\n\t\t}\n\t\thandleTableColumnAutoWidth();\n\t};\n\n\tconst cloneColumns = (columns: FaTableColumnCtx[]): FaTableColumnCtx[] =>\n\t\tcolumns.map((column) => ({\n\t\t\t...column,\n\t\t\t...(column.search && { search: { ...column.search, ...(column.search.props && { props: { ...column.search.props } }) } }),\n\t\t\t...(column._children && { _children: cloneColumns(column._children) }),\n\t\t}));\n\n\tconst loadTableColumns = (): void => {\n\t\tlet columns: FaTableColumnCtx[] = props.columns ? cloneColumns(props.columns) : [];\n\t\t// 默认值处理\n\t\tcolumns.forEach((col) => {\n\t\t\t// 处理搜索项的 key 和 label\n\t\t\tif (col.pureSearch || col.search) {\n\t\t\t\tcol.search ??= { el: \"\" };\n\t\t\t\tcol.search.key ??= col.prop;\n\t\t\t\tcol.search.label ??= col.label;\n\t\t\t\t// 处理默认值\n\t\t\t\tif (col.search.key && col.search.defaultValue !== undefined) {\n\t\t\t\t\tstate.searchParam[col.search.key] = col.search.defaultValue;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// 排序\n\t\tcolumns = columns.sort((a, b) => {\n\t\t\treturn (a.order ?? 0) - (b.order ?? 0);\n\t\t});\n\n\t\t// TODO:这里的扁平化暂时没用到\n\t\tstate.orgColumns = tableUtil.flatColumns(columns, enumMap);\n\t};\n\n\tconst handleSizeChange = (pageSize: number): void => {\n\t\tstate.tablePagination.pageIndex = 1;\n\t\tstate.tablePagination.pageSize = pageSize;\n\t\temit(\"sizeChange\", pageSize);\n\t\temit(\"paginationChange\", 1, pageSize);\n\t\tloadData();\n\t};\n\tconst handlePaginationChange = (val: number): void => {\n\t\tstate.tablePagination.pageIndex = val;\n\t\temit(\"paginationChange\", val, state.tablePagination.pageSize);\n\t\tloadData();\n\t};\n\n\tconst updatedTotalParam = (): void => {\n\t\t// 处理查询参数,可以给查询参数加自定义前缀操作\n\t\tconst newSearchParam: Record<string, unknown> = {};\n\t\t// 防止手动清空输入框携带参数(这里可以自定义查询参数前缀)\n\t\tfor (const key in state.searchParam) {\n\t\t\t// * 某些情况下参数为 false/0 也应该携带参数\n\t\t\tif (state.searchParam[key] || state.searchParam[key] === false || state.searchParam[key] === 0) {\n\t\t\t\tnewSearchParam[key] = state.searchParam[key];\n\t\t\t}\n\t\t\t// 处理某些情况下如果为空字符串,其实是不需要传到后端的\n\t\t\telse if (!state.searchParam[key]) {\n\t\t\t\tdelete state.searchParam[key];\n\t\t\t}\n\t\t}\n\t\tObject.assign(state.searchParam, newSearchParam);\n\t};\n\n\tconst defaultSearchTime = (): void => {\n\t\tif (props.hideSearchTime) {\n\t\t\tstate.searchParam.searchTimeList = undefined;\n\t\t} else {\n\t\t\tconst end = new Date();\n\t\t\tconst start = new Date();\n\t\t\tif (props.futureSearchTime) {\n\t\t\t\tswitch (props.dataSearchRange) {\n\t\t\t\t\tcase \"Past1D\":\n\t\t\t\t\t\tend.setDate(end.getDate() + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3D\":\n\t\t\t\t\t\tend.setDate(end.getDate() + 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1W\":\n\t\t\t\t\t\tend.setDate(end.getDate() + 7);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1M\":\n\t\t\t\t\t\tend.setMonth(end.getMonth() + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3M\":\n\t\t\t\t\t\tend.setMonth(end.getMonth() + 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past6M\":\n\t\t\t\t\t\tend.setMonth(end.getMonth() + 6);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1Y\":\n\t\t\t\t\t\tend.setFullYear(end.getFullYear() + 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3Y\":\n\t\t\t\t\t\tend.setFullYear(end.getFullYear() + 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tswitch (props.dataSearchRange) {\n\t\t\t\t\tcase \"Past1D\":\n\t\t\t\t\t\tstart.setDate(start.getDate() - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3D\":\n\t\t\t\t\t\tstart.setDate(start.getDate() - 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1W\":\n\t\t\t\t\t\tstart.setDate(start.getDate() - 7);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1M\":\n\t\t\t\t\t\tstart.setMonth(start.getMonth() - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3M\":\n\t\t\t\t\t\tstart.setMonth(start.getMonth() - 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past6M\":\n\t\t\t\t\t\tstart.setMonth(start.getMonth() - 6);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past1Y\":\n\t\t\t\t\t\tstart.setFullYear(start.getFullYear() - 1);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"Past3Y\":\n\t\t\t\t\t\tstart.setFullYear(start.getFullYear() - 3);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tstate.searchParam.searchTimeList = [dayjs(start).format(\"YYYY-MM-DD 00:00:00\"), dayjs(end).format(\"YYYY-MM-DD 23:59:59\")];\n\t\t}\n\t};\n\n\tconst tableSearch = async (): Promise<void> => {\n\t\t// 重置到第一页\n\t\tstate.tablePagination.pageIndex = 1;\n\t\tupdatedTotalParam();\n\t\tawait loadData();\n\t};\n\tconst renderTable = debounce((): Promise<void> => {\n\t\tloadTableColumns();\n\t\treturn tableSearch();\n\t}, 300);\n\n\tconst tableReset = async (): Promise<void> => {\n\t\t// 重置到第一页\n\t\tstate.tablePagination.pageIndex = 1;\n\t\t// 清除搜索条件\n\t\tstate.searchParam = {};\n\t\tdefaultSearchTime();\n\t\t// 重置搜索表单的时候,如果有默认搜索参数,则重置默认的搜索参数\n\t\tObject.assign(state.searchParam, state.initParam);\n\t\temit(\"reset\", state.searchParam);\n\t\tawait loadData();\n\t};\n\n\tconst doRender = async (): Promise<void> => {\n\t\tstate.orgColumns = [];\n\t\tstate.autoColumnWidth = [];\n\t\tstate.tableData = [];\n\t\tawait renderTable();\n\t};\n\n\tconst doLoading = async (loadingFunction: () => void | Promise<void>, loadingText = \"加载中...\"): Promise<void> => {\n\t\tstate.loading = true;\n\t\tstate.loadingText = loadingText;\n\t\ttry {\n\t\t\tawait callOptionalFunction(loadingFunction);\n\t\t} finally {\n\t\t\tstate.loading = false;\n\t\t}\n\t};\n\n\tconst handleCustomCellClick = (\n\t\temitName: string,\n\t\t{ row, column, $index }: { row: DefaultRow; column: FaTableColumnCtx; $index: number }\n\t): void => {\n\t\temit(\"customCellClick\", emitName, { row, column, $index, ...getTableDefaultSlots(state) });\n\t};\n\n\twatch(\n\t\t() => props.tableKey,\n\t\t() => doRender()\n\t);\n\n\twatch(\n\t\t() => props.searchForm,\n\t\t(newValue) => {\n\t\t\tstate.searchForm = newValue;\n\t\t}\n\t);\n\n\treturn {\n\t\tglobalSize,\n\t\tstate,\n\t\telementRef,\n\t\ttableRef,\n\t\thandleTableColumnAutoWidth,\n\t\tgetRequestParam,\n\t\tloadTableColumns,\n\t\thandleSizeChange,\n\t\thandlePaginationChange,\n\t\tdefaultSearchTime,\n\t\ttableSearch,\n\t\ttableReset,\n\t\tdoRender,\n\t\tdoLoading,\n\t\thandleCustomCellClick,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
|
//#region src/components/table/utils/table.ts
|
|
3
2
|
/**
|
|
4
3
|
* 表格工具类
|
|
@@ -9,7 +8,7 @@ const tableUtil = {
|
|
|
9
8
|
* @param {String} callValue 需要处理的值
|
|
10
9
|
*/
|
|
11
10
|
formatValue(callValue) {
|
|
12
|
-
if (isArray(callValue)) return callValue.length ? callValue.join(` , `) : null;
|
|
11
|
+
if (Array.isArray(callValue)) return callValue.length ? callValue.join(` , `) : null;
|
|
13
12
|
return callValue;
|
|
14
13
|
},
|
|
15
14
|
/**
|
|
@@ -44,8 +43,7 @@ const tableUtil = {
|
|
|
44
43
|
filterEnum(callValue, enumData, fieldNames, type) {
|
|
45
44
|
const value = fieldNames?.value ?? "value";
|
|
46
45
|
const label = fieldNames?.label ?? "label";
|
|
47
|
-
|
|
48
|
-
if (isArray(enumData)) filterData = enumData.find((item) => item[value] === callValue);
|
|
46
|
+
const filterData = enumData.find((item) => item[value] === callValue);
|
|
49
47
|
if (type === "tag") return filterData?.type ?? "info";
|
|
50
48
|
return filterData ? filterData[label] : null;
|
|
51
49
|
},
|
|
@@ -54,7 +52,7 @@ const tableUtil = {
|
|
|
54
52
|
*/
|
|
55
53
|
arrayDynamicSort(sortList) {
|
|
56
54
|
return (a, b) => {
|
|
57
|
-
if (sortList
|
|
55
|
+
if (sortList.length > 0) for (const condition of sortList) {
|
|
58
56
|
const property = condition.enField;
|
|
59
57
|
const order = condition.mode;
|
|
60
58
|
if (!property) continue;
|
|
@@ -84,8 +82,8 @@ const tableUtil = {
|
|
|
84
82
|
*/
|
|
85
83
|
setEnumMap(columnEnum, prop, enumMap) {
|
|
86
84
|
if (!columnEnum) return;
|
|
87
|
-
if (
|
|
88
|
-
else if (isArray(columnEnum)) enumMap.set(prop, columnEnum);
|
|
85
|
+
if (typeof columnEnum === "function") enumMap.set(prop, columnEnum());
|
|
86
|
+
else if (Array.isArray(columnEnum)) enumMap.set(prop, columnEnum);
|
|
89
87
|
},
|
|
90
88
|
/**
|
|
91
89
|
* 扁平化 columns
|
|
@@ -97,7 +95,7 @@ const tableUtil = {
|
|
|
97
95
|
flatArr.push(col);
|
|
98
96
|
col.show ??= true;
|
|
99
97
|
let enumKey = col.prop ?? col.search?.key;
|
|
100
|
-
if (col.enum &&
|
|
98
|
+
if (col.enum && typeof col.enum === "string") enumKey = col.enum;
|
|
101
99
|
if (col.enum && enumKey && enumMap) this.setEnumMap(col.enum, enumKey, enumMap);
|
|
102
100
|
});
|
|
103
101
|
return flatArr.filter((item) => !item._children?.length);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.mjs","names":[],"sources":["../../../../src/components/table/utils/table.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"table.mjs","names":[],"sources":["../../../../src/components/table/utils/table.ts"],"sourcesContent":["import type { PagedSortInput } from \"../src/page.type\";\nimport type { DefaultRow } from \"../src/table.state\";\nimport type { FaTableColumnCtx, FaTableEnumColumnCtx, FaTableEnumColumnType } from \"../src/table.type\";\n\n/**\n * 表格工具类\n */\nexport const tableUtil = {\n\t/**\n\t * @description 处理无数据情况\n\t * @param {String} callValue 需要处理的值\n\t */\n\tformatValue(callValue: unknown): unknown {\n\t\t// 如果当前值为数组,使用 / 拼接(根据需求自定义)\n\t\tif (Array.isArray(callValue)) return callValue.length ? callValue.join(` , `) : null;\n\t\treturn callValue;\n\t},\n\t/**\n\t * @description 处理 prop 为多级嵌套的情况(列如: prop:user.name)\n\t * @param {Object} row 当前行数据\n\t * @param {String} prop 当前 prop\n\t */\n\thandleRowAccordingToProp(row: DefaultRow, prop: string): unknown {\n\t\tlet value: unknown = row;\n\t\tfor (const item of prop.split(\".\")) {\n\t\t\tif (typeof value !== \"object\" || value === null) return undefined;\n\t\t\tvalue = (value as Record<string, unknown>)[item];\n\t\t}\n\t\treturn value;\n\t},\n\t/**\n\t * @description 处理 prop,当 prop 为多级嵌套时 ==> 返回最后一级 prop\n\t * @param {String} prop 当前 prop\n\t */\n\thandleProp(prop: string): string {\n\t\tconst propArr = prop.split(\".\");\n\t\tif (propArr.length === 1) return prop;\n\t\treturn propArr.at(-1) ?? prop;\n\t},\n\t/**\n\t * @description 根据枚举列表查询当需要的数据(如果指定了 label 和 value 的 key值,会自动识别格式化)\n\t * @param {String} callValue 当前单元格值\n\t * @param {Array} enumData 字典列表\n\t * @param {Array} fieldNames 指定 label && value 的 key 值\n\t * @param {String} type 过滤类型(目前只有 tag)\n\t */\n\tfilterEnum(callValue: unknown, enumData: FaTableEnumColumnCtx[], fieldNames?: { label: string; value: string }, type?: \"tag\"): unknown {\n\t\tconst value = fieldNames?.value ?? \"value\";\n\t\tconst label = fieldNames?.label ?? \"label\";\n\t\tconst filterData = enumData.find((item) => item[value] === callValue);\n\t\tif (type === \"tag\") {\n\t\t\treturn filterData?.type ?? \"info\";\n\t\t}\n\t\treturn filterData ? filterData[label] : null;\n\t},\n\t/**\n\t * 数组动态排序\n\t */\n\tarrayDynamicSort(sortList: PagedSortInput[]): (a: DefaultRow, b: DefaultRow) => number {\n\t\treturn (a, b) => {\n\t\t\tif (sortList.length > 0) {\n\t\t\t\tfor (const condition of sortList) {\n\t\t\t\t\tconst property = condition.enField;\n\t\t\t\t\tconst order = condition.mode;\n\t\t\t\t\tif (!property) continue;\n\n\t\t\t\t\tconst aValue: unknown = a[property];\n\t\t\t\t\tconst bValue: unknown = b[property];\n\n\t\t\t\t\tif (typeof aValue === \"string\" && typeof bValue === \"string\") {\n\t\t\t\t\t\tif (order === \"ascending\") {\n\t\t\t\t\t\t\tconst comparison = aValue.localeCompare(bValue, \"zh-CN\");\n\t\t\t\t\t\t\tif (comparison !== 0) {\n\t\t\t\t\t\t\t\treturn comparison;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else if (order === \"descending\") {\n\t\t\t\t\t\t\tconst comparison = bValue.localeCompare(aValue, \"zh-CN\");\n\t\t\t\t\t\t\tif (comparison !== 0) {\n\t\t\t\t\t\t\t\treturn comparison;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (order === \"ascending\") {\n\t\t\t\t\t\t\tif ((aValue as string) < (bValue as string)) return -1;\n\t\t\t\t\t\t\tif ((aValue as string) > (bValue as string)) return 1;\n\t\t\t\t\t\t} else if (order === \"descending\") {\n\t\t\t\t\t\t\tif ((aValue as string) > (bValue as string)) return -1;\n\t\t\t\t\t\t\tif ((aValue as string) < (bValue as string)) return 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn 0;\n\t\t};\n\t},\n\t/**\n\t * 设置枚举\n\t */\n\tsetEnumMap(columnEnum: FaTableEnumColumnType, prop: string, enumMap: Map<string, FaTableEnumColumnCtx[]>): void {\n\t\tif (!columnEnum) return;\n\t\tif (typeof columnEnum === \"function\") {\n\t\t\tenumMap.set(prop, columnEnum());\n\t\t} else if (Array.isArray(columnEnum)) {\n\t\t\tenumMap.set(prop, columnEnum);\n\t\t}\n\t},\n\t/**\n\t * 扁平化 columns\n\t */\n\tflatColumns(columns: FaTableColumnCtx[], enumMap?: Map<string, FaTableEnumColumnCtx[]>): FaTableColumnCtx[] {\n\t\tconst flatArr: FaTableColumnCtx[] = [];\n\t\tcolumns.forEach((col) => {\n\t\t\tif (col._children?.length) {\n\t\t\t\tflatArr.push(...this.flatColumns(col._children));\n\t\t\t}\n\n\t\t\tflatArr.push(col);\n\n\t\t\t// 给每一项 column 添加 show && filterEnum 默认属性\n\t\t\tcol.show ??= true;\n\t\t\tlet enumKey = col.prop ?? col.search?.key;\n\n\t\t\tif (col.enum && typeof col.enum === \"string\") {\n\t\t\t\tenumKey = col.enum;\n\t\t\t}\n\n\t\t\t// 设置 enumMap\n\t\t\tif (col.enum && enumKey && enumMap) this.setEnumMap(col.enum, enumKey, enumMap);\n\t\t});\n\t\treturn flatArr.filter((item) => !item._children?.length);\n\t},\n};\n"],"mappings":";;;;AAOA,MAAa,YAAY;;;;;CAKxB,YAAY,WAA6B;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O;KACpD,IAAK,SAAqB,QAAmB,OAAO;IACrD,OAAO,IAAI,UAAU,cAAc;KAClC,IAAK,SAAqB,QAAmB,OAAO;KACpD,IAAK,SAAqB,QAAmB,OAAO;IACrD;GAEF;GAGD,OAAO;EACR;CACD;;;;CAIA,WAAW,YAAmC,MAAc,SAAoD;EAC/G,IAAI,CAAC,YAAY;EACjB,IAAI,OAAO,eAAe,YACzB,QAAQ,IAAI,MAAM,WAAW,CAAC;OACxB,IAAI,MAAM,QAAQ,UAAU,GAClC,QAAQ,IAAI,MAAM,UAAU;CAE9B;;;;CAIA,YAAY,SAA6B,SAAmE;EAC3G,MAAM,UAA8B,CAAC;EACrC,QAAQ,SAAS,QAAQ;GACxB,IAAI,IAAI,WAAW,QAClB,QAAQ,KAAK,GAAG,KAAK,YAAY,IAAI,SAAS,CAAC;GAGhD,QAAQ,KAAK,GAAG;GAGhB,IAAI,SAAS;GACb,IAAI,UAAU,IAAI,QAAQ,IAAI,QAAQ;GAEtC,IAAI,IAAI,QAAQ,OAAO,IAAI,SAAS,UACnC,UAAU,IAAI;GAIf,IAAI,IAAI,QAAQ,WAAW,SAAS,KAAK,WAAW,IAAI,MAAM,SAAS,OAAO;EAC/E,CAAC;EACD,OAAO,QAAQ,QAAQ,SAAS,CAAC,KAAK,WAAW,MAAM;CACxD;AACD"}
|
|
@@ -6,7 +6,7 @@ export declare const FaTree: TSXWithInstall<typeof Tree>;
|
|
|
6
6
|
export default FaTree;
|
|
7
7
|
export { faTreeProps, faTreeEmits };
|
|
8
8
|
export type { FaTreeSlots } from "./src/tree";
|
|
9
|
-
export * from "./src/tree.type";
|
|
9
|
+
export type * from "./src/tree.type";
|
|
10
10
|
/** FaTree 暴露的组件实例类型。 */
|
|
11
11
|
export type FaTreeInstance = InstanceType<typeof Tree>;
|
|
12
12
|
/** FaTree 的完整 Props 类型。 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["Tree"],"sources":["../../../src/components/tree/index.ts"],"sourcesContent":["import { withInstall } from \"../../utils\";\nimport Tree, { faTreeEmits, faTreeProps } from \"./src/tree\";\nimport type { ExtractPropTypes } from \"vue\";\nimport type { TSXWithInstall } from \"../../utils\";\n\n/** 支持远程加载、筛选和节点操作的树组件。 */\nexport const FaTree: TSXWithInstall<typeof Tree> = withInstall(Tree);\nexport default FaTree;\n\nexport { faTreeProps, faTreeEmits };\nexport type { FaTreeSlots } from \"./src/tree\";\nexport * from \"./src/tree.type\";\n\n/** FaTree 暴露的组件实例类型。 */\nexport type FaTreeInstance = InstanceType<typeof Tree>;\n\n/** FaTree 的完整 Props 类型。 */\nexport type FaTreeProps = ExtractPropTypes<typeof faTreeProps>;\n\n/** FaTree 的 Emits 类型。 */\nexport type FaTreeEmits = typeof faTreeEmits;\n"],"mappings":";;;;AAMA,MAAa,SAAsC,YAAYA,YAAI"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["Tree"],"sources":["../../../src/components/tree/index.ts"],"sourcesContent":["import { withInstall } from \"../../utils\";\nimport Tree, { faTreeEmits, faTreeProps } from \"./src/tree\";\nimport type { ExtractPropTypes } from \"vue\";\nimport type { TSXWithInstall } from \"../../utils\";\n\n/** 支持远程加载、筛选和节点操作的树组件。 */\nexport const FaTree: TSXWithInstall<typeof Tree> = withInstall(Tree);\nexport default FaTree;\n\nexport { faTreeProps, faTreeEmits };\nexport type { FaTreeSlots } from \"./src/tree\";\nexport type * from \"./src/tree.type\";\n\n/** FaTree 暴露的组件实例类型。 */\nexport type FaTreeInstance = InstanceType<typeof Tree>;\n\n/** FaTree 的完整 Props 类型。 */\nexport type FaTreeProps = ExtractPropTypes<typeof faTreeProps>;\n\n/** FaTree 的 Emits 类型。 */\nexport type FaTreeEmits = typeof faTreeEmits;\n"],"mappings":";;;;AAMA,MAAa,SAAsC,YAAYA,YAAI"}
|
|
@@ -66,14 +66,14 @@ export declare const faTreeProps: {
|
|
|
66
66
|
/** @description 树形数据 */
|
|
67
67
|
data: {
|
|
68
68
|
type: import("vue").PropType<ElTreeOutput<import("./tree.type").ElTreeValue, any>[]>;
|
|
69
|
-
default: () =>
|
|
69
|
+
default: () => never[];
|
|
70
70
|
};
|
|
71
71
|
/** @description 请求api */
|
|
72
72
|
requestApi: {
|
|
73
73
|
type: import("vue").PropType<(params?: string | number | PagedInput) => Promise<ElTreeOutput[]>>;
|
|
74
74
|
};
|
|
75
75
|
/** 初始化参数 */
|
|
76
|
-
initParam: import("vue").PropType<string | number | PagedInput>;
|
|
76
|
+
initParam: import("vue").PropType<string | number | PagedInput | null>;
|
|
77
77
|
emptyText: {
|
|
78
78
|
readonly type: import("vue").PropType<string>;
|
|
79
79
|
readonly required: false;
|
|
@@ -152,7 +152,7 @@ export declare const faTreeEmits: {
|
|
|
152
152
|
/** @description v-model:label 回调 */
|
|
153
153
|
"update:label": (value: string) => boolean;
|
|
154
154
|
/** @description 数据改变 */
|
|
155
|
-
|
|
155
|
+
dataChange: (data: ElTreeOutput[]) => boolean;
|
|
156
156
|
/** @description 选中数据改变 */
|
|
157
157
|
change: (_data: ElTreeOutput, _node: TreeNode, _instance: ComponentInternalInstance, _event: MouseEvent) => boolean;
|
|
158
158
|
/** @description 节点点击 */
|
|
@@ -247,14 +247,14 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
247
247
|
/** @description 树形数据 */
|
|
248
248
|
data: {
|
|
249
249
|
type: import("vue").PropType<ElTreeOutput<import("./tree.type").ElTreeValue, any>[]>;
|
|
250
|
-
default: () =>
|
|
250
|
+
default: () => never[];
|
|
251
251
|
};
|
|
252
252
|
/** @description 请求api */
|
|
253
253
|
requestApi: {
|
|
254
254
|
type: import("vue").PropType<(params?: string | number | PagedInput) => Promise<ElTreeOutput[]>>;
|
|
255
255
|
};
|
|
256
256
|
/** 初始化参数 */
|
|
257
|
-
initParam: import("vue").PropType<string | number | PagedInput>;
|
|
257
|
+
initParam: import("vue").PropType<string | number | PagedInput | null>;
|
|
258
258
|
emptyText: {
|
|
259
259
|
readonly type: import("vue").PropType<string>;
|
|
260
260
|
readonly required: false;
|
|
@@ -376,7 +376,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
376
376
|
/** @description v-model:label 回调 */
|
|
377
377
|
"update:label": (value: string) => boolean;
|
|
378
378
|
/** @description 数据改变 */
|
|
379
|
-
|
|
379
|
+
dataChange: (data: ElTreeOutput[]) => boolean;
|
|
380
380
|
/** @description 选中数据改变 */
|
|
381
381
|
change: (_data: ElTreeOutput, _node: TreeNode, _instance: ComponentInternalInstance, _event: MouseEvent) => boolean;
|
|
382
382
|
/** @description 节点点击 */
|
|
@@ -455,14 +455,14 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
455
455
|
/** @description 树形数据 */
|
|
456
456
|
data: {
|
|
457
457
|
type: import("vue").PropType<ElTreeOutput<import("./tree.type").ElTreeValue, any>[]>;
|
|
458
|
-
default: () =>
|
|
458
|
+
default: () => never[];
|
|
459
459
|
};
|
|
460
460
|
/** @description 请求api */
|
|
461
461
|
requestApi: {
|
|
462
462
|
type: import("vue").PropType<(params?: string | number | PagedInput) => Promise<ElTreeOutput[]>>;
|
|
463
463
|
};
|
|
464
464
|
/** 初始化参数 */
|
|
465
|
-
initParam: import("vue").PropType<string | number | PagedInput>;
|
|
465
|
+
initParam: import("vue").PropType<string | number | PagedInput | null>;
|
|
466
466
|
emptyText: {
|
|
467
467
|
readonly type: import("vue").PropType<string>;
|
|
468
468
|
readonly required: false;
|
|
@@ -538,7 +538,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
538
538
|
"onUpdate:modelValue"?: ((value: string | number | boolean | object | null | undefined) => any) | undefined;
|
|
539
539
|
"onCurrent-change"?: ((data: any, node: import("element-plus/es/components/tree/src/model/node.mjs").default | null) => any) | undefined;
|
|
540
540
|
"onUpdate:label"?: ((value: string) => any) | undefined;
|
|
541
|
-
|
|
541
|
+
onDataChange?: ((data: ElTreeOutput<import("./tree.type").ElTreeValue, any>[]) => any) | undefined;
|
|
542
542
|
"onNode-click"?: ((_data: ElTreeOutput<import("./tree.type").ElTreeValue, any>, _node: TreeNode, _instance: ComponentInternalInstance | null, _event: MouseEvent) => any) | undefined;
|
|
543
543
|
"onCheck-change"?: ((data: any, checked: boolean, indeterminate: boolean) => any) | undefined;
|
|
544
544
|
"onNode-contextmenu"?: ((evt: Event, data: any, node: import("element-plus/es/components/tree/src/model/node.mjs").default, nodeInstance: ComponentInternalInstance | null) => any) | undefined;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { addCssUnit } from "../../../utils/dom/index.mjs";
|
|
2
|
+
import { isEqual } from "../../../utils/object/index.mjs";
|
|
2
3
|
import { useEmits } from "../../../utils/vue/emits.mjs";
|
|
3
4
|
import { useExpose } from "../../../utils/vue/expose.mjs";
|
|
4
5
|
import { definePropType, useProps } from "../../../utils/vue/props.mjs";
|
|
5
6
|
import { useRender } from "../../../utils/vue/render.mjs";
|
|
6
7
|
import { makeSlots } from "../../../utils/vue/slots.mjs";
|
|
7
8
|
import { withDefineType } from "../../../utils/vue/with.mjs";
|
|
8
|
-
import { computed, createTextVNode, createVNode, defineComponent, mergeProps, nextTick, onMounted, reactive,
|
|
9
|
+
import { computed, createTextVNode, createVNode, defineComponent, mergeProps, nextTick, onMounted, reactive, resolveDirective, shallowRef, useModel, watch, withDirectives } from "vue";
|
|
9
10
|
import { Expand, Fold } from "@element-plus/icons-vue";
|
|
10
11
|
import { ElIcon, ElInput, ElScrollbar, ElTree, treeEmits, treeProps, useGlobalSize } from "element-plus";
|
|
11
|
-
import { isArray, isBoolean, isEqual, isNull, isNumber, isObject, isString, isUndefined } from "lodash-unified";
|
|
12
|
-
import { useVModel } from "@vueuse/core";
|
|
13
12
|
//#region src/components/tree/src/tree.tsx
|
|
14
13
|
/** FaTree 的运行时 Props 定义。 */
|
|
15
14
|
const faTreeProps = {
|
|
@@ -98,11 +97,11 @@ const faTreeProps = {
|
|
|
98
97
|
const faTreeEmits = {
|
|
99
98
|
...treeEmits,
|
|
100
99
|
/** @description v-model 回调 */
|
|
101
|
-
"update:modelValue": (value) =>
|
|
100
|
+
"update:modelValue": (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" || typeof value === "object" && value !== null || value == null,
|
|
102
101
|
/** @description v-model:label 回调 */
|
|
103
|
-
"update:label": (value) =>
|
|
102
|
+
"update:label": (value) => typeof value === "string" || value === null,
|
|
104
103
|
/** @description 数据改变 */
|
|
105
|
-
|
|
104
|
+
dataChange: (data) => Array.isArray(data),
|
|
106
105
|
/** @description 选中数据改变 */
|
|
107
106
|
change: (_data, _node, _instance, _event) => true,
|
|
108
107
|
/** @description 节点点击 */
|
|
@@ -114,31 +113,31 @@ var tree_default = defineComponent({
|
|
|
114
113
|
emits: faTreeEmits,
|
|
115
114
|
slots: makeSlots(),
|
|
116
115
|
setup(props, { slots, emit, expose }) {
|
|
117
|
-
const selectedLabel =
|
|
118
|
-
const
|
|
116
|
+
const selectedLabel = useModel(props, "label");
|
|
117
|
+
const globalSize = useGlobalSize();
|
|
118
|
+
const treeRef = shallowRef(null);
|
|
119
119
|
const state = reactive({
|
|
120
|
-
value: withDefineType(
|
|
120
|
+
value: withDefineType(),
|
|
121
121
|
loading: false,
|
|
122
122
|
searchValue: withDefineType(),
|
|
123
|
-
|
|
123
|
+
originalTreeData: withDefineType([]),
|
|
124
124
|
treeData: withDefineType([]),
|
|
125
|
-
hamburger:
|
|
125
|
+
hamburger: false,
|
|
126
126
|
width: computed(() => {
|
|
127
127
|
if (state.hamburger) return "130px";
|
|
128
128
|
else {
|
|
129
129
|
const width = addCssUnit(props.width);
|
|
130
|
-
if (
|
|
130
|
+
if (globalSize.value === "small") return `calc(${width} * 0.9)`;
|
|
131
131
|
else return width;
|
|
132
132
|
}
|
|
133
133
|
})
|
|
134
134
|
});
|
|
135
|
+
let requestVersion = 0;
|
|
135
136
|
/** @description 只有一层节点 */
|
|
136
137
|
const fold = computed(() => {
|
|
137
138
|
const childrenKey = props.props.children ?? "children";
|
|
138
|
-
return state.
|
|
139
|
+
return state.originalTreeData.every((item) => !Array.isArray(item[childrenKey]) || item[childrenKey].length === 0);
|
|
139
140
|
});
|
|
140
|
-
const treeRef = ref();
|
|
141
|
-
let requestVersion = 0;
|
|
142
141
|
const loadData = async () => {
|
|
143
142
|
const currentRequestVersion = ++requestVersion;
|
|
144
143
|
let curSelectedData;
|
|
@@ -169,17 +168,17 @@ var tree_default = defineComponent({
|
|
|
169
168
|
value: null,
|
|
170
169
|
all: true
|
|
171
170
|
});
|
|
172
|
-
state.
|
|
171
|
+
state.originalTreeData = treeData;
|
|
173
172
|
state.treeData = treeData;
|
|
174
|
-
emit("
|
|
173
|
+
emit("dataChange", state.treeData);
|
|
175
174
|
const selectedKey = curSelectedData ?? props.modelValue ?? props.defaultSelection;
|
|
176
175
|
if (props.nodeKey && (typeof selectedKey === "string" || typeof selectedKey === "number")) nextTick(() => {
|
|
177
176
|
treeRef.value?.setCurrentKey(selectedKey);
|
|
178
177
|
});
|
|
179
178
|
};
|
|
180
179
|
const handleHamburgerClick = () => {
|
|
181
|
-
if (state.hamburger) state.treeData = state.
|
|
182
|
-
else state.treeData = state.
|
|
180
|
+
if (state.hamburger) state.treeData = state.originalTreeData;
|
|
181
|
+
else state.treeData = state.originalTreeData.map((item) => ({
|
|
183
182
|
...item,
|
|
184
183
|
[props.props.children ?? "children"]: []
|
|
185
184
|
}));
|
|
@@ -204,7 +203,7 @@ var tree_default = defineComponent({
|
|
|
204
203
|
if (!instance) return;
|
|
205
204
|
if (props.expandOnClickNode) {
|
|
206
205
|
if (!node.expanded) node.expand();
|
|
207
|
-
else if (
|
|
206
|
+
else if (props.collapseOnClickNode) node.collapse();
|
|
208
207
|
}
|
|
209
208
|
if (data["all"] || node.key !== void 0 && node.key !== null) {
|
|
210
209
|
const value = data["all"] ? props.allValue : node.key;
|
|
@@ -217,15 +216,18 @@ var tree_default = defineComponent({
|
|
|
217
216
|
}
|
|
218
217
|
emit("node-click", data, node, instance, event);
|
|
219
218
|
};
|
|
220
|
-
onMounted(async () => {
|
|
221
|
-
await loadData();
|
|
222
|
-
watch(() => props.data, () => {
|
|
223
|
-
if (!props.requestApi) return loadData();
|
|
224
|
-
}, { deep: true });
|
|
225
|
-
});
|
|
226
219
|
watch(() => props.modelValue, (newValue) => {
|
|
227
220
|
state.value = newValue;
|
|
228
221
|
if (typeof newValue === "string" || typeof newValue === "number") treeRef.value?.setCurrentKey(newValue);
|
|
222
|
+
}, { immediate: true });
|
|
223
|
+
watch(() => props.hamburger, (newValue) => {
|
|
224
|
+
state.hamburger = newValue;
|
|
225
|
+
}, { immediate: true });
|
|
226
|
+
watch(() => props.data, () => {
|
|
227
|
+
if (!props.requestApi) return loadData();
|
|
228
|
+
}, { deep: true });
|
|
229
|
+
onMounted(async () => {
|
|
230
|
+
await loadData();
|
|
229
231
|
});
|
|
230
232
|
const elTreeProps = useProps(props, treeProps, [
|
|
231
233
|
"data",
|
|
@@ -236,7 +238,7 @@ var tree_default = defineComponent({
|
|
|
236
238
|
useRender(() => withDirectives(createVNode("div", {
|
|
237
239
|
"class": [
|
|
238
240
|
"el-card fa-tree",
|
|
239
|
-
`fa-tree-${
|
|
241
|
+
`fa-tree-${globalSize.value}`,
|
|
240
242
|
{ "fa-tree__fold": state.hamburger || fold.value }
|
|
241
243
|
],
|
|
242
244
|
"style": { width: state.width }
|