@yh-ui/request 1.0.54 → 1.0.55
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/useLoadMore.cjs +9 -3
- package/dist/useLoadMore.mjs +16 -4
- package/dist/usePagination.cjs +6 -2
- package/dist/usePagination.mjs +14 -3
- package/dist/useQueue.cjs +5 -3
- package/dist/useQueue.mjs +12 -4
- package/dist/useRequest.cjs +36 -20
- package/dist/useRequest.mjs +37 -20
- package/dist/useSSE.cjs +5 -3
- package/dist/useSSE.mjs +6 -4
- package/dist/websocket.cjs +5 -3
- package/dist/websocket.mjs +6 -4
- package/package.json +2 -2
package/dist/useLoadMore.cjs
CHANGED
|
@@ -90,7 +90,9 @@ function useLoadMore(service, options = {}) {
|
|
|
90
90
|
if (page < 1 || totalPages.value > 0 && page > totalPages.value) return;
|
|
91
91
|
await loadData(page, true);
|
|
92
92
|
},
|
|
93
|
-
nextPage:
|
|
93
|
+
nextPage: async () => {
|
|
94
|
+
await pagination.loadPage(current.value + 1);
|
|
95
|
+
},
|
|
94
96
|
prevPage: async () => {
|
|
95
97
|
await pagination.loadPage(current.value - 1);
|
|
96
98
|
},
|
|
@@ -109,9 +111,13 @@ function useLoadMore(service, options = {}) {
|
|
|
109
111
|
}
|
|
110
112
|
};
|
|
111
113
|
if (!manual) {
|
|
112
|
-
(0, _vue.
|
|
114
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
115
|
+
(0, _vue.onMounted)(() => {
|
|
116
|
+
loadData(current.value, false);
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
113
119
|
loadData(current.value, false);
|
|
114
|
-
}
|
|
120
|
+
}
|
|
115
121
|
}
|
|
116
122
|
return {
|
|
117
123
|
current,
|
package/dist/useLoadMore.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
shallowRef,
|
|
4
|
+
computed,
|
|
5
|
+
onMounted,
|
|
6
|
+
getCurrentInstance
|
|
7
|
+
} from "vue";
|
|
2
8
|
export function useLoadMore(service, options = {}) {
|
|
3
9
|
const {
|
|
4
10
|
initialPage = 1,
|
|
@@ -88,7 +94,9 @@ export function useLoadMore(service, options = {}) {
|
|
|
88
94
|
if (page < 1 || totalPages.value > 0 && page > totalPages.value) return;
|
|
89
95
|
await loadData(page, true);
|
|
90
96
|
},
|
|
91
|
-
nextPage:
|
|
97
|
+
nextPage: async () => {
|
|
98
|
+
await pagination.loadPage(current.value + 1);
|
|
99
|
+
},
|
|
92
100
|
prevPage: async () => {
|
|
93
101
|
await pagination.loadPage(current.value - 1);
|
|
94
102
|
},
|
|
@@ -107,9 +115,13 @@ export function useLoadMore(service, options = {}) {
|
|
|
107
115
|
}
|
|
108
116
|
};
|
|
109
117
|
if (!manual) {
|
|
110
|
-
|
|
118
|
+
if (getCurrentInstance()) {
|
|
119
|
+
onMounted(() => {
|
|
120
|
+
loadData(current.value, false);
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
111
123
|
loadData(current.value, false);
|
|
112
|
-
}
|
|
124
|
+
}
|
|
113
125
|
}
|
|
114
126
|
return {
|
|
115
127
|
current,
|
package/dist/usePagination.cjs
CHANGED
|
@@ -139,9 +139,13 @@ function usePagination(service, options = {}) {
|
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
if (!manual) {
|
|
142
|
-
(0, _vue.
|
|
142
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
143
|
+
(0, _vue.onMounted)(() => {
|
|
144
|
+
loadData();
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
143
147
|
loadData();
|
|
144
|
-
}
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
return {
|
|
147
151
|
current,
|
package/dist/usePagination.mjs
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
shallowRef,
|
|
4
|
+
computed,
|
|
5
|
+
watch,
|
|
6
|
+
onMounted,
|
|
7
|
+
getCurrentInstance
|
|
8
|
+
} from "vue";
|
|
2
9
|
export function usePagination(service, options = {}) {
|
|
3
10
|
const {
|
|
4
11
|
defaultPagination = { current: 1, pageSize: 10 },
|
|
@@ -130,9 +137,13 @@ export function usePagination(service, options = {}) {
|
|
|
130
137
|
}
|
|
131
138
|
});
|
|
132
139
|
if (!manual) {
|
|
133
|
-
|
|
140
|
+
if (getCurrentInstance()) {
|
|
141
|
+
onMounted(() => {
|
|
142
|
+
loadData();
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
134
145
|
loadData();
|
|
135
|
-
}
|
|
146
|
+
}
|
|
136
147
|
}
|
|
137
148
|
return {
|
|
138
149
|
current,
|
package/dist/useQueue.cjs
CHANGED
|
@@ -237,9 +237,11 @@ function useQueue(options = {}) {
|
|
|
237
237
|
const getTask = taskId => {
|
|
238
238
|
return taskMap.get(taskId);
|
|
239
239
|
};
|
|
240
|
-
(0, _vue.
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
241
|
+
(0, _vue.onUnmounted)(() => {
|
|
242
|
+
cancelAll();
|
|
243
|
+
});
|
|
244
|
+
}
|
|
243
245
|
return {
|
|
244
246
|
tasks,
|
|
245
247
|
pendingTasks,
|
package/dist/useQueue.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
reactive,
|
|
4
|
+
computed,
|
|
5
|
+
onUnmounted,
|
|
6
|
+
getCurrentInstance
|
|
7
|
+
} from "vue";
|
|
2
8
|
let taskIdCounter = 0;
|
|
3
9
|
function generateTaskId() {
|
|
4
10
|
return `task_${Date.now()}_${++taskIdCounter}`;
|
|
@@ -231,9 +237,11 @@ export function useQueue(options = {}) {
|
|
|
231
237
|
const getTask = (taskId) => {
|
|
232
238
|
return taskMap.get(taskId);
|
|
233
239
|
};
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
240
|
+
if (getCurrentInstance()) {
|
|
241
|
+
onUnmounted(() => {
|
|
242
|
+
cancelAll();
|
|
243
|
+
});
|
|
244
|
+
}
|
|
237
245
|
return {
|
|
238
246
|
tasks,
|
|
239
247
|
pendingTasks,
|
package/dist/useRequest.cjs
CHANGED
|
@@ -150,15 +150,23 @@ function useRequest(service, options = {}) {
|
|
|
150
150
|
wrappedRun.cancel = () => throttled.cancel();
|
|
151
151
|
cancelFn = () => throttled.cancel();
|
|
152
152
|
}
|
|
153
|
-
(0, _vue.
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
154
|
+
(0, _vue.onUnmounted)(() => {
|
|
155
|
+
cancel();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
156
158
|
if (!manual && defaultParams.length > 0) {
|
|
157
|
-
(0, _vue.
|
|
159
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
160
|
+
(0, _vue.onMounted)(() => {
|
|
161
|
+
if (!debounceWait && !throttleWait) {
|
|
162
|
+
run(...defaultParams).catch(() => {});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
158
166
|
if (!debounceWait && !throttleWait) {
|
|
159
167
|
run(...defaultParams).catch(() => {});
|
|
160
168
|
}
|
|
161
|
-
}
|
|
169
|
+
}
|
|
162
170
|
}
|
|
163
171
|
const disabled = (0, _vue.computed)(() => loading.value);
|
|
164
172
|
return {
|
|
@@ -247,14 +255,16 @@ function useRequestSWR(cacheKey, service, options = {}) {
|
|
|
247
255
|
swrRefresh();
|
|
248
256
|
}
|
|
249
257
|
};
|
|
250
|
-
(0, _vue.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
259
|
+
(0, _vue.onMounted)(() => {
|
|
260
|
+
window.addEventListener("visibilitychange", handleFocus);
|
|
261
|
+
window.addEventListener("focus", handleFocus);
|
|
262
|
+
});
|
|
263
|
+
(0, _vue.onUnmounted)(() => {
|
|
264
|
+
window.removeEventListener("visibilitychange", handleFocus);
|
|
265
|
+
window.removeEventListener("focus", handleFocus);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
258
268
|
}
|
|
259
269
|
if (refreshDeps && refreshDeps.length > 0 && !manual) {
|
|
260
270
|
(0, _vue.watch)(() => refreshDeps.map(dep => dep.value), () => {
|
|
@@ -336,14 +346,20 @@ function useRequestPolling(service, options = {}) {
|
|
|
336
346
|
startPolling();
|
|
337
347
|
}
|
|
338
348
|
};
|
|
339
|
-
(0, _vue.
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
if (polling) {
|
|
344
|
-
(0, _vue.onMounted)(() => {
|
|
345
|
-
startPolling();
|
|
349
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
350
|
+
(0, _vue.onUnmounted)(() => {
|
|
351
|
+
pause();
|
|
352
|
+
cancel();
|
|
346
353
|
});
|
|
354
|
+
if (polling) {
|
|
355
|
+
(0, _vue.onMounted)(() => {
|
|
356
|
+
startPolling();
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
if (polling) {
|
|
361
|
+
startPolling();
|
|
362
|
+
}
|
|
347
363
|
}
|
|
348
364
|
return {
|
|
349
365
|
loading,
|
package/dist/useRequest.mjs
CHANGED
|
@@ -155,16 +155,25 @@ export function useRequest(service, options = {}) {
|
|
|
155
155
|
wrappedRun.cancel = () => throttled.cancel();
|
|
156
156
|
cancelFn = () => throttled.cancel();
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
if (getCurrentInstance()) {
|
|
159
|
+
onUnmounted(() => {
|
|
160
|
+
cancel();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
161
163
|
if (!manual && defaultParams.length > 0) {
|
|
162
|
-
|
|
164
|
+
if (getCurrentInstance()) {
|
|
165
|
+
onMounted(() => {
|
|
166
|
+
if (!debounceWait && !throttleWait) {
|
|
167
|
+
run(...defaultParams).catch(() => {
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
} else {
|
|
163
172
|
if (!debounceWait && !throttleWait) {
|
|
164
173
|
run(...defaultParams).catch(() => {
|
|
165
174
|
});
|
|
166
175
|
}
|
|
167
|
-
}
|
|
176
|
+
}
|
|
168
177
|
}
|
|
169
178
|
const disabled = computed(() => loading.value);
|
|
170
179
|
return {
|
|
@@ -259,14 +268,16 @@ export function useRequestSWR(cacheKey, service, options = {}) {
|
|
|
259
268
|
swrRefresh();
|
|
260
269
|
}
|
|
261
270
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
271
|
+
if (getCurrentInstance()) {
|
|
272
|
+
onMounted(() => {
|
|
273
|
+
window.addEventListener("visibilitychange", handleFocus);
|
|
274
|
+
window.addEventListener("focus", handleFocus);
|
|
275
|
+
});
|
|
276
|
+
onUnmounted(() => {
|
|
277
|
+
window.removeEventListener("visibilitychange", handleFocus);
|
|
278
|
+
window.removeEventListener("focus", handleFocus);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
270
281
|
}
|
|
271
282
|
if (refreshDeps && refreshDeps.length > 0 && !manual) {
|
|
272
283
|
watch(
|
|
@@ -353,14 +364,20 @@ export function useRequestPolling(service, options = {}) {
|
|
|
353
364
|
startPolling();
|
|
354
365
|
}
|
|
355
366
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (polling) {
|
|
361
|
-
onMounted(() => {
|
|
362
|
-
startPolling();
|
|
367
|
+
if (getCurrentInstance()) {
|
|
368
|
+
onUnmounted(() => {
|
|
369
|
+
pause();
|
|
370
|
+
cancel();
|
|
363
371
|
});
|
|
372
|
+
if (polling) {
|
|
373
|
+
onMounted(() => {
|
|
374
|
+
startPolling();
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
if (polling) {
|
|
379
|
+
startPolling();
|
|
380
|
+
}
|
|
364
381
|
}
|
|
365
382
|
return {
|
|
366
383
|
loading,
|
package/dist/useSSE.cjs
CHANGED
|
@@ -226,9 +226,11 @@ function useSSE(options = {}) {
|
|
|
226
226
|
messages.value = [];
|
|
227
227
|
error.value = void 0;
|
|
228
228
|
};
|
|
229
|
-
(0, _vue.
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
230
|
+
(0, _vue.onUnmounted)(() => {
|
|
231
|
+
stop();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
232
234
|
return {
|
|
233
235
|
loading,
|
|
234
236
|
content,
|
package/dist/useSSE.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, shallowRef, onUnmounted } from "vue";
|
|
1
|
+
import { ref, shallowRef, onUnmounted, getCurrentInstance } from "vue";
|
|
2
2
|
export function useSSE(options = {}) {
|
|
3
3
|
const {
|
|
4
4
|
parseJSON = true,
|
|
@@ -211,9 +211,11 @@ export function useSSE(options = {}) {
|
|
|
211
211
|
messages.value = [];
|
|
212
212
|
error.value = void 0;
|
|
213
213
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
if (getCurrentInstance()) {
|
|
215
|
+
onUnmounted(() => {
|
|
216
|
+
stop();
|
|
217
|
+
});
|
|
218
|
+
}
|
|
217
219
|
return {
|
|
218
220
|
loading,
|
|
219
221
|
content,
|
package/dist/websocket.cjs
CHANGED
|
@@ -314,9 +314,11 @@ function useWebSocket(options) {
|
|
|
314
314
|
const state = client.state;
|
|
315
315
|
const isConnected = client.isConnected;
|
|
316
316
|
const lastMessage = client.lastMessage;
|
|
317
|
-
(0, _vue.
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
if ((0, _vue.getCurrentInstance)()) {
|
|
318
|
+
(0, _vue.onUnmounted)(() => {
|
|
319
|
+
client.dispose();
|
|
320
|
+
});
|
|
321
|
+
}
|
|
320
322
|
return {
|
|
321
323
|
/** 当前状态 */
|
|
322
324
|
state,
|
package/dist/websocket.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, onUnmounted } from "vue";
|
|
1
|
+
import { ref, onUnmounted, getCurrentInstance } from "vue";
|
|
2
2
|
export class WebSocketClient {
|
|
3
3
|
ws = null;
|
|
4
4
|
url = "";
|
|
@@ -298,9 +298,11 @@ export function useWebSocket(options) {
|
|
|
298
298
|
const state = client.state;
|
|
299
299
|
const isConnected = client.isConnected;
|
|
300
300
|
const lastMessage = client.lastMessage;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
301
|
+
if (getCurrentInstance()) {
|
|
302
|
+
onUnmounted(() => {
|
|
303
|
+
client.dispose();
|
|
304
|
+
});
|
|
305
|
+
}
|
|
304
306
|
return {
|
|
305
307
|
/** 当前状态 */
|
|
306
308
|
state,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yh-ui/request",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"description": "YH-UI HTTP request hooks - Enterprise-grade request management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"postpack": "node ../../scripts/prepare-package-manifest.mjs restore"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@yh-ui/utils": "^1.0.
|
|
35
|
+
"@yh-ui/utils": "^1.0.55"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"vue": "^3.5.35",
|