knt-shared 1.2.2 → 1.2.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.
- package/dist/components/Form/useForm.d.ts +1 -4
- package/dist/components/Form/useForm.d.ts.map +1 -1
- package/dist/components/Modal/useModal.d.ts.map +1 -1
- package/dist/index.cjs.js +46 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +46 -5
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,10 +6,7 @@ import { FormSchema, UseFormOptions, UseFormReturn } from './types';
|
|
|
6
6
|
* @param options 表单配置选项
|
|
7
7
|
* @returns [register, formMethods]
|
|
8
8
|
*/
|
|
9
|
-
export declare function useForm(options?: UseFormOptions): [
|
|
10
|
-
(formInstance: any) => void,
|
|
11
|
-
Omit<UseFormReturn, 'register'>
|
|
12
|
-
];
|
|
9
|
+
export declare function useForm(options?: UseFormOptions): [(formInstance: any) => void, Omit<UseFormReturn, 'register'>];
|
|
13
10
|
/**
|
|
14
11
|
* 创建表单配置
|
|
15
12
|
* 用于快速创建表单 schema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../src/components/Form/useForm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAEzF;;;;;GAKG;AACH,wBAAgB,OAAO,
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../src/components/Form/useForm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,SAAS,CAAC;AAEzF;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,OAAO,GAAE,cAAmB,GAC3B,CAAC,CAAC,YAAY,EAAE,GAAG,KAAK,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAmWhE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,OAAO,EAAE,UAAU,EAAE,EAAE,GAAG,UAAU,EAAE,CAEzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/useModal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAA0B,MAAM,SAAS,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"useModal.d.ts","sourceRoot":"","sources":["../../../src/components/Modal/useModal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAA0B,MAAM,SAAS,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,kBAAkB,CA2F7E"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1621,6 +1621,8 @@ function useForm(options = {}) {
|
|
|
1621
1621
|
const formModel = vue.reactive({});
|
|
1622
1622
|
const loadedRef = vue.ref(false);
|
|
1623
1623
|
const propsRef = vue.ref({});
|
|
1624
|
+
const pendingValues = vue.ref(null);
|
|
1625
|
+
let unwatchFormRef = null;
|
|
1624
1626
|
const initFormModel = () => {
|
|
1625
1627
|
var _a, _b;
|
|
1626
1628
|
const schemas = vue.unref(((_b = (_a = formRef.value) == null ? void 0 : _a.getSchema) == null ? void 0 : _b.call(_a)) || options.schemas || []);
|
|
@@ -1632,12 +1634,38 @@ function useForm(options = {}) {
|
|
|
1632
1634
|
};
|
|
1633
1635
|
const register = async (formInstance) => {
|
|
1634
1636
|
await vue.nextTick();
|
|
1637
|
+
if (unwatchFormRef) {
|
|
1638
|
+
unwatchFormRef();
|
|
1639
|
+
unwatchFormRef = null;
|
|
1640
|
+
}
|
|
1635
1641
|
formRef.value = formInstance;
|
|
1636
1642
|
loadedRef.value = true;
|
|
1637
1643
|
if (options && Object.keys(options).length > 0) {
|
|
1638
1644
|
await setProps(options);
|
|
1639
1645
|
}
|
|
1640
1646
|
initFormModel();
|
|
1647
|
+
if (formInstance.formRef) {
|
|
1648
|
+
unwatchFormRef = vue.watch(
|
|
1649
|
+
() => formInstance.formRef.value,
|
|
1650
|
+
(val) => {
|
|
1651
|
+
if (val === null) {
|
|
1652
|
+
console.log("表单组件已卸载,重置 useForm 状态");
|
|
1653
|
+
formRef.value = null;
|
|
1654
|
+
loadedRef.value = false;
|
|
1655
|
+
if (unwatchFormRef) {
|
|
1656
|
+
unwatchFormRef();
|
|
1657
|
+
unwatchFormRef = null;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
{ flush: "sync" }
|
|
1662
|
+
// 同步执行,确保及时清理
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
if (pendingValues.value) {
|
|
1666
|
+
await setFieldsValue(pendingValues.value);
|
|
1667
|
+
pendingValues.value = null;
|
|
1668
|
+
}
|
|
1641
1669
|
};
|
|
1642
1670
|
const getForm = () => {
|
|
1643
1671
|
const form = vue.unref(formRef);
|
|
@@ -1649,7 +1677,16 @@ function useForm(options = {}) {
|
|
|
1649
1677
|
return form;
|
|
1650
1678
|
};
|
|
1651
1679
|
const getFormSafe = () => {
|
|
1652
|
-
|
|
1680
|
+
var _a;
|
|
1681
|
+
const form = vue.unref(formRef);
|
|
1682
|
+
if (!form) return null;
|
|
1683
|
+
if (((_a = form.formRef) == null ? void 0 : _a.value) === null) {
|
|
1684
|
+
console.log("检测到失效的表单实例,清理引用");
|
|
1685
|
+
formRef.value = null;
|
|
1686
|
+
loadedRef.value = false;
|
|
1687
|
+
return null;
|
|
1688
|
+
}
|
|
1689
|
+
return form;
|
|
1653
1690
|
};
|
|
1654
1691
|
const getFieldsValue = () => {
|
|
1655
1692
|
const form = getFormSafe();
|
|
@@ -1661,7 +1698,10 @@ function useForm(options = {}) {
|
|
|
1661
1698
|
};
|
|
1662
1699
|
const setFieldsValue = async (values) => {
|
|
1663
1700
|
const form = getFormSafe();
|
|
1664
|
-
if (!form)
|
|
1701
|
+
if (!form) {
|
|
1702
|
+
pendingValues.value = { ...pendingValues.value, ...values };
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1665
1705
|
if (form.setFieldsValue) {
|
|
1666
1706
|
await form.setFieldsValue(values);
|
|
1667
1707
|
} else {
|
|
@@ -3733,9 +3773,7 @@ function useModal(props) {
|
|
|
3733
3773
|
const openModal = (visible = true, data) => {
|
|
3734
3774
|
const modal = getModal();
|
|
3735
3775
|
if (!modal) return;
|
|
3736
|
-
|
|
3737
|
-
modal.setModalProps({ _data: data });
|
|
3738
|
-
}
|
|
3776
|
+
modal.setModalProps({ _data: data });
|
|
3739
3777
|
if (visible) {
|
|
3740
3778
|
modal.openModal();
|
|
3741
3779
|
} else {
|
|
@@ -3746,6 +3784,9 @@ function useModal(props) {
|
|
|
3746
3784
|
const modal = getModal();
|
|
3747
3785
|
if (!modal) return;
|
|
3748
3786
|
modal.closeModal();
|
|
3787
|
+
setTimeout(() => {
|
|
3788
|
+
modal.setModalProps({ _data: void 0 });
|
|
3789
|
+
});
|
|
3749
3790
|
};
|
|
3750
3791
|
const setModalProps = (modalProps) => {
|
|
3751
3792
|
const modal = getModal();
|