@qin-ui/antd-vue-pro 2.0.16 → 2.0.19
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/es/antd-vue-pro.css +13 -13
- package/es/component-provider/index.js +151 -3
- package/es/core/index-BrBzu6aj.js +362 -0
- package/es/form/index.js +28 -243
- package/es/index.d.ts +60 -180
- package/es/index.js +9 -7
- package/es/table/index.js +63 -189
- package/package.json +3 -2
- package/es/component-provider/index-D8NF18a1.js +0 -163
package/es/antd-vue-pro.css
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
.pro-table_search-form[data-v-
|
|
1
|
+
.pro-table_search-form[data-v-41da0f82] .ant-form-item {
|
|
2
2
|
margin: 0;
|
|
3
3
|
}
|
|
4
|
-
.pro-table_search-form_expand-toggle-button[data-v-
|
|
4
|
+
.pro-table_search-form_expand-toggle-button[data-v-41da0f82] {
|
|
5
5
|
display: flex;
|
|
6
6
|
align-items: center;
|
|
7
7
|
padding: 0;
|
|
8
8
|
padding-left: 4px;
|
|
9
9
|
}
|
|
10
|
-
.pro-table_search-form .transition[data-v-
|
|
10
|
+
.pro-table_search-form .transition[data-v-41da0f82] {
|
|
11
11
|
transition: all 0.25s;
|
|
12
12
|
}
|
|
13
13
|
.pro-table_search-form-container[data-v-c385cd54] {
|
|
@@ -18,41 +18,41 @@
|
|
|
18
18
|
flex: 1;
|
|
19
19
|
padding: 24px 24px 0;
|
|
20
20
|
}
|
|
21
|
-
.pro-table_size-control_button[data-v-
|
|
21
|
+
.pro-table_size-control_button[data-v-db17998d] {
|
|
22
22
|
display: flex;
|
|
23
23
|
align-items: center;
|
|
24
24
|
padding-right: 12px;
|
|
25
25
|
padding-left: 12px;
|
|
26
26
|
}
|
|
27
|
-
.pro-table_size-control_button[data-v-
|
|
27
|
+
.pro-table_size-control_button[data-v-db17998d] svg {
|
|
28
28
|
transform: scale(1.3);
|
|
29
29
|
}
|
|
30
|
-
.pro-table_column-control_button[data-v-
|
|
30
|
+
.pro-table_column-control_button[data-v-d503f78a] {
|
|
31
31
|
display: flex;
|
|
32
32
|
align-items: center;
|
|
33
33
|
padding-right: 12px;
|
|
34
34
|
padding-left: 12px;
|
|
35
35
|
}
|
|
36
|
-
.pro-table_column-control_button[data-v-
|
|
36
|
+
.pro-table_column-control_button[data-v-d503f78a] svg {
|
|
37
37
|
transform: scale(1.2, 1.4);
|
|
38
38
|
}
|
|
39
|
-
.pro-table_header[data-v-
|
|
39
|
+
.pro-table_header[data-v-291baca6] {
|
|
40
40
|
display: flex;
|
|
41
41
|
align-items: center;
|
|
42
42
|
justify-content: flex-end;
|
|
43
43
|
}
|
|
44
|
-
.pro-table_header[data-v-
|
|
44
|
+
.pro-table_header[data-v-291baca6]:empty {
|
|
45
45
|
display: none;
|
|
46
46
|
}
|
|
47
|
-
.pro-table_header + .pro-table_header_content[data-v-
|
|
47
|
+
.pro-table_header + .pro-table_header_content[data-v-291baca6] {
|
|
48
48
|
margin-top: 16px;
|
|
49
49
|
}
|
|
50
|
-
.pro-table_header_button-bar[data-v-
|
|
50
|
+
.pro-table_header_button-bar[data-v-291baca6] {
|
|
51
51
|
flex: 1;
|
|
52
52
|
}
|
|
53
|
-
.pro-table_header_toolbar[data-v-
|
|
53
|
+
.pro-table_header_toolbar[data-v-291baca6] {
|
|
54
54
|
margin-left: 12px;
|
|
55
55
|
}
|
|
56
|
-
.pro-table[data-v-
|
|
56
|
+
.pro-table[data-v-291baca6] .ant-pagination .ant-pagination-total-text {
|
|
57
57
|
flex: 1;
|
|
58
58
|
}
|
|
@@ -1,5 +1,153 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineComponent, provide, renderSlot } from "vue";
|
|
2
|
+
import { g as getObject } from "../core/index-BrBzu6aj.js";
|
|
3
|
+
const getPopupContainer = (triggerNode) => triggerNode.closest(".ant-form");
|
|
4
|
+
const INJECT_CONFIG = {
|
|
5
|
+
"pro-table": {
|
|
6
|
+
injectionKey: Symbol(""),
|
|
7
|
+
default: {
|
|
8
|
+
pagination: {
|
|
9
|
+
showTotal: (total) => `共 ${total} 条`,
|
|
10
|
+
showSizeChanger: true,
|
|
11
|
+
pageSizeOptions: ["10", "20", "30", "40", "50", "100"],
|
|
12
|
+
showQuickJumper: true
|
|
13
|
+
},
|
|
14
|
+
searchFormConfig: {
|
|
15
|
+
layout: "grid",
|
|
16
|
+
expand: { minExpandRows: 2, expandStatus: false }
|
|
17
|
+
},
|
|
18
|
+
control: true,
|
|
19
|
+
addIndexColumn: true
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"pro-form": {
|
|
23
|
+
injectionKey: Symbol(""),
|
|
24
|
+
default: { grid: { gutter: { xs: 8, sm: 16, md: 16, lg: 24 } } }
|
|
25
|
+
},
|
|
26
|
+
"pro-form-item": {
|
|
27
|
+
injectionKey: Symbol(""),
|
|
28
|
+
default: { validateFirst: true, span: 8 }
|
|
29
|
+
},
|
|
30
|
+
// field
|
|
31
|
+
input: {
|
|
32
|
+
injectionKey: Symbol(""),
|
|
33
|
+
default: { maxlength: 100, allowClear: true, placeholder: "请输入" }
|
|
34
|
+
},
|
|
35
|
+
textarea: {
|
|
36
|
+
injectionKey: Symbol(""),
|
|
37
|
+
default: {
|
|
38
|
+
maxlength: 200,
|
|
39
|
+
autoSize: { minRows: 3, maxRows: 6 },
|
|
40
|
+
showCount: true,
|
|
41
|
+
allowClear: true,
|
|
42
|
+
placeholder: "请输入"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"input-password": {
|
|
46
|
+
injectionKey: Symbol(""),
|
|
47
|
+
default: { maxlength: 100, allowClear: true, placeholder: "请输入" }
|
|
48
|
+
},
|
|
49
|
+
"input-search": {
|
|
50
|
+
injectionKey: Symbol(""),
|
|
51
|
+
default: {}
|
|
52
|
+
},
|
|
53
|
+
"input-number": {
|
|
54
|
+
injectionKey: Symbol(""),
|
|
55
|
+
default: {
|
|
56
|
+
max: 10 ** 15 - 1,
|
|
57
|
+
min: -1000000000000001,
|
|
58
|
+
controls: false,
|
|
59
|
+
placeholder: "请输入",
|
|
60
|
+
style: { width: "100%" }
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
select: {
|
|
64
|
+
injectionKey: Symbol(""),
|
|
65
|
+
default: { allowClear: true, placeholder: "请选择", getPopupContainer }
|
|
66
|
+
},
|
|
67
|
+
cascader: {
|
|
68
|
+
injectionKey: Symbol(""),
|
|
69
|
+
default: { allowClear: true, placeholder: "请选择", getPopupContainer }
|
|
70
|
+
},
|
|
71
|
+
"date-picker": {
|
|
72
|
+
injectionKey: Symbol(""),
|
|
73
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
74
|
+
},
|
|
75
|
+
"date-picker.date": {
|
|
76
|
+
injectionKey: Symbol(""),
|
|
77
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
78
|
+
},
|
|
79
|
+
"date-picker.week": {
|
|
80
|
+
injectionKey: Symbol(""),
|
|
81
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
82
|
+
},
|
|
83
|
+
"date-picker.month": {
|
|
84
|
+
injectionKey: Symbol(""),
|
|
85
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
86
|
+
},
|
|
87
|
+
"date-picker.year": {
|
|
88
|
+
injectionKey: Symbol(""),
|
|
89
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
90
|
+
},
|
|
91
|
+
"date-picker.quarter": {
|
|
92
|
+
injectionKey: Symbol(""),
|
|
93
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
94
|
+
},
|
|
95
|
+
"range-picker": {
|
|
96
|
+
injectionKey: Symbol(""),
|
|
97
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
98
|
+
},
|
|
99
|
+
"time-picker": {
|
|
100
|
+
injectionKey: Symbol(""),
|
|
101
|
+
default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
|
|
102
|
+
},
|
|
103
|
+
"checkbox-group": {
|
|
104
|
+
injectionKey: Symbol(""),
|
|
105
|
+
default: {}
|
|
106
|
+
},
|
|
107
|
+
"radio-group": {
|
|
108
|
+
injectionKey: Symbol(""),
|
|
109
|
+
default: {}
|
|
110
|
+
},
|
|
111
|
+
switch: {
|
|
112
|
+
injectionKey: Symbol(""),
|
|
113
|
+
default: { modelName: "checked" }
|
|
114
|
+
},
|
|
115
|
+
slider: {
|
|
116
|
+
injectionKey: Symbol(""),
|
|
117
|
+
default: {}
|
|
118
|
+
},
|
|
119
|
+
"tree-select": {
|
|
120
|
+
injectionKey: Symbol(""),
|
|
121
|
+
default: {}
|
|
122
|
+
},
|
|
123
|
+
transfer: {
|
|
124
|
+
injectionKey: Symbol(""),
|
|
125
|
+
default: {}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
129
|
+
...{
|
|
130
|
+
inheritAttrs: false
|
|
131
|
+
},
|
|
132
|
+
__name: "index",
|
|
133
|
+
props: {
|
|
134
|
+
componentVars: {}
|
|
135
|
+
},
|
|
136
|
+
setup(__props) {
|
|
137
|
+
const props = __props;
|
|
138
|
+
if (props.componentVars) {
|
|
139
|
+
Object.entries(props.componentVars).forEach(([key, val]) => {
|
|
140
|
+
const config = INJECT_CONFIG[key];
|
|
141
|
+
if (!config) return;
|
|
142
|
+
provide(config.injectionKey, { ...config.default, ...getObject(val) });
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return (_ctx, _cache) => {
|
|
146
|
+
return renderSlot(_ctx.$slots, "default");
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
});
|
|
2
150
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
151
|
+
INJECT_CONFIG,
|
|
152
|
+
_sfc_main as default
|
|
5
153
|
};
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { inject, camelize, reactive, provide, ref, toValue } from "vue";
|
|
2
|
+
import { i as isPlainObject, c as cloneDeep, s as set, g as get, p as pick, t as toPath } from "../vendor/utils/lodash-es-p6jau26B.js";
|
|
3
|
+
const InjectionFormKey = Symbol("form");
|
|
4
|
+
const InjectionPathKey = Symbol("path");
|
|
5
|
+
function getObject(val) {
|
|
6
|
+
return isPlainObject(val) ? val : {};
|
|
7
|
+
}
|
|
8
|
+
function camelizeProperties(obj) {
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(obj).map(([key, value]) => [camelize(key), value])
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const useFields = (initFields) => {
|
|
14
|
+
const fields = ref([]);
|
|
15
|
+
fields.value = initFields || [];
|
|
16
|
+
const _map = /* @__PURE__ */ new Map();
|
|
17
|
+
const cacheMatch = (pathStr, updater) => {
|
|
18
|
+
var _a;
|
|
19
|
+
const fieldPath = _map.get(pathStr) || [];
|
|
20
|
+
if (fieldPath.length === 0) return false;
|
|
21
|
+
const fieldIndex = fieldPath[fieldPath.length - 1];
|
|
22
|
+
const parentField = fieldPath.length === 1 ? fields.value : get(fields.value, fieldPath.slice(0, -2));
|
|
23
|
+
const field = (_a = parentField == null ? void 0 : parentField.fields) == null ? void 0 : _a[fieldIndex];
|
|
24
|
+
const _path = toPath((field == null ? void 0 : field.name) ?? (field == null ? void 0 : field.path)).join(".");
|
|
25
|
+
if (_path === pathStr) {
|
|
26
|
+
updater({ field, fieldIndex, parentField });
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
const updaterMatch = (path, updater, options = {}) => {
|
|
32
|
+
if (!path) return;
|
|
33
|
+
const pathStr = typeof path === "function" ? "" : toPath(path).join(".");
|
|
34
|
+
const { all = typeof path === "function" } = options;
|
|
35
|
+
if (pathStr && _map.has(pathStr) && !all) {
|
|
36
|
+
const bool = cacheMatch(pathStr, updater);
|
|
37
|
+
if (bool) return;
|
|
38
|
+
}
|
|
39
|
+
const queue = fields.value.map((field, i) => ({
|
|
40
|
+
field,
|
|
41
|
+
fieldPath: [i],
|
|
42
|
+
parentField: { fields: fields.value }
|
|
43
|
+
}));
|
|
44
|
+
while (queue.length) {
|
|
45
|
+
const { field, fieldPath, parentField } = queue.shift();
|
|
46
|
+
let matched = false;
|
|
47
|
+
const _path = toPath(field.name ?? field.path).join(".");
|
|
48
|
+
if (_path) _map.set(_path, fieldPath);
|
|
49
|
+
if (typeof path === "function") {
|
|
50
|
+
matched = path(field);
|
|
51
|
+
} else if (_path) {
|
|
52
|
+
matched = pathStr === _path;
|
|
53
|
+
}
|
|
54
|
+
if (matched) {
|
|
55
|
+
const fieldIndex = fieldPath[fieldPath.length - 1];
|
|
56
|
+
updater({ field, fieldIndex, parentField });
|
|
57
|
+
if (!all) return;
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(field.fields)) {
|
|
60
|
+
field.fields.forEach((f, i) => {
|
|
61
|
+
queue.push({
|
|
62
|
+
field: f,
|
|
63
|
+
fieldPath: [...fieldPath, "fields", i],
|
|
64
|
+
parentField: field
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function getField(path, options) {
|
|
71
|
+
if (!path) return void 0;
|
|
72
|
+
const res = [];
|
|
73
|
+
updaterMatch(
|
|
74
|
+
path,
|
|
75
|
+
({ field }) => {
|
|
76
|
+
res.push(field);
|
|
77
|
+
},
|
|
78
|
+
options
|
|
79
|
+
);
|
|
80
|
+
return (options == null ? void 0 : options.all) ? res : res[0];
|
|
81
|
+
}
|
|
82
|
+
function setField(path, field, options) {
|
|
83
|
+
if (!path) return;
|
|
84
|
+
const { updateType = "merge", ...rest } = options || {};
|
|
85
|
+
updaterMatch(
|
|
86
|
+
path,
|
|
87
|
+
({ field: preField, fieldIndex, parentField }) => {
|
|
88
|
+
let value = field;
|
|
89
|
+
if (typeof field === "function") {
|
|
90
|
+
value = field(preField);
|
|
91
|
+
}
|
|
92
|
+
if (!value) return;
|
|
93
|
+
if (updateType === "rewrite") {
|
|
94
|
+
parentField.fields[fieldIndex] = value;
|
|
95
|
+
} else {
|
|
96
|
+
Object.assign(preField, value);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
rest
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function deleteField(path, options) {
|
|
103
|
+
if (!path) return;
|
|
104
|
+
updaterMatch(
|
|
105
|
+
path,
|
|
106
|
+
({ fieldIndex, parentField }) => {
|
|
107
|
+
parentField.fields.splice(fieldIndex, 1);
|
|
108
|
+
},
|
|
109
|
+
options
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
function addFields(path, newFields, options, placement) {
|
|
113
|
+
if (newFields.length === 0) return;
|
|
114
|
+
if (path) {
|
|
115
|
+
updaterMatch(
|
|
116
|
+
path,
|
|
117
|
+
({ fieldIndex, parentField }) => {
|
|
118
|
+
const index = placement === "after" ? fieldIndex + 1 : fieldIndex;
|
|
119
|
+
parentField.fields.splice(index, 0, ...newFields);
|
|
120
|
+
},
|
|
121
|
+
options
|
|
122
|
+
);
|
|
123
|
+
} else if (placement === "after") {
|
|
124
|
+
fields.value.push(...newFields);
|
|
125
|
+
} else {
|
|
126
|
+
fields.value.unshift(...newFields);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function appendField(path, field, options) {
|
|
130
|
+
const newFields = Array.isArray(field) ? field : [field];
|
|
131
|
+
addFields(path, newFields, options, "after");
|
|
132
|
+
}
|
|
133
|
+
function prependField(path, field, options) {
|
|
134
|
+
const newFields = Array.isArray(field) ? field : [field];
|
|
135
|
+
addFields(path, newFields, options, "before");
|
|
136
|
+
}
|
|
137
|
+
function getParentField(path, options) {
|
|
138
|
+
if (!path) return void 0;
|
|
139
|
+
const res = [];
|
|
140
|
+
updaterMatch(
|
|
141
|
+
path,
|
|
142
|
+
({ parentField }) => {
|
|
143
|
+
res.push(parentField);
|
|
144
|
+
},
|
|
145
|
+
options
|
|
146
|
+
);
|
|
147
|
+
return (options == null ? void 0 : options.all) ? res : res[0];
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
fields,
|
|
151
|
+
getField,
|
|
152
|
+
setField,
|
|
153
|
+
deleteField,
|
|
154
|
+
appendField,
|
|
155
|
+
prependField,
|
|
156
|
+
getParentField
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
const InjectionFormDataKey = Symbol("form-data");
|
|
160
|
+
const useFormData = (initFormData) => {
|
|
161
|
+
if (!initFormData) {
|
|
162
|
+
const injectFormDataStore = inject(InjectionFormDataKey, void 0);
|
|
163
|
+
if (injectFormDataStore) return injectFormDataStore;
|
|
164
|
+
}
|
|
165
|
+
const formData = reactive(initFormData ?? {});
|
|
166
|
+
function getFormData(path) {
|
|
167
|
+
if (!path) return void 0;
|
|
168
|
+
return get(formData, path);
|
|
169
|
+
}
|
|
170
|
+
function setFormData(...args) {
|
|
171
|
+
let path;
|
|
172
|
+
let value;
|
|
173
|
+
if (args.length >= 2) {
|
|
174
|
+
[path, value] = args;
|
|
175
|
+
if (!path) return;
|
|
176
|
+
} else {
|
|
177
|
+
[value] = args;
|
|
178
|
+
}
|
|
179
|
+
if (path) {
|
|
180
|
+
if (typeof value === "function") {
|
|
181
|
+
const preValue = getFormData(path);
|
|
182
|
+
value = value(preValue);
|
|
183
|
+
}
|
|
184
|
+
set(formData, path, value);
|
|
185
|
+
} else {
|
|
186
|
+
if (typeof value === "function") {
|
|
187
|
+
const preValue = formData;
|
|
188
|
+
value = value(preValue);
|
|
189
|
+
}
|
|
190
|
+
if (!isPlainObject(value)) return;
|
|
191
|
+
Object.keys(formData).forEach((key) => {
|
|
192
|
+
delete formData[key];
|
|
193
|
+
});
|
|
194
|
+
Object.assign(formData, value);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const formDataStore = { formData, getFormData, setFormData };
|
|
198
|
+
provide(InjectionFormDataKey, formDataStore);
|
|
199
|
+
return formDataStore;
|
|
200
|
+
};
|
|
201
|
+
const useFormRef = () => {
|
|
202
|
+
const formRef = ref();
|
|
203
|
+
const setFormRef = (inst) => {
|
|
204
|
+
formRef.value = inst;
|
|
205
|
+
};
|
|
206
|
+
return { formRef, setFormRef };
|
|
207
|
+
};
|
|
208
|
+
function useForm(...args) {
|
|
209
|
+
let initFormData = {}, initFields = [], root = true;
|
|
210
|
+
if (args.length === 1) {
|
|
211
|
+
root = args[0];
|
|
212
|
+
} else if (args.length >= 2) {
|
|
213
|
+
initFormData = args[0];
|
|
214
|
+
initFields = args[1];
|
|
215
|
+
root = args[2] ?? root;
|
|
216
|
+
}
|
|
217
|
+
if (!root) {
|
|
218
|
+
const injectForm = inject(InjectionFormKey);
|
|
219
|
+
if (injectForm) return injectForm;
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
...useFormData(initFormData),
|
|
223
|
+
...useFields(initFields),
|
|
224
|
+
...useFormRef()
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const getDefaultPageParam = () => ({
|
|
228
|
+
current: 1,
|
|
229
|
+
pageSize: 10,
|
|
230
|
+
total: 0
|
|
231
|
+
});
|
|
232
|
+
const pageParamProperty = ["current", "pageSize", "total"];
|
|
233
|
+
const useTable = (params) => {
|
|
234
|
+
const {
|
|
235
|
+
columns: initColumns = [],
|
|
236
|
+
dataSource: initDataSource = [],
|
|
237
|
+
pageParam: initPageParam = getDefaultPageParam(),
|
|
238
|
+
searchParam: initSearchParam = {},
|
|
239
|
+
searchFields: initSearchFields = []
|
|
240
|
+
} = params;
|
|
241
|
+
const _initSearchParam = cloneDeep(toValue(initSearchParam));
|
|
242
|
+
const columns = ref([]);
|
|
243
|
+
columns.value = initColumns;
|
|
244
|
+
const dataSource = ref(initDataSource);
|
|
245
|
+
const pageParam = reactive(initPageParam);
|
|
246
|
+
const setPageParam = (pa) => {
|
|
247
|
+
let newPageParam = pa;
|
|
248
|
+
if (typeof pa === "function") {
|
|
249
|
+
newPageParam = pa(pageParam);
|
|
250
|
+
}
|
|
251
|
+
Object.assign(pageParam, pick(newPageParam, pageParamProperty));
|
|
252
|
+
};
|
|
253
|
+
const searchForm = useForm(initSearchParam, initSearchFields, true);
|
|
254
|
+
const resetQueryParams = () => {
|
|
255
|
+
Object.assign(pageParam, getDefaultPageParam());
|
|
256
|
+
searchForm.setFormData(cloneDeep(_initSearchParam));
|
|
257
|
+
};
|
|
258
|
+
const updaterMatch = (key, updater, options = {}) => {
|
|
259
|
+
if (!key) return;
|
|
260
|
+
const { all = typeof key === "function" } = options;
|
|
261
|
+
for (let i = 0; i < columns.value.length; i++) {
|
|
262
|
+
const columnItem = columns.value[i];
|
|
263
|
+
let matched = false;
|
|
264
|
+
if (typeof key === "function") {
|
|
265
|
+
matched = key(columnItem);
|
|
266
|
+
} else if (columnItem.key) {
|
|
267
|
+
matched = columnItem.key === key;
|
|
268
|
+
} else if (columnItem.dataIndex) {
|
|
269
|
+
const dataIndexKey = Array.isArray(columnItem.dataIndex) ? columnItem.dataIndex.join(".") : columnItem.dataIndex;
|
|
270
|
+
matched = dataIndexKey === key;
|
|
271
|
+
} else {
|
|
272
|
+
matched = key === i;
|
|
273
|
+
}
|
|
274
|
+
if (matched) {
|
|
275
|
+
updater({
|
|
276
|
+
column: columnItem,
|
|
277
|
+
columnIndex: i,
|
|
278
|
+
group: columns.value
|
|
279
|
+
});
|
|
280
|
+
if (!all) return;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const setColumn = (key, column, options) => {
|
|
285
|
+
if (!key || !column) return;
|
|
286
|
+
const { updateType = "merge", ...rest } = options || {};
|
|
287
|
+
updaterMatch(
|
|
288
|
+
key,
|
|
289
|
+
({ column: preColumn, columnIndex, group }) => {
|
|
290
|
+
let value = column;
|
|
291
|
+
if (typeof column === "function") {
|
|
292
|
+
value = column(preColumn);
|
|
293
|
+
}
|
|
294
|
+
if (!value) return;
|
|
295
|
+
if (updateType === "rewrite") {
|
|
296
|
+
group[columnIndex] = value;
|
|
297
|
+
} else {
|
|
298
|
+
Object.assign(preColumn, value);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
rest
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
function deleteColumn(path, options) {
|
|
305
|
+
if (!path) return;
|
|
306
|
+
updaterMatch(
|
|
307
|
+
path,
|
|
308
|
+
({ columnIndex, group }) => {
|
|
309
|
+
group.splice(columnIndex, 1);
|
|
310
|
+
},
|
|
311
|
+
options
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
function addColumns(path, newColumns, options, placement) {
|
|
315
|
+
if (newColumns.length === 0) return;
|
|
316
|
+
if (path) {
|
|
317
|
+
updaterMatch(
|
|
318
|
+
path,
|
|
319
|
+
({ columnIndex, group }) => {
|
|
320
|
+
const index = placement === "after" ? columnIndex + 1 : columnIndex;
|
|
321
|
+
group.splice(index, 0, ...newColumns);
|
|
322
|
+
},
|
|
323
|
+
options
|
|
324
|
+
);
|
|
325
|
+
} else if (placement === "after") {
|
|
326
|
+
columns.value.push(...newColumns);
|
|
327
|
+
} else {
|
|
328
|
+
columns.value.unshift(...newColumns);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function appendColumn(path, column, options) {
|
|
332
|
+
const newColumns = Array.isArray(column) ? column : [column];
|
|
333
|
+
addColumns(path, newColumns, options, "after");
|
|
334
|
+
}
|
|
335
|
+
function prependColumn(path, column, options) {
|
|
336
|
+
const newColumns = Array.isArray(column) ? column : [column];
|
|
337
|
+
addColumns(path, newColumns, options, "before");
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
columns,
|
|
341
|
+
dataSource,
|
|
342
|
+
pageParam,
|
|
343
|
+
searchForm,
|
|
344
|
+
setColumn,
|
|
345
|
+
deleteColumn,
|
|
346
|
+
appendColumn,
|
|
347
|
+
prependColumn,
|
|
348
|
+
setPageParam,
|
|
349
|
+
resetQueryParams
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
export {
|
|
353
|
+
InjectionFormKey as I,
|
|
354
|
+
InjectionPathKey as a,
|
|
355
|
+
useFields as b,
|
|
356
|
+
camelizeProperties as c,
|
|
357
|
+
useFormRef as d,
|
|
358
|
+
useFormData as e,
|
|
359
|
+
useTable as f,
|
|
360
|
+
getObject as g,
|
|
361
|
+
useForm as u
|
|
362
|
+
};
|