@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,160 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { useCache } from "../../hooks/use-cache.js";
|
|
3
|
+
import { AbTableEnum, checkPermissionsOrRoles } from "./utils.js";
|
|
4
|
+
|
|
5
|
+
const clone = (value) => {
|
|
6
|
+
if (Array.isArray(value)) return value.map(clone);
|
|
7
|
+
if (value && typeof value === "object") {
|
|
8
|
+
const out = {};
|
|
9
|
+
Object.keys(value).forEach((key) => {
|
|
10
|
+
out[key] = clone(value[key]);
|
|
11
|
+
});
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const mergeClass = (...values) => {
|
|
18
|
+
const out = [];
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const push = (item) => {
|
|
21
|
+
if (!item) return;
|
|
22
|
+
if (typeof item === "string") {
|
|
23
|
+
if (seen.has(item)) return;
|
|
24
|
+
seen.add(item);
|
|
25
|
+
}
|
|
26
|
+
out.push(item);
|
|
27
|
+
};
|
|
28
|
+
values.forEach((value) => {
|
|
29
|
+
if (!value) return;
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
value.forEach(push);
|
|
32
|
+
} else {
|
|
33
|
+
push(value);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return out;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
name: "AbTableOperate",
|
|
41
|
+
inject: {
|
|
42
|
+
abTableRef: { default: () => ({}) },
|
|
43
|
+
abTableDetailRef: { default: () => ({}) },
|
|
44
|
+
},
|
|
45
|
+
props: {
|
|
46
|
+
rule: { type: [Object, Array], default: undefined },
|
|
47
|
+
modelValue: { type: Object, default: () => ({}) },
|
|
48
|
+
idField: String,
|
|
49
|
+
idFieldTable: String,
|
|
50
|
+
permiPrefix: String,
|
|
51
|
+
link: Boolean,
|
|
52
|
+
plain: Boolean,
|
|
53
|
+
deleteHandler: Function,
|
|
54
|
+
readonly: Boolean,
|
|
55
|
+
},
|
|
56
|
+
computed: {
|
|
57
|
+
formOption() {
|
|
58
|
+
const { getCurrentSize } = useCache();
|
|
59
|
+
const size = getCurrentSize();
|
|
60
|
+
return {
|
|
61
|
+
formData: this.value,
|
|
62
|
+
form: { size },
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
rules() {
|
|
66
|
+
if (!this.rule || (Array.isArray(this.rule) && !this.rule.length)) return undefined;
|
|
67
|
+
const base = Array.isArray(this.rule) ? { type: "ElRow", children: clone(this.rule), native: true } : { ...clone(this.rule), native: true };
|
|
68
|
+
delete base.field;
|
|
69
|
+
for (const button of base.children || []) {
|
|
70
|
+
button.props = this.buttonProps(button.props?.type || "primary", button);
|
|
71
|
+
if (button.field === AbTableEnum.CREATE) {
|
|
72
|
+
button.children = [{ type: "icon", props: { icon: "ep:plus" } }, "新增"];
|
|
73
|
+
button.props = this.buttonProps("primary", button);
|
|
74
|
+
if (!button.on?.click) button.on = { ...(button.on || {}), click: this.createHandler };
|
|
75
|
+
if (this.permiPrefix && !button.computed?.hidden) button.computed = { ...(button.computed || {}), hidden: this.createEnabled };
|
|
76
|
+
} else if (button.field === AbTableEnum.DETAIL) {
|
|
77
|
+
button.children = [{ type: "icon", props: { icon: "ep:view" } }, "详情"];
|
|
78
|
+
button.props = this.buttonProps("primary", button);
|
|
79
|
+
if (!button.on?.click) button.on = { ...(button.on || {}), click: this.detailHandler };
|
|
80
|
+
} else if (button.field === AbTableEnum.DEL) {
|
|
81
|
+
button.children = [{ type: "icon", props: { icon: "ep:delete" } }, "删除"];
|
|
82
|
+
button.props = this.buttonProps("danger", button);
|
|
83
|
+
if (!button.on?.click) button.on = { ...(button.on || {}), click: this.delHandler };
|
|
84
|
+
if (this.permiPrefix && !button.computed?.hidden) button.computed = { ...(button.computed || {}), hidden: this.deleteEnabled };
|
|
85
|
+
} else if (button.field === AbTableEnum.EXPORT) {
|
|
86
|
+
button.children = [{ type: "icon", props: { icon: "ep:download" } }, "导出"];
|
|
87
|
+
button.props = this.buttonProps("warning", button);
|
|
88
|
+
if (this.permiPrefix && !button.computed?.hidden) button.computed = { ...(button.computed || {}), hidden: this.exportEnabled };
|
|
89
|
+
}
|
|
90
|
+
button.native = true;
|
|
91
|
+
if (button.computed && button.computed.hidden !== undefined) {
|
|
92
|
+
button.hidden = typeof button.computed.hidden === "function" ? !!button.computed.hidden() : !!button.computed.hidden;
|
|
93
|
+
}
|
|
94
|
+
if (button.inject && button.on && typeof button.on.click === "function") {
|
|
95
|
+
const original = button.on.click;
|
|
96
|
+
const modelValue = this.modelValue;
|
|
97
|
+
button.on.click = ($inject) =>
|
|
98
|
+
original({
|
|
99
|
+
api: { getValue: (field) => (modelValue || {})[field] },
|
|
100
|
+
row: modelValue,
|
|
101
|
+
...($inject && typeof $inject === "object" ? $inject : {}),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return [base];
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
methods: {
|
|
109
|
+
buttonProps(semanticType, button) {
|
|
110
|
+
const props = { plain: this.plain, size: "mini" };
|
|
111
|
+
if (this.link) {
|
|
112
|
+
props.type = "text";
|
|
113
|
+
if (button) {
|
|
114
|
+
button.class = mergeClass(button.class, `${semanticType}`);
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
props.type = semanticType;
|
|
118
|
+
}
|
|
119
|
+
return props;
|
|
120
|
+
},
|
|
121
|
+
createEnabled() {
|
|
122
|
+
return !checkPermissionsOrRoles([`${this.permiPrefix}:create`], ["admin"]);
|
|
123
|
+
},
|
|
124
|
+
deleteEnabled() {
|
|
125
|
+
return !checkPermissionsOrRoles([`${this.permiPrefix}:delete`], ["admin"]);
|
|
126
|
+
},
|
|
127
|
+
exportEnabled() {
|
|
128
|
+
return !checkPermissionsOrRoles([`${this.permiPrefix}:export`], ["admin"]);
|
|
129
|
+
},
|
|
130
|
+
toggleDetail(readonly) {
|
|
131
|
+
const detail = this.abTableDetailRef && this.abTableDetailRef.value;
|
|
132
|
+
if (detail && typeof detail.toggle === "function") detail.toggle(true, this.modelValue, readonly);
|
|
133
|
+
},
|
|
134
|
+
createHandler() {
|
|
135
|
+
this.toggleDetail(false);
|
|
136
|
+
},
|
|
137
|
+
detailHandler() {
|
|
138
|
+
this.toggleDetail(this.readonly);
|
|
139
|
+
},
|
|
140
|
+
async delHandler() {
|
|
141
|
+
if (typeof this.deleteHandler === "function" && this.idField) {
|
|
142
|
+
await this.deleteHandler(this.modelValue[this.idField]);
|
|
143
|
+
}
|
|
144
|
+
const table = this.abTableRef && this.abTableRef.value;
|
|
145
|
+
if (table && typeof table.remove === "function") table.remove(this.modelValue);
|
|
146
|
+
this.$emit("refresh");
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
render(h) {
|
|
150
|
+
if (!this.rules) return h("span");
|
|
151
|
+
return h("ab-form", {
|
|
152
|
+
props: { rule: this.rules, value: this.modelValue, inline: true },
|
|
153
|
+
on: {
|
|
154
|
+
refresh: () => this.$emit("refresh"),
|
|
155
|
+
input: (api) => this.$emit("input", api),
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
</script>
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { prepareColumns, reconcileColumnStorage } from "./columns.js";
|
|
3
|
+
import { buildFooterSummary } from "./footer.js";
|
|
4
|
+
import { AbTableEnum, getHeaderRowCount, trans2VxeSize } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
const LINE_HEIGHTS = { mini: 36, small: 40, medium: 44, large: 48 };
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
name: "AbTable",
|
|
10
|
+
provide() {
|
|
11
|
+
return {
|
|
12
|
+
abTableRef: { value: this },
|
|
13
|
+
abTableDetailRef: { value: this },
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
props: {
|
|
17
|
+
id: { type: [String, Number], default: undefined },
|
|
18
|
+
title: String,
|
|
19
|
+
rule: { type: Array, default: () => [] },
|
|
20
|
+
queryHandler: Function,
|
|
21
|
+
query: { type: Object, default: () => ({}) },
|
|
22
|
+
pagerEnable: { type: Boolean, default: true },
|
|
23
|
+
pagerConfig: { type: Object, default: () => ({}) },
|
|
24
|
+
locale: { type: String, default: "zh-cn" },
|
|
25
|
+
idField: { type: String, default: "id" },
|
|
26
|
+
idFieldTable: String,
|
|
27
|
+
permiPrefix: String,
|
|
28
|
+
compactMode: Boolean,
|
|
29
|
+
parentIdField: String,
|
|
30
|
+
accordion: Boolean,
|
|
31
|
+
hasChildField: { type: String, default: "hasChildren" },
|
|
32
|
+
lazyMethod: Function,
|
|
33
|
+
isCurrent: Boolean,
|
|
34
|
+
dragable: Boolean,
|
|
35
|
+
absDragable: Boolean,
|
|
36
|
+
rowClassName: Function,
|
|
37
|
+
headerCellClassName: Function,
|
|
38
|
+
cellClassName: Function,
|
|
39
|
+
rowStyle: [String, Object, Function],
|
|
40
|
+
editable: Boolean,
|
|
41
|
+
singleSelect: Boolean,
|
|
42
|
+
multiSelect: Boolean,
|
|
43
|
+
validRules: Object,
|
|
44
|
+
sortable: { type: Boolean, default: true },
|
|
45
|
+
sortLocally: Boolean,
|
|
46
|
+
footerSummary: Object,
|
|
47
|
+
maxHeight: Number,
|
|
48
|
+
offsetTop: Number,
|
|
49
|
+
autoHeight: Boolean,
|
|
50
|
+
readonly: { type: Boolean, default: true },
|
|
51
|
+
size: { type: String, default: "default" },
|
|
52
|
+
},
|
|
53
|
+
data() {
|
|
54
|
+
return {
|
|
55
|
+
currentValue: [],
|
|
56
|
+
loading: false,
|
|
57
|
+
pageNo: 1,
|
|
58
|
+
pageSize: 10,
|
|
59
|
+
currentPageSizes: [10, 15, 20, 50, 100],
|
|
60
|
+
total: 0,
|
|
61
|
+
sortFieldTable: "",
|
|
62
|
+
sortField: "",
|
|
63
|
+
sortType: "",
|
|
64
|
+
maxH: this.maxHeight || 0,
|
|
65
|
+
requestVersion: 0,
|
|
66
|
+
sortParams: undefined,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
computed: {
|
|
70
|
+
currentRule() {
|
|
71
|
+
return prepareColumns(this.rule, this.idFieldTable);
|
|
72
|
+
},
|
|
73
|
+
tableId() {
|
|
74
|
+
return this.id || `ab-table-${this._uid}`;
|
|
75
|
+
},
|
|
76
|
+
vxeCurrentSize() {
|
|
77
|
+
return trans2VxeSize(this.size);
|
|
78
|
+
},
|
|
79
|
+
pagerFields() {
|
|
80
|
+
return {
|
|
81
|
+
pageNo: this.pagerConfig.pageNoField ?? "pageNo",
|
|
82
|
+
pageSize: this.pagerConfig.pageSizeField ?? "pageSize",
|
|
83
|
+
sortFieldTable: this.pagerConfig.sortFieldTableField ?? "sortFieldTable",
|
|
84
|
+
sortField: this.pagerConfig.sortFieldField ?? "sortField",
|
|
85
|
+
sortType: this.pagerConfig.sortTypeField ?? "sortType",
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
sortConfig() {
|
|
89
|
+
return { trigger: "cell", remote: !this.sortLocally };
|
|
90
|
+
},
|
|
91
|
+
currentFooterData() {
|
|
92
|
+
if (!this.footerSummary) return [];
|
|
93
|
+
const table = this.$refs.table;
|
|
94
|
+
const getColumn = (field) => (table && table.getColumnByField ? table.getColumnByField(field) : undefined);
|
|
95
|
+
return [buildFooterSummary(this.footerSummary, this.currentValue, this.currentRule, "合计", getColumn)];
|
|
96
|
+
},
|
|
97
|
+
currentReadonly() {
|
|
98
|
+
return !(!this.readonly || this.multiSelect || this.singleSelect);
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
watch: {
|
|
102
|
+
query: {
|
|
103
|
+
handler() {
|
|
104
|
+
this.reload();
|
|
105
|
+
},
|
|
106
|
+
deep: true,
|
|
107
|
+
},
|
|
108
|
+
vxeCurrentSize: {
|
|
109
|
+
handler() {
|
|
110
|
+
this.$nextTick(() => this.calculateTableHeight());
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
compactMode: {
|
|
114
|
+
handler() {
|
|
115
|
+
this.$nextTick(() => this.calculateTableHeight());
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
created() {
|
|
120
|
+
this.initializePager();
|
|
121
|
+
},
|
|
122
|
+
mounted() {
|
|
123
|
+
this.calculateTableHeight();
|
|
124
|
+
this.init();
|
|
125
|
+
},
|
|
126
|
+
methods: {
|
|
127
|
+
initializePager() {
|
|
128
|
+
const fields = this.pagerFields;
|
|
129
|
+
this.pageNo = Number(this.query[fields.pageNo] ?? 1);
|
|
130
|
+
this.pageSize = Number(this.query[fields.pageSize] ?? 10);
|
|
131
|
+
this.sortFieldTable = this.query[fields.sortFieldTable] ?? "";
|
|
132
|
+
this.sortField = this.query[fields.sortField] ?? "";
|
|
133
|
+
this.sortType = this.query[fields.sortType] ?? "";
|
|
134
|
+
},
|
|
135
|
+
calculateTableHeight() {
|
|
136
|
+
if (!this.autoHeight) {
|
|
137
|
+
this.maxH = this.maxHeight || 0;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const table = this.$refs.table;
|
|
141
|
+
const lh = table?.cellConfig?.height || LINE_HEIGHTS[this.vxeCurrentSize] || LINE_HEIGHTS.medium;
|
|
142
|
+
const parent = this.$el && this.$el.parentElement;
|
|
143
|
+
const barH = parent?.querySelector(".ab-toolbar")?.getBoundingClientRect().height || 0;
|
|
144
|
+
const pagerEl = this.$refs.pager && this.$refs.pager.$el;
|
|
145
|
+
const pagerH = pagerEl?.getBoundingClientRect().height || 0;
|
|
146
|
+
const headerH = getHeaderRowCount(this.rule) * lh;
|
|
147
|
+
const ph = (parent?.getBoundingClientRect().height || 500) - barH - pagerH;
|
|
148
|
+
this.maxH = this.offsetTop ? Math.max(ph, window.innerHeight - this.offsetTop) : ph;
|
|
149
|
+
if (this.maxH <= 0) return;
|
|
150
|
+
let lines = Math.min(Math.max(Math.round((this.maxH - headerH - lh * 1.5) / lh), 10), 100);
|
|
151
|
+
if (this.footerSummary) lines -= 1;
|
|
152
|
+
if (!this.currentPageSizes.includes(lines)) {
|
|
153
|
+
this.currentPageSizes = [...this.currentPageSizes, lines].sort((a, b) => a - b);
|
|
154
|
+
}
|
|
155
|
+
this.pageSize = lines;
|
|
156
|
+
},
|
|
157
|
+
async init() {
|
|
158
|
+
if (typeof this.queryHandler !== "function") return;
|
|
159
|
+
const version = ++this.requestVersion;
|
|
160
|
+
this.loading = true;
|
|
161
|
+
try {
|
|
162
|
+
const fields = this.pagerFields;
|
|
163
|
+
const request = {
|
|
164
|
+
...this.query,
|
|
165
|
+
[fields.pageNo]: this.pageNo,
|
|
166
|
+
[fields.pageSize]: this.pageSize,
|
|
167
|
+
[fields.sortFieldTable]: this.sortFieldTable,
|
|
168
|
+
[fields.sortField]: this.sortField,
|
|
169
|
+
[fields.sortType]: this.sortType,
|
|
170
|
+
};
|
|
171
|
+
const response = await this.queryHandler(request);
|
|
172
|
+
if (version !== this.requestVersion) return;
|
|
173
|
+
const data = Array.isArray(response) ? response : response?.data ?? response?.list;
|
|
174
|
+
if (!Array.isArray(data)) throw new TypeError("AbTable queryHandler must return an array or an object containing a data or list array.");
|
|
175
|
+
this.currentValue = data;
|
|
176
|
+
this.total = Array.isArray(response) ? response.length : response.total ?? data.length;
|
|
177
|
+
} finally {
|
|
178
|
+
if (version === this.requestVersion) this.loading = false;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
async reload() {
|
|
182
|
+
this.pageNo = 1;
|
|
183
|
+
await this.init();
|
|
184
|
+
},
|
|
185
|
+
async refresh() {
|
|
186
|
+
await this.init();
|
|
187
|
+
},
|
|
188
|
+
resize() {
|
|
189
|
+
this.calculateTableHeight();
|
|
190
|
+
},
|
|
191
|
+
remove(row) {
|
|
192
|
+
const index = this.currentValue.indexOf(row);
|
|
193
|
+
if (index >= 0) this.currentValue.splice(index, 1);
|
|
194
|
+
this.total = Math.max(0, this.total - 1);
|
|
195
|
+
},
|
|
196
|
+
async exportData(filename) {
|
|
197
|
+
const table = this.$refs.table;
|
|
198
|
+
if (!table || typeof table.exportData !== "function") return;
|
|
199
|
+
await table.exportData({
|
|
200
|
+
filename: filename || this.title,
|
|
201
|
+
columns: this.currentRule.filter((rule) => rule.field && rule.field !== AbTableEnum.OPERATE && !rule.hidden),
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
handlePageChange({ currentPage, pageSize: size }) {
|
|
205
|
+
this.pageNo = currentPage;
|
|
206
|
+
this.pageSize = size;
|
|
207
|
+
this.init();
|
|
208
|
+
},
|
|
209
|
+
handleSortChanged({ field, order, column }) {
|
|
210
|
+
if (!order) {
|
|
211
|
+
this.sortFieldTable = this.idFieldTable ?? "";
|
|
212
|
+
this.sortField = this.idField || "id";
|
|
213
|
+
this.sortType = "desc";
|
|
214
|
+
} else {
|
|
215
|
+
this.sortFieldTable = column?.params?.sortFieldTable ?? this.idFieldTable ?? "";
|
|
216
|
+
this.sortField = (column?.params?.sortField || field).replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`);
|
|
217
|
+
this.sortType = order;
|
|
218
|
+
}
|
|
219
|
+
this.refresh();
|
|
220
|
+
},
|
|
221
|
+
handleCellClick({ row, column }) {
|
|
222
|
+
if (column?.field === AbTableEnum.OPERATE) return;
|
|
223
|
+
const table = this.$refs.table;
|
|
224
|
+
if (!this.editable || this.currentReadonly) table?.clearCheckboxRow?.();
|
|
225
|
+
else table?.setCheckboxRow?.(row, true);
|
|
226
|
+
this.$emit("cellClick", { row, column });
|
|
227
|
+
},
|
|
228
|
+
columnProps(rule, index) {
|
|
229
|
+
return {
|
|
230
|
+
rule,
|
|
231
|
+
idx: index,
|
|
232
|
+
idField: this.idField,
|
|
233
|
+
idFieldTable: this.idFieldTable,
|
|
234
|
+
permiPrefix: this.permiPrefix,
|
|
235
|
+
sortable: this.sortable,
|
|
236
|
+
deleteHandler: this.deleteHandler,
|
|
237
|
+
readonly: this.readonly,
|
|
238
|
+
};
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
render(h) {
|
|
242
|
+
const tableProps = {
|
|
243
|
+
id: this.tableId,
|
|
244
|
+
data: this.currentValue,
|
|
245
|
+
stripe: !this.parentIdField,
|
|
246
|
+
border: true,
|
|
247
|
+
size: this.vxeCurrentSize,
|
|
248
|
+
loading: this.loading,
|
|
249
|
+
showOverflow: true,
|
|
250
|
+
showHeaderOverflow: true,
|
|
251
|
+
showFooterOverflow: true,
|
|
252
|
+
autoResize: true,
|
|
253
|
+
sortConfig: this.sortConfig,
|
|
254
|
+
showFooter: !!this.footerSummary,
|
|
255
|
+
footerData: this.currentFooterData,
|
|
256
|
+
cellClassName: this.cellClassName,
|
|
257
|
+
headerCellClassName: this.headerCellClassName,
|
|
258
|
+
rowClassName: this.rowClassName,
|
|
259
|
+
rowStyle: this.rowStyle,
|
|
260
|
+
customConfig: {
|
|
261
|
+
immediate: true,
|
|
262
|
+
storage: true,
|
|
263
|
+
restoreStore: (params = {}) => {
|
|
264
|
+
const storeData = params.storeData;
|
|
265
|
+
const table = params.$table || this.$refs.table;
|
|
266
|
+
if (!storeData || !table || typeof table.getFullColumns !== "function") return storeData;
|
|
267
|
+
return reconcileColumnStorage(storeData, table.getFullColumns());
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
if (this.maxH) tableProps.maxHeight = this.maxH;
|
|
272
|
+
if (this.compactMode) tableProps.cellConfig = { padding: false, height: 30 };
|
|
273
|
+
|
|
274
|
+
const columns = this.currentRule.map((rule, index) =>
|
|
275
|
+
h("ab-table-columns", {
|
|
276
|
+
props: this.columnProps(rule, index),
|
|
277
|
+
on: { refresh: this.refresh },
|
|
278
|
+
key: rule.field || index,
|
|
279
|
+
})
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const children = [
|
|
283
|
+
h(
|
|
284
|
+
"vxe-table",
|
|
285
|
+
{
|
|
286
|
+
props: tableProps,
|
|
287
|
+
ref: "table",
|
|
288
|
+
on: {
|
|
289
|
+
"sort-change": this.handleSortChanged,
|
|
290
|
+
"cell-click": this.handleCellClick,
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
columns
|
|
294
|
+
),
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
if (this.pagerEnable) {
|
|
298
|
+
const pagerProps = {
|
|
299
|
+
currentPage: this.pageNo,
|
|
300
|
+
pageSize: this.pageSize,
|
|
301
|
+
pageSizes: this.currentPageSizes,
|
|
302
|
+
total: this.total,
|
|
303
|
+
};
|
|
304
|
+
if (this.pagerConfig.layouts) pagerProps.layouts = this.pagerConfig.layouts;
|
|
305
|
+
children.push(
|
|
306
|
+
h("vxe-pager", {
|
|
307
|
+
props: pagerProps,
|
|
308
|
+
ref: "pager",
|
|
309
|
+
on: { "page-change": this.handlePageChange },
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return h("div", { class: "ab-table" }, children);
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
</script>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { applyRuleDefaults } from '../../rule/defaults.js';
|
|
2
|
+
|
|
3
|
+
export function prepareColumns(columns, idFieldTable, scope = []) {
|
|
4
|
+
const prepared = columns
|
|
5
|
+
.filter((column) => column.field || column.expand || column.children?.length)
|
|
6
|
+
.filter((column) => column.tableVisible !== false)
|
|
7
|
+
.map((column, index) => {
|
|
8
|
+
const result = applyRuleDefaults({ ...column }, { includeChildren: false });
|
|
9
|
+
if (result.children && result.field !== 'OPERATE') {
|
|
10
|
+
result.children = prepareColumns(result.children, idFieldTable, [...scope, column.field ? `field:${column.field}` : `index:${index}`]);
|
|
11
|
+
}
|
|
12
|
+
if (result.field !== 'operate' && !result.children?.length) {
|
|
13
|
+
if (result.sortFieldTable === undefined && idFieldTable) result.sortFieldTable = idFieldTable;
|
|
14
|
+
if (result.width === undefined && result.minWidth === undefined) result.width = 120;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
});
|
|
18
|
+
return groupColumns(prepared, scope);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function groupColumns(columns, scope = []) {
|
|
22
|
+
const output = [];
|
|
23
|
+
const groups = new Map();
|
|
24
|
+
for (const column of columns) {
|
|
25
|
+
const names = typeof column.group === 'string' ? (column.group ? [column.group] : []) : column.group ?? [];
|
|
26
|
+
if (!Array.isArray(names) || names.some((name) => typeof name !== 'string' || !name.trim())) {
|
|
27
|
+
throw new TypeError('Table column group must be a non-empty name or an array of non-empty names.');
|
|
28
|
+
}
|
|
29
|
+
if (!names.length) {
|
|
30
|
+
output.push(column);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
let siblings = output;
|
|
34
|
+
const path = [];
|
|
35
|
+
let parent;
|
|
36
|
+
for (const name of names) {
|
|
37
|
+
path.push(name);
|
|
38
|
+
const key = JSON.stringify(path);
|
|
39
|
+
let group = groups.get(key);
|
|
40
|
+
if (!group) {
|
|
41
|
+
group = { field: `__ab_table_group__${encodeURIComponent(JSON.stringify([scope, path]))}`, title: name, children: [] };
|
|
42
|
+
groups.set(key, group);
|
|
43
|
+
siblings.push(group);
|
|
44
|
+
}
|
|
45
|
+
parent = group;
|
|
46
|
+
siblings = group.children;
|
|
47
|
+
}
|
|
48
|
+
if (parent && column.groupAlign !== undefined) parent.groupAlign = column.groupAlign;
|
|
49
|
+
siblings.push(column);
|
|
50
|
+
}
|
|
51
|
+
return output;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function reconcileColumnStorage(storeData, columns) {
|
|
55
|
+
const sortData = storeData.sortData;
|
|
56
|
+
if (!sortData) return storeData;
|
|
57
|
+
const parents = new Map();
|
|
58
|
+
const initiallyHidden = new Set();
|
|
59
|
+
function collect(items, parent) {
|
|
60
|
+
for (const column of items) {
|
|
61
|
+
const key = column.getKey ? column.getKey() : column.field;
|
|
62
|
+
if (!key) continue;
|
|
63
|
+
parents.set(key, parent);
|
|
64
|
+
if (column.defaultVisible === false) initiallyHidden.add(key);
|
|
65
|
+
if (column.children?.length) collect(column.children, key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
collect(columns, null);
|
|
69
|
+
const seen = new Set();
|
|
70
|
+
function hasIncompatibleOrder(items, parent) {
|
|
71
|
+
return items.some((item) => {
|
|
72
|
+
if (!item || typeof item.k !== 'string' || (item.c !== undefined && !Array.isArray(item.c))) return true;
|
|
73
|
+
const { k, c } = item;
|
|
74
|
+
if (seen.has(k) || (parents.has(k) && parents.get(k) !== parent)) return true;
|
|
75
|
+
seen.add(k);
|
|
76
|
+
return c ? hasIncompatibleOrder(c, k) : false;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const incompatible = Array.isArray(sortData)
|
|
80
|
+
? hasIncompatibleOrder(sortData, null)
|
|
81
|
+
: typeof sortData !== 'object' || Object.keys(sortData).some((key) => parents.has(key) && parents.get(key) !== null);
|
|
82
|
+
if (!incompatible) return storeData;
|
|
83
|
+
const visibleData = storeData.visibleData && { ...storeData.visibleData };
|
|
84
|
+
if (visibleData) {
|
|
85
|
+
for (const key of initiallyHidden) {
|
|
86
|
+
if (visibleData[key] === true) delete visibleData[key];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { ...storeData, sortData: undefined, visibleData };
|
|
90
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { resolveRuleFormatter } from '../../rule/formatter.js';
|
|
2
|
+
|
|
3
|
+
function findFooterColumn(rules, field) {
|
|
4
|
+
for (const rule of rules) {
|
|
5
|
+
if (rule.field === field) return rule;
|
|
6
|
+
if (rule.children) {
|
|
7
|
+
const child = findFooterColumn(rule.children, field);
|
|
8
|
+
if (child) return child;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function formatFooterCell(value, row, rule, column) {
|
|
15
|
+
if (!rule) return value;
|
|
16
|
+
const formatter = rule.footerFormatter || resolveRuleFormatter(rule).formatter;
|
|
17
|
+
return formatter ? formatter({ cellValue: value, row, column: column || rule }) : value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function buildFooterSummary(summary, rows, rules, defaultLabel, getColumn) {
|
|
21
|
+
if (typeof summary.labelField !== 'string' || !summary.labelField.trim() || !Array.isArray(summary.fields)) {
|
|
22
|
+
throw new TypeError('AbTable footerSummary requires a labelField and a fields array.');
|
|
23
|
+
}
|
|
24
|
+
const blocked = ['__proto__', 'constructor', 'prototype'];
|
|
25
|
+
const used = new Set([summary.labelField]);
|
|
26
|
+
const sums = [];
|
|
27
|
+
const callbacks = [];
|
|
28
|
+
const addField = (field) => {
|
|
29
|
+
if (!field.trim() || used.has(field) || blocked.includes(field)) {
|
|
30
|
+
throw new TypeError(`AbTable footerSummary has an invalid or duplicate field: "${field}".`);
|
|
31
|
+
}
|
|
32
|
+
used.add(field);
|
|
33
|
+
};
|
|
34
|
+
if (blocked.includes(summary.labelField)) throw new TypeError('AbTable footerSummary has an invalid labelField.');
|
|
35
|
+
for (const entry of summary.fields) {
|
|
36
|
+
if (typeof entry === 'string') {
|
|
37
|
+
addField(entry);
|
|
38
|
+
sums.push(entry);
|
|
39
|
+
} else {
|
|
40
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry) || !Object.keys(entry).length) {
|
|
41
|
+
throw new TypeError('AbTable footerSummary fields must be field names or objects of callbacks.');
|
|
42
|
+
}
|
|
43
|
+
for (const [field, handler] of Object.entries(entry)) {
|
|
44
|
+
addField(field);
|
|
45
|
+
if (typeof handler !== 'function') throw new TypeError(`AbTable footerSummary handler for "${field}" must be a function.`);
|
|
46
|
+
callbacks.push([field, handler]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const totals = {};
|
|
51
|
+
for (const field of sums) {
|
|
52
|
+
let total = null;
|
|
53
|
+
for (const row of rows) {
|
|
54
|
+
const value = row[field];
|
|
55
|
+
if (value == null || (typeof value === 'string' && !value.trim())) continue;
|
|
56
|
+
if ((typeof value !== 'number' && typeof value !== 'string') || !Number.isFinite(Number(value))) {
|
|
57
|
+
throw new TypeError(`AbTable footerSummary field "${field}" must contain numbers or numeric strings.`);
|
|
58
|
+
}
|
|
59
|
+
total = (total ?? 0) + Number(value);
|
|
60
|
+
if (!Number.isFinite(total)) throw new RangeError(`AbTable footerSummary total for "${field}" is not finite.`);
|
|
61
|
+
}
|
|
62
|
+
totals[field] = total;
|
|
63
|
+
}
|
|
64
|
+
for (const [field, handler] of callbacks) {
|
|
65
|
+
const value = rows.length ? handler({ rows, totals: Object.freeze({ ...totals }) }) : null;
|
|
66
|
+
if (value !== null && (typeof value !== 'number' || !Number.isFinite(value))) {
|
|
67
|
+
throw new TypeError(`AbTable footerSummary handler for "${field}" must return a finite number or null.`);
|
|
68
|
+
}
|
|
69
|
+
totals[field] = value;
|
|
70
|
+
}
|
|
71
|
+
const rawRow = { [summary.labelField]: summary.label ?? defaultLabel, ...totals };
|
|
72
|
+
const result = { ...rawRow };
|
|
73
|
+
for (const [field, value] of Object.entries(totals)) {
|
|
74
|
+
result[field] = value === null ? '-' : formatFooterCell(value, rawRow, findFooterColumn(rules, field), getColumn(field));
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as AbTable } from './ab-table.vue';
|
|
2
|
+
export { default as AbTableColumns } from './ab-table-columns.vue';
|
|
3
|
+
export { default as AbTableColumn } from './ab-table-column.vue';
|
|
4
|
+
export { default as AbTableOperate } from './ab-table-operate.vue';
|
|
5
|
+
export * from './utils.js';
|
|
6
|
+
export * from './columns.js';
|
|
7
|
+
export * from './footer.js';
|
|
8
|
+
export * from './formatter.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const AbTableEnum = {
|
|
2
|
+
DETAIL: "detail",
|
|
3
|
+
DEL: "del",
|
|
4
|
+
ADD: "add",
|
|
5
|
+
EDIT: "edit",
|
|
6
|
+
SAVE: "save",
|
|
7
|
+
CREATE: "create",
|
|
8
|
+
READ: "read",
|
|
9
|
+
UPDATE: "update",
|
|
10
|
+
EXPORT: "export",
|
|
11
|
+
OPERATE: "OPERATE",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function checkPermissionsOrRoles(permissions, roles) {
|
|
15
|
+
if (!permissions?.length && !roles?.length) return true;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function castArray(value) {
|
|
20
|
+
if (value === undefined || value === null) return [];
|
|
21
|
+
return Array.isArray(value) ? value : [value];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function trans2VxeSize(size = "default") {
|
|
25
|
+
if (size === "large") return "medium";
|
|
26
|
+
if (size === "default") return "small";
|
|
27
|
+
return "mini";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getHeaderRowCount(rule) {
|
|
31
|
+
let maxDepth = 0;
|
|
32
|
+
for (const item of rule) {
|
|
33
|
+
if (item.group) maxDepth = Math.max(maxDepth, castArray(item.group).length);
|
|
34
|
+
}
|
|
35
|
+
return maxDepth + 1;
|
|
36
|
+
}
|