uview-ui-wjf 1.0.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/LICENSE +21 -0
- package/README.md +71 -0
- package/changelog.md +388 -0
- package/components/u--form/u--form.vue +92 -0
- package/components/u--image/u--image.vue +73 -0
- package/components/u--input/u--input.vue +115 -0
- package/components/u--text/u--text.vue +72 -0
- package/components/u--textarea/u--textarea.vue +85 -0
- package/components/u-action-sheet/props.js +54 -0
- package/components/u-action-sheet/u-action-sheet.vue +278 -0
- package/components/u-album/props.js +59 -0
- package/components/u-album/u-album.vue +259 -0
- package/components/u-alert/props.js +44 -0
- package/components/u-alert/u-alert.vue +243 -0
- package/components/u-avatar/props.js +78 -0
- package/components/u-avatar/u-avatar.vue +173 -0
- package/components/u-avatar-group/props.js +52 -0
- package/components/u-avatar-group/u-avatar-group.vue +103 -0
- package/components/u-back-top/props.js +54 -0
- package/components/u-back-top/u-back-top.vue +129 -0
- package/components/u-badge/props.js +72 -0
- package/components/u-badge/u-badge.vue +171 -0
- package/components/u-button/nvue.scss +46 -0
- package/components/u-button/props.js +161 -0
- package/components/u-button/u-button.vue +495 -0
- package/components/u-button/vue.scss +80 -0
- package/components/u-calendar/header.vue +99 -0
- package/components/u-calendar/month.vue +579 -0
- package/components/u-calendar/props.js +144 -0
- package/components/u-calendar/u-calendar.vue +384 -0
- package/components/u-calendar/util.js +85 -0
- package/components/u-car-keyboard/props.js +14 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +311 -0
- package/components/u-cell/props.js +110 -0
- package/components/u-cell/u-cell.vue +229 -0
- package/components/u-cell-group/props.js +14 -0
- package/components/u-cell-group/u-cell-group.vue +61 -0
- package/components/u-checkbox/props.js +69 -0
- package/components/u-checkbox/u-checkbox.vue +344 -0
- package/components/u-checkbox-group/props.js +82 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +103 -0
- package/components/u-circle-progress/props.js +8 -0
- package/components/u-circle-progress/u-circle-progress.vue +198 -0
- package/components/u-code/props.js +34 -0
- package/components/u-code/u-code.vue +129 -0
- package/components/u-code-input/props.js +79 -0
- package/components/u-code-input/u-code-input.vue +252 -0
- package/components/u-col/props.js +29 -0
- package/components/u-col/u-col.vue +162 -0
- package/components/u-collapse/props.js +19 -0
- package/components/u-collapse/u-collapse.vue +90 -0
- package/components/u-collapse-item/props.js +59 -0
- package/components/u-collapse-item/u-collapse-item.vue +225 -0
- package/components/u-column-notice/props.js +55 -0
- package/components/u-column-notice/u-column-notice.vue +160 -0
- package/components/u-count-down/props.js +24 -0
- package/components/u-count-down/u-count-down.vue +163 -0
- package/components/u-count-down/utils.js +62 -0
- package/components/u-count-to/props.js +59 -0
- package/components/u-count-to/u-count-to.vue +184 -0
- package/components/u-datetime-picker/props.js +120 -0
- package/components/u-datetime-picker/u-datetime-picker.vue +361 -0
- package/components/u-divider/props.js +44 -0
- package/components/u-divider/u-divider.vue +116 -0
- package/components/u-dropdown/props.js +65 -0
- package/components/u-dropdown/u-dropdown.vue +127 -0
- package/components/u-dropdown-item/props.js +36 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +127 -0
- package/components/u-empty/props.js +59 -0
- package/components/u-empty/u-empty.vue +128 -0
- package/components/u-form/props.js +45 -0
- package/components/u-form/u-form.vue +214 -0
- package/components/u-form-item/props.js +48 -0
- package/components/u-form-item/u-form-item.vue +235 -0
- package/components/u-gap/props.js +24 -0
- package/components/u-gap/u-gap.vue +38 -0
- package/components/u-grid/props.js +19 -0
- package/components/u-grid/u-grid.vue +97 -0
- package/components/u-grid-item/props.js +14 -0
- package/components/u-grid-item/u-grid-item.vue +209 -0
- package/components/u-icon/icons.js +214 -0
- package/components/u-icon/props.js +89 -0
- package/components/u-icon/u-icon.vue +237 -0
- package/components/u-image/props.js +84 -0
- package/components/u-image/u-image.vue +232 -0
- package/components/u-index-anchor/props.js +29 -0
- package/components/u-index-anchor/u-index-anchor.vue +91 -0
- package/components/u-index-item/props.js +5 -0
- package/components/u-index-item/u-index-item.vue +87 -0
- package/components/u-index-list/props.js +29 -0
- package/components/u-index-list/u-index-list.vue +440 -0
- package/components/u-input/props.js +187 -0
- package/components/u-input/u-input.vue +369 -0
- package/components/u-keyboard/props.js +84 -0
- package/components/u-keyboard/u-keyboard.vue +164 -0
- package/components/u-line/props.js +33 -0
- package/components/u-line/u-line.vue +62 -0
- package/components/u-line-progress/props.js +28 -0
- package/components/u-line-progress/u-line-progress.vue +144 -0
- package/components/u-link/props.js +39 -0
- package/components/u-link/u-link.vue +83 -0
- package/components/u-list/props.js +76 -0
- package/components/u-list/u-list.vue +157 -0
- package/components/u-list-item/props.js +9 -0
- package/components/u-list-item/u-list-item.vue +116 -0
- package/components/u-loading-icon/props.js +59 -0
- package/components/u-loading-icon/u-loading-icon.vue +343 -0
- package/components/u-loading-page/props.js +49 -0
- package/components/u-loading-page/u-loading-page.vue +115 -0
- package/components/u-loadmore/props.js +94 -0
- package/components/u-loadmore/u-loadmore.vue +150 -0
- package/components/u-modal/props.js +89 -0
- package/components/u-modal/u-modal.vue +228 -0
- package/components/u-navbar/props.js +84 -0
- package/components/u-navbar/u-navbar.vue +186 -0
- package/components/u-no-network/props.js +19 -0
- package/components/u-no-network/u-no-network.vue +220 -0
- package/components/u-notice-bar/props.js +70 -0
- package/components/u-notice-bar/u-notice-bar.vue +101 -0
- package/components/u-notify/props.js +49 -0
- package/components/u-notify/u-notify.vue +211 -0
- package/components/u-number-box/props.js +109 -0
- package/components/u-number-box/u-number-box.vue +416 -0
- package/components/u-number-keyboard/props.js +19 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +196 -0
- package/components/u-overlay/props.js +24 -0
- package/components/u-overlay/u-overlay.vue +68 -0
- package/components/u-parse/node/node.vue +499 -0
- package/components/u-parse/parser.js +1075 -0
- package/components/u-parse/props.js +45 -0
- package/components/u-parse/u-parse.vue +366 -0
- package/components/u-picker/props.js +79 -0
- package/components/u-picker/u-picker.vue +286 -0
- package/components/u-picker-column/props.js +5 -0
- package/components/u-picker-column/u-picker-column.vue +27 -0
- package/components/u-popup/props.js +79 -0
- package/components/u-popup/u-popup.vue +304 -0
- package/components/u-radio/props.js +64 -0
- package/components/u-radio/u-radio.vue +339 -0
- package/components/u-radio-group/props.js +85 -0
- package/components/u-radio-group/u-radio-group.vue +108 -0
- package/components/u-rate/props.js +69 -0
- package/components/u-rate/u-rate.vue +306 -0
- package/components/u-read-more/props.js +61 -0
- package/components/u-read-more/u-read-more.vue +157 -0
- package/components/u-row/props.js +19 -0
- package/components/u-row/u-row.vue +93 -0
- package/components/u-row-notice/props.js +39 -0
- package/components/u-row-notice/u-row-notice.vue +330 -0
- package/components/u-safe-bottom/props.js +5 -0
- package/components/u-safe-bottom/u-safe-bottom.vue +56 -0
- package/components/u-scroll-list/nvue.js +28 -0
- package/components/u-scroll-list/other.js +0 -0
- package/components/u-scroll-list/props.js +34 -0
- package/components/u-scroll-list/scrollWxs.wxs +50 -0
- package/components/u-scroll-list/u-scroll-list.vue +224 -0
- package/components/u-search/props.js +118 -0
- package/components/u-search/u-search.vue +303 -0
- package/components/u-skeleton/props.js +59 -0
- package/components/u-skeleton/u-skeleton.vue +244 -0
- package/components/u-slider/mpother.js +113 -0
- package/components/u-slider/mpwxs.js +42 -0
- package/components/u-slider/mpwxs.wxs +121 -0
- package/components/u-slider/nvue - /345/211/257/346/234/254.js" +180 -0
- package/components/u-slider/nvue.js +193 -0
- package/components/u-slider/props.js +54 -0
- package/components/u-slider/u-slider.vue +55 -0
- package/components/u-status-bar/props.js +8 -0
- package/components/u-status-bar/u-status-bar.vue +46 -0
- package/components/u-steps/props.js +39 -0
- package/components/u-steps/u-steps.vue +80 -0
- package/components/u-steps-item/props.js +24 -0
- package/components/u-steps-item/u-steps-item.vue +316 -0
- package/components/u-sticky/props.js +40 -0
- package/components/u-sticky/u-sticky.vue +212 -0
- package/components/u-subsection/props.js +49 -0
- package/components/u-subsection/u-subsection.vue +299 -0
- package/components/u-swipe-action/props.js +9 -0
- package/components/u-swipe-action/u-swipe-action.vue +67 -0
- package/components/u-swipe-action-item/index - backup.wxs +256 -0
- package/components/u-swipe-action-item/index.wxs +225 -0
- package/components/u-swipe-action-item/nvue - backup.js +270 -0
- package/components/u-swipe-action-item/nvue.js +174 -0
- package/components/u-swipe-action-item/props.js +41 -0
- package/components/u-swipe-action-item/u-swipe-action-item.vue +190 -0
- package/components/u-swipe-action-item/wxs.js +15 -0
- package/components/u-swiper/props.js +125 -0
- package/components/u-swiper/u-swiper.vue +255 -0
- package/components/u-swiper-indicator/props.js +29 -0
- package/components/u-swiper-indicator/u-swiper-indicator.vue +110 -0
- package/components/u-switch/props.js +54 -0
- package/components/u-switch/u-switch.vue +177 -0
- package/components/u-tabbar/props.js +44 -0
- package/components/u-tabbar/u-tabbar.vue +141 -0
- package/components/u-tabbar-item/props.js +35 -0
- package/components/u-tabbar-item/u-tabbar-item.vue +142 -0
- package/components/u-table/props.js +5 -0
- package/components/u-table/u-table.vue +29 -0
- package/components/u-tabs/props.js +64 -0
- package/components/u-tabs/u-tabs.vue +363 -0
- package/components/u-tabs-item/props.js +5 -0
- package/components/u-tabs-item/u-tabs-item.vue +29 -0
- package/components/u-tag/props.js +84 -0
- package/components/u-tag/u-tag.vue +358 -0
- package/components/u-td/props.js +5 -0
- package/components/u-td/u-td.vue +31 -0
- package/components/u-text/props.js +110 -0
- package/components/u-text/u-text.vue +223 -0
- package/components/u-text/value.js +85 -0
- package/components/u-textarea/props.js +119 -0
- package/components/u-textarea/u-textarea.vue +239 -0
- package/components/u-toast/u-toast.vue +291 -0
- package/components/u-toolbar/props.js +34 -0
- package/components/u-toolbar/u-toolbar.vue +102 -0
- package/components/u-tooltip/clipboard.min.js +58 -0
- package/components/u-tooltip/props.js +59 -0
- package/components/u-tooltip/u-tooltip.vue +366 -0
- package/components/u-tr/props.js +5 -0
- package/components/u-tr/u-tr.vue +31 -0
- package/components/u-transition/nvue.ani-map.js +68 -0
- package/components/u-transition/props.js +24 -0
- package/components/u-transition/transition.js +157 -0
- package/components/u-transition/u-transition.vue +92 -0
- package/components/u-transition/vue.ani-style.scss +113 -0
- package/components/u-upload/mixin.js +21 -0
- package/components/u-upload/props.js +124 -0
- package/components/u-upload/u-upload.vue +566 -0
- package/components/u-upload/utils.js +151 -0
- package/components/uview-ui/uview-ui.vue +15 -0
- package/index.js +79 -0
- package/index.scss +23 -0
- package/libs/config/color.js +17 -0
- package/libs/config/config.js +34 -0
- package/libs/config/props/actionSheet.js +25 -0
- package/libs/config/props/album.js +25 -0
- package/libs/config/props/alert.js +22 -0
- package/libs/config/props/avatar.js +28 -0
- package/libs/config/props/avatarGroup.js +23 -0
- package/libs/config/props/backtop.js +27 -0
- package/libs/config/props/badge.js +27 -0
- package/libs/config/props/button.js +42 -0
- package/libs/config/props/calendar.js +42 -0
- package/libs/config/props/carKeyboard.js +15 -0
- package/libs/config/props/cell.js +35 -0
- package/libs/config/props/cellGroup.js +17 -0
- package/libs/config/props/checkbox.js +27 -0
- package/libs/config/props/checkboxGroup.js +29 -0
- package/libs/config/props/circleProgress.js +15 -0
- package/libs/config/props/code.js +21 -0
- package/libs/config/props/codeInput.js +29 -0
- package/libs/config/props/col.js +19 -0
- package/libs/config/props/collapse.js +17 -0
- package/libs/config/props/collapseItem.js +25 -0
- package/libs/config/props/columnNotice.js +24 -0
- package/libs/config/props/countDown.js +18 -0
- package/libs/config/props/countTo.js +25 -0
- package/libs/config/props/datetimePicker.js +37 -0
- package/libs/config/props/divider.js +23 -0
- package/libs/config/props/empty.js +26 -0
- package/libs/config/props/form.js +22 -0
- package/libs/config/props/formItem.js +23 -0
- package/libs/config/props/gap.js +19 -0
- package/libs/config/props/grid.js +17 -0
- package/libs/config/props/gridItem.js +16 -0
- package/libs/config/props/icon.js +36 -0
- package/libs/config/props/image.js +30 -0
- package/libs/config/props/indexAnchor.js +19 -0
- package/libs/config/props/indexList.js +19 -0
- package/libs/config/props/input.js +48 -0
- package/libs/config/props/keyboard.js +30 -0
- package/libs/config/props/line.js +20 -0
- package/libs/config/props/lineProgress.js +19 -0
- package/libs/config/props/link.js +26 -0
- package/libs/config/props/list.js +28 -0
- package/libs/config/props/listItem.js +15 -0
- package/libs/config/props/loadingIcon.js +30 -0
- package/libs/config/props/loadingPage.js +23 -0
- package/libs/config/props/loadmore.js +32 -0
- package/libs/config/props/modal.js +31 -0
- package/libs/config/props/navbar.js +32 -0
- package/libs/config/props/noNetwork.js +18 -0
- package/libs/config/props/noticeBar.js +27 -0
- package/libs/config/props/notify.js +22 -0
- package/libs/config/props/numberBox.js +35 -0
- package/libs/config/props/numberKeyboard.js +17 -0
- package/libs/config/props/overlay.js +18 -0
- package/libs/config/props/parse.js +22 -0
- package/libs/config/props/picker.js +29 -0
- package/libs/config/props/popup.js +29 -0
- package/libs/config/props/radio.js +27 -0
- package/libs/config/props/radioGroup.js +30 -0
- package/libs/config/props/rate.js +26 -0
- package/libs/config/props/readMore.js +22 -0
- package/libs/config/props/row.js +17 -0
- package/libs/config/props/rowNotice.js +21 -0
- package/libs/config/props/scrollList.js +20 -0
- package/libs/config/props/search.js +37 -0
- package/libs/config/props/section.js +24 -0
- package/libs/config/props/skeleton.js +25 -0
- package/libs/config/props/slider.js +25 -0
- package/libs/config/props/statusBar.js +15 -0
- package/libs/config/props/steps.js +21 -0
- package/libs/config/props/stepsItem.js +18 -0
- package/libs/config/props/sticky.js +20 -0
- package/libs/config/props/subsection.js +23 -0
- package/libs/config/props/swipeAction.js +15 -0
- package/libs/config/props/swipeActionItem.js +21 -0
- package/libs/config/props/swiper.js +39 -0
- package/libs/config/props/swipterIndicator.js +19 -0
- package/libs/config/props/switch.js +24 -0
- package/libs/config/props/tabbar.js +22 -0
- package/libs/config/props/tabbarItem.js +20 -0
- package/libs/config/props/tabs.js +32 -0
- package/libs/config/props/tag.js +29 -0
- package/libs/config/props/text.js +38 -0
- package/libs/config/props/textarea.js +36 -0
- package/libs/config/props/toast.js +30 -0
- package/libs/config/props/toolbar.js +21 -0
- package/libs/config/props/tooltip.js +25 -0
- package/libs/config/props/transition.js +18 -0
- package/libs/config/props/upload.js +36 -0
- package/libs/config/props.js +190 -0
- package/libs/config/zIndex.js +20 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +97 -0
- package/libs/css/components.scss +15 -0
- package/libs/css/flex.scss +257 -0
- package/libs/css/h5.scss +0 -0
- package/libs/css/mixin.scss +8 -0
- package/libs/css/mp.scss +0 -0
- package/libs/css/nvue.scss +0 -0
- package/libs/css/vue.scss +27 -0
- package/libs/function/colorGradient.js +134 -0
- package/libs/function/debounce.js +29 -0
- package/libs/function/digit.js +167 -0
- package/libs/function/index.js +731 -0
- package/libs/function/platform.js +75 -0
- package/libs/function/test.js +288 -0
- package/libs/function/throttle.js +30 -0
- package/libs/luch-request/adapters/index.js +97 -0
- package/libs/luch-request/core/InterceptorManager.js +50 -0
- package/libs/luch-request/core/Request.js +198 -0
- package/libs/luch-request/core/buildFullPath.js +20 -0
- package/libs/luch-request/core/defaults.js +29 -0
- package/libs/luch-request/core/dispatchRequest.js +3 -0
- package/libs/luch-request/core/mergeConfig.js +103 -0
- package/libs/luch-request/core/settle.js +16 -0
- package/libs/luch-request/helpers/buildURL.js +69 -0
- package/libs/luch-request/helpers/combineURLs.js +14 -0
- package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/libs/luch-request/index.d.ts +116 -0
- package/libs/luch-request/index.js +3 -0
- package/libs/luch-request/utils/clone.js +264 -0
- package/libs/luch-request/utils.js +131 -0
- package/libs/mixin/button.js +13 -0
- package/libs/mixin/mixin.js +160 -0
- package/libs/mixin/mpMixin.js +8 -0
- package/libs/mixin/mpShare.js +13 -0
- package/libs/mixin/openType.js +25 -0
- package/libs/mixin/style.js +228 -0
- package/libs/mixin/touch.js +59 -0
- package/libs/util/async-validator.js +1343 -0
- package/libs/util/calendar.js +546 -0
- package/libs/util/dayjs.js +308 -0
- package/libs/util/emitter.js +51 -0
- package/libs/util/route.js +124 -0
- package/package.json +83 -0
- package/theme.scss +44 -0
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-upload" :style="[$u.addStyle(customStyle)]">
|
|
3
|
+
<view class="u-upload__wrap" >
|
|
4
|
+
<template v-if="previewImage">
|
|
5
|
+
<view
|
|
6
|
+
class="u-upload__wrap__preview"
|
|
7
|
+
v-for="(item, index) in lists"
|
|
8
|
+
:key="index"
|
|
9
|
+
>
|
|
10
|
+
<image
|
|
11
|
+
v-if="item.isImage || (item.type && item.type === 'image')"
|
|
12
|
+
:src="item.thumb || item.url"
|
|
13
|
+
:mode="imageMode"
|
|
14
|
+
class="u-upload__wrap__preview__image"
|
|
15
|
+
@tap="onPreviewImage(item)"
|
|
16
|
+
:style="[{
|
|
17
|
+
width: $u.addUnit(width),
|
|
18
|
+
height: $u.addUnit(height)
|
|
19
|
+
}]"
|
|
20
|
+
/>
|
|
21
|
+
<view
|
|
22
|
+
v-else
|
|
23
|
+
class="u-upload__wrap__preview__other"
|
|
24
|
+
>
|
|
25
|
+
<u-icon
|
|
26
|
+
color="#80CBF9"
|
|
27
|
+
size="26"
|
|
28
|
+
:name="item.isVideo || (item.type && item.type === 'video') ? 'movie' : 'folder'"
|
|
29
|
+
></u-icon>
|
|
30
|
+
<text class="u-upload__wrap__preview__other__text">{{item.isVideo || (item.type && item.type === 'video') ? '视频' : '文件'}}</text>
|
|
31
|
+
</view>
|
|
32
|
+
<view
|
|
33
|
+
class="u-upload__status"
|
|
34
|
+
v-if="item.status === 'uploading' || item.status === 'failed'"
|
|
35
|
+
>
|
|
36
|
+
<view class="u-upload__status__icon">
|
|
37
|
+
<u-icon
|
|
38
|
+
v-if="item.status === 'failed'"
|
|
39
|
+
name="close-circle"
|
|
40
|
+
color="#ffffff"
|
|
41
|
+
size="25"
|
|
42
|
+
/>
|
|
43
|
+
<u-loading-icon
|
|
44
|
+
size="22"
|
|
45
|
+
mode="circle"
|
|
46
|
+
color="#ffffff"
|
|
47
|
+
v-else
|
|
48
|
+
/>
|
|
49
|
+
</view>
|
|
50
|
+
<text
|
|
51
|
+
v-if="item.message"
|
|
52
|
+
class="u-upload__status__message"
|
|
53
|
+
>{{ item.message }}</text>
|
|
54
|
+
</view>
|
|
55
|
+
<view
|
|
56
|
+
class="u-upload__deletable"
|
|
57
|
+
v-if="item.status !== 'uploading' && (deletable || item.deletable)"
|
|
58
|
+
@tap.stop="deleteItem(index)"
|
|
59
|
+
>
|
|
60
|
+
<view class="u-upload__deletable__icon">
|
|
61
|
+
<u-icon
|
|
62
|
+
name="close"
|
|
63
|
+
color="#ffffff"
|
|
64
|
+
size="10"
|
|
65
|
+
></u-icon>
|
|
66
|
+
</view>
|
|
67
|
+
</view>
|
|
68
|
+
<view
|
|
69
|
+
class="u-upload__success"
|
|
70
|
+
v-if="item.status === 'success'"
|
|
71
|
+
>
|
|
72
|
+
<!-- #ifdef APP-NVUE -->
|
|
73
|
+
<image
|
|
74
|
+
:src="successIcon"
|
|
75
|
+
class="u-upload__success__icon"
|
|
76
|
+
></image>
|
|
77
|
+
<!-- #endif -->
|
|
78
|
+
<!-- #ifndef APP-NVUE -->
|
|
79
|
+
<view class="u-upload__success__icon">
|
|
80
|
+
<u-icon
|
|
81
|
+
name="checkmark"
|
|
82
|
+
color="#ffffff"
|
|
83
|
+
size="12"
|
|
84
|
+
></u-icon>
|
|
85
|
+
</view>
|
|
86
|
+
<!-- #endif -->
|
|
87
|
+
</view>
|
|
88
|
+
</view>
|
|
89
|
+
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<template v-if="isInCount">
|
|
93
|
+
<view
|
|
94
|
+
v-if="$slots.default || $slots.$default"
|
|
95
|
+
@tap="chooseFile"
|
|
96
|
+
class="u-upload__default-slot"
|
|
97
|
+
:class="[lists.length === 0 ? 'u-upload__default-slot--empty-list' : '']"
|
|
98
|
+
>
|
|
99
|
+
<slot />
|
|
100
|
+
</view>
|
|
101
|
+
<view
|
|
102
|
+
v-else
|
|
103
|
+
class="u-upload__button"
|
|
104
|
+
:hover-class="!disabled ? 'u-upload__button--hover' : ''"
|
|
105
|
+
hover-stay-time="150"
|
|
106
|
+
@tap="chooseFile"
|
|
107
|
+
:class="[disabled && 'u-upload__button--disabled']"
|
|
108
|
+
:style="[{
|
|
109
|
+
width: $u.addUnit(width),
|
|
110
|
+
height: $u.addUnit(height)
|
|
111
|
+
}]"
|
|
112
|
+
>
|
|
113
|
+
<u-icon
|
|
114
|
+
:name="uploadIcon"
|
|
115
|
+
size="26"
|
|
116
|
+
:color="uploadIconColor"
|
|
117
|
+
></u-icon>
|
|
118
|
+
<text
|
|
119
|
+
v-if="uploadText"
|
|
120
|
+
class="u-upload__button__text"
|
|
121
|
+
>{{ uploadText }}</text>
|
|
122
|
+
</view>
|
|
123
|
+
</template>
|
|
124
|
+
</view>
|
|
125
|
+
|
|
126
|
+
</view>
|
|
127
|
+
</template>
|
|
128
|
+
|
|
129
|
+
<script>
|
|
130
|
+
import {
|
|
131
|
+
chooseFile
|
|
132
|
+
} from './utils';
|
|
133
|
+
import mixin from './mixin.js';
|
|
134
|
+
import props from './props.js';
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* upload 上传
|
|
138
|
+
* @description 该组件用于上传图片场景
|
|
139
|
+
* @tutorial https://uviewui.com/components/upload.html
|
|
140
|
+
* @property {String} accept 接受的文件类型, 可选值为all media image file video (默认 'image' )
|
|
141
|
+
* @property {String | Array} capture 图片或视频拾取模式,当accept为image类型时设置capture可选额外camera可以直接调起摄像头(默认 ['album', 'camera'] )
|
|
142
|
+
* @property {Boolean} compressed 当accept为video时生效,是否压缩视频,默认为true(默认 true )
|
|
143
|
+
* @property {String} camera 当accept为video时生效,可选值为back或front(默认 'back' )
|
|
144
|
+
* @property {Number} maxDuration 当accept为video时生效,拍摄视频最长拍摄时间,单位秒(默认 60 )
|
|
145
|
+
* @property {String} uploadIcon 上传区域的图标,只能内置图标(默认 'camera-fill' )
|
|
146
|
+
* @property {String} uploadIconColor 上传区域的图标的字体颜色,只能内置图标(默认 #D3D4D6 )
|
|
147
|
+
* @property {Boolean} useBeforeRead 是否开启文件读取前事件(默认 false )
|
|
148
|
+
* @property {Boolean} previewFullImage 是否显示组件自带的图片预览功能(默认 true )
|
|
149
|
+
* @property {String | Number} maxCount 最大上传数量(默认 52 )
|
|
150
|
+
* @property {Boolean} disabled 是否启用(默认 false )
|
|
151
|
+
* @property {String} imageMode 预览上传的图片时的裁剪模式,和image组件mode属性一致(默认 'aspectFill' )
|
|
152
|
+
* @property {String} name 标识符,可以在回调函数的第二项参数中获取
|
|
153
|
+
* @property {Array} sizeType 所选的图片的尺寸, 可选值为original compressed(默认 ['original', 'compressed'] )
|
|
154
|
+
* @property {Boolean} multiple 是否开启图片多选,部分安卓机型不支持 (默认 false )
|
|
155
|
+
* @property {Boolean} deletable 是否展示删除按钮(默认 true )
|
|
156
|
+
* @property {String | Number} maxSize 文件大小限制,单位为byte (默认 Number.MAX_VALUE )
|
|
157
|
+
* @property {Array} fileList 显示已上传的文件列表
|
|
158
|
+
* @property {String} uploadText 上传区域的提示文字
|
|
159
|
+
* @property {String | Number} width 内部预览图片区域和选择图片按钮的区域宽度(默认 80 )
|
|
160
|
+
* @property {String | Number} height 内部预览图片区域和选择图片按钮的区域高度(默认 80 )
|
|
161
|
+
* @property {Object} customStyle 组件的样式,对象形式
|
|
162
|
+
* @event {Function} afterRead 读取后的处理函数
|
|
163
|
+
* @event {Function} beforeRead 读取前的处理函数
|
|
164
|
+
* @event {Function} oversize 文件超出大小限制
|
|
165
|
+
* @event {Function} clickPreview 点击预览图片
|
|
166
|
+
* @event {Function} delete 删除图片
|
|
167
|
+
* @example <u-upload :action="action" :fileList="fileList" ></u-upload>
|
|
168
|
+
*/
|
|
169
|
+
export default {
|
|
170
|
+
name: "u-upload",
|
|
171
|
+
mixins: [uni.$u.mpMixin, uni.$u.mixin, mixin,props],
|
|
172
|
+
data() {
|
|
173
|
+
return {
|
|
174
|
+
// #ifdef APP-NVUE
|
|
175
|
+
successIcon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAAXNSR0IArs4c6QAAAERlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAKKADAAQAAAABAAAAKAAAAAB65masAAACP0lEQVRYCc3YXygsURwH8K/dpcWyG3LF5u/6/+dKVylSypuUl6uUPMifKMWL8oKEB1EUT1KeUPdR3uTNUsSLxb2udG/cbvInNuvf2rVnazZ/ZndmZ87snjM1Z+Z3zpzfp9+Z5mEAhlvjRtZgCKs+gnPAOcAkkMOR4jEHfItjDvgRxxSQD8cM0BuOCaAvXNCBQrigAsXgggYUiwsK0B9cwIH+4gIKlIILGFAqLiBAOTjFgXJxigJp4BQD0sIpAqSJow6kjSNAFTnRaHJwLenD6Mud52VQAcrBfTd2oyq+HtGaGGWAcnAVcXWoM3bCZrdi+ncPfaAcXE5UKVpdW/vitGPqqAtn98d0gXJwX7Qp6MmegUYVhvmTIezdmHlxJCjpHRTCFerLkRRu4k0aqdajN3sWOo0BK//msHa+xDuPC/oNFMKRhTtM4xjIX0SCNpXL4+7VIaHuyiWEp2L7ahWLf8fejfPdqPmC3mJicORZUp1CQzm+GiphvljGk+PBvWRbxii+xVTj5M6CiZ/tsDufvaXyxEUDxeLIyvu3m0iOyEFWVAkydcVYdyFrE9tQk9iMq6f/GNlvwt3LjQfh60LUrw9/cFyyMJUW/XkLSNMV4Mi6C5ML+ui4x5ClAX9sB9w0wV6wglJwJCv5fOxcr6EstgbGiEw4XcfUry4cWrcEUW8n+ARKxXEJHhw2WG43UKSvwI/TSZgvl7kh0b3XLZaLEy0QmMgLZAVH7J+ALOE+AVnDvQOyiPMAWcW5gSzjCPAV+78S5WE0GrQAAAAASUVORK5CYII=',
|
|
176
|
+
// #endif
|
|
177
|
+
lists: [],
|
|
178
|
+
isInCount: true,
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
watch: {
|
|
182
|
+
// 监听文件列表的变化,重新整理内部数据
|
|
183
|
+
fileList: {
|
|
184
|
+
immediate: true,
|
|
185
|
+
handler() {
|
|
186
|
+
this.formatFileList()
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
methods: {
|
|
191
|
+
formatFileList() {
|
|
192
|
+
const {
|
|
193
|
+
fileList = [], maxCount
|
|
194
|
+
} = this;
|
|
195
|
+
const lists = fileList.map((item) =>
|
|
196
|
+
Object.assign(Object.assign({}, item), {
|
|
197
|
+
// 如果item.url为本地选择的blob文件的话,无法判断其为video还是image,此处优先通过accept做判断处理
|
|
198
|
+
isImage: this.accept === 'image' || uni.$u.test.image(item.url || item.thumb),
|
|
199
|
+
isVideo: this.accept === 'video' || uni.$u.test.video(item.url || item.thumb),
|
|
200
|
+
deletable: typeof(item.deletable) === 'boolean' ? item.deletable : this.deletable,
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
this.lists = lists
|
|
204
|
+
this.isInCount = lists.length < maxCount
|
|
205
|
+
},
|
|
206
|
+
chooseFile() {
|
|
207
|
+
const {
|
|
208
|
+
maxCount,
|
|
209
|
+
multiple,
|
|
210
|
+
lists,
|
|
211
|
+
disabled
|
|
212
|
+
} = this;
|
|
213
|
+
if (disabled) return;
|
|
214
|
+
// 如果用户传入的是字符串,需要格式化成数组
|
|
215
|
+
let capture;
|
|
216
|
+
try {
|
|
217
|
+
capture = uni.$u.test.array(this.capture) ? this.capture : this.capture.split(',');
|
|
218
|
+
}catch(e) {
|
|
219
|
+
capture = [];
|
|
220
|
+
}
|
|
221
|
+
chooseFile(
|
|
222
|
+
Object.assign({
|
|
223
|
+
accept: this.accept,
|
|
224
|
+
multiple: this.multiple,
|
|
225
|
+
capture: capture,
|
|
226
|
+
compressed: this.compressed,
|
|
227
|
+
maxDuration: this.maxDuration,
|
|
228
|
+
sizeType: this.sizeType,
|
|
229
|
+
camera: this.camera,
|
|
230
|
+
}, {
|
|
231
|
+
maxCount: maxCount - lists.length,
|
|
232
|
+
})
|
|
233
|
+
)
|
|
234
|
+
.then((res) => {
|
|
235
|
+
this.onBeforeRead(multiple ? res : res[0]);
|
|
236
|
+
})
|
|
237
|
+
.catch((error) => {
|
|
238
|
+
this.$emit('error', error);
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
// 文件读取之前
|
|
242
|
+
onBeforeRead(file) {
|
|
243
|
+
const {
|
|
244
|
+
beforeRead,
|
|
245
|
+
useBeforeRead,
|
|
246
|
+
} = this;
|
|
247
|
+
let res = true
|
|
248
|
+
// beforeRead是否为一个方法
|
|
249
|
+
if (uni.$u.test.func(beforeRead)) {
|
|
250
|
+
// 如果用户定义了此方法,则去执行此方法,并传入读取的文件回调
|
|
251
|
+
res = beforeRead(file, this.getDetail());
|
|
252
|
+
}
|
|
253
|
+
if (useBeforeRead) {
|
|
254
|
+
res = new Promise((resolve, reject) => {
|
|
255
|
+
this.$emit(
|
|
256
|
+
'beforeRead',
|
|
257
|
+
Object.assign(Object.assign({
|
|
258
|
+
file
|
|
259
|
+
}, this.getDetail()), {
|
|
260
|
+
callback: (ok) => {
|
|
261
|
+
ok ? resolve() : reject();
|
|
262
|
+
},
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
if (!res) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (uni.$u.test.promise(res)) {
|
|
271
|
+
res.then((data) => this.onAfterRead(data || file));
|
|
272
|
+
} else {
|
|
273
|
+
this.onAfterRead(file);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
getDetail(index) {
|
|
277
|
+
return {
|
|
278
|
+
name: this.name,
|
|
279
|
+
index: index == null ? this.fileList.length : index,
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
onAfterRead(file) {
|
|
283
|
+
const {
|
|
284
|
+
maxSize,
|
|
285
|
+
afterRead
|
|
286
|
+
} = this;
|
|
287
|
+
const oversize = Array.isArray(file) ?
|
|
288
|
+
file.some((item) => item.size > maxSize) :
|
|
289
|
+
file.size > maxSize;
|
|
290
|
+
if (oversize) {
|
|
291
|
+
this.$emit('oversize', Object.assign({
|
|
292
|
+
file
|
|
293
|
+
}, this.getDetail()));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (typeof afterRead === 'function') {
|
|
297
|
+
afterRead(file, this.getDetail());
|
|
298
|
+
}
|
|
299
|
+
this.$emit('afterRead', Object.assign({
|
|
300
|
+
file
|
|
301
|
+
}, this.getDetail()));
|
|
302
|
+
},
|
|
303
|
+
deleteItem(index) {
|
|
304
|
+
this.$emit(
|
|
305
|
+
'delete',
|
|
306
|
+
Object.assign(Object.assign({}, this.getDetail(index)), {
|
|
307
|
+
file: this.fileList[index],
|
|
308
|
+
})
|
|
309
|
+
);
|
|
310
|
+
},
|
|
311
|
+
// 预览图片
|
|
312
|
+
onPreviewImage(item) {
|
|
313
|
+
if (!item.isImage || !this.previewFullImage) return
|
|
314
|
+
uni.previewImage({
|
|
315
|
+
// 先filter找出为图片的item,再返回filter结果中的图片url
|
|
316
|
+
urls: this.lists.filter((item) => this.accept === 'image' || uni.$u.test.image(item.url || item.thumb)).map((item) => item.url || item.thumb),
|
|
317
|
+
current: item.url || item.thumb,
|
|
318
|
+
fail() {
|
|
319
|
+
uni.$u.toast('预览图片失败')
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
onPreviewVideo(event) {
|
|
324
|
+
if (!this.data.previewFullImage) return;
|
|
325
|
+
const {
|
|
326
|
+
index
|
|
327
|
+
} = event.currentTarget.dataset;
|
|
328
|
+
const {
|
|
329
|
+
lists
|
|
330
|
+
} = this.data;
|
|
331
|
+
wx.previewMedia({
|
|
332
|
+
sources: lists
|
|
333
|
+
.filter((item) => isVideoFile(item))
|
|
334
|
+
.map((item) =>
|
|
335
|
+
Object.assign(Object.assign({}, item), {
|
|
336
|
+
type: 'video'
|
|
337
|
+
})
|
|
338
|
+
),
|
|
339
|
+
current: index,
|
|
340
|
+
fail() {
|
|
341
|
+
uni.$u.toast('预览视频失败')
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
},
|
|
345
|
+
onClickPreview(event) {
|
|
346
|
+
const {
|
|
347
|
+
index
|
|
348
|
+
} = event.currentTarget.dataset;
|
|
349
|
+
const item = this.data.lists[index];
|
|
350
|
+
this.$emit(
|
|
351
|
+
'clickPreview',
|
|
352
|
+
Object.assign(Object.assign({}, item), this.getDetail(index))
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
</script>
|
|
358
|
+
|
|
359
|
+
<style lang="scss" scoped>
|
|
360
|
+
@import '../../libs/css/components.scss';
|
|
361
|
+
$u-upload-preview-border-radius: 2px !default;
|
|
362
|
+
$u-upload-preview-margin: 0 8px 8px 0 !default;
|
|
363
|
+
$u-upload-image-width:80px !default;
|
|
364
|
+
$u-upload-image-height:$u-upload-image-width;
|
|
365
|
+
$u-upload-other-bgColor: rgb(242, 242, 242) !default;
|
|
366
|
+
$u-upload-other-flex:1 !default;
|
|
367
|
+
$u-upload-text-font-size:11px !default;
|
|
368
|
+
$u-upload-text-color:$u-tips-color !default;
|
|
369
|
+
$u-upload-text-margin-top:2px !default;
|
|
370
|
+
$u-upload-deletable-right:0 !default;
|
|
371
|
+
$u-upload-deletable-top:0 !default;
|
|
372
|
+
$u-upload-deletable-bgColor:rgb(55, 55, 55) !default;
|
|
373
|
+
$u-upload-deletable-height:14px !default;
|
|
374
|
+
$u-upload-deletable-width:$u-upload-deletable-height;
|
|
375
|
+
$u-upload-deletable-boder-bottom-left-radius:100px !default;
|
|
376
|
+
$u-upload-deletable-zIndex:3 !default;
|
|
377
|
+
$u-upload-success-bottom:0 !default;
|
|
378
|
+
$u-upload-success-right:0 !default;
|
|
379
|
+
$u-upload-success-border-style:solid !default;
|
|
380
|
+
$u-upload-success-border-top-color:transparent !default;
|
|
381
|
+
$u-upload-success-border-left-color:transparent !default;
|
|
382
|
+
$u-upload-success-border-bottom-color: $u-success !default;
|
|
383
|
+
$u-upload-success-border-right-color:$u-upload-success-border-bottom-color;
|
|
384
|
+
$u-upload-success-border-width:9px !default;
|
|
385
|
+
$u-upload-icon-top:0px !default;
|
|
386
|
+
$u-upload-icon-right:0px !default;
|
|
387
|
+
$u-upload-icon-h5-top:1px !default;
|
|
388
|
+
$u-upload-icon-h5-right:0 !default;
|
|
389
|
+
$u-upload-icon-width:16px !default;
|
|
390
|
+
$u-upload-icon-height:$u-upload-icon-width;
|
|
391
|
+
$u-upload-success-icon-bottom:-10px !default;
|
|
392
|
+
$u-upload-success-icon-right:-10px !default;
|
|
393
|
+
$u-upload-status-right:0 !default;
|
|
394
|
+
$u-upload-status-left:0 !default;
|
|
395
|
+
$u-upload-status-bottom:0 !default;
|
|
396
|
+
$u-upload-status-top:0 !default;
|
|
397
|
+
$u-upload-status-bgColor:rgba(0, 0, 0, 0.5) !default;
|
|
398
|
+
$u-upload-status-icon-Zindex:1 !default;
|
|
399
|
+
$u-upload-message-font-size:12px !default;
|
|
400
|
+
$u-upload-message-color:#FFFFFF !default;
|
|
401
|
+
$u-upload-message-margin-top:5px !default;
|
|
402
|
+
$u-upload-button-width:80px !default;
|
|
403
|
+
$u-upload-button-height:$u-upload-button-width;
|
|
404
|
+
$u-upload-button-bgColor:rgb(244, 245, 247) !default;
|
|
405
|
+
$u-upload-button-border-radius:2px !default;
|
|
406
|
+
$u-upload-botton-margin: 0 8px 8px 0 !default;
|
|
407
|
+
$u-upload-text-font-size:11px !default;
|
|
408
|
+
$u-upload-text-color:$u-tips-color !default;
|
|
409
|
+
$u-upload-text-margin-top: 2px !default;
|
|
410
|
+
$u-upload-hover-bgColor:rgb(230, 231, 233) !default;
|
|
411
|
+
$u-upload-disabled-opacity:.5 !default;
|
|
412
|
+
|
|
413
|
+
.u-upload {
|
|
414
|
+
@include flex(column);
|
|
415
|
+
flex: 1;
|
|
416
|
+
|
|
417
|
+
&__wrap {
|
|
418
|
+
@include flex;
|
|
419
|
+
flex-wrap: wrap;
|
|
420
|
+
flex: 1;
|
|
421
|
+
|
|
422
|
+
&__preview {
|
|
423
|
+
border-radius: $u-upload-preview-border-radius;
|
|
424
|
+
margin: $u-upload-preview-margin;
|
|
425
|
+
position: relative;
|
|
426
|
+
overflow: hidden;
|
|
427
|
+
@include flex;
|
|
428
|
+
|
|
429
|
+
&__image {
|
|
430
|
+
width: $u-upload-image-width;
|
|
431
|
+
height: $u-upload-image-height;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
&__other {
|
|
435
|
+
width: $u-upload-image-width;
|
|
436
|
+
height: $u-upload-image-height;
|
|
437
|
+
background-color: $u-upload-other-bgColor;
|
|
438
|
+
flex: $u-upload-other-flex;
|
|
439
|
+
@include flex(column);
|
|
440
|
+
justify-content: center;
|
|
441
|
+
align-items: center;
|
|
442
|
+
|
|
443
|
+
&__text {
|
|
444
|
+
font-size: $u-upload-text-font-size;
|
|
445
|
+
color: $u-upload-text-color;
|
|
446
|
+
margin-top: $u-upload-text-margin-top;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
&__deletable {
|
|
453
|
+
position: absolute;
|
|
454
|
+
top: $u-upload-deletable-top;
|
|
455
|
+
right: $u-upload-deletable-right;
|
|
456
|
+
background-color: $u-upload-deletable-bgColor;
|
|
457
|
+
height: $u-upload-deletable-height;
|
|
458
|
+
width: $u-upload-deletable-width;
|
|
459
|
+
@include flex;
|
|
460
|
+
border-bottom-left-radius: $u-upload-deletable-boder-bottom-left-radius;
|
|
461
|
+
align-items: center;
|
|
462
|
+
justify-content: center;
|
|
463
|
+
z-index: $u-upload-deletable-zIndex;
|
|
464
|
+
|
|
465
|
+
&__icon {
|
|
466
|
+
position: absolute;
|
|
467
|
+
transform: scale(0.7);
|
|
468
|
+
top: $u-upload-icon-top;
|
|
469
|
+
right: $u-upload-icon-right;
|
|
470
|
+
/* #ifdef H5 */
|
|
471
|
+
top: $u-upload-icon-h5-top;
|
|
472
|
+
right: $u-upload-icon-h5-right;
|
|
473
|
+
/* #endif */
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
&__success {
|
|
478
|
+
position: absolute;
|
|
479
|
+
bottom: $u-upload-success-bottom;
|
|
480
|
+
right: $u-upload-success-right;
|
|
481
|
+
@include flex;
|
|
482
|
+
// 由于weex(nvue)为阿里巴巴的KPI(部门业绩考核)的laji产物,不支持css绘制三角形
|
|
483
|
+
// 所以在nvue下使用图片,非nvue下使用css实现
|
|
484
|
+
/* #ifndef APP-NVUE */
|
|
485
|
+
border-style: $u-upload-success-border-style;
|
|
486
|
+
border-top-color: $u-upload-success-border-top-color;
|
|
487
|
+
border-left-color: $u-upload-success-border-left-color;
|
|
488
|
+
border-bottom-color: $u-upload-success-border-bottom-color;
|
|
489
|
+
border-right-color: $u-upload-success-border-right-color;
|
|
490
|
+
border-width: $u-upload-success-border-width;
|
|
491
|
+
align-items: center;
|
|
492
|
+
justify-content: center;
|
|
493
|
+
/* #endif */
|
|
494
|
+
|
|
495
|
+
&__icon {
|
|
496
|
+
/* #ifndef APP-NVUE */
|
|
497
|
+
position: absolute;
|
|
498
|
+
transform: scale(0.7);
|
|
499
|
+
bottom: $u-upload-success-icon-bottom;
|
|
500
|
+
right: $u-upload-success-icon-right;
|
|
501
|
+
/* #endif */
|
|
502
|
+
/* #ifdef APP-NVUE */
|
|
503
|
+
width: $u-upload-icon-width;
|
|
504
|
+
height: $u-upload-icon-height;
|
|
505
|
+
/* #endif */
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
&__status {
|
|
510
|
+
position: absolute;
|
|
511
|
+
top: $u-upload-status-top;
|
|
512
|
+
bottom: $u-upload-status-bottom;
|
|
513
|
+
left: $u-upload-status-left;
|
|
514
|
+
right: $u-upload-status-right;
|
|
515
|
+
background-color: $u-upload-status-bgColor;
|
|
516
|
+
@include flex(column);
|
|
517
|
+
align-items: center;
|
|
518
|
+
justify-content: center;
|
|
519
|
+
|
|
520
|
+
&__icon {
|
|
521
|
+
position: relative;
|
|
522
|
+
z-index: $u-upload-status-icon-Zindex;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
&__message {
|
|
526
|
+
font-size: $u-upload-message-font-size;
|
|
527
|
+
color: $u-upload-message-color;
|
|
528
|
+
margin-top: $u-upload-message-margin-top;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
&__default-slot {
|
|
533
|
+
&--empty-list {
|
|
534
|
+
flex: 1;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
&__button {
|
|
539
|
+
@include flex(column);
|
|
540
|
+
align-items: center;
|
|
541
|
+
justify-content: center;
|
|
542
|
+
width: $u-upload-button-width;
|
|
543
|
+
height: $u-upload-button-height;
|
|
544
|
+
background-color: $u-upload-button-bgColor;
|
|
545
|
+
border-radius: $u-upload-button-border-radius;
|
|
546
|
+
margin: $u-upload-botton-margin;
|
|
547
|
+
/* #ifndef APP-NVUE */
|
|
548
|
+
box-sizing: border-box;
|
|
549
|
+
/* #endif */
|
|
550
|
+
|
|
551
|
+
&__text {
|
|
552
|
+
font-size: $u-upload-text-font-size;
|
|
553
|
+
color: $u-upload-text-color;
|
|
554
|
+
margin-top: $u-upload-text-margin-top;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
&--hover {
|
|
558
|
+
background-color: $u-upload-hover-bgColor;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
&--disabled {
|
|
562
|
+
opacity: $u-upload-disabled-opacity;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
</style>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
function pickExclude(obj, keys) {
|
|
2
|
+
// 某些情况下,type可能会为
|
|
3
|
+
if (!['[object Object]', '[object File]'].includes(Object.prototype.toString.call(obj))) {
|
|
4
|
+
return {}
|
|
5
|
+
}
|
|
6
|
+
return Object.keys(obj).reduce((prev, key) => {
|
|
7
|
+
if (!keys.includes(key)) {
|
|
8
|
+
prev[key] = obj[key]
|
|
9
|
+
}
|
|
10
|
+
return prev
|
|
11
|
+
}, {})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function formatImage(res) {
|
|
15
|
+
return res.tempFiles.map((item) => ({
|
|
16
|
+
...pickExclude(item, ['path']),
|
|
17
|
+
type: 'image',
|
|
18
|
+
url: item.path,
|
|
19
|
+
thumb: item.path,
|
|
20
|
+
size: item.size,
|
|
21
|
+
// #ifdef H5
|
|
22
|
+
name: item.name
|
|
23
|
+
// #endif
|
|
24
|
+
}))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function formatVideo(res) {
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
...pickExclude(res, ['tempFilePath', 'thumbTempFilePath', 'errMsg']),
|
|
31
|
+
type: 'video',
|
|
32
|
+
url: res.tempFilePath,
|
|
33
|
+
thumb: res.thumbTempFilePath,
|
|
34
|
+
size: res.size,
|
|
35
|
+
// #ifdef H5
|
|
36
|
+
name: res.name
|
|
37
|
+
// #endif
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function formatMedia(res) {
|
|
43
|
+
return res.tempFiles.map((item) => ({
|
|
44
|
+
...pickExclude(item, ['fileType', 'thumbTempFilePath', 'tempFilePath']),
|
|
45
|
+
type: res.type,
|
|
46
|
+
url: item.tempFilePath,
|
|
47
|
+
thumb: res.type === 'video' ? item.thumbTempFilePath : item.tempFilePath,
|
|
48
|
+
size: item.size
|
|
49
|
+
}))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatFile(res) {
|
|
53
|
+
return res.tempFiles.map((item) => ({
|
|
54
|
+
...pickExclude(item, ['path']),
|
|
55
|
+
url: item.path,
|
|
56
|
+
size:item.size,
|
|
57
|
+
// #ifdef H5
|
|
58
|
+
name: item.name,
|
|
59
|
+
type: item.type
|
|
60
|
+
// #endif
|
|
61
|
+
}))
|
|
62
|
+
}
|
|
63
|
+
export function chooseFile({
|
|
64
|
+
accept,
|
|
65
|
+
multiple,
|
|
66
|
+
capture,
|
|
67
|
+
compressed,
|
|
68
|
+
maxDuration,
|
|
69
|
+
sizeType,
|
|
70
|
+
camera,
|
|
71
|
+
maxCount
|
|
72
|
+
}) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
switch (accept) {
|
|
75
|
+
case 'image':
|
|
76
|
+
uni.chooseImage({
|
|
77
|
+
count: multiple ? Math.min(maxCount, 9) : 1,
|
|
78
|
+
sourceType: capture,
|
|
79
|
+
sizeType,
|
|
80
|
+
success: (res) => resolve(formatImage(res)),
|
|
81
|
+
fail: reject
|
|
82
|
+
})
|
|
83
|
+
break
|
|
84
|
+
// #ifdef MP-WEIXIN
|
|
85
|
+
// 只有微信小程序才支持chooseMedia接口
|
|
86
|
+
case 'media':
|
|
87
|
+
wx.chooseMedia({
|
|
88
|
+
count: multiple ? Math.min(maxCount, 9) : 1,
|
|
89
|
+
sourceType: capture,
|
|
90
|
+
maxDuration,
|
|
91
|
+
sizeType,
|
|
92
|
+
camera,
|
|
93
|
+
success: (res) => resolve(formatMedia(res)),
|
|
94
|
+
fail: reject
|
|
95
|
+
})
|
|
96
|
+
break
|
|
97
|
+
// #endif
|
|
98
|
+
case 'video':
|
|
99
|
+
uni.chooseVideo({
|
|
100
|
+
sourceType: capture,
|
|
101
|
+
compressed,
|
|
102
|
+
maxDuration,
|
|
103
|
+
camera,
|
|
104
|
+
success: (res) => resolve(formatVideo(res)),
|
|
105
|
+
fail: reject
|
|
106
|
+
})
|
|
107
|
+
break
|
|
108
|
+
// #ifdef MP-WEIXIN || H5
|
|
109
|
+
// 只有微信小程序才支持chooseMessageFile接口
|
|
110
|
+
case 'file':
|
|
111
|
+
// #ifdef MP-WEIXIN
|
|
112
|
+
wx.chooseMessageFile({
|
|
113
|
+
count: multiple ? maxCount : 1,
|
|
114
|
+
type: accept,
|
|
115
|
+
success: (res) => resolve(formatFile(res)),
|
|
116
|
+
fail: reject
|
|
117
|
+
})
|
|
118
|
+
// #endif
|
|
119
|
+
// #ifdef H5
|
|
120
|
+
// 需要hx2.9.9以上才支持uni.chooseFile
|
|
121
|
+
uni.chooseFile({
|
|
122
|
+
count: multiple ? maxCount : 1,
|
|
123
|
+
type: accept,
|
|
124
|
+
success: (res) => resolve(formatFile(res)),
|
|
125
|
+
fail: reject
|
|
126
|
+
})
|
|
127
|
+
// #endif
|
|
128
|
+
break
|
|
129
|
+
// #endif
|
|
130
|
+
default:
|
|
131
|
+
// 此为保底选项,在accept不为上面任意一项的时候选取全部文件
|
|
132
|
+
// #ifdef MP-WEIXIN
|
|
133
|
+
wx.chooseMessageFile({
|
|
134
|
+
count: multiple ? maxCount : 1,
|
|
135
|
+
type: 'all',
|
|
136
|
+
success: (res) => resolve(formatFile(res)),
|
|
137
|
+
fail: reject
|
|
138
|
+
})
|
|
139
|
+
// #endif
|
|
140
|
+
// #ifdef H5
|
|
141
|
+
// 需要hx2.9.9以上才支持uni.chooseFile
|
|
142
|
+
uni.chooseFile({
|
|
143
|
+
count: multiple ? maxCount : 1,
|
|
144
|
+
type: 'all',
|
|
145
|
+
success: (res) => resolve(formatFile(res)),
|
|
146
|
+
fail: reject
|
|
147
|
+
})
|
|
148
|
+
// #endif
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
}
|