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,111 @@
|
|
1
|
+
import { batchMerge, mergeTemp } from "utils/mergeTemp";
|
2
|
+
import { executeFunctionByObject } from "utils";
|
3
|
+
|
4
|
+
export function generateRules(item, scope) {
|
5
|
+
// 获取经过scope处理后的配置
|
6
|
+
const config = executeFunctionByObject(
|
7
|
+
{
|
8
|
+
required: item.required,
|
9
|
+
regular: item.regular,
|
10
|
+
limit: item.limit,
|
11
|
+
rules: item.rules,
|
12
|
+
},
|
13
|
+
scope
|
14
|
+
);
|
15
|
+
|
16
|
+
const rules = [];
|
17
|
+
const rawRules = [];
|
18
|
+
|
19
|
+
// 处理必填规则
|
20
|
+
if (config.required) {
|
21
|
+
const requiredRule = generateRequiredRule(config.required, item);
|
22
|
+
rules.push(requiredRule);
|
23
|
+
rules.required = true;
|
24
|
+
}
|
25
|
+
|
26
|
+
// 处理长度限制规则
|
27
|
+
if (config.limit) {
|
28
|
+
rules.push(generateLimitRule(config.limit));
|
29
|
+
}
|
30
|
+
|
31
|
+
// 处理正则校验规则
|
32
|
+
if (config.regular) {
|
33
|
+
const regularRules = generateRegularRules(
|
34
|
+
config.regular,
|
35
|
+
item,
|
36
|
+
scope,
|
37
|
+
rawRules
|
38
|
+
);
|
39
|
+
rules.push(...regularRules);
|
40
|
+
}
|
41
|
+
|
42
|
+
// 处理自定义规则
|
43
|
+
if (config.rules) {
|
44
|
+
const customRules = generateCustomRules(
|
45
|
+
config.rules,
|
46
|
+
item,
|
47
|
+
scope,
|
48
|
+
rawRules
|
49
|
+
);
|
50
|
+
rules.push(...customRules);
|
51
|
+
}
|
52
|
+
|
53
|
+
return {
|
54
|
+
rules,
|
55
|
+
rawRules,
|
56
|
+
};
|
57
|
+
}
|
58
|
+
function generateRequiredRule(required, item) {
|
59
|
+
return mergeTemp("rules", "required", required, { item });
|
60
|
+
}
|
61
|
+
|
62
|
+
function generateLimitRule([min, max]) {
|
63
|
+
return {
|
64
|
+
min,
|
65
|
+
max,
|
66
|
+
message:
|
67
|
+
min === max ? `请输入 ${min} 个字符` : `请输入 ${min} 到 ${max} 个字符`,
|
68
|
+
trigger: "change",
|
69
|
+
};
|
70
|
+
}
|
71
|
+
|
72
|
+
function generateRegularRules(regular, item, scope, rawRules) {
|
73
|
+
const rules = batchMerge("rules", regular, { item });
|
74
|
+
rawRules.push(...rules);
|
75
|
+
return handleRegularRule(rules, scope);
|
76
|
+
}
|
77
|
+
|
78
|
+
function generateCustomRules(rules, item, scope, rawRules) {
|
79
|
+
const customRules = batchMerge("rules", rules, { item });
|
80
|
+
rawRules.push(...customRules);
|
81
|
+
return handleRegularRule(customRules, scope);
|
82
|
+
}
|
83
|
+
|
84
|
+
function handleRegularRule(rules, scope) {
|
85
|
+
return rules.map((item) => {
|
86
|
+
if (item.regular && item.msg) {
|
87
|
+
return {
|
88
|
+
validator: (rule, value, callback) => {
|
89
|
+
if (!value || item.regular.test(value)) {
|
90
|
+
callback();
|
91
|
+
} else {
|
92
|
+
callback(new Error(item.msg));
|
93
|
+
}
|
94
|
+
},
|
95
|
+
trigger: item.trigger || "change",
|
96
|
+
message: item.msg,
|
97
|
+
};
|
98
|
+
} else {
|
99
|
+
if (item.validator) {
|
100
|
+
const validator = item.validator;
|
101
|
+
return {
|
102
|
+
...item,
|
103
|
+
validator: (...args) => {
|
104
|
+
validator(...args.slice(0, 3), scope);
|
105
|
+
},
|
106
|
+
};
|
107
|
+
}
|
108
|
+
return item;
|
109
|
+
}
|
110
|
+
});
|
111
|
+
}
|
@@ -0,0 +1,205 @@
|
|
1
|
+
<script>
|
2
|
+
import create from "core/create";
|
3
|
+
import calcColumnWidth from "./mixins/calcColumnWidth";
|
4
|
+
import columnCell from "./columnCell.vue";
|
5
|
+
import column from "./column.vue";
|
6
|
+
import searchHeader from "./searchHeader.vue";
|
7
|
+
import position from "core/components/position";
|
8
|
+
import { set, merge, isFunction } from "lodash-es";
|
9
|
+
import { checkVisibility } from "utils";
|
10
|
+
// 调试时element-ui导入地址需要改成引入项目下的node_modules地址
|
11
|
+
import { TableColumn } from "element-ui";
|
12
|
+
// import { TableColumn } from "C:/Users/Administrator/Desktop/jhfCloud2/ruoyi-ui/lib";
|
13
|
+
|
14
|
+
TableColumn.destroyed = function () {
|
15
|
+
if (!this.$parent) return;
|
16
|
+
let parent = this.$parent;
|
17
|
+
if (parent.$options.name === "sc-crud-column") {
|
18
|
+
// 解决children动态变化时el-table的columns被错误删除的问题,因为给el-table-column多套了一层,导致饿了么内部parent取错,所以这里需要再往上取一层
|
19
|
+
parent = parent.$parent;
|
20
|
+
}
|
21
|
+
this.owner.store.commit(
|
22
|
+
"removeColumn",
|
23
|
+
this.columnConfig,
|
24
|
+
this.isSubColumn ? parent.columnConfig : null
|
25
|
+
);
|
26
|
+
};
|
27
|
+
|
28
|
+
export default create({
|
29
|
+
name: "crud-column",
|
30
|
+
props: {
|
31
|
+
col: Object,
|
32
|
+
},
|
33
|
+
inject: ["ctx"],
|
34
|
+
mixins: [calcColumnWidth],
|
35
|
+
data() {
|
36
|
+
return {
|
37
|
+
isSearch: false,
|
38
|
+
};
|
39
|
+
},
|
40
|
+
components: { TableColumn, columnCell, column, searchHeader, position },
|
41
|
+
watch: {
|
42
|
+
col() {
|
43
|
+
this.bindColumnConfig();
|
44
|
+
},
|
45
|
+
},
|
46
|
+
computed: {
|
47
|
+
defaultMinWidth() {
|
48
|
+
// 计算头部默认宽度
|
49
|
+
const labelSpan = document.createElement("span");
|
50
|
+
labelSpan.innerText = this.col.label;
|
51
|
+
document.body.appendChild(labelSpan);
|
52
|
+
let labelMinWidth = labelSpan.getBoundingClientRect().width + 20;
|
53
|
+
this.col.search && (labelMinWidth += 20);
|
54
|
+
this.col.sortable && (labelMinWidth += 25);
|
55
|
+
document.body.removeChild(labelSpan);
|
56
|
+
labelMinWidth = Math.round(labelMinWidth);
|
57
|
+
return Math.max(labelMinWidth, 80);
|
58
|
+
},
|
59
|
+
showOverflowTooltip() {
|
60
|
+
const col = this.col;
|
61
|
+
if (col.showOverflowTooltip !== undefined) return col.showOverflowTooltip;
|
62
|
+
return this.ctx.isDefaultColumn(col);
|
63
|
+
},
|
64
|
+
calcOpts() {
|
65
|
+
return { ...this.ctx.crudOptions.calcColumnWidth, ...this.col };
|
66
|
+
},
|
67
|
+
colWidth() {
|
68
|
+
return this.getColumnWidth(
|
69
|
+
this.col.width,
|
70
|
+
this.col.prop,
|
71
|
+
this.ctx.data,
|
72
|
+
this.calcOpts.widthType,
|
73
|
+
this.calcOpts.widthFont,
|
74
|
+
this.calcOpts.calcWidth
|
75
|
+
);
|
76
|
+
},
|
77
|
+
colMinWidth() {
|
78
|
+
if (!this.col.width) {
|
79
|
+
return this.defaultMinWidth;
|
80
|
+
}
|
81
|
+
return this.getColumnWidth(
|
82
|
+
this.col.minWidth,
|
83
|
+
this.col.prop,
|
84
|
+
this.ctx.data,
|
85
|
+
this.calcOpts.widthType,
|
86
|
+
this.calcOpts.widthFont,
|
87
|
+
this.calcOpts.calcWidth
|
88
|
+
);
|
89
|
+
},
|
90
|
+
isShow() {
|
91
|
+
// hiddenList 只隐藏列表
|
92
|
+
if (this.col.hiddenList) return false;
|
93
|
+
return !this.hidden;
|
94
|
+
},
|
95
|
+
hidden() {
|
96
|
+
if (this.ctx.setOptions.hidden.includes(this.col.prop)) return true;
|
97
|
+
},
|
98
|
+
fixed() {
|
99
|
+
if (this.col.fixed) return this.col.fixed;
|
100
|
+
const fixed = this.ctx.setOptions.fixed[this.col.prop];
|
101
|
+
if (fixed) return fixed;
|
102
|
+
},
|
103
|
+
showSearchHeader() {
|
104
|
+
if (this.col.search?.hidden) return false;
|
105
|
+
if (this.col.searchHeader?.hidden) return false;
|
106
|
+
const show = checkVisibility(this.ctx.crudOptions.searchHeader);
|
107
|
+
return (this.col.search && show) || (this.col.searchHeader && show);
|
108
|
+
},
|
109
|
+
},
|
110
|
+
methods: {
|
111
|
+
bindColumnConfig() {
|
112
|
+
const columnConfig = this.$refs.column?.columnConfig;
|
113
|
+
if (columnConfig) {
|
114
|
+
columnConfig.col = { ...this.col };
|
115
|
+
columnConfig.options = { ...this.ctx.crudOptions };
|
116
|
+
}
|
117
|
+
},
|
118
|
+
getTopProps() {
|
119
|
+
return {
|
120
|
+
size: this.ctx.crudOptions.size,
|
121
|
+
isTree: this.ctx.isTree,
|
122
|
+
valueKey: this.ctx.valueKey,
|
123
|
+
extendsScopedSlots: this.ctx.extendsScopedSlots,
|
124
|
+
defaultRender: this.ctx.crudOptions.defaultRender,
|
125
|
+
};
|
126
|
+
},
|
127
|
+
},
|
128
|
+
render(h) {
|
129
|
+
const {
|
130
|
+
col,
|
131
|
+
ctx,
|
132
|
+
showSearchHeader,
|
133
|
+
showOverflowTooltip,
|
134
|
+
isShow,
|
135
|
+
fixed,
|
136
|
+
} = this;
|
137
|
+
const isDefaultColumn = this.ctx.isDefaultColumn(col);
|
138
|
+
if (!isShow) return null;
|
139
|
+
const topProps = this.getTopProps();
|
140
|
+
const cellRender = (scope) => {
|
141
|
+
return (
|
142
|
+
<columnCell col={col} scope={scope} ctx={ctx} topProps={topProps} />
|
143
|
+
);
|
144
|
+
};
|
145
|
+
const columnHeader = () => {
|
146
|
+
return (
|
147
|
+
<div
|
148
|
+
class={this.b(["header"])}
|
149
|
+
style={{ color: this.isSearch ? "var(--color-primary)" : "" }}
|
150
|
+
>
|
151
|
+
<position
|
152
|
+
slotName={`${col.prop}-header`}
|
153
|
+
render={col.labelRender || col.headerRender}
|
154
|
+
slots={ctx.$scopedSlots}
|
155
|
+
>
|
156
|
+
<span
|
157
|
+
style="white-space: nowrap;" // 解决动态列因为换行导致el-table中updateElsHeight重新计算有误
|
158
|
+
domProps={{
|
159
|
+
innerHTML: col.label,
|
160
|
+
}}
|
161
|
+
></span>
|
162
|
+
</position>
|
163
|
+
{showSearchHeader && (
|
164
|
+
<searchHeader
|
165
|
+
on={{
|
166
|
+
"update:isSearch": (val) => {
|
167
|
+
this.isSearch = val;
|
168
|
+
},
|
169
|
+
}}
|
170
|
+
item={col.searchHeader}
|
171
|
+
/>
|
172
|
+
)}
|
173
|
+
</div>
|
174
|
+
);
|
175
|
+
};
|
176
|
+
return (
|
177
|
+
<TableColumn
|
178
|
+
ref="column"
|
179
|
+
props={col}
|
180
|
+
prop={col.prop}
|
181
|
+
fixed={fixed}
|
182
|
+
header-align={col.headerAlign || col.align || "center"}
|
183
|
+
align={col.align || "center"}
|
184
|
+
width={col.width}
|
185
|
+
min-width={col.minWidth}
|
186
|
+
show-overflow-tooltip={showOverflowTooltip}
|
187
|
+
scopedSlots={{
|
188
|
+
default: !isDefaultColumn ? (scope) => cellRender(scope) : null,
|
189
|
+
header: columnHeader,
|
190
|
+
}}
|
191
|
+
on={{
|
192
|
+
"hook:mounted": () => {
|
193
|
+
this.bindColumnConfig();
|
194
|
+
},
|
195
|
+
}}
|
196
|
+
>
|
197
|
+
{col.children &&
|
198
|
+
col.children.map((sub) => {
|
199
|
+
return <column key={sub.label + sub.prop} col={sub}></column>;
|
200
|
+
})}
|
201
|
+
</TableColumn>
|
202
|
+
);
|
203
|
+
},
|
204
|
+
});
|
205
|
+
</script>
|
@@ -0,0 +1,207 @@
|
|
1
|
+
<template>
|
2
|
+
<!-- 操作栏 -->
|
3
|
+
<el-table-column
|
4
|
+
ref="column"
|
5
|
+
v-if="showAction"
|
6
|
+
v-bind="action"
|
7
|
+
:width="width"
|
8
|
+
:fixed="fixed"
|
9
|
+
@hook:mounted="bindColumnConfig"
|
10
|
+
>
|
11
|
+
<template v-slot="scope">
|
12
|
+
<div :class="b()" ref="actionRef">
|
13
|
+
<button_
|
14
|
+
v-for="(btn, index) in handleActionButtons(scope, actionButtons)"
|
15
|
+
:type="btn.type || 'text'"
|
16
|
+
:size="ctx.crudOptions.size"
|
17
|
+
:scope="scope"
|
18
|
+
v-bind="btn"
|
19
|
+
:key="index"
|
20
|
+
/>
|
21
|
+
</div>
|
22
|
+
</template>
|
23
|
+
</el-table-column>
|
24
|
+
</template>
|
25
|
+
|
26
|
+
<script>
|
27
|
+
import create from "core/create";
|
28
|
+
import { batchMerge } from "utils/mergeTemp";
|
29
|
+
import { checkVisibility } from "utils";
|
30
|
+
import button_ from "pak/button";
|
31
|
+
import { cloneDeep, debounce } from "lodash-es";
|
32
|
+
|
33
|
+
export default create({
|
34
|
+
name: "crud-action-column",
|
35
|
+
components: {
|
36
|
+
button_,
|
37
|
+
},
|
38
|
+
inject: ["ctx"],
|
39
|
+
data() {
|
40
|
+
return {
|
41
|
+
buttonList: [],
|
42
|
+
actionWidth: "",
|
43
|
+
};
|
44
|
+
},
|
45
|
+
created() {
|
46
|
+
const calcAutoWidth = this.calcAutoWidth;
|
47
|
+
this.calcAutoWidth = debounce(calcAutoWidth, 0);
|
48
|
+
},
|
49
|
+
watch: {
|
50
|
+
action() {
|
51
|
+
this.bindColumnConfig();
|
52
|
+
},
|
53
|
+
},
|
54
|
+
computed: {
|
55
|
+
width() {
|
56
|
+
if (this.action.width === "auto")
|
57
|
+
return Math.max(this.actionWidth, this.action.defaultWidth);
|
58
|
+
if (this.action.width) return this.action.width;
|
59
|
+
return this.action.defaultWidth;
|
60
|
+
},
|
61
|
+
fixed() {
|
62
|
+
if (this.action.fixed) return this.action.fixed;
|
63
|
+
return this.ctx.setOptions.fixed[this.action.prop];
|
64
|
+
},
|
65
|
+
action() {
|
66
|
+
const editConfig = this.ctx.editConfig;
|
67
|
+
return {
|
68
|
+
type: "action",
|
69
|
+
delete: editConfig.delete,
|
70
|
+
view: editConfig.view,
|
71
|
+
edit: editConfig.edit,
|
72
|
+
rowEdit: editConfig.rowEdit,
|
73
|
+
rowSave: editConfig.rowEdit,
|
74
|
+
rowCancel: editConfig.rowEdit,
|
75
|
+
...cloneDeep(this.ctx.crudOptions.action),
|
76
|
+
};
|
77
|
+
},
|
78
|
+
showAction() {
|
79
|
+
if (this.ctx.setOptions.hidden.includes(this.action.prop)) return false;
|
80
|
+
return checkVisibility(this.action, null, this.actionButtons.length > 0);
|
81
|
+
},
|
82
|
+
actionButtons() {
|
83
|
+
let buttons = [];
|
84
|
+
const merges = batchMerge(
|
85
|
+
"btn.crud.action",
|
86
|
+
this.action,
|
87
|
+
{
|
88
|
+
ctx: this.ctx,
|
89
|
+
},
|
90
|
+
this.actionTemps
|
91
|
+
);
|
92
|
+
buttons.push(...merges);
|
93
|
+
return buttons;
|
94
|
+
},
|
95
|
+
actionTemps() {
|
96
|
+
return {
|
97
|
+
rowEdit: (item, { ctx }) => ({
|
98
|
+
icon: "el-icon-edit",
|
99
|
+
label: "编辑",
|
100
|
+
order: 9,
|
101
|
+
disabled: (scope) => {
|
102
|
+
return this.ctx.disabledRowEdit({
|
103
|
+
row: scope.row,
|
104
|
+
$index: scope.$index,
|
105
|
+
});
|
106
|
+
},
|
107
|
+
innerHide: (scope) => this.isRowEditing(scope),
|
108
|
+
onClick: (scope) => {
|
109
|
+
this.ctx.handleRowEdit(scope);
|
110
|
+
},
|
111
|
+
}),
|
112
|
+
rowSave: (item, { ctx }) => ({
|
113
|
+
icon: "el-icon-circle-check",
|
114
|
+
label: "保存",
|
115
|
+
order: 10,
|
116
|
+
innerHide: (scope) => !this.isRowEditing(scope),
|
117
|
+
onClick: (scope) => {
|
118
|
+
this.ctx.handleRowSave(scope);
|
119
|
+
},
|
120
|
+
}),
|
121
|
+
rowCancel: (item, { ctx }) => ({
|
122
|
+
icon: "el-icon-circle-close",
|
123
|
+
label: "取消",
|
124
|
+
order: 11,
|
125
|
+
innerHide: (scope) => !this.isRowEditing(scope),
|
126
|
+
onClick: (scope) => {
|
127
|
+
this.ctx.handleRowCancel(scope);
|
128
|
+
},
|
129
|
+
}),
|
130
|
+
view: (item, { ctx }) => ({
|
131
|
+
icon: "el-icon-view",
|
132
|
+
label: "查看",
|
133
|
+
order: 8,
|
134
|
+
onClick: (scope) => {
|
135
|
+
this.ctx.handleView(scope);
|
136
|
+
},
|
137
|
+
}),
|
138
|
+
edit: (item, { ctx }) => ({
|
139
|
+
icon: "el-icon-edit",
|
140
|
+
label: "编辑",
|
141
|
+
order: 9,
|
142
|
+
onClick: (scope) => {
|
143
|
+
this.ctx.handleEdit(scope);
|
144
|
+
},
|
145
|
+
}),
|
146
|
+
delete: (item, { ctx }) => ({
|
147
|
+
icon: "el-icon-delete",
|
148
|
+
label: "删除",
|
149
|
+
order: 12,
|
150
|
+
innerHide: (scope) =>
|
151
|
+
this.ctx.editConfig.mode === "row" && this.isRowEditing(scope),
|
152
|
+
onClick: (scope) => {
|
153
|
+
this.ctx.handleDelete(scope);
|
154
|
+
},
|
155
|
+
}),
|
156
|
+
};
|
157
|
+
},
|
158
|
+
},
|
159
|
+
methods: {
|
160
|
+
bindColumnConfig() {
|
161
|
+
const columnConfig = this.$refs.column?.columnConfig;
|
162
|
+
if (columnConfig) {
|
163
|
+
columnConfig.col = { ...this.action };
|
164
|
+
columnConfig.options = { ...this.ctx.crudOptions };
|
165
|
+
}
|
166
|
+
},
|
167
|
+
isRowEditing(scope) {
|
168
|
+
return this.ctx.editState.isRowEditing(scope.row);
|
169
|
+
},
|
170
|
+
handleActionButtons(scope, actionButtons) {
|
171
|
+
let buttons = actionButtons;
|
172
|
+
|
173
|
+
buttons = buttons.filter((btn) => {
|
174
|
+
if (btn.innerHide && btn.innerHide(scope)) {
|
175
|
+
return false;
|
176
|
+
}
|
177
|
+
return true;
|
178
|
+
});
|
179
|
+
|
180
|
+
this.ctx.buttonList[scope.$index] = this.buttonList[
|
181
|
+
scope.$index
|
182
|
+
] = buttons;
|
183
|
+
|
184
|
+
this.$nextTick(() => {
|
185
|
+
this.calcAutoWidth();
|
186
|
+
});
|
187
|
+
return buttons;
|
188
|
+
},
|
189
|
+
calcAutoWidth() {
|
190
|
+
if (this.action.width === "auto") {
|
191
|
+
let width = this.actionWidth;
|
192
|
+
let list = document.querySelectorAll(".sc-crud-action-column");
|
193
|
+
list.forEach((ele) => {
|
194
|
+
let childList = ele.children;
|
195
|
+
let allWidth = 0;
|
196
|
+
for (let i = 0; i < childList.length; i++) {
|
197
|
+
const child = childList[i];
|
198
|
+
allWidth += child.offsetWidth + this.action.calcWidth;
|
199
|
+
}
|
200
|
+
if (allWidth >= width) width = allWidth;
|
201
|
+
});
|
202
|
+
this.actionWidth = width;
|
203
|
+
}
|
204
|
+
},
|
205
|
+
},
|
206
|
+
});
|
207
|
+
</script>
|
@@ -0,0 +1,146 @@
|
|
1
|
+
<script>
|
2
|
+
import create from "core/create";
|
3
|
+
import { generateRules } from "core";
|
4
|
+
import Render from "core/components/render";
|
5
|
+
import { bem } from "src/utils/bem";
|
6
|
+
import { defaultRender } from "core";
|
7
|
+
|
8
|
+
export default create({
|
9
|
+
functional: true,
|
10
|
+
name: "crud-cell",
|
11
|
+
props: {
|
12
|
+
col: Object,
|
13
|
+
scope: Object,
|
14
|
+
ctx: Object,
|
15
|
+
topProps: Object,
|
16
|
+
},
|
17
|
+
render(h, context) {
|
18
|
+
const { props, data } = context;
|
19
|
+
const { col, scope, ctx, topProps } = props;
|
20
|
+
|
21
|
+
const b = (...args) => bem("sc-crud-cell", ...args);
|
22
|
+
|
23
|
+
// 辅助函数
|
24
|
+
const findTreeProp = (tree, targetId, path = "") => {
|
25
|
+
for (let i = 0; i < tree.length; i++) {
|
26
|
+
const node = tree[i];
|
27
|
+
if (node.id === targetId) {
|
28
|
+
return path + i;
|
29
|
+
}
|
30
|
+
if (node.children && node.children.length > 0) {
|
31
|
+
const childPath = `${path}${i}.children.`;
|
32
|
+
const result = findTreeProp(node.children, targetId, childPath);
|
33
|
+
if (result !== null) {
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
return null;
|
39
|
+
};
|
40
|
+
|
41
|
+
// 获取表单属性
|
42
|
+
const getFormProp = (item) => {
|
43
|
+
if (!item.prop) return;
|
44
|
+
if (topProps.isTree) {
|
45
|
+
return (
|
46
|
+
"list." +
|
47
|
+
findTreeProp(ctx.list, scope.row[topProps.valueKey]) +
|
48
|
+
"." +
|
49
|
+
item.prop
|
50
|
+
);
|
51
|
+
}
|
52
|
+
return "list." + scope.$index + "." + (item.validateProp || item.prop);
|
53
|
+
};
|
54
|
+
|
55
|
+
// 获取渲染项
|
56
|
+
const getItem = (editMode) => {
|
57
|
+
const props = { ...col };
|
58
|
+
return (editMode && props[editMode]) || props;
|
59
|
+
};
|
60
|
+
|
61
|
+
// 单元格渲染
|
62
|
+
const cellRender = (item, editMode, rawRules, formProp) => {
|
63
|
+
return (
|
64
|
+
<Render
|
65
|
+
props={item}
|
66
|
+
item={item}
|
67
|
+
slots={topProps.extendsScopedSlots}
|
68
|
+
mode={editMode}
|
69
|
+
scope={scope}
|
70
|
+
size={topProps.size}
|
71
|
+
rawRules={rawRules}
|
72
|
+
defaultRender={topProps.defaultRender}
|
73
|
+
controlDefault={(defaultRender, scope) => {
|
74
|
+
if (editMode === "add" || editMode === "edit") {
|
75
|
+
return defaultRender.input;
|
76
|
+
}
|
77
|
+
}}
|
78
|
+
data-row-key={scope.row[topProps.valueKey]}
|
79
|
+
data-full-prop={formProp}
|
80
|
+
data-prop={item.prop}
|
81
|
+
></Render>
|
82
|
+
);
|
83
|
+
};
|
84
|
+
|
85
|
+
const cellDefaultRender = (item) => {
|
86
|
+
const _scope = {
|
87
|
+
...scope,
|
88
|
+
item,
|
89
|
+
$value: {
|
90
|
+
get: scope.row[item.prop],
|
91
|
+
},
|
92
|
+
};
|
93
|
+
return defaultRender.formatter(h, _scope);
|
94
|
+
};
|
95
|
+
|
96
|
+
const isDefaultRender = (item) => {
|
97
|
+
if (
|
98
|
+
item.comp ||
|
99
|
+
item.render ||
|
100
|
+
ctx.extendsScopedSlots[item.prop] ||
|
101
|
+
item.position ||
|
102
|
+
item.formatData
|
103
|
+
) {
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
return true;
|
107
|
+
};
|
108
|
+
|
109
|
+
// 主渲染逻辑
|
110
|
+
const editMode = ctx.validateEdit(col, scope);
|
111
|
+
const item = getItem(editMode);
|
112
|
+
const formProp = getFormProp(item);
|
113
|
+
const { rules, rawRules } = generateRules(item, scope);
|
114
|
+
const isValidate = editMode && rules.length;
|
115
|
+
const CompName = editMode && isValidate ? "el-form-item" : "div";
|
116
|
+
let VNode;
|
117
|
+
|
118
|
+
if (isDefaultRender(item) && !editMode) {
|
119
|
+
VNode = cellDefaultRender(item);
|
120
|
+
} else {
|
121
|
+
VNode = cellRender(item, editMode, rawRules, formProp);
|
122
|
+
}
|
123
|
+
return (
|
124
|
+
<CompName
|
125
|
+
class={[
|
126
|
+
rules.required && editMode ? "is-required" : "",
|
127
|
+
b([col.align || "center"]),
|
128
|
+
col.showOverflowTooltip && "sc-over-ellipsis",
|
129
|
+
]}
|
130
|
+
label-width={item.labelWidth}
|
131
|
+
size={topProps.size}
|
132
|
+
prop={formProp}
|
133
|
+
rules={rules}
|
134
|
+
style="width:100%"
|
135
|
+
on={{
|
136
|
+
"hook:destroyed": () => {
|
137
|
+
ctx.clearErrorMsg(scope.row, item.prop);
|
138
|
+
},
|
139
|
+
}}
|
140
|
+
>
|
141
|
+
{VNode}
|
142
|
+
</CompName>
|
143
|
+
);
|
144
|
+
},
|
145
|
+
});
|
146
|
+
</script>
|