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,302 @@
|
|
1
|
+
import {
|
2
|
+
cloneDeep,
|
3
|
+
merge,
|
4
|
+
get,
|
5
|
+
set,
|
6
|
+
isPlainObject,
|
7
|
+
isFunction,
|
8
|
+
} from "lodash-es";
|
9
|
+
import { mergeTemp, getObjectType } from "utils";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* 配置管理器
|
13
|
+
*/
|
14
|
+
class ConfigManager {
|
15
|
+
constructor(defaultConfigs = {}, globalConfigs = {}, options = {}) {
|
16
|
+
this.excludeKeys = options.excludeKeys || [];
|
17
|
+
this.defaultConfigs = defaultConfigs;
|
18
|
+
this.globalConfigs = globalConfigs;
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* 获取预设配置
|
22
|
+
*/
|
23
|
+
getPresetConfig(userConfig) {
|
24
|
+
const presetName = userConfig.presetType;
|
25
|
+
return presetName
|
26
|
+
? mergeTemp("options", presetName, userConfig)
|
27
|
+
: userConfig;
|
28
|
+
}
|
29
|
+
|
30
|
+
getDefaultConfig(key) {
|
31
|
+
return cloneDeep(this.defaultConfigs[key]) || {};
|
32
|
+
}
|
33
|
+
|
34
|
+
getGlobalConfig(key) {
|
35
|
+
return (
|
36
|
+
cloneDeep({
|
37
|
+
size: this.globalConfigs.size,
|
38
|
+
checkPermission:
|
39
|
+
this.globalConfigs.checkPermission ||
|
40
|
+
(() => {
|
41
|
+
return true;
|
42
|
+
}),
|
43
|
+
...this.globalConfigs[key],
|
44
|
+
}) || {}
|
45
|
+
);
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* 转换配置对象
|
50
|
+
*/
|
51
|
+
transformConfig(config, transforms) {
|
52
|
+
const result = cloneDeep(config);
|
53
|
+
if (this.excludeKeys.length > 0) {
|
54
|
+
this.excludeKeys.forEach((key) => {
|
55
|
+
delete result[key];
|
56
|
+
});
|
57
|
+
}
|
58
|
+
if (!transforms) return result;
|
59
|
+
const handleTransform = (source, key) => {
|
60
|
+
for (const transform of transforms) {
|
61
|
+
transform(source, key, source[key]);
|
62
|
+
}
|
63
|
+
// 如果值是对象,递归处理
|
64
|
+
const value = source[key];
|
65
|
+
if (isPlainObject(value)) {
|
66
|
+
Object.keys(value).forEach((key) => {
|
67
|
+
handleTransform(value, key, value[key]);
|
68
|
+
});
|
69
|
+
}
|
70
|
+
};
|
71
|
+
|
72
|
+
// 处理每个顶级属性
|
73
|
+
Object.keys(result).forEach((key) => {
|
74
|
+
handleTransform(result, key);
|
75
|
+
});
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* 合并配置
|
80
|
+
*/
|
81
|
+
mergeConfig(userConfig = {}, options = {}) {
|
82
|
+
const { type = "", config = {} } = options;
|
83
|
+
|
84
|
+
const defaultConfig = this.getDefaultConfig(type) || config;
|
85
|
+
const globalConfig = this.getGlobalConfig(type) || {};
|
86
|
+
|
87
|
+
userConfig = this.getPresetConfig(userConfig);
|
88
|
+
|
89
|
+
const transformConfig = this.transformConfig(
|
90
|
+
merge({}, globalConfig, userConfig),
|
91
|
+
defaultConfig.transforms
|
92
|
+
);
|
93
|
+
const resultConfig = this.applyDefaults(
|
94
|
+
transformConfig,
|
95
|
+
defaultConfig.schema
|
96
|
+
);
|
97
|
+
// 验证配置
|
98
|
+
this.validateConfig(resultConfig, {
|
99
|
+
schema: defaultConfig.schema,
|
100
|
+
strict: defaultConfig.strict,
|
101
|
+
ignoreKeys: defaultConfig.ignoreKeys,
|
102
|
+
type,
|
103
|
+
});
|
104
|
+
|
105
|
+
return resultConfig;
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* 验证配置
|
110
|
+
*/
|
111
|
+
validateConfig(config, options = {}) {
|
112
|
+
const { schema, strict, ignoreKeys, type } = options;
|
113
|
+
// 对schema对象进行严格校验
|
114
|
+
if (strict) {
|
115
|
+
const extraKeys = Object.keys(config).filter(
|
116
|
+
(key) => !schema[key] && !(ignoreKeys || []).includes(key)
|
117
|
+
);
|
118
|
+
if (extraKeys.length > 0) {
|
119
|
+
console.warn(
|
120
|
+
`配置对象 ${type} 包含不存在的属性: ${extraKeys.join(", ")}`
|
121
|
+
);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
const validate = (config, schema, path = "") => {
|
125
|
+
for (const [key, definition] of Object.entries(schema)) {
|
126
|
+
const value = get(config, key);
|
127
|
+
const fullPath = path ? `${path}.${key}` : key;
|
128
|
+
let def = definition;
|
129
|
+
if (!isPlainObject(def)) {
|
130
|
+
def = {
|
131
|
+
type: def,
|
132
|
+
};
|
133
|
+
}
|
134
|
+
if (value === undefined || value === null) {
|
135
|
+
if (def.required) console.warn(`缺少必填配置项: "${fullPath}"`);
|
136
|
+
} else {
|
137
|
+
// 类型检查
|
138
|
+
if (def.type) {
|
139
|
+
const types = Array.isArray(def.type) ? def.type : [def.type];
|
140
|
+
|
141
|
+
const valid = types.some((type) => {
|
142
|
+
if (type === Boolean) return typeof value === "boolean";
|
143
|
+
if (type === Function) return typeof value === "function";
|
144
|
+
if (type === Object) return isPlainObject(value);
|
145
|
+
if (type === Array) return Array.isArray(value);
|
146
|
+
if (type === String) return typeof value === "string";
|
147
|
+
if (type === Number) return typeof value === "number";
|
148
|
+
if (type === Promise) return value instanceof Promise;
|
149
|
+
if (type === RegExp) return value instanceof RegExp;
|
150
|
+
if (type === Date) return value instanceof Date;
|
151
|
+
return false;
|
152
|
+
});
|
153
|
+
|
154
|
+
if (!valid) {
|
155
|
+
console.warn(
|
156
|
+
`配置项 "${fullPath.replace(
|
157
|
+
/\.arrayOf/g,
|
158
|
+
""
|
159
|
+
)}" 类型错误: 期望类型为 ${types
|
160
|
+
.map((t) => t.name)
|
161
|
+
.join("|")}, 实际类型为 ${getObjectType(
|
162
|
+
value
|
163
|
+
)}, 值为 ${value}`
|
164
|
+
);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
// 数组类型校验
|
169
|
+
if (def.arrayOf && Array.isArray(value)) {
|
170
|
+
value.forEach((item, index) => {
|
171
|
+
const itemPath = `${fullPath}[${index}]`;
|
172
|
+
|
173
|
+
if (isPlainObject(def.arrayOf)) {
|
174
|
+
validate({ arrayOf: item }, { arrayOf: def.arrayOf }, itemPath);
|
175
|
+
}
|
176
|
+
|
177
|
+
if (isFunction(def.arrayOf.validate)) {
|
178
|
+
try {
|
179
|
+
def.arrayOf.validate(item);
|
180
|
+
} catch (error) {
|
181
|
+
console.warn(
|
182
|
+
`数组项 "${itemPath}" 验证失败: ${error.message}, 值为 ${value}`
|
183
|
+
);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
});
|
187
|
+
}
|
188
|
+
|
189
|
+
// 枚举值校验
|
190
|
+
if (
|
191
|
+
def.enum &&
|
192
|
+
typeof value === "string" &&
|
193
|
+
!def.enum.includes(value)
|
194
|
+
) {
|
195
|
+
console.warn(
|
196
|
+
`配置项 "${fullPath}" 的值无效: 必须是 ${def.enum.join(
|
197
|
+
", "
|
198
|
+
)}, 当前值为 ${value}`
|
199
|
+
);
|
200
|
+
}
|
201
|
+
|
202
|
+
// 自定义验证
|
203
|
+
if (def.validator && !def.validator(value)) {
|
204
|
+
console.warn(`配置项 "${fullPath}" 验证失败, 值为 ${value}`);
|
205
|
+
}
|
206
|
+
|
207
|
+
// 嵌套对象验证
|
208
|
+
if (def.properties && isPlainObject(value)) {
|
209
|
+
// 对象严格校验
|
210
|
+
if (def.strict) {
|
211
|
+
const extraKeys = Object.keys(value).filter(
|
212
|
+
(k) => !def.properties[k] && !(def.ignoreKeys || []).includes(k)
|
213
|
+
);
|
214
|
+
if (extraKeys.length > 0) {
|
215
|
+
console.warn(
|
216
|
+
`配置项 "${fullPath}" 包含不存在的属性: ${extraKeys.join(
|
217
|
+
", "
|
218
|
+
)}}`
|
219
|
+
);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
validate(value, def.properties, fullPath);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
};
|
227
|
+
validate(config, schema);
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* 应用默认值
|
232
|
+
*/
|
233
|
+
applyDefaults(config, schema) {
|
234
|
+
const result = cloneDeep(config);
|
235
|
+
|
236
|
+
const applyDefaultsRecursive = (config, schema, basePath = "") => {
|
237
|
+
for (const [key, definition] of Object.entries(schema)) {
|
238
|
+
const fullPath = basePath ? `${basePath}.${key}` : key;
|
239
|
+
const value = get(config, key);
|
240
|
+
|
241
|
+
let def = definition;
|
242
|
+
if (!isPlainObject(def)) {
|
243
|
+
def = {
|
244
|
+
type: def,
|
245
|
+
};
|
246
|
+
}
|
247
|
+
|
248
|
+
if (def.default) {
|
249
|
+
if (value === undefined) {
|
250
|
+
const defaultValue = isFunction(definition.default)
|
251
|
+
? definition.default()
|
252
|
+
: definition.default;
|
253
|
+
defaultValue && set(result, fullPath, defaultValue);
|
254
|
+
} else if (isPlainObject(value)) {
|
255
|
+
// 值为对象类型与默认值合并
|
256
|
+
const defaultValue = isFunction(definition.default)
|
257
|
+
? definition.default()
|
258
|
+
: definition.default;
|
259
|
+
if (isPlainObject(defaultValue)) {
|
260
|
+
defaultValue &&
|
261
|
+
set(result, fullPath, merge({}, defaultValue, value));
|
262
|
+
}
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
// 空字符串转换为 true
|
267
|
+
if (def.type) {
|
268
|
+
const types = Array.isArray(def.type) ? def.type : [def.type];
|
269
|
+
if (types.includes(Boolean) && value === "") {
|
270
|
+
set(result, fullPath, true);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
// 处理嵌套对象的属性
|
275
|
+
if (def.properties) {
|
276
|
+
const currentValue = get(result, fullPath) || {};
|
277
|
+
if (isPlainObject(currentValue)) {
|
278
|
+
applyDefaultsRecursive(currentValue, def.properties, fullPath);
|
279
|
+
}
|
280
|
+
}
|
281
|
+
}
|
282
|
+
};
|
283
|
+
|
284
|
+
applyDefaultsRecursive(config, schema);
|
285
|
+
return result;
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
let instance = null;
|
290
|
+
|
291
|
+
export default {
|
292
|
+
create: (conf, gloConf) => {
|
293
|
+
if (!instance) {
|
294
|
+
instance = new ConfigManager(conf, gloConf);
|
295
|
+
return instance;
|
296
|
+
}
|
297
|
+
return instance;
|
298
|
+
},
|
299
|
+
getInstance: () => instance,
|
300
|
+
};
|
301
|
+
|
302
|
+
export { ConfigManager };
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import tooltip from "../tooltip";
|
2
|
+
export default {
|
3
|
+
input: (h, { item, $value }) => {
|
4
|
+
return h("el-input", {
|
5
|
+
class: "sc-default-input",
|
6
|
+
props: {
|
7
|
+
value: $value.get,
|
8
|
+
clearable: true,
|
9
|
+
},
|
10
|
+
attrs: {
|
11
|
+
placeholder: `请输入${item.label}`,
|
12
|
+
},
|
13
|
+
on: {
|
14
|
+
input: (v) => {
|
15
|
+
$value.set(v);
|
16
|
+
},
|
17
|
+
},
|
18
|
+
});
|
19
|
+
},
|
20
|
+
formatter: (h, { row, column, $index, item, $value }) => {
|
21
|
+
let value = item.formatter
|
22
|
+
? typeof item.formatter === "function"
|
23
|
+
? item.formatter(row, column, $value.get, $index)
|
24
|
+
: item.formatter
|
25
|
+
: $value.get;
|
26
|
+
let vm;
|
27
|
+
const tooltipEvents = {
|
28
|
+
mouseenter: (e) => {
|
29
|
+
vm = tooltip({
|
30
|
+
content: value + "",
|
31
|
+
placement: "top",
|
32
|
+
target: e.target,
|
33
|
+
overflow: true,
|
34
|
+
});
|
35
|
+
vm.show();
|
36
|
+
},
|
37
|
+
mouseleave: (e) => {
|
38
|
+
vm && vm.hide();
|
39
|
+
},
|
40
|
+
};
|
41
|
+
if (item.suffix && value) value = value + " " + item.suffix;
|
42
|
+
if (item.html) {
|
43
|
+
return h("div", {
|
44
|
+
class: "sc-default-formatter",
|
45
|
+
domProps: {
|
46
|
+
innerHTML: value,
|
47
|
+
},
|
48
|
+
style: {
|
49
|
+
display: "inline",
|
50
|
+
},
|
51
|
+
on: tooltipEvents,
|
52
|
+
});
|
53
|
+
}
|
54
|
+
|
55
|
+
return h(
|
56
|
+
"div",
|
57
|
+
{
|
58
|
+
class: "sc-default-formatter",
|
59
|
+
on: tooltipEvents,
|
60
|
+
},
|
61
|
+
value
|
62
|
+
);
|
63
|
+
},
|
64
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { DictManager } from "./index";
|
2
|
+
import resolveTemp from "src/template";
|
3
|
+
import { get } from "lodash-es";
|
4
|
+
|
5
|
+
export default function (Vue, globalOpt) {
|
6
|
+
const dictManager = new DictManager(Vue, globalOpt);
|
7
|
+
const dicts = get(resolveTemp, "dicts");
|
8
|
+
if (dicts) dictManager.registerBatch(dicts);
|
9
|
+
return dictManager;
|
10
|
+
}
|