@varlet/axle 0.0.26 → 0.1.0
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 +124 -70
- package/README.zh-CN.md +124 -70
- package/es/instance.d.ts +0 -1
- package/es/instance.js +4 -1
- package/es/use.d.ts +3 -0
- package/es/use.js +4 -1
- package/es/useAllData.d.ts +1 -0
- package/es/useAllData.js +11 -0
- package/es/useAverageProgress.d.ts +2 -0
- package/es/useAverageProgress.js +9 -0
- package/es/useHasLoading.d.ts +2 -0
- package/es/useHasLoading.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<span>English</span> |
|
|
2
|
-
<a href="https://github.com/varletjs/axle/blob/
|
|
3
|
-
|
|
4
|
-
---
|
|
2
|
+
<a href="https://github.com/varletjs/axle/blob/main/README.zh-CN.md">中文</a>
|
|
5
3
|
|
|
6
4
|
### Intro
|
|
7
5
|
|
|
@@ -37,71 +35,6 @@ axle.get('/url', { current: 1, pageSize: 10 }, { headers: {} })
|
|
|
37
35
|
axle.post('/url', { name: 'Axle' }, { headers: {} })
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
#### Vue Composition API
|
|
41
|
-
|
|
42
|
-
Axle provides the usage of Vue Composition API style, which encapsulates the `loading status`, `error status`, `upload and download progress` of the request, `return data`, `error retry`, `lifecycle`, etc., And inherit all the configuration of `axios`.
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<script setup>
|
|
46
|
-
import { createAxle } from '@varlet/axle'
|
|
47
|
-
import { createUseAxle } from '@varlet/axle/use'
|
|
48
|
-
|
|
49
|
-
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
50
|
-
const useAxle = createUseAxle(/** Unstable **/)
|
|
51
|
-
|
|
52
|
-
const [users, getUsers, { loading, error, uploadProgress, downloadProgress }] = useAxle({
|
|
53
|
-
// Request initial data
|
|
54
|
-
data: [],
|
|
55
|
-
// Request runner
|
|
56
|
-
runner: axle.get,
|
|
57
|
-
// Request url
|
|
58
|
-
url: '/user',
|
|
59
|
-
// Whether to send the request immediately, defaults false
|
|
60
|
-
immediate: true,
|
|
61
|
-
// The number of retries after a failed request, defaults 0
|
|
62
|
-
retry: 3,
|
|
63
|
-
// Request params, defaults {}
|
|
64
|
-
params: { current: 1, pageSize: 10 },
|
|
65
|
-
// Axios config, see https://axios-http.com
|
|
66
|
-
config: { headers: {} },
|
|
67
|
-
// lifecycle
|
|
68
|
-
onBefore(refs) {
|
|
69
|
-
const { data, loading, error, uploadProgress, downloadProgress } = refs
|
|
70
|
-
console.log(
|
|
71
|
-
data.value,
|
|
72
|
-
loading.value,
|
|
73
|
-
error.value,
|
|
74
|
-
uploadProgress.value,
|
|
75
|
-
downloadProgress.value
|
|
76
|
-
)
|
|
77
|
-
// Do request before
|
|
78
|
-
},
|
|
79
|
-
onTransform(response, refs) {
|
|
80
|
-
// Handle data transform
|
|
81
|
-
return response.data
|
|
82
|
-
},
|
|
83
|
-
onSuccess(response, refs) {
|
|
84
|
-
// Do request success
|
|
85
|
-
},
|
|
86
|
-
onError(error, refs) {
|
|
87
|
-
// Do request error
|
|
88
|
-
},
|
|
89
|
-
onAfter(refs) {
|
|
90
|
-
// Do request after
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
</script>
|
|
94
|
-
|
|
95
|
-
<template>
|
|
96
|
-
<span>{{ users }}</span>
|
|
97
|
-
<span>{{ loading }}</span>
|
|
98
|
-
<span>{{ error }}</span>
|
|
99
|
-
<span>{{ uploadProgress }}</span>
|
|
100
|
-
<span>{{ downloadProgress }}</span>
|
|
101
|
-
<button @click="getUsers">Send Request</button>
|
|
102
|
-
</template>
|
|
103
|
-
```
|
|
104
|
-
|
|
105
38
|
### Config
|
|
106
39
|
|
|
107
40
|
Axle fully supports all configuration abilities of axios.
|
|
@@ -240,12 +173,14 @@ axios.post('/url', formData, {
|
|
|
240
173
|
axle.postMultipart('/url', { name: 'foo', file: new File() })
|
|
241
174
|
```
|
|
242
175
|
|
|
243
|
-
|
|
176
|
+
## Utils
|
|
244
177
|
|
|
245
178
|
#### Notify the browser to download the file
|
|
246
179
|
|
|
247
180
|
```js
|
|
248
|
-
|
|
181
|
+
import { download } from '@varlet/axle'
|
|
182
|
+
|
|
183
|
+
download(await axle.getBlob('/url', { id: 1 }), 'filename')
|
|
249
184
|
```
|
|
250
185
|
|
|
251
186
|
#### Common Header Operate
|
|
@@ -256,6 +191,125 @@ axle.setHeader('TOKEN', TOKEN)
|
|
|
256
191
|
axle.removeHeader('TOKEN')
|
|
257
192
|
```
|
|
258
193
|
|
|
194
|
+
## Vue Composition API
|
|
195
|
+
|
|
196
|
+
Axle provides the usage of Vue Composition API style, which encapsulates the `loading status`, `error status`, `upload and download progress` of the request, `return data`, `error retry`, `lifecycle`, etc., And inherit all the configuration of `axios`.
|
|
197
|
+
|
|
198
|
+
```html
|
|
199
|
+
<script setup>
|
|
200
|
+
import { createAxle } from '@varlet/axle'
|
|
201
|
+
import { createUseAxle } from '@varlet/axle/use'
|
|
202
|
+
|
|
203
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
204
|
+
const useAxle = createUseAxle()
|
|
205
|
+
|
|
206
|
+
const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abort }] = useAxle({
|
|
207
|
+
// Request initial data
|
|
208
|
+
data: [],
|
|
209
|
+
// Request runner
|
|
210
|
+
runner: axle.get,
|
|
211
|
+
// Request url
|
|
212
|
+
url: '/user',
|
|
213
|
+
// Whether to send the request immediately, defaults false
|
|
214
|
+
immediate: true,
|
|
215
|
+
// The number of retries after a failed request, defaults 0
|
|
216
|
+
retry: 3,
|
|
217
|
+
// Request params, defaults {}
|
|
218
|
+
params: { current: 1, pageSize: 10 },
|
|
219
|
+
// Axios config, see https://axios-http.com
|
|
220
|
+
config: { headers: {} },
|
|
221
|
+
// lifecycle
|
|
222
|
+
onBefore(refs) {
|
|
223
|
+
const { data, loading, error, uploadProgress, downloadProgress } = refs
|
|
224
|
+
console.log(
|
|
225
|
+
data.value,
|
|
226
|
+
loading.value,
|
|
227
|
+
error.value,
|
|
228
|
+
uploadProgress.value,
|
|
229
|
+
downloadProgress.value
|
|
230
|
+
)
|
|
231
|
+
// Do request before
|
|
232
|
+
},
|
|
233
|
+
onTransform(response, refs) {
|
|
234
|
+
// Handle data transform, The transformed data will be the value of users.
|
|
235
|
+
return response.data
|
|
236
|
+
},
|
|
237
|
+
onSuccess(response, refs) {
|
|
238
|
+
// Do request success
|
|
239
|
+
},
|
|
240
|
+
onError(error, refs) {
|
|
241
|
+
// Do request error
|
|
242
|
+
},
|
|
243
|
+
onAfter(refs) {
|
|
244
|
+
// Do request after
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
</script>
|
|
248
|
+
|
|
249
|
+
<template>
|
|
250
|
+
<span>{{ users }}</span>
|
|
251
|
+
<span>{{ loading }}</span>
|
|
252
|
+
<span>{{ error }}</span>
|
|
253
|
+
<span>{{ uploadProgress }}</span>
|
|
254
|
+
<span>{{ downloadProgress }}</span>
|
|
255
|
+
<button @click="getUsers">Send Request</button>
|
|
256
|
+
<button @click="abort">Abort Request</button>
|
|
257
|
+
</template>
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Parallel Utils
|
|
261
|
+
|
|
262
|
+
Axle provides some parallel request processing tools, please refer to the following examples.
|
|
263
|
+
|
|
264
|
+
```html
|
|
265
|
+
<script setup>
|
|
266
|
+
import { createAxle } from '@varlet/axle'
|
|
267
|
+
import { createUseAxle, useAllData, useAverageProgress, useHasLoading } from '@varlet/axle/use'
|
|
268
|
+
|
|
269
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
270
|
+
const useAxle = createUseAxle()
|
|
271
|
+
|
|
272
|
+
const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
|
|
273
|
+
data: [],
|
|
274
|
+
runner: axle.get,
|
|
275
|
+
url: '/user',
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
|
|
279
|
+
data: [],
|
|
280
|
+
runner: axle.get,
|
|
281
|
+
url: '/role',
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
// At the end of all requests, loading is false
|
|
285
|
+
const loading = useHasLoading(isUsersLoading, isRolesLoading)
|
|
286
|
+
// At the end of all requests, downloadProgress is 1
|
|
287
|
+
const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
|
|
288
|
+
// Ref<[
|
|
289
|
+
// [{ name: 'foo' }, { name: 'bar' }],
|
|
290
|
+
// [{ role: 'admin' }, { role: 'user' }]
|
|
291
|
+
// ]> <-
|
|
292
|
+
// [
|
|
293
|
+
// Ref<[{ name: 'foo' }, { name: 'bar' }]>,
|
|
294
|
+
// Ref<[{ role: 'admin' }, { role: 'user' }]>
|
|
295
|
+
// ]
|
|
296
|
+
const usersRoles = useAllData(users, roles)
|
|
297
|
+
|
|
298
|
+
function sendAllRequest() {
|
|
299
|
+
// parallel
|
|
300
|
+
getUsers()
|
|
301
|
+
getRoles()
|
|
302
|
+
}
|
|
303
|
+
</script>
|
|
304
|
+
|
|
305
|
+
<template>
|
|
306
|
+
<span>{{ usersRoles }}</span>
|
|
307
|
+
<span>{{ loading }}</span>
|
|
308
|
+
<span>{{ downloadProgress }}</span>
|
|
309
|
+
<button @click="sendAllRequest">Send All Request</button>
|
|
310
|
+
</template>
|
|
311
|
+
```
|
|
312
|
+
|
|
259
313
|
|
|
260
314
|
|
|
261
315
|
|
package/README.zh-CN.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
<a href="https://github.com/varletjs/axle/blob/
|
|
1
|
+
<a href="https://github.com/varletjs/axle/blob/main/README.md">English</a> |
|
|
2
2
|
<span>中文</span>
|
|
3
3
|
|
|
4
|
-
---
|
|
5
|
-
|
|
6
4
|
### 介绍
|
|
7
5
|
|
|
8
6
|
基于 [axios](https://axios-http.com/) 的渐进式请求工具。 它不会破坏 `axios` 原有的能力,帮助您更轻松地处理请求。
|
|
@@ -37,71 +35,6 @@ axle.get('/url', { current: 1, pageSize: 10 }, { headers: {} })
|
|
|
37
35
|
axle.post('/url', { name: 'Axle' }, { headers: {} })
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
#### Vue 组合式 API
|
|
41
|
-
|
|
42
|
-
Axle 提供了 Vue Composition API 风格的用法,封装了请求的 `加载状态`, `错误状态`, `请求的上下行进度`,`返回数据`,`错误重试`,`生命周期` 等等,并继承了 `axios` 的所有配置。
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<script setup>
|
|
46
|
-
import { createAxle } from '@varlet/axle'
|
|
47
|
-
import { createUseAxle } from '@varlet/axle/use'
|
|
48
|
-
|
|
49
|
-
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
50
|
-
const useAxle = createUseAxle()
|
|
51
|
-
|
|
52
|
-
const [users, getUsers, { loading, error, uploadProgress, downloadProgress }] = useAxle({
|
|
53
|
-
// 请求初始化数据
|
|
54
|
-
data: [],
|
|
55
|
-
// 请求函数
|
|
56
|
-
runner: axle.get,
|
|
57
|
-
// 请求地址
|
|
58
|
-
url: '/user',
|
|
59
|
-
// 是否立即发送请求, 默认值: false
|
|
60
|
-
immediate: true,
|
|
61
|
-
// 错误重试次数, 默认值: 0
|
|
62
|
-
retry: 3,
|
|
63
|
-
// 请求参数, 默认值: {}
|
|
64
|
-
params: { current: 1, pageSize: 10 },
|
|
65
|
-
// Axios 配置, see https://axios-http.com
|
|
66
|
-
config: { headers: {} },
|
|
67
|
-
// 生命周期
|
|
68
|
-
onBefore(refs) {
|
|
69
|
-
const { data, loading, error, uploadProgress, downloadProgress } = refs
|
|
70
|
-
console.log(
|
|
71
|
-
data.value,
|
|
72
|
-
loading.value,
|
|
73
|
-
error.value,
|
|
74
|
-
uploadProgress.value,
|
|
75
|
-
downloadProgress.value
|
|
76
|
-
)
|
|
77
|
-
// 处理请求前逻辑
|
|
78
|
-
},
|
|
79
|
-
onTransform(response, refs) {
|
|
80
|
-
// 处理数据转换,转换后的数据将成为 users 的值。
|
|
81
|
-
return response.data
|
|
82
|
-
},
|
|
83
|
-
onSuccess(response, refs) {
|
|
84
|
-
// 处理请求成功逻辑
|
|
85
|
-
},
|
|
86
|
-
onError(error, refs) {
|
|
87
|
-
// 处理请求错误逻辑
|
|
88
|
-
},
|
|
89
|
-
onAfter(refs) {
|
|
90
|
-
// 处理请求结束逻辑,无论成功失败都会触发。
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
</script>
|
|
94
|
-
|
|
95
|
-
<template>
|
|
96
|
-
<span>{{ users }}</span>
|
|
97
|
-
<span>{{ loading }}</span>
|
|
98
|
-
<span>{{ error }}</span>
|
|
99
|
-
<span>{{ uploadProgress }}</span>
|
|
100
|
-
<span>{{ downloadProgress }}</span>
|
|
101
|
-
<button @click="getUsers">发送请求</button>
|
|
102
|
-
</template>
|
|
103
|
-
```
|
|
104
|
-
|
|
105
38
|
### 配置
|
|
106
39
|
|
|
107
40
|
`Axle` 完全支持 `axios` 的所有配置能力。
|
|
@@ -240,12 +173,14 @@ axios.post('/url', formData, {
|
|
|
240
173
|
axle.postMultipart('/url', { name: 'foo', file: new File() })
|
|
241
174
|
```
|
|
242
175
|
|
|
243
|
-
|
|
176
|
+
## 实用工具
|
|
244
177
|
|
|
245
178
|
#### 通知浏览器下载文件
|
|
246
179
|
|
|
247
180
|
```js
|
|
248
|
-
|
|
181
|
+
import { download } from '@varlet/axle'
|
|
182
|
+
|
|
183
|
+
download(await axle.getBlob('/url', { id: 1 }), 'filename')
|
|
249
184
|
```
|
|
250
185
|
|
|
251
186
|
#### 公共 header 操作
|
|
@@ -256,6 +191,125 @@ axle.setHeader('TOKEN', TOKEN)
|
|
|
256
191
|
axle.removeHeader('TOKEN')
|
|
257
192
|
```
|
|
258
193
|
|
|
194
|
+
## Vue 组合式 API
|
|
195
|
+
|
|
196
|
+
Axle 提供了 Vue Composition API 风格的用法,封装了请求的 `加载状态`, `错误状态`, `请求的上下行进度`,`返回数据`,`错误重试`,`生命周期` 等等,并继承了 `axios` 的所有配置。
|
|
197
|
+
|
|
198
|
+
```html
|
|
199
|
+
<script setup>
|
|
200
|
+
import { createAxle } from '@varlet/axle'
|
|
201
|
+
import { createUseAxle } from '@varlet/axle/use'
|
|
202
|
+
|
|
203
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
204
|
+
const useAxle = createUseAxle()
|
|
205
|
+
|
|
206
|
+
const [users, getUsers, { loading, error, uploadProgress, downloadProgress, abort }] = useAxle({
|
|
207
|
+
// 请求初始化数据
|
|
208
|
+
data: [],
|
|
209
|
+
// 请求函数
|
|
210
|
+
runner: axle.get,
|
|
211
|
+
// 请求地址
|
|
212
|
+
url: '/user',
|
|
213
|
+
// 是否立即发送请求, 默认值: false
|
|
214
|
+
immediate: true,
|
|
215
|
+
// 错误重试次数, 默认值: 0
|
|
216
|
+
retry: 3,
|
|
217
|
+
// 请求参数, 默认值: {}
|
|
218
|
+
params: { current: 1, pageSize: 10 },
|
|
219
|
+
// Axios 配置, see https://axios-http.com
|
|
220
|
+
config: { headers: {} },
|
|
221
|
+
// 生命周期
|
|
222
|
+
onBefore(refs) {
|
|
223
|
+
const { data, loading, error, uploadProgress, downloadProgress } = refs
|
|
224
|
+
console.log(
|
|
225
|
+
data.value,
|
|
226
|
+
loading.value,
|
|
227
|
+
error.value,
|
|
228
|
+
uploadProgress.value,
|
|
229
|
+
downloadProgress.value
|
|
230
|
+
)
|
|
231
|
+
// 处理请求前逻辑
|
|
232
|
+
},
|
|
233
|
+
onTransform(response, refs) {
|
|
234
|
+
// 处理数据转换,转换后的数据将成为 users 的值。
|
|
235
|
+
return response.data
|
|
236
|
+
},
|
|
237
|
+
onSuccess(response, refs) {
|
|
238
|
+
// 处理请求成功逻辑
|
|
239
|
+
},
|
|
240
|
+
onError(error, refs) {
|
|
241
|
+
// 处理请求错误逻辑
|
|
242
|
+
},
|
|
243
|
+
onAfter(refs) {
|
|
244
|
+
// 处理请求结束逻辑,无论成功失败都会触发。
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
</script>
|
|
248
|
+
|
|
249
|
+
<template>
|
|
250
|
+
<span>{{ users }}</span>
|
|
251
|
+
<span>{{ loading }}</span>
|
|
252
|
+
<span>{{ error }}</span>
|
|
253
|
+
<span>{{ uploadProgress }}</span>
|
|
254
|
+
<span>{{ downloadProgress }}</span>
|
|
255
|
+
<button @click="getUsers">发送请求</button>
|
|
256
|
+
<button @click="abort">中断请求</button>
|
|
257
|
+
</template>
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### 并行请求实用工具
|
|
261
|
+
|
|
262
|
+
Axle 提供了一些并行请求处理工具,请参考以下示例。
|
|
263
|
+
|
|
264
|
+
```html
|
|
265
|
+
<script setup>
|
|
266
|
+
import { createAxle } from '@varlet/axle'
|
|
267
|
+
import { createUseAxle, useAllData, useAverageProgress, useHasLoading } from '@varlet/axle/use'
|
|
268
|
+
|
|
269
|
+
const axle = createAxle(/** @see https://axios-http.com **/)
|
|
270
|
+
const useAxle = createUseAxle()
|
|
271
|
+
|
|
272
|
+
const [users, getUsers, { loading: isUsersLoading, downloadProgress: usersDownloadProgress }] = useAxle({
|
|
273
|
+
data: [],
|
|
274
|
+
runner: axle.get,
|
|
275
|
+
url: '/user',
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
const [roles, getRoles, { loading: isRolesLoading, downloadProgress: rolesDownloadProgress }] = useAxle({
|
|
279
|
+
data: [],
|
|
280
|
+
runner: axle.get,
|
|
281
|
+
url: '/role',
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
// 所有请求结束时,loading 为 false
|
|
285
|
+
const loading = useHasLoading(isUsersLoading, isRolesLoading)
|
|
286
|
+
// 所有请求结束时,downloadProgress 为 1
|
|
287
|
+
const downloadProgress = useAverageProgress(usersDownloadProgress, rolesDownloadProgress)
|
|
288
|
+
// Ref<[
|
|
289
|
+
// [{ name: 'foo' }, { name: 'bar' }],
|
|
290
|
+
// [{ role: 'admin' }, { role: 'user' }]
|
|
291
|
+
// ]> <-
|
|
292
|
+
// [
|
|
293
|
+
// Ref<[{ name: 'foo' }, { name: 'bar' }]>,
|
|
294
|
+
// Ref<[{ role: 'admin' }, { role: 'user' }]>
|
|
295
|
+
// ]
|
|
296
|
+
const usersRoles = useAllData(users, roles)
|
|
297
|
+
|
|
298
|
+
function sendAllRequest() {
|
|
299
|
+
// parallel
|
|
300
|
+
getUsers()
|
|
301
|
+
getRoles()
|
|
302
|
+
}
|
|
303
|
+
</script>
|
|
304
|
+
|
|
305
|
+
<template>
|
|
306
|
+
<span>{{ usersRoles }}</span>
|
|
307
|
+
<span>{{ loading }}</span>
|
|
308
|
+
<span>{{ downloadProgress }}</span>
|
|
309
|
+
<button @click="sendAllRequest">发送全部请求</button>
|
|
310
|
+
</template>
|
|
311
|
+
```
|
|
312
|
+
|
|
259
313
|
|
|
260
314
|
|
|
261
315
|
|
package/es/instance.d.ts
CHANGED
|
@@ -40,7 +40,6 @@ export type AxleInstance = {
|
|
|
40
40
|
patch: ModifyHelper;
|
|
41
41
|
patchUrlEncode: ModifyHelper;
|
|
42
42
|
patchMultipart: ModifyHelper;
|
|
43
|
-
download(blob: string | Blob, filename: string): void;
|
|
44
43
|
getHeaders(): HeadersDefaults['common'];
|
|
45
44
|
setHeader(key: string, value: string): void;
|
|
46
45
|
removeHeader(key: string | string[]): void;
|
package/es/instance.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import qs from 'qs';
|
|
3
|
+
import { inBrowser } from '@varlet/shared';
|
|
3
4
|
export function createFetchHelper(service, method, responseType) {
|
|
4
5
|
return function (url, params, config) {
|
|
5
6
|
return service[method](url, Object.assign({ params,
|
|
@@ -22,6 +23,9 @@ export function createModifyHelper(service, method, contentType) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
export function download(url, filename) {
|
|
26
|
+
if (!inBrowser()) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
25
29
|
const a = document.createElement('a');
|
|
26
30
|
a.download = filename;
|
|
27
31
|
a.style.display = 'none';
|
|
@@ -81,7 +85,6 @@ export function createAxle(config = {}) {
|
|
|
81
85
|
patch: createModifyHelper(service, 'patch', 'application/json'),
|
|
82
86
|
patchUrlEncode: createModifyHelper(service, 'patch', 'application/x-www-form-urlencoded'),
|
|
83
87
|
patchMultipart: createModifyHelper(service, 'patch', 'multipart/form-data'),
|
|
84
|
-
download,
|
|
85
88
|
getHeaders,
|
|
86
89
|
setHeader,
|
|
87
90
|
removeHeader,
|
package/es/use.d.ts
CHANGED
|
@@ -43,3 +43,6 @@ export interface CreateUseAxleOptions {
|
|
|
43
43
|
onTransform?(response: any, refs: any): any;
|
|
44
44
|
}
|
|
45
45
|
export declare function createUseAxle(options?: CreateUseAxleOptions): <D = any, R = any, P = Record<string, any>>(options: UseAxleOptions<D, R, P>) => UseAxleInstance<D, R, P>;
|
|
46
|
+
export * from './useAllData.js';
|
|
47
|
+
export * from './useHasLoading.js';
|
|
48
|
+
export * from './useAverageProgress.js';
|
package/es/use.js
CHANGED
|
@@ -16,7 +16,7 @@ export function createUseAxle(options = {}) {
|
|
|
16
16
|
loading,
|
|
17
17
|
error,
|
|
18
18
|
downloadProgress,
|
|
19
|
-
uploadProgress
|
|
19
|
+
uploadProgress,
|
|
20
20
|
};
|
|
21
21
|
let controller = new AbortController();
|
|
22
22
|
const run = async (options = {}) => {
|
|
@@ -81,3 +81,6 @@ export function createUseAxle(options = {}) {
|
|
|
81
81
|
};
|
|
82
82
|
return useAxle;
|
|
83
83
|
}
|
|
84
|
+
export * from './useAllData.js';
|
|
85
|
+
export * from './useHasLoading.js';
|
|
86
|
+
export * from './useAverageProgress.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useAllData<DC extends any[]>(...dataCollection: DC): import("vue").WritableComputedRef<any[]>;
|
package/es/useAllData.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
export function useAllData(...dataCollection) {
|
|
3
|
+
return computed({
|
|
4
|
+
get: () => dataCollection.map((data) => data.value),
|
|
5
|
+
set(values) {
|
|
6
|
+
dataCollection.forEach((data, index) => {
|
|
7
|
+
data.value = values[index];
|
|
8
|
+
});
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ref, watch } from "vue";
|
|
2
|
+
export function useAverageProgress(...progressCollection) {
|
|
3
|
+
const averageProgress = ref(0);
|
|
4
|
+
watch(() => progressCollection.map(progress => progress.value), (newProgressCollection) => {
|
|
5
|
+
const total = newProgressCollection.reduce((total, progress) => total + progress, 0);
|
|
6
|
+
averageProgress.value = total / progressCollection.length;
|
|
7
|
+
}, { immediate: true });
|
|
8
|
+
return averageProgress;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ref, watch } from "vue";
|
|
2
|
+
export function useHasLoading(...loadings) {
|
|
3
|
+
const hasLoading = ref(false);
|
|
4
|
+
watch(() => loadings.map(loading => loading.value), (newLoadings) => {
|
|
5
|
+
hasLoading.value = newLoadings.some(Boolean);
|
|
6
|
+
}, { immediate: true });
|
|
7
|
+
return hasLoading;
|
|
8
|
+
}
|