@archbiz/element-ui 0.0.0-stage → 0.1.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/dist/element-ui.cjs +11 -0
- package/dist/element-ui.js +5518 -0
- package/dist/style.css +1 -0
- package/package.json +50 -4
- package/src/components/ab-checkbox.vue +51 -0
- package/src/components/ab-color-picker.vue +39 -0
- package/src/components/ab-detail/ab-detail.vue +285 -0
- package/src/components/ab-detail/index.js +1 -0
- package/src/components/ab-drawer/ab-drawer.vue +50 -0
- package/src/components/ab-drawer/index.js +3 -0
- package/src/components/ab-icon/ab-icon.vue +90 -0
- package/src/components/ab-icon/index.js +1 -0
- package/src/components/ab-input-number.vue +49 -0
- package/src/components/ab-input-range.vue +90 -0
- package/src/components/ab-radio.vue +51 -0
- package/src/components/ab-router-link.vue +46 -0
- package/src/components/ab-search/ab-search.vue +168 -0
- package/src/components/ab-search/index.js +4 -0
- package/src/components/ab-select.vue +107 -0
- package/src/components/ab-table/ab-table-column.vue +131 -0
- package/src/components/ab-table/ab-table-columns.vue +62 -0
- package/src/components/ab-table/ab-table-operate.vue +160 -0
- package/src/components/ab-table/ab-table.vue +316 -0
- package/src/components/ab-table/columns.js +90 -0
- package/src/components/ab-table/footer.js +77 -0
- package/src/components/ab-table/formatter.js +2 -0
- package/src/components/ab-table/index.js +8 -0
- package/src/components/ab-table/utils.js +36 -0
- package/src/components/ab-time-period.vue +116 -0
- package/src/components/ab-time-picker.vue +38 -0
- package/src/components/ab-toolbar/ab-toolbar.vue +102 -0
- package/src/components/ab-toolbar/index.js +1 -0
- package/src/components/ab-tree-select.vue +456 -0
- package/src/components/ab-upload-file.vue +277 -0
- package/src/components/index.js +27 -0
- package/src/core/ab-form.js +25 -0
- package/src/core/alias.js +36 -0
- package/src/core/config.js +65 -0
- package/src/core/form-render.js +256 -0
- package/src/core/options.js +25 -0
- package/src/hooks/use-cache.js +75 -0
- package/src/index.js +39 -0
- package/src/makers/datePicker.js +8 -0
- package/src/makers/frame.js +23 -0
- package/src/makers/index.js +23 -0
- package/src/makers/input.js +12 -0
- package/src/makers/select.js +8 -0
- package/src/makers/slider.js +7 -0
- package/src/makers/timePicker.js +8 -0
- package/src/makers/tree.js +10 -0
- package/src/makers/upload.js +20 -0
- package/src/parsers/checkbox.js +5 -0
- package/src/parsers/colorPicker.js +29 -0
- package/src/parsers/datePicker.js +24 -0
- package/src/parsers/frame.js +17 -0
- package/src/parsers/hidden.js +11 -0
- package/src/parsers/index.js +36 -0
- package/src/parsers/input.js +15 -0
- package/src/parsers/number.js +29 -0
- package/src/parsers/radio.js +5 -0
- package/src/parsers/select.js +15 -0
- package/src/parsers/slider.js +21 -0
- package/src/parsers/switch.js +11 -0
- package/src/parsers/text.js +25 -0
- package/src/parsers/timePicker.js +12 -0
- package/src/parsers/tree.js +37 -0
- package/src/parsers/upload.js +35 -0
- package/src/plugins/ab-detail.js +7 -0
- package/src/plugins/ab-drawer.js +7 -0
- package/src/plugins/ab-form.js +14 -0
- package/src/plugins/ab-search.js +7 -0
- package/src/plugins/ab-table.js +15 -0
- package/src/plugins/ab-toolbar.js +7 -0
- package/src/rule/defaults.js +187 -0
- package/src/rule/formatter.js +218 -0
- package/src/style/index.css +356 -0
- package/src/utils/formatter.js +188 -0
- package/src/utils/router-link.js +59 -0
- package/README.md +0 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import AbTable from "../components/ab-table/ab-table.vue";
|
|
2
|
+
import AbTableColumns from "../components/ab-table/ab-table-columns.vue";
|
|
3
|
+
import AbTableColumn from "../components/ab-table/ab-table-column.vue";
|
|
4
|
+
import AbTableOperate from "../components/ab-table/ab-table-operate.vue";
|
|
5
|
+
import AbRouterLink from "../components/ab-router-link.vue";
|
|
6
|
+
|
|
7
|
+
export function setupAbTable(Vue) {
|
|
8
|
+
Vue.component("ab-table", AbTable);
|
|
9
|
+
Vue.component("ab-table-columns", AbTableColumns);
|
|
10
|
+
Vue.component("ab-table-column", AbTableColumn);
|
|
11
|
+
Vue.component("ab-table-operate", AbTableOperate);
|
|
12
|
+
Vue.component("ab-router-link", AbRouterLink);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default { install: setupAbTable };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Migrated from element-plus/src/rule/defaults.ts
|
|
2
|
+
// Kept dependency-free (no lodash/dayjs) for the Vue 2 adapter.
|
|
3
|
+
|
|
4
|
+
const MS_DAY = 24 * 60 * 60 * 1000;
|
|
5
|
+
|
|
6
|
+
const labels = {
|
|
7
|
+
today: "今天",
|
|
8
|
+
yesterday: "昨天",
|
|
9
|
+
lastWeek: "上周",
|
|
10
|
+
last7: "近7天",
|
|
11
|
+
last30: "近30天",
|
|
12
|
+
thisMonth: "本月",
|
|
13
|
+
thisYear: "今年",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const predefineColors = [
|
|
17
|
+
"rgba(1, 1, 1, 0)",
|
|
18
|
+
"#45b787",
|
|
19
|
+
"#21532fff",
|
|
20
|
+
"#6e9bc5",
|
|
21
|
+
"#2775b6",
|
|
22
|
+
"#F26666",
|
|
23
|
+
"#D95970",
|
|
24
|
+
"#ECD2B9",
|
|
25
|
+
"#BF9D8A",
|
|
26
|
+
"#ECDEC0",
|
|
27
|
+
"#D0AC57",
|
|
28
|
+
"#e0e0e0",
|
|
29
|
+
"#beb6b6",
|
|
30
|
+
"#918883",
|
|
31
|
+
"#F2F2F2",
|
|
32
|
+
"#ececec",
|
|
33
|
+
"#2E3032", // 403C3A
|
|
34
|
+
"#182327",
|
|
35
|
+
"rgba(0, 0, 0, 0.5)",
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
function isPlainObject(value) {
|
|
39
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function deepMerge(target, ...sources) {
|
|
43
|
+
const out = isPlainObject(target) ? { ...target } : {};
|
|
44
|
+
for (const source of sources) {
|
|
45
|
+
if (!isPlainObject(source)) continue;
|
|
46
|
+
for (const key of Object.keys(source)) {
|
|
47
|
+
const value = source[key];
|
|
48
|
+
out[key] = isPlainObject(value) ? deepMerge(isPlainObject(out[key]) ? out[key] : {}, value) : value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getValue(obj, path, def) {
|
|
55
|
+
let cur = obj;
|
|
56
|
+
for (const key of path.split(".")) {
|
|
57
|
+
if (cur === null || cur === undefined) return def;
|
|
58
|
+
cur = cur[key];
|
|
59
|
+
}
|
|
60
|
+
return cur === undefined ? def : cur;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ============== shortcuts ==============
|
|
64
|
+
function startOfDay(date) {
|
|
65
|
+
const d = new Date(date);
|
|
66
|
+
d.setHours(0, 0, 0, 0);
|
|
67
|
+
return d;
|
|
68
|
+
}
|
|
69
|
+
function endOfDay(date) {
|
|
70
|
+
const d = new Date(date);
|
|
71
|
+
d.setHours(23, 59, 59, 999);
|
|
72
|
+
return d;
|
|
73
|
+
}
|
|
74
|
+
function startOfWeek(date) {
|
|
75
|
+
const d = startOfDay(date);
|
|
76
|
+
d.setDate(d.getDate() - d.getDay());
|
|
77
|
+
return d;
|
|
78
|
+
}
|
|
79
|
+
function endOfWeek(date) {
|
|
80
|
+
const d = startOfDay(date);
|
|
81
|
+
d.setDate(d.getDate() - d.getDay() + 6);
|
|
82
|
+
return endOfDay(d);
|
|
83
|
+
}
|
|
84
|
+
function startOfMonth(date) {
|
|
85
|
+
const d = startOfDay(date);
|
|
86
|
+
d.setDate(1);
|
|
87
|
+
return d;
|
|
88
|
+
}
|
|
89
|
+
function startOfYear(date) {
|
|
90
|
+
return new Date(new Date(date).getFullYear(), 0, 1, 0, 0, 0, 0);
|
|
91
|
+
}
|
|
92
|
+
function addDays(date, days) {
|
|
93
|
+
return new Date(date.getTime() + days * MS_DAY);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const defaultShortcuts = [
|
|
97
|
+
{ text: labels.today, value: () => startOfDay(new Date()).getTime() },
|
|
98
|
+
{ text: labels.yesterday, value: () => startOfDay(addDays(new Date(), -1)).getTime() },
|
|
99
|
+
{ text: labels.lastWeek, value: () => startOfWeek(addDays(new Date(), -7)).getTime() },
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
export const defaultRangeShortcuts = [
|
|
103
|
+
{
|
|
104
|
+
text: labels.today,
|
|
105
|
+
value: () => [startOfDay(new Date()).getTime(), endOfDay(new Date()).getTime()],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
text: labels.yesterday,
|
|
109
|
+
value: () => [startOfDay(addDays(new Date(), -1)).getTime(), endOfDay(addDays(new Date(), -1)).getTime()],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
text: labels.lastWeek,
|
|
113
|
+
value: () => [startOfWeek(addDays(new Date(), -7)).getTime(), endOfWeek(addDays(new Date(), -7)).getTime()],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
text: labels.last7,
|
|
117
|
+
value: () => [startOfDay(addDays(new Date(), -7)).getTime(), endOfDay(new Date()).getTime()],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
text: labels.last30,
|
|
121
|
+
value: () => [startOfDay(addDays(new Date(), -30)).getTime(), endOfDay(new Date()).getTime()],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
text: labels.thisMonth,
|
|
125
|
+
value: () => [startOfMonth(new Date()).getTime(), endOfDay(new Date()).getTime()],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
text: labels.thisYear,
|
|
129
|
+
value: () => [startOfYear(new Date()).getTime(), endOfDay(new Date()).getTime()],
|
|
130
|
+
},
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
function defaultDisableDate(time) {
|
|
134
|
+
return time.getTime() > Date.now();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ============== defaults ==============
|
|
138
|
+
const defaults = {
|
|
139
|
+
hidden: { hidden: true },
|
|
140
|
+
// Element UI 使用 value-format="timestamp",故此处使用 "timestamp"
|
|
141
|
+
datePicker: { props: { valueFormat: "timestamp" } },
|
|
142
|
+
timePicker: { props: { format: "HH:mm", valueFormat: "HH:mm" } },
|
|
143
|
+
select: { props: { showKey: true, showCode: true } },
|
|
144
|
+
treeSelect: { props: { defaultExpandAll: true, expandOnClickNode: false } },
|
|
145
|
+
treeSelectMultiple: { props: { multiple: true, type: "checked", showCheckbox: true } },
|
|
146
|
+
inputNumber: { align: "right" },
|
|
147
|
+
inputCurrency: { align: "right" },
|
|
148
|
+
inputPercent: { align: "right" },
|
|
149
|
+
switch: { align: "center" },
|
|
150
|
+
colorPicker: { props: { showAlpha: true, predefine: predefineColors } },
|
|
151
|
+
divider: { props: { contentPosition: "left" } },
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function mergeDefaultChildren(defaultChildren, children) {
|
|
155
|
+
if (children === undefined) return defaultChildren;
|
|
156
|
+
if (!Array.isArray(children)) return children;
|
|
157
|
+
const childSlots = new Set(children.map((child) => child && child.slot).filter(Boolean));
|
|
158
|
+
return [...defaultChildren.filter((child) => !child.slot || !childSlots.has(child.slot)), ...children];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function applyRuleDefaults(rule, options = {}) {
|
|
162
|
+
const { type, disabledDate, shortcuts } = rule || {};
|
|
163
|
+
let typeDefaults = defaults[type || ""];
|
|
164
|
+
if (type === "datePicker") {
|
|
165
|
+
if (disabledDate === true) {
|
|
166
|
+
typeDefaults = deepMerge({}, typeDefaults, { props: { disabledDate: defaultDisableDate } });
|
|
167
|
+
}
|
|
168
|
+
if (shortcuts === true) {
|
|
169
|
+
const isRange = getValue(rule, "props.type") === "daterange";
|
|
170
|
+
typeDefaults = deepMerge({}, typeDefaults, {
|
|
171
|
+
props: { shortcuts: isRange ? defaultRangeShortcuts : defaultShortcuts },
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
} else if (type === "treeSelect" && getValue(rule, "props.multiple")) {
|
|
175
|
+
typeDefaults = deepMerge({}, typeDefaults, defaults.treeSelectMultiple);
|
|
176
|
+
}
|
|
177
|
+
if (!typeDefaults) return rule;
|
|
178
|
+
|
|
179
|
+
const includeChildren = options.includeChildren !== false;
|
|
180
|
+
const { children: defaultChildren, ...otherDefaults } = typeDefaults;
|
|
181
|
+
const ruleDefaults = includeChildren ? typeDefaults : otherDefaults;
|
|
182
|
+
const decoratedRule = deepMerge({}, ruleDefaults, rule);
|
|
183
|
+
if (includeChildren && defaultChildren) {
|
|
184
|
+
return { ...decoratedRule, children: mergeDefaultChildren(defaultChildren, rule.children) };
|
|
185
|
+
}
|
|
186
|
+
return decoratedRule;
|
|
187
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionsFormatter,
|
|
3
|
+
valueDate,
|
|
4
|
+
vxeCurrency,
|
|
5
|
+
vxeDateM,
|
|
6
|
+
vxeDateQ,
|
|
7
|
+
vxeDateTime,
|
|
8
|
+
vxeDateW,
|
|
9
|
+
vxeDateY,
|
|
10
|
+
vxeNumber,
|
|
11
|
+
vxePercentByNumber,
|
|
12
|
+
} from "../utils/formatter.js";
|
|
13
|
+
|
|
14
|
+
function isEqual(a, b) {
|
|
15
|
+
if (a === b) return true;
|
|
16
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
17
|
+
return a.length === b.length && a.every((item, index) => isEqual(item, b[index]));
|
|
18
|
+
}
|
|
19
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
20
|
+
const keys = Object.keys(a);
|
|
21
|
+
return keys.length === Object.keys(b).length && keys.every((key) => isEqual(a[key], b[key]));
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function findTreeByValue(nodes, value, { valueField = "value", childrenField = "children" } = {}) {
|
|
27
|
+
for (const node of nodes || []) {
|
|
28
|
+
if (isEqual(node ? node[valueField] : undefined, value)) return node;
|
|
29
|
+
const found = findTreeByValue(node ? node[childrenField] : undefined, value, { valueField, childrenField });
|
|
30
|
+
if (found) return found;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createChoiceFormatter(rule) {
|
|
36
|
+
const options = rule.props?.options || rule.options;
|
|
37
|
+
return ({ cellValue }) => {
|
|
38
|
+
if (cellValue === null || cellValue === undefined || cellValue === "") return "";
|
|
39
|
+
const values = Array.isArray(cellValue) ? cellValue : [cellValue];
|
|
40
|
+
return values
|
|
41
|
+
.map((value) => {
|
|
42
|
+
const option = Array.isArray(options) ? options.find((item) => item && item.value === value) : undefined;
|
|
43
|
+
return option && option.label !== undefined ? option.label : value ?? "";
|
|
44
|
+
})
|
|
45
|
+
.join("、");
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createSwitchFormatter(rule) {
|
|
50
|
+
return ({ cellValue }) => {
|
|
51
|
+
const { activeValue = true, inactiveValue = false, activeText, inactiveText } = rule.props || {};
|
|
52
|
+
if (cellValue === activeValue) return activeText || "开启";
|
|
53
|
+
if (cellValue === inactiveValue) return inactiveText || "关闭";
|
|
54
|
+
return cellValue ?? "";
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createTreeSelectFormatter(rule) {
|
|
59
|
+
const props = rule.props || {};
|
|
60
|
+
const mapping = props.props || {};
|
|
61
|
+
const data = rule.optionsTo === "props.data" && Array.isArray(rule.options) ? rule.options : props.data;
|
|
62
|
+
const valueField = mapping.value ?? props.nodeKey ?? props.valueKey ?? "value";
|
|
63
|
+
const labelField = mapping.label ?? "label";
|
|
64
|
+
const childrenField = mapping.children ?? "children";
|
|
65
|
+
return ({ cellValue }) => {
|
|
66
|
+
if (cellValue === null || cellValue === undefined || cellValue === "") return "";
|
|
67
|
+
const values = Array.isArray(cellValue) ? cellValue : [cellValue];
|
|
68
|
+
return values
|
|
69
|
+
.map((value) => {
|
|
70
|
+
const node = Array.isArray(data) ? findTreeByValue(data, value, { valueField, childrenField }) : undefined;
|
|
71
|
+
return node && node[labelField] !== undefined ? node[labelField] : value;
|
|
72
|
+
})
|
|
73
|
+
.join("、");
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function findCascaderPath(nodes, value, valueField, childrenField) {
|
|
78
|
+
for (const node of nodes || []) {
|
|
79
|
+
if (isEqual(node[valueField], value)) return [node];
|
|
80
|
+
const path = findCascaderPath(node[childrenField], value, valueField, childrenField);
|
|
81
|
+
if (path) return [node, ...path];
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function createCascaderFormatter(rule) {
|
|
87
|
+
const props = rule.props || {};
|
|
88
|
+
const config = props.props || {};
|
|
89
|
+
const options = rule.optionsTo === "props.options" && Array.isArray(rule.options) ? rule.options : props.options;
|
|
90
|
+
const valueField = config.value ?? "value";
|
|
91
|
+
const labelField = config.label ?? "label";
|
|
92
|
+
const childrenField = config.children ?? "children";
|
|
93
|
+
const nodes = Array.isArray(options) ? options : [];
|
|
94
|
+
const separator = props.separator ?? " / ";
|
|
95
|
+
const showAllLevels = props.showAllLevels !== false;
|
|
96
|
+
|
|
97
|
+
function formatPath(value) {
|
|
98
|
+
let path;
|
|
99
|
+
if (config.emitPath === false) {
|
|
100
|
+
const found = findCascaderPath(nodes, value, valueField, childrenField);
|
|
101
|
+
path = found ? found.map((node) => node[labelField] ?? node[valueField]) : [value];
|
|
102
|
+
} else {
|
|
103
|
+
const values = Array.isArray(value) ? value : [value];
|
|
104
|
+
let siblings = nodes;
|
|
105
|
+
path = values.map((item) => {
|
|
106
|
+
const node = siblings.find((candidate) => isEqual(candidate[valueField], item));
|
|
107
|
+
siblings = node && Array.isArray(node[childrenField]) ? node[childrenField] : [];
|
|
108
|
+
return node && node[labelField] !== undefined ? node[labelField] : item;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return (showAllLevels ? path : path.slice(-1)).join(separator);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return ({ cellValue }) => {
|
|
115
|
+
if (cellValue === null || cellValue === undefined || cellValue === "") return "";
|
|
116
|
+
if (config.multiple === true) return (Array.isArray(cellValue) ? cellValue : [cellValue]).map(formatPath).join("、");
|
|
117
|
+
return formatPath(cellValue);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const dateFormatters = {
|
|
122
|
+
year: vxeDateY,
|
|
123
|
+
years: vxeDateY,
|
|
124
|
+
yearrange: vxeDateY,
|
|
125
|
+
quarter: vxeDateQ,
|
|
126
|
+
quarters: vxeDateQ,
|
|
127
|
+
quarterrange: vxeDateQ,
|
|
128
|
+
month: vxeDateM,
|
|
129
|
+
months: vxeDateM,
|
|
130
|
+
monthrange: vxeDateM,
|
|
131
|
+
week: vxeDateW,
|
|
132
|
+
datetime: vxeDateTime,
|
|
133
|
+
datetimerange: vxeDateTime,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const DATE_TOKEN_REGEXP = /YYYY|MM|DD|HH|mm|ss/g;
|
|
137
|
+
const REGEXP_SPECIAL_REGEXP = /[.*+?^${}()|[\]\\]/g;
|
|
138
|
+
|
|
139
|
+
function parseFormattedDate(value, inputFormat) {
|
|
140
|
+
if (typeof value !== "string" || typeof inputFormat !== "string" || inputFormat === "YYYY-wo") return value;
|
|
141
|
+
if (inputFormat === "x" || inputFormat === "X") {
|
|
142
|
+
const time = Number(value);
|
|
143
|
+
return Number.isFinite(time) ? new Date(inputFormat === "X" ? time * 1000 : time) : value;
|
|
144
|
+
}
|
|
145
|
+
const tokens = [];
|
|
146
|
+
const source = inputFormat
|
|
147
|
+
.replace(REGEXP_SPECIAL_REGEXP, "\\$&")
|
|
148
|
+
.replace(DATE_TOKEN_REGEXP, (token) => {
|
|
149
|
+
tokens.push(token);
|
|
150
|
+
return "\\d{1,4}";
|
|
151
|
+
});
|
|
152
|
+
const matched = new RegExp(`^${source}$`).exec(value);
|
|
153
|
+
if (!matched) return value;
|
|
154
|
+
const parts = { YYYY: 1970, MM: 1, DD: 1, HH: 0, mm: 0, ss: 0 };
|
|
155
|
+
tokens.forEach((token, index) => {
|
|
156
|
+
parts[token] = Number(matched[index + 1]);
|
|
157
|
+
});
|
|
158
|
+
const date = new Date(parts.YYYY, parts.MM - 1, parts.DD, parts.HH, parts.mm, parts.ss);
|
|
159
|
+
return isNaN(date.getTime()) ? value : date;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function createDatePickerFormatter(rule) {
|
|
163
|
+
const type = rule.props?.type ?? "date";
|
|
164
|
+
const formatDate = (value) => {
|
|
165
|
+
if (value === null || value === undefined || value === "") return "";
|
|
166
|
+
const date = parseFormattedDate(value, rule.props?.valueFormat);
|
|
167
|
+
if (rule.props?.format) return valueDate(date, rule.props.format);
|
|
168
|
+
const formatter = dateFormatters[type];
|
|
169
|
+
return formatter ? formatter({ cellValue: date }) : valueDate(date);
|
|
170
|
+
};
|
|
171
|
+
return ({ cellValue }) => {
|
|
172
|
+
if (!Array.isArray(cellValue)) return formatDate(cellValue);
|
|
173
|
+
if (cellValue.every((value) => value === null || value === undefined || value === "")) return "";
|
|
174
|
+
const separator = type.endsWith("range") ? (rule.props?.rangeSeparator ?? " - ") : "、";
|
|
175
|
+
return cellValue.map(formatDate).join(separator);
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function createTimePickerFormatter(rule) {
|
|
180
|
+
const formatTime = (value) => {
|
|
181
|
+
if (value === null || value === undefined || value === "") return "";
|
|
182
|
+
const time = parseFormattedDate(value, rule.props?.valueFormat ?? "HH:mm");
|
|
183
|
+
return valueDate(time, rule.props?.format ?? "HH:mm");
|
|
184
|
+
};
|
|
185
|
+
return ({ cellValue }) => {
|
|
186
|
+
if (!Array.isArray(cellValue)) return formatTime(cellValue);
|
|
187
|
+
if (cellValue.every((value) => value === null || value === undefined || value === "")) return "";
|
|
188
|
+
return cellValue.map(formatTime).join(rule.props?.rangeSeparator ?? " - ");
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const formatterFactories = new Map([
|
|
193
|
+
["radio", createChoiceFormatter],
|
|
194
|
+
["checkbox", createChoiceFormatter],
|
|
195
|
+
["switch", createSwitchFormatter],
|
|
196
|
+
["treeSelect", createTreeSelectFormatter],
|
|
197
|
+
["cascader", createCascaderFormatter],
|
|
198
|
+
["inputNumber", () => vxeNumber],
|
|
199
|
+
["inputCurrency", () => vxeCurrency],
|
|
200
|
+
["inputPercent", () => vxePercentByNumber],
|
|
201
|
+
["datePicker", createDatePickerFormatter],
|
|
202
|
+
["timePicker", createTimePickerFormatter],
|
|
203
|
+
]);
|
|
204
|
+
|
|
205
|
+
export function resolveRuleFormatter(rule) {
|
|
206
|
+
if (typeof rule.formatter === "function") return { ...rule, formatter: rule.formatter };
|
|
207
|
+
|
|
208
|
+
const factory = formatterFactories.get(rule.type ?? "");
|
|
209
|
+
let formatter;
|
|
210
|
+
if (factory) formatter = factory(rule);
|
|
211
|
+
else if (Array.isArray(rule.options) && rule.options.length > 0) formatter = createOptionsFormatter(rule);
|
|
212
|
+
|
|
213
|
+
return { ...rule, formatter };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function createOptionsFormatter(rule) {
|
|
217
|
+
return ({ cellValue }) => optionsFormatter(rule.options, cellValue);
|
|
218
|
+
}
|