knt-shared 1.2.2 → 1.2.4

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
@@ -1,4 +1,4 @@
1
- import { getCurrentInstance, inject, defineComponent, computed, createElementBlock, openBlock, normalizeStyle, normalizeClass, createElementVNode, ref, unref, watch, onMounted, nextTick, resolveComponent, createVNode, mergeProps, createSlots, withCtx, renderSlot, createBlock, createCommentVNode, toDisplayString, createTextVNode, reactive, onBeforeUnmount, normalizeProps, guardReactiveProps, Fragment, renderList, resolveDynamicComponent, withDirectives, vShow, withModifiers, h, onUnmounted } from "vue";
1
+ import { getCurrentInstance, inject, defineComponent, computed, createElementBlock, openBlock, normalizeStyle, normalizeClass, createElementVNode, useCssVars, ref, unref, watch, onMounted, nextTick, resolveComponent, createVNode, mergeProps, createSlots, withCtx, renderSlot, createBlock, createCommentVNode, toDisplayString, createTextVNode, reactive, onBeforeUnmount, normalizeProps, guardReactiveProps, Fragment, renderList, resolveDynamicComponent, withDirectives, vShow, withModifiers, h, onUnmounted } from "vue";
2
2
  import { Message, Transfer, Mention, Upload, Rate, Slider, Switch, RangePicker, TimePicker, DatePicker, TreeSelect, Cascader, CheckboxGroup, Checkbox, RadioGroup, Radio, Select, AutoComplete, Textarea, InputPassword, InputNumber, Input } from "@arco-design/web-vue";
3
3
  const configProviderInjectionKey = Symbol("ArcoConfigProvider");
4
4
  const CLASS_PREFIX = "arco";
@@ -708,6 +708,9 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
708
708
  },
709
709
  emits: ["register", "update:modelValue", "change", "success", "handleSuccess", "error", "handlError", "progress", "remove", "preview", "exceed"],
710
710
  setup(__props, { expose: __expose, emit: __emit }) {
711
+ useCssVars((_ctx) => ({
712
+ "v439946ba": cardSizeValue.value
713
+ }));
711
714
  const props = __props;
712
715
  const emit = __emit;
713
716
  const uploadRef = ref();
@@ -727,6 +730,9 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
727
730
  }
728
731
  return false;
729
732
  });
733
+ const cardSizeValue = computed(() => {
734
+ return `${getProps.value.cardSize || 80}px`;
735
+ });
730
736
  const getBindValue = computed(() => {
731
737
  const propsData = unref(getProps);
732
738
  return {
@@ -1118,8 +1124,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
1118
1124
  key: 0,
1119
1125
  class: "upload-card-button",
1120
1126
  style: normalizeStyle({
1121
- width: `${getProps.value.cardSize || 80}px`,
1122
- height: `${getProps.value.cardSize || 80}px`
1127
+ width: cardSizeValue.value,
1128
+ height: cardSizeValue.value
1123
1129
  })
1124
1130
  }, [
1125
1131
  createVNode(unref(IconPlus), { size: 16 }),
@@ -1175,7 +1181,7 @@ const _export_sfc = (sfc, props) => {
1175
1181
  }
1176
1182
  return target;
1177
1183
  };
1178
- const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-1a5a7ff7"]]);
1184
+ const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-c83c45f0"]]);
1179
1185
  const componentMap = {
1180
1186
  Input,
1181
1187
  InputNumber,
@@ -1236,6 +1242,15 @@ function getPlaceholder(component, label) {
1236
1242
  }
1237
1243
  return "";
1238
1244
  }
1245
+ function getRules(component, label) {
1246
+ if (componentsNeedPlaceholder.has(component)) {
1247
+ return [{ required: true, message: `请输入${label}` }];
1248
+ }
1249
+ if (componentsNeedSelectPlaceholder.has(component)) {
1250
+ return [{ required: true, message: `请选择${label}` }];
1251
+ }
1252
+ return [];
1253
+ }
1239
1254
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1240
1255
  ...{
1241
1256
  name: "BasicForm",
@@ -1338,12 +1353,17 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1338
1353
  if (schema.disabled !== void 0) {
1339
1354
  disabled = typeof schema.disabled === "boolean" ? schema.disabled : schema.disabled(formModel);
1340
1355
  }
1356
+ let rules = schema.rules;
1357
+ if (schema.required && (!rules || rules.length === 0)) {
1358
+ const componentType = typeof schema.component === "string" ? schema.component : "";
1359
+ rules = getRules(componentType, schema.label);
1360
+ }
1341
1361
  return {
1342
1362
  field: schema.field,
1343
1363
  label: schema.label,
1344
1364
  labelColProps: schema.labelColProps || propsData.labelColProps,
1345
1365
  wrapperColProps: schema.wrapperColProps || propsData.wrapperColProps,
1346
- rules: schema.rules,
1366
+ rules,
1347
1367
  disabled,
1348
1368
  help: schema.help,
1349
1369
  extra: schema.extra,
@@ -1619,6 +1639,8 @@ function useForm(options = {}) {
1619
1639
  const formModel = reactive({});
1620
1640
  const loadedRef = ref(false);
1621
1641
  const propsRef = ref({});
1642
+ const pendingValues = ref(null);
1643
+ let unwatchFormRef = null;
1622
1644
  const initFormModel = () => {
1623
1645
  var _a, _b;
1624
1646
  const schemas = unref(((_b = (_a = formRef.value) == null ? void 0 : _a.getSchema) == null ? void 0 : _b.call(_a)) || options.schemas || []);
@@ -1630,12 +1652,37 @@ function useForm(options = {}) {
1630
1652
  };
1631
1653
  const register = async (formInstance) => {
1632
1654
  await nextTick();
1655
+ if (unwatchFormRef) {
1656
+ unwatchFormRef();
1657
+ unwatchFormRef = null;
1658
+ }
1633
1659
  formRef.value = formInstance;
1634
1660
  loadedRef.value = true;
1635
1661
  if (options && Object.keys(options).length > 0) {
1636
1662
  await setProps(options);
1637
1663
  }
1638
1664
  initFormModel();
1665
+ if (formInstance.formRef) {
1666
+ unwatchFormRef = watch(
1667
+ () => formInstance.formRef.value,
1668
+ (val) => {
1669
+ if (val === null) {
1670
+ formRef.value = null;
1671
+ loadedRef.value = false;
1672
+ if (unwatchFormRef) {
1673
+ unwatchFormRef();
1674
+ unwatchFormRef = null;
1675
+ }
1676
+ }
1677
+ },
1678
+ { flush: "sync" }
1679
+ // 同步执行,确保及时清理
1680
+ );
1681
+ }
1682
+ if (pendingValues.value) {
1683
+ await setFieldsValue(pendingValues.value);
1684
+ pendingValues.value = null;
1685
+ }
1639
1686
  };
1640
1687
  const getForm = () => {
1641
1688
  const form = unref(formRef);
@@ -1647,7 +1694,15 @@ function useForm(options = {}) {
1647
1694
  return form;
1648
1695
  };
1649
1696
  const getFormSafe = () => {
1650
- return unref(formRef);
1697
+ var _a;
1698
+ const form = unref(formRef);
1699
+ if (!form) return null;
1700
+ if (((_a = form.formRef) == null ? void 0 : _a.value) === null) {
1701
+ formRef.value = null;
1702
+ loadedRef.value = false;
1703
+ return null;
1704
+ }
1705
+ return form;
1651
1706
  };
1652
1707
  const getFieldsValue = () => {
1653
1708
  const form = getFormSafe();
@@ -1659,7 +1714,10 @@ function useForm(options = {}) {
1659
1714
  };
1660
1715
  const setFieldsValue = async (values) => {
1661
1716
  const form = getFormSafe();
1662
- if (!form) return;
1717
+ if (!form) {
1718
+ pendingValues.value = { ...pendingValues.value, ...values };
1719
+ return;
1720
+ }
1663
1721
  if (form.setFieldsValue) {
1664
1722
  await form.setFieldsValue(values);
1665
1723
  } else {
@@ -3341,7 +3399,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3341
3399
  footer: { type: Boolean, default: true },
3342
3400
  titleAlign: { default: "center" },
3343
3401
  height: {},
3344
- minHeight: { default: 60 },
3402
+ minHeight: { default: 46 },
3345
3403
  useWrapper: { type: Boolean, default: true },
3346
3404
  wrapperFooterOffset: { default: 0 },
3347
3405
  canFullscreen: { type: Boolean, default: false },
@@ -3419,10 +3477,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3419
3477
  const spinStyle = computed(() => {
3420
3478
  const propsData = unref(getProps);
3421
3479
  const style = {
3422
- minHeight: propsData.minHeight ? typeof propsData.minHeight === "number" ? `${propsData.minHeight}px` : propsData.minHeight : "200px",
3423
- pointerEvents: "none"
3424
- // 禁用所有交互
3480
+ minHeight: propsData.minHeight ? typeof propsData.minHeight === "number" ? `${propsData.minHeight}px` : propsData.minHeight : "46px"
3425
3481
  };
3482
+ if (propsData.loading) {
3483
+ style.pointerEvents = "none";
3484
+ }
3426
3485
  return style;
3427
3486
  });
3428
3487
  const getCancelButtonProps = computed(() => {
@@ -3570,10 +3629,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3570
3629
  onCancel: handleCancel
3571
3630
  }), createSlots({
3572
3631
  default: withCtx(() => [
3573
- getProps.value.loading ? (openBlock(), createBlock(_component_a_spin, {
3574
- key: 0,
3632
+ createVNode(_component_a_spin, {
3633
+ loading: getProps.value.loading,
3575
3634
  tip: getProps.value.loadingTip,
3576
- loading: true,
3577
3635
  style: normalizeStyle(spinStyle.value),
3578
3636
  class: "w-full"
3579
3637
  }, {
@@ -3587,15 +3645,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3587
3645
  ], 4)) : renderSlot(_ctx.$slots, "default", { key: 1 }, void 0, true)
3588
3646
  ]),
3589
3647
  _: 3
3590
- }, 8, ["tip", "style"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
3591
- getProps.value.useWrapper ? (openBlock(), createElementBlock("div", {
3592
- key: 0,
3593
- style: normalizeStyle(wrapperStyle.value),
3594
- class: "modal-wrapper"
3595
- }, [
3596
- renderSlot(_ctx.$slots, "default", {}, void 0, true)
3597
- ], 4)) : renderSlot(_ctx.$slots, "default", { key: 1 }, void 0, true)
3598
- ], 64))
3648
+ }, 8, ["loading", "tip", "style"])
3599
3649
  ]),
3600
3650
  _: 2
3601
3651
  }, [
@@ -3709,7 +3759,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3709
3759
  };
3710
3760
  }
3711
3761
  });
3712
- const BasicModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-4117f967"]]);
3762
+ const BasicModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-860bd3ac"]]);
3713
3763
  function useModal(props) {
3714
3764
  const modalRef = ref(null);
3715
3765
  const loadedRef = ref(false);
@@ -3731,9 +3781,7 @@ function useModal(props) {
3731
3781
  const openModal = (visible = true, data) => {
3732
3782
  const modal = getModal();
3733
3783
  if (!modal) return;
3734
- if (data !== void 0) {
3735
- modal.setModalProps({ _data: data });
3736
- }
3784
+ modal.setModalProps({ _data: data });
3737
3785
  if (visible) {
3738
3786
  modal.openModal();
3739
3787
  } else {
@@ -3744,6 +3792,9 @@ function useModal(props) {
3744
3792
  const modal = getModal();
3745
3793
  if (!modal) return;
3746
3794
  modal.closeModal();
3795
+ setTimeout(() => {
3796
+ modal.setModalProps({ _data: void 0 });
3797
+ });
3747
3798
  };
3748
3799
  const setModalProps = (modalProps) => {
3749
3800
  const modal = getModal();