@netang/quasar 0.1.67 → 0.1.69
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-query/index.vue +84 -32
- package/package.json +1 -1
- package/utils/config.js +2 -0
- package/utils/uploader.js +161 -24
|
@@ -12,16 +12,32 @@
|
|
|
12
12
|
class="n-uploader-query__button--button"
|
|
13
13
|
v-else-if="! noButton && currentButtonType === 'button'"
|
|
14
14
|
>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
<!-- 按钮组-->
|
|
16
|
+
<q-btn-group outline>
|
|
17
|
+
<!-- 上传本地图片 -->
|
|
18
|
+
<q-btn
|
|
19
|
+
class="n-button-icon"
|
|
20
|
+
:label="buttonText || '上传'"
|
|
21
|
+
@click="uploader.chooseUpload"
|
|
22
|
+
color="primary"
|
|
23
|
+
outline
|
|
24
|
+
:disable="disable || readonly"
|
|
25
|
+
unelevated
|
|
26
|
+
v-bind="buttonProps"
|
|
27
|
+
/>
|
|
28
|
+
<!-- 上传网络图片 -->
|
|
29
|
+
<q-btn
|
|
30
|
+
class="n-button-icon q-px-sm"
|
|
31
|
+
icon="cloud_upload"
|
|
32
|
+
@click="uploader.chooseUploadNet"
|
|
33
|
+
color="primary"
|
|
34
|
+
outline
|
|
35
|
+
:disable="disable || readonly"
|
|
36
|
+
unelevated
|
|
37
|
+
v-bind="buttonProps"
|
|
38
|
+
v-if="showUploadNetButton"
|
|
39
|
+
/>
|
|
40
|
+
</q-btn-group>
|
|
25
41
|
</div>
|
|
26
42
|
|
|
27
43
|
<!-- 拖拽器 -->
|
|
@@ -44,20 +60,38 @@
|
|
|
44
60
|
v-if="$slots['square-button']"
|
|
45
61
|
/>
|
|
46
62
|
<div
|
|
47
|
-
class="n-uploader-query__button--square
|
|
63
|
+
class="n-uploader-query__button--square"
|
|
48
64
|
:style="{
|
|
49
65
|
width: toPx(currentSize),
|
|
50
66
|
height: toPx(currentSize),
|
|
51
67
|
}"
|
|
52
|
-
@click="uploader.chooseUpload"
|
|
53
68
|
v-show="showSquareButton"
|
|
54
69
|
v-else-if="! noButton && currentButtonType === 'square'"
|
|
55
70
|
>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
<!-- 上传本地图片 -->
|
|
72
|
+
<div
|
|
73
|
+
class="n-uploader-query__button--square-button cursor-pointer"
|
|
74
|
+
@click="uploader.chooseUpload"
|
|
75
|
+
>
|
|
76
|
+
<q-icon
|
|
77
|
+
name="add"
|
|
78
|
+
:size="toPx(currentSize / 2)"
|
|
79
|
+
/>
|
|
80
|
+
<div class="n-uploader-query__button--square-button__text" v-if="buttonText">{{buttonText}}</div>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<!-- 上传网络图片 -->
|
|
84
|
+
<div
|
|
85
|
+
class="n-uploader-query__button--square-button q-mt-xs cursor-pointer"
|
|
86
|
+
@click="uploader.chooseUploadNet"
|
|
87
|
+
v-if="showUploadNetButton"
|
|
88
|
+
>
|
|
89
|
+
<q-icon
|
|
90
|
+
name="cloud_upload"
|
|
91
|
+
:size="toPx(currentSize / 3)"
|
|
92
|
+
/>
|
|
93
|
+
<div class="n-uploader-query__button--square-button__text" v-if="buttonText">{{buttonText}}</div>
|
|
94
|
+
</div>
|
|
61
95
|
</div>
|
|
62
96
|
</template>
|
|
63
97
|
|
|
@@ -81,6 +115,7 @@
|
|
|
81
115
|
:spinner-size="toPx(currentSize / 2)"
|
|
82
116
|
:width="toPx(currentSize)"
|
|
83
117
|
:height="toPx(currentSize)"
|
|
118
|
+
@click="onFileItemClick(fileItem)"
|
|
84
119
|
fit="fill"
|
|
85
120
|
>
|
|
86
121
|
<!-- 如果是外链 -->
|
|
@@ -163,7 +198,6 @@
|
|
|
163
198
|
/>
|
|
164
199
|
|
|
165
200
|
</div>
|
|
166
|
-
|
|
167
201
|
</n-img>
|
|
168
202
|
</div>
|
|
169
203
|
|
|
@@ -273,7 +307,7 @@
|
|
|
273
307
|
</div>
|
|
274
308
|
|
|
275
309
|
<!-- 信息 -->
|
|
276
|
-
<div class="n-uploader-query__item__info">
|
|
310
|
+
<div class="n-uploader-query__item__info" @click="onFileItemClick(fileItem)">
|
|
277
311
|
<!-- 标题 -->
|
|
278
312
|
<div class="n-uploader-query__item__info__title ellipsis">{{getFileName(fileItem)}}</div>
|
|
279
313
|
<!-- 错误提示 -->
|
|
@@ -434,6 +468,8 @@ export default {
|
|
|
434
468
|
},
|
|
435
469
|
// 设置图标传参
|
|
436
470
|
settingsIconProps: Object,
|
|
471
|
+
// 是否显示上传网络外链按钮
|
|
472
|
+
showUploadNetButton: Boolean,
|
|
437
473
|
},
|
|
438
474
|
|
|
439
475
|
/**
|
|
@@ -441,12 +477,13 @@ export default {
|
|
|
441
477
|
*/
|
|
442
478
|
emits: [
|
|
443
479
|
'update:modelValue',
|
|
480
|
+
'itemClick',
|
|
444
481
|
],
|
|
445
482
|
|
|
446
483
|
/**
|
|
447
484
|
* 组合式
|
|
448
485
|
*/
|
|
449
|
-
setup(props) {
|
|
486
|
+
setup(props, { emit }) {
|
|
450
487
|
|
|
451
488
|
// ==========【数据】============================================================================================
|
|
452
489
|
|
|
@@ -572,6 +609,12 @@ export default {
|
|
|
572
609
|
return fileItem.title + ($n_get(fileItem, 'ext') ? '.' + fileItem.ext : '')
|
|
573
610
|
}
|
|
574
611
|
|
|
612
|
+
/**
|
|
613
|
+
* 文件点击
|
|
614
|
+
*/
|
|
615
|
+
function onFileItemClick(fileItem) {
|
|
616
|
+
emit('itemClick', fileItem)
|
|
617
|
+
}
|
|
575
618
|
|
|
576
619
|
// ==========【返回】=============================================================================================
|
|
577
620
|
|
|
@@ -603,6 +646,8 @@ export default {
|
|
|
603
646
|
previewImage,
|
|
604
647
|
// 获取文件名称
|
|
605
648
|
getFileName,
|
|
649
|
+
// 文件点击
|
|
650
|
+
onFileItemClick,
|
|
606
651
|
|
|
607
652
|
toPx: $n_px,
|
|
608
653
|
}
|
|
@@ -622,22 +667,29 @@ export default {
|
|
|
622
667
|
// 方块
|
|
623
668
|
&--square {
|
|
624
669
|
display: inline-flex;
|
|
625
|
-
vertical-align: middle;
|
|
626
670
|
overflow: hidden;
|
|
627
|
-
border: 1px dashed rgba(var(--n-reverse-color-rgb), 0.2);
|
|
628
671
|
flex-direction: column;
|
|
629
|
-
justify-content: center;
|
|
630
|
-
align-items: center;
|
|
631
|
-
color: rgba(var(--n-reverse-color-rgb), 0.4);
|
|
632
|
-
border-radius: 4px;
|
|
633
672
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
673
|
+
&-button {
|
|
674
|
+
flex: 1;
|
|
675
|
+
display: flex;
|
|
676
|
+
vertical-align: middle;
|
|
677
|
+
border: 1px dashed rgba(var(--n-reverse-color-rgb), 0.2);
|
|
678
|
+
flex-direction: column;
|
|
679
|
+
justify-content: center;
|
|
680
|
+
align-items: center;
|
|
681
|
+
color: rgba(var(--n-reverse-color-rgb), 0.4);
|
|
682
|
+
border-radius: 4px;
|
|
683
|
+
overflow: hidden;
|
|
637
684
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
685
|
+
&:hover {
|
|
686
|
+
border-color: $primary;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// 文字
|
|
690
|
+
&__text {
|
|
691
|
+
font-size: 12px;
|
|
692
|
+
}
|
|
641
693
|
}
|
|
642
694
|
}
|
|
643
695
|
|
package/package.json
CHANGED
package/utils/config.js
CHANGED
package/utils/uploader.js
CHANGED
|
@@ -25,6 +25,7 @@ import $n_http from '@netang/utils/http'
|
|
|
25
25
|
import $n_getThrowMessage from '@netang/utils/getThrowMessage'
|
|
26
26
|
import $n_runAsync from '@netang/utils/runAsync'
|
|
27
27
|
|
|
28
|
+
import $n_$ruleValid from './$ruleValid'
|
|
28
29
|
import $n_toast from './toast'
|
|
29
30
|
import $n_confirm from './confirm'
|
|
30
31
|
import $n_alert from './alert'
|
|
@@ -399,38 +400,37 @@ function create(options) {
|
|
|
399
400
|
/**
|
|
400
401
|
* 上传网络外链文件
|
|
401
402
|
*/
|
|
402
|
-
async function uploadNet() {
|
|
403
|
+
async function uploadNet(submitUploadNet = false) {
|
|
403
404
|
|
|
404
405
|
// 如果提交时禁止上传网络外链文件
|
|
405
|
-
if ($n_get(optionsProps, 'submitUploadNet')
|
|
406
|
-
return
|
|
407
|
-
}
|
|
406
|
+
if (submitUploadNet === true || $n_get(optionsProps, 'submitUploadNet') === true) {
|
|
408
407
|
|
|
409
|
-
|
|
408
|
+
const promises = []
|
|
410
409
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
410
|
+
for (const fileItem of uploadFileLists.value) {
|
|
411
|
+
if (
|
|
412
|
+
fileItem.isNet
|
|
413
|
+
&& fileItem.status === UPLOAD_STATUS.waiting
|
|
414
|
+
) {
|
|
415
|
+
// 设置网络图片 file
|
|
416
|
+
promises.push(setNetFile(fileItem))
|
|
417
|
+
}
|
|
418
418
|
}
|
|
419
|
-
}
|
|
420
419
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
420
|
+
if (! promises.length) {
|
|
421
|
+
return
|
|
422
|
+
}
|
|
423
|
+
await Promise.all(promises)
|
|
425
424
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
425
|
+
// 检查待上传文件在服务器上是否存在
|
|
426
|
+
// --------------------------------------------------
|
|
427
|
+
if (! await checkWaitUploadFileExists()) {
|
|
428
|
+
return
|
|
429
|
+
}
|
|
431
430
|
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
// 上传
|
|
432
|
+
await upload()
|
|
433
|
+
}
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
/**
|
|
@@ -604,6 +604,141 @@ function create(options) {
|
|
|
604
604
|
fileRef.value.click()
|
|
605
605
|
}
|
|
606
606
|
|
|
607
|
+
/**
|
|
608
|
+
* 选择网络外链上传
|
|
609
|
+
*/
|
|
610
|
+
function chooseUploadNet() {
|
|
611
|
+
$q.dialog({
|
|
612
|
+
title: `添加网络${FilE_NAME[FilE_TYPE[props.type]]}`,
|
|
613
|
+
style: 'min-width:600px;',
|
|
614
|
+
// message: `添加网络${FilE_NAME[FilE_TYPE[props.type]]}`,
|
|
615
|
+
prompt: {
|
|
616
|
+
model: '',
|
|
617
|
+
isValid: $n_$ruleValid('required'),
|
|
618
|
+
type: 'textarea',
|
|
619
|
+
placeholder: '多个链接,使用中英文逗号、空格、换行隔开',
|
|
620
|
+
outlined: true,
|
|
621
|
+
},
|
|
622
|
+
cancel: true,
|
|
623
|
+
persistent: true,
|
|
624
|
+
})
|
|
625
|
+
.onOk(async function(value) {
|
|
626
|
+
|
|
627
|
+
let files = $n_isValidString(value)
|
|
628
|
+
? $n_uniq($n_split(value.replace(/\n|,|,/g, ','), ','))
|
|
629
|
+
.map(e => $n_trimString(e))
|
|
630
|
+
.filter(
|
|
631
|
+
val => val && /^(http(s)?:\/\/)/i.test(val)
|
|
632
|
+
)
|
|
633
|
+
: []
|
|
634
|
+
|
|
635
|
+
if (! files.length) {
|
|
636
|
+
// 轻提示
|
|
637
|
+
$n_toast({
|
|
638
|
+
message: '请输入正确的链接'
|
|
639
|
+
})
|
|
640
|
+
return
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// 格式化上传网络链接
|
|
644
|
+
// --------------------------------------------------
|
|
645
|
+
const {
|
|
646
|
+
formatUploadNet,
|
|
647
|
+
} = configs
|
|
648
|
+
if ($n_isFunction(formatUploadNet)) {
|
|
649
|
+
files = formatUploadNet(files, props.type === 'image')
|
|
650
|
+
}
|
|
651
|
+
// --------------------------------------------------
|
|
652
|
+
|
|
653
|
+
if (! $n_isValidArray(files)) {
|
|
654
|
+
// 轻提示
|
|
655
|
+
$n_toast({
|
|
656
|
+
message: '请输入正确的链接'
|
|
657
|
+
})
|
|
658
|
+
return
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// 添加上传网络外链至文件列表
|
|
662
|
+
function addFileNetItem(hash) {
|
|
663
|
+
uploadFileLists.value.push(Object.assign(createRawFileItem(), {
|
|
664
|
+
// id
|
|
665
|
+
id: ++_fileNum,
|
|
666
|
+
// 文件唯一 key
|
|
667
|
+
key: hash,
|
|
668
|
+
// hash
|
|
669
|
+
hash,
|
|
670
|
+
// 将文件状态修改为: 等待上传中
|
|
671
|
+
status: UPLOAD_STATUS.waiting,
|
|
672
|
+
// 进度
|
|
673
|
+
progress: 100,
|
|
674
|
+
// 信息
|
|
675
|
+
msg: '',
|
|
676
|
+
|
|
677
|
+
__img: hash,
|
|
678
|
+
isNet: true,
|
|
679
|
+
isNetUploaded: false,
|
|
680
|
+
}))
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// 遍历选择的文件列表
|
|
684
|
+
for (const file of files) {
|
|
685
|
+
|
|
686
|
+
// 如果只能上传一个
|
|
687
|
+
if (props.count === 1) {
|
|
688
|
+
|
|
689
|
+
// 如果有上传文件列表
|
|
690
|
+
if (uploadFileLists.value.length) {
|
|
691
|
+
|
|
692
|
+
// 如果开启单文件上传提示
|
|
693
|
+
if (props.confirm) {
|
|
694
|
+
|
|
695
|
+
// 确认框
|
|
696
|
+
$n_confirm({
|
|
697
|
+
message: '最多只能上传1个文件,确认上传并替换吗?',
|
|
698
|
+
})
|
|
699
|
+
// 点击确认执行
|
|
700
|
+
.onOk(function () {
|
|
701
|
+
|
|
702
|
+
// 删除所有文件
|
|
703
|
+
deleteAll()
|
|
704
|
+
|
|
705
|
+
// 添加上传网络外链至文件列表
|
|
706
|
+
addFileNetItem(file)
|
|
707
|
+
|
|
708
|
+
// 上传网络外链文件
|
|
709
|
+
uploadNet(true)
|
|
710
|
+
.finally()
|
|
711
|
+
})
|
|
712
|
+
return
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// 删除所有文件
|
|
716
|
+
deleteAll()
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
} else if (
|
|
720
|
+
// 如果有上传数量限制
|
|
721
|
+
props.count > 1
|
|
722
|
+
// 上传文件列表数量 === 上传数量限制
|
|
723
|
+
&& uploadFileLists.value.length >= props.count
|
|
724
|
+
) {
|
|
725
|
+
// 轻提示
|
|
726
|
+
$n_toast({
|
|
727
|
+
message: `最多只能上传${props.count}个文件,请先删除后再上传`,
|
|
728
|
+
})
|
|
729
|
+
return
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// 添加上传网络外链至文件列表
|
|
733
|
+
addFileNetItem(file)
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// 上传网络外链文件
|
|
737
|
+
uploadNet(true)
|
|
738
|
+
.finally()
|
|
739
|
+
})
|
|
740
|
+
}
|
|
741
|
+
|
|
607
742
|
/**
|
|
608
743
|
* 文件输入框更新
|
|
609
744
|
*/
|
|
@@ -1460,6 +1595,8 @@ function create(options) {
|
|
|
1460
1595
|
checkUploading,
|
|
1461
1596
|
// 选择文件上传
|
|
1462
1597
|
chooseUpload,
|
|
1598
|
+
// 选择网络外链上传
|
|
1599
|
+
chooseUploadNet,
|
|
1463
1600
|
// 文件输入框更新
|
|
1464
1601
|
fileChange,
|
|
1465
1602
|
// 删除所有文件
|