@vue-ui-kit/ant 1.1.1 → 1.2.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.
@@ -1,4 +1,4 @@
1
- import { RenderFormParams, RenderOptions, RenderTableParams } from '#/antProxy';
1
+ import { RenderFormParams, RenderOptions, RenderTableParams } from '#/antProxy'
2
2
  import {
3
3
  Button,
4
4
  Dropdown,
@@ -20,13 +20,13 @@ import {
20
20
  Textarea,
21
21
  TimePicker,
22
22
  TreeSelect,
23
- } from 'ant-design-vue';
24
- import { set, isFunction, merge, omit } from 'lodash-es';
25
- import { ButtonProps } from 'ant-design-vue/lib/button';
26
- import { noValue, valued } from '@/utils/is';
27
- import TableInput from '@/renders/TableInput.vue';
28
- import Icon from '@/renders/Icon';
29
- import { computed } from 'vue';
23
+ } from 'ant-design-vue'
24
+ import { set, isFunction, merge, omit } from 'lodash-es'
25
+ import { ButtonProps } from 'ant-design-vue/lib/button'
26
+ import { noValue, valued } from '@/utils/is'
27
+ import TableInput from '@/renders/TableInput.vue'
28
+ import Icon from '@/renders/Icon'
29
+ import { computed } from 'vue'
30
30
 
31
31
  interface BtnOptions extends ButtonProps {
32
32
  content?: string;
@@ -84,7 +84,7 @@ const antDefaultProps = {
84
84
  filterOption: (input: string, option: IOption) =>
85
85
  option.label && option.label.toLowerCase().includes(input.toLowerCase()),
86
86
  },
87
- };
87
+ }
88
88
  const defaultProps: Recordable = {
89
89
  PercentInput: {
90
90
  controls: false,
@@ -92,7 +92,10 @@ const defaultProps: Recordable = {
92
92
  max: 100,
93
93
  addonAfter: '%',
94
94
  },
95
- };
95
+ autoComplete: {
96
+ inputProps: {}
97
+ }
98
+ }
96
99
  const componentsMap = {
97
100
  $input: Input,
98
101
  AInput: Input,
@@ -119,16 +122,16 @@ const componentsMap = {
119
122
  $time: TimePicker,
120
123
  ATimePicker: TimePicker,
121
124
  ATreeSelect: TreeSelect,
122
- };
125
+ }
123
126
  const renderBasic = (name: string) => {
124
- const DynamicComponent = componentsMap[name];
127
+ const DynamicComponent = componentsMap[name]
125
128
  return {
126
- renderItemContent(
129
+ renderItemContent (
127
130
  { props = {}, attrs = {}, events = {}, defaultValue }: RenderOptions,
128
131
  { data, field }: RenderFormParams,
129
132
  ) {
130
133
  if (valued(defaultValue) && valued(field) && noValue(data[field!])) {
131
- data[field!] = defaultValue;
134
+ data[field!] = defaultValue
132
135
  }
133
136
  return field ? (
134
137
  <DynamicComponent
@@ -137,19 +140,19 @@ const renderBasic = (name: string) => {
137
140
  {...attrs}
138
141
  {...merge({}, antDefaultProps[name], props)}
139
142
  onChange={(...arg) => {
140
- events.change?.({ data, field }, ...arg);
143
+ events.change?.({ data, field }, ...arg)
141
144
  }}
142
145
  />
143
146
  ) : (
144
147
  <DynamicComponent is={name} {...props} />
145
- );
148
+ )
146
149
  },
147
- renderDefault(
150
+ renderDefault (
148
151
  { props = antDefaultProps[name] ?? {}, attrs = {}, events = {}, defaultValue }: RenderOptions,
149
152
  { data, row, field }: RenderTableParams,
150
153
  ) {
151
154
  if (valued(defaultValue) && valued(field) && noValue(row[field!])) {
152
- row[field!] = defaultValue;
155
+ row[field!] = defaultValue
153
156
  }
154
157
  return field ? (
155
158
  <DynamicComponent
@@ -158,15 +161,15 @@ const renderBasic = (name: string) => {
158
161
  {...attrs}
159
162
  {...merge({}, antDefaultProps[name], props)}
160
163
  onChange={(...arg) => {
161
- events.change?.({ data, row, field }, ...arg);
164
+ events.change?.({ data, row, field }, ...arg)
162
165
  }}
163
166
  />
164
167
  ) : (
165
168
  <DynamicComponent is={name} {...props} />
166
- );
169
+ )
167
170
  },
168
- };
169
- };
171
+ }
172
+ }
170
173
 
171
174
  const renderBtn = (btnOpt: BtnOptions, params: RenderTableParams) =>
172
175
  btnOpt.dropdowns && btnOpt.dropdowns.length > 0 ? (
@@ -182,7 +185,7 @@ const renderBtn = (btnOpt: BtnOptions, params: RenderTableParams) =>
182
185
  'clickEvt',
183
186
  'dropdowns',
184
187
  ])}
185
- icon={btnOpt.icon ? <Icon icon={btnOpt.icon} /> : null}
188
+ icon={btnOpt.icon ? <Icon icon={btnOpt.icon}/> : null}
186
189
  >
187
190
  {btnOpt.content || (btnOpt?.getContent?.(params) ?? '')}
188
191
  </Button>
@@ -205,21 +208,21 @@ const renderBtn = (btnOpt: BtnOptions, params: RenderTableParams) =>
205
208
  'clickEvt',
206
209
  'dropdowns',
207
210
  ])}
208
- icon={btnOpt.icon ? <Icon icon={btnOpt.icon} /> : null}
211
+ icon={btnOpt.icon ? <Icon icon={btnOpt.icon}/> : null}
209
212
  onClick={() => {
210
213
  if (btnOpt?.clickEvt) {
211
- btnOpt.clickEvt(params);
214
+ btnOpt.clickEvt(params)
212
215
  }
213
216
  }}
214
217
  >
215
218
  {btnOpt.content || (btnOpt?.getContent?.(params) ?? '')}
216
219
  </Button>
217
- );
220
+ )
218
221
  const renders = {
219
222
  ...Object.fromEntries(Object.keys(componentsMap).map((name) => [name, renderBasic(name)])),
220
223
  //简单按钮
221
224
  $button: {
222
- renderItemContent(
225
+ renderItemContent (
223
226
  { props = {}, events = {} }: RenderOptions,
224
227
  { data, field }: RenderFormParams,
225
228
  defaultHandler: {
@@ -229,19 +232,19 @@ const renders = {
229
232
  return (
230
233
  <Button
231
234
  {...omit(props, ['content'])}
232
- icon={props.icon ? <Icon icon={props.icon} /> : null}
235
+ icon={props.icon ? <Icon icon={props.icon}/> : null}
233
236
  onClick={() => {
234
- events.click?.({ data, field });
237
+ events.click?.({ data, field })
235
238
  if (props.htmlType === 'reset' && defaultHandler?.reset) {
236
- defaultHandler.reset({ data, field });
239
+ defaultHandler.reset({ data, field })
237
240
  }
238
241
  }}
239
242
  >
240
243
  {props.content}
241
244
  </Button>
242
- );
245
+ )
243
246
  },
244
- renderDefault(
247
+ renderDefault (
245
248
  { props = {}, events = {} }: RenderOptions,
246
249
  { row, field }: RenderTableParams,
247
250
  defaultHandler: {
@@ -251,25 +254,25 @@ const renders = {
251
254
  return (
252
255
  <Button
253
256
  {...omit(props, ['content'])}
254
- icon={props.icon ? <Icon icon={props.icon} /> : null}
257
+ icon={props.icon ? <Icon icon={props.icon}/> : null}
255
258
  onClick={() => {
256
- events.click?.({ row, field });
259
+ events.click?.({ row, field })
257
260
  if (props.htmlType === 'reset' && defaultHandler?.reset) {
258
- defaultHandler.reset({ row, field });
261
+ defaultHandler.reset({ row, field })
259
262
  }
260
263
  if (props.htmlType === 'pick' && defaultHandler?.pick) {
261
- defaultHandler.pick({ row, field });
264
+ defaultHandler.pick({ row, field })
262
265
  }
263
266
  }}
264
267
  >
265
268
  {props.content}
266
269
  </Button>
267
- );
270
+ )
268
271
  },
269
272
  },
270
273
  // 简单按钮组
271
274
  $buttons: {
272
- renderItemContent(
275
+ renderItemContent (
273
276
  { props = {}, children = [] }: RenderOptions,
274
277
  { data, field }: RenderFormParams,
275
278
  defaultHandler: {
@@ -281,11 +284,11 @@ const renders = {
281
284
  {children.map((m) => (
282
285
  <Button
283
286
  {...omit(Object.assign(props, m.props), ['content'])}
284
- icon={m.props.icon ? <Icon icon={m.props.icon} /> : null}
287
+ icon={m.props.icon ? <Icon icon={m.props.icon}/> : null}
285
288
  onClick={() => {
286
- m.events?.click?.({ data, field });
289
+ m.events?.click?.({ data, field })
287
290
  if (m.props.htmlType === 'reset' && defaultHandler?.reset) {
288
- defaultHandler.reset({ data, field });
291
+ defaultHandler.reset({ data, field })
289
292
  }
290
293
  }}
291
294
  >
@@ -293,9 +296,9 @@ const renders = {
293
296
  </Button>
294
297
  ))}
295
298
  </span>
296
- );
299
+ )
297
300
  },
298
- renderDefault(
301
+ renderDefault (
299
302
  { props = {}, children = [] }: RenderOptions,
300
303
  { data, row, field }: RenderTableParams,
301
304
  ) {
@@ -304,49 +307,67 @@ const renders = {
304
307
  {children.map((m) => (
305
308
  <Button
306
309
  {...omit(Object.assign(props, m.props), ['content'])}
307
- icon={m.props.icon ? <Icon icon={m.props.icon} /> : null}
310
+ icon={m.props.icon ? <Icon icon={m.props.icon}/> : null}
308
311
  onClick={() => {
309
- m.events?.click?.({ data, row, field });
312
+ m.events?.click?.({ data, row, field })
310
313
  }}
311
314
  >
312
315
  {m.props.content}
313
316
  </Button>
314
317
  ))}
315
318
  </span>
316
- );
319
+ )
317
320
  },
318
321
  },
319
322
  ButtonTree: {
320
- renderDefault({ children = [], props = {} as Recordable }, params: RenderTableParams) {
323
+ renderDefault ({ children = [], props = {} as Recordable }, params: RenderTableParams) {
321
324
  return (
322
325
  <span class={props.noGap ? 'align-no-gap-box' : 'align-gap-box'}>
323
326
  {(children as BtnOptions[]).map((item) => renderBtn(item, params)) ?? []}
324
327
  </span>
325
- );
328
+ )
326
329
  },
327
330
  },
328
331
  $radio: {
329
- renderItemContent({ props = {}, options }: RenderOptions, { data, field }: RenderFormParams) {
332
+ renderItemContent ({ props = {}, options }: RenderOptions, { data, field }: RenderFormParams) {
330
333
  return valued(field) ? (
331
334
  <RadioGroup
332
335
  v-model:value={data[field!]}
333
336
  {...props}
334
337
  options={props.options ?? options ?? []}
335
338
  />
336
- ) : null;
339
+ ) : null
337
340
  },
338
- renderDefault({ props = {}, options }: RenderOptions, { row, field }: RenderTableParams) {
341
+ renderDefault ({ props = {}, options }: RenderOptions, { row, field }: RenderTableParams) {
339
342
  return valued(field) ? (
340
343
  <RadioGroup
341
344
  v-model:value={row[field!]}
342
345
  {...props}
343
346
  options={props.options ?? options ?? []}
344
347
  />
345
- ) : null;
348
+ ) : null
346
349
  },
347
350
  },
351
+ $autoComplete: {
352
+ renderItemContent ({ props = {}, events = {} }: RenderOptions, {
353
+ data,
354
+ field
355
+ }: RenderFormParams) {
356
+ return (valued(field) ?
357
+ <AutoComplete v-model:value={data[field!]} {...props}
358
+ onChange={(...arg) => {
359
+ events.change?.({ data, field }, ...arg)
360
+ }}>
361
+ {{
362
+ default: () =>
363
+ <a-input {...(Object.assign({}, defaultProps.autoComplete.inputProps, props.inputProps ?? {}))}/>
364
+ }}
365
+
366
+ </AutoComplete> : null)
367
+ }
368
+ },
348
369
  $switch: {
349
- renderItemContent(
370
+ renderItemContent (
350
371
  { props = {}, events = {} }: RenderOptions,
351
372
  { data, field }: RenderFormParams,
352
373
  ) {
@@ -355,14 +376,14 @@ const renders = {
355
376
  v-model:checked={data[field!]}
356
377
  {...props}
357
378
  onChange={(...arg) => {
358
- events.change?.({ data, field }, ...arg);
379
+ events.change?.({ data, field }, ...arg)
359
380
  }}
360
381
  />
361
- ) : null;
382
+ ) : null
362
383
  },
363
384
  },
364
385
  $checkbox: {
365
- renderItemContent(
386
+ renderItemContent (
366
387
  { props = {}, options, events = {} }: RenderOptions,
367
388
  { data, field }: RenderFormParams,
368
389
  ) {
@@ -372,40 +393,40 @@ const renders = {
372
393
  {...props}
373
394
  options={props.options ?? options ?? []}
374
395
  onChange={(...arg) => {
375
- events.change?.({ data, field }, ...arg);
396
+ events.change?.({ data, field }, ...arg)
376
397
  }}
377
398
  />
378
- ) : null;
399
+ ) : null
379
400
  },
380
- renderDefault({ props = {}, options }: RenderOptions, { row, field }: RenderTableParams) {
401
+ renderDefault ({ props = {}, options }: RenderOptions, { row, field }: RenderTableParams) {
381
402
  return valued(field) ? (
382
403
  <CheckboxGroup
383
404
  v-model:value={row[field!]}
384
405
  {...props}
385
406
  options={props.options ?? options ?? []}
386
407
  />
387
- ) : null;
408
+ ) : null
388
409
  },
389
410
  },
390
411
  $paragraph: {
391
- renderDefault({ props = {} }: RenderOptions, { row, field }: RenderTableParams) {
412
+ renderDefault ({ props = {} }: RenderOptions, { row, field }: RenderTableParams) {
392
413
  const defaultProps = {
393
414
  ellipsis: {
394
415
  expandable: true,
395
416
  rows: 3,
396
417
  },
397
- };
398
- const content = props.getContent?.({ row, field }) ?? (valued(field) ? row[field!] : '');
418
+ }
419
+ const content = props.getContent?.({ row, field }) ?? (valued(field) ? row[field!] : '')
399
420
  return valued(field) ? (
400
421
  <TypographyParagraph
401
422
  {...merge({}, defaultProps, omit(props, ['content', 'getContent']))}
402
423
  content={content}
403
424
  />
404
- ) : null;
425
+ ) : null
405
426
  },
406
427
  },
407
428
  $tableInput: {
408
- renderItemContent(
429
+ renderItemContent (
409
430
  { props = {}, handleTrigger }: RenderOptions,
410
431
  { data, field }: RenderFormParams,
411
432
  ) {
@@ -414,28 +435,28 @@ const renders = {
414
435
  v-model={data[field!]}
415
436
  onTrigger={() => {
416
437
  if (handleTrigger && isFunction(handleTrigger)) {
417
- handleTrigger(props.cusFields ?? field);
438
+ handleTrigger(props.cusFields ?? field)
418
439
  }
419
440
  }}
420
441
  editColumns={props.editColumns ?? []}
421
442
  tableConfig={props.tableConfig ?? {}}
422
443
  />
423
- ) : null;
444
+ ) : null
424
445
  },
425
446
  },
426
447
  PercentInput: {
427
- renderItemContent(
448
+ renderItemContent (
428
449
  { props = {}, attrs = {} }: RenderOptions,
429
450
  { data, field }: RenderFormParams,
430
451
  ) {
431
- const rate = props.parse ? 100 : 1;
452
+ const rate = props.parse ? 100 : 1
432
453
  if (valued(field)) {
433
454
  const percentage = computed({
434
455
  get: () => (data[field!] ?? 0) * rate,
435
456
  set: (val) => {
436
- data[field!] = (val ?? 0) / rate;
457
+ data[field!] = (val ?? 0) / rate
437
458
  },
438
- });
459
+ })
439
460
  return (
440
461
  <div class="flex items-center">
441
462
  {props.info ? <span class="pr-4">{props.info}</span> : null}
@@ -446,20 +467,20 @@ const renders = {
446
467
  {...merge({}, defaultProps.PercentInput, omit(props, ['info']))}
447
468
  />
448
469
  </div>
449
- );
470
+ )
450
471
  } else {
451
- return null;
472
+ return null
452
473
  }
453
474
  },
454
- renderDefault({ props = {}, attrs = {} }: RenderOptions, { row, field }: RenderTableParams) {
455
- const rate = props.parse ? 100 : 1;
475
+ renderDefault ({ props = {}, attrs = {} }: RenderOptions, { row, field }: RenderTableParams) {
476
+ const rate = props.parse ? 100 : 1
456
477
  if (valued(field)) {
457
478
  const percentage = computed({
458
479
  get: () => (row[field!] ?? 0) * rate,
459
480
  set: (val) => {
460
- set(row, field!, (val ?? 0) / rate);
481
+ set(row, field!, (val ?? 0) / rate)
461
482
  },
462
- });
483
+ })
463
484
  return [
464
485
  props.info ? <span class="pr-4">{props.info}</span> : null,
465
486
  <a-input-number
@@ -468,21 +489,21 @@ const renders = {
468
489
  v-model:value={percentage.value}
469
490
  {...merge({}, defaultProps.PercentInput, omit(props, ['info']))}
470
491
  />,
471
- ];
492
+ ]
472
493
  } else {
473
- return null;
494
+ return null
474
495
  }
475
496
  },
476
497
  },
477
498
  TreeSelect: {
478
- renderItemContent({ props = {} }: RenderOptions, { data, field }: RenderFormParams) {
479
- return valued(field) ? <TreeSelect v-model:value={data[field!]} {...props} /> : null;
499
+ renderItemContent ({ props = {} }: RenderOptions, { data, field }: RenderFormParams) {
500
+ return valued(field) ? <TreeSelect v-model:value={data[field!]} {...props} /> : null
480
501
  },
481
- renderDefault({ props = {} }: RenderOptions, { row, field }: RenderTableParams) {
482
- return valued(field) ? <TreeSelect v-model:value={row[field!]} {...props} /> : null;
502
+ renderDefault ({ props = {} }: RenderOptions, { row, field }: RenderTableParams) {
503
+ return valued(field) ? <TreeSelect v-model:value={row[field!]} {...props} /> : null
483
504
  },
484
505
  },
485
- };
506
+ }
486
507
  export const addRender = (
487
508
  name: string,
488
509
  {
@@ -502,14 +523,14 @@ export const addRender = (
502
523
  },
503
524
  ) => {
504
525
  if (renders.hasOwnProperty(name)) {
505
- console.warn(`render ${name} already exists`);
526
+ console.warn(`render ${name} already exists`)
506
527
  }
507
528
  renders[name] = {
508
529
  renderItemContent,
509
530
  renderDefault,
510
- };
511
- };
531
+ }
532
+ }
512
533
  export default {
513
534
  renders,
514
535
  addRender,
515
- };
536
+ }