knt-shared 1.2.1 → 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/index.esm.js CHANGED
@@ -703,9 +703,10 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
703
703
  autoUpload: { type: Boolean, default: true },
704
704
  resultType: { default: "fileList" },
705
705
  uploadButtonText: {},
706
- uploadButtonType: { default: "primary" }
706
+ uploadButtonType: { default: "primary" },
707
+ responseUrlKey: { type: [String, Function], default: void 0 }
707
708
  },
708
- emits: ["register", "update:modelValue", "change", "success", "error", "progress", "remove", "preview", "exceed"],
709
+ emits: ["register", "update:modelValue", "change", "success", "handleSuccess", "error", "handlError", "progress", "remove", "preview", "exceed"],
709
710
  setup(__props, { expose: __expose, emit: __emit }) {
710
711
  const props = __props;
711
712
  const emit = __emit;
@@ -713,7 +714,6 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
713
714
  const fileListRef = ref([]);
714
715
  const propsRef = ref({});
715
716
  const hasShownActionError = ref(false);
716
- const isInternalUpdate = ref(false);
717
717
  const processedFiles = ref(/* @__PURE__ */ new Map());
718
718
  const getProps = computed(() => {
719
719
  return { ...props, ...unref(propsRef) };
@@ -930,7 +930,6 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
930
930
  };
931
931
  };
932
932
  const handleChange = (fileList, currentFile) => {
933
- if (isInternalUpdate.value) return;
934
933
  const oldLength = fileListRef.value.length;
935
934
  const newLength = fileList.length;
936
935
  fileListRef.value = fileList;
@@ -940,11 +939,11 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
940
939
  const lastStatus = processedFiles.value.get(fileKey);
941
940
  if (currentFile.status === "done" && lastStatus !== "done" && !isRemove) {
942
941
  processedFiles.value.set(fileKey, "done");
943
- emit("success", currentFile.response, currentFile);
942
+ emit("handleSuccess", currentFile.response, currentFile);
944
943
  } else if (currentFile.status === "error" && lastStatus !== "error") {
945
944
  processedFiles.value.set(fileKey, "error");
946
945
  const error = new Error("上传失败");
947
- emit("error", error, currentFile);
946
+ emit("handlError", error, currentFile);
948
947
  }
949
948
  if (isRemove) {
950
949
  const fileUids = new Set(fileList.map((f) => f.uid));
@@ -970,7 +969,6 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
970
969
  const updateModelValue = (fileList) => {
971
970
  var _a;
972
971
  const propsData = unref(getProps);
973
- isInternalUpdate.value = true;
974
972
  switch (propsData.resultType) {
975
973
  case "fileList":
976
974
  emit("update:modelValue", fileList);
@@ -991,11 +989,6 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
991
989
  default:
992
990
  emit("update:modelValue", fileList);
993
991
  }
994
- nextTick(() => {
995
- setTimeout(() => {
996
- isInternalUpdate.value = false;
997
- }, 50);
998
- });
999
992
  };
1000
993
  const parseModelValue = (value) => {
1001
994
  if (!value) return [];
@@ -1081,8 +1074,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
1081
1074
  });
1082
1075
  watch(
1083
1076
  () => props.modelValue,
1084
- (val, oldVal) => {
1085
- if (isInternalUpdate.value) return;
1077
+ (val) => {
1086
1078
  fileListRef.value = parseModelValue(val);
1087
1079
  },
1088
1080
  { immediate: true }
@@ -1183,7 +1175,7 @@ const _export_sfc = (sfc, props) => {
1183
1175
  }
1184
1176
  return target;
1185
1177
  };
1186
- const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-10587859"]]);
1178
+ const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-1a5a7ff7"]]);
1187
1179
  const componentMap = {
1188
1180
  Input,
1189
1181
  InputNumber,
@@ -1627,6 +1619,8 @@ function useForm(options = {}) {
1627
1619
  const formModel = reactive({});
1628
1620
  const loadedRef = ref(false);
1629
1621
  const propsRef = ref({});
1622
+ const pendingValues = ref(null);
1623
+ let unwatchFormRef = null;
1630
1624
  const initFormModel = () => {
1631
1625
  var _a, _b;
1632
1626
  const schemas = unref(((_b = (_a = formRef.value) == null ? void 0 : _a.getSchema) == null ? void 0 : _b.call(_a)) || options.schemas || []);
@@ -1638,12 +1632,38 @@ function useForm(options = {}) {
1638
1632
  };
1639
1633
  const register = async (formInstance) => {
1640
1634
  await nextTick();
1635
+ if (unwatchFormRef) {
1636
+ unwatchFormRef();
1637
+ unwatchFormRef = null;
1638
+ }
1641
1639
  formRef.value = formInstance;
1642
1640
  loadedRef.value = true;
1643
1641
  if (options && Object.keys(options).length > 0) {
1644
1642
  await setProps(options);
1645
1643
  }
1646
1644
  initFormModel();
1645
+ if (formInstance.formRef) {
1646
+ unwatchFormRef = watch(
1647
+ () => formInstance.formRef.value,
1648
+ (val) => {
1649
+ if (val === null) {
1650
+ console.log("表单组件已卸载,重置 useForm 状态");
1651
+ formRef.value = null;
1652
+ loadedRef.value = false;
1653
+ if (unwatchFormRef) {
1654
+ unwatchFormRef();
1655
+ unwatchFormRef = null;
1656
+ }
1657
+ }
1658
+ },
1659
+ { flush: "sync" }
1660
+ // 同步执行,确保及时清理
1661
+ );
1662
+ }
1663
+ if (pendingValues.value) {
1664
+ await setFieldsValue(pendingValues.value);
1665
+ pendingValues.value = null;
1666
+ }
1647
1667
  };
1648
1668
  const getForm = () => {
1649
1669
  const form = unref(formRef);
@@ -1655,7 +1675,16 @@ function useForm(options = {}) {
1655
1675
  return form;
1656
1676
  };
1657
1677
  const getFormSafe = () => {
1658
- return unref(formRef);
1678
+ var _a;
1679
+ const form = unref(formRef);
1680
+ if (!form) return null;
1681
+ if (((_a = form.formRef) == null ? void 0 : _a.value) === null) {
1682
+ console.log("检测到失效的表单实例,清理引用");
1683
+ formRef.value = null;
1684
+ loadedRef.value = false;
1685
+ return null;
1686
+ }
1687
+ return form;
1659
1688
  };
1660
1689
  const getFieldsValue = () => {
1661
1690
  const form = getFormSafe();
@@ -1667,7 +1696,10 @@ function useForm(options = {}) {
1667
1696
  };
1668
1697
  const setFieldsValue = async (values) => {
1669
1698
  const form = getFormSafe();
1670
- if (!form) return;
1699
+ if (!form) {
1700
+ pendingValues.value = { ...pendingValues.value, ...values };
1701
+ return;
1702
+ }
1671
1703
  if (form.setFieldsValue) {
1672
1704
  await form.setFieldsValue(values);
1673
1705
  } else {
@@ -3739,9 +3771,7 @@ function useModal(props) {
3739
3771
  const openModal = (visible = true, data) => {
3740
3772
  const modal = getModal();
3741
3773
  if (!modal) return;
3742
- if (data !== void 0) {
3743
- modal.setModalProps({ _data: data });
3744
- }
3774
+ modal.setModalProps({ _data: data });
3745
3775
  if (visible) {
3746
3776
  modal.openModal();
3747
3777
  } else {
@@ -3752,6 +3782,9 @@ function useModal(props) {
3752
3782
  const modal = getModal();
3753
3783
  if (!modal) return;
3754
3784
  modal.closeModal();
3785
+ setTimeout(() => {
3786
+ modal.setModalProps({ _data: void 0 });
3787
+ });
3755
3788
  };
3756
3789
  const setModalProps = (modalProps) => {
3757
3790
  const modal = getModal();