@qin-ui/antd-vue-pro 2.0.15 → 2.0.18

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.
@@ -1,13 +1,13 @@
1
- .pro-table_search-form[data-v-0bb2bc70] .ant-form-item {
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-0bb2bc70] {
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-0bb2bc70] {
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-0df8d4ae] {
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-0df8d4ae] svg {
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-49bb3de5] {
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-49bb3de5] svg {
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-54982423] {
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-54982423]:empty {
44
+ .pro-table_header[data-v-291baca6]:empty {
45
45
  display: none;
46
46
  }
47
- .pro-table_header + .pro-table_header_content[data-v-54982423] {
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-54982423] {
50
+ .pro-table_header_button-bar[data-v-291baca6] {
51
51
  flex: 1;
52
52
  }
53
- .pro-table_header_toolbar[data-v-54982423] {
53
+ .pro-table_header_toolbar[data-v-291baca6] {
54
54
  margin-left: 12px;
55
55
  }
56
- .pro-table[data-v-54982423] .ant-pagination .ant-pagination-total-text {
56
+ .pro-table[data-v-291baca6] .ant-pagination .ant-pagination-total-text {
57
57
  flex: 1;
58
58
  }
@@ -0,0 +1,511 @@
1
+ import { inject, camelize, reactive, provide, ref, toValue, defineComponent, renderSlot } 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 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 InjectionFormKey = Symbol("form");
129
+ const InjectionPathKey = Symbol("path");
130
+ function getObject(val) {
131
+ return isPlainObject(val) ? val : {};
132
+ }
133
+ function camelizeProperties(obj) {
134
+ return Object.fromEntries(
135
+ Object.entries(obj).map(([key, value]) => [camelize(key), value])
136
+ );
137
+ }
138
+ const useFields = (initFields) => {
139
+ const fields = ref([]);
140
+ fields.value = initFields || [];
141
+ const _map = /* @__PURE__ */ new Map();
142
+ const cacheMatch = (pathStr, updater) => {
143
+ var _a;
144
+ const fieldPath = _map.get(pathStr) || [];
145
+ if (fieldPath.length === 0) return false;
146
+ const fieldIndex = fieldPath[fieldPath.length - 1];
147
+ const parentField = fieldPath.length === 1 ? fields.value : get(fields.value, fieldPath.slice(0, -2));
148
+ const field = (_a = parentField == null ? void 0 : parentField.fields) == null ? void 0 : _a[fieldIndex];
149
+ const _path = toPath((field == null ? void 0 : field.name) ?? (field == null ? void 0 : field.path)).join(".");
150
+ if (_path === pathStr) {
151
+ updater({ field, fieldIndex, parentField });
152
+ return true;
153
+ }
154
+ return false;
155
+ };
156
+ const updaterMatch = (path, updater, options = {}) => {
157
+ if (!path) return;
158
+ const pathStr = typeof path === "function" ? "" : toPath(path).join(".");
159
+ const { all = typeof path === "function" } = options;
160
+ if (pathStr && _map.has(pathStr) && !all) {
161
+ const bool = cacheMatch(pathStr, updater);
162
+ if (bool) return;
163
+ }
164
+ const queue = fields.value.map((field, i) => ({
165
+ field,
166
+ fieldPath: [i],
167
+ parentField: { fields: fields.value }
168
+ }));
169
+ while (queue.length) {
170
+ const { field, fieldPath, parentField } = queue.shift();
171
+ let matched = false;
172
+ const _path = toPath(field.name ?? field.path).join(".");
173
+ if (_path) _map.set(_path, fieldPath);
174
+ if (typeof path === "function") {
175
+ matched = path(field);
176
+ } else if (_path) {
177
+ matched = pathStr === _path;
178
+ }
179
+ if (matched) {
180
+ const fieldIndex = fieldPath[fieldPath.length - 1];
181
+ updater({ field, fieldIndex, parentField });
182
+ if (!all) return;
183
+ }
184
+ if (Array.isArray(field.fields)) {
185
+ field.fields.forEach((f, i) => {
186
+ queue.push({
187
+ field: f,
188
+ fieldPath: [...fieldPath, "fields", i],
189
+ parentField: field
190
+ });
191
+ });
192
+ }
193
+ }
194
+ };
195
+ function getField(path, options) {
196
+ if (!path) return void 0;
197
+ const res = [];
198
+ updaterMatch(
199
+ path,
200
+ ({ field }) => {
201
+ res.push(field);
202
+ },
203
+ options
204
+ );
205
+ return (options == null ? void 0 : options.all) ? res : res[0];
206
+ }
207
+ function setField(path, field, options) {
208
+ if (!path) return;
209
+ const { updateType = "merge", ...rest } = options || {};
210
+ updaterMatch(
211
+ path,
212
+ ({ field: preField, fieldIndex, parentField }) => {
213
+ let value = field;
214
+ if (typeof field === "function") {
215
+ value = field(preField);
216
+ }
217
+ if (!value) return;
218
+ if (updateType === "rewrite") {
219
+ parentField.fields[fieldIndex] = value;
220
+ } else {
221
+ Object.assign(preField, value);
222
+ }
223
+ },
224
+ rest
225
+ );
226
+ }
227
+ function deleteField(path, options) {
228
+ if (!path) return;
229
+ updaterMatch(
230
+ path,
231
+ ({ fieldIndex, parentField }) => {
232
+ parentField.fields.splice(fieldIndex, 1);
233
+ },
234
+ options
235
+ );
236
+ }
237
+ function addFields(path, newFields, options, placement) {
238
+ if (newFields.length === 0) return;
239
+ if (path) {
240
+ updaterMatch(
241
+ path,
242
+ ({ fieldIndex, parentField }) => {
243
+ const index = placement === "after" ? fieldIndex + 1 : fieldIndex;
244
+ parentField.fields.splice(index, 0, ...newFields);
245
+ },
246
+ options
247
+ );
248
+ } else if (placement === "after") {
249
+ fields.value.push(...newFields);
250
+ } else {
251
+ fields.value.unshift(...newFields);
252
+ }
253
+ }
254
+ function appendField(path, field, options) {
255
+ const newFields = Array.isArray(field) ? field : [field];
256
+ addFields(path, newFields, options, "after");
257
+ }
258
+ function prependField(path, field, options) {
259
+ const newFields = Array.isArray(field) ? field : [field];
260
+ addFields(path, newFields, options, "before");
261
+ }
262
+ function getParentField(path, options) {
263
+ if (!path) return void 0;
264
+ const res = [];
265
+ updaterMatch(
266
+ path,
267
+ ({ parentField }) => {
268
+ res.push(parentField);
269
+ },
270
+ options
271
+ );
272
+ return (options == null ? void 0 : options.all) ? res : res[0];
273
+ }
274
+ return {
275
+ fields,
276
+ getField,
277
+ setField,
278
+ deleteField,
279
+ appendField,
280
+ prependField,
281
+ getParentField
282
+ };
283
+ };
284
+ const InjectionFormDataKey = Symbol("form-data");
285
+ const useFormData = (initFormData) => {
286
+ if (!initFormData) {
287
+ const injectFormDataStore = inject(InjectionFormDataKey, void 0);
288
+ if (injectFormDataStore) return injectFormDataStore;
289
+ }
290
+ const formData = reactive(initFormData ?? {});
291
+ function getFormData(path) {
292
+ if (!path) return void 0;
293
+ return get(formData, path);
294
+ }
295
+ function setFormData(...args) {
296
+ let path;
297
+ let value;
298
+ if (args.length >= 2) {
299
+ [path, value] = args;
300
+ if (!path) return;
301
+ } else {
302
+ [value] = args;
303
+ }
304
+ if (path) {
305
+ if (typeof value === "function") {
306
+ const preValue = getFormData(path);
307
+ value = value(preValue);
308
+ }
309
+ set(formData, path, value);
310
+ } else {
311
+ if (typeof value === "function") {
312
+ const preValue = formData;
313
+ value = value(preValue);
314
+ }
315
+ if (!isPlainObject(value)) return;
316
+ Object.keys(formData).forEach((key) => {
317
+ delete formData[key];
318
+ });
319
+ Object.assign(formData, value);
320
+ }
321
+ }
322
+ const formDataStore = { formData, getFormData, setFormData };
323
+ provide(InjectionFormDataKey, formDataStore);
324
+ return formDataStore;
325
+ };
326
+ const useFormRef = () => {
327
+ const formRef = ref();
328
+ const setFormRef = (inst) => {
329
+ formRef.value = inst;
330
+ };
331
+ return { formRef, setFormRef };
332
+ };
333
+ function useForm(...args) {
334
+ let initFormData = {}, initFields = [], root = true;
335
+ if (args.length === 1) {
336
+ root = args[0];
337
+ } else if (args.length >= 2) {
338
+ initFormData = args[0];
339
+ initFields = args[1];
340
+ root = args[2] ?? root;
341
+ }
342
+ if (!root) {
343
+ const injectForm = inject(InjectionFormKey);
344
+ if (injectForm) return injectForm;
345
+ }
346
+ return {
347
+ ...useFormData(initFormData),
348
+ ...useFields(initFields),
349
+ ...useFormRef()
350
+ };
351
+ }
352
+ const getDefaultPageParam = () => ({
353
+ current: 1,
354
+ pageSize: 10,
355
+ total: 0
356
+ });
357
+ const pageParamProperty = ["current", "pageSize", "total"];
358
+ const useTable = (params) => {
359
+ const {
360
+ columns: initColumns = [],
361
+ dataSource: initDataSource = [],
362
+ pageParam: initPageParam = getDefaultPageParam(),
363
+ searchParam: initSearchParam = {},
364
+ searchFields: initSearchFields = []
365
+ } = params;
366
+ const _initSearchParam = cloneDeep(toValue(initSearchParam));
367
+ const columns = ref([]);
368
+ columns.value = initColumns;
369
+ const dataSource = ref(initDataSource);
370
+ const pageParam = reactive(initPageParam);
371
+ const setPageParam = (pa) => {
372
+ let newPageParam = pa;
373
+ if (typeof pa === "function") {
374
+ newPageParam = pa(pageParam);
375
+ }
376
+ Object.assign(pageParam, pick(newPageParam, pageParamProperty));
377
+ };
378
+ const searchForm = useForm(initSearchParam, initSearchFields, true);
379
+ const resetQueryParams = () => {
380
+ Object.assign(pageParam, getDefaultPageParam());
381
+ searchForm.setFormData(cloneDeep(_initSearchParam));
382
+ };
383
+ const updaterMatch = (key, updater, options = {}) => {
384
+ if (!key) return;
385
+ const { all = typeof key === "function" } = options;
386
+ for (let i = 0; i < columns.value.length; i++) {
387
+ const columnItem = columns.value[i];
388
+ let matched = false;
389
+ if (typeof key === "function") {
390
+ matched = key(columnItem);
391
+ } else if (columnItem.key) {
392
+ matched = columnItem.key === key;
393
+ } else if (columnItem.dataIndex) {
394
+ const dataIndexKey = Array.isArray(columnItem.dataIndex) ? columnItem.dataIndex.join(".") : columnItem.dataIndex;
395
+ matched = dataIndexKey === key;
396
+ } else {
397
+ matched = key === i;
398
+ }
399
+ if (matched) {
400
+ updater({
401
+ column: columnItem,
402
+ columnIndex: i,
403
+ group: columns.value
404
+ });
405
+ if (!all) return;
406
+ }
407
+ }
408
+ };
409
+ const setColumn = (key, column, options) => {
410
+ if (!key || !column) return;
411
+ const { updateType = "merge", ...rest } = options || {};
412
+ updaterMatch(
413
+ key,
414
+ ({ column: preColumn, columnIndex, group }) => {
415
+ let value = column;
416
+ if (typeof column === "function") {
417
+ value = column(preColumn);
418
+ }
419
+ if (!value) return;
420
+ if (updateType === "rewrite") {
421
+ group[columnIndex] = value;
422
+ } else {
423
+ Object.assign(preColumn, value);
424
+ }
425
+ },
426
+ rest
427
+ );
428
+ };
429
+ function deleteColumn(path, options) {
430
+ if (!path) return;
431
+ updaterMatch(
432
+ path,
433
+ ({ columnIndex, group }) => {
434
+ group.splice(columnIndex, 1);
435
+ },
436
+ options
437
+ );
438
+ }
439
+ function addColumns(path, newColumns, options, placement) {
440
+ if (newColumns.length === 0) return;
441
+ if (path) {
442
+ updaterMatch(
443
+ path,
444
+ ({ columnIndex, group }) => {
445
+ const index = placement === "after" ? columnIndex + 1 : columnIndex;
446
+ group.splice(index, 0, ...newColumns);
447
+ },
448
+ options
449
+ );
450
+ } else if (placement === "after") {
451
+ columns.value.push(...newColumns);
452
+ } else {
453
+ columns.value.unshift(...newColumns);
454
+ }
455
+ }
456
+ function appendColumn(path, column, options) {
457
+ const newColumns = Array.isArray(column) ? column : [column];
458
+ addColumns(path, newColumns, options, "after");
459
+ }
460
+ function prependColumn(path, column, options) {
461
+ const newColumns = Array.isArray(column) ? column : [column];
462
+ addColumns(path, newColumns, options, "before");
463
+ }
464
+ return {
465
+ columns,
466
+ dataSource,
467
+ pageParam,
468
+ searchForm,
469
+ setColumn,
470
+ deleteColumn,
471
+ appendColumn,
472
+ prependColumn,
473
+ setPageParam,
474
+ resetQueryParams
475
+ };
476
+ };
477
+ const _sfc_main = /* @__PURE__ */ defineComponent({
478
+ ...{
479
+ inheritAttrs: false
480
+ },
481
+ __name: "index",
482
+ props: {
483
+ componentVars: {}
484
+ },
485
+ setup(__props) {
486
+ const props = __props;
487
+ if (props.componentVars) {
488
+ Object.entries(props.componentVars).forEach(([key, val]) => {
489
+ const config = INJECT_CONFIG[key];
490
+ if (!config) return;
491
+ provide(config.injectionKey, { ...config.default, ...getObject(val) });
492
+ });
493
+ }
494
+ return (_ctx, _cache) => {
495
+ return renderSlot(_ctx.$slots, "default");
496
+ };
497
+ }
498
+ });
499
+ export {
500
+ InjectionFormKey as I,
501
+ _sfc_main as _,
502
+ INJECT_CONFIG as a,
503
+ InjectionPathKey as b,
504
+ camelizeProperties as c,
505
+ useFields as d,
506
+ useFormRef as e,
507
+ useFormData as f,
508
+ getObject as g,
509
+ useTable as h,
510
+ useForm as u
511
+ };
@@ -1,5 +1,5 @@
1
- import { I, _ } from "./index-D8NF18a1.js";
1
+ import { a, _ } from "./index-BeGPcKnM.js";
2
2
  export {
3
- I as INJECT_CONFIG,
3
+ a as INJECT_CONFIG,
4
4
  _ as default
5
5
  };