@peng_kai/kit 0.2.6 → 0.2.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.
@@ -4,7 +4,7 @@ import type { Component } from 'vue';
4
4
  import type { ButtonProps, DrawerProps } from 'ant-design-vue';
5
5
  import type { ComponentProps } from 'vue-component-type-helpers';
6
6
  import type { Writable } from 'type-fest';
7
- import { useComponentRef } from '../../vue';
7
+ import { useTemplateRefs } from '../../vue';
8
8
 
9
9
  const defaultDrawerProps: DrawerProps = { open: false, destroyOnClose: true, rootClassName: 'antd-cover__basic-drawer' };
10
10
 
@@ -19,7 +19,9 @@ export function useAntdDrawer<Comp extends Component>(
19
19
  ) {
20
20
  const _comp = ({ props: {}, ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>;
21
21
  const compProps = reactive(_comp.props);
22
- const compRef = useComponentRef(_comp.is);
22
+ const [refs, setRefs] = useTemplateRefs<{
23
+ comp: typeof _comp.is
24
+ }>();
23
25
  const _drawerProps: DrawerProps = reactive({
24
26
  ...defaultDrawerProps,
25
27
  ...isProxy(drawerProps) ? toRefs(drawerProps) : drawerProps,
@@ -39,8 +41,8 @@ export function useAntdDrawer<Comp extends Component>(
39
41
  const cancelBtnProps: ButtonProps = reactive({ onClick: close });
40
42
  const confirmBtnProps: ButtonProps = reactive({
41
43
  type: 'primary',
42
- loading: toRef(() => (compRef as any)?.loading),
43
- onClick: () => (compRef as any)?.confirm?.(),
44
+ loading: toRef(() => (refs.comp as any)?.loading),
45
+ onClick: () => (refs.comp as any)?.confirm?.(),
44
46
  });
45
47
 
46
48
  return { cancelBtnProps, confirmBtnProps };
@@ -66,8 +68,16 @@ export function useAntdDrawer<Comp extends Component>(
66
68
  _drawerProps['onUpdate:open'] = (visiable) => {
67
69
  _drawerProps.open = visiable;
68
70
  };
69
- (compProps as any).ref = compRef;
71
+ (compProps as any).ref = setRefs.comp;
70
72
  (compProps as any).onClose = close;
71
73
 
72
- return { PresetComponent, drawerProps: _drawerProps, open, close };
74
+ return {
75
+ PresetComponent,
76
+ drawerProps: _drawerProps,
77
+ get $comp() {
78
+ return refs.comp;
79
+ },
80
+ open,
81
+ close,
82
+ };
73
83
  }
@@ -82,7 +82,20 @@ function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRe
82
82
 
83
83
  watch(itemProps, () => $form.clearValidate?.(), { flush: 'post', deep: true });
84
84
 
85
- watchEffect(() => {
85
+ // watchEffect(() => {
86
+ // const _state: any = {};
87
+
88
+ // for (const k in schemasR.value) {
89
+ // const item = schemasR.value[k];
90
+ // _state[k] = (k in state.value) ? toRef(state.value, k) : toRef(item, 'value');
91
+ // }
92
+
93
+ // console.log('🤡 / _state:', _state);
94
+ // state.value = _state;
95
+ // });
96
+
97
+ // 为什么之前用 watchEffect?
98
+ watch(schemasR, () => {
86
99
  const _state: any = {};
87
100
 
88
101
  for (const k in schemasR.value) {
@@ -90,8 +103,9 @@ function useAntdForm<S extends Record<string, unknown>, TS = S>(schemas: MaybeRe
90
103
  _state[k] = (k in state.value) ? toRef(state.value, k) : toRef(item, 'value');
91
104
  }
92
105
 
106
+ console.log('🤡 / _state:', _state);
93
107
  state.value = _state;
94
- });
108
+ }, { immediate: true });
95
109
 
96
110
  return reactive({ state, stateTF, show, props, itemProps, $form });
97
111
  }
@@ -4,7 +4,7 @@ import type { Component } from 'vue';
4
4
  import type { ModalProps } from 'ant-design-vue';
5
5
  import type { ComponentProps } from 'vue-component-type-helpers';
6
6
  import type { Writable } from 'type-fest';
7
- import { useComponentRef } from '../../vue';
7
+ import { useTemplateRefs } from '../../vue';
8
8
 
9
9
  const defaultModalProps: ModalProps = { open: false, destroyOnClose: true, wrapClassName: 'antd-cover__basic-modal' };
10
10
 
@@ -28,13 +28,15 @@ export function useAntdModal<Comp extends Component>(
28
28
  ) {
29
29
  const _comp = ({ props: {}, type: 'body', ...((comp as any)?.is ? comp : { is: comp }) }) as Required<IComponentConfig<Comp>>;
30
30
  const compProps = reactive(_comp.props);
31
- const compRef = useComponentRef(_comp.is);
31
+ const [refs, setRefs] = useTemplateRefs<{
32
+ comp: typeof _comp.is
33
+ }>();
32
34
  const _modalProps: ModalProps = reactive({
33
35
  ...defaultModalProps,
34
36
  ...isProxy(modalProps) ? toRefs(modalProps) : modalProps,
35
- confirmLoading: toRef(() => (compRef as any)?.loading),
37
+ confirmLoading: toRef(() => (refs.comp as any)?.loading),
36
38
  onOk: (e: MouseEvent) => {
37
- (compRef as any)?.confirm?.(e);
39
+ (refs.comp as any)?.confirm?.(e);
38
40
  modalProps.onOk?.(e);
39
41
  },
40
42
  });
@@ -61,8 +63,17 @@ export function useAntdModal<Comp extends Component>(
61
63
  _modalProps['onUpdate:open'] = (visiable) => {
62
64
  _modalProps.open = visiable;
63
65
  };
64
- (compProps as any).ref = compRef;
66
+ (compProps as any).ref = setRefs.comp;
65
67
  (compProps as any).onClose = close;
66
68
 
67
- return { PresetComponent, modalProps: _modalProps, compProps, $comp: compRef, open, close };
69
+ return {
70
+ PresetComponent,
71
+ modalProps: _modalProps,
72
+ compProps,
73
+ get $comp() {
74
+ return refs.comp;
75
+ },
76
+ open,
77
+ close,
78
+ };
68
79
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.6",
4
+ "version": "0.2.7",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",