@netang/quasar 0.2.61 → 0.2.64
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/uploader/index.vue +7 -0
- package/package.json +1 -1
- package/utils/uploader.js +117 -38
|
@@ -69,6 +69,11 @@ export default {
|
|
|
69
69
|
confirm: Boolean,
|
|
70
70
|
// 提交时上传网络外链文件
|
|
71
71
|
submitUploadNet: Boolean,
|
|
72
|
+
// 是否必须登录
|
|
73
|
+
login: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: true,
|
|
76
|
+
},
|
|
72
77
|
},
|
|
73
78
|
|
|
74
79
|
/**
|
|
@@ -109,6 +114,8 @@ export default {
|
|
|
109
114
|
type: props.type,
|
|
110
115
|
// 声明属性
|
|
111
116
|
props,
|
|
117
|
+
// 是否必须登录
|
|
118
|
+
login: props.login,
|
|
112
119
|
// 上传文件输入框节点
|
|
113
120
|
fileRef,
|
|
114
121
|
// 上传文件列表
|
package/package.json
CHANGED
package/utils/uploader.js
CHANGED
|
@@ -125,6 +125,8 @@ function create(options) {
|
|
|
125
125
|
onUpdateModelValue,
|
|
126
126
|
// 更新方法
|
|
127
127
|
onUpdate,
|
|
128
|
+
// 是否必须登录
|
|
129
|
+
login: isLogin,
|
|
128
130
|
|
|
129
131
|
} = Object.assign({
|
|
130
132
|
// 上传器类型
|
|
@@ -133,6 +135,8 @@ function create(options) {
|
|
|
133
135
|
onUpdateModelValue: null,
|
|
134
136
|
// 更新方法
|
|
135
137
|
onUpdate: null,
|
|
138
|
+
// 是否必须登录
|
|
139
|
+
login: true,
|
|
136
140
|
}, options)
|
|
137
141
|
|
|
138
142
|
const optionsProps = $n_get(options, 'props')
|
|
@@ -323,8 +327,21 @@ function create(options) {
|
|
|
323
327
|
|
|
324
328
|
} else if (! $n_has(hashAll, 'hash')) {
|
|
325
329
|
|
|
330
|
+
// 如果是 data: 开头的地址
|
|
331
|
+
if (/^data:/i.test(hash)) {
|
|
332
|
+
const __img = hash
|
|
333
|
+
const fileItem = base64ToFileItem(hash)
|
|
334
|
+
hash = fileItem.hash
|
|
335
|
+
hashs.push(hash)
|
|
336
|
+
hashAll[hash] = Object.assign({
|
|
337
|
+
__img,
|
|
338
|
+
isBase64: true,
|
|
339
|
+
isNet: true,
|
|
340
|
+
isNetUploaded: false,
|
|
341
|
+
}, fileItem)
|
|
342
|
+
|
|
326
343
|
// 如果是外链
|
|
327
|
-
if (/^http(s)?:\/\//i.test(hash)) {
|
|
344
|
+
} else if (/^http(s)?:\/\//i.test(hash)) {
|
|
328
345
|
hashs.push(hash)
|
|
329
346
|
hashAll[hash] = {
|
|
330
347
|
hash,
|
|
@@ -359,6 +376,8 @@ function create(options) {
|
|
|
359
376
|
data: {
|
|
360
377
|
hashs: $n_uniq(hashs),
|
|
361
378
|
},
|
|
379
|
+
// 是否需要登录
|
|
380
|
+
token: isLogin,
|
|
362
381
|
// 关闭错误
|
|
363
382
|
warn: false,
|
|
364
383
|
// 关闭防抖(可以重复请求)
|
|
@@ -526,6 +545,83 @@ function create(options) {
|
|
|
526
545
|
// }
|
|
527
546
|
// }
|
|
528
547
|
|
|
548
|
+
function getBlobExt(blob) {
|
|
549
|
+
// 后缀名
|
|
550
|
+
let ext = ''
|
|
551
|
+
|
|
552
|
+
if (blob.type) {
|
|
553
|
+
|
|
554
|
+
// 如果为图片
|
|
555
|
+
if (
|
|
556
|
+
props.type === 'image'
|
|
557
|
+
|| $n_indexOf(blob.type, 'image/') > -1
|
|
558
|
+
) {
|
|
559
|
+
switch (blob.type) {
|
|
560
|
+
case 'image/png':
|
|
561
|
+
ext = 'png'
|
|
562
|
+
break
|
|
563
|
+
case 'image/gif':
|
|
564
|
+
ext = 'gif'
|
|
565
|
+
break
|
|
566
|
+
default:
|
|
567
|
+
ext = 'jpg'
|
|
568
|
+
break
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// 如果为视频
|
|
572
|
+
} else if (props.type === 'video') {
|
|
573
|
+
ext = 'mp4'
|
|
574
|
+
|
|
575
|
+
// 如果为音频
|
|
576
|
+
} else if (props.type === 'audio') {
|
|
577
|
+
ext = 'mp3'
|
|
578
|
+
|
|
579
|
+
// 否则为文件
|
|
580
|
+
} else {
|
|
581
|
+
const arr = $n_split(props.type, '/')
|
|
582
|
+
if (arr.length > 0) {
|
|
583
|
+
ext = arr[1]
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return ext
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function base64ToFileItem(value) {
|
|
592
|
+
const arr = value.split(',')
|
|
593
|
+
const mime = arr[0].match(/:(.*?);/)[1]
|
|
594
|
+
const bstr = atob(arr[1])
|
|
595
|
+
let n = bstr.length
|
|
596
|
+
const arrayBuffer = new Uint8Array(n)
|
|
597
|
+
while (n--) {
|
|
598
|
+
arrayBuffer[n] = bstr.charCodeAt(n)
|
|
599
|
+
}
|
|
600
|
+
const blob = new Blob([arrayBuffer], { type: mime })
|
|
601
|
+
|
|
602
|
+
// 初始化 SparkMD5
|
|
603
|
+
const spark = new SparkMD5.ArrayBuffer()
|
|
604
|
+
spark.append(arrayBuffer)
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
const title = String($n_timestamp())
|
|
608
|
+
|
|
609
|
+
const file = new File([blob], title, { type: blob.type })
|
|
610
|
+
const ext = getBlobExt(blob)
|
|
611
|
+
|
|
612
|
+
const {
|
|
613
|
+
size,
|
|
614
|
+
} = file
|
|
615
|
+
|
|
616
|
+
return {
|
|
617
|
+
file,
|
|
618
|
+
ext,
|
|
619
|
+
title,
|
|
620
|
+
size,
|
|
621
|
+
hash: spark.end(false),
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
529
625
|
/**
|
|
530
626
|
* 设置网络图片 file
|
|
531
627
|
*/
|
|
@@ -536,6 +632,17 @@ function create(options) {
|
|
|
536
632
|
// 设置文件检查进度
|
|
537
633
|
fileItem.progress = 0
|
|
538
634
|
|
|
635
|
+
// 如果是 base 64
|
|
636
|
+
if (fileItem.isBase64) {
|
|
637
|
+
// 设置文件状态
|
|
638
|
+
fileItem.status = UPLOAD_STATUS.hashChecked
|
|
639
|
+
// 设置文件检查进度
|
|
640
|
+
fileItem.progress = 100
|
|
641
|
+
// 设置单个文件信息
|
|
642
|
+
await setFileItemInfo(fileItem, setFileFail)
|
|
643
|
+
return
|
|
644
|
+
}
|
|
645
|
+
|
|
539
646
|
try {
|
|
540
647
|
const r = await fetch(fileItem.__img, {
|
|
541
648
|
method: 'GET',
|
|
@@ -556,44 +663,8 @@ function create(options) {
|
|
|
556
663
|
|
|
557
664
|
// 如果有类型
|
|
558
665
|
if (blob.type) {
|
|
559
|
-
|
|
560
|
-
// 后缀名
|
|
561
|
-
let ext = ''
|
|
562
|
-
|
|
563
|
-
// 如果为图片
|
|
564
|
-
if (
|
|
565
|
-
props.type === 'image'
|
|
566
|
-
|| $n_indexOf(blob.type, 'image/') > -1
|
|
567
|
-
) {
|
|
568
|
-
switch (blob.type) {
|
|
569
|
-
case 'image/png':
|
|
570
|
-
ext = 'png'
|
|
571
|
-
break
|
|
572
|
-
case 'image/gif':
|
|
573
|
-
ext = 'gif'
|
|
574
|
-
break
|
|
575
|
-
default:
|
|
576
|
-
ext = 'jpg'
|
|
577
|
-
break
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// 如果为视频
|
|
581
|
-
} else if (props.type === 'video') {
|
|
582
|
-
ext = 'mp4'
|
|
583
|
-
|
|
584
|
-
// 如果为音频
|
|
585
|
-
} else if (props.type === 'audio') {
|
|
586
|
-
ext = 'mp3'
|
|
587
|
-
|
|
588
|
-
// 否则为文件
|
|
589
|
-
} else {
|
|
590
|
-
const arr = $n_split(props.type, '/')
|
|
591
|
-
if (arr.length > 0) {
|
|
592
|
-
ext = arr[1]
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
666
|
// 如果有后缀名
|
|
667
|
+
const ext = getBlobExt(blob)
|
|
597
668
|
if (ext) {
|
|
598
669
|
// 设置文件
|
|
599
670
|
fileItem.file = new File([blob], String($n_timestamp()), { type: blob.type })
|
|
@@ -1197,6 +1268,8 @@ function create(options) {
|
|
|
1197
1268
|
data: {
|
|
1198
1269
|
hashs: $n_uniq(checkHashs),
|
|
1199
1270
|
},
|
|
1271
|
+
// 是否需要登录
|
|
1272
|
+
token: isLogin,
|
|
1200
1273
|
// 关闭错误
|
|
1201
1274
|
warn: false,
|
|
1202
1275
|
// 关闭防抖(可以重复请求)
|
|
@@ -1532,6 +1605,8 @@ function create(options) {
|
|
|
1532
1605
|
hash,
|
|
1533
1606
|
title: newTitle,
|
|
1534
1607
|
},
|
|
1608
|
+
// 是否需要登录
|
|
1609
|
+
token: isLogin,
|
|
1535
1610
|
})
|
|
1536
1611
|
|
|
1537
1612
|
// 如果修改失败
|
|
@@ -1795,6 +1870,8 @@ function create(options) {
|
|
|
1795
1870
|
// 空间名称
|
|
1796
1871
|
bucket,
|
|
1797
1872
|
},
|
|
1873
|
+
// 是否需要登录
|
|
1874
|
+
token: isLogin,
|
|
1798
1875
|
})
|
|
1799
1876
|
|
|
1800
1877
|
// 如果成功
|
|
@@ -2023,6 +2100,8 @@ function create(options) {
|
|
|
2023
2100
|
data,
|
|
2024
2101
|
// 关闭错误提示
|
|
2025
2102
|
warn: false,
|
|
2103
|
+
// 是否需要登录
|
|
2104
|
+
token: isLogin,
|
|
2026
2105
|
})
|
|
2027
2106
|
|
|
2028
2107
|
// 请求失败
|