hy-app 0.4.13 → 0.5.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/components/hy-action-sheet/hy-action-sheet.vue +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,534 +1,385 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
: "文件"
|
|
42
|
-
}}
|
|
43
|
-
</text>
|
|
44
|
-
</view>
|
|
2
|
+
<view class="hy-upload" :style="[customStyle]">
|
|
3
|
+
<view class="hy-upload__wrap">
|
|
4
|
+
<template v-if="previewImage">
|
|
5
|
+
<view class="hy-upload__wrap--preview" v-for="(item, index) in lists" :key="index">
|
|
6
|
+
<image
|
|
7
|
+
v-if="item.isImage || (item.type && item.type === 'image')"
|
|
8
|
+
:src="item.thumb || item.url"
|
|
9
|
+
:mode="imageMode"
|
|
10
|
+
class="hy-upload__wrap--preview__image"
|
|
11
|
+
@tap="onPreviewImage(item, index)"
|
|
12
|
+
:style="[
|
|
13
|
+
{
|
|
14
|
+
width: addUnit(width),
|
|
15
|
+
height: addUnit(height)
|
|
16
|
+
}
|
|
17
|
+
]"
|
|
18
|
+
/>
|
|
19
|
+
<view
|
|
20
|
+
v-else
|
|
21
|
+
class="hy-upload__wrap--preview__other"
|
|
22
|
+
@tap="onClickPreview(item, index)"
|
|
23
|
+
>
|
|
24
|
+
<HyIcon
|
|
25
|
+
color="#80CBF9"
|
|
26
|
+
size="26"
|
|
27
|
+
:name="
|
|
28
|
+
item.isVideo || (item.type && item.type === 'video')
|
|
29
|
+
? 'movie'
|
|
30
|
+
: 'folder'
|
|
31
|
+
"
|
|
32
|
+
></HyIcon>
|
|
33
|
+
<text class="hy-upload__wrap--preview__other--text">
|
|
34
|
+
{{
|
|
35
|
+
item.isVideo || (item.type && item.type === 'video')
|
|
36
|
+
? '视频'
|
|
37
|
+
: '文件'
|
|
38
|
+
}}
|
|
39
|
+
</text>
|
|
40
|
+
</view>
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
<!-- 上传进度条 -->
|
|
43
|
+
<view
|
|
44
|
+
class="hy-upload__wrap--preview__progress"
|
|
45
|
+
v-if="item.status === 'loading'"
|
|
46
|
+
>
|
|
47
|
+
<progress
|
|
48
|
+
class="hy-upload__wrap--preview__progress--number"
|
|
49
|
+
:percent="item.schedule"
|
|
50
|
+
stroke-width="4"
|
|
51
|
+
activeColor="#B99C65"
|
|
52
|
+
/>
|
|
53
|
+
<view class="hy-upload__wrap--preview__progress--value"
|
|
54
|
+
>上传进度{{ item.schedule }}%</view
|
|
55
|
+
>
|
|
56
|
+
</view>
|
|
57
|
+
<!-- 上传进度条 -->
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
></HyIcon>
|
|
75
|
-
</view>
|
|
76
|
-
</view>
|
|
77
|
-
<!-- 删除图片图标 -->
|
|
59
|
+
<!-- 删除图片图标 -->
|
|
60
|
+
<view
|
|
61
|
+
class="hy-upload__deletable"
|
|
62
|
+
v-if="item.status !== 'loading' && (deletable || item.deletable)"
|
|
63
|
+
@tap.stop="deleteItem(index)"
|
|
64
|
+
>
|
|
65
|
+
<view class="hy-upload__deletable--icon">
|
|
66
|
+
<HyIcon :name="IconConfig.CLOSE" color="#ffffff" size="14"></HyIcon>
|
|
67
|
+
</view>
|
|
68
|
+
</view>
|
|
69
|
+
<!-- 删除图片图标 -->
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
<!-- 上传成功图标 -->
|
|
72
|
+
<view class="hy-upload__success" v-if="item.status === 'success'">
|
|
73
|
+
<!-- #ifndef APP-NVUE -->
|
|
74
|
+
<view class="hy-upload__success--icon">
|
|
75
|
+
<HyIcon
|
|
76
|
+
:name="IconConfig.CHECK_MASK"
|
|
77
|
+
color="#ffffff"
|
|
78
|
+
size="12"
|
|
79
|
+
></HyIcon>
|
|
80
|
+
</view>
|
|
81
|
+
<!-- #endif -->
|
|
82
|
+
</view>
|
|
83
|
+
<!-- 上传成功图标 -->
|
|
84
|
+
</view>
|
|
85
|
+
</template>
|
|
94
86
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
></HyIcon>
|
|
124
|
-
<text v-if="uploadText" class="hy-upload__button--text">{{
|
|
125
|
-
uploadText
|
|
126
|
-
}}</text>
|
|
87
|
+
<template v-if="isInCount">
|
|
88
|
+
<view v-if="$slots.trigger" @tap="chooseFileFn">
|
|
89
|
+
<slot name="trigger" />
|
|
90
|
+
</view>
|
|
91
|
+
<view
|
|
92
|
+
v-else-if="!$slots.trigger && ($slots.default || $slots.$default)"
|
|
93
|
+
@tap="chooseFileFn"
|
|
94
|
+
>
|
|
95
|
+
<slot />
|
|
96
|
+
</view>
|
|
97
|
+
<view
|
|
98
|
+
v-else
|
|
99
|
+
class="hy-upload__button"
|
|
100
|
+
:hover-class="!disabled ? 'hy-upload__button--hover' : ''"
|
|
101
|
+
hover-stay-time="150"
|
|
102
|
+
@tap="chooseFileFn"
|
|
103
|
+
:class="[disabled && 'hy-upload__button--disabled']"
|
|
104
|
+
:style="[
|
|
105
|
+
{
|
|
106
|
+
width: addUnit(width),
|
|
107
|
+
height: addUnit(height)
|
|
108
|
+
}
|
|
109
|
+
]"
|
|
110
|
+
>
|
|
111
|
+
<HyIcon :name="uploadIcon" size="26" :color="uploadIconColor"></HyIcon>
|
|
112
|
+
<text v-if="uploadText" class="hy-upload__button--text">{{ uploadText }}</text>
|
|
113
|
+
</view>
|
|
114
|
+
</template>
|
|
127
115
|
</view>
|
|
128
|
-
</template>
|
|
129
116
|
</view>
|
|
130
|
-
</view>
|
|
131
117
|
</template>
|
|
132
118
|
|
|
133
119
|
<script lang="ts">
|
|
134
120
|
export default {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
121
|
+
name: 'hy-upload',
|
|
122
|
+
options: {
|
|
123
|
+
addGlobalClass: true,
|
|
124
|
+
virtualHost: true,
|
|
125
|
+
styleIsolation: 'shared'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
142
128
|
</script>
|
|
143
129
|
|
|
144
130
|
<script setup lang="ts">
|
|
145
|
-
import { ref, watch } from
|
|
146
|
-
import type {
|
|
147
|
-
import
|
|
148
|
-
import
|
|
149
|
-
addUnit,
|
|
150
|
-
bytesToSize,
|
|
151
|
-
chooseFile,
|
|
152
|
-
isArray,
|
|
153
|
-
IconConfig,
|
|
154
|
-
} from "../../libs";
|
|
131
|
+
import { ref, watch } from 'vue'
|
|
132
|
+
import type { FileVo, IUploadEmits } from './typing'
|
|
133
|
+
import { addUnit, chooseFile, isArray, IconConfig } from '../../libs'
|
|
134
|
+
import uploadProps from './props'
|
|
155
135
|
// 组件
|
|
156
|
-
import HyIcon from
|
|
136
|
+
import HyIcon from '../hy-icon/hy-icon.vue'
|
|
157
137
|
|
|
158
138
|
/**
|
|
159
139
|
* 该组件用于上传图片或者视频等场景
|
|
160
140
|
* @displayName hy-upload
|
|
161
141
|
*/
|
|
162
|
-
defineOptions({})
|
|
142
|
+
defineOptions({})
|
|
163
143
|
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
/**
|
|
167
|
-
* 接受的文件类型
|
|
168
|
-
* @values all,media,image,file,video
|
|
169
|
-
* */
|
|
170
|
-
accept: {
|
|
171
|
-
type: String,
|
|
172
|
-
default: "image",
|
|
173
|
-
},
|
|
174
|
-
/** 根据文件拓展名过滤,每一项都不能是空字符串。默认不过滤。 */
|
|
175
|
-
extension: {
|
|
176
|
-
type: Array as PropType<string[]>,
|
|
177
|
-
default: () => [],
|
|
178
|
-
},
|
|
179
|
-
/** 图片或视频拾取模式,当accept为image类型时设置capture可选额外camera可以直接调起摄像头 */
|
|
180
|
-
capture: {
|
|
181
|
-
type: Array as PropType<("album" | "camera")[]>,
|
|
182
|
-
default: () => ["album", "camera"],
|
|
183
|
-
},
|
|
184
|
-
/** 当accept为video时生效,是否压缩视频 */
|
|
185
|
-
compressed: {
|
|
186
|
-
type: Boolean,
|
|
187
|
-
default: true,
|
|
188
|
-
},
|
|
189
|
-
/** 当accept为video时生效,可选值为back或front */
|
|
190
|
-
camera: {
|
|
191
|
-
type: String,
|
|
192
|
-
default: "back",
|
|
193
|
-
},
|
|
194
|
-
/** 当accept为video时生效,拍摄视频最长拍摄时间,单位秒 */
|
|
195
|
-
maxDuration: {
|
|
196
|
-
type: Number,
|
|
197
|
-
default: 60,
|
|
198
|
-
},
|
|
199
|
-
/** 上传区域的图标,只能内置图标 */
|
|
200
|
-
uploadIcon: {
|
|
201
|
-
type: String,
|
|
202
|
-
default: IconConfig.UPLOAD,
|
|
203
|
-
},
|
|
204
|
-
/** 上传区域的图标的字体颜色,只能内置图标 */
|
|
205
|
-
uploadIconColor: {
|
|
206
|
-
type: String,
|
|
207
|
-
default: "#D3D4D6",
|
|
208
|
-
},
|
|
209
|
-
/** 是否开启文件读取前事件 */
|
|
210
|
-
useBeforeRead: {
|
|
211
|
-
type: Boolean,
|
|
212
|
-
default: false,
|
|
213
|
-
},
|
|
214
|
-
/** 是否显示组件自带的图片预览功能 */
|
|
215
|
-
previewFullImage: {
|
|
216
|
-
type: Boolean,
|
|
217
|
-
default: true,
|
|
218
|
-
},
|
|
219
|
-
/** 最大上传数量 */
|
|
220
|
-
maxCount: {
|
|
221
|
-
type: Number,
|
|
222
|
-
default: 52,
|
|
223
|
-
},
|
|
224
|
-
/** 是否启用 */
|
|
225
|
-
disabled: {
|
|
226
|
-
type: Boolean,
|
|
227
|
-
default: false,
|
|
228
|
-
},
|
|
229
|
-
/**
|
|
230
|
-
* 预览上传的图片时的裁剪模式,和image组件mode属性一致
|
|
231
|
-
* @values scaleToFill,aspectFit,aspectFill,widthFix,heightFix,top,bottom,center,left,right,top left,top right,bottom left,bottom right
|
|
232
|
-
* */
|
|
233
|
-
imageMode: {
|
|
234
|
-
type: String,
|
|
235
|
-
default: "aspectFill",
|
|
236
|
-
},
|
|
237
|
-
/** 标识符,可以在回调函数的第二项参数中获取 */
|
|
238
|
-
name: {
|
|
239
|
-
type: String,
|
|
240
|
-
default: "",
|
|
241
|
-
},
|
|
242
|
-
/** 所选的图片的尺寸 */
|
|
243
|
-
sizeType: {
|
|
244
|
-
type: Array as PropType<("original" | "compressed")[]>,
|
|
245
|
-
default: ["original", "compressed"],
|
|
246
|
-
},
|
|
247
|
-
/** 是否开启图片多选,部分安卓机型不支持 */
|
|
248
|
-
multiple: {
|
|
249
|
-
type: Boolean,
|
|
250
|
-
default: false,
|
|
251
|
-
},
|
|
252
|
-
/** 是否展示删除按钮 */
|
|
253
|
-
deletable: {
|
|
254
|
-
type: Boolean,
|
|
255
|
-
default: true,
|
|
256
|
-
},
|
|
257
|
-
/** 文件大小限制,单位为byte */
|
|
258
|
-
maxSize: {
|
|
259
|
-
type: Number,
|
|
260
|
-
default: Number.MAX_VALUE,
|
|
261
|
-
},
|
|
262
|
-
/** 显示已上传的文件列表 */
|
|
263
|
-
fileList: {
|
|
264
|
-
type: Array as PropType<FileVo[]>,
|
|
265
|
-
default: () => [],
|
|
266
|
-
},
|
|
267
|
-
/** 上传区域的提示文字 */
|
|
268
|
-
uploadText: {
|
|
269
|
-
type: String,
|
|
270
|
-
default: "",
|
|
271
|
-
},
|
|
272
|
-
/** 内部预览图片区域和选择图片按钮的区域宽度 */
|
|
273
|
-
width: {
|
|
274
|
-
type: [String, Number],
|
|
275
|
-
default: 80,
|
|
276
|
-
},
|
|
277
|
-
/** 内部预览图片区域和选择图片按钮的区域高度 */
|
|
278
|
-
height: {
|
|
279
|
-
type: [String, Number],
|
|
280
|
-
default: 80,
|
|
281
|
-
},
|
|
282
|
-
/** 读取前的处理函数 */
|
|
283
|
-
beforeRead: Function as PropType<ReadFunctionVo>,
|
|
284
|
-
/** 读取后的处理函数 */
|
|
285
|
-
afterRead: Function as PropType<ReadFunctionVo>,
|
|
286
|
-
/** 定义需要用到的外部样式 */
|
|
287
|
-
customStyle: {
|
|
288
|
-
type: Object as PropType<CSSProperties>,
|
|
289
|
-
},
|
|
290
|
-
});
|
|
291
|
-
const emit = defineEmits<IUploadEmits>();
|
|
144
|
+
const props = defineProps(uploadProps)
|
|
145
|
+
const emit = defineEmits<IUploadEmits>()
|
|
292
146
|
|
|
293
|
-
const lists = ref<FileVo[]>([])
|
|
147
|
+
const lists = ref<FileVo[]>([])
|
|
294
148
|
// 上传按钮
|
|
295
|
-
const isInCount = ref<boolean>(true)
|
|
149
|
+
const isInCount = ref<boolean>(true)
|
|
296
150
|
// 遮罩框
|
|
297
|
-
const previewImage = ref<boolean>(true)
|
|
151
|
+
const previewImage = ref<boolean>(true)
|
|
298
152
|
|
|
299
153
|
const formatFileList = () => {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
154
|
+
lists.value = props.fileList.map((item: FileVo) =>
|
|
155
|
+
Object.assign(Object.assign({}, item), {
|
|
156
|
+
// 如果item.url为本地选择的blob文件的话,无法判断其为video还是image,此处优先通过accept做判断处理
|
|
157
|
+
isImage: props.accept === 'image',
|
|
158
|
+
isVideo: props.accept === 'video',
|
|
159
|
+
deletable: item.deletable || props.deletable
|
|
160
|
+
})
|
|
161
|
+
)
|
|
162
|
+
isInCount.value = lists.value.length < props.maxCount
|
|
163
|
+
}
|
|
310
164
|
|
|
311
165
|
watch(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
)
|
|
166
|
+
() => props.fileList,
|
|
167
|
+
() => {
|
|
168
|
+
formatFileList()
|
|
169
|
+
},
|
|
170
|
+
{ immediate: true, deep: true }
|
|
171
|
+
)
|
|
318
172
|
|
|
319
173
|
watch(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
)
|
|
174
|
+
() => props.deletable,
|
|
175
|
+
() => {
|
|
176
|
+
formatFileList()
|
|
177
|
+
}
|
|
178
|
+
)
|
|
325
179
|
|
|
326
180
|
watch(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
)
|
|
181
|
+
() => props.maxCount,
|
|
182
|
+
() => {
|
|
183
|
+
formatFileList()
|
|
184
|
+
}
|
|
185
|
+
)
|
|
332
186
|
|
|
333
187
|
watch(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
)
|
|
188
|
+
() => props.accept,
|
|
189
|
+
() => {
|
|
190
|
+
formatFileList()
|
|
191
|
+
}
|
|
192
|
+
)
|
|
339
193
|
|
|
340
194
|
const chooseFileFn = () => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
Object.assign(
|
|
345
|
-
{
|
|
346
|
-
accept: props.accept,
|
|
347
|
-
extension: props.extension,
|
|
348
|
-
multiple: props.multiple,
|
|
349
|
-
capture: props.capture,
|
|
350
|
-
compressed: props.compressed,
|
|
351
|
-
maxDuration: props.maxDuration,
|
|
352
|
-
sizeType: props.sizeType,
|
|
353
|
-
camera: props.camera,
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
maxCount: props.maxCount - lists.value.length,
|
|
357
|
-
},
|
|
358
|
-
),
|
|
359
|
-
)
|
|
360
|
-
.then((res: any) => {
|
|
361
|
-
onBeforeRead(props.multiple ? res : res[0]);
|
|
362
|
-
})
|
|
363
|
-
.catch((error) => {
|
|
364
|
-
emit("error", error);
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
// 文件读取之前
|
|
368
|
-
const onBeforeRead = (file: FileVo) => {
|
|
369
|
-
let res: any = true;
|
|
370
|
-
// beforeRead是否为一个方法
|
|
371
|
-
if (typeof props.beforeRead === "function") {
|
|
372
|
-
// 如果用户定义了此方法,则去执行此方法,并传入读取的文件回调
|
|
373
|
-
res = props.beforeRead(file, getDetail());
|
|
374
|
-
}
|
|
375
|
-
if (props.useBeforeRead) {
|
|
376
|
-
res = new Promise((resolve, reject) => {
|
|
377
|
-
emit(
|
|
378
|
-
"beforeRead",
|
|
195
|
+
if (props.disabled) return
|
|
196
|
+
// 如果用户传入的是字符串,需要格式化成数组
|
|
197
|
+
chooseFile(
|
|
379
198
|
Object.assign(
|
|
380
|
-
Object.assign(
|
|
381
199
|
{
|
|
382
|
-
|
|
200
|
+
accept: props.accept,
|
|
201
|
+
extension: props.extension,
|
|
202
|
+
multiple: props.multiple,
|
|
203
|
+
capture: props.capture,
|
|
204
|
+
compressed: props.compressed,
|
|
205
|
+
maxDuration: props.maxDuration,
|
|
206
|
+
sizeType: props.sizeType,
|
|
207
|
+
camera: props.camera
|
|
383
208
|
},
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
)
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
209
|
+
{
|
|
210
|
+
maxCount: props.maxCount - lists.value.length
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
.then((res: any) => {
|
|
215
|
+
onBeforeRead(props.multiple ? res : res[0])
|
|
216
|
+
})
|
|
217
|
+
.catch((error) => {
|
|
218
|
+
emit('error', error)
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
// 文件读取之前
|
|
222
|
+
const onBeforeRead = (file: FileVo) => {
|
|
223
|
+
let res: any = true
|
|
224
|
+
// beforeRead是否为一个方法
|
|
225
|
+
if (typeof props.beforeRead === 'function') {
|
|
226
|
+
// 如果用户定义了此方法,则去执行此方法,并传入读取的文件回调
|
|
227
|
+
res = props.beforeRead(file, getDetail())
|
|
228
|
+
}
|
|
229
|
+
if (props.useBeforeRead) {
|
|
230
|
+
res = new Promise((resolve, reject) => {
|
|
231
|
+
emit(
|
|
232
|
+
'beforeRead',
|
|
233
|
+
Object.assign(
|
|
234
|
+
Object.assign(
|
|
235
|
+
{
|
|
236
|
+
file
|
|
237
|
+
},
|
|
238
|
+
getDetail()
|
|
239
|
+
),
|
|
240
|
+
{
|
|
241
|
+
callback: (ok: any) => {
|
|
242
|
+
ok ? resolve(ok) : reject()
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
if (!res) return
|
|
250
|
+
if (typeof res === 'function') {
|
|
251
|
+
res.then((data: any) => onAfterRead(data || file))
|
|
252
|
+
} else {
|
|
253
|
+
onAfterRead(file)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
402
256
|
const getDetail = (index?: number) => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
257
|
+
return {
|
|
258
|
+
name: props.name,
|
|
259
|
+
index: index == null ? props.fileList.length : index
|
|
260
|
+
}
|
|
261
|
+
}
|
|
408
262
|
const onAfterRead = (file: FileVo) => {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
263
|
+
const oversize = isArray(file)
|
|
264
|
+
? file.some((item) => item.size > props.maxSize)
|
|
265
|
+
: Number(file.size) > props.maxSize
|
|
266
|
+
if (oversize) {
|
|
267
|
+
emit(
|
|
268
|
+
'oversize',
|
|
269
|
+
Object.assign(
|
|
270
|
+
{
|
|
271
|
+
file
|
|
272
|
+
},
|
|
273
|
+
getDetail()
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
if (typeof props.afterRead === 'function') {
|
|
279
|
+
props.afterRead(file, getDetail())
|
|
280
|
+
}
|
|
413
281
|
emit(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
if (typeof props.afterRead === "function") {
|
|
425
|
-
props.afterRead(file, getDetail());
|
|
426
|
-
}
|
|
427
|
-
emit(
|
|
428
|
-
"afterRead",
|
|
429
|
-
Object.assign(
|
|
430
|
-
{
|
|
431
|
-
file,
|
|
432
|
-
},
|
|
433
|
-
getDetail(),
|
|
434
|
-
),
|
|
435
|
-
);
|
|
436
|
-
};
|
|
282
|
+
'afterRead',
|
|
283
|
+
Object.assign(
|
|
284
|
+
{
|
|
285
|
+
file
|
|
286
|
+
},
|
|
287
|
+
getDetail()
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
}
|
|
437
291
|
|
|
438
292
|
/**
|
|
439
293
|
* @description 删除文件
|
|
440
294
|
* */
|
|
441
295
|
const deleteItem = (index: number) => {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
296
|
+
props.fileList.splice(index, 1)
|
|
297
|
+
isInCount.value = lists.value.length < props.maxCount
|
|
298
|
+
emit(
|
|
299
|
+
'delete',
|
|
300
|
+
Object.assign(Object.assign({}, getDetail(index)), {
|
|
301
|
+
file: props.fileList[index]
|
|
302
|
+
})
|
|
303
|
+
)
|
|
304
|
+
}
|
|
451
305
|
|
|
452
306
|
/**
|
|
453
307
|
* @description 预览图片
|
|
454
308
|
* */
|
|
455
309
|
const onPreviewImage = (previewItem: FileVo, index: number) => {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
310
|
+
if (!previewItem.isImage || !props.previewFullImage) return
|
|
311
|
+
let current = 0
|
|
312
|
+
const urls: string[] = []
|
|
313
|
+
let imageIndex = 0
|
|
314
|
+
for (let i = 0; i < lists.value.length; i++) {
|
|
315
|
+
const item: FileVo = lists.value[i]
|
|
316
|
+
if (item.isImage || (item.type && item.type === 'image')) {
|
|
317
|
+
urls.push(item.url || (item.thumb as string))
|
|
318
|
+
if (i === index) {
|
|
319
|
+
current = imageIndex
|
|
320
|
+
}
|
|
321
|
+
imageIndex += 1
|
|
322
|
+
}
|
|
468
323
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
};
|
|
324
|
+
if (!urls || urls.length < 1) return
|
|
325
|
+
uni.previewImage({
|
|
326
|
+
urls: urls,
|
|
327
|
+
current: current,
|
|
328
|
+
fail() {
|
|
329
|
+
uni.showToast({ title: '预览图片失败' })
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
}
|
|
479
333
|
|
|
480
334
|
/**
|
|
481
335
|
* @description 预览视频
|
|
482
336
|
* */
|
|
483
337
|
const onPreviewVideo = (index: number) => {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
338
|
+
if (!props.previewFullImage) return
|
|
339
|
+
let current = 0
|
|
340
|
+
const sources: any[] = []
|
|
341
|
+
let videoIndex = 0
|
|
342
|
+
for (let i = 0; i < lists.value.length; i++) {
|
|
343
|
+
const item: FileVo = lists.value[i]
|
|
344
|
+
if (item.isVideo || (item.type && item.type === 'video')) {
|
|
345
|
+
sources.push(
|
|
346
|
+
Object.assign(Object.assign({}, item), {
|
|
347
|
+
type: 'video'
|
|
348
|
+
})
|
|
349
|
+
)
|
|
350
|
+
if (i === index) {
|
|
351
|
+
current = videoIndex
|
|
352
|
+
}
|
|
353
|
+
videoIndex += 1
|
|
354
|
+
}
|
|
500
355
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
};
|
|
356
|
+
if (sources.length < 1) {
|
|
357
|
+
return
|
|
358
|
+
}
|
|
359
|
+
// #ifdef MP-WEIXIN
|
|
360
|
+
wx.previewMedia({
|
|
361
|
+
sources: sources,
|
|
362
|
+
current: current,
|
|
363
|
+
fail() {
|
|
364
|
+
uni.showToast({ title: '预览视频失败' })
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
// #endif
|
|
368
|
+
}
|
|
515
369
|
|
|
516
370
|
const onClickPreview = (item: FileVo, index: number) => {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
Object.assign(Object.assign({}, item), getDetail(index)),
|
|
528
|
-
);
|
|
529
|
-
};
|
|
371
|
+
if (!props.previewFullImage) return
|
|
372
|
+
switch (item.type) {
|
|
373
|
+
case 'video':
|
|
374
|
+
onPreviewVideo(index)
|
|
375
|
+
break
|
|
376
|
+
default:
|
|
377
|
+
break
|
|
378
|
+
}
|
|
379
|
+
emit('clickPreview', Object.assign(Object.assign({}, item), getDetail(index)))
|
|
380
|
+
}
|
|
530
381
|
</script>
|
|
531
382
|
|
|
532
383
|
<style lang="scss" scoped>
|
|
533
|
-
@import
|
|
384
|
+
@import './index.scss';
|
|
534
385
|
</style>
|