@duxweb/dvha-core 1.0.45 → 1.0.47
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/cjs/hooks/list.cjs +1 -1
- package/dist/esm/hooks/list.js +98 -75
- package/dist/types/hooks/list.d.ts +5 -0
- package/package.json +1 -1
package/dist/cjs/hooks/list.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@vueuse/core"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@vueuse/core"),o=require("vue"),E=require("./data.cjs"),C=require("./exportCsv.cjs"),Q=require("./importCsv.cjs");function W(t){const r=o.toRef(t,"filters",{}),c=o.toRef(t,"sorters",{}),n=o.toRef(typeof t.pagination=="object"?t.pagination:{page:1,pageSize:20}),d=[10,20,30,40,50,100],h=e=>d.includes(e)?d:Array.from({length:5},(l,N)=>e*(N+1)),g=o.ref(h(n.value.pageSize));o.watch(()=>n.value.pageSize,e=>{g.value.includes(e)||(g.value=h(e))});const P=e=>{n.value.pageSize=e,n.value.page=1},z=e=>{n.value.page=e},{data:s,isLoading:L,refetch:R}=E.useList({path:t.path,pagination:t.pagination?n.value:!1,filters:r.value,sorters:c.value}),b=o.computed(()=>s.value?.data||[]),m=o.computed(()=>s.value?.meta||{}),f=o.computed(()=>t.total?.(s.value)||m.value?.[t.totalField||"total"]||0),I=o.computed(()=>Math.ceil(f.value/n.value.pageSize)||0),k=e=>{r.value=e},w=e=>{c.value=e},a=o.ref([]),p=o.computed(()=>a.value.length>0&&a.value.length===s.value?.data?.length),y=o.computed(()=>a.value.length>0&&a.value.length<(s.value?.data?.length||0)),U=e=>{const l=a.value.indexOf(e);l>-1?a.value.splice(l,1):a.value.push(e)},q=e=>{a.value=e},F=e=>a.value.includes(e),M=()=>{p.value?a.value=[]:a.value=s.value?.data?.map(e=>e[t.key||"id"]).filter(e=>e!=null)||[]};o.watch(()=>s.value?.data,()=>{a.value=[]});const u=()=>{a.value=[],R()},v=o.ref({page:1,pageSize:100}),{trigger:A,isLoading:B}=C.useExportCsv({path:t.path,filters:r.value||{},sorters:c.value||{},maxPage:()=>t.exportMaxPage||0,pagination:v.value,filename:t.exportFilename||"data.csv",onSuccess:e=>{t.onExportSuccess?.(e),v.value.page=1},onProgress:e=>{t.onExportProgress?.(e)},onError:e=>{t.onExportError?.(e),v.value.page=1}}),O=S.reactiveComputed(()=>({ids:a.value})),{trigger:j,isLoading:T}=C.useExportCsv({path:t.path,filters:O,maxPage:1,filename:t.exportFilename||"rows.csv",onSuccess:e=>{t.onExportSuccess?.(e)},onError:e=>{t.onExportError?.(e)}}),{open:$,isLoading:V}=Q.useImportCsv({path:t.path,onComplete:e=>{t.onImportSuccess?.(e)},onProgress:e=>{t.onImportProgress?.(e)},onError:e=>{t.onImportError?.(e)}}),i=o.ref(!1),{remaining:_,start:x,stop:D}=S.useCountdown(10,{onComplete:()=>{u(),x()}}),G=()=>{i.value=!i.value,i.value?(u(),x()):D()},{mutate:H,isLoading:J}=E.useCustomMutation({path:t.batchPath||`${t.path}/batch`,method:"POST",onSuccess:e=>{t?.onBatchSuccess?.(e),a.value=[],u()},onError:e=>{t?.onBatchError?.(e),u()}}),K=(e,l)=>{H({payload:{type:e,ids:a.value,...l||{}}})};return{list:b,meta:m,isLoading:L,pagination:n,filters:r,sorters:c,onRefresh:u,onUpdateFilters:k,onUpdateSorters:w,checkeds:a,isAllChecked:p,isIndeterminate:y,toggleChecked:U,isChecked:F,toggleSelectAll:M,onUpdateChecked:q,total:f,page:o.computed(()=>n.value.page),pageSize:o.computed(()=>n.value.pageSize),pageSizes:g.value,pageCount:I,onUpdatePage:z,onUpdatePageSize:P,onExport:A,isExporting:B,onExportRows:j,isExportingRows:T,onImport:$,isImporting:V,autoRefetch:i,onAutoRefetch:G,autoCountdown:_,onBatch:K,isBatching:J}}exports.useExtendList=W;
|
package/dist/esm/hooks/list.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { reactiveComputed as
|
|
2
|
-
import { toRef as
|
|
3
|
-
import { useList as
|
|
4
|
-
import { useExportCsv as
|
|
5
|
-
import { useImportCsv as
|
|
6
|
-
function
|
|
7
|
-
const
|
|
1
|
+
import { reactiveComputed as W, useCountdown as X } from "@vueuse/core";
|
|
2
|
+
import { toRef as h, ref as g, watch as C, computed as n } from "vue";
|
|
3
|
+
import { useList as Y, useCustomMutation as Z } from "./data.js";
|
|
4
|
+
import { useExportCsv as P } from "./exportCsv.js";
|
|
5
|
+
import { useImportCsv as ee } from "./importCsv.js";
|
|
6
|
+
function se(t) {
|
|
7
|
+
const u = h(t, "filters", {}), i = h(t, "sorters", {}), o = h(typeof t.pagination == "object" ? t.pagination : {
|
|
8
8
|
page: 1,
|
|
9
9
|
pageSize: 20
|
|
10
|
-
}),
|
|
10
|
+
}), m = [10, 20, 30, 40, 50, 100], f = (e) => m.includes(e) ? m : Array.from({
|
|
11
11
|
length: 5
|
|
12
|
-
}, (
|
|
12
|
+
}, (r, V) => e * (V + 1)), v = g(f(o.value.pageSize));
|
|
13
13
|
C(() => o.value.pageSize, (e) => {
|
|
14
|
-
|
|
14
|
+
v.value.includes(e) || (v.value = f(e));
|
|
15
15
|
});
|
|
16
|
-
const
|
|
16
|
+
const z = (e) => {
|
|
17
17
|
o.value.pageSize = e, o.value.page = 1;
|
|
18
|
-
},
|
|
18
|
+
}, L = (e) => {
|
|
19
19
|
o.value.page = e;
|
|
20
20
|
}, {
|
|
21
21
|
data: l,
|
|
22
|
-
isLoading:
|
|
23
|
-
refetch:
|
|
24
|
-
} =
|
|
22
|
+
isLoading: I,
|
|
23
|
+
refetch: k
|
|
24
|
+
} = Y({
|
|
25
25
|
path: t.path,
|
|
26
26
|
pagination: t.pagination ? o.value : !1,
|
|
27
|
-
filters:
|
|
28
|
-
sorters:
|
|
29
|
-
}), R = n(() => l.value?.data || []),
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
}, a =
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
},
|
|
27
|
+
filters: u.value,
|
|
28
|
+
sorters: i.value
|
|
29
|
+
}), R = n(() => l.value?.data || []), p = n(() => l.value?.meta || {}), x = n(() => t.total?.(l.value) || p.value?.[t.totalField || "total"] || 0), b = n(() => Math.ceil(x.value / o.value.pageSize) || 0), w = (e) => {
|
|
30
|
+
u.value = e;
|
|
31
|
+
}, F = (e) => {
|
|
32
|
+
i.value = e;
|
|
33
|
+
}, a = g([]), S = n(() => a.value.length > 0 && a.value.length === l.value?.data?.length), U = n(() => a.value.length > 0 && a.value.length < (l.value?.data?.length || 0)), y = (e) => {
|
|
34
|
+
const r = a.value.indexOf(e);
|
|
35
|
+
r > -1 ? a.value.splice(r, 1) : a.value.push(e);
|
|
36
|
+
}, A = (e) => {
|
|
37
37
|
a.value = e;
|
|
38
|
-
},
|
|
38
|
+
}, B = (e) => a.value.includes(e), M = () => {
|
|
39
39
|
S.value ? a.value = [] : a.value = l.value?.data?.map((e) => e[t.key || "id"]).filter((e) => e != null) || [];
|
|
40
40
|
};
|
|
41
41
|
C(() => l.value?.data, () => {
|
|
42
42
|
a.value = [];
|
|
43
43
|
});
|
|
44
|
-
const
|
|
45
|
-
a.value = [],
|
|
46
|
-
},
|
|
44
|
+
const s = () => {
|
|
45
|
+
a.value = [], k();
|
|
46
|
+
}, d = g({
|
|
47
47
|
page: 1,
|
|
48
48
|
pageSize: 100
|
|
49
49
|
}), {
|
|
50
50
|
trigger: O,
|
|
51
|
-
isLoading:
|
|
52
|
-
} =
|
|
51
|
+
isLoading: j
|
|
52
|
+
} = P({
|
|
53
53
|
path: t.path,
|
|
54
|
-
filters:
|
|
55
|
-
sorters:
|
|
54
|
+
filters: u.value || {},
|
|
55
|
+
sorters: i.value || {},
|
|
56
56
|
maxPage: () => t.exportMaxPage || 0,
|
|
57
|
-
pagination:
|
|
57
|
+
pagination: d.value,
|
|
58
58
|
filename: t.exportFilename || "data.csv",
|
|
59
59
|
onSuccess: (e) => {
|
|
60
|
-
t.onExportSuccess?.(e),
|
|
60
|
+
t.onExportSuccess?.(e), d.value.page = 1;
|
|
61
61
|
},
|
|
62
62
|
onProgress: (e) => {
|
|
63
63
|
t.onExportProgress?.(e);
|
|
64
64
|
},
|
|
65
65
|
onError: (e) => {
|
|
66
|
-
t.onExportError?.(e),
|
|
66
|
+
t.onExportError?.(e), d.value.page = 1;
|
|
67
67
|
}
|
|
68
|
-
}),
|
|
68
|
+
}), T = W(() => ({
|
|
69
69
|
ids: a.value
|
|
70
70
|
})), {
|
|
71
|
-
trigger:
|
|
72
|
-
isLoading:
|
|
73
|
-
} =
|
|
71
|
+
trigger: _,
|
|
72
|
+
isLoading: $
|
|
73
|
+
} = P({
|
|
74
74
|
path: t.path,
|
|
75
|
-
filters:
|
|
75
|
+
filters: T,
|
|
76
76
|
maxPage: 1,
|
|
77
77
|
filename: t.exportFilename || "rows.csv",
|
|
78
78
|
onSuccess: (e) => {
|
|
@@ -82,9 +82,9 @@ function ae(t) {
|
|
|
82
82
|
t.onExportError?.(e);
|
|
83
83
|
}
|
|
84
84
|
}), {
|
|
85
|
-
open:
|
|
86
|
-
isLoading:
|
|
87
|
-
} =
|
|
85
|
+
open: q,
|
|
86
|
+
isLoading: D
|
|
87
|
+
} = ee({
|
|
88
88
|
path: t.path,
|
|
89
89
|
onComplete: (e) => {
|
|
90
90
|
t.onImportSuccess?.(e);
|
|
@@ -95,58 +95,81 @@ function ae(t) {
|
|
|
95
95
|
onError: (e) => {
|
|
96
96
|
t.onImportError?.(e);
|
|
97
97
|
}
|
|
98
|
-
}),
|
|
99
|
-
remaining:
|
|
98
|
+
}), c = g(!1), {
|
|
99
|
+
remaining: G,
|
|
100
100
|
start: E,
|
|
101
|
-
stop:
|
|
102
|
-
} =
|
|
101
|
+
stop: H
|
|
102
|
+
} = X(10, {
|
|
103
103
|
onComplete: () => {
|
|
104
|
-
|
|
104
|
+
s(), E();
|
|
105
|
+
}
|
|
106
|
+
}), J = () => {
|
|
107
|
+
c.value = !c.value, c.value ? (s(), E()) : H();
|
|
108
|
+
}, {
|
|
109
|
+
mutate: K,
|
|
110
|
+
isLoading: N
|
|
111
|
+
} = Z({
|
|
112
|
+
path: t.batchPath || `${t.path}/batch`,
|
|
113
|
+
method: "POST",
|
|
114
|
+
onSuccess: (e) => {
|
|
115
|
+
t?.onBatchSuccess?.(e), a.value = [], s();
|
|
116
|
+
},
|
|
117
|
+
onError: (e) => {
|
|
118
|
+
t?.onBatchError?.(e), s();
|
|
105
119
|
}
|
|
106
|
-
}),
|
|
107
|
-
|
|
120
|
+
}), Q = (e, r) => {
|
|
121
|
+
K({
|
|
122
|
+
payload: {
|
|
123
|
+
type: e,
|
|
124
|
+
ids: a.value,
|
|
125
|
+
...r || {}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
108
128
|
};
|
|
109
129
|
return {
|
|
110
130
|
// 数据
|
|
111
131
|
list: R,
|
|
112
|
-
meta:
|
|
113
|
-
isLoading:
|
|
132
|
+
meta: p,
|
|
133
|
+
isLoading: I,
|
|
114
134
|
pagination: o,
|
|
115
|
-
filters:
|
|
116
|
-
sorters:
|
|
117
|
-
onRefresh:
|
|
118
|
-
onUpdateFilters:
|
|
119
|
-
onUpdateSorters:
|
|
135
|
+
filters: u,
|
|
136
|
+
sorters: i,
|
|
137
|
+
onRefresh: s,
|
|
138
|
+
onUpdateFilters: w,
|
|
139
|
+
onUpdateSorters: F,
|
|
120
140
|
// 选中
|
|
121
141
|
checkeds: a,
|
|
122
142
|
isAllChecked: S,
|
|
123
|
-
isIndeterminate:
|
|
143
|
+
isIndeterminate: U,
|
|
124
144
|
toggleChecked: y,
|
|
125
|
-
isChecked:
|
|
126
|
-
toggleSelectAll:
|
|
127
|
-
onUpdateChecked:
|
|
145
|
+
isChecked: B,
|
|
146
|
+
toggleSelectAll: M,
|
|
147
|
+
onUpdateChecked: A,
|
|
128
148
|
// 分页
|
|
129
149
|
total: x,
|
|
130
150
|
page: n(() => o.value.page),
|
|
131
151
|
pageSize: n(() => o.value.pageSize),
|
|
132
|
-
pageSizes:
|
|
133
|
-
pageCount:
|
|
134
|
-
onUpdatePage:
|
|
135
|
-
onUpdatePageSize:
|
|
152
|
+
pageSizes: v.value,
|
|
153
|
+
pageCount: b,
|
|
154
|
+
onUpdatePage: L,
|
|
155
|
+
onUpdatePageSize: z,
|
|
136
156
|
// 导出
|
|
137
157
|
onExport: O,
|
|
138
|
-
isExporting:
|
|
139
|
-
onExportRows:
|
|
140
|
-
isExportingRows:
|
|
158
|
+
isExporting: j,
|
|
159
|
+
onExportRows: _,
|
|
160
|
+
isExportingRows: $,
|
|
141
161
|
// 导入
|
|
142
|
-
onImport:
|
|
143
|
-
isImporting:
|
|
162
|
+
onImport: q,
|
|
163
|
+
isImporting: D,
|
|
144
164
|
// 自动刷新
|
|
145
|
-
autoRefetch:
|
|
146
|
-
onAutoRefetch:
|
|
147
|
-
autoCountdown:
|
|
165
|
+
autoRefetch: c,
|
|
166
|
+
onAutoRefetch: J,
|
|
167
|
+
autoCountdown: G,
|
|
168
|
+
// 批量操作
|
|
169
|
+
onBatch: Q,
|
|
170
|
+
isBatching: N
|
|
148
171
|
};
|
|
149
172
|
}
|
|
150
173
|
export {
|
|
151
|
-
|
|
174
|
+
se as useExtendList
|
|
152
175
|
};
|
|
@@ -14,6 +14,7 @@ export interface UseExtendListProps {
|
|
|
14
14
|
pagination?: boolean | IListPagination;
|
|
15
15
|
exportFilename?: string;
|
|
16
16
|
exportMaxPage?: number;
|
|
17
|
+
batchPath?: string;
|
|
17
18
|
total?: (data?: IDataProviderResponse) => number;
|
|
18
19
|
onExportSuccess?: (data?: IDataProviderResponse) => void;
|
|
19
20
|
onExportProgress?: (data?: IDataProviderPagination) => void;
|
|
@@ -21,6 +22,8 @@ export interface UseExtendListProps {
|
|
|
21
22
|
onImportSuccess?: (progress?: IImportProgress) => void;
|
|
22
23
|
onImportProgress?: (progress?: IImportProgress) => void;
|
|
23
24
|
onImportError?: (error?: IDataProviderError) => void;
|
|
25
|
+
onBatchSuccess?: (data?: IDataProviderResponse) => void;
|
|
26
|
+
onBatchError?: (error?: IDataProviderError) => void;
|
|
24
27
|
}
|
|
25
28
|
export declare function useExtendList(props: UseExtendListProps): {
|
|
26
29
|
list: import("vue").ComputedRef<Record<string, any>[]>;
|
|
@@ -61,5 +64,7 @@ export declare function useExtendList(props: UseExtendListProps): {
|
|
|
61
64
|
autoRefetch: import("vue").Ref<boolean, boolean>;
|
|
62
65
|
onAutoRefetch: () => void;
|
|
63
66
|
autoCountdown: import("vue").ShallowRef<number>;
|
|
67
|
+
onBatch: (type: string, data?: Record<string, any>) => void;
|
|
68
|
+
isBatching: import("vue").ComputedRef<boolean>;
|
|
64
69
|
};
|
|
65
70
|
export {};
|