@vue-ui-kit/ant 2.0.6 → 2.0.7

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,8 +1,10 @@
1
1
  import { ColumnProps, Responsive } from '../../declarations/antProxy';
2
2
  import { TableColumnGroupType, TableColumnType } from 'ant-design-vue';
3
+ import { WatchOptions, WatchSource } from 'vue';
3
4
  export declare const cleanCol: (col: ColumnProps) => TableColumnType | TableColumnGroupType<Recordable>;
4
5
  export declare const defaultItemResponsive: Responsive;
5
6
  export declare const defaultLabelCol: Responsive;
6
7
  export declare const labelColDict: Record<number, Responsive>;
7
8
  export declare const get24rest: (exist: number[]) => number;
8
9
  export declare const getButtonResponsive: (itemResponsive: number | Responsive[]) => any;
10
+ export declare function watchPreviousDeep<T extends object>(source: WatchSource<T>, cb: (value: T, oldValue: T, onCleanup: () => void) => void, options?: WatchOptions): import('vue').WatchHandle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-ui-kit/ant",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Vue3 UI Kit based on Ant Design",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -21,6 +21,7 @@
21
21
  import { v4 as uuidv4 } from 'uuid';
22
22
  import { antFormatters } from '@/utils/AFormatters';
23
23
  import { getCanvasTableDefaults } from '@/utils/config';
24
+ import { watchPreviousDeep } from '@/utils/core';
24
25
 
25
26
  const emit = defineEmits<{
26
27
  (e: 'change', value: any[]): void; // 需要默认实现change,不能动态绑定
@@ -197,7 +198,7 @@
197
198
  },
198
199
  { deep: true },
199
200
  );
200
- watch(
201
+ watchPreviousDeep(
201
202
  () => props.columns,
202
203
  (newValue, oldValue) => {
203
204
  if (!isEqual(newValue, oldValue)) {
@@ -1,46 +1,50 @@
1
1
  <script setup lang="ts" generic="T extends Recordable = Recordable">
2
- import type { PFormItemProps } from '#/antProxy'
3
- import { defaultItemResponsive } from '@/utils/core';
4
- import RenderAntItem from '@/components/RenderAntItem';
5
- import RenderItemSlots from '@/components/RenderItemSlots';
6
- import { InfoCircleOutlined } from '@ant-design/icons-vue'
7
- import { v4 as uuid_v4 } from 'uuid'
8
- import { ref, watch } from 'vue'
9
- import { isEqual,debounce, isFunction, omit } from 'xe-utils'
2
+ import type { PFormItemProps } from '#/antProxy';
3
+ import { defaultItemResponsive, watchPreviousDeep } from '@/utils/core';
4
+ import RenderAntItem from '@/components/RenderAntItem';
5
+ import RenderItemSlots from '@/components/RenderItemSlots';
6
+ import { InfoCircleOutlined } from '@ant-design/icons-vue';
7
+ import { v4 as uuid_v4 } from 'uuid';
8
+ import { ref } from 'vue';
9
+ import { isEqual, debounce, isFunction, omit } from 'xe-utils';
10
10
 
11
- const props = defineProps<{
12
- item: PFormItemProps<T>
13
- formData: T
14
- }>()
15
- const emit = defineEmits<{
16
- (e: 'trigger', cusFields?: string | string[]): void
17
- (e: 'reset'): void
18
- }>()
19
- const hangOut = ref(false)
20
- const renderFormKey = ref(uuid_v4())
21
- const handleDelayTrigger = (cusFields?: string | string[], time?: number) => {
22
- const delayTime = time ?? 222
23
- hangOut.value = true
24
- setTimeout(() => {
25
- hangOut.value = false
26
- emit('trigger', cusFields)
27
- }, delayTime)
28
- }
29
- const handleTrigger = (cusFields?: string | string[]) => {
30
- emit('trigger', cusFields)
31
- }
32
- const resetFormData = () => {
33
- emit('reset')
34
- }
35
- const refreshCol = () => {
36
- renderFormKey.value = uuid_v4()
37
- }
38
- const debounceRefreshCol = debounce(refreshCol, 100)
39
- watch(() => props.item, (cur, old) => {
40
- if (!isEqual(cur, old)) {
41
- debounceRefreshCol()
42
- }
43
- }, { deep: true })
11
+ const props = defineProps<{
12
+ item: PFormItemProps<T>;
13
+ formData: T;
14
+ }>();
15
+ const emit = defineEmits<{
16
+ (e: 'trigger', cusFields?: string | string[]): void;
17
+ (e: 'reset'): void;
18
+ }>();
19
+ const hangOut = ref(false);
20
+ const renderFormKey = ref(uuid_v4());
21
+ const handleDelayTrigger = (cusFields?: string | string[], time?: number) => {
22
+ const delayTime = time ?? 222;
23
+ hangOut.value = true;
24
+ setTimeout(() => {
25
+ hangOut.value = false;
26
+ emit('trigger', cusFields);
27
+ }, delayTime);
28
+ };
29
+ const handleTrigger = (cusFields?: string | string[]) => {
30
+ emit('trigger', cusFields);
31
+ };
32
+ const resetFormData = () => {
33
+ emit('reset');
34
+ };
35
+ const refreshCol = () => {
36
+ renderFormKey.value = uuid_v4();
37
+ };
38
+ const debounceRefreshCol = debounce(refreshCol, 100);
39
+ watchPreviousDeep(
40
+ () => props.item,
41
+ (cur, old) => {
42
+ if (!isEqual(cur, old)) {
43
+ debounceRefreshCol();
44
+ }
45
+ },
46
+ { deep: true },
47
+ );
44
48
  </script>
45
49
 
46
50
  <template>
@@ -58,7 +62,18 @@ watch(() => props.item, (cur, old) => {
58
62
  :label="item.title"
59
63
  :name="item.field"
60
64
  :wrapper-col="item.wrapperCol ?? (item.title ? undefined : { span: 24 })"
61
- v-bind="omit(item, ['field', 'title', 'span', 'col', 'wrapperCol', 'itemRender', 'forceRequired', 'tooltip'])"
65
+ v-bind="
66
+ omit(item, [
67
+ 'field',
68
+ 'title',
69
+ 'span',
70
+ 'col',
71
+ 'wrapperCol',
72
+ 'itemRender',
73
+ 'forceRequired',
74
+ 'tooltip',
75
+ ])
76
+ "
62
77
  >
63
78
  <template v-if="item.slots?.title" #label>
64
79
  <component :is="item.slots.title" />
@@ -82,7 +97,10 @@ watch(() => props.item, (cur, old) => {
82
97
  />
83
98
  <span v-else />
84
99
  <template v-if="item.tooltipConfig" #tooltip>
85
- <a-tooltip v-if="isFunction(item.tooltipConfig.title)" v-bind="omit(item.tooltipConfig, ['title'])">
100
+ <a-tooltip
101
+ v-if="isFunction(item.tooltipConfig.title)"
102
+ v-bind="omit(item.tooltipConfig, ['title'])"
103
+ >
86
104
  <info-circle-outlined class="cursor-pointer py-4 px-2" />
87
105
  <template #title>
88
106
  <div v-html="item.tooltipConfig.title()" />
@@ -52,7 +52,7 @@
52
52
  { content: '复制', code: 'copy' },
53
53
  { content: '删除', code: 'delete' },
54
54
  ];
55
- const getPopupContainer = (el) =>
55
+ const getPopupContainer = (el: HTMLElement) =>
56
56
  el?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement?.parentElement ??
57
57
  rootRef.value?.$el ??
58
58
  document.body;
@@ -1,7 +1,8 @@
1
1
  import { ColumnProps, Responsive } from '#/antProxy';
2
2
  import { TableColumnGroupType, TableColumnType } from 'ant-design-vue';
3
- import { isArray, isNumber, omit, zipObject } from 'xe-utils';
3
+ import { clone, isArray, isNumber, omit, zipObject } from 'xe-utils';
4
4
  import { valued } from '@/utils/is';
5
+ import { toValue, watch, WatchCallback, WatchOptions, WatchSource } from 'vue';
5
6
 
6
7
  export const cleanCol = (col: ColumnProps): TableColumnType | TableColumnGroupType<Recordable> => {
7
8
  return {
@@ -50,3 +51,23 @@ export const getButtonResponsive = (itemResponsive: number | Responsive[]) => {
50
51
  ),
51
52
  );
52
53
  };
54
+
55
+ export function watchPreviousDeep<T extends object>(
56
+ source: WatchSource<T>,
57
+ cb: (value: T, oldValue: T, onCleanup: () => void) => void,
58
+ options?: WatchOptions,
59
+ ) {
60
+ const val = toValue(source);
61
+ if (typeof val !== 'object' || val === null) {
62
+ return watch(source, cb as WatchCallback<T>, options);
63
+ }
64
+ let previousValue = clone(val) as T;
65
+ return watch(
66
+ source,
67
+ (crtValue, _, onCleanup) => {
68
+ cb(crtValue as T, previousValue, onCleanup as () => void);
69
+ previousValue = clone(crtValue) as T;
70
+ },
71
+ options,
72
+ );
73
+ }