@qin-ui/antdv-next-pro 1.0.0

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.
@@ -0,0 +1,58 @@
1
+ .pro-table_search-form[data-v-37368080] .ant-form-item {
2
+ margin: 0;
3
+ }
4
+ .pro-table_search-form_expand-toggle-button[data-v-37368080] {
5
+ display: flex;
6
+ align-items: center;
7
+ padding: 0;
8
+ padding-left: 4px;
9
+ }
10
+ .pro-table_search-form .transition[data-v-37368080] {
11
+ transition: all 0.25s;
12
+ }
13
+ .pro-table_search-form-container[data-v-8f67830d] {
14
+ margin-bottom: 24px;
15
+ padding: 24px;
16
+ }
17
+ .pro-table_table-container[data-v-02fe26ae] {
18
+ flex: 1;
19
+ padding: 24px 24px 0;
20
+ }
21
+ .pro-table_size-control_button[data-v-832ddd0e] {
22
+ display: flex;
23
+ align-items: center;
24
+ padding-right: 12px;
25
+ padding-left: 12px;
26
+ }
27
+ .pro-table_size-control_button[data-v-832ddd0e] svg {
28
+ transform: scale(1.3);
29
+ }
30
+ .pro-table_column-control_button[data-v-246b0faf] {
31
+ display: flex;
32
+ align-items: center;
33
+ padding-right: 12px;
34
+ padding-left: 12px;
35
+ }
36
+ .pro-table_column-control_button[data-v-246b0faf] svg {
37
+ transform: scale(1.2, 1.4);
38
+ }
39
+ .pro-table_header[data-v-270ae6c9] {
40
+ display: flex;
41
+ align-items: center;
42
+ justify-content: flex-end;
43
+ }
44
+ .pro-table_header[data-v-270ae6c9]:empty {
45
+ display: none;
46
+ }
47
+ .pro-table_header + .pro-table_header_content[data-v-270ae6c9] {
48
+ margin-top: 16px;
49
+ }
50
+ .pro-table_header_button-bar[data-v-270ae6c9] {
51
+ flex: 1;
52
+ }
53
+ .pro-table_header_toolbar[data-v-270ae6c9] {
54
+ margin-left: 12px;
55
+ }
56
+ .pro-table[data-v-270ae6c9] .ant-pagination .ant-pagination-total-text {
57
+ flex: 1;
58
+ }
@@ -0,0 +1,519 @@
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
+ "input-opt": {
64
+ injectionKey: Symbol(""),
65
+ default: {}
66
+ },
67
+ select: {
68
+ injectionKey: Symbol(""),
69
+ default: { allowClear: true, placeholder: "请选择", getPopupContainer }
70
+ },
71
+ cascader: {
72
+ injectionKey: Symbol(""),
73
+ default: { allowClear: true, placeholder: "请选择", getPopupContainer }
74
+ },
75
+ "date-picker": {
76
+ injectionKey: Symbol(""),
77
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
78
+ },
79
+ "date-picker.date": {
80
+ injectionKey: Symbol(""),
81
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
82
+ },
83
+ "date-picker.week": {
84
+ injectionKey: Symbol(""),
85
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
86
+ },
87
+ "date-picker.month": {
88
+ injectionKey: Symbol(""),
89
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
90
+ },
91
+ "date-picker.year": {
92
+ injectionKey: Symbol(""),
93
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
94
+ },
95
+ "date-picker.quarter": {
96
+ injectionKey: Symbol(""),
97
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
98
+ },
99
+ "range-picker": {
100
+ injectionKey: Symbol(""),
101
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
102
+ },
103
+ "time-picker": {
104
+ injectionKey: Symbol(""),
105
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
106
+ },
107
+ "time-range-picker": {
108
+ injectionKey: Symbol(""),
109
+ default: { allowClear: true, getPopupContainer, style: { width: "100%" } }
110
+ },
111
+ "checkbox-group": {
112
+ injectionKey: Symbol(""),
113
+ default: {}
114
+ },
115
+ "radio-group": {
116
+ injectionKey: Symbol(""),
117
+ default: {}
118
+ },
119
+ switch: {
120
+ injectionKey: Symbol(""),
121
+ default: { modelName: "checked" }
122
+ },
123
+ slider: {
124
+ injectionKey: Symbol(""),
125
+ default: {}
126
+ },
127
+ "tree-select": {
128
+ injectionKey: Symbol(""),
129
+ default: {}
130
+ },
131
+ transfer: {
132
+ injectionKey: Symbol(""),
133
+ default: {}
134
+ }
135
+ };
136
+ const InjectionFormKey = Symbol("form");
137
+ const InjectionPathKey = Symbol("path");
138
+ function getObject(val) {
139
+ return isPlainObject(val) ? val : {};
140
+ }
141
+ function camelizeProperties(obj) {
142
+ return Object.fromEntries(
143
+ Object.entries(obj).map(([key, value]) => [camelize(key), value])
144
+ );
145
+ }
146
+ const useFields = (initFields) => {
147
+ const fields = ref([]);
148
+ fields.value = initFields || [];
149
+ const _map = /* @__PURE__ */ new Map();
150
+ const cacheMatch = (pathStr, updater) => {
151
+ var _a;
152
+ const fieldPath = _map.get(pathStr) || [];
153
+ if (fieldPath.length === 0) return false;
154
+ const fieldIndex = fieldPath[fieldPath.length - 1];
155
+ const parentField = fieldPath.length === 1 ? fields.value : get(fields.value, fieldPath.slice(0, -2));
156
+ const field = (_a = parentField == null ? void 0 : parentField.fields) == null ? void 0 : _a[fieldIndex];
157
+ const _path = toPath((field == null ? void 0 : field.name) ?? (field == null ? void 0 : field.path)).join(".");
158
+ if (_path === pathStr) {
159
+ updater({ field, fieldIndex, parentField });
160
+ return true;
161
+ }
162
+ return false;
163
+ };
164
+ const updaterMatch = (path, updater, options = {}) => {
165
+ if (!path) return;
166
+ const pathStr = typeof path === "function" ? "" : toPath(path).join(".");
167
+ const { all = typeof path === "function" } = options;
168
+ if (pathStr && _map.has(pathStr) && !all) {
169
+ const bool = cacheMatch(pathStr, updater);
170
+ if (bool) return;
171
+ }
172
+ const queue = fields.value.map((field, i) => ({
173
+ field,
174
+ fieldPath: [i],
175
+ parentField: { fields: fields.value }
176
+ }));
177
+ while (queue.length) {
178
+ const { field, fieldPath, parentField } = queue.shift();
179
+ let matched = false;
180
+ const _path = toPath(field.name ?? field.path).join(".");
181
+ if (_path) _map.set(_path, fieldPath);
182
+ if (typeof path === "function") {
183
+ matched = path(field);
184
+ } else if (_path) {
185
+ matched = pathStr === _path;
186
+ }
187
+ if (matched) {
188
+ const fieldIndex = fieldPath[fieldPath.length - 1];
189
+ updater({ field, fieldIndex, parentField });
190
+ if (!all) return;
191
+ }
192
+ if (Array.isArray(field.fields)) {
193
+ field.fields.forEach((f, i) => {
194
+ queue.push({
195
+ field: f,
196
+ fieldPath: [...fieldPath, "fields", i],
197
+ parentField: field
198
+ });
199
+ });
200
+ }
201
+ }
202
+ };
203
+ function getField(path, options) {
204
+ if (!path) return void 0;
205
+ const res = [];
206
+ updaterMatch(
207
+ path,
208
+ ({ field }) => {
209
+ res.push(field);
210
+ },
211
+ options
212
+ );
213
+ return (options == null ? void 0 : options.all) ? res : res[0];
214
+ }
215
+ function setField(path, field, options) {
216
+ if (!path) return;
217
+ const { updateType = "merge", ...rest } = options || {};
218
+ updaterMatch(
219
+ path,
220
+ ({ field: preField, fieldIndex, parentField }) => {
221
+ let value = field;
222
+ if (typeof field === "function") {
223
+ value = field(preField);
224
+ }
225
+ if (!value) return;
226
+ if (updateType === "rewrite") {
227
+ parentField.fields[fieldIndex] = value;
228
+ } else {
229
+ Object.assign(preField, value);
230
+ }
231
+ },
232
+ rest
233
+ );
234
+ }
235
+ function deleteField(path, options) {
236
+ if (!path) return;
237
+ updaterMatch(
238
+ path,
239
+ ({ fieldIndex, parentField }) => {
240
+ parentField.fields.splice(fieldIndex, 1);
241
+ },
242
+ options
243
+ );
244
+ }
245
+ function addFields(path, newFields, options, placement) {
246
+ if (newFields.length === 0) return;
247
+ if (path) {
248
+ updaterMatch(
249
+ path,
250
+ ({ fieldIndex, parentField }) => {
251
+ const index = placement === "after" ? fieldIndex + 1 : fieldIndex;
252
+ parentField.fields.splice(index, 0, ...newFields);
253
+ },
254
+ options
255
+ );
256
+ } else if (placement === "after") {
257
+ fields.value.push(...newFields);
258
+ } else {
259
+ fields.value.unshift(...newFields);
260
+ }
261
+ }
262
+ function appendField(path, field, options) {
263
+ const newFields = Array.isArray(field) ? field : [field];
264
+ addFields(path, newFields, options, "after");
265
+ }
266
+ function prependField(path, field, options) {
267
+ const newFields = Array.isArray(field) ? field : [field];
268
+ addFields(path, newFields, options, "before");
269
+ }
270
+ function getParentField(path, options) {
271
+ if (!path) return void 0;
272
+ const res = [];
273
+ updaterMatch(
274
+ path,
275
+ ({ parentField }) => {
276
+ res.push(parentField);
277
+ },
278
+ options
279
+ );
280
+ return (options == null ? void 0 : options.all) ? res : res[0];
281
+ }
282
+ return {
283
+ fields,
284
+ getField,
285
+ setField,
286
+ deleteField,
287
+ appendField,
288
+ prependField,
289
+ getParentField
290
+ };
291
+ };
292
+ const InjectionFormDataKey = Symbol("form-data");
293
+ const useFormData = (initFormData) => {
294
+ if (!initFormData) {
295
+ const injectFormDataStore = inject(InjectionFormDataKey, void 0);
296
+ if (injectFormDataStore) return injectFormDataStore;
297
+ }
298
+ const formData = reactive(initFormData ?? {});
299
+ function getFormData(path) {
300
+ if (!path) return void 0;
301
+ return get(formData, path);
302
+ }
303
+ function setFormData(...args) {
304
+ let path;
305
+ let value;
306
+ if (args.length >= 2) {
307
+ [path, value] = args;
308
+ if (!path) return;
309
+ } else {
310
+ [value] = args;
311
+ }
312
+ if (path) {
313
+ if (typeof value === "function") {
314
+ const preValue = getFormData(path);
315
+ value = value(preValue);
316
+ }
317
+ set(formData, path, value);
318
+ } else {
319
+ if (typeof value === "function") {
320
+ const preValue = formData;
321
+ value = value(preValue);
322
+ }
323
+ if (!isPlainObject(value)) return;
324
+ Object.keys(formData).forEach((key) => {
325
+ delete formData[key];
326
+ });
327
+ Object.assign(formData, value);
328
+ }
329
+ }
330
+ const formDataStore = { formData, getFormData, setFormData };
331
+ provide(InjectionFormDataKey, formDataStore);
332
+ return formDataStore;
333
+ };
334
+ const useFormRef = () => {
335
+ const formRef = ref();
336
+ const setFormRef = (inst) => {
337
+ formRef.value = inst;
338
+ };
339
+ return { formRef, setFormRef };
340
+ };
341
+ function useForm(...args) {
342
+ let initFormData = {}, initFields = [], root = true;
343
+ if (args.length === 1) {
344
+ root = args[0];
345
+ } else if (args.length >= 2) {
346
+ initFormData = args[0];
347
+ initFields = args[1];
348
+ root = args[2] ?? root;
349
+ }
350
+ if (!root) {
351
+ const injectForm = inject(InjectionFormKey);
352
+ if (injectForm) return injectForm;
353
+ }
354
+ return {
355
+ ...useFormData(initFormData),
356
+ ...useFields(initFields),
357
+ ...useFormRef()
358
+ };
359
+ }
360
+ const getDefaultPageParam = () => ({
361
+ current: 1,
362
+ pageSize: 10,
363
+ total: 0
364
+ });
365
+ const pageParamProperty = ["current", "pageSize", "total"];
366
+ const useTable = (params) => {
367
+ const {
368
+ columns: initColumns = [],
369
+ dataSource: initDataSource = [],
370
+ pageParam: initPageParam = getDefaultPageParam(),
371
+ searchParam: initSearchParam = {},
372
+ searchFields: initSearchFields = []
373
+ } = params;
374
+ const _initSearchParam = cloneDeep(toValue(initSearchParam));
375
+ const columns = ref([]);
376
+ columns.value = initColumns;
377
+ const dataSource = ref(initDataSource);
378
+ const pageParam = reactive(initPageParam);
379
+ const setPageParam = (pa) => {
380
+ let newPageParam = pa;
381
+ if (typeof pa === "function") {
382
+ newPageParam = pa(pageParam);
383
+ }
384
+ Object.assign(pageParam, pick(newPageParam, pageParamProperty));
385
+ };
386
+ const searchForm = useForm(initSearchParam, initSearchFields, true);
387
+ const resetQueryParams = () => {
388
+ Object.assign(pageParam, getDefaultPageParam());
389
+ searchForm.setFormData(cloneDeep(_initSearchParam));
390
+ };
391
+ const updaterMatch = (key, updater, options = {}) => {
392
+ if (!key) return;
393
+ const { all = typeof key === "function" } = options;
394
+ for (let i = 0; i < columns.value.length; i++) {
395
+ const columnItem = columns.value[i];
396
+ let matched = false;
397
+ if (typeof key === "function") {
398
+ matched = key(columnItem);
399
+ } else if (columnItem.key) {
400
+ matched = columnItem.key === key;
401
+ } else if (columnItem.dataIndex) {
402
+ const dataIndexKey = Array.isArray(columnItem.dataIndex) ? columnItem.dataIndex.join(".") : columnItem.dataIndex;
403
+ matched = dataIndexKey === key;
404
+ } else {
405
+ matched = key === i;
406
+ }
407
+ if (matched) {
408
+ updater({
409
+ column: columnItem,
410
+ columnIndex: i,
411
+ group: columns.value
412
+ });
413
+ if (!all) return;
414
+ }
415
+ }
416
+ };
417
+ const setColumn = (key, column, options) => {
418
+ if (!key || !column) return;
419
+ const { updateType = "merge", ...rest } = options || {};
420
+ updaterMatch(
421
+ key,
422
+ ({ column: preColumn, columnIndex, group }) => {
423
+ let value = column;
424
+ if (typeof column === "function") {
425
+ value = column(preColumn);
426
+ }
427
+ if (!value) return;
428
+ if (updateType === "rewrite") {
429
+ group[columnIndex] = value;
430
+ } else {
431
+ Object.assign(preColumn, value);
432
+ }
433
+ },
434
+ rest
435
+ );
436
+ };
437
+ function deleteColumn(path, options) {
438
+ if (!path) return;
439
+ updaterMatch(
440
+ path,
441
+ ({ columnIndex, group }) => {
442
+ group.splice(columnIndex, 1);
443
+ },
444
+ options
445
+ );
446
+ }
447
+ function addColumns(path, newColumns, options, placement) {
448
+ if (newColumns.length === 0) return;
449
+ if (path) {
450
+ updaterMatch(
451
+ path,
452
+ ({ columnIndex, group }) => {
453
+ const index = placement === "after" ? columnIndex + 1 : columnIndex;
454
+ group.splice(index, 0, ...newColumns);
455
+ },
456
+ options
457
+ );
458
+ } else if (placement === "after") {
459
+ columns.value.push(...newColumns);
460
+ } else {
461
+ columns.value.unshift(...newColumns);
462
+ }
463
+ }
464
+ function appendColumn(path, column, options) {
465
+ const newColumns = Array.isArray(column) ? column : [column];
466
+ addColumns(path, newColumns, options, "after");
467
+ }
468
+ function prependColumn(path, column, options) {
469
+ const newColumns = Array.isArray(column) ? column : [column];
470
+ addColumns(path, newColumns, options, "before");
471
+ }
472
+ return {
473
+ columns,
474
+ dataSource,
475
+ pageParam,
476
+ searchForm,
477
+ setColumn,
478
+ deleteColumn,
479
+ appendColumn,
480
+ prependColumn,
481
+ setPageParam,
482
+ resetQueryParams
483
+ };
484
+ };
485
+ const _sfc_main = /* @__PURE__ */ defineComponent({
486
+ ...{
487
+ inheritAttrs: false
488
+ },
489
+ __name: "index",
490
+ props: {
491
+ componentVars: {}
492
+ },
493
+ setup(__props) {
494
+ const props = __props;
495
+ if (props.componentVars) {
496
+ Object.entries(props.componentVars).forEach(([key, val]) => {
497
+ const config = INJECT_CONFIG[key];
498
+ if (!config) return;
499
+ provide(config.injectionKey, { ...config.default, ...getObject(val) });
500
+ });
501
+ }
502
+ return (_ctx, _cache) => {
503
+ return renderSlot(_ctx.$slots, "default");
504
+ };
505
+ }
506
+ });
507
+ export {
508
+ InjectionFormKey as I,
509
+ _sfc_main as _,
510
+ INJECT_CONFIG as a,
511
+ InjectionPathKey as b,
512
+ camelizeProperties as c,
513
+ useFields as d,
514
+ useFormRef as e,
515
+ useFormData as f,
516
+ getObject as g,
517
+ useTable as h,
518
+ useForm as u
519
+ };
@@ -0,0 +1,5 @@
1
+ import { a, _ } from "./index-B-Yy-eoc.js";
2
+ export {
3
+ a as INJECT_CONFIG,
4
+ _ as default
5
+ };