@netang/quasar 0.1.57 → 0.1.59
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/components/empty/index.vue +80 -71
- package/components/power-page/index.vue +94 -92
- package/components/uploader/index.vue +186 -158
- package/components/uploader-query/index.vue +757 -758
- package/package.json +2 -3
- package/utils/uploader.js +139 -37
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netang/quasar",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.59",
|
|
4
4
|
"description": "netang-quasar",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
-
"publish": "npm publish --access public"
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
7
|
},
|
|
9
8
|
"repository": {
|
|
10
9
|
"type": "git",
|
package/utils/uploader.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, isRef } from 'vue'
|
|
1
|
+
import { ref, isRef, watch } from 'vue'
|
|
2
2
|
import SparkMD5 from 'spark-md5'
|
|
3
3
|
|
|
4
4
|
import $n_has from 'lodash/has'
|
|
@@ -94,6 +94,9 @@ function create(options) {
|
|
|
94
94
|
confirm: false,
|
|
95
95
|
}, $n_get(options, 'props'))
|
|
96
96
|
|
|
97
|
+
// options 中是否存在 props.modelValue
|
|
98
|
+
const hasPropsModelValue = $n_has(options, 'props.modelValue')
|
|
99
|
+
|
|
97
100
|
// 上传文件列表
|
|
98
101
|
const uploadFileLists = $n_has(options, 'uploadFileLists') && isRef(options.uploadFileLists) ? options.uploadFileLists : ref([])
|
|
99
102
|
|
|
@@ -135,6 +138,13 @@ function create(options) {
|
|
|
135
138
|
/**
|
|
136
139
|
* 监听上传文件列表
|
|
137
140
|
*/
|
|
141
|
+
// if (props.watchModelValue && hasPropsModelValue) {
|
|
142
|
+
// watch(()=>options.props.modelValue, function() {
|
|
143
|
+
// // 初始化上传列表
|
|
144
|
+
// initUploadFileLists()
|
|
145
|
+
// .finally()
|
|
146
|
+
// })
|
|
147
|
+
// }
|
|
138
148
|
|
|
139
149
|
// ==========【方法】=================================================================================================
|
|
140
150
|
|
|
@@ -190,49 +200,127 @@ function create(options) {
|
|
|
190
200
|
* 初始化上传列表
|
|
191
201
|
*/
|
|
192
202
|
async function initUploadFileLists() {
|
|
193
|
-
if ($n_isRequired(props.modelValue)) {
|
|
194
|
-
|
|
195
|
-
// 获取值数组
|
|
196
|
-
const hashs = props.valueArray ? props.modelValue : $n_split(props.modelValue, ',')
|
|
197
|
-
|
|
198
|
-
// 如果类型不是图片 || 初始加载文件信息, 则请求文件信息
|
|
199
|
-
if (props.type !== 'image' || props.loadInfo) {
|
|
200
|
-
|
|
201
|
-
// 请求 - 获取文件
|
|
202
|
-
const { status, data: resExisted } = await $n_http({
|
|
203
|
-
url: $n_config('apiFileUrl') + 'get_file',
|
|
204
|
-
data: {
|
|
205
|
-
hashs,
|
|
206
|
-
},
|
|
207
|
-
// 关闭错误
|
|
208
|
-
warn: false,
|
|
209
|
-
})
|
|
210
|
-
if (status) {
|
|
211
203
|
|
|
212
|
-
|
|
204
|
+
const modelValue = hasPropsModelValue ? options.props.modelValue : props.modelValue
|
|
213
205
|
|
|
214
|
-
|
|
215
|
-
|
|
206
|
+
if (! $n_isRequired(modelValue)) {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
216
209
|
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
// 值数组
|
|
211
|
+
const hashs = []
|
|
219
212
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
213
|
+
// hash all
|
|
214
|
+
const hashAll = {}
|
|
215
|
+
|
|
216
|
+
// 新上传文件列表
|
|
217
|
+
const newUploadFileLists = []
|
|
218
|
+
|
|
219
|
+
// 获取值数组
|
|
220
|
+
const lists = props.valueArray ? modelValue : $n_split(modelValue, ',')
|
|
221
|
+
|
|
222
|
+
// 新列表
|
|
223
|
+
const newLists = []
|
|
224
|
+
|
|
225
|
+
// 是否更新
|
|
226
|
+
let isUpdate = false
|
|
227
|
+
|
|
228
|
+
// 合并当前上传列表中未上传成功的文件
|
|
229
|
+
for (const fileItem of uploadFileLists.value) {
|
|
230
|
+
if (fileItem.status !== UPLOAD_STATUS.success) {
|
|
231
|
+
newUploadFileLists.push(fileItem)
|
|
232
|
+
hashAll[fileItem.hash] = fileItem
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
$n_forEach(lists, function(hash) {
|
|
237
|
+
if ($n_isValidString(hash)) {
|
|
238
|
+
|
|
239
|
+
const hasItem = $n_find(uploadFileLists.value, { hash })
|
|
240
|
+
|
|
241
|
+
// 如果在当前上传文件列表中已存在
|
|
242
|
+
if (hasItem) {
|
|
243
|
+
hashAll[hash] = hasItem
|
|
244
|
+
|
|
245
|
+
} else if (! $n_has(hashAll, 'hash')) {
|
|
246
|
+
|
|
247
|
+
// 如果是 http(s):// 开头的地址
|
|
248
|
+
if (/^http(s)?:\/\//i.test(hash)) {
|
|
249
|
+
hashs.push(hash)
|
|
250
|
+
hashAll[hash] = {
|
|
251
|
+
hash,
|
|
252
|
+
isNet: true,
|
|
253
|
+
}
|
|
225
254
|
|
|
226
|
-
//
|
|
227
|
-
|
|
255
|
+
// 否则为 hash 文件
|
|
256
|
+
} else {
|
|
257
|
+
hashs.push(hash)
|
|
258
|
+
hashAll[hash] = {
|
|
259
|
+
hash,
|
|
260
|
+
isNet: false,
|
|
261
|
+
}
|
|
262
|
+
}
|
|
228
263
|
}
|
|
229
|
-
|
|
264
|
+
|
|
265
|
+
// 新列表
|
|
266
|
+
newLists.push(hash)
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
// 如果类型不是图片 || 初始加载文件信息, 则请求文件信息
|
|
271
|
+
if (
|
|
272
|
+
(props.type !== 'image' || props.loadInfo)
|
|
273
|
+
&& hashs.length
|
|
274
|
+
) {
|
|
275
|
+
// 请求 - 获取文件
|
|
276
|
+
const { status, data: resExisted } = await $n_http({
|
|
277
|
+
url: $n_config('apiFileUrl') + 'get_file',
|
|
278
|
+
data: {
|
|
279
|
+
hashs: $n_uniq(hashs),
|
|
280
|
+
},
|
|
281
|
+
// 关闭错误
|
|
282
|
+
warn: false,
|
|
283
|
+
})
|
|
284
|
+
if (status) {
|
|
285
|
+
|
|
286
|
+
$n_forEach(resExisted, function (existedItem) {
|
|
287
|
+
|
|
288
|
+
// 创建原始单个文件
|
|
289
|
+
const fileItem = createRawFileItem()
|
|
290
|
+
|
|
291
|
+
// 设置已存在文件
|
|
292
|
+
setExistedFileItem(fileItem, existedItem)
|
|
293
|
+
|
|
294
|
+
// 添加至 hash all
|
|
295
|
+
hashAll[fileItem.hash] = Object.assign(fileItem, {
|
|
296
|
+
key: fileItem.hash,
|
|
297
|
+
})
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
// 需要更新
|
|
301
|
+
isUpdate = true
|
|
230
302
|
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
for (const hash of newLists) {
|
|
306
|
+
|
|
307
|
+
let hasItem = hashAll[hash]
|
|
308
|
+
|
|
309
|
+
// 如果该 hash 已存在
|
|
310
|
+
if ($n_has(hasItem, 'id')) {
|
|
231
311
|
|
|
232
|
-
|
|
312
|
+
// 如果新列表中存在 该 id
|
|
313
|
+
if ($n_findIndex(newUploadFileLists, { id: hasItem.id }) > -1) {
|
|
314
|
+
|
|
315
|
+
// 更新 id
|
|
316
|
+
hasItem = Object.assign({}, hasItem, {
|
|
317
|
+
id: ++_fileNum
|
|
318
|
+
})
|
|
319
|
+
}
|
|
233
320
|
|
|
234
|
-
|
|
235
|
-
|
|
321
|
+
// 否则该 hash 不存在
|
|
322
|
+
} else {
|
|
323
|
+
hasItem = Object.assign(createRawFileItem(), hasItem, {
|
|
236
324
|
// 文件唯一 key
|
|
237
325
|
key: hash,
|
|
238
326
|
// hash
|
|
@@ -243,8 +331,20 @@ function create(options) {
|
|
|
243
331
|
progress: 100,
|
|
244
332
|
// 信息
|
|
245
333
|
msg: '',
|
|
246
|
-
})
|
|
247
|
-
|
|
334
|
+
})
|
|
335
|
+
hashAll[hash] = hasItem
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// 添加至新列表中
|
|
339
|
+
newUploadFileLists.push(hasItem)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 更新上传文件列表
|
|
343
|
+
uploadFileLists.value = newUploadFileLists
|
|
344
|
+
|
|
345
|
+
if (isUpdate) {
|
|
346
|
+
// 更新
|
|
347
|
+
update()
|
|
248
348
|
}
|
|
249
349
|
}
|
|
250
350
|
|
|
@@ -785,6 +885,8 @@ function create(options) {
|
|
|
785
885
|
progress: 0,
|
|
786
886
|
// 信息
|
|
787
887
|
msg: '待上传',
|
|
888
|
+
// 是否为网络文件
|
|
889
|
+
isNet: false,
|
|
788
890
|
// 中断上传
|
|
789
891
|
abort() {},
|
|
790
892
|
}
|