knt-shared 1.2.3 → 1.2.5

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
+ "v43e7547c": 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 {
@@ -1073,7 +1079,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
1073
1079
  updateFile
1074
1080
  });
1075
1081
  watch(
1076
- () => props.modelValue,
1082
+ () => getProps.value.modelValue,
1077
1083
  (val) => {
1078
1084
  fileListRef.value = parseModelValue(val);
1079
1085
  },
@@ -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-00569ecd"]]);
1179
1185
  const componentMap = {
1180
1186
  Input,
1181
1187
  InputNumber,
@@ -1227,6 +1233,10 @@ const componentsNeedSelectPlaceholder = /* @__PURE__ */ new Set([
1227
1233
  "Cascader",
1228
1234
  "TreeSelect"
1229
1235
  ]);
1236
+ const componentsNeedUploadPlaceholder = /* @__PURE__ */ new Set([
1237
+ "Upload",
1238
+ "BasicUpload"
1239
+ ]);
1230
1240
  function getPlaceholder(component, label) {
1231
1241
  if (componentsNeedPlaceholder.has(component)) {
1232
1242
  return `请输入${label}`;
@@ -1236,6 +1246,15 @@ function getPlaceholder(component, label) {
1236
1246
  }
1237
1247
  return "";
1238
1248
  }
1249
+ function getRules(component, label) {
1250
+ if (componentsNeedPlaceholder.has(component)) {
1251
+ return [{ required: true, message: `请输入${label}` }];
1252
+ }
1253
+ if (componentsNeedUploadPlaceholder.has(component)) {
1254
+ return [{ required: true, message: `请上传${label}` }];
1255
+ }
1256
+ return [{ required: true, message: `请选择${label}` }];
1257
+ }
1239
1258
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1240
1259
  ...{
1241
1260
  name: "BasicForm",
@@ -1338,12 +1357,17 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1338
1357
  if (schema.disabled !== void 0) {
1339
1358
  disabled = typeof schema.disabled === "boolean" ? schema.disabled : schema.disabled(formModel);
1340
1359
  }
1360
+ let rules = schema.rules;
1361
+ if (schema.required && (!rules || rules.length === 0)) {
1362
+ const componentType = typeof schema.component === "string" ? schema.component : "";
1363
+ rules = getRules(componentType, schema.label);
1364
+ }
1341
1365
  return {
1342
1366
  field: schema.field,
1343
1367
  label: schema.label,
1344
1368
  labelColProps: schema.labelColProps || propsData.labelColProps,
1345
1369
  wrapperColProps: schema.wrapperColProps || propsData.wrapperColProps,
1346
- rules: schema.rules,
1370
+ rules,
1347
1371
  disabled,
1348
1372
  help: schema.help,
1349
1373
  extra: schema.extra,
@@ -1489,7 +1513,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1489
1513
  scrollToField
1490
1514
  });
1491
1515
  const stopSchemasWatch = watch(
1492
- () => props.schemas,
1516
+ () => getProps.value.schemas,
1493
1517
  (newSchemas) => {
1494
1518
  if (newSchemas) {
1495
1519
  internalSchemas.value = [...newSchemas];
@@ -1556,8 +1580,12 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1556
1580
  ref_for: true
1557
1581
  }, getFormItemBindValue(schema)), {
1558
1582
  default: withCtx(() => [
1559
- schema.renderComponentContent ? (openBlock(), createBlock(resolveDynamicComponent(schema.renderComponentContent(schema, formModel)), { key: 0 })) : (openBlock(), createBlock(resolveDynamicComponent(unref(getComponent)(schema.component)), mergeProps({
1560
- key: 1,
1583
+ schema.slotName ? renderSlot(_ctx.$slots, schema.slotName, {
1584
+ key: 0,
1585
+ schema,
1586
+ model: formModel
1587
+ }) : schema.renderComponentContent ? (openBlock(), createBlock(resolveDynamicComponent(schema.renderComponentContent(schema, formModel)), { key: 1 })) : (openBlock(), createBlock(resolveDynamicComponent(unref(getComponent)(schema.component)), mergeProps({
1588
+ key: 2,
1561
1589
  modelValue: formModel[schema.field],
1562
1590
  "onUpdate:modelValue": ($event) => formModel[schema.field] = $event,
1563
1591
  placeholder: getPlaceholderText(schema)
@@ -1647,7 +1675,6 @@ function useForm(options = {}) {
1647
1675
  () => formInstance.formRef.value,
1648
1676
  (val) => {
1649
1677
  if (val === null) {
1650
- console.log("表单组件已卸载,重置 useForm 状态");
1651
1678
  formRef.value = null;
1652
1679
  loadedRef.value = false;
1653
1680
  if (unwatchFormRef) {
@@ -1679,7 +1706,6 @@ function useForm(options = {}) {
1679
1706
  const form = unref(formRef);
1680
1707
  if (!form) return null;
1681
1708
  if (((_a = form.formRef) == null ? void 0 : _a.value) === null) {
1682
- console.log("检测到失效的表单实例,清理引用");
1683
1709
  formRef.value = null;
1684
1710
  loadedRef.value = false;
1685
1711
  return null;
@@ -1985,11 +2011,19 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1985
2011
  expandable: {},
1986
2012
  scroll: {},
1987
2013
  draggable: {},
1988
- pagination: { type: [Boolean, Object] },
1989
- search: { type: [Boolean, Object] },
1990
- toolbar: { type: [Boolean, Object] },
2014
+ pagination: { type: [Boolean, Object], default: () => ({
2015
+ current: 1,
2016
+ pageSize: 20,
2017
+ showTotal: true,
2018
+ showJumper: true,
2019
+ showPageSize: true,
2020
+ pageSizeOptions: [5, 10, 20, 50, 100]
2021
+ }) },
2022
+ search: { type: [Boolean, Object], default: () => ({ show: false }) },
2023
+ toolbar: { type: [Boolean, Object], default: () => ({ show: false }) },
1991
2024
  immediate: { type: Boolean, default: true },
1992
2025
  api: {},
2026
+ fetchSetting: {},
1993
2027
  beforeFetch: {},
1994
2028
  afterFetch: {},
1995
2029
  onFetchError: {},
@@ -2044,7 +2078,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2044
2078
  };
2045
2079
  const paginationRef = ref({
2046
2080
  current: 1,
2047
- pageSize: 10,
2081
+ pageSize: 20,
2048
2082
  total: 0,
2049
2083
  showTotal: true,
2050
2084
  showJumper: true,
@@ -2067,7 +2101,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2067
2101
  }
2068
2102
  };
2069
2103
  watch(
2070
- () => [props.data, props.loading],
2104
+ () => [getMergedProps.value.data, getMergedProps.value.loading],
2071
2105
  ([data, loading]) => {
2072
2106
  if (data) {
2073
2107
  dataSource.value = data;
@@ -2275,6 +2309,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2275
2309
  search,
2276
2310
  toolbar,
2277
2311
  api,
2312
+ fetchSetting,
2278
2313
  beforeFetch,
2279
2314
  afterFetch,
2280
2315
  onFetchError,
@@ -2479,15 +2514,22 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2479
2514
  const signal = currentAbortController.signal;
2480
2515
  try {
2481
2516
  loadingRef.value = true;
2517
+ const fetchSetting = {
2518
+ pageField: "page",
2519
+ sizeField: "pageSize",
2520
+ listField: "records",
2521
+ totalField: "total",
2522
+ ...mergedProps.fetchSetting
2523
+ };
2482
2524
  let params = {
2483
2525
  ...searchParams.value
2484
2526
  };
2485
2527
  if (paginationRef.value) {
2486
- params.page = paginationRef.value.current;
2487
- params.pageSize = paginationRef.value.pageSize;
2528
+ params[fetchSetting.pageField] = paginationRef.value.current;
2529
+ params[fetchSetting.sizeField] = paginationRef.value.pageSize;
2488
2530
  }
2489
2531
  if (mergedProps.beforeFetch) {
2490
- params = mergedProps.beforeFetch(params);
2532
+ params = await Promise.resolve(mergedProps.beforeFetch(params));
2491
2533
  }
2492
2534
  const result = await mergedProps.api(params, signal);
2493
2535
  if (!result || typeof result !== "object") {
@@ -2497,30 +2539,29 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2497
2539
  data: result
2498
2540
  };
2499
2541
  }
2500
- if (!("data" in result)) {
2542
+ const listField = fetchSetting.listField;
2543
+ const totalField = fetchSetting.totalField;
2544
+ if (!(listField in result)) {
2501
2545
  throw {
2502
2546
  code: ERROR_CODES.INVALID_RESPONSE,
2503
- message: "API 响应格式无效:缺少 data 字段",
2547
+ message: `API 响应格式无效:缺少 ${listField} 字段`,
2504
2548
  data: result
2505
2549
  };
2506
2550
  }
2507
- if (!Array.isArray(result.data)) {
2508
- console.warn("API 响应格式警告:data 字段不是数组,已转换为空数组");
2509
- }
2510
- if (!("total" in result) || typeof result.total !== "number") {
2511
- console.warn("API 响应格式警告:total 字段缺失或类型错误,已设置为 0");
2551
+ if (!Array.isArray(result[listField])) {
2552
+ console.warn(`API 响应格式警告:${listField} 字段不是数组,已转换为空数组`);
2512
2553
  }
2513
- let data = Array.isArray(result.data) ? result.data : [];
2514
- let total = typeof result.total === "number" ? result.total : 0;
2554
+ let data = Array.isArray(result[listField]) ? result[listField] : [];
2555
+ let total = typeof result[totalField] === "number" ? result[totalField] : data.length;
2515
2556
  if (total < data.length) {
2516
2557
  console.warn(
2517
2558
  `数据一致性警告:total(${total}) 小于 data.length(${data.length})`
2518
2559
  );
2519
2560
  }
2520
2561
  if (mergedProps.afterFetch) {
2521
- const processed = mergedProps.afterFetch(result);
2522
- data = Array.isArray(processed.data) ? processed.data : data;
2523
- total = typeof processed.total === "number" ? processed.total : total;
2562
+ const processed = await Promise.resolve(mergedProps.afterFetch(result));
2563
+ data = Array.isArray(processed[listField]) ? processed[listField] : data;
2564
+ total = typeof processed[totalField] === "number" ? processed[totalField] : total;
2524
2565
  }
2525
2566
  dataSource.value = data;
2526
2567
  if (paginationRef.value) {
@@ -2688,7 +2729,6 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2688
2729
  initPagination();
2689
2730
  initColumnSetting();
2690
2731
  document.addEventListener("fullscreenchange", handleFullscreenChange);
2691
- await nextTick();
2692
2732
  const tableInstance = {
2693
2733
  getDataSource,
2694
2734
  setDataSource,
@@ -3100,7 +3140,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3100
3140
  };
3101
3141
  }
3102
3142
  });
3103
- const BasicTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-04667d35"]]);
3143
+ const BasicTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-7a27a6be"]]);
3104
3144
  function useTable(options = {}) {
3105
3145
  const tableRef = ref(null);
3106
3146
  const formRef = ref(null);
@@ -3381,7 +3421,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3381
3421
  footer: { type: Boolean, default: true },
3382
3422
  titleAlign: { default: "center" },
3383
3423
  height: {},
3384
- minHeight: { default: 60 },
3424
+ minHeight: { default: 46 },
3385
3425
  useWrapper: { type: Boolean, default: true },
3386
3426
  wrapperFooterOffset: { default: 0 },
3387
3427
  canFullscreen: { type: Boolean, default: false },
@@ -3459,10 +3499,11 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3459
3499
  const spinStyle = computed(() => {
3460
3500
  const propsData = unref(getProps);
3461
3501
  const style = {
3462
- minHeight: propsData.minHeight ? typeof propsData.minHeight === "number" ? `${propsData.minHeight}px` : propsData.minHeight : "200px",
3463
- pointerEvents: "none"
3464
- // 禁用所有交互
3502
+ minHeight: propsData.minHeight ? typeof propsData.minHeight === "number" ? `${propsData.minHeight}px` : propsData.minHeight : "46px"
3465
3503
  };
3504
+ if (propsData.loading) {
3505
+ style.pointerEvents = "none";
3506
+ }
3466
3507
  return style;
3467
3508
  });
3468
3509
  const getCancelButtonProps = computed(() => {
@@ -3579,14 +3620,14 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3579
3620
  };
3580
3621
  __expose(modalMethods);
3581
3622
  watch(
3582
- () => props.visible,
3623
+ () => getProps.value.visible,
3583
3624
  (val) => {
3584
3625
  visibleRef.value = val;
3585
3626
  },
3586
3627
  { immediate: true }
3587
3628
  );
3588
3629
  watch(
3589
- () => props.defaultFullscreen,
3630
+ () => getProps.value.defaultFullscreen,
3590
3631
  (val) => {
3591
3632
  fullscreenRef.value = val || false;
3592
3633
  },
@@ -3610,10 +3651,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3610
3651
  onCancel: handleCancel
3611
3652
  }), createSlots({
3612
3653
  default: withCtx(() => [
3613
- getProps.value.loading ? (openBlock(), createBlock(_component_a_spin, {
3614
- key: 0,
3654
+ createVNode(_component_a_spin, {
3655
+ loading: getProps.value.loading,
3615
3656
  tip: getProps.value.loadingTip,
3616
- loading: true,
3617
3657
  style: normalizeStyle(spinStyle.value),
3618
3658
  class: "w-full"
3619
3659
  }, {
@@ -3627,15 +3667,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3627
3667
  ], 4)) : renderSlot(_ctx.$slots, "default", { key: 1 }, void 0, true)
3628
3668
  ]),
3629
3669
  _: 3
3630
- }, 8, ["tip", "style"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
3631
- getProps.value.useWrapper ? (openBlock(), createElementBlock("div", {
3632
- key: 0,
3633
- style: normalizeStyle(wrapperStyle.value),
3634
- class: "modal-wrapper"
3635
- }, [
3636
- renderSlot(_ctx.$slots, "default", {}, void 0, true)
3637
- ], 4)) : renderSlot(_ctx.$slots, "default", { key: 1 }, void 0, true)
3638
- ], 64))
3670
+ }, 8, ["loading", "tip", "style"])
3639
3671
  ]),
3640
3672
  _: 2
3641
3673
  }, [
@@ -3749,7 +3781,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3749
3781
  };
3750
3782
  }
3751
3783
  });
3752
- const BasicModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-4117f967"]]);
3784
+ const BasicModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-1e847475"]]);
3753
3785
  function useModal(props) {
3754
3786
  const modalRef = ref(null);
3755
3787
  const loadedRef = ref(false);