@ys-knife-crud/vue 0.0.14 → 0.0.15

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/README.md CHANGED
@@ -128,6 +128,7 @@ const {
128
128
  currentRows: toRef(props, "currentRows"),
129
129
  selectedRows: toRef(props, "selectedRows"),
130
130
  total: toRef(props, "total"),
131
+ totalKnown: toRef(props, "totalKnown"), // true when dataFun returns totalCount → "all" option shows 共 N 条
131
132
  exportPageSize: toRef(props, "exportPageSize"),
132
133
  hasMorePage: toRef(props, "hasMorePage"),
133
134
  });
package/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  isGroupNode: () => isGroupNode,
30
30
  setDefaultModalAppContext: () => setDefaultModalAppContext,
31
31
  useAdvancedFilter: () => useAdvancedFilter,
32
+ useCollectData: () => useCollectData,
32
33
  useCustomConfig: () => useCustomConfig,
33
34
  useDateFilterItem: () => useDateFilterItem,
34
35
  useDateRangeFilterItem: () => useDateRangeFilterItem,
@@ -339,6 +340,7 @@ function useExportExcel({
339
340
  currentRows,
340
341
  selectedRows,
341
342
  total,
343
+ totalKnown,
342
344
  exportPageSize,
343
345
  hasMorePage,
344
346
  pageScopeLabel
@@ -354,7 +356,11 @@ function useExportExcel({
354
356
  }
355
357
  opts.push({ value: "page", label: `${pageScopeLabel?.value ?? "\u5BFC\u51FA\u5F53\u524D\u9875\u6570\u636E"}\uFF08${currentRows.value.length} \u6761\uFF09`, disabled: false });
356
358
  if (hasMorePage.value) {
357
- opts.push({ value: "all", label: "\u5BFC\u51FA\u6240\u6709\u6570\u636E", disabled: false });
359
+ opts.push({
360
+ value: "all",
361
+ label: totalKnown.value ? `\u5BFC\u51FA\u6240\u6709\u6570\u636E\uFF08\u5171 ${total.value} \u6761\uFF09` : "\u5BFC\u51FA\u6240\u6709\u6570\u636E",
362
+ disabled: false
363
+ });
358
364
  }
359
365
  return opts;
360
366
  });
@@ -508,8 +514,167 @@ function useExportExcel({
508
514
  };
509
515
  }
510
516
 
511
- // src/importExcel/importExcel.ts
517
+ // src/table/collectData.ts
512
518
  var import_vue6 = require("vue");
519
+ function useCollectData({
520
+ props,
521
+ selectable,
522
+ currentRows,
523
+ selectedRows,
524
+ total,
525
+ totalKnown,
526
+ collectPageSize,
527
+ hasMorePage,
528
+ pageScopeLabel
529
+ }) {
530
+ function maxCount() {
531
+ return Math.max(1, Math.floor(props.maxCollectCount));
532
+ }
533
+ const collectOptions = (0, import_vue6.computed)(() => {
534
+ const opts = [];
535
+ if (selectable.value) {
536
+ opts.push({
537
+ value: "selected",
538
+ label: `\u9009\u4E2D\u7684\u6570\u636E\uFF08\u5DF2\u9009 ${selectedRows.value.length} \u9879\uFF09`,
539
+ disabled: selectedRows.value.length === 0
540
+ });
541
+ }
542
+ opts.push({
543
+ value: "page",
544
+ label: `${pageScopeLabel?.value ?? "\u5F53\u524D\u9875\u7684\u6570\u636E"}\uFF08${currentRows.value.length} \u6761\uFF09`,
545
+ disabled: false
546
+ });
547
+ if (hasMorePage.value) {
548
+ opts.push({
549
+ value: "all",
550
+ label: totalKnown.value ? `\u6240\u6709\u6570\u636E\uFF08\u5171 ${total.value} \u6761\uFF09` : "\u6240\u6709\u6570\u636E",
551
+ disabled: false
552
+ });
553
+ }
554
+ return opts;
555
+ });
556
+ const collectDialogVisible = (0, import_vue6.ref)(false);
557
+ const collecting = (0, import_vue6.ref)(false);
558
+ const collectFetched = (0, import_vue6.ref)(0);
559
+ const collectTotal = (0, import_vue6.ref)(0);
560
+ const collectTotalKnown = (0, import_vue6.ref)(false);
561
+ let collectCancelled = false;
562
+ let collectAbort = null;
563
+ let collectStartedAt = 0;
564
+ let etaTimer = null;
565
+ const etaNow = (0, import_vue6.ref)(0);
566
+ (0, import_vue6.onScopeDispose)(stopEtaTimer);
567
+ function stopEtaTimer() {
568
+ if (etaTimer != null) {
569
+ clearInterval(etaTimer);
570
+ etaTimer = null;
571
+ }
572
+ }
573
+ const collectEtaSeconds = (0, import_vue6.computed)(() => {
574
+ if (!collectTotalKnown.value || collectFetched.value === 0) return null;
575
+ const elapsed = (etaNow.value - collectStartedAt) / 1e3;
576
+ if (elapsed < 0.5) return null;
577
+ const remaining = collectTotal.value - collectFetched.value;
578
+ if (remaining <= 0) return null;
579
+ return Math.max(1, Math.ceil(remaining / (collectFetched.value / elapsed)));
580
+ });
581
+ const collectPercent = (0, import_vue6.computed)(() => {
582
+ if (collectTotalKnown.value && collectTotal.value > 0)
583
+ return Math.min(100, Math.round(collectFetched.value / collectTotal.value * 100));
584
+ return collectFetched.value > 0 ? 99 : 0;
585
+ });
586
+ function onCollectClick() {
587
+ if (!props.collectorFunc) return;
588
+ const enabled = collectOptions.value.filter((o) => !o.disabled);
589
+ if (enabled.length === 1) {
590
+ void doCollect(enabled[0].value);
591
+ return;
592
+ }
593
+ collectDialogVisible.value = true;
594
+ }
595
+ async function doCollect(scope) {
596
+ collectDialogVisible.value = false;
597
+ const collector = props.collectorFunc;
598
+ if (!collector) return;
599
+ if (scope === "all") {
600
+ await collectAllStreaming(collector);
601
+ return;
602
+ }
603
+ const source = scope === "selected" ? selectedRows.value : currentRows.value;
604
+ const max = maxCount();
605
+ const truncated = source.length > max;
606
+ const rows = (truncated ? source.slice(0, max) : source).slice();
607
+ await collector(rows, { scope, truncated, maxCount: max });
608
+ }
609
+ async function collectAllStreaming(collector) {
610
+ collecting.value = true;
611
+ collectCancelled = false;
612
+ collectFetched.value = 0;
613
+ collectTotal.value = total.value;
614
+ collectTotalKnown.value = false;
615
+ collectStartedAt = Date.now();
616
+ etaNow.value = collectStartedAt;
617
+ stopEtaTimer();
618
+ etaTimer = setInterval(() => {
619
+ etaNow.value = Date.now();
620
+ }, 500);
621
+ collectAbort = new AbortController();
622
+ const collected = [];
623
+ const max = maxCount();
624
+ let truncated = false;
625
+ try {
626
+ const limit = Math.max(1, Math.floor(collectPageSize.value));
627
+ let offset = 0;
628
+ for (; ; ) {
629
+ const res = await props.dataFun({ limit, offset }, collectAbort.signal);
630
+ if (res.totalCount != null) {
631
+ collectTotal.value = res.totalCount;
632
+ collectTotalKnown.value = true;
633
+ }
634
+ const items = res.items;
635
+ const remaining = max - collected.length;
636
+ if (items.length >= remaining) {
637
+ collected.push(...items.slice(0, remaining));
638
+ collectFetched.value = collected.length;
639
+ truncated = res.hasNext || items.length > remaining;
640
+ break;
641
+ }
642
+ collected.push(...items);
643
+ collectFetched.value = collected.length;
644
+ if (collectCancelled || !res.hasNext || items.length === 0) break;
645
+ offset += limit;
646
+ }
647
+ } catch (e) {
648
+ if (!collectCancelled) throw e;
649
+ } finally {
650
+ collecting.value = false;
651
+ stopEtaTimer();
652
+ collectAbort = null;
653
+ }
654
+ if (collectCancelled) return;
655
+ await collector(collected, { scope: "all", truncated, maxCount: max });
656
+ }
657
+ function cancelCollect() {
658
+ collectCancelled = true;
659
+ collectAbort?.abort();
660
+ }
661
+ return {
662
+ collectOptions,
663
+ collectDialogVisible,
664
+ collecting,
665
+ collectFetched,
666
+ collectTotal,
667
+ collectTotalKnown,
668
+ collectEtaSeconds,
669
+ collectPercent,
670
+ onCollectClick,
671
+ doCollect,
672
+ cancelCollect
673
+ };
674
+ }
675
+
676
+ // src/importExcel/importExcel.ts
677
+ var import_vue7 = require("vue");
513
678
  function normalizeHeader(value) {
514
679
  return String(value ?? "").trim().toLowerCase();
515
680
  }
@@ -550,29 +715,29 @@ function resolveColumns(columns, header) {
550
715
  return { resolved, missing };
551
716
  }
552
717
  function useImportExcel({ columns, processor, parser }) {
553
- const rows = (0, import_vue6.ref)([]);
718
+ const rows = (0, import_vue7.ref)([]);
554
719
  let resolvedColumns = [];
555
- const fileName = (0, import_vue6.ref)("");
556
- const sheetName = (0, import_vue6.ref)("");
557
- const loading = (0, import_vue6.ref)(false);
558
- const processing = (0, import_vue6.ref)(false);
559
- const stopping = (0, import_vue6.ref)(false);
720
+ const fileName = (0, import_vue7.ref)("");
721
+ const sheetName = (0, import_vue7.ref)("");
722
+ const loading = (0, import_vue7.ref)(false);
723
+ const processing = (0, import_vue7.ref)(false);
724
+ const stopping = (0, import_vue7.ref)(false);
560
725
  let processController = null;
561
- const processingTotal = (0, import_vue6.ref)(0);
562
- const progressDone = (0, import_vue6.ref)(0);
563
- const progressSuccess = (0, import_vue6.ref)(0);
564
- const progressFailed = (0, import_vue6.ref)(0);
565
- const hasData = (0, import_vue6.computed)(() => rows.value.length > 0);
566
- const invalidCount = (0, import_vue6.computed)(() => rows.value.filter((r) => r.status === "invalid").length);
567
- const successCount = (0, import_vue6.computed)(() => rows.value.filter((r) => r.status === "success").length);
568
- const failedCount = (0, import_vue6.computed)(() => rows.value.filter((r) => r.status === "failed").length);
569
- const selectedCount = (0, import_vue6.computed)(() => rows.value.filter((r) => r.selected).length);
570
- const pendingCount = (0, import_vue6.computed)(
726
+ const processingTotal = (0, import_vue7.ref)(0);
727
+ const progressDone = (0, import_vue7.ref)(0);
728
+ const progressSuccess = (0, import_vue7.ref)(0);
729
+ const progressFailed = (0, import_vue7.ref)(0);
730
+ const hasData = (0, import_vue7.computed)(() => rows.value.length > 0);
731
+ const invalidCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.status === "invalid").length);
732
+ const successCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.status === "success").length);
733
+ const failedCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.status === "failed").length);
734
+ const selectedCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.selected).length);
735
+ const pendingCount = (0, import_vue7.computed)(
571
736
  () => rows.value.filter(
572
737
  (r) => r.selected && (r.status === "valid" || r.status === "failed")
573
738
  ).length
574
739
  );
575
- const processedCount = (0, import_vue6.computed)(() => successCount.value + failedCount.value);
740
+ const processedCount = (0, import_vue7.computed)(() => successCount.value + failedCount.value);
576
741
  function mapInputs(inputs) {
577
742
  const data = {};
578
743
  const errors = [];
@@ -685,7 +850,7 @@ function useImportExcel({ columns, processor, parser }) {
685
850
  row.status = "processing";
686
851
  row.message = void 0;
687
852
  }
688
- await (0, import_vue6.nextTick)();
853
+ await (0, import_vue7.nextTick)();
689
854
  try {
690
855
  const results = await importer.process(chunk, signal);
691
856
  if (!Array.isArray(results) || results.length !== chunk.length) {
@@ -794,7 +959,7 @@ function useImportExcel({ columns, processor, parser }) {
794
959
  }
795
960
 
796
961
  // src/mainPanel/nodes.ts
797
- var import_vue7 = require("vue");
962
+ var import_vue8 = require("vue");
798
963
  function isGroupNode(node) {
799
964
  return !!(node.children && node.children.length > 0);
800
965
  }
@@ -842,8 +1007,8 @@ function filterNodesByKeyword(list, keyword) {
842
1007
  return walk(list);
843
1008
  }
844
1009
  function useMainPanelNodes(props) {
845
- const nodes = (0, import_vue7.ref)([]);
846
- const menuLoading = (0, import_vue7.ref)(false);
1010
+ const nodes = (0, import_vue8.ref)([]);
1011
+ const menuLoading = (0, import_vue8.ref)(false);
847
1012
  async function loadNodes() {
848
1013
  menuLoading.value = true;
849
1014
  try {
@@ -852,7 +1017,7 @@ function useMainPanelNodes(props) {
852
1017
  menuLoading.value = false;
853
1018
  }
854
1019
  }
855
- (0, import_vue7.watch)(() => props.nodesFunc, () => {
1020
+ (0, import_vue8.watch)(() => props.nodesFunc, () => {
856
1021
  void loadNodes();
857
1022
  });
858
1023
  return {
@@ -863,10 +1028,10 @@ function useMainPanelNodes(props) {
863
1028
  }
864
1029
 
865
1030
  // src/mainPanel/tabs.ts
866
- var import_vue8 = require("vue");
1031
+ var import_vue9 = require("vue");
867
1032
  function useMainPanelTabs(props) {
868
- const openTabs = (0, import_vue8.ref)([]);
869
- const activeKey = (0, import_vue8.ref)("");
1033
+ const openTabs = (0, import_vue9.ref)([]);
1034
+ const activeKey = (0, import_vue9.ref)("");
870
1035
  function openTab(node) {
871
1036
  const label = (node.icon ? `${node.icon} ` : "") + node.label;
872
1037
  if (!openTabs.value.some((tab) => tab.key === node.key)) {
@@ -897,9 +1062,9 @@ function useMainPanelTabs(props) {
897
1062
  const loader = props.componentMap?.[path];
898
1063
  componentCache.set(
899
1064
  path,
900
- loader ? (0, import_vue8.defineAsyncComponent)(() => loader().then((m) => m.default)) : (
1065
+ loader ? (0, import_vue9.defineAsyncComponent)(() => loader().then((m) => m.default)) : (
901
1066
  // 未提供 componentMap 时的兜底:跳过打包器静态分析,按运行时动态 import 解析
902
- (0, import_vue8.defineAsyncComponent)(() => import(
1067
+ (0, import_vue9.defineAsyncComponent)(() => import(
903
1068
  /* @vite-ignore */
904
1069
  path
905
1070
  ).then((m) => m.default))
@@ -918,11 +1083,11 @@ function useMainPanelTabs(props) {
918
1083
  }
919
1084
 
920
1085
  // src/filter/filterPanel.ts
921
- var import_vue9 = require("vue");
1086
+ var import_vue10 = require("vue");
922
1087
  var import_ys_knife_query = require("ys.knife.query.js");
923
1088
  var FilterPanelKey = /* @__PURE__ */ Symbol("YsFilterPanel");
924
1089
  function useFilterPanel() {
925
- const items = (0, import_vue9.ref)(/* @__PURE__ */ new Map());
1090
+ const items = (0, import_vue10.ref)(/* @__PURE__ */ new Map());
926
1091
  let counter = 0;
927
1092
  const register = (api) => {
928
1093
  const key = String(++counter);
@@ -933,7 +1098,7 @@ function useFilterPanel() {
933
1098
  items.value = new Map(items.value);
934
1099
  };
935
1100
  };
936
- const filter6 = (0, import_vue9.computed)(() => {
1101
+ const filter6 = (0, import_vue10.computed)(() => {
937
1102
  const nonNull = [...items.value.values()].map((a) => a.filter).filter((f) => f !== null);
938
1103
  if (nonNull.length === 0) return (0, import_ys_knife_query.emptyFilter)();
939
1104
  return import_ys_knife_query.FilterInfo.createAnd(...nonNull);
@@ -945,16 +1110,16 @@ function useFilterPanel() {
945
1110
  }
946
1111
 
947
1112
  // src/filter/textFilterItem.ts
948
- var import_vue10 = require("vue");
1113
+ var import_vue11 = require("vue");
949
1114
  var import_ys_knife_query2 = require("ys.knife.query.js");
950
1115
  function useTextFilterItem(props) {
951
- const value = (0, import_vue10.ref)(
1116
+ const value = (0, import_vue11.ref)(
952
1117
  typeof props.defaultValue === "string" ? props.defaultValue : ""
953
1118
  );
954
1119
  function isEmpty(v) {
955
1120
  return v == null || v.trim() === "";
956
1121
  }
957
- const filterInfo = (0, import_vue10.computed)(() => {
1122
+ const filterInfo = (0, import_vue11.computed)(() => {
958
1123
  if (isEmpty(value.value)) return null;
959
1124
  return (0, import_ys_knife_query2.filter)(props.propertyPath, props.op, (0, import_ys_knife_query2.con)(value.value));
960
1125
  });
@@ -965,16 +1130,16 @@ function useTextFilterItem(props) {
965
1130
  }
966
1131
 
967
1132
  // src/filter/dateFilterItem.ts
968
- var import_vue11 = require("vue");
1133
+ var import_vue12 = require("vue");
969
1134
  var import_ys_knife_query3 = require("ys.knife.query.js");
970
1135
  function useDateFilterItem(props) {
971
- const value = (0, import_vue11.ref)(
1136
+ const value = (0, import_vue12.ref)(
972
1137
  typeof props.defaultValue === "string" ? props.defaultValue : ""
973
1138
  );
974
1139
  function isEmpty(v) {
975
1140
  return v == null || v.trim() === "";
976
1141
  }
977
- const filterInfo = (0, import_vue11.computed)(() => {
1142
+ const filterInfo = (0, import_vue12.computed)(() => {
978
1143
  if (isEmpty(value.value)) return null;
979
1144
  return (0, import_ys_knife_query3.filter)(props.propertyPath, props.op, (0, import_ys_knife_query3.con)(value.value));
980
1145
  });
@@ -985,7 +1150,7 @@ function useDateFilterItem(props) {
985
1150
  }
986
1151
 
987
1152
  // src/filter/dateRangeFilterItem.ts
988
- var import_vue12 = require("vue");
1153
+ var import_vue13 = require("vue");
989
1154
  var import_ys_knife_query4 = require("ys.knife.query.js");
990
1155
  function useDateRangeFilterItem(props) {
991
1156
  function toRange(v) {
@@ -995,11 +1160,11 @@ function useDateRangeFilterItem(props) {
995
1160
  return null;
996
1161
  }
997
1162
  const initial = toRange(props.defaultValue);
998
- const value = (0, import_vue12.ref)(initial);
1163
+ const value = (0, import_vue13.ref)(initial);
999
1164
  function isEmpty(v) {
1000
1165
  return v == null || v.length !== 2 || !v[0] || !v[1];
1001
1166
  }
1002
- const filterInfo = (0, import_vue12.computed)(() => {
1167
+ const filterInfo = (0, import_vue13.computed)(() => {
1003
1168
  if (isEmpty(value.value)) return null;
1004
1169
  const [start, end] = value.value;
1005
1170
  return (0, import_ys_knife_query4.filter)(props.propertyPath, import_ys_knife_query4.Operator.Between, (0, import_ys_knife_query4.con)([start, end]));
@@ -1011,7 +1176,7 @@ function useDateRangeFilterItem(props) {
1011
1176
  }
1012
1177
 
1013
1178
  // src/filter/enumFilterItem.ts
1014
- var import_vue13 = require("vue");
1179
+ var import_vue14 = require("vue");
1015
1180
  var import_ys_knife_query5 = require("ys.knife.query.js");
1016
1181
  function toSingleValue(v) {
1017
1182
  if (typeof v === "string" || typeof v === "number") return v;
@@ -1027,7 +1192,7 @@ function toMultiValue(v) {
1027
1192
  }
1028
1193
  function useEnumFilterItem(props) {
1029
1194
  const isMultiple = props.multiple === true;
1030
- const value = (0, import_vue13.ref)(
1195
+ const value = (0, import_vue14.ref)(
1031
1196
  isMultiple ? toMultiValue(props.defaultValue) : toSingleValue(props.defaultValue)
1032
1197
  );
1033
1198
  function isEmpty() {
@@ -1039,7 +1204,7 @@ function useEnumFilterItem(props) {
1039
1204
  if (typeof v === "string" && v.trim() === "") return true;
1040
1205
  return false;
1041
1206
  }
1042
- const filterInfo = (0, import_vue13.computed)(() => {
1207
+ const filterInfo = (0, import_vue14.computed)(() => {
1043
1208
  if (isEmpty()) return null;
1044
1209
  if (isMultiple) {
1045
1210
  const arr = value.value;
@@ -1065,7 +1230,7 @@ function useEnumFilterItem(props) {
1065
1230
  }
1066
1231
 
1067
1232
  // src/advancedFilter/advancedFilter.ts
1068
- var import_vue14 = require("vue");
1233
+ var import_vue15 = require("vue");
1069
1234
  var import_ys_knife_query6 = require("ys.knife.query.js");
1070
1235
  var import_core2 = require("@ys-knife-crud/core");
1071
1236
  var import_core3 = require("@ys-knife-crud/core");
@@ -1074,7 +1239,7 @@ function useAdvancedFilter(props) {
1074
1239
  function nextId(prefix) {
1075
1240
  return `adv-${prefix}-${++seq}`;
1076
1241
  }
1077
- const fieldTypeMap = (0, import_vue14.computed)(() => {
1242
+ const fieldTypeMap = (0, import_vue15.computed)(() => {
1078
1243
  const map = /* @__PURE__ */ new Map();
1079
1244
  for (const col of props.columns) {
1080
1245
  map.set(
@@ -1116,7 +1281,7 @@ function useAdvancedFilter(props) {
1116
1281
  children: [newLeaf()]
1117
1282
  };
1118
1283
  }
1119
- const rootGroup = (0, import_vue14.ref)({
1284
+ const rootGroup = (0, import_vue15.ref)({
1120
1285
  id: "root",
1121
1286
  combinator: "and",
1122
1287
  children: [newLeaf()]
@@ -1270,7 +1435,7 @@ function useAdvancedFilter(props) {
1270
1435
  }
1271
1436
  return buildConditionFilter(node);
1272
1437
  }
1273
- const filterInfo = (0, import_vue14.computed)(() => {
1438
+ const filterInfo = (0, import_vue15.computed)(() => {
1274
1439
  const f = buildNodeFilter(rootGroup.value);
1275
1440
  return f ?? (0, import_ys_knife_query6.emptyFilter)();
1276
1441
  });
@@ -1314,6 +1479,7 @@ function getDefaultModalAppContext() {
1314
1479
  isGroupNode,
1315
1480
  setDefaultModalAppContext,
1316
1481
  useAdvancedFilter,
1482
+ useCollectData,
1317
1483
  useCustomConfig,
1318
1484
  useDateFilterItem,
1319
1485
  useDateRangeFilterItem,