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,507 @@
|
|
1
|
+
import { isEmptyData } from "utils";
|
2
|
+
import dayjs from "dayjs";
|
3
|
+
import { DATE_PATTERNS } from "../constants";
|
4
|
+
import { get } from "lodash-es";
|
5
|
+
|
6
|
+
export default {
|
7
|
+
// 字符串转数组
|
8
|
+
strToArr: (item) => {
|
9
|
+
const separator =
|
10
|
+
get(item, "formatData.separator") || item.separator || ",";
|
11
|
+
return {
|
12
|
+
input: (value, { row }) => {
|
13
|
+
if (!value) {
|
14
|
+
return [];
|
15
|
+
}
|
16
|
+
return typeof value === "string" ? value.split(separator) : value;
|
17
|
+
},
|
18
|
+
output: (value, { row }) => {
|
19
|
+
if (!value) {
|
20
|
+
return "";
|
21
|
+
}
|
22
|
+
return value.join(separator);
|
23
|
+
},
|
24
|
+
};
|
25
|
+
},
|
26
|
+
// 双字段格式化
|
27
|
+
doublePropToArr: (item) => {
|
28
|
+
const props = get(item, "formatData.doubleProp") || item.doubleProp;
|
29
|
+
if (!Array.isArray(props)) {
|
30
|
+
console.error("doubleProp必须为数组");
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
return {
|
34
|
+
input: (value, { row }) => {
|
35
|
+
return row[props[0]] !== undefined || row[props[1]] !== undefined
|
36
|
+
? [row[props[0]] || "", row[props[1]] || ""]
|
37
|
+
: [];
|
38
|
+
},
|
39
|
+
output: (value, { row }, setRow) => {
|
40
|
+
if (value && value.length) {
|
41
|
+
setRow(props[0], value[0]);
|
42
|
+
setRow(props[1], value[1]);
|
43
|
+
} else {
|
44
|
+
setRow(props[0], "");
|
45
|
+
setRow(props[1], "");
|
46
|
+
}
|
47
|
+
},
|
48
|
+
};
|
49
|
+
},
|
50
|
+
// 多字段格式化
|
51
|
+
multiPropToArr: (item) => {
|
52
|
+
const props = get(item, "formatData.multiProp") || item.multiProp;
|
53
|
+
// 是否包裹对象
|
54
|
+
const isObject = get(item, "formatData.isObject") || item.isObject;
|
55
|
+
if (!Array.isArray(props)) {
|
56
|
+
console.error("multiProp必须为数组");
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
return {
|
60
|
+
input: (value, { row }) => {
|
61
|
+
// 检查是否所有字段都为空
|
62
|
+
|
63
|
+
const isAllEmpty = props.every((prop) =>
|
64
|
+
isEmptyData(isObject ? get(row, [item.prop, prop]) : get(row, prop))
|
65
|
+
);
|
66
|
+
if (isAllEmpty) return [];
|
67
|
+
|
68
|
+
// 获取所有值(包括空值)
|
69
|
+
const values = props.map((prop) =>
|
70
|
+
isObject ? get(row, [item.prop, prop]) : row[prop]
|
71
|
+
);
|
72
|
+
|
73
|
+
// 找到最后一个非空值的索引
|
74
|
+
const lastValidIndex = values.reduce((lastIndex, val, index) => {
|
75
|
+
return !isEmptyData(val) ? index : lastIndex;
|
76
|
+
}, -1);
|
77
|
+
|
78
|
+
// 检查从开始到最后一个非空值之间是否有空值
|
79
|
+
const hasInvalidGap = values
|
80
|
+
.slice(0, lastValidIndex + 1)
|
81
|
+
.some((val, index) => isEmptyData(val));
|
82
|
+
|
83
|
+
// 如果中间有空值,返回空数组;否则返回到最后一个非空值的数组
|
84
|
+
return hasInvalidGap ? [] : values.slice(0, lastValidIndex + 1);
|
85
|
+
},
|
86
|
+
output: (value, { row }, setRow) => {
|
87
|
+
// 如果value为空数组或undefined,清空所有字段
|
88
|
+
if (!value || !Array.isArray(value) || value.length === 0) {
|
89
|
+
props.forEach((prop) =>
|
90
|
+
setRow(isObject ? [item.prop, prop] : prop, "")
|
91
|
+
);
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
|
95
|
+
// 设置有值的字段,其余字段清空
|
96
|
+
props.forEach((prop, index) => {
|
97
|
+
setRow(isObject ? [item.prop, prop] : prop, value[index] || "");
|
98
|
+
});
|
99
|
+
},
|
100
|
+
};
|
101
|
+
},
|
102
|
+
// 通用日期格式化
|
103
|
+
dateFormat: (item) => {
|
104
|
+
// 转换日期格式标记
|
105
|
+
const convertDateFormat = (format) => {
|
106
|
+
if (!format) return format;
|
107
|
+
|
108
|
+
return format
|
109
|
+
.replace(/yyyy/g, "YYYY") // 年份
|
110
|
+
.replace(/dd/g, "DD"); // 日期
|
111
|
+
};
|
112
|
+
// 默认配置
|
113
|
+
const config = {
|
114
|
+
valueFormat:
|
115
|
+
convertDateFormat(get(item, "comp.valueFormat")) || "YYYY-MM-DD", // 优先获取时间组件格式,否则使用默认格式
|
116
|
+
outputFormat: null, // 输出格式化
|
117
|
+
outputType: "string",
|
118
|
+
...(get(item, "formatData") || item),
|
119
|
+
};
|
120
|
+
|
121
|
+
// 检测日期格式
|
122
|
+
const detectDateFormat = (value) => {
|
123
|
+
if (!value) return null;
|
124
|
+
|
125
|
+
// 检测是否为时间戳
|
126
|
+
if (typeof value === "number") {
|
127
|
+
return { type: "timestamp" };
|
128
|
+
}
|
129
|
+
|
130
|
+
// 检测是否为 Date 对象
|
131
|
+
if (value instanceof Date) {
|
132
|
+
return { type: "Date" };
|
133
|
+
}
|
134
|
+
|
135
|
+
// 检测字符串格式
|
136
|
+
if (typeof value === "string") {
|
137
|
+
for (const pattern of DATE_PATTERNS) {
|
138
|
+
if (pattern.regex.test(value)) {
|
139
|
+
return { type: "string", format: pattern.format };
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
// 如果没有匹配到预定义格式,但是是有效日期
|
144
|
+
if (dayjs(value).isValid()) {
|
145
|
+
return { type: "string", format: "unknown" };
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
return null;
|
150
|
+
};
|
151
|
+
|
152
|
+
// 通用的日期转换函数
|
153
|
+
const convertDate = (value, format) => {
|
154
|
+
if (!value) return undefined;
|
155
|
+
|
156
|
+
try {
|
157
|
+
const date = dayjs(value);
|
158
|
+
if (!date.isValid()) return undefined;
|
159
|
+
return date.format(format);
|
160
|
+
} catch (error) {
|
161
|
+
console.warn("日期格式化失败:", error);
|
162
|
+
return undefined;
|
163
|
+
}
|
164
|
+
};
|
165
|
+
|
166
|
+
let originalFormat = null;
|
167
|
+
return {
|
168
|
+
input: (value) => {
|
169
|
+
// 检测并存储原始格式
|
170
|
+
originalFormat = detectDateFormat(value);
|
171
|
+
|
172
|
+
return convertDate(value, config.valueFormat);
|
173
|
+
},
|
174
|
+
output: (value) => {
|
175
|
+
if (!value) return undefined;
|
176
|
+
|
177
|
+
// 优先使用 outputFormat, 否则使用原始格式
|
178
|
+
const format =
|
179
|
+
config.outputFormat || originalFormat?.format || config.valueFormat;
|
180
|
+
|
181
|
+
// 如果是特殊类型(timestamp 或 Date),使用对应的转换器
|
182
|
+
if (originalFormat?.type === "timestamp") {
|
183
|
+
return dayjs(value).valueOf();
|
184
|
+
}
|
185
|
+
if (originalFormat?.type === "Date") {
|
186
|
+
return dayjs(value).toDate();
|
187
|
+
}
|
188
|
+
return convertDate(value, format);
|
189
|
+
},
|
190
|
+
};
|
191
|
+
},
|
192
|
+
// 周格式化
|
193
|
+
weekFormat: (item) => {
|
194
|
+
// 默认配置
|
195
|
+
const config = {
|
196
|
+
valueFormat: "YYYY-MM-DD", // 日期格式
|
197
|
+
weekStart: 0, // 周起始日(0-6)
|
198
|
+
includeTime: false, // 是否包含时间
|
199
|
+
separator: " ~ ", // 日期分隔符
|
200
|
+
outputType: "array", // 输出类型:array 或 string
|
201
|
+
...(get(item, "formatData") || item),
|
202
|
+
};
|
203
|
+
|
204
|
+
let originalValue = null;
|
205
|
+
return {
|
206
|
+
input: (value) => {
|
207
|
+
if (Array.isArray(value) && originalValue) return originalValue;
|
208
|
+
return value;
|
209
|
+
},
|
210
|
+
output: (value) => {
|
211
|
+
if (!value) return undefined;
|
212
|
+
originalValue = value;
|
213
|
+
try {
|
214
|
+
const date = dayjs(value);
|
215
|
+
if (!date.isValid()) return undefined;
|
216
|
+
|
217
|
+
// 获取周的开始和结束日期
|
218
|
+
const weekStart = date.startOf("week").add(config.weekStart, "day");
|
219
|
+
const weekEnd = date.endOf("week").add(config.weekStart, "day");
|
220
|
+
|
221
|
+
// 设置格式
|
222
|
+
const format = config.includeTime
|
223
|
+
? `${config.valueFormat} HH:mm:ss`
|
224
|
+
: config.valueFormat;
|
225
|
+
|
226
|
+
const startStr = weekStart.format(format);
|
227
|
+
const endStr = weekEnd.format(format);
|
228
|
+
|
229
|
+
// 根据输出类型返回不同格式
|
230
|
+
return config.outputType === "array"
|
231
|
+
? [startStr, endStr]
|
232
|
+
: `${startStr}${config.separator}${endStr}`;
|
233
|
+
} catch (error) {
|
234
|
+
console.warn("周格式化失败:", error);
|
235
|
+
return undefined;
|
236
|
+
}
|
237
|
+
},
|
238
|
+
};
|
239
|
+
},
|
240
|
+
// 数字格式化
|
241
|
+
numberFormat: (item) => {
|
242
|
+
const config = {
|
243
|
+
precision: 2, // 精度(小数位数)
|
244
|
+
round: true, // 是否四舍五入
|
245
|
+
toFixed: false, // 是否固定小数位数
|
246
|
+
thousandth: false, // 是否显示千分位
|
247
|
+
prefix: "", // 前缀
|
248
|
+
suffix: "", // 后缀
|
249
|
+
keepZero: false, // 是否保留末尾0
|
250
|
+
...(get(item, "formatData") || item),
|
251
|
+
};
|
252
|
+
|
253
|
+
// 处理千分位逻辑
|
254
|
+
const formatThousandth = (numStr) => {
|
255
|
+
const parts = numStr.split(".");
|
256
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
257
|
+
return parts.join(".");
|
258
|
+
};
|
259
|
+
|
260
|
+
// 处理数字精度
|
261
|
+
const formatPrecision = (num) => {
|
262
|
+
if (typeof num !== "number") return num;
|
263
|
+
|
264
|
+
if (config.precision !== undefined) {
|
265
|
+
const multiplier = Math.pow(10, config.precision);
|
266
|
+
num = config.round
|
267
|
+
? Math.round(num * multiplier) / multiplier
|
268
|
+
: Math.floor(num * multiplier) / multiplier;
|
269
|
+
}
|
270
|
+
|
271
|
+
if (config.toFixed && config.precision !== undefined) {
|
272
|
+
num = num.toFixed(config.precision);
|
273
|
+
if (!config.keepZero) {
|
274
|
+
num = String(Number(num));
|
275
|
+
}
|
276
|
+
}
|
277
|
+
return num;
|
278
|
+
};
|
279
|
+
|
280
|
+
// 处理多个小数点的情况(只保留第一个)
|
281
|
+
const normalizeInput = (inputStr) => {
|
282
|
+
let str = inputStr;
|
283
|
+
const parts = str.split(".");
|
284
|
+
if (parts.length > 2) {
|
285
|
+
str = parts[0] + "." + parts.slice(1).join("");
|
286
|
+
}
|
287
|
+
return str;
|
288
|
+
};
|
289
|
+
|
290
|
+
return {
|
291
|
+
input: (value) => {
|
292
|
+
try {
|
293
|
+
let rawStr = "";
|
294
|
+
if (typeof value === "string") {
|
295
|
+
rawStr = normalizeInput(value);
|
296
|
+
} else {
|
297
|
+
rawStr = String(value);
|
298
|
+
}
|
299
|
+
|
300
|
+
// 校验是否为有效的数字格式(允许负号和小数点)
|
301
|
+
if (!/^-?\d*\.?\d*$/.test(rawStr)) {
|
302
|
+
return value;
|
303
|
+
}
|
304
|
+
|
305
|
+
// 检查原始字符串是否以小数点结尾
|
306
|
+
const endsWithDot = rawStr.endsWith(".");
|
307
|
+
|
308
|
+
const num = Number(rawStr);
|
309
|
+
if (isNaN(num)) {
|
310
|
+
return value;
|
311
|
+
}
|
312
|
+
let formatted = formatPrecision(num);
|
313
|
+
formatted = String(formatted);
|
314
|
+
|
315
|
+
// 如果原始输入以小数点结尾,但格式化后中没有小数点,则补回
|
316
|
+
if (endsWithDot && !formatted.includes(".")) {
|
317
|
+
formatted += ".";
|
318
|
+
}
|
319
|
+
|
320
|
+
if (config.thousandth) {
|
321
|
+
formatted = formatThousandth(formatted);
|
322
|
+
}
|
323
|
+
|
324
|
+
return `${config.prefix}${formatted}${config.suffix}`;
|
325
|
+
} catch (error) {
|
326
|
+
console.warn("数字格式化失败:", error);
|
327
|
+
return value;
|
328
|
+
}
|
329
|
+
},
|
330
|
+
// 输出时去除格式化(还原为原始数字字符串)
|
331
|
+
output: (value) => {
|
332
|
+
try {
|
333
|
+
let rawStr = String(value);
|
334
|
+
|
335
|
+
rawStr = rawStr
|
336
|
+
.replace(config.prefix, "")
|
337
|
+
.replace(config.suffix, "")
|
338
|
+
.replace(/,/g, "");
|
339
|
+
|
340
|
+
// 如果用户处于删除过程(例如后缀已丢失),则移除最后一个字符
|
341
|
+
if (config.suffix && value.indexOf(config.suffix) === -1) {
|
342
|
+
rawStr = rawStr.slice(0, -1);
|
343
|
+
}
|
344
|
+
|
345
|
+
if (rawStr.endsWith(".")) {
|
346
|
+
return rawStr;
|
347
|
+
}
|
348
|
+
const num = Number(rawStr);
|
349
|
+
return isNaN(num) ? undefined : rawStr;
|
350
|
+
} catch (error) {
|
351
|
+
console.warn("数字还原失败:", error);
|
352
|
+
return undefined;
|
353
|
+
}
|
354
|
+
},
|
355
|
+
};
|
356
|
+
},
|
357
|
+
// 输入格式化
|
358
|
+
inputFormat: (item) => {
|
359
|
+
// 预设的正则规则
|
360
|
+
const REGEX_RULES = {
|
361
|
+
number: /[^\d]/g, // 仅数字
|
362
|
+
phone: /[^\d]/g, // 手机号
|
363
|
+
decimal: /[^\d.]/g, // 小数
|
364
|
+
letter: /[^a-zA-Z]/g, // 仅字母
|
365
|
+
chinese: /[^\u4e00-\u9fa5]/g, // 仅中文
|
366
|
+
letterNumber: /[^a-zA-Z0-9]/g, // 字母和数字
|
367
|
+
email: /[^a-zA-Z0-9@._-]/g, // 邮箱
|
368
|
+
custom: null, // 自定义正则
|
369
|
+
};
|
370
|
+
|
371
|
+
// 默认配置
|
372
|
+
const config = {
|
373
|
+
inputType: "number", // 格式化类型
|
374
|
+
pattern: "", // 自定义正则
|
375
|
+
maxLength: undefined, // 最大长度
|
376
|
+
decimal: undefined, // 小数位数(type为decimal时使用)
|
377
|
+
...(get(item, "formatData") || item),
|
378
|
+
};
|
379
|
+
|
380
|
+
// 处理小数格式化
|
381
|
+
const formatDecimal = (value) => {
|
382
|
+
if (!value) return value;
|
383
|
+
|
384
|
+
// 先去除非数字和小数点
|
385
|
+
let formatted = value.replace(/[^\d.]/g, "");
|
386
|
+
|
387
|
+
// 只保留第一个小数点
|
388
|
+
const parts = formatted.split(".");
|
389
|
+
if (parts.length > 2) {
|
390
|
+
formatted = parts[0] + "." + parts.slice(1).join("");
|
391
|
+
}
|
392
|
+
|
393
|
+
// 处理小数位数
|
394
|
+
if (config.decimal !== undefined && parts[1]) {
|
395
|
+
formatted = parts[0] + "." + parts[1].slice(0, config.decimal);
|
396
|
+
}
|
397
|
+
|
398
|
+
return formatted;
|
399
|
+
};
|
400
|
+
|
401
|
+
return {
|
402
|
+
input: (value) => {
|
403
|
+
if (!value) return value;
|
404
|
+
|
405
|
+
try {
|
406
|
+
let formatted = String(value);
|
407
|
+
|
408
|
+
// 处理最大长度
|
409
|
+
if (config.maxLength) {
|
410
|
+
formatted = formatted.slice(0, config.maxLength);
|
411
|
+
}
|
412
|
+
|
413
|
+
// 小数特殊处理
|
414
|
+
if (config.inputType === "decimal") {
|
415
|
+
return formatDecimal(formatted);
|
416
|
+
}
|
417
|
+
|
418
|
+
// 优先使用自定义正则,如果没有则使用预设规则
|
419
|
+
const rule = config.pattern
|
420
|
+
? new RegExp(config.pattern, "g")
|
421
|
+
: REGEX_RULES[config.inputType];
|
422
|
+
|
423
|
+
return formatted.replace(rule, "");
|
424
|
+
} catch (error) {
|
425
|
+
console.warn("输入格式化失败:", error);
|
426
|
+
return value;
|
427
|
+
}
|
428
|
+
},
|
429
|
+
output: (value) => value,
|
430
|
+
};
|
431
|
+
},
|
432
|
+
// 百分比格式化
|
433
|
+
percentFormat: (item) => {
|
434
|
+
const config = {
|
435
|
+
precision: 2, // 小数位数
|
436
|
+
multiplier: 100, // 乘数因子
|
437
|
+
addSymbol: true, // 是否添加百分号
|
438
|
+
...(get(item, "formatData") || item),
|
439
|
+
};
|
440
|
+
|
441
|
+
return {
|
442
|
+
input: (value) => {
|
443
|
+
if (!value && value !== 0) return "";
|
444
|
+
try {
|
445
|
+
const num = Number(value) * config.multiplier;
|
446
|
+
const formatted = num.toFixed(config.precision);
|
447
|
+
return config.addSymbol ? `${formatted}%` : formatted;
|
448
|
+
} catch (error) {
|
449
|
+
console.warn("百分比格式化失败:", error);
|
450
|
+
return value;
|
451
|
+
}
|
452
|
+
},
|
453
|
+
output: (value) => {
|
454
|
+
if (!value && value !== 0) return undefined;
|
455
|
+
try {
|
456
|
+
const num = parseFloat(value.replace("%", "")) / config.multiplier;
|
457
|
+
return isNaN(num) ? undefined : String(num);
|
458
|
+
} catch (error) {
|
459
|
+
console.warn("百分比还原失败:", error);
|
460
|
+
return undefined;
|
461
|
+
}
|
462
|
+
},
|
463
|
+
};
|
464
|
+
},
|
465
|
+
// 文件大小格式化
|
466
|
+
fileSizeFormat: (item) => {
|
467
|
+
const config = {
|
468
|
+
units: ["B", "KB", "MB", "GB", "TB"],
|
469
|
+
precision: 2,
|
470
|
+
...(get(item, "formatData") || item),
|
471
|
+
};
|
472
|
+
|
473
|
+
return {
|
474
|
+
input: (value) => {
|
475
|
+
if (!value && value !== 0) return "";
|
476
|
+
try {
|
477
|
+
let size = Number(value);
|
478
|
+
let unitIndex = 0;
|
479
|
+
|
480
|
+
while (size >= 1024 && unitIndex < config.units.length - 1) {
|
481
|
+
size /= 1024;
|
482
|
+
unitIndex++;
|
483
|
+
}
|
484
|
+
|
485
|
+
return `${size.toFixed(config.precision)} ${config.units[unitIndex]}`;
|
486
|
+
} catch (error) {
|
487
|
+
console.warn("文件大小格式化失败:", error);
|
488
|
+
return value;
|
489
|
+
}
|
490
|
+
},
|
491
|
+
output: (value) => {
|
492
|
+
if (!value) return undefined;
|
493
|
+
try {
|
494
|
+
const [size, unit] = value.split(" ");
|
495
|
+
const unitIndex = config.units.indexOf(unit);
|
496
|
+
if (unitIndex === -1) return undefined;
|
497
|
+
|
498
|
+
const bytes = parseFloat(size) * Math.pow(1024, unitIndex);
|
499
|
+
return String(Math.round(bytes));
|
500
|
+
} catch (error) {
|
501
|
+
console.warn("文件大小还原失败:", error);
|
502
|
+
return undefined;
|
503
|
+
}
|
504
|
+
},
|
505
|
+
};
|
506
|
+
},
|
507
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import rules from "./rules";
|
2
|
+
import formatData from "./formatData";
|
3
|
+
import render from "./render";
|
4
|
+
import btn from "./btn/index";
|
5
|
+
import dicts from "./dicts";
|
6
|
+
import { merge } from "lodash-es";
|
7
|
+
const template = {
|
8
|
+
rules,
|
9
|
+
formatData,
|
10
|
+
render,
|
11
|
+
btn,
|
12
|
+
dicts,
|
13
|
+
};
|
14
|
+
|
15
|
+
export default template;
|
16
|
+
|
17
|
+
export function mergeTemplate(presetType) {
|
18
|
+
merge(template, presetType);
|
19
|
+
}
|
@@ -0,0 +1,124 @@
|
|
1
|
+
export default {
|
2
|
+
date: {
|
3
|
+
comp: {
|
4
|
+
name: "el-date-picker",
|
5
|
+
type: "date",
|
6
|
+
valueFormat: "yyyy-MM-dd",
|
7
|
+
},
|
8
|
+
},
|
9
|
+
dateRange: () => ({
|
10
|
+
comp: () => {
|
11
|
+
return {
|
12
|
+
name: "el-date-picker",
|
13
|
+
type: "daterange",
|
14
|
+
"range-separator": "-",
|
15
|
+
"start-placeholder": "开始",
|
16
|
+
"end-placeholder": "结束",
|
17
|
+
valueFormat: "yyyy-MM-dd",
|
18
|
+
};
|
19
|
+
},
|
20
|
+
}),
|
21
|
+
textLink(item) {
|
22
|
+
return {
|
23
|
+
render: (h, { row }) => {
|
24
|
+
return row[item.prop] ? (
|
25
|
+
<el-button
|
26
|
+
class="sc-default-formatter"
|
27
|
+
type="text"
|
28
|
+
onClick={() => {
|
29
|
+
if (item.onClick) {
|
30
|
+
item.onClick(row);
|
31
|
+
}
|
32
|
+
}}
|
33
|
+
>
|
34
|
+
{row[item.prop]}
|
35
|
+
</el-button>
|
36
|
+
) : null;
|
37
|
+
},
|
38
|
+
};
|
39
|
+
},
|
40
|
+
// 返回指定页
|
41
|
+
successBack: (item) => {
|
42
|
+
return {
|
43
|
+
title: "提交成功",
|
44
|
+
footer: {
|
45
|
+
hidden: true,
|
46
|
+
},
|
47
|
+
render: (h, scope) => (
|
48
|
+
<el-result icon="success" title="提交成功" subTitle="是否立即返回?">
|
49
|
+
<template slot="extra">
|
50
|
+
<el-button
|
51
|
+
type="primary"
|
52
|
+
style="width: 100px;"
|
53
|
+
size="small"
|
54
|
+
onClick={item.onClick}
|
55
|
+
>
|
56
|
+
返回
|
57
|
+
</el-button>
|
58
|
+
</template>
|
59
|
+
</el-result>
|
60
|
+
),
|
61
|
+
};
|
62
|
+
},
|
63
|
+
// 确认提示
|
64
|
+
confirmTip: (item) => {
|
65
|
+
return {
|
66
|
+
title: item.title || "提示",
|
67
|
+
width: item.width || "400px",
|
68
|
+
render: (h, scope) => {
|
69
|
+
return (
|
70
|
+
<div style="display:flex">
|
71
|
+
<div
|
72
|
+
class="el-icon-warning"
|
73
|
+
style="color:#E6A23C;font-size:24px;margin-right:15px"
|
74
|
+
></div>
|
75
|
+
<div style="flex:1;padding-right:20px">
|
76
|
+
<div style="margin-top:2px;">
|
77
|
+
{item.label || "确定要执行此操作吗?"}
|
78
|
+
</div>
|
79
|
+
{item.content ? (
|
80
|
+
typeof item.content !== "function" ? (
|
81
|
+
<div style="margin-top:10px;">{item.content || ""}</div>
|
82
|
+
) : (
|
83
|
+
<div style="margin-top:10px;">{item.content(h)}</div>
|
84
|
+
)
|
85
|
+
) : null}
|
86
|
+
</div>
|
87
|
+
</div>
|
88
|
+
);
|
89
|
+
},
|
90
|
+
};
|
91
|
+
},
|
92
|
+
// 文本提交
|
93
|
+
textSubmit: (item) => {
|
94
|
+
let formRef = null;
|
95
|
+
return {
|
96
|
+
title: item.title || "提示",
|
97
|
+
width: item.width || "400px",
|
98
|
+
comp: {
|
99
|
+
name: "sc-form",
|
100
|
+
labelPosition: "top",
|
101
|
+
mounted: (scope, instance) => {
|
102
|
+
formRef = instance;
|
103
|
+
},
|
104
|
+
renderColumns: [
|
105
|
+
{
|
106
|
+
prop: "input",
|
107
|
+
label: item.label || item.title || "原因",
|
108
|
+
required: item.required || true,
|
109
|
+
comp: {
|
110
|
+
type: item.type || "textarea",
|
111
|
+
rows: item.rows || 4,
|
112
|
+
maxlength: item.maxlength || 200,
|
113
|
+
showWordLimit: item.showWordLimit || true,
|
114
|
+
},
|
115
|
+
},
|
116
|
+
],
|
117
|
+
},
|
118
|
+
confirm: async (cb, d) => {
|
119
|
+
await formRef.validate();
|
120
|
+
item.submit(cb, d.value.input);
|
121
|
+
},
|
122
|
+
};
|
123
|
+
},
|
124
|
+
};
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { isEmptyData } from "utils";
|
2
|
+
const regulars = {
|
3
|
+
integer: {
|
4
|
+
msg: "请输入正整数",
|
5
|
+
regular: /^[0-9]\d*$/,
|
6
|
+
},
|
7
|
+
integer100: {
|
8
|
+
msg: "请输入1~100的正整数",
|
9
|
+
regular: /^([0-9][0-9]{0,1}|100)$/,
|
10
|
+
},
|
11
|
+
phone: {
|
12
|
+
msg: "请输入正确的手机号码",
|
13
|
+
regular: /^1[3-9]\d{9}$/,
|
14
|
+
},
|
15
|
+
email: {
|
16
|
+
msg: "请输入正确的邮箱地址",
|
17
|
+
regular: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(com|cn|net|org|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$/,
|
18
|
+
},
|
19
|
+
number: {
|
20
|
+
msg: "请输入数字",
|
21
|
+
regular: /^(0\.\d{1,2}|[1-9]\d*(\.\d{1,2})?|0)$/,
|
22
|
+
},
|
23
|
+
};
|
24
|
+
|
25
|
+
export default {
|
26
|
+
required: (rules, { item }) => {
|
27
|
+
return {
|
28
|
+
validator: (rule, value, callback) => {
|
29
|
+
if (!isEmptyData(value)) {
|
30
|
+
callback();
|
31
|
+
} else {
|
32
|
+
callback(new Error(item.label + "不能为空"));
|
33
|
+
}
|
34
|
+
},
|
35
|
+
trigger: item.trigger || "change",
|
36
|
+
message: item.msg,
|
37
|
+
};
|
38
|
+
// return {
|
39
|
+
// required: true,
|
40
|
+
// message: item.label + "不能为空",
|
41
|
+
// trigger: rules.trigger || "change",
|
42
|
+
// };
|
43
|
+
},
|
44
|
+
limit: (rules, { item }) => {
|
45
|
+
return {
|
46
|
+
min: rules.min,
|
47
|
+
max: rules.max,
|
48
|
+
message: `长度在 ${rules.min} 到 ${rules.max} 个字符`,
|
49
|
+
trigger: rules.trigger || "change",
|
50
|
+
};
|
51
|
+
},
|
52
|
+
...regulars,
|
53
|
+
};
|