vue-super-crud 1.7.1
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/.browserslistrc +3 -0
- package/.versionrc.json +36 -0
- package/CHANGELOG.md +232 -0
- package/LICENSE +201 -0
- package/README.md +46 -0
- package/babel.config.js +12 -0
- package/build/alias.js +10 -0
- package/build/build.js +52 -0
- package/build/config.js +70 -0
- package/deploy.bat +14 -0
- package/docs/.vuepress/components/button/base.vue +88 -0
- package/docs/.vuepress/components/common/code-format.vue +331 -0
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/base.vue +68 -0
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/customParams.vue +73 -0
- package/docs/.vuepress/components/commonConfig/renderType/component.vue +160 -0
- package/docs/.vuepress/components/commonConfig/renderType/formatter.vue +49 -0
- package/docs/.vuepress/components/commonConfig/renderType/render.vue +91 -0
- package/docs/.vuepress/components/commonConfig/renderType/slot.vue +63 -0
- package/docs/.vuepress/components/crud/baseUse/baseUse.vue +98 -0
- package/docs/.vuepress/components/crud/baseUse/columnAction.vue +72 -0
- package/docs/.vuepress/components/crud/baseUse/columnWidth.vue +107 -0
- package/docs/.vuepress/components/crud/baseUse/handleRow.vue +65 -0
- package/docs/.vuepress/components/crud/baseUse/height.vue +82 -0
- package/docs/.vuepress/components/crud/baseUse/index.vue +54 -0
- package/docs/.vuepress/components/crud/baseUse/loading.vue +70 -0
- package/docs/.vuepress/components/crud/baseUse/pagination.vue +108 -0
- package/docs/.vuepress/components/crud/baseUse/selection.vue +114 -0
- package/docs/.vuepress/components/crud/baseUse/summaryMethod.vue +118 -0
- package/docs/.vuepress/components/crud/baseUse/title.vue +54 -0
- package/docs/.vuepress/components/crud/baseUse/toolbar.vue +69 -0
- package/docs/.vuepress/components/crud/buttons/common.vue +115 -0
- package/docs/.vuepress/components/crud/buttons/fast.vue +82 -0
- package/docs/.vuepress/components/crud/contextMenu/base.vue +72 -0
- package/docs/.vuepress/components/crud/copy.vue +52 -0
- package/docs/.vuepress/components/crud/crudEvents/api.vue +157 -0
- package/docs/.vuepress/components/crud/crudEvents/deleteTip.vue +93 -0
- package/docs/.vuepress/components/crud/crudEvents/events.vue +188 -0
- package/docs/.vuepress/components/crud/dataSort/base.vue +142 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/base.vue +53 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/dynamicAndFixed.vue +111 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/treeDynamic.vue +68 -0
- package/docs/.vuepress/components/crud/handleBar/handleRow.vue +65 -0
- package/docs/.vuepress/components/crud/handleBar/toolbar.vue +69 -0
- package/docs/.vuepress/components/crud/renderType/1.vue +57 -0
- package/docs/.vuepress/components/crud/renderType/2.vue +63 -0
- package/docs/.vuepress/components/crud/renderType/3.vue +105 -0
- package/docs/.vuepress/components/crud/renderType/5.vue +91 -0
- package/docs/.vuepress/components/crud/search/1.vue +90 -0
- package/docs/.vuepress/components/crud/search/2.vue +78 -0
- package/docs/.vuepress/components/crud/search/3.vue +107 -0
- package/docs/.vuepress/components/crud/search/base.vue +123 -0
- package/docs/.vuepress/components/crud/search/localSearch.vue +124 -0
- package/docs/.vuepress/components/crud/search/special.vue +148 -0
- package/docs/.vuepress/components/crud/selection/events.vue +47 -0
- package/docs/.vuepress/components/crud/selection/pagination.vue +94 -0
- package/docs/.vuepress/components/crud/selection/singleSelection.vue +64 -0
- package/docs/.vuepress/components/crud/span/base.vue +69 -0
- package/docs/.vuepress/components/crud/span/special.vue +75 -0
- package/docs/.vuepress/components/crud/summary/base.vue +99 -0
- package/docs/.vuepress/components/crud/tableEdit/addDeleteBtn.vue +174 -0
- package/docs/.vuepress/components/crud/tableEdit/cellEdit.vue +194 -0
- package/docs/.vuepress/components/crud/tableEdit/controlEdit.vue +219 -0
- package/docs/.vuepress/components/crud/tableEdit/dialog.vue +172 -0
- package/docs/.vuepress/components/crud/tableEdit/free.vue +88 -0
- package/docs/.vuepress/components/crud/tableEdit/freeColumn.vue +82 -0
- package/docs/.vuepress/components/crud/tableEdit/methods.vue +154 -0
- package/docs/.vuepress/components/crud/tableEdit/rowAction.vue +107 -0
- package/docs/.vuepress/components/crud/tableEdit/rowBatch.vue +116 -0
- package/docs/.vuepress/components/crud/tableEdit/rowClick.vue +98 -0
- package/docs/.vuepress/components/crud/validate/base.vue +122 -0
- package/docs/.vuepress/components/crud/validate/custom.vue +82 -0
- package/docs/.vuepress/components/crud/validate/regulars.vue +88 -0
- package/docs/.vuepress/components/crud/validate/relation.vue +91 -0
- package/docs/.vuepress/components/crud/validate/tree.vue +82 -0
- package/docs/.vuepress/components/dialog/baseUse/base.vue +92 -0
- package/docs/.vuepress/components/dialog/baseUse/beforeConfirm.vue +78 -0
- package/docs/.vuepress/components/dialog/baseUse/control.vue +79 -0
- package/docs/.vuepress/components/dialog/baseUse/drawer.vue +59 -0
- package/docs/.vuepress/components/dialog/baseUse/footer.vue +87 -0
- package/docs/.vuepress/components/dialog/baseUse/insertSlot.vue +79 -0
- package/docs/.vuepress/components/dict/DictLinkage.vue +91 -0
- package/docs/.vuepress/components/dict/baseUse.vue +72 -0
- package/docs/.vuepress/components/dict/component.vue +82 -0
- package/docs/.vuepress/components/dict/localDict.vue +68 -0
- package/docs/.vuepress/components/form/baseUse/base.vue +48 -0
- package/docs/.vuepress/components/form/baseUse/dataFormat.vue +92 -0
- package/docs/.vuepress/components/form/baseUse/deep.vue +57 -0
- package/docs/.vuepress/components/form/baseUse/gridLayout.vue +47 -0
- package/docs/.vuepress/components/form/baseUse/group.vue +66 -0
- package/docs/.vuepress/components/form/baseUse/hidden.vue +40 -0
- package/docs/.vuepress/components/form/baseUse/inlineLayout.vue +48 -0
- package/docs/.vuepress/components/form/baseUse/label.vue +51 -0
- package/docs/.vuepress/components/form/baseUse/tooltip.vue +40 -0
- package/docs/.vuepress/components/form/baseUse/validate.vue +52 -0
- package/docs/.vuepress/components/form/detail/base.vue +78 -0
- package/docs/.vuepress/components/form/detail/border.vue +90 -0
- package/docs/.vuepress/components/form/detail/singleDetail.vue +72 -0
- package/docs/.vuepress/components/formatData/baseUse.vue +131 -0
- package/docs/.vuepress/components/mock/index.js +347 -0
- package/docs/.vuepress/components/mockData/custom.vue +69 -0
- package/docs/.vuepress/components/mockData/example.vue +290 -0
- package/docs/.vuepress/components/positionSlot/base.vue +24 -0
- package/docs/.vuepress/components/positionSlot/form.vue +71 -0
- package/docs/.vuepress/components/positionSlot/table.vue +85 -0
- package/docs/.vuepress/components/tabs/base.vue +57 -0
- package/docs/.vuepress/components/temp.js +195 -0
- package/docs/.vuepress/config.js +146 -0
- package/docs/.vuepress/enhanceApp.js +142 -0
- package/docs/.vuepress/public/favicon.ico +0 -0
- package/docs/.vuepress/public/super.png +0 -0
- package/docs/.vuepress/styles/index.styl +25 -0
- package/docs/.vuepress/styles/palette.styl +6 -0
- package/docs/README.md +14 -0
- package/docs/guide/button/base.md +31 -0
- package/docs/guide/commonConfig/jsx.md +166 -0
- package/docs/guide/commonConfig/presetCodeTemplate.md +68 -0
- package/docs/guide/commonConfig/renderType.md +181 -0
- package/docs/guide/crud/baseUse.md +120 -0
- package/docs/guide/crud/buttons.md +18 -0
- package/docs/guide/crud/config.md +217 -0
- package/docs/guide/crud/contextMenu.md +18 -0
- package/docs/guide/crud/dataSort.md +66 -0
- package/docs/guide/crud/genDynamicColumns.md +145 -0
- package/docs/guide/crud/handleBar.md +26 -0
- package/docs/guide/crud/renderType.md +4 -0
- package/docs/guide/crud/search.md +150 -0
- package/docs/guide/crud/selection.md +73 -0
- package/docs/guide/crud/span.md +98 -0
- package/docs/guide/crud/summary.md +167 -0
- package/docs/guide/crud/tableEdit.md +377 -0
- package/docs/guide/crud/validate.md +158 -0
- package/docs/guide/dialog/baseUse.md +81 -0
- package/docs/guide/dict/baseUse.md +174 -0
- package/docs/guide/dict/component.md +88 -0
- package/docs/guide/dict/config.md +44 -0
- package/docs/guide/form/baseUse.md +142 -0
- package/docs/guide/form/detail.md +38 -0
- package/docs/guide/formatData/baseUse.md +98 -0
- package/docs/guide/formatData/config.md +142 -0
- package/docs/guide/mockData/base.md +26 -0
- package/docs/guide/positionSlot/base.md +41 -0
- package/docs/guide/question/base.md +44 -0
- package/docs/guide/start/base.md +30 -0
- package/docs/guide/tabs/base.md +63 -0
- package/examples/App.vue +52 -0
- package/examples/Layout/components/AppMain.vue +40 -0
- package/examples/Layout/components/Item.vue +29 -0
- package/examples/Layout/components/Link.vue +44 -0
- package/examples/Layout/components/SidebarItem.vue +93 -0
- package/examples/Layout/index.vue +69 -0
- package/examples/assets/logo.png +0 -0
- package/examples/favicon.ico +0 -0
- package/examples/index.html +18 -0
- package/examples/main.js +54 -0
- package/examples/router/index.js +140 -0
- package/examples/store/index.js +0 -0
- package/examples/styles/index.scss +63 -0
- package/examples/styles/sidebar.scss +226 -0
- package/examples/styles/transition.scss +48 -0
- package/examples/styles/variables.scss +25 -0
- package/examples/views/crud/base.vue +68 -0
- package/examples/views/crud/handleRow.vue +84 -0
- package/examples/views/crud/search.vue +116 -0
- package/examples/views/dashboard/index.vue +244 -0
- package/examples/views/dashboard/index1.vue +234 -0
- package/examples/views/dashboard/test.vue +9 -0
- package/examples/views/formTest/index.vue +168 -0
- package/examples/views/nested/menu1/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-1/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-2/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-2/menu1-2-1/index.vue +5 -0
- package/examples/views/nested/menu1/menu1-2/menu1-2-2/index.vue +5 -0
- package/examples/views/nested/menu1/menu1-3/index.vue +5 -0
- package/examples/views/nested/menu2/index.vue +5 -0
- package/gulpfile.js +84 -0
- package/lib/index.css +1 -0
- package/lib/super-crud.min.js +15 -0
- package/package.json +66 -0
- package/packages/button/index.vue +189 -0
- package/packages/core/components/comp.vue +223 -0
- package/packages/core/components/position.vue +135 -0
- package/packages/core/components/render.vue +460 -0
- package/packages/core/configManager.js +302 -0
- package/packages/core/create.js +8 -0
- package/packages/core/defaultRender.js +64 -0
- package/packages/core/dict/global.js +10 -0
- package/packages/core/dict/index.js +432 -0
- package/packages/core/dict/mixin.js +94 -0
- package/packages/core/event.js +60 -0
- package/packages/core/index.js +6 -0
- package/packages/core/init.js +122 -0
- package/packages/core/mock/genConfig.js +228 -0
- package/packages/core/mock/genData.js +422 -0
- package/packages/core/mock/index.js +4 -0
- package/packages/core/rules.js +111 -0
- package/packages/crud/column.vue +205 -0
- package/packages/crud/columnAction.vue +207 -0
- package/packages/crud/columnCell.vue +146 -0
- package/packages/crud/defaultColumn.vue +130 -0
- package/packages/crud/drawerColumn.vue +225 -0
- package/packages/crud/form.vue +69 -0
- package/packages/crud/index.vue +564 -0
- package/packages/crud/menuBar.vue +298 -0
- package/packages/crud/mixins/cacheHandler.js +36 -0
- package/packages/crud/mixins/calcColumnWidth.js +79 -0
- package/packages/crud/mixins/calcHeight.js +105 -0
- package/packages/crud/mixins/columnHandler.js +128 -0
- package/packages/crud/mixins/contextMenu.js +98 -0
- package/packages/crud/mixins/dataProcessor.js +202 -0
- package/packages/crud/mixins/dialog.js +109 -0
- package/packages/crud/mixins/excelHandler.js +150 -0
- package/packages/crud/mixins/exposeMethods.js +107 -0
- package/packages/crud/mixins/generateDynamicColumns.js +250 -0
- package/packages/crud/mixins/props.js +38 -0
- package/packages/crud/mixins/searchHandler.js +151 -0
- package/packages/crud/mixins/select.js +359 -0
- package/packages/crud/mixins/spanMethod.js +288 -0
- package/packages/crud/mixins/summary.js +177 -0
- package/packages/crud/mixins/tableEdit.js +547 -0
- package/packages/crud/mixins/validate.js +219 -0
- package/packages/crud/pagination.vue +110 -0
- package/packages/crud/search.vue +119 -0
- package/packages/crud/searchHeader.vue +231 -0
- package/packages/crud/selectBanner.vue +138 -0
- package/packages/crud/utils/EditState.js +319 -0
- package/packages/crud/utils/excelExport.js +112 -0
- package/packages/crud/utils/excelImport.js +112 -0
- package/packages/crud/utils/index.js +98 -0
- package/packages/dialog/dialog.js +233 -0
- package/packages/dialog/dialog.vue +15 -0
- package/packages/dialog/index.js +22 -0
- package/packages/dict/cascadeFormat.vue +179 -0
- package/packages/dict/dateFormat.vue +40 -0
- package/packages/dict/form/cascade.vue +61 -0
- package/packages/dict/form/checkbox.vue +90 -0
- package/packages/dict/form/extendMethod.js +22 -0
- package/packages/dict/form/input-base.js +31 -0
- package/packages/dict/form/input.js +20 -0
- package/packages/dict/form/radio.vue +69 -0
- package/packages/dict/form/select.vue +118 -0
- package/packages/dict/form/switch.vue +75 -0
- package/packages/dict/valueFormat.vue +188 -0
- package/packages/directive/dialog/drag.js +86 -0
- package/packages/directive/dialog/dragSize.js +42 -0
- package/packages/directive/index.js +9 -0
- package/packages/directive/insertSlot.js +10 -0
- package/packages/form/contextMenu.js +192 -0
- package/packages/form/draftDrawer.vue +391 -0
- package/packages/form/formAction.vue +97 -0
- package/packages/form/formItem.vue +259 -0
- package/packages/form/index.vue +451 -0
- package/packages/form/props.js +15 -0
- package/packages/grid/cell.vue +65 -0
- package/packages/grid/index.vue +130 -0
- package/packages/group/index.vue +96 -0
- package/packages/tabs/index.vue +290 -0
- package/packages/tooltip/index.js +9 -0
- package/packages/tooltip/tooltip.vue +32 -0
- package/packages/tooltip/tooltipComponent.js +38 -0
- package/packages/verifyInput/index.vue +131 -0
- package/src/config/common.js +88 -0
- package/src/config/crud.js +567 -0
- package/src/config/dialog.js +87 -0
- package/src/config/form.js +215 -0
- package/src/config/index.js +9 -0
- package/src/constants/index.js +72 -0
- package/src/index.js +67 -0
- package/src/template/btn/crud.js +6 -0
- package/src/template/btn/dialog.js +1 -0
- package/src/template/btn/form.js +3 -0
- package/src/template/btn/index.js +9 -0
- package/src/template/dicts.js +1 -0
- package/src/template/formatData.js +507 -0
- package/src/template/index.js +19 -0
- package/src/template/render.js +124 -0
- package/src/template/rules.js +53 -0
- package/src/utils/bem.js +49 -0
- package/src/utils/cache.js +77 -0
- package/src/utils/getType.js +34 -0
- package/src/utils/index.js +212 -0
- package/src/utils/mergeTemp.js +124 -0
- package/styles/button.scss +3 -0
- package/styles/crud.scss +425 -0
- package/styles/dialog.scss +95 -0
- package/styles/form.scss +532 -0
- package/styles/group.scss +78 -0
- package/styles/index.scss +94 -0
- package/styles/tabs.scss +139 -0
- package/styles/verifyInput.scss +56 -0
- package/vue-jsx-sync.js +90 -0
- package/vue.config.js +54 -0
@@ -0,0 +1,250 @@
|
|
1
|
+
export default {
|
2
|
+
methods: {
|
3
|
+
insertColumns(newColumns, columns, position) {
|
4
|
+
columns = [...columns];
|
5
|
+
if (!Array.isArray(newColumns)) {
|
6
|
+
return columns;
|
7
|
+
}
|
8
|
+
|
9
|
+
let insertIndex = -1;
|
10
|
+
|
11
|
+
// 通过prop查找位置
|
12
|
+
if (typeof position === "string") {
|
13
|
+
insertIndex = columns.findIndex((col) => col.prop === position);
|
14
|
+
insertIndex += 1;
|
15
|
+
if (insertIndex === -1) {
|
16
|
+
console.warn(`insertColumns: 未找到prop为${position}的列`);
|
17
|
+
return columns;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
// 通过index指定位置
|
21
|
+
else if (typeof position === "number") {
|
22
|
+
if (position < 0 || position > columns.length) {
|
23
|
+
console.warn("insertColumns: index超出范围");
|
24
|
+
return columns;
|
25
|
+
}
|
26
|
+
insertIndex = position;
|
27
|
+
}
|
28
|
+
// 没有指定位置则追加到末尾
|
29
|
+
else {
|
30
|
+
insertIndex = columns.length;
|
31
|
+
}
|
32
|
+
|
33
|
+
// 处理新列配置
|
34
|
+
newColumns.forEach((col) => {
|
35
|
+
// 初始化列配置
|
36
|
+
this.initColumn(col, insertIndex);
|
37
|
+
});
|
38
|
+
|
39
|
+
// 插入新列
|
40
|
+
columns.splice(insertIndex, 0, ...newColumns);
|
41
|
+
return columns;
|
42
|
+
},
|
43
|
+
// 预处理数据
|
44
|
+
prepareData(rawData, config, level = 0, noProcessing) {
|
45
|
+
if (!Array.isArray(rawData) || !config?.length) return [];
|
46
|
+
|
47
|
+
if (noProcessing) return rawData;
|
48
|
+
|
49
|
+
const currentConfig = config[level];
|
50
|
+
if (!currentConfig) return [];
|
51
|
+
|
52
|
+
// 使用自定义转换函数
|
53
|
+
if (typeof currentConfig.dataTransformer === "function") {
|
54
|
+
return currentConfig.dataTransformer(rawData);
|
55
|
+
}
|
56
|
+
|
57
|
+
// 按数据路径提取数据
|
58
|
+
return rawData.flatMap((item) => {
|
59
|
+
const result = item[currentConfig.path || "children"];
|
60
|
+
return Array.isArray(result) ? result : [];
|
61
|
+
});
|
62
|
+
},
|
63
|
+
/**
|
64
|
+
* 生成动态列配置
|
65
|
+
* @param {Array} data - 原始数据
|
66
|
+
* @param {Array} levelConfig - 层级配置数组
|
67
|
+
* @returns {Array} 生成的列配置数组
|
68
|
+
*/
|
69
|
+
generateDynamicColumns(data, levelConfig) {
|
70
|
+
/**
|
71
|
+
* 处理每一层级的数据
|
72
|
+
* @param {Array} currentData - 当前层级的数据
|
73
|
+
* @param {number} currentLevel - 当前层级索引
|
74
|
+
* @param {string} parentPath - 父级路径
|
75
|
+
* @returns {Array} 当前层级的列配置
|
76
|
+
*/
|
77
|
+
const processLevel = (currentData, currentLevel = 0, parentPath = "") => {
|
78
|
+
// 如果没有数据或超出配置层级,返回空数组
|
79
|
+
if (!currentData?.length || currentLevel >= levelConfig.length)
|
80
|
+
return [];
|
81
|
+
|
82
|
+
const config = levelConfig[currentLevel];
|
83
|
+
// 用于去重的Map
|
84
|
+
const uniqueMap = new Map();
|
85
|
+
|
86
|
+
// 遍历当前层级数据
|
87
|
+
currentData.forEach((item) => {
|
88
|
+
// 获取prop值,支持函数或属性名
|
89
|
+
const prop = item[config.prop];
|
90
|
+
|
91
|
+
// 获取label值,支持函数或属性名
|
92
|
+
const label =
|
93
|
+
typeof config.label === "function"
|
94
|
+
? config.label(item)
|
95
|
+
: item[config.label];
|
96
|
+
|
97
|
+
if (!prop) return;
|
98
|
+
|
99
|
+
// 去重并收集源数据项
|
100
|
+
if (!uniqueMap.has(prop)) {
|
101
|
+
uniqueMap.set(prop, {
|
102
|
+
...config,
|
103
|
+
prop,
|
104
|
+
label: label || `未命名-${prop}`,
|
105
|
+
sourceItems: [item],
|
106
|
+
});
|
107
|
+
} else {
|
108
|
+
uniqueMap.get(prop).sourceItems.push(item);
|
109
|
+
}
|
110
|
+
});
|
111
|
+
|
112
|
+
// 生成列配置
|
113
|
+
return Array.from(uniqueMap.values()).map(
|
114
|
+
({ prop, label, sourceItems, path, dataTransformer, ...rest }) => {
|
115
|
+
// 构建当前路径
|
116
|
+
const currentPath = parentPath ? `${parentPath}.${prop}` : prop;
|
117
|
+
|
118
|
+
const column = {
|
119
|
+
...rest,
|
120
|
+
label,
|
121
|
+
prop: currentPath + "." + config.prop,
|
122
|
+
};
|
123
|
+
|
124
|
+
// 处理子列
|
125
|
+
if (currentLevel < levelConfig.length - 1) {
|
126
|
+
// 递归处理下一层级
|
127
|
+
const nextLevelData = this.prepareData(
|
128
|
+
sourceItems,
|
129
|
+
levelConfig,
|
130
|
+
currentLevel + 1
|
131
|
+
);
|
132
|
+
column.children = processLevel(
|
133
|
+
nextLevelData,
|
134
|
+
currentLevel + 1,
|
135
|
+
currentPath
|
136
|
+
);
|
137
|
+
}
|
138
|
+
if (config.columnConfig) {
|
139
|
+
Object.assign(
|
140
|
+
column,
|
141
|
+
config.columnConfig(currentPath, sourceItems)
|
142
|
+
);
|
143
|
+
}
|
144
|
+
return column;
|
145
|
+
}
|
146
|
+
);
|
147
|
+
};
|
148
|
+
|
149
|
+
// 预处理初始数据
|
150
|
+
const initialData = this.prepareData(
|
151
|
+
data,
|
152
|
+
levelConfig,
|
153
|
+
0,
|
154
|
+
levelConfig[0].root
|
155
|
+
);
|
156
|
+
return processLevel(initialData);
|
157
|
+
},
|
158
|
+
// 打平数据 - 将多层级的数据结构转换为扁平化的对象结构
|
159
|
+
flattenData(data, levelConfig) {
|
160
|
+
// 将单个对象打平的内部函数
|
161
|
+
const flattenObject = (item, config, parentPath = "") => {
|
162
|
+
// 创建结果对象,复制原始item的属性
|
163
|
+
const result = item;
|
164
|
+
|
165
|
+
// 处理每一层级数据的递归函数
|
166
|
+
const processLevel = (currentItem, currentConfig, currentPath) => {
|
167
|
+
// 如果没有配置信息则返回
|
168
|
+
if (!currentConfig) return;
|
169
|
+
|
170
|
+
// 获取当前层级的子节点数据
|
171
|
+
const children = currentItem[currentConfig.path || "children"];
|
172
|
+
// 如果子节点不是数组则返回
|
173
|
+
if (!Array.isArray(children)) return;
|
174
|
+
|
175
|
+
// 遍历每个子节点
|
176
|
+
children.forEach((child) => {
|
177
|
+
// 获取标识符 - 可以是函数或属性名
|
178
|
+
const identifier =
|
179
|
+
typeof currentConfig.prop === "function"
|
180
|
+
? currentConfig.prop(child)
|
181
|
+
: child[currentConfig.prop];
|
182
|
+
|
183
|
+
// 如果没有标识符则跳过
|
184
|
+
if (!identifier) return;
|
185
|
+
|
186
|
+
// 构建新的路径名
|
187
|
+
const newPath = currentPath
|
188
|
+
? `${currentPath}-${identifier}`
|
189
|
+
: identifier;
|
190
|
+
|
191
|
+
// 遍历子节点的所有属性
|
192
|
+
Object.entries(child).forEach(([key, value]) => {
|
193
|
+
// 只处理非数组类型的值
|
194
|
+
if (!Array.isArray(value)) {
|
195
|
+
this.$set(result, `${newPath}-${key}`, value);
|
196
|
+
}
|
197
|
+
});
|
198
|
+
|
199
|
+
// 获取下一层级的配置
|
200
|
+
const nextConfig = config[config.indexOf(currentConfig) + 1];
|
201
|
+
// 如果存在下一层级配置,则递归处理
|
202
|
+
if (nextConfig) {
|
203
|
+
processLevel(child, nextConfig, newPath);
|
204
|
+
}
|
205
|
+
});
|
206
|
+
};
|
207
|
+
|
208
|
+
// 从第一层配置开始处理
|
209
|
+
processLevel(item, config[0], parentPath);
|
210
|
+
return result;
|
211
|
+
};
|
212
|
+
|
213
|
+
// 对数据数组中的每个对象进行打平处理
|
214
|
+
data.forEach((item) => flattenObject(item, levelConfig));
|
215
|
+
},
|
216
|
+
// 将数据映射为树形结构
|
217
|
+
transformToTree(data, levelConfig) {
|
218
|
+
const transformObject = (item, config) => {
|
219
|
+
const processLevel = (currentItem, currentConfig, level = 0) => {
|
220
|
+
if (!currentConfig) return;
|
221
|
+
|
222
|
+
const children = currentItem[currentConfig.path];
|
223
|
+
if (!Array.isArray(children)) return;
|
224
|
+
|
225
|
+
children.forEach((child) => {
|
226
|
+
const identifier =
|
227
|
+
typeof currentConfig.prop === "function"
|
228
|
+
? currentConfig.prop(child)
|
229
|
+
: child[currentConfig.prop];
|
230
|
+
|
231
|
+
if (!identifier) return;
|
232
|
+
|
233
|
+
// 直接使用原始对象,而不是创建新对象
|
234
|
+
this.$set(currentItem, identifier, child);
|
235
|
+
|
236
|
+
// 递归处理下一层级
|
237
|
+
const nextConfig = config[level + 1];
|
238
|
+
if (nextConfig && child[nextConfig.path]) {
|
239
|
+
processLevel(child, nextConfig, level + 1);
|
240
|
+
}
|
241
|
+
});
|
242
|
+
};
|
243
|
+
|
244
|
+
processLevel(item, config[0], 0);
|
245
|
+
};
|
246
|
+
|
247
|
+
data.forEach((item) => transformObject(item, levelConfig));
|
248
|
+
},
|
249
|
+
},
|
250
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
export default [
|
2
|
+
"data",
|
3
|
+
"size",
|
4
|
+
"width",
|
5
|
+
"height",
|
6
|
+
"maxHeight",
|
7
|
+
"fit",
|
8
|
+
"stripe",
|
9
|
+
"border",
|
10
|
+
"rowKey",
|
11
|
+
"context",
|
12
|
+
"showHeader",
|
13
|
+
"showSummary",
|
14
|
+
"sumText",
|
15
|
+
"summaryMethod",
|
16
|
+
"rowClassName",
|
17
|
+
"rowStyle",
|
18
|
+
"cellClassName",
|
19
|
+
"cellStyle",
|
20
|
+
"headerRowClassName",
|
21
|
+
"headerRowStyle",
|
22
|
+
"headerCellClassName",
|
23
|
+
"headerCellStyle",
|
24
|
+
"highlightCurrentRow",
|
25
|
+
"highlightSelectionRow",
|
26
|
+
"currentRowKey",
|
27
|
+
"emptyText",
|
28
|
+
"expandRowKeys",
|
29
|
+
"defaultExpandAll",
|
30
|
+
"defaultSort",
|
31
|
+
"tooltipEffect",
|
32
|
+
"spanMethod",
|
33
|
+
"selectOnIndeterminate",
|
34
|
+
"indent",
|
35
|
+
"treeProps",
|
36
|
+
"lazy",
|
37
|
+
"load",
|
38
|
+
];
|
@@ -0,0 +1,151 @@
|
|
1
|
+
import dayjs from "dayjs";
|
2
|
+
import { isFunction } from "lodash-es";
|
3
|
+
import { isEmptyData } from "utils";
|
4
|
+
|
5
|
+
export default {
|
6
|
+
methods: {
|
7
|
+
// 处理本地搜索
|
8
|
+
handleLocalSearch() {
|
9
|
+
if (!this.crudOptions.localSearch) return;
|
10
|
+
|
11
|
+
this.localFilteredData = this.data.filter((row) => {
|
12
|
+
return Object.entries(this.query).every(([key, value]) => {
|
13
|
+
if (isEmptyData(value)) return true;
|
14
|
+
if (Array.isArray(value) && value.every(isEmptyData)) return true;
|
15
|
+
|
16
|
+
const column = this.columnsMap[key];
|
17
|
+
if (!column) return true;
|
18
|
+
|
19
|
+
const cellValue = row[key];
|
20
|
+
if (cellValue === undefined || cellValue === null) return false;
|
21
|
+
|
22
|
+
return this.filterBySearchType(column, cellValue, value, row);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
|
26
|
+
// 如果使用本地分页,重置到第一页
|
27
|
+
if (this.crudOptions.localPagination) {
|
28
|
+
const { pageNum } = this.crudOptions.props;
|
29
|
+
this.query[pageNum] = 1;
|
30
|
+
}
|
31
|
+
},
|
32
|
+
// 日期类型过滤
|
33
|
+
filterDateValue(cellValue, searchValue) {
|
34
|
+
if (!cellValue || !searchValue) return true;
|
35
|
+
|
36
|
+
const cellDate = dayjs(cellValue);
|
37
|
+
|
38
|
+
if (Array.isArray(searchValue)) {
|
39
|
+
const [startDate, endDate] = searchValue.map((date) => dayjs(date));
|
40
|
+
|
41
|
+
// 检查是否为同一天
|
42
|
+
if (startDate.isSame(endDate, "day")) {
|
43
|
+
return cellDate.isSame(startDate, "day");
|
44
|
+
}
|
45
|
+
|
46
|
+
// 范围查询处理
|
47
|
+
if (startDate.isValid() && endDate.isValid()) {
|
48
|
+
return (
|
49
|
+
(cellDate.isAfter(startDate.startOf("day")) ||
|
50
|
+
cellDate.isSame(startDate, "day")) &&
|
51
|
+
(cellDate.isBefore(endDate.endOf("day")) ||
|
52
|
+
cellDate.isSame(endDate, "day"))
|
53
|
+
);
|
54
|
+
}
|
55
|
+
|
56
|
+
// 单边范围的处理
|
57
|
+
if (startDate.isValid()) {
|
58
|
+
return (
|
59
|
+
cellDate.isAfter(startDate.startOf("day")) ||
|
60
|
+
cellDate.isSame(startDate, "day")
|
61
|
+
);
|
62
|
+
}
|
63
|
+
if (endDate.isValid()) {
|
64
|
+
return (
|
65
|
+
cellDate.isBefore(endDate.endOf("day")) ||
|
66
|
+
cellDate.isSame(endDate, "day")
|
67
|
+
);
|
68
|
+
}
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
|
72
|
+
// 单个日期的处理
|
73
|
+
return cellDate.isSame(dayjs(searchValue), "day");
|
74
|
+
},
|
75
|
+
|
76
|
+
// 判断两个日期是否是同一天
|
77
|
+
isSameDay(date1, date2) {
|
78
|
+
return (
|
79
|
+
date1.getFullYear() === date2.getFullYear() &&
|
80
|
+
date1.getMonth() === date2.getMonth() &&
|
81
|
+
date1.getDate() === date2.getDate()
|
82
|
+
);
|
83
|
+
},
|
84
|
+
|
85
|
+
// 根据搜索类型过滤数据
|
86
|
+
filterBySearchType(column, cellValue, value, row) {
|
87
|
+
const COMPONENT_MAP = {
|
88
|
+
"el-input": "input",
|
89
|
+
"el-select": "select",
|
90
|
+
"el-date-picker": "date",
|
91
|
+
"el-cascader": "cascader",
|
92
|
+
};
|
93
|
+
|
94
|
+
const searchType =
|
95
|
+
column.search?.type ||
|
96
|
+
COMPONENT_MAP[column.search?.comp?.name] ||
|
97
|
+
"input";
|
98
|
+
if (isFunction(column.search?.filter)) {
|
99
|
+
return column.search.filter(cellValue, value, row, this.data);
|
100
|
+
}
|
101
|
+
switch (searchType) {
|
102
|
+
case "input":
|
103
|
+
return String(cellValue)
|
104
|
+
.toLowerCase()
|
105
|
+
.includes(String(value).toLowerCase());
|
106
|
+
|
107
|
+
case "select":
|
108
|
+
return String(cellValue) === String(value);
|
109
|
+
|
110
|
+
case "date":
|
111
|
+
return this.filterDateValue(cellValue, value);
|
112
|
+
|
113
|
+
default:
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
},
|
117
|
+
// 搜索
|
118
|
+
handleSearch() {
|
119
|
+
this.changeLoading(true);
|
120
|
+
this.runBefore("search", (res) => {
|
121
|
+
this.changeLoading();
|
122
|
+
this.handleLocalSearch();
|
123
|
+
!this.crudOptions.localSearch && this.$nextTick(this.getList);
|
124
|
+
this.$emit("closeSearchPopover");
|
125
|
+
});
|
126
|
+
},
|
127
|
+
// 重置
|
128
|
+
handleReset(prop) {
|
129
|
+
this.changeLoading(true);
|
130
|
+
this.runBefore(
|
131
|
+
"reset",
|
132
|
+
(res) => {
|
133
|
+
this.changeLoading();
|
134
|
+
const searchRef = this.$refs.searchRef;
|
135
|
+
if (!searchRef) return;
|
136
|
+
if (prop) {
|
137
|
+
searchRef.resetField(prop);
|
138
|
+
} else {
|
139
|
+
searchRef.resetFields();
|
140
|
+
searchRef.searchForm.renderColumns.forEach((item) => {
|
141
|
+
if (isFunction(item.reset)) item.reset();
|
142
|
+
});
|
143
|
+
}
|
144
|
+
!this.crudOptions.localSearch && this.$nextTick(this.getList);
|
145
|
+
this.crudOptions.localSearch && (this.localFilteredData = undefined);
|
146
|
+
},
|
147
|
+
prop
|
148
|
+
);
|
149
|
+
},
|
150
|
+
},
|
151
|
+
};
|