@ys-knife-crud/vue 0.0.14 → 0.0.16

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.js CHANGED
@@ -284,7 +284,8 @@ function useCustomConfig(props, meta) {
284
284
  // src/table/exportExcel.ts
285
285
  import { computed as computed4, onScopeDispose, ref as ref5 } from "vue";
286
286
  import {
287
- createConsoleExportApiFunc
287
+ createConsoleExportApiFunc,
288
+ formatCellValue
288
289
  } from "@ys-knife-crud/core";
289
290
  function useExportExcel({
290
291
  props,
@@ -293,6 +294,7 @@ function useExportExcel({
293
294
  currentRows,
294
295
  selectedRows,
295
296
  total,
297
+ totalKnown,
296
298
  exportPageSize,
297
299
  hasMorePage,
298
300
  pageScopeLabel
@@ -308,7 +310,11 @@ function useExportExcel({
308
310
  }
309
311
  opts.push({ value: "page", label: `${pageScopeLabel?.value ?? "\u5BFC\u51FA\u5F53\u524D\u9875\u6570\u636E"}\uFF08${currentRows.value.length} \u6761\uFF09`, disabled: false });
310
312
  if (hasMorePage.value) {
311
- opts.push({ value: "all", label: "\u5BFC\u51FA\u6240\u6709\u6570\u636E", disabled: false });
313
+ opts.push({
314
+ value: "all",
315
+ label: totalKnown.value ? `\u5BFC\u51FA\u6240\u6709\u6570\u636E\uFF08\u5171 ${total.value} \u6761\uFF09` : "\u5BFC\u51FA\u6240\u6709\u6570\u636E",
316
+ disabled: false
317
+ });
312
318
  }
313
319
  return opts;
314
320
  });
@@ -361,7 +367,7 @@ function useExportExcel({
361
367
  return createConsoleExportApiFunc()();
362
368
  }
363
369
  function exportRowValues(row) {
364
- return columns.value.map((c) => row[c.propertyPath] ?? null);
370
+ return columns.value.map((c) => formatCellValue(c, row));
365
371
  }
366
372
  async function doExport(scope) {
367
373
  exportDialogVisible.value = false;
@@ -462,8 +468,181 @@ function useExportExcel({
462
468
  };
463
469
  }
464
470
 
471
+ // src/table/collectData.ts
472
+ import { computed as computed5, onScopeDispose as onScopeDispose2, ref as ref6 } from "vue";
473
+ import { formatCellValue as formatCellValue2, getDefaultFormatter } from "@ys-knife-crud/core";
474
+ function useCollectData({
475
+ props,
476
+ selectable,
477
+ currentRows,
478
+ selectedRows,
479
+ total,
480
+ totalKnown,
481
+ collectPageSize,
482
+ hasMorePage,
483
+ columns,
484
+ pageScopeLabel
485
+ }) {
486
+ function maxCount() {
487
+ return Math.max(1, Math.floor(props.maxCollectCount));
488
+ }
489
+ const collectOptions = computed5(() => {
490
+ const opts = [];
491
+ if (selectable.value) {
492
+ opts.push({
493
+ value: "selected",
494
+ label: `\u9009\u4E2D\u7684\u6570\u636E\uFF08\u5DF2\u9009 ${selectedRows.value.length} \u9879\uFF09`,
495
+ disabled: selectedRows.value.length === 0
496
+ });
497
+ }
498
+ opts.push({
499
+ value: "page",
500
+ label: `${pageScopeLabel?.value ?? "\u5F53\u524D\u9875\u7684\u6570\u636E"}\uFF08${currentRows.value.length} \u6761\uFF09`,
501
+ disabled: false
502
+ });
503
+ if (hasMorePage.value) {
504
+ opts.push({
505
+ value: "all",
506
+ label: totalKnown.value ? `\u6240\u6709\u6570\u636E\uFF08\u5171 ${total.value} \u6761\uFF09` : "\u6240\u6709\u6570\u636E",
507
+ disabled: false
508
+ });
509
+ }
510
+ return opts;
511
+ });
512
+ const collectDialogVisible = ref6(false);
513
+ const formatValues = ref6(true);
514
+ function formatRows(rows) {
515
+ if (!formatValues.value) return rows;
516
+ const cols = columns.value.filter((c) => c.formatter || getDefaultFormatter(c));
517
+ if (cols.length === 0) return rows;
518
+ return rows.map((row) => {
519
+ const out = { ...row };
520
+ for (const c of cols) out[c.propertyPath] = formatCellValue2(c, row);
521
+ return out;
522
+ });
523
+ }
524
+ const collecting = ref6(false);
525
+ const collectFetched = ref6(0);
526
+ const collectTotal = ref6(0);
527
+ const collectTotalKnown = ref6(false);
528
+ let collectCancelled = false;
529
+ let collectAbort = null;
530
+ let collectStartedAt = 0;
531
+ let etaTimer = null;
532
+ const etaNow = ref6(0);
533
+ onScopeDispose2(stopEtaTimer);
534
+ function stopEtaTimer() {
535
+ if (etaTimer != null) {
536
+ clearInterval(etaTimer);
537
+ etaTimer = null;
538
+ }
539
+ }
540
+ const collectEtaSeconds = computed5(() => {
541
+ if (!collectTotalKnown.value || collectFetched.value === 0) return null;
542
+ const elapsed = (etaNow.value - collectStartedAt) / 1e3;
543
+ if (elapsed < 0.5) return null;
544
+ const remaining = collectTotal.value - collectFetched.value;
545
+ if (remaining <= 0) return null;
546
+ return Math.max(1, Math.ceil(remaining / (collectFetched.value / elapsed)));
547
+ });
548
+ const collectPercent = computed5(() => {
549
+ if (collectTotalKnown.value && collectTotal.value > 0)
550
+ return Math.min(100, Math.round(collectFetched.value / collectTotal.value * 100));
551
+ return collectFetched.value > 0 ? 99 : 0;
552
+ });
553
+ function onCollectClick(options) {
554
+ if (!props.collectorFunc) return;
555
+ formatValues.value = options?.format !== false;
556
+ const enabled = collectOptions.value.filter((o) => !o.disabled);
557
+ if (enabled.length === 1) {
558
+ void doCollect(enabled[0].value);
559
+ return;
560
+ }
561
+ collectDialogVisible.value = true;
562
+ }
563
+ async function doCollect(scope) {
564
+ collectDialogVisible.value = false;
565
+ const collector = props.collectorFunc;
566
+ if (!collector) return;
567
+ if (scope === "all") {
568
+ await collectAllStreaming(collector);
569
+ return;
570
+ }
571
+ const source = scope === "selected" ? selectedRows.value : currentRows.value;
572
+ const max = maxCount();
573
+ const truncated = source.length > max;
574
+ const rows = (truncated ? source.slice(0, max) : source).slice();
575
+ await collector(formatRows(rows), { scope, truncated, maxCount: max });
576
+ }
577
+ async function collectAllStreaming(collector) {
578
+ collecting.value = true;
579
+ collectCancelled = false;
580
+ collectFetched.value = 0;
581
+ collectTotal.value = total.value;
582
+ collectTotalKnown.value = false;
583
+ collectStartedAt = Date.now();
584
+ etaNow.value = collectStartedAt;
585
+ stopEtaTimer();
586
+ etaTimer = setInterval(() => {
587
+ etaNow.value = Date.now();
588
+ }, 500);
589
+ collectAbort = new AbortController();
590
+ const collected = [];
591
+ const max = maxCount();
592
+ let truncated = false;
593
+ try {
594
+ const limit = Math.max(1, Math.floor(collectPageSize.value));
595
+ let offset = 0;
596
+ for (; ; ) {
597
+ const res = await props.dataFun({ limit, offset }, collectAbort.signal);
598
+ if (res.totalCount != null) {
599
+ collectTotal.value = res.totalCount;
600
+ collectTotalKnown.value = true;
601
+ }
602
+ const items = res.items;
603
+ const remaining = max - collected.length;
604
+ if (items.length >= remaining) {
605
+ collected.push(...items.slice(0, remaining));
606
+ collectFetched.value = collected.length;
607
+ truncated = res.hasNext || items.length > remaining;
608
+ break;
609
+ }
610
+ collected.push(...items);
611
+ collectFetched.value = collected.length;
612
+ if (collectCancelled || !res.hasNext || items.length === 0) break;
613
+ offset += limit;
614
+ }
615
+ } catch (e) {
616
+ if (!collectCancelled) throw e;
617
+ } finally {
618
+ collecting.value = false;
619
+ stopEtaTimer();
620
+ collectAbort = null;
621
+ }
622
+ if (collectCancelled) return;
623
+ await collector(formatRows(collected), { scope: "all", truncated, maxCount: max });
624
+ }
625
+ function cancelCollect() {
626
+ collectCancelled = true;
627
+ collectAbort?.abort();
628
+ }
629
+ return {
630
+ collectOptions,
631
+ collectDialogVisible,
632
+ collecting,
633
+ collectFetched,
634
+ collectTotal,
635
+ collectTotalKnown,
636
+ collectEtaSeconds,
637
+ collectPercent,
638
+ onCollectClick,
639
+ doCollect,
640
+ cancelCollect
641
+ };
642
+ }
643
+
465
644
  // src/importExcel/importExcel.ts
466
- import { computed as computed5, nextTick as nextTick2, ref as ref6 } from "vue";
645
+ import { computed as computed6, nextTick as nextTick2, ref as ref7 } from "vue";
467
646
  function normalizeHeader(value) {
468
647
  return String(value ?? "").trim().toLowerCase();
469
648
  }
@@ -504,29 +683,29 @@ function resolveColumns(columns, header) {
504
683
  return { resolved, missing };
505
684
  }
506
685
  function useImportExcel({ columns, processor, parser }) {
507
- const rows = ref6([]);
686
+ const rows = ref7([]);
508
687
  let resolvedColumns = [];
509
- const fileName = ref6("");
510
- const sheetName = ref6("");
511
- const loading = ref6(false);
512
- const processing = ref6(false);
513
- const stopping = ref6(false);
688
+ const fileName = ref7("");
689
+ const sheetName = ref7("");
690
+ const loading = ref7(false);
691
+ const processing = ref7(false);
692
+ const stopping = ref7(false);
514
693
  let processController = null;
515
- const processingTotal = ref6(0);
516
- const progressDone = ref6(0);
517
- const progressSuccess = ref6(0);
518
- const progressFailed = ref6(0);
519
- const hasData = computed5(() => rows.value.length > 0);
520
- const invalidCount = computed5(() => rows.value.filter((r) => r.status === "invalid").length);
521
- const successCount = computed5(() => rows.value.filter((r) => r.status === "success").length);
522
- const failedCount = computed5(() => rows.value.filter((r) => r.status === "failed").length);
523
- const selectedCount = computed5(() => rows.value.filter((r) => r.selected).length);
524
- const pendingCount = computed5(
694
+ const processingTotal = ref7(0);
695
+ const progressDone = ref7(0);
696
+ const progressSuccess = ref7(0);
697
+ const progressFailed = ref7(0);
698
+ const hasData = computed6(() => rows.value.length > 0);
699
+ const invalidCount = computed6(() => rows.value.filter((r) => r.status === "invalid").length);
700
+ const successCount = computed6(() => rows.value.filter((r) => r.status === "success").length);
701
+ const failedCount = computed6(() => rows.value.filter((r) => r.status === "failed").length);
702
+ const selectedCount = computed6(() => rows.value.filter((r) => r.selected).length);
703
+ const pendingCount = computed6(
525
704
  () => rows.value.filter(
526
705
  (r) => r.selected && (r.status === "valid" || r.status === "failed")
527
706
  ).length
528
707
  );
529
- const processedCount = computed5(() => successCount.value + failedCount.value);
708
+ const processedCount = computed6(() => successCount.value + failedCount.value);
530
709
  function mapInputs(inputs) {
531
710
  const data = {};
532
711
  const errors = [];
@@ -748,7 +927,7 @@ function useImportExcel({ columns, processor, parser }) {
748
927
  }
749
928
 
750
929
  // src/mainPanel/nodes.ts
751
- import { ref as ref7, watch as watch5 } from "vue";
930
+ import { ref as ref8, watch as watch5 } from "vue";
752
931
  function isGroupNode(node) {
753
932
  return !!(node.children && node.children.length > 0);
754
933
  }
@@ -796,8 +975,8 @@ function filterNodesByKeyword(list, keyword) {
796
975
  return walk(list);
797
976
  }
798
977
  function useMainPanelNodes(props) {
799
- const nodes = ref7([]);
800
- const menuLoading = ref7(false);
978
+ const nodes = ref8([]);
979
+ const menuLoading = ref8(false);
801
980
  async function loadNodes() {
802
981
  menuLoading.value = true;
803
982
  try {
@@ -817,10 +996,10 @@ function useMainPanelNodes(props) {
817
996
  }
818
997
 
819
998
  // src/mainPanel/tabs.ts
820
- import { defineAsyncComponent, ref as ref8 } from "vue";
999
+ import { defineAsyncComponent, ref as ref9 } from "vue";
821
1000
  function useMainPanelTabs(props) {
822
- const openTabs = ref8([]);
823
- const activeKey = ref8("");
1001
+ const openTabs = ref9([]);
1002
+ const activeKey = ref9("");
824
1003
  function openTab(node) {
825
1004
  const label = (node.icon ? `${node.icon} ` : "") + node.label;
826
1005
  if (!openTabs.value.some((tab) => tab.key === node.key)) {
@@ -872,11 +1051,11 @@ function useMainPanelTabs(props) {
872
1051
  }
873
1052
 
874
1053
  // src/filter/filterPanel.ts
875
- import { computed as computed6, ref as ref9 } from "vue";
1054
+ import { computed as computed7, ref as ref10 } from "vue";
876
1055
  import { FilterInfo, emptyFilter } from "ys.knife.query.js";
877
1056
  var FilterPanelKey = /* @__PURE__ */ Symbol("YsFilterPanel");
878
1057
  function useFilterPanel() {
879
- const items = ref9(/* @__PURE__ */ new Map());
1058
+ const items = ref10(/* @__PURE__ */ new Map());
880
1059
  let counter = 0;
881
1060
  const register = (api) => {
882
1061
  const key = String(++counter);
@@ -887,7 +1066,7 @@ function useFilterPanel() {
887
1066
  items.value = new Map(items.value);
888
1067
  };
889
1068
  };
890
- const filter6 = computed6(() => {
1069
+ const filter6 = computed7(() => {
891
1070
  const nonNull = [...items.value.values()].map((a) => a.filter).filter((f) => f !== null);
892
1071
  if (nonNull.length === 0) return emptyFilter();
893
1072
  return FilterInfo.createAnd(...nonNull);
@@ -899,16 +1078,16 @@ function useFilterPanel() {
899
1078
  }
900
1079
 
901
1080
  // src/filter/textFilterItem.ts
902
- import { computed as computed7, ref as ref10 } from "vue";
1081
+ import { computed as computed8, ref as ref11 } from "vue";
903
1082
  import { filter, con } from "ys.knife.query.js";
904
1083
  function useTextFilterItem(props) {
905
- const value = ref10(
1084
+ const value = ref11(
906
1085
  typeof props.defaultValue === "string" ? props.defaultValue : ""
907
1086
  );
908
1087
  function isEmpty(v) {
909
1088
  return v == null || v.trim() === "";
910
1089
  }
911
- const filterInfo = computed7(() => {
1090
+ const filterInfo = computed8(() => {
912
1091
  if (isEmpty(value.value)) return null;
913
1092
  return filter(props.propertyPath, props.op, con(value.value));
914
1093
  });
@@ -919,16 +1098,16 @@ function useTextFilterItem(props) {
919
1098
  }
920
1099
 
921
1100
  // src/filter/dateFilterItem.ts
922
- import { computed as computed8, ref as ref11 } from "vue";
1101
+ import { computed as computed9, ref as ref12 } from "vue";
923
1102
  import { filter as filter2, con as con2 } from "ys.knife.query.js";
924
1103
  function useDateFilterItem(props) {
925
- const value = ref11(
1104
+ const value = ref12(
926
1105
  typeof props.defaultValue === "string" ? props.defaultValue : ""
927
1106
  );
928
1107
  function isEmpty(v) {
929
1108
  return v == null || v.trim() === "";
930
1109
  }
931
- const filterInfo = computed8(() => {
1110
+ const filterInfo = computed9(() => {
932
1111
  if (isEmpty(value.value)) return null;
933
1112
  return filter2(props.propertyPath, props.op, con2(value.value));
934
1113
  });
@@ -939,7 +1118,7 @@ function useDateFilterItem(props) {
939
1118
  }
940
1119
 
941
1120
  // src/filter/dateRangeFilterItem.ts
942
- import { computed as computed9, ref as ref12 } from "vue";
1121
+ import { computed as computed10, ref as ref13 } from "vue";
943
1122
  import { filter as filter3, con as con3, Operator } from "ys.knife.query.js";
944
1123
  function useDateRangeFilterItem(props) {
945
1124
  function toRange(v) {
@@ -949,11 +1128,11 @@ function useDateRangeFilterItem(props) {
949
1128
  return null;
950
1129
  }
951
1130
  const initial = toRange(props.defaultValue);
952
- const value = ref12(initial);
1131
+ const value = ref13(initial);
953
1132
  function isEmpty(v) {
954
1133
  return v == null || v.length !== 2 || !v[0] || !v[1];
955
1134
  }
956
- const filterInfo = computed9(() => {
1135
+ const filterInfo = computed10(() => {
957
1136
  if (isEmpty(value.value)) return null;
958
1137
  const [start, end] = value.value;
959
1138
  return filter3(props.propertyPath, Operator.Between, con3([start, end]));
@@ -965,7 +1144,7 @@ function useDateRangeFilterItem(props) {
965
1144
  }
966
1145
 
967
1146
  // src/filter/enumFilterItem.ts
968
- import { computed as computed10, ref as ref13 } from "vue";
1147
+ import { computed as computed11, ref as ref14 } from "vue";
969
1148
  import { filter as filter4, con as con4, Operator as Operator2 } from "ys.knife.query.js";
970
1149
  function toSingleValue(v) {
971
1150
  if (typeof v === "string" || typeof v === "number") return v;
@@ -981,7 +1160,7 @@ function toMultiValue(v) {
981
1160
  }
982
1161
  function useEnumFilterItem(props) {
983
1162
  const isMultiple = props.multiple === true;
984
- const value = ref13(
1163
+ const value = ref14(
985
1164
  isMultiple ? toMultiValue(props.defaultValue) : toSingleValue(props.defaultValue)
986
1165
  );
987
1166
  function isEmpty() {
@@ -993,7 +1172,7 @@ function useEnumFilterItem(props) {
993
1172
  if (typeof v === "string" && v.trim() === "") return true;
994
1173
  return false;
995
1174
  }
996
- const filterInfo = computed10(() => {
1175
+ const filterInfo = computed11(() => {
997
1176
  if (isEmpty()) return null;
998
1177
  if (isMultiple) {
999
1178
  const arr = value.value;
@@ -1019,7 +1198,7 @@ function useEnumFilterItem(props) {
1019
1198
  }
1020
1199
 
1021
1200
  // src/advancedFilter/advancedFilter.ts
1022
- import { computed as computed11, ref as ref14 } from "vue";
1201
+ import { computed as computed12, ref as ref15 } from "vue";
1023
1202
  import { FilterInfo as FilterInfo2, Operator as Operator3, con as con5, emptyFilter as emptyFilter2, filter as filter5 } from "ys.knife.query.js";
1024
1203
  import { isConditionGroup, isNullOperator } from "@ys-knife-crud/core";
1025
1204
  import {
@@ -1034,7 +1213,7 @@ function useAdvancedFilter(props) {
1034
1213
  function nextId(prefix) {
1035
1214
  return `adv-${prefix}-${++seq}`;
1036
1215
  }
1037
- const fieldTypeMap = computed11(() => {
1216
+ const fieldTypeMap = computed12(() => {
1038
1217
  const map = /* @__PURE__ */ new Map();
1039
1218
  for (const col of props.columns) {
1040
1219
  map.set(
@@ -1076,7 +1255,7 @@ function useAdvancedFilter(props) {
1076
1255
  children: [newLeaf()]
1077
1256
  };
1078
1257
  }
1079
- const rootGroup = ref14({
1258
+ const rootGroup = ref15({
1080
1259
  id: "root",
1081
1260
  combinator: "and",
1082
1261
  children: [newLeaf()]
@@ -1230,7 +1409,7 @@ function useAdvancedFilter(props) {
1230
1409
  }
1231
1410
  return buildConditionFilter(node);
1232
1411
  }
1233
- const filterInfo = computed11(() => {
1412
+ const filterInfo = computed12(() => {
1234
1413
  const f = buildNodeFilter(rootGroup.value);
1235
1414
  return f ?? emptyFilter2();
1236
1415
  });
@@ -1273,6 +1452,7 @@ export {
1273
1452
  isGroupNode,
1274
1453
  setDefaultModalAppContext,
1275
1454
  useAdvancedFilter,
1455
+ useCollectData,
1276
1456
  useCustomConfig,
1277
1457
  useDateFilterItem,
1278
1458
  useDateRangeFilterItem,