@ditari/bsui 1.1.47 → 1.1.49
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/CHANGELOG.md +6 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/menu/Menu.cjs +6 -1
- package/dist/cjs/menu/Menu.cjs.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/menu/Menu.mjs +6 -1
- package/dist/esm/menu/Menu.mjs.map +1 -1
- package/package.json +7 -3
- package/example/index.html +0 -13
- package/example/node_modules/.vite/deps/@ant-design_icons-vue.js +0 -29406
- package/example/node_modules/.vite/deps/@ant-design_icons-vue.js.map +0 -7
- package/example/node_modules/.vite/deps/@vueuse_core.js +0 -8255
- package/example/node_modules/.vite/deps/@vueuse_core.js.map +0 -7
- package/example/node_modules/.vite/deps/_metadata.json +0 -80
- package/example/node_modules/.vite/deps/ant-design-vue.js +0 -62756
- package/example/node_modules/.vite/deps/ant-design-vue.js.map +0 -7
- package/example/node_modules/.vite/deps/axios.js +0 -2126
- package/example/node_modules/.vite/deps/axios.js.map +0 -7
- package/example/node_modules/.vite/deps/chunk-5WWUZCGV.js +0 -36
- package/example/node_modules/.vite/deps/chunk-5WWUZCGV.js.map +0 -7
- package/example/node_modules/.vite/deps/chunk-D36HXFYL.js +0 -25
- package/example/node_modules/.vite/deps/chunk-D36HXFYL.js.map +0 -7
- package/example/node_modules/.vite/deps/chunk-EBDM3ESC.js +0 -161
- package/example/node_modules/.vite/deps/chunk-EBDM3ESC.js.map +0 -7
- package/example/node_modules/.vite/deps/chunk-EKNPBJBG.js +0 -3600
- package/example/node_modules/.vite/deps/chunk-EKNPBJBG.js.map +0 -7
- package/example/node_modules/.vite/deps/chunk-GK7Q6YQN.js +0 -10796
- package/example/node_modules/.vite/deps/chunk-GK7Q6YQN.js.map +0 -7
- package/example/node_modules/.vite/deps/chunk-TDI2FIXO.js +0 -19
- package/example/node_modules/.vite/deps/chunk-TDI2FIXO.js.map +0 -7
- package/example/node_modules/.vite/deps/package.json +0 -3
- package/example/node_modules/.vite/deps/pinia-plugin-persistedstate.js +0 -125
- package/example/node_modules/.vite/deps/pinia-plugin-persistedstate.js.map +0 -7
- package/example/node_modules/.vite/deps/pinia.js +0 -1519
- package/example/node_modules/.vite/deps/pinia.js.map +0 -7
- package/example/node_modules/.vite/deps/vue-request.js +0 -1191
- package/example/node_modules/.vite/deps/vue-request.js.map +0 -7
- package/example/node_modules/.vite/deps/vue-router.js +0 -2667
- package/example/node_modules/.vite/deps/vue-router.js.map +0 -7
- package/example/node_modules/.vite/deps/vue.js +0 -314
- package/example/node_modules/.vite/deps/vue.js.map +0 -7
- package/example/package.json +0 -17
- package/example/src/App.vue +0 -7
- package/example/src/api/list.ts +0 -22
- package/example/src/api/user.ts +0 -13
- package/example/src/components/AppMain.vue +0 -113
- package/example/src/hooks.ts +0 -103
- package/example/src/main.ts +0 -22
- package/example/src/router/form/index.route.ts +0 -23
- package/example/src/router/index.ts +0 -61
- package/example/src/router/table/index.route.ts +0 -39
- package/example/src/views/Demo.vue +0 -49
- package/example/src/views/DemoBk.vue +0 -34
- package/example/src/views/Login.vue +0 -79
- package/example/src/views/form/List.vue +0 -16
- package/example/src/views/form/List2.vue +0 -74
- package/example/src/views/form/QueryFormDemo.vue +0 -49
- package/example/src/views/form/dyn/List.vue +0 -121
- package/example/src/views/table/Add.vue +0 -377
- package/example/src/views/table/Demo.vue +0 -15
- package/example/src/views/table/Demo2.vue +0 -12
- package/example/src/views/table/Edit.vue +0 -10
- package/example/src/views/table/List.vue +0 -415
- package/example/src/views/table/Test.tsx +0 -42
- package/example/src/views/table/TestModal.vue +0 -64
- package/example/src/views/table/WorkStatusRound.vue +0 -31
- package/example/src/views/table/components/AddForm.vue +0 -44
- package/example/src/views/table/hooks.ts +0 -106
- package/example/src/views/task/Todo.vue +0 -6
- package/example/tsconfig.json +0 -16
- package/example/utils/http.ts +0 -107
- package/example/vite-env.d.ts +0 -8
- package/example/vite.config.ts +0 -10
- package/src/_utils/html.ts +0 -17
- package/src/_utils/install.ts +0 -12
- package/src/components.ts +0 -10
- package/src/config/Config.vue +0 -8
- package/src/date/RangePicker.tsx +0 -93
- package/src/date/index.ts +0 -9
- package/src/desensitize/Desensitize.tsx +0 -97
- package/src/desensitize/index.ts +0 -9
- package/src/desensitize/style/index.scss +0 -8
- package/src/dic/DicReplace.tsx +0 -63
- package/src/dic/index.ts +0 -8
- package/src/dic/replace.worker.ts +0 -25
- package/src/form/DQueryForm.tsx +0 -258
- package/src/form/index.ts +0 -9
- package/src/form/style/index.less +0 -0
- package/src/grid/Grid.tsx +0 -83
- package/src/grid/GridItem.tsx +0 -15
- package/src/grid/index.md +0 -4
- package/src/grid/index.ts +0 -16
- package/src/grid/style/index.scss +0 -70
- package/src/index.scss +0 -19
- package/src/index.ts +0 -50
- package/src/json-scheme-render/JsonSchemeRender.tsx +0 -101
- package/src/json-scheme-render/index.ts +0 -9
- package/src/layout/Breadcrumb.vue +0 -39
- package/src/layout/FuckMain.vue +0 -90
- package/src/layout/List.vue +0 -145
- package/src/layout/Main.vue +0 -97
- package/src/layout/NavTabs.vue +0 -129
- package/src/layout/Show.vue +0 -135
- package/src/layout/index.ts +0 -24
- package/src/layout/style/breadcrumb.scss +0 -61
- package/src/layout/style/fuckmain.scss +0 -21
- package/src/layout/style/index.scss +0 -35
- package/src/layout/style/list.scss +0 -26
- package/src/layout/style/main.scss +0 -74
- package/src/layout/style/navtab.scss +0 -146
- package/src/layout/style/show.scss +0 -50
- package/src/menu/Menu.tsx +0 -181
- package/src/menu/style/index.scss +0 -26
- package/src/modal/Modal.tsx +0 -83
- package/src/modal/index.ts +0 -9
- package/src/modal/style/index.scss +0 -74
- package/src/select/Select.vue +0 -177
- package/src/select/dic.worker.ts +0 -32
- package/src/select/index.ts +0 -9
- package/src/table/Field.vue +0 -44
- package/src/table/Table.tsx +0 -515
- package/src/table/index.md +0 -1
- package/src/table/index.ts +0 -9
- package/src/table/interface/table.ts +0 -64
- package/src/table/style/index.scss +0 -10
- package/src/theme/index.ts +0 -1
- package/src/theme/theme.scss +0 -1
- package/src/theme/variable.scss +0 -67
|
@@ -1,1191 +0,0 @@
|
|
|
1
|
-
import "./chunk-TDI2FIXO.js";
|
|
2
|
-
import {
|
|
3
|
-
computed,
|
|
4
|
-
inject,
|
|
5
|
-
isRef,
|
|
6
|
-
onUnmounted,
|
|
7
|
-
provide,
|
|
8
|
-
ref,
|
|
9
|
-
shallowRef,
|
|
10
|
-
watch,
|
|
11
|
-
watchEffect
|
|
12
|
-
} from "./chunk-GK7Q6YQN.js";
|
|
13
|
-
import "./chunk-5WWUZCGV.js";
|
|
14
|
-
|
|
15
|
-
// ../../../node_modules/.pnpm/vue-request@2.0.0-rc.4_@vue+composition-api@1.7.1_vue@3.3.4/node_modules/vue-request/dist/index.es.js
|
|
16
|
-
var GLOBAL_OPTIONS = {};
|
|
17
|
-
var GLOBAL_OPTIONS_PROVIDE_KEY = Symbol("GLOBAL_OPTIONS_PROVIDE_KEY");
|
|
18
|
-
var setGlobalOptions = (config) => {
|
|
19
|
-
Object.keys(config).forEach((key) => {
|
|
20
|
-
GLOBAL_OPTIONS[key] = config[key];
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
var getGlobalOptions = () => {
|
|
24
|
-
return GLOBAL_OPTIONS;
|
|
25
|
-
};
|
|
26
|
-
var objectToString = Object.prototype.toString;
|
|
27
|
-
var toTypeString = (val) => objectToString.call(val);
|
|
28
|
-
var isPlainObject = (val) => toTypeString(val) === "[object Object]";
|
|
29
|
-
var isArray = (val) => Array.isArray(val);
|
|
30
|
-
var isObject = (val) => val !== null && typeof val === "object";
|
|
31
|
-
var isFunction = (fn) => fn instanceof Function;
|
|
32
|
-
var isNil = (val) => val === null || val === void 0;
|
|
33
|
-
var isServer = typeof window === "undefined";
|
|
34
|
-
var isDocumentVisibility = () => {
|
|
35
|
-
var _window$document;
|
|
36
|
-
if (isServer || isNil((_window$document = window.document) === null || _window$document === void 0 ? void 0 : _window$document.visibilityState))
|
|
37
|
-
return true;
|
|
38
|
-
return window.document.visibilityState === "visible";
|
|
39
|
-
};
|
|
40
|
-
var isOnline = () => {
|
|
41
|
-
var _ref, _window$navigator;
|
|
42
|
-
return (_ref = !isServer && ((_window$navigator = window.navigator) === null || _window$navigator === void 0 ? void 0 : _window$navigator.onLine)) !== null && _ref !== void 0 ? _ref : true;
|
|
43
|
-
};
|
|
44
|
-
var resolvedPromise = () => new Promise(() => {
|
|
45
|
-
});
|
|
46
|
-
var get = (source, path, defaultValue = void 0) => {
|
|
47
|
-
const paths = path.replace(/\[(\d+)\]/g, ".$1").split(".");
|
|
48
|
-
let result = source;
|
|
49
|
-
for (const p of paths) {
|
|
50
|
-
result = Object(result)[p];
|
|
51
|
-
if (result === void 0) {
|
|
52
|
-
return defaultValue;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
};
|
|
57
|
-
function omit(object, keys) {
|
|
58
|
-
const result = Object.assign({}, object);
|
|
59
|
-
for (const key of keys) {
|
|
60
|
-
delete result[key];
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
var warning = (message, throwError = false) => {
|
|
65
|
-
const msg = `Warning: [vue-request] ${message}`;
|
|
66
|
-
if (throwError) {
|
|
67
|
-
return new Error(msg);
|
|
68
|
-
} else {
|
|
69
|
-
console.error(msg);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var refToRaw = (value) => {
|
|
73
|
-
return isRef(value) ? value.value : value;
|
|
74
|
-
};
|
|
75
|
-
var shallowCopy = (value) => {
|
|
76
|
-
if (isObject(value)) {
|
|
77
|
-
return Object.assign(isArray(value) ? [] : {}, value);
|
|
78
|
-
} else {
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var CACHE_MAP = /* @__PURE__ */ new Map();
|
|
83
|
-
var getCache = (cacheKey) => {
|
|
84
|
-
if (isNil(cacheKey))
|
|
85
|
-
return;
|
|
86
|
-
const data = CACHE_MAP.get(cacheKey);
|
|
87
|
-
return data;
|
|
88
|
-
};
|
|
89
|
-
var setCache = (cacheKey, cacheTime, data) => {
|
|
90
|
-
const oldCache = CACHE_MAP.get(cacheKey);
|
|
91
|
-
if (oldCache !== null && oldCache !== void 0 && oldCache.timer) {
|
|
92
|
-
clearTimeout(oldCache.timer);
|
|
93
|
-
}
|
|
94
|
-
const timer = setTimeout(() => CACHE_MAP.delete(cacheKey), cacheTime);
|
|
95
|
-
CACHE_MAP.set(cacheKey, {
|
|
96
|
-
...data,
|
|
97
|
-
timer
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
var clearCache = (cacheKey) => {
|
|
101
|
-
if (cacheKey) {
|
|
102
|
-
var _CACHE_MAP$get;
|
|
103
|
-
const timer = (_CACHE_MAP$get = CACHE_MAP.get(cacheKey)) === null || _CACHE_MAP$get === void 0 ? void 0 : _CACHE_MAP$get.timer;
|
|
104
|
-
timer && clearTimeout(timer);
|
|
105
|
-
CACHE_MAP.delete(cacheKey);
|
|
106
|
-
} else {
|
|
107
|
-
CACHE_MAP.forEach((i) => i.timer && clearTimeout(i.timer));
|
|
108
|
-
CACHE_MAP.clear();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var definePlugin = (options) => {
|
|
112
|
-
return options;
|
|
113
|
-
};
|
|
114
|
-
function debounce(func, wait, options) {
|
|
115
|
-
let lastArgs, lastThis, maxWait, result, timerId, lastCallTime;
|
|
116
|
-
let lastInvokeTime = 0;
|
|
117
|
-
let leading = false;
|
|
118
|
-
let maxing = false;
|
|
119
|
-
let trailing = true;
|
|
120
|
-
const useRAF = !wait && wait !== 0 && typeof window.requestAnimationFrame === "function";
|
|
121
|
-
if (typeof func !== "function") {
|
|
122
|
-
throw new TypeError("Expected a function");
|
|
123
|
-
}
|
|
124
|
-
wait = +wait || 0;
|
|
125
|
-
if (isObject(options)) {
|
|
126
|
-
leading = !!options.leading;
|
|
127
|
-
maxing = "maxWait" in options;
|
|
128
|
-
maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : maxWait;
|
|
129
|
-
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
130
|
-
}
|
|
131
|
-
function invokeFunc(time) {
|
|
132
|
-
const args = lastArgs;
|
|
133
|
-
const thisArg = lastThis;
|
|
134
|
-
lastArgs = lastThis = void 0;
|
|
135
|
-
lastInvokeTime = time;
|
|
136
|
-
result = func.apply(thisArg, args);
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
|
-
function startTimer(pendingFunc, wait2) {
|
|
140
|
-
if (useRAF) {
|
|
141
|
-
window.cancelAnimationFrame(timerId);
|
|
142
|
-
return window.requestAnimationFrame(pendingFunc);
|
|
143
|
-
}
|
|
144
|
-
return setTimeout(pendingFunc, wait2);
|
|
145
|
-
}
|
|
146
|
-
function cancelTimer(id) {
|
|
147
|
-
if (useRAF) {
|
|
148
|
-
return window.cancelAnimationFrame(id);
|
|
149
|
-
}
|
|
150
|
-
clearTimeout(id);
|
|
151
|
-
}
|
|
152
|
-
function leadingEdge(time) {
|
|
153
|
-
lastInvokeTime = time;
|
|
154
|
-
timerId = startTimer(timerExpired, wait);
|
|
155
|
-
return leading ? invokeFunc(time) : result;
|
|
156
|
-
}
|
|
157
|
-
function remainingWait(time) {
|
|
158
|
-
const timeSinceLastCall = time - lastCallTime;
|
|
159
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
160
|
-
const timeWaiting = wait - timeSinceLastCall;
|
|
161
|
-
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
162
|
-
}
|
|
163
|
-
function shouldInvoke(time) {
|
|
164
|
-
const timeSinceLastCall = time - lastCallTime;
|
|
165
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
166
|
-
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
167
|
-
}
|
|
168
|
-
function timerExpired() {
|
|
169
|
-
const time = Date.now();
|
|
170
|
-
if (shouldInvoke(time)) {
|
|
171
|
-
return trailingEdge(time);
|
|
172
|
-
}
|
|
173
|
-
timerId = startTimer(timerExpired, remainingWait(time));
|
|
174
|
-
}
|
|
175
|
-
function trailingEdge(time) {
|
|
176
|
-
timerId = void 0;
|
|
177
|
-
if (trailing && lastArgs) {
|
|
178
|
-
return invokeFunc(time);
|
|
179
|
-
}
|
|
180
|
-
lastArgs = lastThis = void 0;
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
function cancel() {
|
|
184
|
-
if (timerId !== void 0) {
|
|
185
|
-
cancelTimer(timerId);
|
|
186
|
-
}
|
|
187
|
-
lastInvokeTime = 0;
|
|
188
|
-
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
189
|
-
}
|
|
190
|
-
function flush() {
|
|
191
|
-
return timerId === void 0 ? result : trailingEdge(Date.now());
|
|
192
|
-
}
|
|
193
|
-
function pending() {
|
|
194
|
-
return timerId !== void 0;
|
|
195
|
-
}
|
|
196
|
-
function debounced(...args) {
|
|
197
|
-
const time = Date.now();
|
|
198
|
-
const isInvoking = shouldInvoke(time);
|
|
199
|
-
lastArgs = args;
|
|
200
|
-
lastThis = this;
|
|
201
|
-
lastCallTime = time;
|
|
202
|
-
if (isInvoking) {
|
|
203
|
-
if (timerId === void 0) {
|
|
204
|
-
return leadingEdge(lastCallTime);
|
|
205
|
-
}
|
|
206
|
-
if (maxing) {
|
|
207
|
-
timerId = startTimer(timerExpired, wait);
|
|
208
|
-
return invokeFunc(lastCallTime);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
if (timerId === void 0) {
|
|
212
|
-
timerId = startTimer(timerExpired, wait);
|
|
213
|
-
}
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
|
-
debounced.cancel = cancel;
|
|
217
|
-
debounced.flush = flush;
|
|
218
|
-
debounced.pending = pending;
|
|
219
|
-
return debounced;
|
|
220
|
-
}
|
|
221
|
-
function baseMerge(origin, target) {
|
|
222
|
-
for (const key in target) {
|
|
223
|
-
if (target[key] === void 0) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
if (!isObject(target[key]) || // `target[key]` is not an object
|
|
227
|
-
!isObject(origin[key]) || // `target[key]` is not an object
|
|
228
|
-
!(key in origin)) {
|
|
229
|
-
origin[key] = target[key];
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
if (isPlainObject(target[key]) || isArray(target[key])) {
|
|
233
|
-
baseMerge(origin[key], target[key]);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function merge(origin, ...others) {
|
|
238
|
-
const result = Object.assign({}, origin);
|
|
239
|
-
if (!others.length)
|
|
240
|
-
return result;
|
|
241
|
-
for (const item of others) {
|
|
242
|
-
baseMerge(result, item);
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
}
|
|
246
|
-
function throttle(func, wait, options) {
|
|
247
|
-
let leading = true;
|
|
248
|
-
let trailing = true;
|
|
249
|
-
if (typeof func !== "function") {
|
|
250
|
-
throw new TypeError("Expected a function");
|
|
251
|
-
}
|
|
252
|
-
if (isObject(options)) {
|
|
253
|
-
leading = "leading" in options ? !!options.leading : leading;
|
|
254
|
-
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
255
|
-
}
|
|
256
|
-
return debounce(func, wait, {
|
|
257
|
-
leading,
|
|
258
|
-
trailing,
|
|
259
|
-
maxWait: wait
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
var useDebouncePlugin = definePlugin((queryInstance, {
|
|
263
|
-
debounceInterval,
|
|
264
|
-
debounceOptions,
|
|
265
|
-
manual
|
|
266
|
-
}) => {
|
|
267
|
-
const initialAutoRunFlag = ref(false);
|
|
268
|
-
const debouncedRun = ref();
|
|
269
|
-
const debounceOptionsRef = computed(() => debounceOptions);
|
|
270
|
-
const debounceIntervalRef = computed(() => refToRaw(debounceInterval));
|
|
271
|
-
const originRunRef = ref(queryInstance.context.runAsync);
|
|
272
|
-
if (!manual) {
|
|
273
|
-
initialAutoRunFlag.value = true;
|
|
274
|
-
}
|
|
275
|
-
watchEffect((onInvalidate) => {
|
|
276
|
-
if (isNil(debounceIntervalRef.value))
|
|
277
|
-
return;
|
|
278
|
-
debouncedRun.value = debounce((callback) => callback(), debounceIntervalRef.value, debounceOptionsRef.value);
|
|
279
|
-
queryInstance.context.runAsync = (...args) => new Promise((resolve, reject) => {
|
|
280
|
-
if (initialAutoRunFlag.value) {
|
|
281
|
-
initialAutoRunFlag.value = false;
|
|
282
|
-
originRunRef.value(...args).then(resolve).catch(reject);
|
|
283
|
-
} else {
|
|
284
|
-
debouncedRun.value(() => {
|
|
285
|
-
originRunRef.value(...args).then(resolve).catch(reject);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
onInvalidate(() => {
|
|
290
|
-
var _debouncedRun$value;
|
|
291
|
-
(_debouncedRun$value = debouncedRun.value) === null || _debouncedRun$value === void 0 ? void 0 : _debouncedRun$value.cancel();
|
|
292
|
-
queryInstance.context.runAsync = originRunRef.value;
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
return {
|
|
296
|
-
onCancel() {
|
|
297
|
-
var _debouncedRun$value2;
|
|
298
|
-
(_debouncedRun$value2 = debouncedRun.value) === null || _debouncedRun$value2 === void 0 ? void 0 : _debouncedRun$value2.cancel();
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
});
|
|
302
|
-
var useErrorRetryPlugin = definePlugin((queryInstance, {
|
|
303
|
-
errorRetryCount = 0,
|
|
304
|
-
errorRetryInterval = 0
|
|
305
|
-
}) => {
|
|
306
|
-
const retryTimer = ref();
|
|
307
|
-
const retriedCount = ref(0);
|
|
308
|
-
const errorRetryCountRef = computed(() => refToRaw(errorRetryCount));
|
|
309
|
-
const errorRetryIntervalRef = computed(() => refToRaw(errorRetryInterval));
|
|
310
|
-
let isRetrying = false;
|
|
311
|
-
const resetRetriedCount = () => {
|
|
312
|
-
retriedCount.value = 0;
|
|
313
|
-
};
|
|
314
|
-
const actualErrorRetryInterval = computed(() => {
|
|
315
|
-
if (errorRetryIntervalRef.value)
|
|
316
|
-
return errorRetryIntervalRef.value;
|
|
317
|
-
const baseTime = 1e3;
|
|
318
|
-
const minCoefficient = 1;
|
|
319
|
-
const maxCoefficient = 9;
|
|
320
|
-
const coefficient = Math.floor(Math.random() * 2 ** Math.min(retriedCount.value, maxCoefficient) + minCoefficient);
|
|
321
|
-
return baseTime * coefficient;
|
|
322
|
-
});
|
|
323
|
-
const errorRetryHooks = () => {
|
|
324
|
-
let timerId;
|
|
325
|
-
const isInfiniteRetry = errorRetryCountRef.value === -1;
|
|
326
|
-
const hasRetryCount = retriedCount.value < errorRetryCountRef.value;
|
|
327
|
-
if (isInfiniteRetry || hasRetryCount) {
|
|
328
|
-
if (!isInfiniteRetry)
|
|
329
|
-
retriedCount.value += 1;
|
|
330
|
-
timerId = setTimeout(() => {
|
|
331
|
-
isRetrying = true;
|
|
332
|
-
queryInstance.context.refresh();
|
|
333
|
-
}, actualErrorRetryInterval.value);
|
|
334
|
-
}
|
|
335
|
-
return () => timerId && clearTimeout(timerId);
|
|
336
|
-
};
|
|
337
|
-
const clearTimer = () => {
|
|
338
|
-
if (retryTimer.value) {
|
|
339
|
-
retryTimer.value();
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
return {
|
|
343
|
-
onBefore() {
|
|
344
|
-
if (!isRetrying) {
|
|
345
|
-
resetRetriedCount();
|
|
346
|
-
}
|
|
347
|
-
isRetrying = false;
|
|
348
|
-
clearTimer();
|
|
349
|
-
},
|
|
350
|
-
onSuccess() {
|
|
351
|
-
resetRetriedCount();
|
|
352
|
-
},
|
|
353
|
-
onError() {
|
|
354
|
-
retryTimer.value = errorRetryHooks();
|
|
355
|
-
},
|
|
356
|
-
onCancel() {
|
|
357
|
-
resetRetriedCount();
|
|
358
|
-
clearTimer();
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
});
|
|
362
|
-
var useReadyPlugin = definePlugin((queryInstance, {
|
|
363
|
-
ready = ref(true),
|
|
364
|
-
manual,
|
|
365
|
-
defaultParams = []
|
|
366
|
-
}) => {
|
|
367
|
-
watch(ready, (val) => {
|
|
368
|
-
if (!manual && val) {
|
|
369
|
-
queryInstance.context.run(...defaultParams);
|
|
370
|
-
}
|
|
371
|
-
}, {
|
|
372
|
-
flush: "sync"
|
|
373
|
-
});
|
|
374
|
-
return {
|
|
375
|
-
onBefore() {
|
|
376
|
-
if (!ready.value) {
|
|
377
|
-
queryInstance.loading.value = false;
|
|
378
|
-
return {
|
|
379
|
-
isBreak: true
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
});
|
|
385
|
-
var useRefreshDepsPlugin = definePlugin((queryInstance, {
|
|
386
|
-
refreshDeps = [],
|
|
387
|
-
refreshDepsAction,
|
|
388
|
-
manual
|
|
389
|
-
}) => {
|
|
390
|
-
if (refreshDeps !== null && refreshDeps !== void 0 && refreshDeps.length) {
|
|
391
|
-
watch(refreshDeps, () => {
|
|
392
|
-
if (refreshDepsAction) {
|
|
393
|
-
refreshDepsAction();
|
|
394
|
-
} else {
|
|
395
|
-
!manual && queryInstance.context.refresh();
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
return {};
|
|
400
|
-
});
|
|
401
|
-
var useThrottlePlugin = definePlugin((queryInstance, {
|
|
402
|
-
throttleInterval,
|
|
403
|
-
throttleOptions
|
|
404
|
-
}) => {
|
|
405
|
-
const throttledRun = ref();
|
|
406
|
-
const throttleIntervalRef = computed(() => refToRaw(throttleInterval));
|
|
407
|
-
const throttleOptionsRef = computed(() => throttleOptions);
|
|
408
|
-
const originRunRef = ref(queryInstance.context.runAsync);
|
|
409
|
-
watchEffect((onInvalidate) => {
|
|
410
|
-
if (isNil(throttleInterval))
|
|
411
|
-
return {};
|
|
412
|
-
throttledRun.value = throttle((callback) => callback(), throttleIntervalRef.value, throttleOptionsRef.value);
|
|
413
|
-
queryInstance.context.runAsync = (...args) => new Promise((resolve, reject) => {
|
|
414
|
-
throttledRun.value(() => {
|
|
415
|
-
originRunRef.value(...args).then(resolve).catch(reject);
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
onInvalidate(() => {
|
|
419
|
-
var _throttledRun$value;
|
|
420
|
-
(_throttledRun$value = throttledRun.value) === null || _throttledRun$value === void 0 ? void 0 : _throttledRun$value.cancel();
|
|
421
|
-
queryInstance.context.runAsync = originRunRef.value;
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
return {
|
|
425
|
-
onCancel() {
|
|
426
|
-
var _throttledRun$value2;
|
|
427
|
-
(_throttledRun$value2 = throttledRun.value) === null || _throttledRun$value2 === void 0 ? void 0 : _throttledRun$value2.cancel();
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
});
|
|
431
|
-
var setStateBind = (oldState, publicCb) => {
|
|
432
|
-
return (newState) => {
|
|
433
|
-
Object.keys(newState).forEach((key) => {
|
|
434
|
-
oldState[key].value = newState[key];
|
|
435
|
-
});
|
|
436
|
-
publicCb.forEach((fun) => fun(oldState));
|
|
437
|
-
};
|
|
438
|
-
};
|
|
439
|
-
var composeMiddleware = (middleArray, hook) => {
|
|
440
|
-
return () => {
|
|
441
|
-
let next = hook;
|
|
442
|
-
for (let i = middleArray.length; i-- > 0; ) {
|
|
443
|
-
next = middleArray[i](next);
|
|
444
|
-
}
|
|
445
|
-
return next();
|
|
446
|
-
};
|
|
447
|
-
};
|
|
448
|
-
var createQuery = (service, config, initialState) => {
|
|
449
|
-
var _initialState$loading, _initialState$data;
|
|
450
|
-
const {
|
|
451
|
-
initialData,
|
|
452
|
-
onSuccess,
|
|
453
|
-
onError,
|
|
454
|
-
onBefore,
|
|
455
|
-
onAfter
|
|
456
|
-
} = config;
|
|
457
|
-
const loading = ref((_initialState$loading = initialState === null || initialState === void 0 ? void 0 : initialState.loading) !== null && _initialState$loading !== void 0 ? _initialState$loading : false);
|
|
458
|
-
const data = shallowRef((_initialState$data = initialState === null || initialState === void 0 ? void 0 : initialState.data) !== null && _initialState$data !== void 0 ? _initialState$data : initialData);
|
|
459
|
-
const error = shallowRef(initialState === null || initialState === void 0 ? void 0 : initialState.error);
|
|
460
|
-
const params = ref(initialState === null || initialState === void 0 ? void 0 : initialState.params);
|
|
461
|
-
const plugins = ref([]);
|
|
462
|
-
const status = shallowRef("pending");
|
|
463
|
-
const context = {};
|
|
464
|
-
const setState = setStateBind({
|
|
465
|
-
status,
|
|
466
|
-
loading,
|
|
467
|
-
data,
|
|
468
|
-
error,
|
|
469
|
-
params
|
|
470
|
-
}, []);
|
|
471
|
-
const emit = (event, ...args) => {
|
|
472
|
-
if (event === "onQuery") {
|
|
473
|
-
const queryFn = plugins.value.map((i) => i.onQuery).filter(Boolean);
|
|
474
|
-
return {
|
|
475
|
-
servicePromise: composeMiddleware(queryFn, args[0])()
|
|
476
|
-
};
|
|
477
|
-
} else {
|
|
478
|
-
const res = plugins.value.map((i) => {
|
|
479
|
-
var _i$event;
|
|
480
|
-
return (_i$event = i[event]) === null || _i$event === void 0 ? void 0 : _i$event.call(i, ...args);
|
|
481
|
-
});
|
|
482
|
-
return Object.assign({}, ...res);
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
const count = ref(0);
|
|
486
|
-
context.runAsync = async (...args) => {
|
|
487
|
-
setState({
|
|
488
|
-
loading: true,
|
|
489
|
-
params: args,
|
|
490
|
-
status: "pending"
|
|
491
|
-
});
|
|
492
|
-
count.value += 1;
|
|
493
|
-
const currentCount = count.value;
|
|
494
|
-
const {
|
|
495
|
-
isBreak,
|
|
496
|
-
breakResult = resolvedPromise()
|
|
497
|
-
} = emit("onBefore", args);
|
|
498
|
-
if (isBreak) {
|
|
499
|
-
setState({
|
|
500
|
-
status: "settled"
|
|
501
|
-
});
|
|
502
|
-
return breakResult;
|
|
503
|
-
}
|
|
504
|
-
onBefore === null || onBefore === void 0 ? void 0 : onBefore(args);
|
|
505
|
-
try {
|
|
506
|
-
const serviceWrapper = () => new Promise((resolve) => resolve(service(...params.value)));
|
|
507
|
-
let {
|
|
508
|
-
servicePromise
|
|
509
|
-
} = emit("onQuery", serviceWrapper);
|
|
510
|
-
if (!servicePromise) {
|
|
511
|
-
servicePromise = serviceWrapper();
|
|
512
|
-
}
|
|
513
|
-
const res = await servicePromise;
|
|
514
|
-
if (currentCount !== count.value)
|
|
515
|
-
return resolvedPromise();
|
|
516
|
-
setState({
|
|
517
|
-
data: res,
|
|
518
|
-
loading: false,
|
|
519
|
-
error: void 0,
|
|
520
|
-
status: "settled"
|
|
521
|
-
});
|
|
522
|
-
emit("onSuccess", res, args);
|
|
523
|
-
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(res, args);
|
|
524
|
-
emit("onAfter", args, res, void 0);
|
|
525
|
-
onAfter === null || onAfter === void 0 ? void 0 : onAfter(args);
|
|
526
|
-
return res;
|
|
527
|
-
} catch (error2) {
|
|
528
|
-
if (currentCount !== count.value)
|
|
529
|
-
return resolvedPromise();
|
|
530
|
-
setState({
|
|
531
|
-
loading: false,
|
|
532
|
-
error: error2,
|
|
533
|
-
status: "settled"
|
|
534
|
-
});
|
|
535
|
-
emit("onError", error2, args);
|
|
536
|
-
onError === null || onError === void 0 ? void 0 : onError(error2, args);
|
|
537
|
-
emit("onAfter", args, void 0, error2);
|
|
538
|
-
onAfter === null || onAfter === void 0 ? void 0 : onAfter(args);
|
|
539
|
-
throw error2;
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
context.run = (...args) => {
|
|
543
|
-
context.runAsync(...args).catch((error2) => {
|
|
544
|
-
if (!onError) {
|
|
545
|
-
console.error(error2);
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
};
|
|
549
|
-
context.cancel = () => {
|
|
550
|
-
count.value += 1;
|
|
551
|
-
setState({
|
|
552
|
-
loading: false
|
|
553
|
-
});
|
|
554
|
-
emit("onCancel");
|
|
555
|
-
};
|
|
556
|
-
context.refresh = () => {
|
|
557
|
-
context.run(...params.value || []);
|
|
558
|
-
};
|
|
559
|
-
context.refreshAsync = () => {
|
|
560
|
-
return context.runAsync(...params.value || []);
|
|
561
|
-
};
|
|
562
|
-
context.mutate = (x) => {
|
|
563
|
-
const mutateData = isFunction(x) ? x(data.value) : x;
|
|
564
|
-
const _mutateData = shallowCopy(mutateData);
|
|
565
|
-
setState({
|
|
566
|
-
data: _mutateData
|
|
567
|
-
});
|
|
568
|
-
emit("onMutate", _mutateData);
|
|
569
|
-
};
|
|
570
|
-
return {
|
|
571
|
-
status,
|
|
572
|
-
loading,
|
|
573
|
-
data,
|
|
574
|
-
error,
|
|
575
|
-
params,
|
|
576
|
-
plugins,
|
|
577
|
-
context
|
|
578
|
-
};
|
|
579
|
-
};
|
|
580
|
-
function useQuery(service, options = {}, plugins) {
|
|
581
|
-
const injectedGlobalOptions = inject(GLOBAL_OPTIONS_PROVIDE_KEY, {});
|
|
582
|
-
const config = {
|
|
583
|
-
...getGlobalOptions(),
|
|
584
|
-
...injectedGlobalOptions,
|
|
585
|
-
...options
|
|
586
|
-
};
|
|
587
|
-
const {
|
|
588
|
-
manual = false,
|
|
589
|
-
defaultParams = []
|
|
590
|
-
} = config;
|
|
591
|
-
const queryInstance = createQuery(service, config);
|
|
592
|
-
queryInstance.plugins.value = plugins.map((i) => i(queryInstance, config));
|
|
593
|
-
if (!manual) {
|
|
594
|
-
const params = queryInstance.params.value || defaultParams;
|
|
595
|
-
queryInstance.context.run(...params);
|
|
596
|
-
}
|
|
597
|
-
onUnmounted(() => {
|
|
598
|
-
queryInstance.context.cancel();
|
|
599
|
-
});
|
|
600
|
-
return {
|
|
601
|
-
loading: queryInstance.loading,
|
|
602
|
-
data: queryInstance.data,
|
|
603
|
-
error: queryInstance.error,
|
|
604
|
-
params: queryInstance.params,
|
|
605
|
-
cancel: queryInstance.context.cancel,
|
|
606
|
-
refresh: queryInstance.context.refresh,
|
|
607
|
-
refreshAsync: queryInstance.context.refreshAsync,
|
|
608
|
-
mutate: queryInstance.context.mutate,
|
|
609
|
-
run: queryInstance.context.run,
|
|
610
|
-
runAsync: queryInstance.context.runAsync
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
function useLoadMore(service, options) {
|
|
614
|
-
const {
|
|
615
|
-
isNoMore,
|
|
616
|
-
...restOptions
|
|
617
|
-
} = options !== null && options !== void 0 ? options : {};
|
|
618
|
-
const data = shallowRef();
|
|
619
|
-
const dataList = computed(() => {
|
|
620
|
-
var _data$value;
|
|
621
|
-
return ((_data$value = data.value) === null || _data$value === void 0 ? void 0 : _data$value.list) || [];
|
|
622
|
-
});
|
|
623
|
-
const loadingMore = ref(false);
|
|
624
|
-
const isTriggerByLoadMore = ref(false);
|
|
625
|
-
const count = ref(0);
|
|
626
|
-
const {
|
|
627
|
-
runAsync,
|
|
628
|
-
run,
|
|
629
|
-
cancel: _cancel,
|
|
630
|
-
...rest
|
|
631
|
-
} = useQuery(async (lastData) => {
|
|
632
|
-
const currentCount = count.value;
|
|
633
|
-
const currentData = await service(lastData);
|
|
634
|
-
if (currentCount === count.value) {
|
|
635
|
-
if (lastData) {
|
|
636
|
-
data.value = {
|
|
637
|
-
...currentData,
|
|
638
|
-
list: [...lastData.list, ...currentData.list]
|
|
639
|
-
};
|
|
640
|
-
} else {
|
|
641
|
-
data.value = currentData;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
return currentData;
|
|
645
|
-
}, {
|
|
646
|
-
...restOptions,
|
|
647
|
-
defaultParams: [],
|
|
648
|
-
refreshDepsAction: () => {
|
|
649
|
-
if (restOptions !== null && restOptions !== void 0 && restOptions.refreshDepsAction) {
|
|
650
|
-
restOptions.refreshDepsAction();
|
|
651
|
-
} else {
|
|
652
|
-
refresh();
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
onError: (error) => {
|
|
656
|
-
var _restOptions$onError;
|
|
657
|
-
restOptions === null || restOptions === void 0 ? void 0 : (_restOptions$onError = restOptions.onError) === null || _restOptions$onError === void 0 ? void 0 : _restOptions$onError.call(restOptions, error);
|
|
658
|
-
},
|
|
659
|
-
onSuccess: (data2) => {
|
|
660
|
-
var _restOptions$onSucces;
|
|
661
|
-
restOptions === null || restOptions === void 0 ? void 0 : (_restOptions$onSucces = restOptions.onSuccess) === null || _restOptions$onSucces === void 0 ? void 0 : _restOptions$onSucces.call(restOptions, data2);
|
|
662
|
-
},
|
|
663
|
-
onBefore: () => {
|
|
664
|
-
var _restOptions$onBefore;
|
|
665
|
-
count.value += 1;
|
|
666
|
-
if (isTriggerByLoadMore.value) {
|
|
667
|
-
isTriggerByLoadMore.value = false;
|
|
668
|
-
loadingMore.value = true;
|
|
669
|
-
}
|
|
670
|
-
restOptions === null || restOptions === void 0 ? void 0 : (_restOptions$onBefore = restOptions.onBefore) === null || _restOptions$onBefore === void 0 ? void 0 : _restOptions$onBefore.call(restOptions);
|
|
671
|
-
},
|
|
672
|
-
onAfter: () => {
|
|
673
|
-
var _restOptions$onAfter;
|
|
674
|
-
loadingMore.value = false;
|
|
675
|
-
isTriggerByLoadMore.value = false;
|
|
676
|
-
restOptions === null || restOptions === void 0 ? void 0 : (_restOptions$onAfter = restOptions.onAfter) === null || _restOptions$onAfter === void 0 ? void 0 : _restOptions$onAfter.call(restOptions);
|
|
677
|
-
}
|
|
678
|
-
}, [useErrorRetryPlugin, useDebouncePlugin, useThrottlePlugin, useRefreshDepsPlugin, useReadyPlugin]);
|
|
679
|
-
const noMore = computed(() => {
|
|
680
|
-
return isNoMore && isFunction(isNoMore) ? isNoMore(data.value) : false;
|
|
681
|
-
});
|
|
682
|
-
const loadMore = () => {
|
|
683
|
-
loadMoreAsync().catch(() => {
|
|
684
|
-
});
|
|
685
|
-
};
|
|
686
|
-
const loadMoreAsync = () => {
|
|
687
|
-
if (noMore.value) {
|
|
688
|
-
return Promise.reject(warning("No more data. You need to ignore this error by checking if `noMore` is false before calling `loadMoreAsync`", true));
|
|
689
|
-
}
|
|
690
|
-
isTriggerByLoadMore.value = true;
|
|
691
|
-
return runAsync(data.value);
|
|
692
|
-
};
|
|
693
|
-
const refresh = () => run();
|
|
694
|
-
const refreshAsync = () => runAsync();
|
|
695
|
-
const cancel = () => {
|
|
696
|
-
count.value += 1;
|
|
697
|
-
_cancel();
|
|
698
|
-
loadingMore.value = false;
|
|
699
|
-
};
|
|
700
|
-
const mutate = (x) => {
|
|
701
|
-
const mutateData = isFunction(x) ? x(data.value) : x;
|
|
702
|
-
const _mutateData = shallowCopy(mutateData);
|
|
703
|
-
data.value = _mutateData;
|
|
704
|
-
};
|
|
705
|
-
return {
|
|
706
|
-
data,
|
|
707
|
-
dataList,
|
|
708
|
-
loadingMore,
|
|
709
|
-
noMore,
|
|
710
|
-
cancel,
|
|
711
|
-
mutate,
|
|
712
|
-
refresh,
|
|
713
|
-
refreshAsync,
|
|
714
|
-
loadMore,
|
|
715
|
-
loadMoreAsync,
|
|
716
|
-
...omit(rest, ["refresh", "refreshAsync", "mutate", "params", "data"])
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
var cacheQuery = /* @__PURE__ */ new Map();
|
|
720
|
-
var setCacheQuery = (cacheKey, query) => {
|
|
721
|
-
cacheQuery.set(cacheKey, query);
|
|
722
|
-
query.then((res) => {
|
|
723
|
-
cacheQuery.delete(cacheKey);
|
|
724
|
-
return res;
|
|
725
|
-
}).catch(() => {
|
|
726
|
-
cacheQuery.delete(cacheKey);
|
|
727
|
-
});
|
|
728
|
-
};
|
|
729
|
-
var getCacheQuery = (cacheKey) => {
|
|
730
|
-
return cacheQuery.get(cacheKey);
|
|
731
|
-
};
|
|
732
|
-
var listeners = /* @__PURE__ */ new Map();
|
|
733
|
-
var trigger = (key, data) => {
|
|
734
|
-
if (listeners.has(key)) {
|
|
735
|
-
listeners.get(key).forEach((item) => item(data));
|
|
736
|
-
}
|
|
737
|
-
};
|
|
738
|
-
var subscribe = (key, listener) => {
|
|
739
|
-
if (!listeners.has(key)) {
|
|
740
|
-
listeners.set(key, [listener]);
|
|
741
|
-
} else {
|
|
742
|
-
listeners.get(key).push(listener);
|
|
743
|
-
}
|
|
744
|
-
return () => {
|
|
745
|
-
const index = listeners.get(key).indexOf(listener);
|
|
746
|
-
listeners.get(key).splice(index, 1);
|
|
747
|
-
};
|
|
748
|
-
};
|
|
749
|
-
var useCachePlugin = definePlugin((queryInstance, {
|
|
750
|
-
cacheKey: customCacheKey,
|
|
751
|
-
cacheTime = 6e5,
|
|
752
|
-
staleTime = 0,
|
|
753
|
-
getCache: customGetCache,
|
|
754
|
-
setCache: customSetCache
|
|
755
|
-
}) => {
|
|
756
|
-
if (!customCacheKey)
|
|
757
|
-
return {};
|
|
758
|
-
const cacheKey = isFunction(customCacheKey) ? customCacheKey : () => customCacheKey;
|
|
759
|
-
const unSubscribe = ref(() => {
|
|
760
|
-
});
|
|
761
|
-
let currentQuery;
|
|
762
|
-
const _getCache = (key) => {
|
|
763
|
-
if (customGetCache) {
|
|
764
|
-
return customGetCache(key);
|
|
765
|
-
} else {
|
|
766
|
-
return getCache(key);
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
const _setCache = (key, time, cacheData) => {
|
|
770
|
-
if (customSetCache) {
|
|
771
|
-
customSetCache(key, cacheData);
|
|
772
|
-
} else {
|
|
773
|
-
setCache(key, time, cacheData);
|
|
774
|
-
}
|
|
775
|
-
trigger(key, cacheData.data);
|
|
776
|
-
};
|
|
777
|
-
const isFresh = (time) => staleTime === -1 || time + staleTime > (/* @__PURE__ */ new Date()).getTime();
|
|
778
|
-
const hasProp = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
|
|
779
|
-
const subscribeCache = (params) => {
|
|
780
|
-
const _cacheKey2 = cacheKey(params);
|
|
781
|
-
return subscribe(_cacheKey2, (data) => {
|
|
782
|
-
queryInstance.data.value = data;
|
|
783
|
-
});
|
|
784
|
-
};
|
|
785
|
-
const _cacheKey = cacheKey();
|
|
786
|
-
const cache = _getCache(_cacheKey);
|
|
787
|
-
if (cache && hasProp(cache, "data")) {
|
|
788
|
-
queryInstance.data.value = cache.data;
|
|
789
|
-
queryInstance.params.value = cache.params;
|
|
790
|
-
}
|
|
791
|
-
if (_cacheKey) {
|
|
792
|
-
unSubscribe.value = subscribeCache();
|
|
793
|
-
}
|
|
794
|
-
onUnmounted(() => {
|
|
795
|
-
unSubscribe.value();
|
|
796
|
-
});
|
|
797
|
-
return {
|
|
798
|
-
onBefore(params) {
|
|
799
|
-
const _cacheKey2 = cacheKey(params);
|
|
800
|
-
const cache2 = _getCache(_cacheKey2);
|
|
801
|
-
if (!cache2 || !hasProp(cache2, "data")) {
|
|
802
|
-
return {};
|
|
803
|
-
}
|
|
804
|
-
if (isFresh(cache2.time)) {
|
|
805
|
-
queryInstance.data.value = cache2.data;
|
|
806
|
-
queryInstance.loading.value = false;
|
|
807
|
-
return {
|
|
808
|
-
isBreak: true,
|
|
809
|
-
breakResult: cache2.data
|
|
810
|
-
};
|
|
811
|
-
} else {
|
|
812
|
-
queryInstance.data.value = cache2.data;
|
|
813
|
-
}
|
|
814
|
-
},
|
|
815
|
-
onQuery(service) {
|
|
816
|
-
const params = queryInstance.params.value;
|
|
817
|
-
const _cacheKey2 = cacheKey(params);
|
|
818
|
-
let servicePromise = getCacheQuery(_cacheKey2);
|
|
819
|
-
if (servicePromise && servicePromise !== currentQuery) {
|
|
820
|
-
return () => servicePromise;
|
|
821
|
-
}
|
|
822
|
-
servicePromise = service();
|
|
823
|
-
currentQuery = servicePromise;
|
|
824
|
-
setCacheQuery(_cacheKey2, servicePromise);
|
|
825
|
-
return () => servicePromise;
|
|
826
|
-
},
|
|
827
|
-
onSuccess(data, params) {
|
|
828
|
-
const _cacheKey2 = cacheKey(params);
|
|
829
|
-
if (_cacheKey2) {
|
|
830
|
-
unSubscribe.value();
|
|
831
|
-
_setCache(_cacheKey2, cacheTime, {
|
|
832
|
-
data,
|
|
833
|
-
params,
|
|
834
|
-
time: (/* @__PURE__ */ new Date()).getTime()
|
|
835
|
-
});
|
|
836
|
-
unSubscribe.value = subscribeCache(params);
|
|
837
|
-
}
|
|
838
|
-
},
|
|
839
|
-
onMutate(data) {
|
|
840
|
-
const _cacheKey2 = cacheKey(queryInstance.params.value);
|
|
841
|
-
if (_cacheKey2) {
|
|
842
|
-
unSubscribe.value();
|
|
843
|
-
_setCache(_cacheKey2, cacheTime, {
|
|
844
|
-
data,
|
|
845
|
-
params: queryInstance.params.value,
|
|
846
|
-
time: (/* @__PURE__ */ new Date()).getTime()
|
|
847
|
-
});
|
|
848
|
-
unSubscribe.value = subscribeCache(queryInstance.params.value);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
});
|
|
853
|
-
function setTimeoutPromise(duration) {
|
|
854
|
-
let timerId, stop;
|
|
855
|
-
class Timer extends Promise {
|
|
856
|
-
constructor(fn) {
|
|
857
|
-
super(fn);
|
|
858
|
-
this.cancel = () => {
|
|
859
|
-
stop();
|
|
860
|
-
clearTimeout(timerId);
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
return new Timer((resolve) => {
|
|
865
|
-
stop = resolve;
|
|
866
|
-
timerId = setTimeout(stop, duration);
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
function getCurrentTime() {
|
|
870
|
-
return (/* @__PURE__ */ new Date()).getTime();
|
|
871
|
-
}
|
|
872
|
-
var useLoadingDelayPlugin = definePlugin((queryInstance, {
|
|
873
|
-
loadingDelay = 0,
|
|
874
|
-
loadingKeep = 0
|
|
875
|
-
}) => {
|
|
876
|
-
const delayLoadingTimer = ref(() => {
|
|
877
|
-
});
|
|
878
|
-
const loadingDelayRef = computed(() => refToRaw(loadingDelay));
|
|
879
|
-
const loadingKeepRef = computed(() => refToRaw(loadingKeep));
|
|
880
|
-
let startTime = 0;
|
|
881
|
-
let timeoutPromise = {};
|
|
882
|
-
const delayLoading = () => {
|
|
883
|
-
let timerId;
|
|
884
|
-
if (loadingDelayRef.value) {
|
|
885
|
-
timerId = setTimeout(() => {
|
|
886
|
-
if (queryInstance.status.value === "pending") {
|
|
887
|
-
queryInstance.loading.value = true;
|
|
888
|
-
}
|
|
889
|
-
}, loadingDelayRef.value);
|
|
890
|
-
}
|
|
891
|
-
return () => timerId && clearTimeout(timerId);
|
|
892
|
-
};
|
|
893
|
-
return {
|
|
894
|
-
onBefore() {
|
|
895
|
-
queryInstance.loading.value = !loadingDelayRef.value;
|
|
896
|
-
delayLoadingTimer.value();
|
|
897
|
-
delayLoadingTimer.value = delayLoading();
|
|
898
|
-
startTime = getCurrentTime();
|
|
899
|
-
},
|
|
900
|
-
onQuery(service) {
|
|
901
|
-
if (!loadingKeepRef.value)
|
|
902
|
-
return () => service();
|
|
903
|
-
timeoutPromise = setTimeoutPromise(loadingKeepRef.value + loadingDelayRef.value);
|
|
904
|
-
const _service = async () => {
|
|
905
|
-
try {
|
|
906
|
-
const res = await service();
|
|
907
|
-
if (getCurrentTime() - startTime <= loadingDelayRef.value) {
|
|
908
|
-
timeoutPromise.cancel();
|
|
909
|
-
}
|
|
910
|
-
return Promise.resolve(res);
|
|
911
|
-
} catch (error) {
|
|
912
|
-
if (getCurrentTime() - startTime <= loadingDelayRef.value) {
|
|
913
|
-
timeoutPromise.cancel();
|
|
914
|
-
}
|
|
915
|
-
return Promise.reject(error);
|
|
916
|
-
}
|
|
917
|
-
};
|
|
918
|
-
const servicePromise = Promise.allSettled([_service(), timeoutPromise]).then((res) => {
|
|
919
|
-
const result = res[0];
|
|
920
|
-
if (result.status === "fulfilled") {
|
|
921
|
-
return result.value;
|
|
922
|
-
} else {
|
|
923
|
-
return Promise.reject(result.reason);
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
return () => servicePromise;
|
|
927
|
-
},
|
|
928
|
-
onCancel() {
|
|
929
|
-
delayLoadingTimer.value();
|
|
930
|
-
},
|
|
931
|
-
onAfter() {
|
|
932
|
-
delayLoadingTimer.value();
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
});
|
|
936
|
-
var _window;
|
|
937
|
-
var FOCUS_LISTENER = /* @__PURE__ */ new Set();
|
|
938
|
-
var VISIBLE_LISTENER = /* @__PURE__ */ new Set();
|
|
939
|
-
var RECONNECT_LISTENER = /* @__PURE__ */ new Set();
|
|
940
|
-
var subscriber = (listenerType, event) => {
|
|
941
|
-
let listeners2;
|
|
942
|
-
switch (listenerType) {
|
|
943
|
-
case "FOCUS_LISTENER":
|
|
944
|
-
listeners2 = FOCUS_LISTENER;
|
|
945
|
-
break;
|
|
946
|
-
case "RECONNECT_LISTENER":
|
|
947
|
-
listeners2 = RECONNECT_LISTENER;
|
|
948
|
-
break;
|
|
949
|
-
case "VISIBLE_LISTENER":
|
|
950
|
-
listeners2 = VISIBLE_LISTENER;
|
|
951
|
-
break;
|
|
952
|
-
}
|
|
953
|
-
if (listeners2.has(event))
|
|
954
|
-
return;
|
|
955
|
-
listeners2.add(event);
|
|
956
|
-
return () => {
|
|
957
|
-
listeners2.delete(event);
|
|
958
|
-
};
|
|
959
|
-
};
|
|
960
|
-
var observer = (listeners2) => {
|
|
961
|
-
listeners2.forEach((event) => {
|
|
962
|
-
event();
|
|
963
|
-
});
|
|
964
|
-
};
|
|
965
|
-
if (!isServer && (_window = window) !== null && _window !== void 0 && _window.addEventListener) {
|
|
966
|
-
window.addEventListener("visibilitychange", () => {
|
|
967
|
-
if (isDocumentVisibility()) {
|
|
968
|
-
observer(VISIBLE_LISTENER);
|
|
969
|
-
}
|
|
970
|
-
}, false);
|
|
971
|
-
window.addEventListener("focus", () => observer(FOCUS_LISTENER), false);
|
|
972
|
-
window.addEventListener("online", () => observer(RECONNECT_LISTENER), false);
|
|
973
|
-
}
|
|
974
|
-
var usePollingPlugin = definePlugin((queryInstance, {
|
|
975
|
-
pollingInterval,
|
|
976
|
-
pollingWhenHidden = false,
|
|
977
|
-
pollingWhenOffline = false,
|
|
978
|
-
errorRetryCount = 0
|
|
979
|
-
}) => {
|
|
980
|
-
const pollingTimer = ref();
|
|
981
|
-
const stopPollingWhenHiddenOrOffline = ref(false);
|
|
982
|
-
const pollingIntervalRef = computed(() => refToRaw(pollingInterval));
|
|
983
|
-
const errorRetryCountRef = computed(() => refToRaw(errorRetryCount));
|
|
984
|
-
const unsubscribeList = [];
|
|
985
|
-
const addUnsubscribeList = (event) => {
|
|
986
|
-
event && unsubscribeList.push(event);
|
|
987
|
-
};
|
|
988
|
-
const isKeepPolling = () => {
|
|
989
|
-
return (
|
|
990
|
-
// pollingWhenHidden = true or pollingWhenHidden = false and document is visibility
|
|
991
|
-
(pollingWhenHidden || isDocumentVisibility()) && // pollingWhenOffline = true or pollingWhenOffline = false and is online
|
|
992
|
-
(pollingWhenOffline || isOnline())
|
|
993
|
-
);
|
|
994
|
-
};
|
|
995
|
-
const polling = (pollingFunc) => {
|
|
996
|
-
if (queryInstance.error.value && errorRetryCountRef.value !== 0)
|
|
997
|
-
return;
|
|
998
|
-
let timerId;
|
|
999
|
-
if (!isNil(pollingIntervalRef.value) && pollingIntervalRef.value >= 0) {
|
|
1000
|
-
if (isKeepPolling()) {
|
|
1001
|
-
timerId = setTimeout(pollingFunc, pollingIntervalRef.value);
|
|
1002
|
-
} else {
|
|
1003
|
-
stopPollingWhenHiddenOrOffline.value = true;
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
return () => timerId && clearTimeout(timerId);
|
|
1008
|
-
};
|
|
1009
|
-
const rePolling = () => {
|
|
1010
|
-
if (stopPollingWhenHiddenOrOffline.value && isKeepPolling()) {
|
|
1011
|
-
queryInstance.context.refresh();
|
|
1012
|
-
stopPollingWhenHiddenOrOffline.value = false;
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
watch(pollingIntervalRef, () => {
|
|
1016
|
-
if (pollingTimer.value) {
|
|
1017
|
-
pollingTimer.value();
|
|
1018
|
-
pollingTimer.value = polling(() => queryInstance.context.refresh());
|
|
1019
|
-
}
|
|
1020
|
-
});
|
|
1021
|
-
if (!pollingWhenHidden) {
|
|
1022
|
-
addUnsubscribeList(subscriber("VISIBLE_LISTENER", rePolling));
|
|
1023
|
-
}
|
|
1024
|
-
if (!pollingWhenOffline) {
|
|
1025
|
-
addUnsubscribeList(subscriber("RECONNECT_LISTENER", rePolling));
|
|
1026
|
-
}
|
|
1027
|
-
onUnmounted(() => {
|
|
1028
|
-
unsubscribeList.forEach((unsubscribe) => unsubscribe());
|
|
1029
|
-
});
|
|
1030
|
-
return {
|
|
1031
|
-
onBefore() {
|
|
1032
|
-
var _pollingTimer$value;
|
|
1033
|
-
(_pollingTimer$value = pollingTimer.value) === null || _pollingTimer$value === void 0 ? void 0 : _pollingTimer$value.call(pollingTimer);
|
|
1034
|
-
},
|
|
1035
|
-
onCancel() {
|
|
1036
|
-
var _pollingTimer$value2;
|
|
1037
|
-
(_pollingTimer$value2 = pollingTimer.value) === null || _pollingTimer$value2 === void 0 ? void 0 : _pollingTimer$value2.call(pollingTimer);
|
|
1038
|
-
},
|
|
1039
|
-
onAfter() {
|
|
1040
|
-
pollingTimer.value = polling(() => queryInstance.context.refresh());
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
});
|
|
1044
|
-
var limitTrigger = (fn, timeInterval) => {
|
|
1045
|
-
let running = false;
|
|
1046
|
-
return (...args) => {
|
|
1047
|
-
if (running)
|
|
1048
|
-
return;
|
|
1049
|
-
running = true;
|
|
1050
|
-
fn(...args);
|
|
1051
|
-
setTimeout(() => {
|
|
1052
|
-
running = false;
|
|
1053
|
-
}, timeInterval);
|
|
1054
|
-
};
|
|
1055
|
-
};
|
|
1056
|
-
var useRefreshOnWindowFocus = definePlugin((queryInstance, {
|
|
1057
|
-
refreshOnWindowFocus = false,
|
|
1058
|
-
refocusTimespan = 5e3
|
|
1059
|
-
}) => {
|
|
1060
|
-
const refreshOnWindowFocusRef = computed(() => refToRaw(refreshOnWindowFocus));
|
|
1061
|
-
const refocusTimespanRef = computed(() => refToRaw(refocusTimespan));
|
|
1062
|
-
const unsubscribeList = [];
|
|
1063
|
-
const addUnsubscribeList = (event) => {
|
|
1064
|
-
event && unsubscribeList.push(event);
|
|
1065
|
-
};
|
|
1066
|
-
const unsubscribe = () => {
|
|
1067
|
-
unsubscribeList.forEach((fn) => fn());
|
|
1068
|
-
};
|
|
1069
|
-
watchEffect(() => {
|
|
1070
|
-
unsubscribe();
|
|
1071
|
-
if (refreshOnWindowFocusRef.value) {
|
|
1072
|
-
const limitRefresh = limitTrigger(queryInstance.context.refresh, refocusTimespanRef.value);
|
|
1073
|
-
addUnsubscribeList(subscriber("VISIBLE_LISTENER", limitRefresh));
|
|
1074
|
-
addUnsubscribeList(subscriber("FOCUS_LISTENER", limitRefresh));
|
|
1075
|
-
}
|
|
1076
|
-
});
|
|
1077
|
-
onUnmounted(() => {
|
|
1078
|
-
unsubscribe();
|
|
1079
|
-
});
|
|
1080
|
-
return {};
|
|
1081
|
-
});
|
|
1082
|
-
function useRequest(service, options) {
|
|
1083
|
-
return useQuery(service, options, [useLoadingDelayPlugin, useErrorRetryPlugin, useDebouncePlugin, usePollingPlugin, useThrottlePlugin, useRefreshOnWindowFocus, useRefreshDepsPlugin, useReadyPlugin, useCachePlugin]);
|
|
1084
|
-
}
|
|
1085
|
-
function usePagination(service, options = {}) {
|
|
1086
|
-
const defaultPaginationOptions = {
|
|
1087
|
-
currentKey: "current",
|
|
1088
|
-
pageSizeKey: "pageSize",
|
|
1089
|
-
totalKey: "total",
|
|
1090
|
-
totalPageKey: "totalPage"
|
|
1091
|
-
};
|
|
1092
|
-
const injectedGlobalOptions = inject(GLOBAL_OPTIONS_PROVIDE_KEY, {});
|
|
1093
|
-
const {
|
|
1094
|
-
pagination,
|
|
1095
|
-
...restOptions
|
|
1096
|
-
} = options;
|
|
1097
|
-
const {
|
|
1098
|
-
currentKey,
|
|
1099
|
-
pageSizeKey,
|
|
1100
|
-
totalKey,
|
|
1101
|
-
totalPageKey
|
|
1102
|
-
} = merge(defaultPaginationOptions, getGlobalOptions().pagination || {}, injectedGlobalOptions.pagination || {}, pagination || {});
|
|
1103
|
-
const finallyOptions = merge({
|
|
1104
|
-
defaultParams: [{
|
|
1105
|
-
[currentKey]: 1,
|
|
1106
|
-
[pageSizeKey]: 10
|
|
1107
|
-
}]
|
|
1108
|
-
}, restOptions);
|
|
1109
|
-
const {
|
|
1110
|
-
data,
|
|
1111
|
-
params,
|
|
1112
|
-
run,
|
|
1113
|
-
...rest
|
|
1114
|
-
} = useRequest(service, finallyOptions);
|
|
1115
|
-
const paging = (paginationParams) => {
|
|
1116
|
-
const [oldPaginationParams, ...restParams] = params.value || [];
|
|
1117
|
-
const newPaginationParams = {
|
|
1118
|
-
...oldPaginationParams,
|
|
1119
|
-
...paginationParams
|
|
1120
|
-
};
|
|
1121
|
-
const mergerParams = [newPaginationParams, ...restParams];
|
|
1122
|
-
run(...mergerParams);
|
|
1123
|
-
};
|
|
1124
|
-
const changeCurrent = (current2) => {
|
|
1125
|
-
paging({
|
|
1126
|
-
[currentKey]: current2
|
|
1127
|
-
});
|
|
1128
|
-
};
|
|
1129
|
-
const changePageSize = (pageSize2) => {
|
|
1130
|
-
paging({
|
|
1131
|
-
[pageSizeKey]: pageSize2
|
|
1132
|
-
});
|
|
1133
|
-
};
|
|
1134
|
-
const changePagination = (current2, pageSize2) => {
|
|
1135
|
-
paging({
|
|
1136
|
-
[currentKey]: current2,
|
|
1137
|
-
[pageSizeKey]: pageSize2
|
|
1138
|
-
});
|
|
1139
|
-
};
|
|
1140
|
-
const total = computed(() => get(data.value, totalKey, 0));
|
|
1141
|
-
const current = computed({
|
|
1142
|
-
get: () => {
|
|
1143
|
-
var _params$value$0$curre, _params$value, _params$value$;
|
|
1144
|
-
return (
|
|
1145
|
-
// @ts-ignore
|
|
1146
|
-
(_params$value$0$curre = (_params$value = params.value) === null || _params$value === void 0 ? void 0 : (_params$value$ = _params$value[0]) === null || _params$value$ === void 0 ? void 0 : _params$value$[currentKey]) !== null && _params$value$0$curre !== void 0 ? _params$value$0$curre : finallyOptions.defaultParams[0][currentKey]
|
|
1147
|
-
);
|
|
1148
|
-
},
|
|
1149
|
-
set: (val) => {
|
|
1150
|
-
changeCurrent(val);
|
|
1151
|
-
}
|
|
1152
|
-
});
|
|
1153
|
-
const pageSize = computed({
|
|
1154
|
-
get: () => {
|
|
1155
|
-
var _params$value$0$pageS, _params$value2, _params$value2$;
|
|
1156
|
-
return (
|
|
1157
|
-
// @ts-ignore
|
|
1158
|
-
(_params$value$0$pageS = (_params$value2 = params.value) === null || _params$value2 === void 0 ? void 0 : (_params$value2$ = _params$value2[0]) === null || _params$value2$ === void 0 ? void 0 : _params$value2$[pageSizeKey]) !== null && _params$value$0$pageS !== void 0 ? _params$value$0$pageS : finallyOptions.defaultParams[0][pageSizeKey]
|
|
1159
|
-
);
|
|
1160
|
-
},
|
|
1161
|
-
set: (val) => {
|
|
1162
|
-
changePageSize(val);
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
const totalPage = computed(() => get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)));
|
|
1166
|
-
return {
|
|
1167
|
-
data,
|
|
1168
|
-
params,
|
|
1169
|
-
current,
|
|
1170
|
-
pageSize,
|
|
1171
|
-
total,
|
|
1172
|
-
totalPage,
|
|
1173
|
-
run,
|
|
1174
|
-
changeCurrent,
|
|
1175
|
-
changePageSize,
|
|
1176
|
-
changePagination,
|
|
1177
|
-
...rest
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
var useRequestProvider = (config) => {
|
|
1181
|
-
provide(GLOBAL_OPTIONS_PROVIDE_KEY, config);
|
|
1182
|
-
};
|
|
1183
|
-
export {
|
|
1184
|
-
clearCache,
|
|
1185
|
-
setGlobalOptions,
|
|
1186
|
-
useLoadMore,
|
|
1187
|
-
usePagination,
|
|
1188
|
-
useRequest,
|
|
1189
|
-
useRequestProvider
|
|
1190
|
-
};
|
|
1191
|
-
//# sourceMappingURL=vue-request.js.map
|