@vue-ui-kit/ant 1.7.2 → 1.7.3

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.
@@ -11,7 +11,7 @@ declare const _default: <F = Recordable<any>>(__VLS_props: NonNullable<Awaited<t
11
11
  activeKey: import('vue').ComputedRef<number>;
12
12
  setActiveKey: (key: number) => void;
13
13
  validateAll: () => Promise<any[]>;
14
- validate: (index: any) => any;
14
+ validate: (__index: number) => any;
15
15
  }>): void;
16
16
  attrs: any;
17
17
  slots: ReturnType<() => {
@@ -44,6 +44,7 @@ declare const _default: <D = Recordable<any>, F = Recordable<any>>(__VLS_props:
44
44
  field?: string;
45
45
  }>;
46
46
  grid: import('vue').Ref<PGridInstance<D, Recordable<any>> | undefined, PGridInstance<D, Recordable<any>> | undefined>;
47
+ hide: () => void;
47
48
  }>): void;
48
49
  attrs: any;
49
50
  slots: ReturnType<() => {}>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-ui-kit/ant",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Vue3 UI Kit based on Ant Design",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -108,8 +108,10 @@ export interface PFormGroupProps<F = Recordable> {
108
108
  tabLabel?: string;
109
109
  editAble?: boolean;
110
110
  showAdd?: boolean;
111
+ forceRender?: boolean;
111
112
  /* 是否保持连续编号 */
112
113
  keepSerial?: boolean;
114
+ loading?: boolean;
113
115
  itemMenus?: Array<GroupMenuItem<F>>;
114
116
  creatItem?: ({ list }: { list?: Partial<F>[] }) => Promise<Partial<F>>;
115
117
  max?: number;
@@ -144,7 +146,7 @@ export interface ToolbarButtonProps extends PButtonProps {
144
146
 
145
147
  export interface ToolbarConfig {
146
148
  buttons?: Array<ToolbarButtonProps>;
147
- tools?: Array<{ code: string; icon: string; type?: ButtonType; disabled?: boolean }>;
149
+ tools?: Array<{ code: string; icon: string; type?: ButtonType; disabled?: boolean; size?: 'small' | 'large' | 'middle' }>;
148
150
  disabled?: boolean;
149
151
  }
150
152
 
@@ -279,7 +281,8 @@ export interface PFormInstance {
279
281
  export interface PromisePickerInstance<D = Recordable> {
280
282
  pick: () => Promise<{ row: D; field?: string }>;
281
283
  pickMultiple: () => Promise<D[]>;
282
- grid: PGridInstance<D>
284
+ grid: PGridInstance<D>;
285
+ hide: () => void;
283
286
  }
284
287
 
285
288
  export interface PFormBlockInstance {
@@ -2,6 +2,7 @@
2
2
  import { computed, nextTick, PropType, ref, watchEffect } from 'vue';
3
3
  import { PFormGroupProps, PFormBlockInstance } from '#/antProxy';
4
4
  import { MoreOutlined } from '@ant-design/icons-vue';
5
+ import { Form } from 'ant-design-vue'
5
6
  import { cloneDeep, toString, isFunction, omit, maxBy, debounce } from 'lodash-es';
6
7
  import PGroupBlock from '@/components/PGroupBlock.vue';
7
8
  import {
@@ -15,7 +16,9 @@
15
16
  } from 'ant-design-vue';
16
17
  import { valued } from '@/utils/is';
17
18
  import { MenuInfo } from 'ant-design-vue/es/menu/src/interface';
18
-
19
+ import { $warning } from '@/hooks/useMessage';
20
+
21
+ const useForm = Form.useForm
19
22
  const props = defineProps<PFormGroupProps<F>>();
20
23
  const model = defineModel({
21
24
  type: Array as PropType<Partial<F & { __index: number }>[]>,
@@ -44,6 +47,15 @@
44
47
  { content: '复制', code: 'copy' },
45
48
  { content: '删除', code: 'delete' },
46
49
  ];
50
+ // 实际是否强制渲染
51
+ const fr = computed(() => {
52
+ return props.forceRender || model.value.length <= 5
53
+ })
54
+ const handleTabChange = () => {
55
+ nextTick().then(() => {
56
+ blockInstance.value[activeKey.value]?.$form?.validate()
57
+ })
58
+ }
47
59
  watchEffect(() => {
48
60
  if (!props.keepSerial) {
49
61
  const unSortItems = model.value.filter((f) => !valued(f.__index));
@@ -70,6 +82,10 @@
70
82
  });
71
83
  break;
72
84
  case 'copy':
85
+ if (model.value.length >= maxLen.value) {
86
+ $warning('已达到最大数量')
87
+ return
88
+ }
73
89
  model.value = [
74
90
  ...model.value,
75
91
  cloneDeep({
@@ -93,18 +109,22 @@
93
109
  activeKey: computed(() => activeKey.value),
94
110
  setActiveKey,
95
111
  validateAll: () => {
96
- return Promise.all(
97
- blockInstance.value.map((block) => block.$form?.validate() ?? Promise.resolve()),
98
- );
112
+ return Promise.all(blockInstance.value.map((block, idx) =>
113
+ fr.value ? (block.$form?.validate() ?? Promise.resolve()) : (useForm(model.value[idx], props.getFormSetting(model.value[idx]).rules)?.validate() ?? Promise.resolve()),
114
+ ))
99
115
  },
100
- validate: (index) => {
101
- return blockInstance.value[index]?.$form?.validate()
116
+ validate: (__index: number) => {
117
+ const index = model.value.findIndex(f => f.__index === __index)
118
+ return fr.value
119
+ ? (blockInstance.value[index]?.$form?.validate() ?? Promise.resolve())
120
+ : (useForm(model.value[index], props.getFormSetting(model.value[index]).rules)?.validate() ?? Promise.resolve())
102
121
  },
103
122
  });
104
123
  </script>
105
124
  <template>
106
125
  <a-card :title="title" size="small">
107
- <a-tabs type="editable-card" v-model:activeKey="activeKey" hide-add>
126
+ <a-spin v-if="loading" class="w-full" />
127
+ <a-tabs v-else type="editable-card" v-model:activeKey="activeKey" hide-add @change="handleTabChange">
108
128
  <template #rightExtra>
109
129
  <slot name="rightExtra">
110
130
  <a-button
@@ -120,7 +140,7 @@
120
140
  v-for="(item, idx) in model"
121
141
  :key="idx"
122
142
  :tab="`${tabLabel} ${keepSerial ? idx + 1 : (item.__index ?? 0) + 1}`"
123
- force-render
143
+ :force-render="fr"
124
144
  >
125
145
  <template #closeIcon>
126
146
  <a-dropdown v-if="editAble && itemMenus?.length">
@@ -592,7 +592,7 @@
592
592
  v-for="(tool, idx) in toolbarConfig.tools"
593
593
  :key="idx"
594
594
  :type="tool.type"
595
- :size="btn.size ?? 'middle'"
595
+ :size="tool.size ?? 'middle'"
596
596
  :disabled="toolbarConfig.disabled || tool.disabled"
597
597
  @click="debounceToolToolClick(tool.code)"
598
598
  :loading="loading.toolbar || (!!tool.code && codeLoadings[tool.code])"
@@ -603,7 +603,7 @@
603
603
  </span>
604
604
  </div>
605
605
  <div :class="`p-pane flex-1 ${enoughSpacing ? 'h-0' : ''} p-${scrollMode ?? 'inner'}-scroll`">
606
- <div v-if="selectConfig?.multiple && selectConfig.showCount" class="w-100p text-slate-5 pl-4">
606
+ <div v-if="selectConfig?.multiple && selectConfig.showCount" class="w-full text-slate-5 pl-4">
607
607
  已选:{{ selectedRowKeys.length }}
608
608
  </div>
609
609
  <a-table
@@ -78,7 +78,10 @@
78
78
  rejectPromise = reject;
79
79
  visible.modal = true;
80
80
  }),
81
- grid: gridEl,
81
+ grid: gridEl,
82
+ hide: () => {
83
+ visible.modal = false;
84
+ }
82
85
  });
83
86
  </script>
84
87
  <template>
@@ -34,6 +34,7 @@ interface BtnOptions extends ButtonProps {
34
34
  dynamicClassName?: (p: RenderTableParams) => string;
35
35
  dropdowns?: BtnOptions[];
36
36
  clickEvt?: (p: RenderTableParams) => any;
37
+ hiddenIf?: (p: RenderTableParams) => boolean;
37
38
  }
38
39
 
39
40
  const antDefaultProps = {
@@ -236,8 +237,8 @@ const renders = {
236
237
  events.click?.({ data, field })
237
238
  if (props.htmlType === 'reset' && defaultHandler?.reset) {
238
239
  if (props.beforeClick && isFunction(props.beforeClick)) {
239
- props.beforeClick({ data, field }).then(() => {
240
- defaultHandler.reset({ data, field })
240
+ props.beforeClick({ data, field }).then((res: void | Recordable) => {
241
+ defaultHandler.reset(res ? { data: res, field } : { data, field })
241
242
  })
242
243
  }
243
244
  else {
@@ -268,8 +269,8 @@ const renders = {
268
269
  if (props.htmlType === 'reset' && defaultHandler?.reset) {
269
270
  if (props.beforeClick && isFunction(props.beforeClick)) {
270
271
  defaultHandler?.setLoadings?.(true)
271
- props.beforeClick({ row, field }).then(() => {
272
- defaultHandler.reset({ row, field })
272
+ props.beforeClick({ row, field }).then((res: void | Recordable) => {
273
+ defaultHandler.reset(res ? { row: res, field } : { row, field })
273
274
  }).finally(() => {
274
275
  defaultHandler?.setLoadings?.(false)
275
276
  })
@@ -281,8 +282,8 @@ const renders = {
281
282
  if (props.htmlType === 'pick' && defaultHandler?.pick) {
282
283
  if (props.beforeClick && isFunction(props.beforeClick)) {
283
284
  defaultHandler?.setLoadings?.(true)
284
- props.beforeClick({ row, field }).then(() => {
285
- defaultHandler.pick({ row, field })
285
+ props.beforeClick({ row, field }).then((res: void | Recordable) => {
286
+ defaultHandler.pick(res ? { row: res, field } : { row, field })
286
287
  }).finally(() => {
287
288
  defaultHandler?.setLoadings?.(false)
288
289
  })
@@ -318,8 +319,8 @@ const renders = {
318
319
  m.events?.click?.({ data, field })
319
320
  if (m.props.htmlType === 'reset' && defaultHandler?.reset) {
320
321
  if (props.beforeClick && isFunction(props.beforeClick)) {
321
- props.beforeClick({ data, field }).then(() => {
322
- defaultHandler.reset({ data, field })
322
+ props.beforeClick({ data, field }).then((res: void | Recordable) => {
323
+ defaultHandler.reset(res ? { data: res, field } : { data, field })
323
324
  })
324
325
  }
325
326
  else {
@@ -328,8 +329,8 @@ const renders = {
328
329
  }
329
330
  if (m.props.htmlType === 'pick' && defaultHandler?.pick) {
330
331
  if (props.beforeClick && isFunction(props.beforeClick)) {
331
- props.beforeClick({ data, field }).then(() => {
332
- defaultHandler.pick({ data, field })
332
+ props.beforeClick({ data, field }).then((res: void | Recordable) => {
333
+ defaultHandler.pick(res ? { data: res, field } : { data, field })
333
334
  })
334
335
  }
335
336
  else {
@@ -369,8 +370,8 @@ const renders = {
369
370
  if (m.props.htmlType === 'reset' && defaultHandler?.reset) {
370
371
  if (props.beforeClick && isFunction(props.beforeClick)) {
371
372
  defaultHandler?.setLoadings?.(true)
372
- props.beforeClick({ row, field }).then(() => {
373
- defaultHandler.reset({ row, field })
373
+ props.beforeClick({ row, field }).then((res: void | Recordable) => {
374
+ defaultHandler.reset(res ? { row: res, field } : { row, field })
374
375
  }).finally(() => {
375
376
  defaultHandler?.setLoadings?.(false)
376
377
  })
@@ -382,8 +383,8 @@ const renders = {
382
383
  if (m.props.htmlType === 'pick' && defaultHandler?.pick) {
383
384
  if (props.beforeClick && isFunction(props.beforeClick)) {
384
385
  defaultHandler?.setLoadings?.(true)
385
- props.beforeClick({ row, field }).then(() => {
386
- defaultHandler.pick({ row, field })
386
+ props.beforeClick({ row, field }).then((res: void | Recordable) => {
387
+ defaultHandler.pick(res ? { row: res, field } : { row, field })
387
388
  }).finally(() => {
388
389
  defaultHandler?.setLoadings?.(false)
389
390
  })