knt-shared 1.2.4 → 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
@@ -709,7 +709,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
709
709
  emits: ["register", "update:modelValue", "change", "success", "handleSuccess", "error", "handlError", "progress", "remove", "preview", "exceed"],
710
710
  setup(__props, { expose: __expose, emit: __emit }) {
711
711
  useCssVars((_ctx) => ({
712
- "v439946ba": cardSizeValue.value
712
+ "v43e7547c": cardSizeValue.value
713
713
  }));
714
714
  const props = __props;
715
715
  const emit = __emit;
@@ -1079,7 +1079,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
1079
1079
  updateFile
1080
1080
  });
1081
1081
  watch(
1082
- () => props.modelValue,
1082
+ () => getProps.value.modelValue,
1083
1083
  (val) => {
1084
1084
  fileListRef.value = parseModelValue(val);
1085
1085
  },
@@ -1181,7 +1181,7 @@ const _export_sfc = (sfc, props) => {
1181
1181
  }
1182
1182
  return target;
1183
1183
  };
1184
- const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-c83c45f0"]]);
1184
+ const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-00569ecd"]]);
1185
1185
  const componentMap = {
1186
1186
  Input,
1187
1187
  InputNumber,
@@ -1233,6 +1233,10 @@ const componentsNeedSelectPlaceholder = /* @__PURE__ */ new Set([
1233
1233
  "Cascader",
1234
1234
  "TreeSelect"
1235
1235
  ]);
1236
+ const componentsNeedUploadPlaceholder = /* @__PURE__ */ new Set([
1237
+ "Upload",
1238
+ "BasicUpload"
1239
+ ]);
1236
1240
  function getPlaceholder(component, label) {
1237
1241
  if (componentsNeedPlaceholder.has(component)) {
1238
1242
  return `请输入${label}`;
@@ -1246,10 +1250,10 @@ function getRules(component, label) {
1246
1250
  if (componentsNeedPlaceholder.has(component)) {
1247
1251
  return [{ required: true, message: `请输入${label}` }];
1248
1252
  }
1249
- if (componentsNeedSelectPlaceholder.has(component)) {
1250
- return [{ required: true, message: `请选择${label}` }];
1253
+ if (componentsNeedUploadPlaceholder.has(component)) {
1254
+ return [{ required: true, message: `请上传${label}` }];
1251
1255
  }
1252
- return [];
1256
+ return [{ required: true, message: `请选择${label}` }];
1253
1257
  }
1254
1258
  const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1255
1259
  ...{
@@ -1509,7 +1513,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1509
1513
  scrollToField
1510
1514
  });
1511
1515
  const stopSchemasWatch = watch(
1512
- () => props.schemas,
1516
+ () => getProps.value.schemas,
1513
1517
  (newSchemas) => {
1514
1518
  if (newSchemas) {
1515
1519
  internalSchemas.value = [...newSchemas];
@@ -1576,8 +1580,12 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
1576
1580
  ref_for: true
1577
1581
  }, getFormItemBindValue(schema)), {
1578
1582
  default: withCtx(() => [
1579
- schema.renderComponentContent ? (openBlock(), createBlock(resolveDynamicComponent(schema.renderComponentContent(schema, formModel)), { key: 0 })) : (openBlock(), createBlock(resolveDynamicComponent(unref(getComponent)(schema.component)), mergeProps({
1580
- 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,
1581
1589
  modelValue: formModel[schema.field],
1582
1590
  "onUpdate:modelValue": ($event) => formModel[schema.field] = $event,
1583
1591
  placeholder: getPlaceholderText(schema)
@@ -2003,11 +2011,19 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2003
2011
  expandable: {},
2004
2012
  scroll: {},
2005
2013
  draggable: {},
2006
- pagination: { type: [Boolean, Object] },
2007
- search: { type: [Boolean, Object] },
2008
- 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 }) },
2009
2024
  immediate: { type: Boolean, default: true },
2010
2025
  api: {},
2026
+ fetchSetting: {},
2011
2027
  beforeFetch: {},
2012
2028
  afterFetch: {},
2013
2029
  onFetchError: {},
@@ -2062,7 +2078,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2062
2078
  };
2063
2079
  const paginationRef = ref({
2064
2080
  current: 1,
2065
- pageSize: 10,
2081
+ pageSize: 20,
2066
2082
  total: 0,
2067
2083
  showTotal: true,
2068
2084
  showJumper: true,
@@ -2085,7 +2101,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2085
2101
  }
2086
2102
  };
2087
2103
  watch(
2088
- () => [props.data, props.loading],
2104
+ () => [getMergedProps.value.data, getMergedProps.value.loading],
2089
2105
  ([data, loading]) => {
2090
2106
  if (data) {
2091
2107
  dataSource.value = data;
@@ -2293,6 +2309,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2293
2309
  search,
2294
2310
  toolbar,
2295
2311
  api,
2312
+ fetchSetting,
2296
2313
  beforeFetch,
2297
2314
  afterFetch,
2298
2315
  onFetchError,
@@ -2497,15 +2514,22 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2497
2514
  const signal = currentAbortController.signal;
2498
2515
  try {
2499
2516
  loadingRef.value = true;
2517
+ const fetchSetting = {
2518
+ pageField: "page",
2519
+ sizeField: "pageSize",
2520
+ listField: "records",
2521
+ totalField: "total",
2522
+ ...mergedProps.fetchSetting
2523
+ };
2500
2524
  let params = {
2501
2525
  ...searchParams.value
2502
2526
  };
2503
2527
  if (paginationRef.value) {
2504
- params.page = paginationRef.value.current;
2505
- params.pageSize = paginationRef.value.pageSize;
2528
+ params[fetchSetting.pageField] = paginationRef.value.current;
2529
+ params[fetchSetting.sizeField] = paginationRef.value.pageSize;
2506
2530
  }
2507
2531
  if (mergedProps.beforeFetch) {
2508
- params = mergedProps.beforeFetch(params);
2532
+ params = await Promise.resolve(mergedProps.beforeFetch(params));
2509
2533
  }
2510
2534
  const result = await mergedProps.api(params, signal);
2511
2535
  if (!result || typeof result !== "object") {
@@ -2515,30 +2539,29 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2515
2539
  data: result
2516
2540
  };
2517
2541
  }
2518
- if (!("data" in result)) {
2542
+ const listField = fetchSetting.listField;
2543
+ const totalField = fetchSetting.totalField;
2544
+ if (!(listField in result)) {
2519
2545
  throw {
2520
2546
  code: ERROR_CODES.INVALID_RESPONSE,
2521
- message: "API 响应格式无效:缺少 data 字段",
2547
+ message: `API 响应格式无效:缺少 ${listField} 字段`,
2522
2548
  data: result
2523
2549
  };
2524
2550
  }
2525
- if (!Array.isArray(result.data)) {
2526
- console.warn("API 响应格式警告:data 字段不是数组,已转换为空数组");
2551
+ if (!Array.isArray(result[listField])) {
2552
+ console.warn(`API 响应格式警告:${listField} 字段不是数组,已转换为空数组`);
2527
2553
  }
2528
- if (!("total" in result) || typeof result.total !== "number") {
2529
- console.warn("API 响应格式警告:total 字段缺失或类型错误,已设置为 0");
2530
- }
2531
- let data = Array.isArray(result.data) ? result.data : [];
2532
- 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;
2533
2556
  if (total < data.length) {
2534
2557
  console.warn(
2535
2558
  `数据一致性警告:total(${total}) 小于 data.length(${data.length})`
2536
2559
  );
2537
2560
  }
2538
2561
  if (mergedProps.afterFetch) {
2539
- const processed = mergedProps.afterFetch(result);
2540
- data = Array.isArray(processed.data) ? processed.data : data;
2541
- 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;
2542
2565
  }
2543
2566
  dataSource.value = data;
2544
2567
  if (paginationRef.value) {
@@ -2706,7 +2729,6 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2706
2729
  initPagination();
2707
2730
  initColumnSetting();
2708
2731
  document.addEventListener("fullscreenchange", handleFullscreenChange);
2709
- await nextTick();
2710
2732
  const tableInstance = {
2711
2733
  getDataSource,
2712
2734
  setDataSource,
@@ -3118,7 +3140,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
3118
3140
  };
3119
3141
  }
3120
3142
  });
3121
- 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"]]);
3122
3144
  function useTable(options = {}) {
3123
3145
  const tableRef = ref(null);
3124
3146
  const formRef = ref(null);
@@ -3598,14 +3620,14 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3598
3620
  };
3599
3621
  __expose(modalMethods);
3600
3622
  watch(
3601
- () => props.visible,
3623
+ () => getProps.value.visible,
3602
3624
  (val) => {
3603
3625
  visibleRef.value = val;
3604
3626
  },
3605
3627
  { immediate: true }
3606
3628
  );
3607
3629
  watch(
3608
- () => props.defaultFullscreen,
3630
+ () => getProps.value.defaultFullscreen,
3609
3631
  (val) => {
3610
3632
  fullscreenRef.value = val || false;
3611
3633
  },
@@ -3759,7 +3781,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3759
3781
  };
3760
3782
  }
3761
3783
  });
3762
- const BasicModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-860bd3ac"]]);
3784
+ const BasicModal = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-1e847475"]]);
3763
3785
  function useModal(props) {
3764
3786
  const modalRef = ref(null);
3765
3787
  const loadedRef = ref(false);