vue-super-crud 1.7.1 → 1.7.4
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/README.md +42 -10
- package/lib/index.css +1 -1
- package/lib/super-crud.min.js +2 -2
- package/package.json +21 -16
- package/src/config/common.js +2 -1
- package/src/config/crud.js +3 -3
- package/src/index.js +4 -0
- package/src/template/formatData.js +75 -87
- package/.browserslistrc +0 -3
- package/.versionrc.json +0 -36
- package/CHANGELOG.md +0 -232
- package/babel.config.js +0 -12
- package/build/alias.js +0 -10
- package/build/build.js +0 -52
- package/build/config.js +0 -70
- package/deploy.bat +0 -14
- package/docs/.vuepress/components/button/base.vue +0 -88
- package/docs/.vuepress/components/common/code-format.vue +0 -331
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/base.vue +0 -68
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/customParams.vue +0 -73
- package/docs/.vuepress/components/commonConfig/renderType/component.vue +0 -160
- package/docs/.vuepress/components/commonConfig/renderType/formatter.vue +0 -49
- package/docs/.vuepress/components/commonConfig/renderType/render.vue +0 -91
- package/docs/.vuepress/components/commonConfig/renderType/slot.vue +0 -63
- package/docs/.vuepress/components/crud/baseUse/baseUse.vue +0 -98
- package/docs/.vuepress/components/crud/baseUse/columnAction.vue +0 -72
- package/docs/.vuepress/components/crud/baseUse/columnWidth.vue +0 -107
- package/docs/.vuepress/components/crud/baseUse/handleRow.vue +0 -65
- package/docs/.vuepress/components/crud/baseUse/height.vue +0 -82
- package/docs/.vuepress/components/crud/baseUse/index.vue +0 -54
- package/docs/.vuepress/components/crud/baseUse/loading.vue +0 -70
- package/docs/.vuepress/components/crud/baseUse/pagination.vue +0 -108
- package/docs/.vuepress/components/crud/baseUse/selection.vue +0 -114
- package/docs/.vuepress/components/crud/baseUse/summaryMethod.vue +0 -118
- package/docs/.vuepress/components/crud/baseUse/title.vue +0 -54
- package/docs/.vuepress/components/crud/baseUse/toolbar.vue +0 -69
- package/docs/.vuepress/components/crud/buttons/common.vue +0 -115
- package/docs/.vuepress/components/crud/buttons/fast.vue +0 -82
- package/docs/.vuepress/components/crud/contextMenu/base.vue +0 -72
- package/docs/.vuepress/components/crud/copy.vue +0 -52
- package/docs/.vuepress/components/crud/crudEvents/api.vue +0 -157
- package/docs/.vuepress/components/crud/crudEvents/deleteTip.vue +0 -93
- package/docs/.vuepress/components/crud/crudEvents/events.vue +0 -188
- package/docs/.vuepress/components/crud/dataSort/base.vue +0 -142
- package/docs/.vuepress/components/crud/genDynamicColumns/base.vue +0 -53
- package/docs/.vuepress/components/crud/genDynamicColumns/dynamicAndFixed.vue +0 -111
- package/docs/.vuepress/components/crud/genDynamicColumns/treeDynamic.vue +0 -68
- package/docs/.vuepress/components/crud/handleBar/handleRow.vue +0 -65
- package/docs/.vuepress/components/crud/handleBar/toolbar.vue +0 -69
- package/docs/.vuepress/components/crud/renderType/1.vue +0 -57
- package/docs/.vuepress/components/crud/renderType/2.vue +0 -63
- package/docs/.vuepress/components/crud/renderType/3.vue +0 -105
- package/docs/.vuepress/components/crud/renderType/5.vue +0 -91
- package/docs/.vuepress/components/crud/search/1.vue +0 -90
- package/docs/.vuepress/components/crud/search/2.vue +0 -78
- package/docs/.vuepress/components/crud/search/3.vue +0 -107
- package/docs/.vuepress/components/crud/search/base.vue +0 -123
- package/docs/.vuepress/components/crud/search/localSearch.vue +0 -124
- package/docs/.vuepress/components/crud/search/special.vue +0 -148
- package/docs/.vuepress/components/crud/selection/events.vue +0 -47
- package/docs/.vuepress/components/crud/selection/pagination.vue +0 -94
- package/docs/.vuepress/components/crud/selection/singleSelection.vue +0 -64
- package/docs/.vuepress/components/crud/span/base.vue +0 -69
- package/docs/.vuepress/components/crud/span/special.vue +0 -75
- package/docs/.vuepress/components/crud/summary/base.vue +0 -99
- package/docs/.vuepress/components/crud/tableEdit/addDeleteBtn.vue +0 -174
- package/docs/.vuepress/components/crud/tableEdit/cellEdit.vue +0 -194
- package/docs/.vuepress/components/crud/tableEdit/controlEdit.vue +0 -219
- package/docs/.vuepress/components/crud/tableEdit/dialog.vue +0 -172
- package/docs/.vuepress/components/crud/tableEdit/free.vue +0 -88
- package/docs/.vuepress/components/crud/tableEdit/freeColumn.vue +0 -82
- package/docs/.vuepress/components/crud/tableEdit/methods.vue +0 -154
- package/docs/.vuepress/components/crud/tableEdit/rowAction.vue +0 -107
- package/docs/.vuepress/components/crud/tableEdit/rowBatch.vue +0 -116
- package/docs/.vuepress/components/crud/tableEdit/rowClick.vue +0 -98
- package/docs/.vuepress/components/crud/validate/base.vue +0 -122
- package/docs/.vuepress/components/crud/validate/custom.vue +0 -82
- package/docs/.vuepress/components/crud/validate/regulars.vue +0 -88
- package/docs/.vuepress/components/crud/validate/relation.vue +0 -91
- package/docs/.vuepress/components/crud/validate/tree.vue +0 -82
- package/docs/.vuepress/components/dialog/baseUse/base.vue +0 -92
- package/docs/.vuepress/components/dialog/baseUse/beforeConfirm.vue +0 -78
- package/docs/.vuepress/components/dialog/baseUse/control.vue +0 -79
- package/docs/.vuepress/components/dialog/baseUse/drawer.vue +0 -59
- package/docs/.vuepress/components/dialog/baseUse/footer.vue +0 -87
- package/docs/.vuepress/components/dialog/baseUse/insertSlot.vue +0 -79
- package/docs/.vuepress/components/dict/DictLinkage.vue +0 -91
- package/docs/.vuepress/components/dict/baseUse.vue +0 -72
- package/docs/.vuepress/components/dict/component.vue +0 -82
- package/docs/.vuepress/components/dict/localDict.vue +0 -68
- package/docs/.vuepress/components/form/baseUse/base.vue +0 -48
- package/docs/.vuepress/components/form/baseUse/dataFormat.vue +0 -92
- package/docs/.vuepress/components/form/baseUse/deep.vue +0 -57
- package/docs/.vuepress/components/form/baseUse/gridLayout.vue +0 -47
- package/docs/.vuepress/components/form/baseUse/group.vue +0 -66
- package/docs/.vuepress/components/form/baseUse/hidden.vue +0 -40
- package/docs/.vuepress/components/form/baseUse/inlineLayout.vue +0 -48
- package/docs/.vuepress/components/form/baseUse/label.vue +0 -51
- package/docs/.vuepress/components/form/baseUse/tooltip.vue +0 -40
- package/docs/.vuepress/components/form/baseUse/validate.vue +0 -52
- package/docs/.vuepress/components/form/detail/base.vue +0 -78
- package/docs/.vuepress/components/form/detail/border.vue +0 -90
- package/docs/.vuepress/components/form/detail/singleDetail.vue +0 -72
- package/docs/.vuepress/components/formatData/baseUse.vue +0 -131
- package/docs/.vuepress/components/mock/index.js +0 -347
- package/docs/.vuepress/components/mockData/custom.vue +0 -69
- package/docs/.vuepress/components/mockData/example.vue +0 -290
- package/docs/.vuepress/components/positionSlot/base.vue +0 -24
- package/docs/.vuepress/components/positionSlot/form.vue +0 -71
- package/docs/.vuepress/components/positionSlot/table.vue +0 -85
- package/docs/.vuepress/components/tabs/base.vue +0 -57
- package/docs/.vuepress/components/temp.js +0 -195
- package/docs/.vuepress/config.js +0 -146
- package/docs/.vuepress/enhanceApp.js +0 -142
- package/docs/.vuepress/public/favicon.ico +0 -0
- package/docs/.vuepress/public/super.png +0 -0
- package/docs/.vuepress/styles/index.styl +0 -25
- package/docs/.vuepress/styles/palette.styl +0 -6
- package/docs/README.md +0 -14
- package/docs/guide/button/base.md +0 -31
- package/docs/guide/commonConfig/jsx.md +0 -166
- package/docs/guide/commonConfig/presetCodeTemplate.md +0 -68
- package/docs/guide/commonConfig/renderType.md +0 -181
- package/docs/guide/crud/baseUse.md +0 -120
- package/docs/guide/crud/buttons.md +0 -18
- package/docs/guide/crud/config.md +0 -217
- package/docs/guide/crud/contextMenu.md +0 -18
- package/docs/guide/crud/dataSort.md +0 -66
- package/docs/guide/crud/genDynamicColumns.md +0 -145
- package/docs/guide/crud/handleBar.md +0 -26
- package/docs/guide/crud/renderType.md +0 -4
- package/docs/guide/crud/search.md +0 -150
- package/docs/guide/crud/selection.md +0 -73
- package/docs/guide/crud/span.md +0 -98
- package/docs/guide/crud/summary.md +0 -167
- package/docs/guide/crud/tableEdit.md +0 -377
- package/docs/guide/crud/validate.md +0 -158
- package/docs/guide/dialog/baseUse.md +0 -81
- package/docs/guide/dict/baseUse.md +0 -174
- package/docs/guide/dict/component.md +0 -88
- package/docs/guide/dict/config.md +0 -44
- package/docs/guide/form/baseUse.md +0 -142
- package/docs/guide/form/detail.md +0 -38
- package/docs/guide/formatData/baseUse.md +0 -98
- package/docs/guide/formatData/config.md +0 -142
- package/docs/guide/mockData/base.md +0 -26
- package/docs/guide/positionSlot/base.md +0 -41
- package/docs/guide/question/base.md +0 -44
- package/docs/guide/start/base.md +0 -30
- package/docs/guide/tabs/base.md +0 -63
- package/examples/App.vue +0 -52
- package/examples/Layout/components/AppMain.vue +0 -40
- package/examples/Layout/components/Item.vue +0 -29
- package/examples/Layout/components/Link.vue +0 -44
- package/examples/Layout/components/SidebarItem.vue +0 -93
- package/examples/Layout/index.vue +0 -69
- package/examples/assets/logo.png +0 -0
- package/examples/favicon.ico +0 -0
- package/examples/index.html +0 -18
- package/examples/main.js +0 -54
- package/examples/router/index.js +0 -140
- package/examples/store/index.js +0 -0
- package/examples/styles/index.scss +0 -63
- package/examples/styles/sidebar.scss +0 -226
- package/examples/styles/transition.scss +0 -48
- package/examples/styles/variables.scss +0 -25
- package/examples/views/crud/base.vue +0 -68
- package/examples/views/crud/handleRow.vue +0 -84
- package/examples/views/crud/search.vue +0 -116
- package/examples/views/dashboard/index.vue +0 -244
- package/examples/views/dashboard/index1.vue +0 -234
- package/examples/views/dashboard/test.vue +0 -9
- package/examples/views/formTest/index.vue +0 -168
- package/examples/views/nested/menu1/index.vue +0 -7
- package/examples/views/nested/menu1/menu1-1/index.vue +0 -7
- package/examples/views/nested/menu1/menu1-2/index.vue +0 -7
- package/examples/views/nested/menu1/menu1-2/menu1-2-1/index.vue +0 -5
- package/examples/views/nested/menu1/menu1-2/menu1-2-2/index.vue +0 -5
- package/examples/views/nested/menu1/menu1-3/index.vue +0 -5
- package/examples/views/nested/menu2/index.vue +0 -5
- package/gulpfile.js +0 -84
- package/packages/button/index.vue +0 -189
- package/packages/core/components/comp.vue +0 -223
- package/packages/core/components/position.vue +0 -135
- package/packages/core/components/render.vue +0 -460
- package/packages/core/configManager.js +0 -302
- package/packages/core/create.js +0 -8
- package/packages/core/defaultRender.js +0 -64
- package/packages/core/dict/global.js +0 -10
- package/packages/core/dict/index.js +0 -432
- package/packages/core/dict/mixin.js +0 -94
- package/packages/core/event.js +0 -60
- package/packages/core/index.js +0 -6
- package/packages/core/init.js +0 -122
- package/packages/core/mock/genConfig.js +0 -228
- package/packages/core/mock/genData.js +0 -422
- package/packages/core/mock/index.js +0 -4
- package/packages/core/rules.js +0 -111
- package/packages/crud/column.vue +0 -205
- package/packages/crud/columnAction.vue +0 -207
- package/packages/crud/columnCell.vue +0 -146
- package/packages/crud/defaultColumn.vue +0 -130
- package/packages/crud/drawerColumn.vue +0 -225
- package/packages/crud/form.vue +0 -69
- package/packages/crud/index.vue +0 -564
- package/packages/crud/menuBar.vue +0 -298
- package/packages/crud/mixins/cacheHandler.js +0 -36
- package/packages/crud/mixins/calcColumnWidth.js +0 -79
- package/packages/crud/mixins/calcHeight.js +0 -105
- package/packages/crud/mixins/columnHandler.js +0 -128
- package/packages/crud/mixins/contextMenu.js +0 -98
- package/packages/crud/mixins/dataProcessor.js +0 -202
- package/packages/crud/mixins/dialog.js +0 -109
- package/packages/crud/mixins/excelHandler.js +0 -150
- package/packages/crud/mixins/exposeMethods.js +0 -107
- package/packages/crud/mixins/generateDynamicColumns.js +0 -250
- package/packages/crud/mixins/props.js +0 -38
- package/packages/crud/mixins/searchHandler.js +0 -151
- package/packages/crud/mixins/select.js +0 -359
- package/packages/crud/mixins/spanMethod.js +0 -288
- package/packages/crud/mixins/summary.js +0 -177
- package/packages/crud/mixins/tableEdit.js +0 -547
- package/packages/crud/mixins/validate.js +0 -219
- package/packages/crud/pagination.vue +0 -110
- package/packages/crud/search.vue +0 -119
- package/packages/crud/searchHeader.vue +0 -231
- package/packages/crud/selectBanner.vue +0 -138
- package/packages/crud/utils/EditState.js +0 -319
- package/packages/crud/utils/excelExport.js +0 -112
- package/packages/crud/utils/excelImport.js +0 -112
- package/packages/crud/utils/index.js +0 -98
- package/packages/dialog/dialog.js +0 -233
- package/packages/dialog/dialog.vue +0 -15
- package/packages/dialog/index.js +0 -22
- package/packages/dict/cascadeFormat.vue +0 -179
- package/packages/dict/dateFormat.vue +0 -40
- package/packages/dict/form/cascade.vue +0 -61
- package/packages/dict/form/checkbox.vue +0 -90
- package/packages/dict/form/extendMethod.js +0 -22
- package/packages/dict/form/input-base.js +0 -31
- package/packages/dict/form/input.js +0 -20
- package/packages/dict/form/radio.vue +0 -69
- package/packages/dict/form/select.vue +0 -118
- package/packages/dict/form/switch.vue +0 -75
- package/packages/dict/valueFormat.vue +0 -188
- package/packages/directive/dialog/drag.js +0 -86
- package/packages/directive/dialog/dragSize.js +0 -42
- package/packages/directive/index.js +0 -9
- package/packages/directive/insertSlot.js +0 -10
- package/packages/form/contextMenu.js +0 -192
- package/packages/form/draftDrawer.vue +0 -391
- package/packages/form/formAction.vue +0 -97
- package/packages/form/formItem.vue +0 -259
- package/packages/form/index.vue +0 -451
- package/packages/form/props.js +0 -15
- package/packages/grid/cell.vue +0 -65
- package/packages/grid/index.vue +0 -130
- package/packages/group/index.vue +0 -96
- package/packages/tabs/index.vue +0 -290
- package/packages/tooltip/index.js +0 -9
- package/packages/tooltip/tooltip.vue +0 -32
- package/packages/tooltip/tooltipComponent.js +0 -38
- package/packages/verifyInput/index.vue +0 -131
- package/styles/button.scss +0 -3
- package/styles/crud.scss +0 -425
- package/styles/dialog.scss +0 -95
- package/styles/form.scss +0 -532
- package/styles/group.scss +0 -78
- package/styles/index.scss +0 -94
- package/styles/tabs.scss +0 -139
- package/styles/verifyInput.scss +0 -56
- package/vue-jsx-sync.js +0 -90
- package/vue.config.js +0 -54
@@ -1,460 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
import { isComponent, isVNode } from "utils";
|
3
|
-
import Comp from "./comp.vue";
|
4
|
-
import {
|
5
|
-
cloneDeep,
|
6
|
-
isFunction,
|
7
|
-
isPlainObject,
|
8
|
-
merge,
|
9
|
-
get,
|
10
|
-
set,
|
11
|
-
} from "lodash-es";
|
12
|
-
import { mergeTemp } from "utils/mergeTemp";
|
13
|
-
import { defaultRender as _defaultRender } from "core";
|
14
|
-
import DictMixin from "../dict/mixin";
|
15
|
-
import position from "./position.vue";
|
16
|
-
import { isEmptyData, resolveRender } from "utils";
|
17
|
-
import {
|
18
|
-
getComponentConfig,
|
19
|
-
generateMockData,
|
20
|
-
generateCustomMockData,
|
21
|
-
} from "../mock/index";
|
22
|
-
export default {
|
23
|
-
name: "render",
|
24
|
-
props: {
|
25
|
-
value: {},
|
26
|
-
prop: {
|
27
|
-
type: String,
|
28
|
-
default: "",
|
29
|
-
},
|
30
|
-
comp: [Object, Function],
|
31
|
-
render: Function,
|
32
|
-
item: Object,
|
33
|
-
raw: Object, // 未加工的item
|
34
|
-
slots: Object,
|
35
|
-
mode: [String, Boolean],
|
36
|
-
scope: {},
|
37
|
-
size: String,
|
38
|
-
controlDefault: Function, // 控制已有的默认渲染
|
39
|
-
defaultRender: Function, // 自定义默认渲染
|
40
|
-
position: Boolean, // 是否渲染位置
|
41
|
-
compStrategy: Array, // 渲染策略
|
42
|
-
commonCompStrategy: Object, // 公共组件策略
|
43
|
-
defaultComp: Object, // 默认组件
|
44
|
-
rawRules: Array, // 未加工的rules
|
45
|
-
strategies: Object, // 策略
|
46
|
-
},
|
47
|
-
inject: {
|
48
|
-
controlCtx: { default: undefined },
|
49
|
-
elForm: {
|
50
|
-
default: "",
|
51
|
-
},
|
52
|
-
},
|
53
|
-
mixins: [DictMixin],
|
54
|
-
computed: {
|
55
|
-
$value: {
|
56
|
-
get() {
|
57
|
-
try {
|
58
|
-
const input = this.item.formatData?.input;
|
59
|
-
if (input) return input(this.getRow(), this.scope);
|
60
|
-
return this.getRow();
|
61
|
-
} catch (error) {
|
62
|
-
console.error("获取格式化值失败:", error);
|
63
|
-
return this.getRow();
|
64
|
-
}
|
65
|
-
},
|
66
|
-
set(value) {
|
67
|
-
try {
|
68
|
-
this.setFormatValue(value);
|
69
|
-
} catch (error) {
|
70
|
-
console.error("设置格式化值失败:", error);
|
71
|
-
this.setRow(this.prop, value);
|
72
|
-
}
|
73
|
-
},
|
74
|
-
},
|
75
|
-
},
|
76
|
-
created() {
|
77
|
-
if (this.item.formatData) {
|
78
|
-
setTimeout(() => {
|
79
|
-
this.isSettingValue = false;
|
80
|
-
this.$watch("value", (val) => {
|
81
|
-
// 防止重复触发
|
82
|
-
if (this.isSettingValue) return;
|
83
|
-
this.setFormatValue(this.$value);
|
84
|
-
});
|
85
|
-
this.setFormatValue(this.$value);
|
86
|
-
}, 0);
|
87
|
-
}
|
88
|
-
if (this.compStrategy) {
|
89
|
-
this.matcher = this.createMatcher(this.compStrategy);
|
90
|
-
}
|
91
|
-
if (this.controlCtx) {
|
92
|
-
this.setupMockDataListener();
|
93
|
-
}
|
94
|
-
},
|
95
|
-
mounted() {
|
96
|
-
if (this.item.ref && typeof this.item.ref === "function") {
|
97
|
-
this.item.ref(this.$vnode.componentInstance);
|
98
|
-
}
|
99
|
-
},
|
100
|
-
destroyed() {
|
101
|
-
if (this.controlCtx && this.mockDataListener) {
|
102
|
-
this.controlCtx.$off("mockData", this.mockDataListener);
|
103
|
-
this.mockDataListener = null;
|
104
|
-
}
|
105
|
-
},
|
106
|
-
methods: {
|
107
|
-
setupMockDataListener() {
|
108
|
-
this.mockDataListener = () => {
|
109
|
-
if (
|
110
|
-
(this.elForm || {}).disabled ||
|
111
|
-
(!isEmptyData(this.$value) && this.$value !== 0)
|
112
|
-
)
|
113
|
-
return;
|
114
|
-
const config = this.getComponentConfig();
|
115
|
-
if (config && config.disabled) return;
|
116
|
-
if (this.item.mock) {
|
117
|
-
const mockValue = generateCustomMockData(this.item.mock, this.scope);
|
118
|
-
mockValue && this.setFormatValue(mockValue);
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
|
122
|
-
const mockValue = generateMockData(config, {
|
123
|
-
pattern: this.getPattern(),
|
124
|
-
});
|
125
|
-
!isEmptyData(mockValue) && this.setFormatValue(mockValue);
|
126
|
-
};
|
127
|
-
|
128
|
-
this.controlCtx.$on("mockData", this.mockDataListener);
|
129
|
-
},
|
130
|
-
getComponentConfig() {
|
131
|
-
return getComponentConfig(this.$vnode);
|
132
|
-
},
|
133
|
-
getPattern() {
|
134
|
-
const rules = this.rawRules;
|
135
|
-
if (rules) {
|
136
|
-
const pattern = rules.find((rule) => rule.regular);
|
137
|
-
if (pattern) return pattern.regular;
|
138
|
-
}
|
139
|
-
},
|
140
|
-
getRow() {
|
141
|
-
if (!this.prop) return this.scope.row;
|
142
|
-
return get(this.scope.row, this.prop);
|
143
|
-
},
|
144
|
-
// 设置行数据
|
145
|
-
setRow(prop, val) {
|
146
|
-
if (!prop) {
|
147
|
-
this.$set(this.scope, "row", val);
|
148
|
-
return;
|
149
|
-
}
|
150
|
-
// 处理数组路径 ['a', 'b'] 或字符串路径 'a.b'
|
151
|
-
const path = Array.isArray(prop) ? prop : prop.split(".");
|
152
|
-
if (path.length > 1) {
|
153
|
-
if (!get(this.scope.row, path)) {
|
154
|
-
// 绑定深层响应式对象
|
155
|
-
path.slice(0, -1).reduce((obj, key, index) => {
|
156
|
-
// 如果当前key值不存在,创建一个新响应式对象
|
157
|
-
if (!obj[key] || typeof obj[key] !== "object") {
|
158
|
-
this.$set(obj, key, {});
|
159
|
-
}
|
160
|
-
return obj[key];
|
161
|
-
}, this.scope.row);
|
162
|
-
|
163
|
-
// 获取最后一层的父对象
|
164
|
-
const parentObj = path
|
165
|
-
.slice(0, -1)
|
166
|
-
.reduce((obj, key) => obj[key], this.scope.row);
|
167
|
-
|
168
|
-
this.$set(parentObj, path[path.length - 1], val);
|
169
|
-
} else {
|
170
|
-
set(this.scope.row, path, val);
|
171
|
-
this.$set(this.scope.row, path[0], this.scope.row[path[0]]);
|
172
|
-
}
|
173
|
-
} else {
|
174
|
-
// 触发响应式更新
|
175
|
-
this.$set(this.scope.row, prop, val);
|
176
|
-
}
|
177
|
-
},
|
178
|
-
setFormatValue(value) {
|
179
|
-
const output = this.item.formatData?.output;
|
180
|
-
if (output) {
|
181
|
-
this.isSettingValue = true; // 设置标志
|
182
|
-
const outputValue = output(value, this.scope, this.setRow);
|
183
|
-
const formatValueProp = get(this.item, ["formatData", "formatValue"]);
|
184
|
-
if (formatValueProp && typeof formatValueProp === "string") {
|
185
|
-
this.setRow(formatValueProp, value);
|
186
|
-
} else if (formatValueProp) {
|
187
|
-
this.setRow("$" + this.prop, value);
|
188
|
-
}
|
189
|
-
if (outputValue !== undefined) {
|
190
|
-
this.setRow(this.prop, outputValue);
|
191
|
-
}
|
192
|
-
this.$nextTick(() => {
|
193
|
-
this.isSettingValue = false; // 重置标志
|
194
|
-
});
|
195
|
-
} else {
|
196
|
-
this.setRow(this.prop, value);
|
197
|
-
}
|
198
|
-
},
|
199
|
-
interruptibleCompose(...funcs) {
|
200
|
-
return funcs.reduce((f1, f2) => {
|
201
|
-
return function (...args) {
|
202
|
-
var result = f1.apply(this, args);
|
203
|
-
return result ? result : f2.apply(this, args);
|
204
|
-
};
|
205
|
-
});
|
206
|
-
},
|
207
|
-
getSlot(h, scope) {
|
208
|
-
const slots = this.slots;
|
209
|
-
const prop = this.prop;
|
210
|
-
const mode = this.mode;
|
211
|
-
if (isFunction(slots)) slots = slots();
|
212
|
-
if (slots) {
|
213
|
-
let slotName;
|
214
|
-
if (prop && mode) {
|
215
|
-
slotName = `${prop}-${mode}`;
|
216
|
-
} else if (prop && !mode) {
|
217
|
-
slotName = prop;
|
218
|
-
} else if (!prop && mode) {
|
219
|
-
slotName = mode;
|
220
|
-
}
|
221
|
-
const slot = slots[slotName];
|
222
|
-
if (slot) return slot(scope);
|
223
|
-
}
|
224
|
-
},
|
225
|
-
getRender(h, scope) {
|
226
|
-
return resolveRender(this.render, h, scope);
|
227
|
-
},
|
228
|
-
// 合并一个函数和一个对象(或两个函数)
|
229
|
-
mergeFunctionAndObject(t, s, scope) {
|
230
|
-
if (!s) {
|
231
|
-
if (isFunction(t)) return t(scope);
|
232
|
-
return t;
|
233
|
-
}
|
234
|
-
if (isFunction(t) && isFunction(s))
|
235
|
-
return Object.assign(s(scope), t(scope));
|
236
|
-
if (isFunction(t) && isPlainObject(s)) return Object.assign(s, t(scope));
|
237
|
-
if (isPlainObject(t) && isFunction(s)) return Object.assign(s(scope), t);
|
238
|
-
return t;
|
239
|
-
},
|
240
|
-
createMatcher(strategies) {
|
241
|
-
const exactMatches = new Map();
|
242
|
-
const suffixMatches = new Map();
|
243
|
-
const functionMatches = [];
|
244
|
-
strategies.forEach(({ rule, comp }) => {
|
245
|
-
if (typeof rule === "string") {
|
246
|
-
if (rule.startsWith("*")) {
|
247
|
-
suffixMatches.set(rule.slice(1).toLowerCase(), comp);
|
248
|
-
} else {
|
249
|
-
exactMatches.set(rule, comp);
|
250
|
-
}
|
251
|
-
} else if (typeof rule === "function") {
|
252
|
-
functionMatches.push({ rule, comp });
|
253
|
-
}
|
254
|
-
});
|
255
|
-
return (name, comp, scope) => {
|
256
|
-
if (typeof name === "string") {
|
257
|
-
// 精确匹配
|
258
|
-
const exactMatch = exactMatches.get(name);
|
259
|
-
if (exactMatch) return exactMatch;
|
260
|
-
|
261
|
-
// 后缀匹配
|
262
|
-
const nameLower = name.toLowerCase();
|
263
|
-
for (const [suffix, comp] of suffixMatches) {
|
264
|
-
if (nameLower.endsWith(suffix)) {
|
265
|
-
return comp;
|
266
|
-
}
|
267
|
-
}
|
268
|
-
}
|
269
|
-
// 函数匹配
|
270
|
-
if (isFunction(name)) {
|
271
|
-
return functionMatches.find(({ rule }) => rule(name, comp, scope))
|
272
|
-
?.comp;
|
273
|
-
}
|
274
|
-
};
|
275
|
-
},
|
276
|
-
getComponent(h, scope) {
|
277
|
-
if (this.comp || this.defaultComp) {
|
278
|
-
let comp = this.comp || this.defaultComp;
|
279
|
-
comp =
|
280
|
-
typeof comp === "string" || isComponent(comp)
|
281
|
-
? { name: comp }
|
282
|
-
: this.mergeFunctionAndObject(comp, this.raw?.comp, scope);
|
283
|
-
if (this.compStrategy) {
|
284
|
-
const strategy = this.matcher(
|
285
|
-
isComponent(comp.name) ? comp.name.name : comp.name,
|
286
|
-
comp,
|
287
|
-
scope
|
288
|
-
);
|
289
|
-
if (strategy || this.commonCompStrategy) {
|
290
|
-
comp = merge(comp, this.commonCompStrategy, strategy);
|
291
|
-
}
|
292
|
-
}
|
293
|
-
return (
|
294
|
-
<Comp
|
295
|
-
props={{ ...comp, comp }}
|
296
|
-
prop={this.prop}
|
297
|
-
size={this.size}
|
298
|
-
scope={scope}
|
299
|
-
/>
|
300
|
-
);
|
301
|
-
}
|
302
|
-
},
|
303
|
-
getDefaultRender(h, scope) {
|
304
|
-
if (this.$scopedSlots.default) {
|
305
|
-
return this.$scopedSlots.default(scope);
|
306
|
-
}
|
307
|
-
if (isFunction(this.defaultRender)) {
|
308
|
-
return this.defaultRender(h, scope);
|
309
|
-
}
|
310
|
-
if (this.controlDefault) {
|
311
|
-
const renderFunc = this.controlDefault(_defaultRender, scope);
|
312
|
-
const VNode = renderFunc && renderFunc(h, scope);
|
313
|
-
if (VNode) return VNode;
|
314
|
-
}
|
315
|
-
return _defaultRender.formatter(h, scope);
|
316
|
-
},
|
317
|
-
applyComponentSpecificModifications(vnode, scope) {
|
318
|
-
if (!vnode) return vnode;
|
319
|
-
|
320
|
-
// 从虚拟DOM中获取组件名称
|
321
|
-
let compName;
|
322
|
-
if (vnode.componentOptions && vnode.componentOptions.Ctor) {
|
323
|
-
compName =
|
324
|
-
vnode.componentOptions.Ctor.options.name ||
|
325
|
-
(vnode.componentOptions.tag || "").toLowerCase();
|
326
|
-
}
|
327
|
-
|
328
|
-
// 如果无法获取组件名称,则返回原始vnode
|
329
|
-
if (!compName) return vnode;
|
330
|
-
|
331
|
-
// 如果提供了组件特定的修改配置
|
332
|
-
if (this.strategies) {
|
333
|
-
const modifier = this.strategies[compName];
|
334
|
-
|
335
|
-
// 如果没有精确匹配,尝试后缀匹配
|
336
|
-
let matchedModifier = modifier;
|
337
|
-
if (!matchedModifier) {
|
338
|
-
const compNameLower = compName.toLowerCase();
|
339
|
-
// 查找所有以*开头的键,表示后缀匹配
|
340
|
-
for (const key in this.strategies) {
|
341
|
-
if (
|
342
|
-
key.startsWith("*") &&
|
343
|
-
compNameLower.endsWith(key.slice(1).toLowerCase())
|
344
|
-
) {
|
345
|
-
matchedModifier = this.strategies[key];
|
346
|
-
break;
|
347
|
-
}
|
348
|
-
}
|
349
|
-
}
|
350
|
-
|
351
|
-
if (typeof matchedModifier === "function") {
|
352
|
-
// 允许通过函数完全控制VNode的修改
|
353
|
-
return matchedModifier(vnode, scope, this);
|
354
|
-
} else if (matchedModifier && typeof matchedModifier === "object") {
|
355
|
-
// 应用预定义的修改
|
356
|
-
if (matchedModifier.props && vnode.componentOptions) {
|
357
|
-
vnode.componentOptions.propsData = {
|
358
|
-
...vnode.componentOptions.propsData,
|
359
|
-
...(typeof matchedModifier.props === "function"
|
360
|
-
? matchedModifier.props(scope)
|
361
|
-
: matchedModifier.props),
|
362
|
-
};
|
363
|
-
}
|
364
|
-
|
365
|
-
// 添加或修改事件
|
366
|
-
if (matchedModifier.on && vnode.componentOptions) {
|
367
|
-
vnode.componentOptions.listeners =
|
368
|
-
vnode.componentOptions.listeners || {};
|
369
|
-
Object.entries(matchedModifier.on).forEach(([event, handler]) => {
|
370
|
-
const originalHandler = vnode.componentOptions.listeners[event];
|
371
|
-
vnode.componentOptions.listeners[event] = originalHandler
|
372
|
-
? (...args) => {
|
373
|
-
originalHandler(...args);
|
374
|
-
handler(...args, scope, this);
|
375
|
-
}
|
376
|
-
: (...args) => handler(...args, scope, this);
|
377
|
-
});
|
378
|
-
}
|
379
|
-
|
380
|
-
// 添加或修改样式
|
381
|
-
if (matchedModifier.style && vnode.data) {
|
382
|
-
vnode.data.style = {
|
383
|
-
...(vnode.data.style || {}),
|
384
|
-
...(typeof matchedModifier.style === "function"
|
385
|
-
? matchedModifier.style(scope)
|
386
|
-
: matchedModifier.style),
|
387
|
-
};
|
388
|
-
}
|
389
|
-
|
390
|
-
// 添加或修改类名
|
391
|
-
if (matchedModifier.class && vnode.data) {
|
392
|
-
const newClass =
|
393
|
-
typeof matchedModifier.class === "function"
|
394
|
-
? matchedModifier.class(scope)
|
395
|
-
: matchedModifier.class;
|
396
|
-
|
397
|
-
if (Array.isArray(vnode.data.class)) {
|
398
|
-
vnode.data.class = [
|
399
|
-
...vnode.data.class,
|
400
|
-
...(Array.isArray(newClass) ? newClass : [newClass]),
|
401
|
-
];
|
402
|
-
} else if (typeof vnode.data.class === "object") {
|
403
|
-
vnode.data.class = { ...vnode.data.class, ...newClass };
|
404
|
-
} else {
|
405
|
-
vnode.data.class = newClass;
|
406
|
-
}
|
407
|
-
}
|
408
|
-
|
409
|
-
// 添加或修改属性
|
410
|
-
if (matchedModifier.attrs && vnode.data) {
|
411
|
-
vnode.data.attrs = {
|
412
|
-
...(vnode.data.attrs || {}),
|
413
|
-
...(typeof matchedModifier.attrs === "function"
|
414
|
-
? matchedModifier.attrs(scope)
|
415
|
-
: matchedModifier.attrs),
|
416
|
-
};
|
417
|
-
}
|
418
|
-
}
|
419
|
-
}
|
420
|
-
|
421
|
-
return vnode;
|
422
|
-
},
|
423
|
-
},
|
424
|
-
render(h) {
|
425
|
-
const chains = this.interruptibleCompose(
|
426
|
-
this.getSlot,
|
427
|
-
this.getRender,
|
428
|
-
this.getComponent,
|
429
|
-
this.getDefaultRender
|
430
|
-
);
|
431
|
-
const VNode = chains(h, {
|
432
|
-
...this.scope,
|
433
|
-
item: this.item,
|
434
|
-
mode: this.mode,
|
435
|
-
dict: this.dictData,
|
436
|
-
self: this,
|
437
|
-
$value: {
|
438
|
-
get: this.$value,
|
439
|
-
set: this.setFormatValue,
|
440
|
-
},
|
441
|
-
});
|
442
|
-
|
443
|
-
if (this.position) {
|
444
|
-
return (
|
445
|
-
<position
|
446
|
-
slotName={this.prop}
|
447
|
-
slots={this.slots}
|
448
|
-
scope={this.scope}
|
449
|
-
style={{
|
450
|
-
width: "100%",
|
451
|
-
}}
|
452
|
-
>
|
453
|
-
{VNode}
|
454
|
-
</position>
|
455
|
-
);
|
456
|
-
}
|
457
|
-
return VNode;
|
458
|
-
},
|
459
|
-
};
|
460
|
-
</script>
|