@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/README.md +1 -0
- package/dist/index.cjs +249 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -6
- package/dist/index.d.ts +60 -6
- package/dist/index.js +226 -46
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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({
|
|
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
|
});
|
|
@@ -407,7 +413,7 @@ function useExportExcel({
|
|
|
407
413
|
return (0, import_core.createConsoleExportApiFunc)()();
|
|
408
414
|
}
|
|
409
415
|
function exportRowValues(row) {
|
|
410
|
-
return columns.value.map((c) =>
|
|
416
|
+
return columns.value.map((c) => (0, import_core.formatCellValue)(c, row));
|
|
411
417
|
}
|
|
412
418
|
async function doExport(scope) {
|
|
413
419
|
exportDialogVisible.value = false;
|
|
@@ -508,8 +514,181 @@ function useExportExcel({
|
|
|
508
514
|
};
|
|
509
515
|
}
|
|
510
516
|
|
|
511
|
-
// src/
|
|
517
|
+
// src/table/collectData.ts
|
|
512
518
|
var import_vue6 = require("vue");
|
|
519
|
+
var import_core2 = require("@ys-knife-crud/core");
|
|
520
|
+
function useCollectData({
|
|
521
|
+
props,
|
|
522
|
+
selectable,
|
|
523
|
+
currentRows,
|
|
524
|
+
selectedRows,
|
|
525
|
+
total,
|
|
526
|
+
totalKnown,
|
|
527
|
+
collectPageSize,
|
|
528
|
+
hasMorePage,
|
|
529
|
+
columns,
|
|
530
|
+
pageScopeLabel
|
|
531
|
+
}) {
|
|
532
|
+
function maxCount() {
|
|
533
|
+
return Math.max(1, Math.floor(props.maxCollectCount));
|
|
534
|
+
}
|
|
535
|
+
const collectOptions = (0, import_vue6.computed)(() => {
|
|
536
|
+
const opts = [];
|
|
537
|
+
if (selectable.value) {
|
|
538
|
+
opts.push({
|
|
539
|
+
value: "selected",
|
|
540
|
+
label: `\u9009\u4E2D\u7684\u6570\u636E\uFF08\u5DF2\u9009 ${selectedRows.value.length} \u9879\uFF09`,
|
|
541
|
+
disabled: selectedRows.value.length === 0
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
opts.push({
|
|
545
|
+
value: "page",
|
|
546
|
+
label: `${pageScopeLabel?.value ?? "\u5F53\u524D\u9875\u7684\u6570\u636E"}\uFF08${currentRows.value.length} \u6761\uFF09`,
|
|
547
|
+
disabled: false
|
|
548
|
+
});
|
|
549
|
+
if (hasMorePage.value) {
|
|
550
|
+
opts.push({
|
|
551
|
+
value: "all",
|
|
552
|
+
label: totalKnown.value ? `\u6240\u6709\u6570\u636E\uFF08\u5171 ${total.value} \u6761\uFF09` : "\u6240\u6709\u6570\u636E",
|
|
553
|
+
disabled: false
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
return opts;
|
|
557
|
+
});
|
|
558
|
+
const collectDialogVisible = (0, import_vue6.ref)(false);
|
|
559
|
+
const formatValues = (0, import_vue6.ref)(true);
|
|
560
|
+
function formatRows(rows) {
|
|
561
|
+
if (!formatValues.value) return rows;
|
|
562
|
+
const cols = columns.value.filter((c) => c.formatter || (0, import_core2.getDefaultFormatter)(c));
|
|
563
|
+
if (cols.length === 0) return rows;
|
|
564
|
+
return rows.map((row) => {
|
|
565
|
+
const out = { ...row };
|
|
566
|
+
for (const c of cols) out[c.propertyPath] = (0, import_core2.formatCellValue)(c, row);
|
|
567
|
+
return out;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
const collecting = (0, import_vue6.ref)(false);
|
|
571
|
+
const collectFetched = (0, import_vue6.ref)(0);
|
|
572
|
+
const collectTotal = (0, import_vue6.ref)(0);
|
|
573
|
+
const collectTotalKnown = (0, import_vue6.ref)(false);
|
|
574
|
+
let collectCancelled = false;
|
|
575
|
+
let collectAbort = null;
|
|
576
|
+
let collectStartedAt = 0;
|
|
577
|
+
let etaTimer = null;
|
|
578
|
+
const etaNow = (0, import_vue6.ref)(0);
|
|
579
|
+
(0, import_vue6.onScopeDispose)(stopEtaTimer);
|
|
580
|
+
function stopEtaTimer() {
|
|
581
|
+
if (etaTimer != null) {
|
|
582
|
+
clearInterval(etaTimer);
|
|
583
|
+
etaTimer = null;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const collectEtaSeconds = (0, import_vue6.computed)(() => {
|
|
587
|
+
if (!collectTotalKnown.value || collectFetched.value === 0) return null;
|
|
588
|
+
const elapsed = (etaNow.value - collectStartedAt) / 1e3;
|
|
589
|
+
if (elapsed < 0.5) return null;
|
|
590
|
+
const remaining = collectTotal.value - collectFetched.value;
|
|
591
|
+
if (remaining <= 0) return null;
|
|
592
|
+
return Math.max(1, Math.ceil(remaining / (collectFetched.value / elapsed)));
|
|
593
|
+
});
|
|
594
|
+
const collectPercent = (0, import_vue6.computed)(() => {
|
|
595
|
+
if (collectTotalKnown.value && collectTotal.value > 0)
|
|
596
|
+
return Math.min(100, Math.round(collectFetched.value / collectTotal.value * 100));
|
|
597
|
+
return collectFetched.value > 0 ? 99 : 0;
|
|
598
|
+
});
|
|
599
|
+
function onCollectClick(options) {
|
|
600
|
+
if (!props.collectorFunc) return;
|
|
601
|
+
formatValues.value = options?.format !== false;
|
|
602
|
+
const enabled = collectOptions.value.filter((o) => !o.disabled);
|
|
603
|
+
if (enabled.length === 1) {
|
|
604
|
+
void doCollect(enabled[0].value);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
collectDialogVisible.value = true;
|
|
608
|
+
}
|
|
609
|
+
async function doCollect(scope) {
|
|
610
|
+
collectDialogVisible.value = false;
|
|
611
|
+
const collector = props.collectorFunc;
|
|
612
|
+
if (!collector) return;
|
|
613
|
+
if (scope === "all") {
|
|
614
|
+
await collectAllStreaming(collector);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const source = scope === "selected" ? selectedRows.value : currentRows.value;
|
|
618
|
+
const max = maxCount();
|
|
619
|
+
const truncated = source.length > max;
|
|
620
|
+
const rows = (truncated ? source.slice(0, max) : source).slice();
|
|
621
|
+
await collector(formatRows(rows), { scope, truncated, maxCount: max });
|
|
622
|
+
}
|
|
623
|
+
async function collectAllStreaming(collector) {
|
|
624
|
+
collecting.value = true;
|
|
625
|
+
collectCancelled = false;
|
|
626
|
+
collectFetched.value = 0;
|
|
627
|
+
collectTotal.value = total.value;
|
|
628
|
+
collectTotalKnown.value = false;
|
|
629
|
+
collectStartedAt = Date.now();
|
|
630
|
+
etaNow.value = collectStartedAt;
|
|
631
|
+
stopEtaTimer();
|
|
632
|
+
etaTimer = setInterval(() => {
|
|
633
|
+
etaNow.value = Date.now();
|
|
634
|
+
}, 500);
|
|
635
|
+
collectAbort = new AbortController();
|
|
636
|
+
const collected = [];
|
|
637
|
+
const max = maxCount();
|
|
638
|
+
let truncated = false;
|
|
639
|
+
try {
|
|
640
|
+
const limit = Math.max(1, Math.floor(collectPageSize.value));
|
|
641
|
+
let offset = 0;
|
|
642
|
+
for (; ; ) {
|
|
643
|
+
const res = await props.dataFun({ limit, offset }, collectAbort.signal);
|
|
644
|
+
if (res.totalCount != null) {
|
|
645
|
+
collectTotal.value = res.totalCount;
|
|
646
|
+
collectTotalKnown.value = true;
|
|
647
|
+
}
|
|
648
|
+
const items = res.items;
|
|
649
|
+
const remaining = max - collected.length;
|
|
650
|
+
if (items.length >= remaining) {
|
|
651
|
+
collected.push(...items.slice(0, remaining));
|
|
652
|
+
collectFetched.value = collected.length;
|
|
653
|
+
truncated = res.hasNext || items.length > remaining;
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
collected.push(...items);
|
|
657
|
+
collectFetched.value = collected.length;
|
|
658
|
+
if (collectCancelled || !res.hasNext || items.length === 0) break;
|
|
659
|
+
offset += limit;
|
|
660
|
+
}
|
|
661
|
+
} catch (e) {
|
|
662
|
+
if (!collectCancelled) throw e;
|
|
663
|
+
} finally {
|
|
664
|
+
collecting.value = false;
|
|
665
|
+
stopEtaTimer();
|
|
666
|
+
collectAbort = null;
|
|
667
|
+
}
|
|
668
|
+
if (collectCancelled) return;
|
|
669
|
+
await collector(formatRows(collected), { scope: "all", truncated, maxCount: max });
|
|
670
|
+
}
|
|
671
|
+
function cancelCollect() {
|
|
672
|
+
collectCancelled = true;
|
|
673
|
+
collectAbort?.abort();
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
collectOptions,
|
|
677
|
+
collectDialogVisible,
|
|
678
|
+
collecting,
|
|
679
|
+
collectFetched,
|
|
680
|
+
collectTotal,
|
|
681
|
+
collectTotalKnown,
|
|
682
|
+
collectEtaSeconds,
|
|
683
|
+
collectPercent,
|
|
684
|
+
onCollectClick,
|
|
685
|
+
doCollect,
|
|
686
|
+
cancelCollect
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// src/importExcel/importExcel.ts
|
|
691
|
+
var import_vue7 = require("vue");
|
|
513
692
|
function normalizeHeader(value) {
|
|
514
693
|
return String(value ?? "").trim().toLowerCase();
|
|
515
694
|
}
|
|
@@ -550,29 +729,29 @@ function resolveColumns(columns, header) {
|
|
|
550
729
|
return { resolved, missing };
|
|
551
730
|
}
|
|
552
731
|
function useImportExcel({ columns, processor, parser }) {
|
|
553
|
-
const rows = (0,
|
|
732
|
+
const rows = (0, import_vue7.ref)([]);
|
|
554
733
|
let resolvedColumns = [];
|
|
555
|
-
const fileName = (0,
|
|
556
|
-
const sheetName = (0,
|
|
557
|
-
const loading = (0,
|
|
558
|
-
const processing = (0,
|
|
559
|
-
const stopping = (0,
|
|
734
|
+
const fileName = (0, import_vue7.ref)("");
|
|
735
|
+
const sheetName = (0, import_vue7.ref)("");
|
|
736
|
+
const loading = (0, import_vue7.ref)(false);
|
|
737
|
+
const processing = (0, import_vue7.ref)(false);
|
|
738
|
+
const stopping = (0, import_vue7.ref)(false);
|
|
560
739
|
let processController = null;
|
|
561
|
-
const processingTotal = (0,
|
|
562
|
-
const progressDone = (0,
|
|
563
|
-
const progressSuccess = (0,
|
|
564
|
-
const progressFailed = (0,
|
|
565
|
-
const hasData = (0,
|
|
566
|
-
const invalidCount = (0,
|
|
567
|
-
const successCount = (0,
|
|
568
|
-
const failedCount = (0,
|
|
569
|
-
const selectedCount = (0,
|
|
570
|
-
const pendingCount = (0,
|
|
740
|
+
const processingTotal = (0, import_vue7.ref)(0);
|
|
741
|
+
const progressDone = (0, import_vue7.ref)(0);
|
|
742
|
+
const progressSuccess = (0, import_vue7.ref)(0);
|
|
743
|
+
const progressFailed = (0, import_vue7.ref)(0);
|
|
744
|
+
const hasData = (0, import_vue7.computed)(() => rows.value.length > 0);
|
|
745
|
+
const invalidCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.status === "invalid").length);
|
|
746
|
+
const successCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.status === "success").length);
|
|
747
|
+
const failedCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.status === "failed").length);
|
|
748
|
+
const selectedCount = (0, import_vue7.computed)(() => rows.value.filter((r) => r.selected).length);
|
|
749
|
+
const pendingCount = (0, import_vue7.computed)(
|
|
571
750
|
() => rows.value.filter(
|
|
572
751
|
(r) => r.selected && (r.status === "valid" || r.status === "failed")
|
|
573
752
|
).length
|
|
574
753
|
);
|
|
575
|
-
const processedCount = (0,
|
|
754
|
+
const processedCount = (0, import_vue7.computed)(() => successCount.value + failedCount.value);
|
|
576
755
|
function mapInputs(inputs) {
|
|
577
756
|
const data = {};
|
|
578
757
|
const errors = [];
|
|
@@ -685,7 +864,7 @@ function useImportExcel({ columns, processor, parser }) {
|
|
|
685
864
|
row.status = "processing";
|
|
686
865
|
row.message = void 0;
|
|
687
866
|
}
|
|
688
|
-
await (0,
|
|
867
|
+
await (0, import_vue7.nextTick)();
|
|
689
868
|
try {
|
|
690
869
|
const results = await importer.process(chunk, signal);
|
|
691
870
|
if (!Array.isArray(results) || results.length !== chunk.length) {
|
|
@@ -794,7 +973,7 @@ function useImportExcel({ columns, processor, parser }) {
|
|
|
794
973
|
}
|
|
795
974
|
|
|
796
975
|
// src/mainPanel/nodes.ts
|
|
797
|
-
var
|
|
976
|
+
var import_vue8 = require("vue");
|
|
798
977
|
function isGroupNode(node) {
|
|
799
978
|
return !!(node.children && node.children.length > 0);
|
|
800
979
|
}
|
|
@@ -842,8 +1021,8 @@ function filterNodesByKeyword(list, keyword) {
|
|
|
842
1021
|
return walk(list);
|
|
843
1022
|
}
|
|
844
1023
|
function useMainPanelNodes(props) {
|
|
845
|
-
const nodes = (0,
|
|
846
|
-
const menuLoading = (0,
|
|
1024
|
+
const nodes = (0, import_vue8.ref)([]);
|
|
1025
|
+
const menuLoading = (0, import_vue8.ref)(false);
|
|
847
1026
|
async function loadNodes() {
|
|
848
1027
|
menuLoading.value = true;
|
|
849
1028
|
try {
|
|
@@ -852,7 +1031,7 @@ function useMainPanelNodes(props) {
|
|
|
852
1031
|
menuLoading.value = false;
|
|
853
1032
|
}
|
|
854
1033
|
}
|
|
855
|
-
(0,
|
|
1034
|
+
(0, import_vue8.watch)(() => props.nodesFunc, () => {
|
|
856
1035
|
void loadNodes();
|
|
857
1036
|
});
|
|
858
1037
|
return {
|
|
@@ -863,10 +1042,10 @@ function useMainPanelNodes(props) {
|
|
|
863
1042
|
}
|
|
864
1043
|
|
|
865
1044
|
// src/mainPanel/tabs.ts
|
|
866
|
-
var
|
|
1045
|
+
var import_vue9 = require("vue");
|
|
867
1046
|
function useMainPanelTabs(props) {
|
|
868
|
-
const openTabs = (0,
|
|
869
|
-
const activeKey = (0,
|
|
1047
|
+
const openTabs = (0, import_vue9.ref)([]);
|
|
1048
|
+
const activeKey = (0, import_vue9.ref)("");
|
|
870
1049
|
function openTab(node) {
|
|
871
1050
|
const label = (node.icon ? `${node.icon} ` : "") + node.label;
|
|
872
1051
|
if (!openTabs.value.some((tab) => tab.key === node.key)) {
|
|
@@ -897,9 +1076,9 @@ function useMainPanelTabs(props) {
|
|
|
897
1076
|
const loader = props.componentMap?.[path];
|
|
898
1077
|
componentCache.set(
|
|
899
1078
|
path,
|
|
900
|
-
loader ? (0,
|
|
1079
|
+
loader ? (0, import_vue9.defineAsyncComponent)(() => loader().then((m) => m.default)) : (
|
|
901
1080
|
// 未提供 componentMap 时的兜底:跳过打包器静态分析,按运行时动态 import 解析
|
|
902
|
-
(0,
|
|
1081
|
+
(0, import_vue9.defineAsyncComponent)(() => import(
|
|
903
1082
|
/* @vite-ignore */
|
|
904
1083
|
path
|
|
905
1084
|
).then((m) => m.default))
|
|
@@ -918,11 +1097,11 @@ function useMainPanelTabs(props) {
|
|
|
918
1097
|
}
|
|
919
1098
|
|
|
920
1099
|
// src/filter/filterPanel.ts
|
|
921
|
-
var
|
|
1100
|
+
var import_vue10 = require("vue");
|
|
922
1101
|
var import_ys_knife_query = require("ys.knife.query.js");
|
|
923
1102
|
var FilterPanelKey = /* @__PURE__ */ Symbol("YsFilterPanel");
|
|
924
1103
|
function useFilterPanel() {
|
|
925
|
-
const items = (0,
|
|
1104
|
+
const items = (0, import_vue10.ref)(/* @__PURE__ */ new Map());
|
|
926
1105
|
let counter = 0;
|
|
927
1106
|
const register = (api) => {
|
|
928
1107
|
const key = String(++counter);
|
|
@@ -933,7 +1112,7 @@ function useFilterPanel() {
|
|
|
933
1112
|
items.value = new Map(items.value);
|
|
934
1113
|
};
|
|
935
1114
|
};
|
|
936
|
-
const filter6 = (0,
|
|
1115
|
+
const filter6 = (0, import_vue10.computed)(() => {
|
|
937
1116
|
const nonNull = [...items.value.values()].map((a) => a.filter).filter((f) => f !== null);
|
|
938
1117
|
if (nonNull.length === 0) return (0, import_ys_knife_query.emptyFilter)();
|
|
939
1118
|
return import_ys_knife_query.FilterInfo.createAnd(...nonNull);
|
|
@@ -945,16 +1124,16 @@ function useFilterPanel() {
|
|
|
945
1124
|
}
|
|
946
1125
|
|
|
947
1126
|
// src/filter/textFilterItem.ts
|
|
948
|
-
var
|
|
1127
|
+
var import_vue11 = require("vue");
|
|
949
1128
|
var import_ys_knife_query2 = require("ys.knife.query.js");
|
|
950
1129
|
function useTextFilterItem(props) {
|
|
951
|
-
const value = (0,
|
|
1130
|
+
const value = (0, import_vue11.ref)(
|
|
952
1131
|
typeof props.defaultValue === "string" ? props.defaultValue : ""
|
|
953
1132
|
);
|
|
954
1133
|
function isEmpty(v) {
|
|
955
1134
|
return v == null || v.trim() === "";
|
|
956
1135
|
}
|
|
957
|
-
const filterInfo = (0,
|
|
1136
|
+
const filterInfo = (0, import_vue11.computed)(() => {
|
|
958
1137
|
if (isEmpty(value.value)) return null;
|
|
959
1138
|
return (0, import_ys_knife_query2.filter)(props.propertyPath, props.op, (0, import_ys_knife_query2.con)(value.value));
|
|
960
1139
|
});
|
|
@@ -965,16 +1144,16 @@ function useTextFilterItem(props) {
|
|
|
965
1144
|
}
|
|
966
1145
|
|
|
967
1146
|
// src/filter/dateFilterItem.ts
|
|
968
|
-
var
|
|
1147
|
+
var import_vue12 = require("vue");
|
|
969
1148
|
var import_ys_knife_query3 = require("ys.knife.query.js");
|
|
970
1149
|
function useDateFilterItem(props) {
|
|
971
|
-
const value = (0,
|
|
1150
|
+
const value = (0, import_vue12.ref)(
|
|
972
1151
|
typeof props.defaultValue === "string" ? props.defaultValue : ""
|
|
973
1152
|
);
|
|
974
1153
|
function isEmpty(v) {
|
|
975
1154
|
return v == null || v.trim() === "";
|
|
976
1155
|
}
|
|
977
|
-
const filterInfo = (0,
|
|
1156
|
+
const filterInfo = (0, import_vue12.computed)(() => {
|
|
978
1157
|
if (isEmpty(value.value)) return null;
|
|
979
1158
|
return (0, import_ys_knife_query3.filter)(props.propertyPath, props.op, (0, import_ys_knife_query3.con)(value.value));
|
|
980
1159
|
});
|
|
@@ -985,7 +1164,7 @@ function useDateFilterItem(props) {
|
|
|
985
1164
|
}
|
|
986
1165
|
|
|
987
1166
|
// src/filter/dateRangeFilterItem.ts
|
|
988
|
-
var
|
|
1167
|
+
var import_vue13 = require("vue");
|
|
989
1168
|
var import_ys_knife_query4 = require("ys.knife.query.js");
|
|
990
1169
|
function useDateRangeFilterItem(props) {
|
|
991
1170
|
function toRange(v) {
|
|
@@ -995,11 +1174,11 @@ function useDateRangeFilterItem(props) {
|
|
|
995
1174
|
return null;
|
|
996
1175
|
}
|
|
997
1176
|
const initial = toRange(props.defaultValue);
|
|
998
|
-
const value = (0,
|
|
1177
|
+
const value = (0, import_vue13.ref)(initial);
|
|
999
1178
|
function isEmpty(v) {
|
|
1000
1179
|
return v == null || v.length !== 2 || !v[0] || !v[1];
|
|
1001
1180
|
}
|
|
1002
|
-
const filterInfo = (0,
|
|
1181
|
+
const filterInfo = (0, import_vue13.computed)(() => {
|
|
1003
1182
|
if (isEmpty(value.value)) return null;
|
|
1004
1183
|
const [start, end] = value.value;
|
|
1005
1184
|
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 +1190,7 @@ function useDateRangeFilterItem(props) {
|
|
|
1011
1190
|
}
|
|
1012
1191
|
|
|
1013
1192
|
// src/filter/enumFilterItem.ts
|
|
1014
|
-
var
|
|
1193
|
+
var import_vue14 = require("vue");
|
|
1015
1194
|
var import_ys_knife_query5 = require("ys.knife.query.js");
|
|
1016
1195
|
function toSingleValue(v) {
|
|
1017
1196
|
if (typeof v === "string" || typeof v === "number") return v;
|
|
@@ -1027,7 +1206,7 @@ function toMultiValue(v) {
|
|
|
1027
1206
|
}
|
|
1028
1207
|
function useEnumFilterItem(props) {
|
|
1029
1208
|
const isMultiple = props.multiple === true;
|
|
1030
|
-
const value = (0,
|
|
1209
|
+
const value = (0, import_vue14.ref)(
|
|
1031
1210
|
isMultiple ? toMultiValue(props.defaultValue) : toSingleValue(props.defaultValue)
|
|
1032
1211
|
);
|
|
1033
1212
|
function isEmpty() {
|
|
@@ -1039,7 +1218,7 @@ function useEnumFilterItem(props) {
|
|
|
1039
1218
|
if (typeof v === "string" && v.trim() === "") return true;
|
|
1040
1219
|
return false;
|
|
1041
1220
|
}
|
|
1042
|
-
const filterInfo = (0,
|
|
1221
|
+
const filterInfo = (0, import_vue14.computed)(() => {
|
|
1043
1222
|
if (isEmpty()) return null;
|
|
1044
1223
|
if (isMultiple) {
|
|
1045
1224
|
const arr = value.value;
|
|
@@ -1065,21 +1244,21 @@ function useEnumFilterItem(props) {
|
|
|
1065
1244
|
}
|
|
1066
1245
|
|
|
1067
1246
|
// src/advancedFilter/advancedFilter.ts
|
|
1068
|
-
var
|
|
1247
|
+
var import_vue15 = require("vue");
|
|
1069
1248
|
var import_ys_knife_query6 = require("ys.knife.query.js");
|
|
1070
|
-
var import_core2 = require("@ys-knife-crud/core");
|
|
1071
1249
|
var import_core3 = require("@ys-knife-crud/core");
|
|
1250
|
+
var import_core4 = require("@ys-knife-crud/core");
|
|
1072
1251
|
function useAdvancedFilter(props) {
|
|
1073
1252
|
let seq = 0;
|
|
1074
1253
|
function nextId(prefix) {
|
|
1075
1254
|
return `adv-${prefix}-${++seq}`;
|
|
1076
1255
|
}
|
|
1077
|
-
const fieldTypeMap = (0,
|
|
1256
|
+
const fieldTypeMap = (0, import_vue15.computed)(() => {
|
|
1078
1257
|
const map = /* @__PURE__ */ new Map();
|
|
1079
1258
|
for (const col of props.columns) {
|
|
1080
1259
|
map.set(
|
|
1081
1260
|
col.propertyPath,
|
|
1082
|
-
(0,
|
|
1261
|
+
(0, import_core4.inferColumnFieldType)(col, props.optionSources?.[col.propertyPath] !== void 0)
|
|
1083
1262
|
);
|
|
1084
1263
|
}
|
|
1085
1264
|
return map;
|
|
@@ -1088,12 +1267,12 @@ function useAdvancedFilter(props) {
|
|
|
1088
1267
|
return fieldTypeMap.value.get(propertyPath) ?? "string";
|
|
1089
1268
|
}
|
|
1090
1269
|
function operatorsOf(propertyPath) {
|
|
1091
|
-
return
|
|
1270
|
+
return import_core4.FIELD_TYPE_OPERATORS[fieldTypeOf(propertyPath)];
|
|
1092
1271
|
}
|
|
1093
1272
|
function emptyValue(type, op) {
|
|
1094
|
-
if ((0,
|
|
1095
|
-
if ((0,
|
|
1096
|
-
if ((0,
|
|
1273
|
+
if ((0, import_core3.isNullOperator)(op)) return null;
|
|
1274
|
+
if ((0, import_core4.isRangeOperator)(op)) return [null, null];
|
|
1275
|
+
if ((0, import_core4.isMultiValueOperator)(op)) return [];
|
|
1097
1276
|
void type;
|
|
1098
1277
|
return null;
|
|
1099
1278
|
}
|
|
@@ -1101,7 +1280,7 @@ function useAdvancedFilter(props) {
|
|
|
1101
1280
|
const first = props.columns[0];
|
|
1102
1281
|
const propertyPath = first?.propertyPath ?? "";
|
|
1103
1282
|
const type = first ? fieldTypeOf(propertyPath) : "string";
|
|
1104
|
-
const op = (0,
|
|
1283
|
+
const op = (0, import_core4.defaultOperatorForType)(type);
|
|
1105
1284
|
return {
|
|
1106
1285
|
id: nextId("leaf"),
|
|
1107
1286
|
propertyPath,
|
|
@@ -1116,7 +1295,7 @@ function useAdvancedFilter(props) {
|
|
|
1116
1295
|
children: [newLeaf()]
|
|
1117
1296
|
};
|
|
1118
1297
|
}
|
|
1119
|
-
const rootGroup = (0,
|
|
1298
|
+
const rootGroup = (0, import_vue15.ref)({
|
|
1120
1299
|
id: "root",
|
|
1121
1300
|
combinator: "and",
|
|
1122
1301
|
children: [newLeaf()]
|
|
@@ -1124,7 +1303,7 @@ function useAdvancedFilter(props) {
|
|
|
1124
1303
|
function findNode2(id, group = rootGroup.value) {
|
|
1125
1304
|
for (const child of group.children) {
|
|
1126
1305
|
if (child.id === id) return child;
|
|
1127
|
-
if ((0,
|
|
1306
|
+
if ((0, import_core3.isConditionGroup)(child)) {
|
|
1128
1307
|
const found = findNode2(id, child);
|
|
1129
1308
|
if (found) return found;
|
|
1130
1309
|
}
|
|
@@ -1134,7 +1313,7 @@ function useAdvancedFilter(props) {
|
|
|
1134
1313
|
function findParentGroup(id, group = rootGroup.value) {
|
|
1135
1314
|
for (const child of group.children) {
|
|
1136
1315
|
if (child.id === id) return group;
|
|
1137
|
-
if ((0,
|
|
1316
|
+
if ((0, import_core3.isConditionGroup)(child)) {
|
|
1138
1317
|
const found = findParentGroup(id, child);
|
|
1139
1318
|
if (found) return found;
|
|
1140
1319
|
}
|
|
@@ -1143,7 +1322,7 @@ function useAdvancedFilter(props) {
|
|
|
1143
1322
|
}
|
|
1144
1323
|
function addLeaf(parentId, index) {
|
|
1145
1324
|
const parent = parentId === rootGroup.value.id ? rootGroup.value : findNode2(parentId);
|
|
1146
|
-
if (!parent || !(0,
|
|
1325
|
+
if (!parent || !(0, import_core3.isConditionGroup)(parent)) return;
|
|
1147
1326
|
const leaf = newLeaf();
|
|
1148
1327
|
if (typeof index === "number") {
|
|
1149
1328
|
parent.children.splice(index, 0, leaf);
|
|
@@ -1153,7 +1332,7 @@ function useAdvancedFilter(props) {
|
|
|
1153
1332
|
}
|
|
1154
1333
|
function addNestedGroup(parentId, index) {
|
|
1155
1334
|
const parent = parentId === rootGroup.value.id ? rootGroup.value : findNode2(parentId);
|
|
1156
|
-
if (!parent || !(0,
|
|
1335
|
+
if (!parent || !(0, import_core3.isConditionGroup)(parent)) return;
|
|
1157
1336
|
const childCombinator = parent.combinator === "and" ? "or" : "and";
|
|
1158
1337
|
const sub = newGroup(childCombinator);
|
|
1159
1338
|
if (typeof index === "number") {
|
|
@@ -1171,31 +1350,31 @@ function useAdvancedFilter(props) {
|
|
|
1171
1350
|
}
|
|
1172
1351
|
function changeField(id, propertyPath) {
|
|
1173
1352
|
const node = findNode2(id);
|
|
1174
|
-
if (!node || (0,
|
|
1353
|
+
if (!node || (0, import_core3.isConditionGroup)(node)) return;
|
|
1175
1354
|
node.propertyPath = propertyPath;
|
|
1176
1355
|
const type = fieldTypeOf(propertyPath);
|
|
1177
|
-
node.op = (0,
|
|
1356
|
+
node.op = (0, import_core4.defaultOperatorForType)(type);
|
|
1178
1357
|
node.value = emptyValue(type, node.op);
|
|
1179
1358
|
}
|
|
1180
1359
|
function changeOperator(id, op) {
|
|
1181
1360
|
const node = findNode2(id);
|
|
1182
|
-
if (!node || (0,
|
|
1361
|
+
if (!node || (0, import_core3.isConditionGroup)(node)) return;
|
|
1183
1362
|
node.op = op;
|
|
1184
1363
|
node.value = emptyValue(fieldTypeOf(node.propertyPath), op);
|
|
1185
1364
|
}
|
|
1186
1365
|
function setGroupCombinator(groupId, comb) {
|
|
1187
1366
|
const node = groupId === rootGroup.value.id ? rootGroup.value : findNode2(groupId);
|
|
1188
|
-
if (node && (0,
|
|
1367
|
+
if (node && (0, import_core3.isConditionGroup)(node)) node.combinator = comb;
|
|
1189
1368
|
}
|
|
1190
1369
|
function isConditionEmpty(row) {
|
|
1191
|
-
if ((0,
|
|
1370
|
+
if ((0, import_core3.isNullOperator)(row.op)) return false;
|
|
1192
1371
|
const type = fieldTypeOf(row.propertyPath);
|
|
1193
1372
|
const v = row.value;
|
|
1194
|
-
if ((0,
|
|
1373
|
+
if ((0, import_core4.isRangeOperator)(row.op)) {
|
|
1195
1374
|
if (!Array.isArray(v) || v.length !== 2) return true;
|
|
1196
1375
|
return v[0] === null || v[0] === void 0 || v[0] === "" || v[1] === null || v[1] === void 0 || v[1] === "";
|
|
1197
1376
|
}
|
|
1198
|
-
if ((0,
|
|
1377
|
+
if ((0, import_core4.isMultiValueOperator)(row.op)) {
|
|
1199
1378
|
return !Array.isArray(v) || v.length === 0;
|
|
1200
1379
|
}
|
|
1201
1380
|
if (type === "boolean") {
|
|
@@ -1255,7 +1434,7 @@ function useAdvancedFilter(props) {
|
|
|
1255
1434
|
);
|
|
1256
1435
|
}
|
|
1257
1436
|
function buildNodeFilter(node) {
|
|
1258
|
-
if ((0,
|
|
1437
|
+
if ((0, import_core3.isConditionGroup)(node)) {
|
|
1259
1438
|
const items = node.children.map(buildNodeFilter).filter((f) => f !== null);
|
|
1260
1439
|
if (items.length === 0) return null;
|
|
1261
1440
|
if (items.length === 1) return items[0];
|
|
@@ -1270,7 +1449,7 @@ function useAdvancedFilter(props) {
|
|
|
1270
1449
|
}
|
|
1271
1450
|
return buildConditionFilter(node);
|
|
1272
1451
|
}
|
|
1273
|
-
const filterInfo = (0,
|
|
1452
|
+
const filterInfo = (0, import_vue15.computed)(() => {
|
|
1274
1453
|
const f = buildNodeFilter(rootGroup.value);
|
|
1275
1454
|
return f ?? (0, import_ys_knife_query6.emptyFilter)();
|
|
1276
1455
|
});
|
|
@@ -1289,7 +1468,7 @@ function useAdvancedFilter(props) {
|
|
|
1289
1468
|
changeOperator,
|
|
1290
1469
|
setGroupCombinator,
|
|
1291
1470
|
isConditionEmpty,
|
|
1292
|
-
isConditionGroup:
|
|
1471
|
+
isConditionGroup: import_core3.isConditionGroup,
|
|
1293
1472
|
filter: filterInfo,
|
|
1294
1473
|
reset
|
|
1295
1474
|
};
|
|
@@ -1314,6 +1493,7 @@ function getDefaultModalAppContext() {
|
|
|
1314
1493
|
isGroupNode,
|
|
1315
1494
|
setDefaultModalAppContext,
|
|
1316
1495
|
useAdvancedFilter,
|
|
1496
|
+
useCollectData,
|
|
1317
1497
|
useCustomConfig,
|
|
1318
1498
|
useDateFilterItem,
|
|
1319
1499
|
useDateRangeFilterItem,
|