@kengic/uni 0.5.1 → 0.5.2-beta.1
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/dist/uni/uni-ui/uni-badge/uni-badge.vue +222 -219
- package/dist/uni/uni-ui/uni-breadcrumb/uni-breadcrumb.vue +29 -29
- package/dist/uni/uni-ui/uni-breadcrumb-item/uni-breadcrumb-item.vue +88 -88
- package/dist/uni/uni-ui/uni-calendar/calendar.js +936 -532
- package/dist/uni/uni-ui/uni-calendar/i18n/en.json +10 -10
- package/dist/uni/uni-ui/uni-calendar/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-calendar/i18n/zh-Hans.json +10 -10
- package/dist/uni/uni-ui/uni-calendar/i18n/zh-Hant.json +10 -10
- package/dist/uni/uni-ui/uni-calendar/uni-calendar-item.vue +190 -168
- package/dist/uni/uni-ui/uni-calendar/uni-calendar.vue +459 -459
- package/dist/uni/uni-ui/uni-calendar/util.js +324 -340
- package/dist/uni/uni-ui/uni-card/uni-card.vue +8 -1
- package/dist/uni/uni-ui/uni-col/uni-col.vue +294 -287
- package/dist/uni/uni-ui/uni-collapse/uni-collapse.vue +139 -140
- package/dist/uni/uni-ui/uni-collapse-item/uni-collapse-item.vue +381 -378
- package/dist/uni/uni-ui/uni-combox/uni-combox.vue +280 -272
- package/dist/uni/uni-ui/uni-countdown/i18n/en.json +4 -4
- package/dist/uni/uni-ui/uni-countdown/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-countdown/i18n/zh-Hans.json +4 -4
- package/dist/uni/uni-ui/uni-countdown/i18n/zh-Hant.json +4 -4
- package/dist/uni/uni-ui/uni-countdown/uni-countdown.vue +249 -257
- package/dist/uni/uni-ui/uni-data-checkbox/uni-data-checkbox.vue +832 -813
- package/dist/uni/uni-ui/uni-data-picker/keypress.js +42 -42
- package/dist/uni/uni-ui/uni-data-picker/uni-data-picker.vue +535 -516
- package/dist/uni/uni-ui/uni-data-pickerview/uni-data-picker.js +623 -618
- package/dist/uni/uni-ui/uni-data-pickerview/uni-data-pickerview.vue +293 -288
- package/dist/uni/uni-ui/uni-data-select/uni-data-select.vue +495 -509
- package/dist/uni/uni-ui/uni-dateformat/date-format.js +181 -184
- package/dist/uni/uni-ui/uni-dateformat/uni-dateformat.vue +81 -82
- package/dist/uni/uni-ui/uni-datetime-picker/calendar-item.vue +176 -170
- package/dist/uni/uni-ui/uni-datetime-picker/calendar.vue +926 -920
- package/dist/uni/uni-ui/uni-datetime-picker/i18n/en.json +20 -20
- package/dist/uni/uni-ui/uni-datetime-picker/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-datetime-picker/i18n/zh-Hans.json +21 -21
- package/dist/uni/uni-ui/uni-datetime-picker/i18n/zh-Hant.json +21 -21
- package/dist/uni/uni-ui/uni-datetime-picker/time-picker.vue +921 -926
- package/dist/uni/uni-ui/uni-datetime-picker/uni-datetime-picker.vue +1059 -1012
- package/dist/uni/uni-ui/uni-datetime-picker/util.js +366 -377
- package/dist/uni/uni-ui/uni-drawer/keypress.js +42 -42
- package/dist/uni/uni-ui/uni-drawer/uni-drawer.vue +176 -167
- package/dist/uni/uni-ui/uni-easyinput/common.js +40 -42
- package/dist/uni/uni-ui/uni-easyinput/uni-easyinput.vue +628 -547
- package/dist/uni/uni-ui/uni-fab/uni-fab.vue +507 -483
- package/dist/uni/uni-ui/uni-fav/i18n/en.json +2 -2
- package/dist/uni/uni-ui/uni-fav/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-fav/i18n/zh-Hans.json +2 -2
- package/dist/uni/uni-ui/uni-fav/i18n/zh-Hant.json +2 -2
- package/dist/uni/uni-ui/uni-fav/uni-fav.vue +155 -147
- package/dist/uni/uni-ui/uni-file-picker/choose-and-upload-file.js +172 -198
- package/dist/uni/uni-ui/uni-file-picker/uni-file-picker.vue +636 -634
- package/dist/uni/uni-ui/uni-file-picker/upload-file.vue +294 -293
- package/dist/uni/uni-ui/uni-file-picker/upload-image.vue +267 -270
- package/dist/uni/uni-ui/uni-file-picker/utils.js +81 -82
- package/dist/uni/uni-ui/uni-forms/uni-forms.vue +360 -372
- package/dist/uni/uni-ui/uni-forms/utils.js +170 -174
- package/dist/uni/uni-ui/uni-forms/validate.js +447 -456
- package/dist/uni/uni-ui/uni-forms-item/uni-forms-item.vue +497 -497
- package/dist/uni/uni-ui/uni-goods-nav/i18n/en.json +4 -4
- package/dist/uni/uni-ui/uni-goods-nav/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-goods-nav/i18n/zh-Hans.json +4 -4
- package/dist/uni/uni-ui/uni-goods-nav/i18n/zh-Hant.json +4 -4
- package/dist/uni/uni-ui/uni-goods-nav/uni-goods-nav.vue +238 -222
- package/dist/uni/uni-ui/uni-grid/uni-grid.vue +134 -134
- package/dist/uni/uni-ui/uni-grid-item/uni-grid-item.vue +121 -119
- package/dist/uni/uni-ui/uni-group/uni-group.vue +121 -121
- package/dist/uni/uni-ui/uni-icons/icons.js +1170 -1168
- package/dist/uni/uni-ui/uni-icons/uni-icons.vue +91 -86
- package/dist/uni/uni-ui/uni-icons/uniicons.css +166 -166
- package/dist/uni/uni-ui/uni-indexed-list/uni-indexed-list-item.vue +129 -129
- package/dist/uni/uni-ui/uni-indexed-list/uni-indexed-list.vue +352 -347
- package/dist/uni/uni-ui/uni-link/uni-link.vue +134 -119
- package/dist/uni/uni-ui/uni-list/uni-list.vue +119 -110
- package/dist/uni/uni-ui/uni-list/uni-refresh.vue +14 -14
- package/dist/uni/uni-ui/uni-list/uni-refresh.wxs +14 -14
- package/dist/uni/uni-ui/uni-list-ad/uni-list-ad.vue +101 -95
- package/dist/uni/uni-ui/uni-list-chat/uni-list-chat.scss +18 -18
- package/dist/uni/uni-ui/uni-list-chat/uni-list-chat.vue +602 -586
- package/dist/uni/uni-ui/uni-list-item/uni-list-item.vue +507 -503
- package/dist/uni/uni-ui/uni-load-more/i18n/en.json +3 -3
- package/dist/uni/uni-ui/uni-load-more/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-load-more/i18n/zh-Hans.json +3 -3
- package/dist/uni/uni-ui/uni-load-more/i18n/zh-Hant.json +3 -3
- package/dist/uni/uni-ui/uni-load-more/uni-load-more.vue +402 -392
- package/dist/uni/uni-ui/uni-nav-bar/uni-nav-bar.vue +328 -330
- package/dist/uni/uni-ui/uni-nav-bar/uni-status-bar.vue +17 -17
- package/dist/uni/uni-ui/uni-notice-bar/uni-notice-bar.vue +422 -401
- package/dist/uni/uni-ui/uni-number-box/uni-number-box.vue +211 -205
- package/dist/uni/uni-ui/uni-pagination/i18n/en.json +3 -3
- package/dist/uni/uni-ui/uni-pagination/i18n/es.json +3 -3
- package/dist/uni/uni-ui/uni-pagination/i18n/fr.json +3 -3
- package/dist/uni/uni-ui/uni-pagination/i18n/index.js +12 -11
- package/dist/uni/uni-ui/uni-pagination/i18n/zh-Hans.json +3 -3
- package/dist/uni/uni-ui/uni-pagination/i18n/zh-Hant.json +3 -3
- package/dist/uni/uni-ui/uni-pagination/uni-pagination.vue +450 -433
- package/dist/uni/uni-ui/uni-popup/uni-popup.vue +404 -404
- package/dist/uni/uni-ui/uni-popup-dialog/keypress.js +42 -42
- package/dist/uni/uni-ui/uni-popup-dialog/uni-popup-dialog.vue +1 -0
- package/dist/uni/uni-ui/uni-popup-message/uni-popup-message.vue +126 -125
- package/dist/uni/uni-ui/uni-popup-share/uni-popup-share.vue +172 -172
- package/dist/uni/uni-ui/uni-rate/uni-rate.vue +343 -347
- package/dist/uni/uni-ui/uni-row/uni-row.vue +180 -182
- package/dist/uni/uni-ui/uni-scss/changelog.md +11 -4
- package/dist/uni/uni-ui/uni-scss/package.json +73 -73
- package/dist/uni/uni-ui/uni-scss/readme.md +2 -1
- package/dist/uni/uni-ui/uni-scss/styles/setting/_border.scss +2 -2
- package/dist/uni/uni-ui/uni-scss/styles/setting/_color.scss +46 -47
- package/dist/uni/uni-ui/uni-scss/styles/setting/_radius.scss +49 -49
- package/dist/uni/uni-ui/uni-scss/styles/setting/_space.scss +52 -53
- package/dist/uni/uni-ui/uni-scss/styles/setting/_styles.scss +142 -147
- package/dist/uni/uni-ui/uni-scss/styles/setting/_text.scss +20 -20
- package/dist/uni/uni-ui/uni-scss/styles/setting/_variables.scss +111 -95
- package/dist/uni/uni-ui/uni-scss/styles/tools/functions.scss +28 -18
- package/dist/uni/uni-ui/uni-scss/theme.scss +10 -7
- package/dist/uni/uni-ui/uni-scss/variables.scss +42 -24
- package/dist/uni/uni-ui/uni-search-bar/i18n/en.json +3 -3
- package/dist/uni/uni-ui/uni-search-bar/i18n/index.js +8 -7
- package/dist/uni/uni-ui/uni-search-bar/i18n/zh-Hans.json +2 -2
- package/dist/uni/uni-ui/uni-search-bar/i18n/zh-Hant.json +2 -2
- package/dist/uni/uni-ui/uni-search-bar/uni-search-bar.vue +290 -281
- package/dist/uni/uni-ui/uni-section/uni-section.vue +149 -146
- package/dist/uni/uni-ui/uni-segmented-control/uni-segmented-control.vue +141 -131
- package/dist/uni/uni-ui/uni-steps/uni-steps.vue +255 -236
- package/dist/uni/uni-ui/uni-swipe-action/uni-swipe-action.vue +51 -51
- package/dist/uni/uni-ui/uni-swipe-action-item/bindingx.js +276 -282
- package/dist/uni/uni-ui/uni-swipe-action-item/isPC.js +10 -10
- package/dist/uni/uni-ui/uni-swipe-action-item/mpalipay.js +182 -187
- package/dist/uni/uni-ui/uni-swipe-action-item/mpother.js +235 -244
- package/dist/uni/uni-ui/uni-swipe-action-item/mpwxs.js +70 -75
- package/dist/uni/uni-ui/uni-swipe-action-item/render.js +238 -247
- package/dist/uni/uni-ui/uni-swipe-action-item/uni-swipe-action-item.vue +387 -313
- package/dist/uni/uni-ui/uni-swipe-action-item/wx.wxs +206 -215
- package/dist/uni/uni-ui/uni-swiper-dot/uni-swiper-dot.vue +241 -197
- package/dist/uni/uni-ui/uni-table/uni-table.vue +445 -447
- package/dist/uni/uni-ui/uni-tag/uni-tag.vue +234 -244
- package/dist/uni/uni-ui/uni-tbody/uni-tbody.vue +20 -23
- package/dist/uni/uni-ui/uni-td/uni-td.vue +79 -80
- package/dist/uni/uni-ui/uni-th/filter-dropdown.vue +510 -503
- package/dist/uni/uni-ui/uni-th/uni-th.vue +289 -273
- package/dist/uni/uni-ui/uni-thead/uni-thead.vue +115 -114
- package/dist/uni/uni-ui/uni-title/uni-title.vue +151 -154
- package/dist/uni/uni-ui/uni-tooltip/uni-tooltip.vue +55 -60
- package/dist/uni/uni-ui/uni-tr/table-checkbox.vue +162 -163
- package/dist/uni/uni-ui/uni-tr/uni-tr.vue +158 -157
- package/dist/uni/uni-ui/uni-transition/createAnimation.js +130 -113
- package/dist/uni/uni-ui/uni-transition/uni-transition.vue +274 -272
- package/package.json +1 -1
|
@@ -1,667 +1,669 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
<view class="uni-file-picker">
|
|
3
|
+
<view v-if="title" class="uni-file-picker__header">
|
|
4
|
+
<text class="file-title">{{ title }}</text>
|
|
5
|
+
<text class="file-count">{{ filesList.length }}/{{ limitLength }}</text>
|
|
6
|
+
</view>
|
|
7
|
+
<upload-image
|
|
8
|
+
v-if="fileMediatype === 'image' && showType === 'grid'"
|
|
9
|
+
:readonly="readonly"
|
|
10
|
+
:image-styles="imageStyles"
|
|
11
|
+
:files-list="filesList"
|
|
12
|
+
:limit="limitLength"
|
|
13
|
+
:disablePreview="disablePreview"
|
|
14
|
+
:delIcon="delIcon"
|
|
15
|
+
@uploadFiles="uploadFiles"
|
|
16
|
+
@choose="choose"
|
|
17
|
+
@delFile="delFile"
|
|
18
|
+
>
|
|
19
|
+
<slot>
|
|
20
|
+
<view class="is-add">
|
|
21
|
+
<view class="icon-add"></view>
|
|
22
|
+
<view class="icon-add rotate"></view>
|
|
23
|
+
</view>
|
|
24
|
+
</slot>
|
|
25
|
+
</upload-image>
|
|
26
|
+
<upload-file
|
|
27
|
+
v-if="fileMediatype !== 'image' || showType !== 'grid'"
|
|
28
|
+
:readonly="readonly"
|
|
29
|
+
:list-styles="listStyles"
|
|
30
|
+
:files-list="filesList"
|
|
31
|
+
:showType="showType"
|
|
32
|
+
:delIcon="delIcon"
|
|
33
|
+
@uploadFiles="uploadFiles"
|
|
34
|
+
@choose="choose"
|
|
35
|
+
@delFile="delFile"
|
|
36
|
+
>
|
|
37
|
+
<slot><button type="primary" size="mini">选择文件</button></slot>
|
|
38
|
+
</upload-file>
|
|
39
|
+
</view>
|
|
23
40
|
</template>
|
|
24
41
|
|
|
25
42
|
<script>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
import {
|
|
31
|
-
get_file_ext,
|
|
32
|
-
get_extname,
|
|
33
|
-
get_files_and_is_max,
|
|
34
|
-
get_file_info,
|
|
35
|
-
get_file_data
|
|
36
|
-
} from './utils.js'
|
|
37
|
-
import uploadImage from './upload-image.vue'
|
|
38
|
-
import uploadFile from './upload-file.vue'
|
|
39
|
-
let fileInput = null
|
|
40
|
-
/**
|
|
41
|
-
* FilePicker 文件选择上传
|
|
42
|
-
* @description 文件选择上传组件,可以选择图片、视频等任意文件并上传到当前绑定的服务空间
|
|
43
|
-
* @tutorial https://ext.dcloud.net.cn/plugin?id=4079
|
|
44
|
-
* @property {Object|Array} value 组件数据,通常用来回显 ,类型由return-type属性决定
|
|
45
|
-
* @property {Boolean} disabled = [true|false] 组件禁用
|
|
46
|
-
* @value true 禁用
|
|
47
|
-
* @value false 取消禁用
|
|
48
|
-
* @property {Boolean} readonly = [true|false] 组件只读,不可选择,不显示进度,不显示删除按钮
|
|
49
|
-
* @value true 只读
|
|
50
|
-
* @value false 取消只读
|
|
51
|
-
* @property {String} return-type = [array|object] 限制 value 格式,当为 object 时 ,组件只能单选,且会覆盖
|
|
52
|
-
* @value array 规定 value 属性的类型为数组
|
|
53
|
-
* @value object 规定 value 属性的类型为对象
|
|
54
|
-
* @property {Boolean} disable-preview = [true|false] 禁用图片预览,仅 mode:grid 时生效
|
|
55
|
-
* @value true 禁用图片预览
|
|
56
|
-
* @value false 取消禁用图片预览
|
|
57
|
-
* @property {Boolean} del-icon = [true|false] 是否显示删除按钮
|
|
58
|
-
* @value true 显示删除按钮
|
|
59
|
-
* @value false 不显示删除按钮
|
|
60
|
-
* @property {Boolean} auto-upload = [true|false] 是否自动上传,值为true则只触发@select,可自行上传
|
|
61
|
-
* @value true 自动上传
|
|
62
|
-
* @value false 取消自动上传
|
|
63
|
-
* @property {Number|String} limit 最大选择个数 ,h5 会自动忽略多选的部分
|
|
64
|
-
* @property {String} title 组件标题,右侧显示上传计数
|
|
65
|
-
* @property {String} mode = [list|grid] 选择文件后的文件列表样式
|
|
66
|
-
* @value list 列表显示
|
|
67
|
-
* @value grid 宫格显示
|
|
68
|
-
* @property {String} file-mediatype = [image|video|all] 选择文件类型
|
|
69
|
-
* @value image 只选择图片
|
|
70
|
-
* @value video 只选择视频
|
|
71
|
-
* @value all 选择所有文件
|
|
72
|
-
* @property {Array} file-extname 选择文件后缀,根据 file-mediatype 属性而不同
|
|
73
|
-
* @property {Object} list-style mode:list 时的样式
|
|
74
|
-
* @property {Object} image-styles 选择文件后缀,根据 file-mediatype 属性而不同
|
|
75
|
-
* @event {Function} select 选择文件后触发
|
|
76
|
-
* @event {Function} progress 文件上传时触发
|
|
77
|
-
* @event {Function} success 上传成功触发
|
|
78
|
-
* @event {Function} fail 上传失败触发
|
|
79
|
-
* @event {Function} delete 文件从列表移除时触发
|
|
80
|
-
*/
|
|
81
|
-
export default {
|
|
82
|
-
name: 'uniFilePicker',
|
|
83
|
-
components: {
|
|
84
|
-
uploadImage,
|
|
85
|
-
uploadFile
|
|
86
|
-
},
|
|
87
|
-
options: {
|
|
88
|
-
virtualHost: true
|
|
89
|
-
},
|
|
90
|
-
emits: ['select', 'success', 'fail', 'progress', 'delete', 'update:modelValue', 'input'],
|
|
91
|
-
props: {
|
|
92
|
-
// #ifdef VUE3
|
|
93
|
-
modelValue: {
|
|
94
|
-
type: [Array, Object],
|
|
95
|
-
default () {
|
|
96
|
-
return []
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
// #endif
|
|
43
|
+
import { chooseAndUploadFile, uploadCloudFiles } from './choose-and-upload-file.js';
|
|
44
|
+
import { get_extname, get_file_data, get_files_and_is_max } from './utils.js';
|
|
45
|
+
import uploadImage from './upload-image.vue';
|
|
46
|
+
import uploadFile from './upload-file.vue';
|
|
100
47
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
48
|
+
let fileInput = null;
|
|
49
|
+
/**
|
|
50
|
+
* FilePicker 文件选择上传
|
|
51
|
+
* @description 文件选择上传组件,可以选择图片、视频等任意文件并上传到当前绑定的服务空间
|
|
52
|
+
* @tutorial https://ext.dcloud.net.cn/plugin?id=4079
|
|
53
|
+
* @property {Object|Array} value 组件数据,通常用来回显 ,类型由return-type属性决定
|
|
54
|
+
* @property {Boolean} disabled = [true|false] 组件禁用
|
|
55
|
+
* @value true 禁用
|
|
56
|
+
* @value false 取消禁用
|
|
57
|
+
* @property {Boolean} readonly = [true|false] 组件只读,不可选择,不显示进度,不显示删除按钮
|
|
58
|
+
* @value true 只读
|
|
59
|
+
* @value false 取消只读
|
|
60
|
+
* @property {String} return-type = [array|object] 限制 value 格式,当为 object 时 ,组件只能单选,且会覆盖
|
|
61
|
+
* @value array 规定 value 属性的类型为数组
|
|
62
|
+
* @value object 规定 value 属性的类型为对象
|
|
63
|
+
* @property {Boolean} disable-preview = [true|false] 禁用图片预览,仅 mode:grid 时生效
|
|
64
|
+
* @value true 禁用图片预览
|
|
65
|
+
* @value false 取消禁用图片预览
|
|
66
|
+
* @property {Boolean} del-icon = [true|false] 是否显示删除按钮
|
|
67
|
+
* @value true 显示删除按钮
|
|
68
|
+
* @value false 不显示删除按钮
|
|
69
|
+
* @property {Boolean} auto-upload = [true|false] 是否自动上传,值为true则只触发@select,可自行上传
|
|
70
|
+
* @value true 自动上传
|
|
71
|
+
* @value false 取消自动上传
|
|
72
|
+
* @property {Number|String} limit 最大选择个数 ,h5 会自动忽略多选的部分
|
|
73
|
+
* @property {String} title 组件标题,右侧显示上传计数
|
|
74
|
+
* @property {String} mode = [list|grid] 选择文件后的文件列表样式
|
|
75
|
+
* @value list 列表显示
|
|
76
|
+
* @value grid 宫格显示
|
|
77
|
+
* @property {String} file-mediatype = [image|video|all] 选择文件类型
|
|
78
|
+
* @value image 只选择图片
|
|
79
|
+
* @value video 只选择视频
|
|
80
|
+
* @value all 选择所有文件
|
|
81
|
+
* @property {Array} file-extname 选择文件后缀,根据 file-mediatype 属性而不同
|
|
82
|
+
* @property {Object} list-style mode:list 时的样式
|
|
83
|
+
* @property {Object} image-styles 选择文件后缀,根据 file-mediatype 属性而不同
|
|
84
|
+
* @event {Function} select 选择文件后触发
|
|
85
|
+
* @event {Function} progress 文件上传时触发
|
|
86
|
+
* @event {Function} success 上传成功触发
|
|
87
|
+
* @event {Function} fail 上传失败触发
|
|
88
|
+
* @event {Function} delete 文件从列表移除时触发
|
|
89
|
+
*/
|
|
90
|
+
export default {
|
|
91
|
+
name: 'uniFilePicker',
|
|
92
|
+
components: {
|
|
93
|
+
uploadImage,
|
|
94
|
+
uploadFile,
|
|
95
|
+
},
|
|
96
|
+
options: {
|
|
97
|
+
virtualHost: true,
|
|
98
|
+
},
|
|
99
|
+
emits: ['select', 'success', 'fail', 'progress', 'delete', 'update:modelValue', 'input'],
|
|
100
|
+
props: {
|
|
101
|
+
// #ifdef VUE3
|
|
102
|
+
modelValue: {
|
|
103
|
+
type: [Array, Object],
|
|
104
|
+
default() {
|
|
105
|
+
return [];
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
// #endif
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
delIcon: {
|
|
119
|
-
type: Boolean,
|
|
120
|
-
default: true
|
|
121
|
-
},
|
|
122
|
-
// 自动上传
|
|
123
|
-
autoUpload: {
|
|
124
|
-
type: Boolean,
|
|
125
|
-
default: true
|
|
126
|
-
},
|
|
127
|
-
// 最大选择个数 ,h5只能限制单选或是多选
|
|
128
|
-
limit: {
|
|
129
|
-
type: [Number, String],
|
|
130
|
-
default: 9
|
|
131
|
-
},
|
|
132
|
-
// 列表样式 grid | list | list-card
|
|
133
|
-
mode: {
|
|
134
|
-
type: String,
|
|
135
|
-
default: 'grid'
|
|
136
|
-
},
|
|
137
|
-
// 选择文件类型 image/video/all
|
|
138
|
-
fileMediatype: {
|
|
139
|
-
type: String,
|
|
140
|
-
default: 'image'
|
|
141
|
-
},
|
|
142
|
-
// 文件类型筛选
|
|
143
|
-
fileExtname: {
|
|
144
|
-
type: [Array, String],
|
|
145
|
-
default () {
|
|
146
|
-
return []
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
title: {
|
|
150
|
-
type: String,
|
|
151
|
-
default: ''
|
|
152
|
-
},
|
|
153
|
-
listStyles: {
|
|
154
|
-
type: Object,
|
|
155
|
-
default () {
|
|
156
|
-
return {
|
|
157
|
-
// 是否显示边框
|
|
158
|
-
border: true,
|
|
159
|
-
// 是否显示分隔线
|
|
160
|
-
dividline: true,
|
|
161
|
-
// 线条样式
|
|
162
|
-
borderStyle: {}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
imageStyles: {
|
|
167
|
-
type: Object,
|
|
168
|
-
default () {
|
|
169
|
-
return {
|
|
170
|
-
width: 'auto',
|
|
171
|
-
height: 'auto'
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
readonly: {
|
|
176
|
-
type: Boolean,
|
|
177
|
-
default: false
|
|
178
|
-
},
|
|
179
|
-
returnType: {
|
|
180
|
-
type: String,
|
|
181
|
-
default: 'array'
|
|
182
|
-
},
|
|
183
|
-
sizeType: {
|
|
184
|
-
type: Array,
|
|
185
|
-
default () {
|
|
186
|
-
return ['original', 'compressed']
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
sourceType: {
|
|
190
|
-
type: Array,
|
|
191
|
-
default () {
|
|
192
|
-
return ['album', 'camera']
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
data() {
|
|
197
|
-
return {
|
|
198
|
-
files: [],
|
|
199
|
-
localValue: []
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
watch: {
|
|
203
|
-
// #ifndef VUE3
|
|
204
|
-
value: {
|
|
205
|
-
handler(newVal, oldVal) {
|
|
206
|
-
this.setValue(newVal, oldVal)
|
|
207
|
-
},
|
|
208
|
-
immediate: true
|
|
209
|
-
},
|
|
210
|
-
// #endif
|
|
211
|
-
// #ifdef VUE3
|
|
212
|
-
modelValue: {
|
|
213
|
-
handler(newVal, oldVal) {
|
|
214
|
-
this.setValue(newVal, oldVal)
|
|
215
|
-
},
|
|
216
|
-
immediate: true
|
|
217
|
-
},
|
|
218
|
-
// #endif
|
|
219
|
-
},
|
|
220
|
-
computed: {
|
|
221
|
-
filesList() {
|
|
222
|
-
let files = []
|
|
223
|
-
this.files.forEach(v => {
|
|
224
|
-
files.push(v)
|
|
225
|
-
})
|
|
226
|
-
return files
|
|
227
|
-
},
|
|
228
|
-
showType() {
|
|
229
|
-
if (this.fileMediatype === 'image') {
|
|
230
|
-
return this.mode
|
|
231
|
-
}
|
|
232
|
-
return 'list'
|
|
233
|
-
},
|
|
234
|
-
limitLength() {
|
|
235
|
-
if (this.returnType === 'object') {
|
|
236
|
-
return 1
|
|
237
|
-
}
|
|
238
|
-
if (!this.limit) {
|
|
239
|
-
return 1
|
|
240
|
-
}
|
|
241
|
-
if (this.limit >= 9) {
|
|
242
|
-
return 9
|
|
243
|
-
}
|
|
244
|
-
return this.limit
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
created() {
|
|
248
|
-
// TODO 兼容不开通服务空间的情况
|
|
249
|
-
if (!(uniCloud.config && uniCloud.config.provider)) {
|
|
250
|
-
this.noSpace = true
|
|
251
|
-
uniCloud.chooseAndUploadFile = chooseAndUploadFile
|
|
252
|
-
}
|
|
253
|
-
this.form = this.getForm('uniForms')
|
|
254
|
-
this.formItem = this.getForm('uniFormsItem')
|
|
255
|
-
if (this.form && this.formItem) {
|
|
256
|
-
if (this.formItem.name) {
|
|
257
|
-
this.rename = this.formItem.name
|
|
258
|
-
this.form.inputChildrens.push(this)
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
methods: {
|
|
263
|
-
/**
|
|
264
|
-
* 公开用户使用,清空文件
|
|
265
|
-
* @param {Object} index
|
|
266
|
-
*/
|
|
267
|
-
clearFiles(index) {
|
|
268
|
-
if (index !== 0 && !index) {
|
|
269
|
-
this.files = []
|
|
270
|
-
this.$nextTick(() => {
|
|
271
|
-
this.setEmit()
|
|
272
|
-
})
|
|
273
|
-
} else {
|
|
274
|
-
this.files.splice(index, 1)
|
|
275
|
-
}
|
|
276
|
-
this.$nextTick(() => {
|
|
277
|
-
this.setEmit()
|
|
278
|
-
})
|
|
279
|
-
},
|
|
280
|
-
/**
|
|
281
|
-
* 公开用户使用,继续上传
|
|
282
|
-
*/
|
|
283
|
-
upload() {
|
|
284
|
-
let files = []
|
|
285
|
-
this.files.forEach((v, index) => {
|
|
286
|
-
if (v.status === 'ready' || v.status === 'error') {
|
|
287
|
-
files.push(Object.assign({}, v))
|
|
288
|
-
}
|
|
289
|
-
})
|
|
290
|
-
return this.uploadFiles(files)
|
|
291
|
-
},
|
|
292
|
-
async setValue(newVal, oldVal) {
|
|
293
|
-
const newData = async (v) => {
|
|
294
|
-
const reg = /cloud:\/\/([\w.]+\/?)\S*/
|
|
295
|
-
let url = ''
|
|
296
|
-
if(v.fileID){
|
|
297
|
-
url = v.fileID
|
|
298
|
-
}else{
|
|
299
|
-
url = v.url
|
|
300
|
-
}
|
|
301
|
-
if (reg.test(url)) {
|
|
302
|
-
v.fileID = url
|
|
303
|
-
v.url = await this.getTempFileURL(url)
|
|
304
|
-
}
|
|
305
|
-
if(v.url) v.path = v.url
|
|
306
|
-
return v
|
|
307
|
-
}
|
|
308
|
-
if (this.returnType === 'object') {
|
|
309
|
-
if (newVal) {
|
|
310
|
-
await newData(newVal)
|
|
311
|
-
} else {
|
|
312
|
-
newVal = {}
|
|
313
|
-
}
|
|
314
|
-
} else {
|
|
315
|
-
if (!newVal) newVal = []
|
|
316
|
-
for(let i =0 ;i < newVal.length ;i++){
|
|
317
|
-
let v = newVal[i]
|
|
318
|
-
await newData(v)
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
this.localValue = newVal
|
|
322
|
-
if (this.form && this.formItem &&!this.is_reset) {
|
|
323
|
-
this.is_reset = false
|
|
324
|
-
this.formItem.setValue(this.localValue)
|
|
325
|
-
}
|
|
326
|
-
let filesData = Object.keys(newVal).length > 0 ? newVal : [];
|
|
327
|
-
this.files = [].concat(filesData)
|
|
328
|
-
},
|
|
110
|
+
// #ifndef VUE3
|
|
111
|
+
value: {
|
|
112
|
+
type: [Array, Object],
|
|
113
|
+
default() {
|
|
114
|
+
return [];
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
// #endif
|
|
329
118
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
119
|
+
disabled: {
|
|
120
|
+
type: Boolean,
|
|
121
|
+
default: false,
|
|
122
|
+
},
|
|
123
|
+
disablePreview: {
|
|
124
|
+
type: Boolean,
|
|
125
|
+
default: false,
|
|
126
|
+
},
|
|
127
|
+
delIcon: {
|
|
128
|
+
type: Boolean,
|
|
129
|
+
default: true,
|
|
130
|
+
},
|
|
131
|
+
// 自动上传
|
|
132
|
+
autoUpload: {
|
|
133
|
+
type: Boolean,
|
|
134
|
+
default: true,
|
|
135
|
+
},
|
|
136
|
+
// 最大选择个数 ,h5只能限制单选或是多选
|
|
137
|
+
limit: {
|
|
138
|
+
type: [Number, String],
|
|
139
|
+
default: 9,
|
|
140
|
+
},
|
|
141
|
+
// 列表样式 grid | list | list-card
|
|
142
|
+
mode: {
|
|
143
|
+
type: String,
|
|
144
|
+
default: 'grid',
|
|
145
|
+
},
|
|
146
|
+
// 选择文件类型 image/video/all
|
|
147
|
+
fileMediatype: {
|
|
148
|
+
type: String,
|
|
149
|
+
default: 'image',
|
|
150
|
+
},
|
|
151
|
+
// 文件类型筛选
|
|
152
|
+
fileExtname: {
|
|
153
|
+
type: [Array, String],
|
|
154
|
+
default() {
|
|
155
|
+
return [];
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
title: {
|
|
159
|
+
type: String,
|
|
160
|
+
default: '',
|
|
161
|
+
},
|
|
162
|
+
listStyles: {
|
|
163
|
+
type: Object,
|
|
164
|
+
default() {
|
|
165
|
+
return {
|
|
166
|
+
// 是否显示边框
|
|
167
|
+
border: true,
|
|
168
|
+
// 是否显示分隔线
|
|
169
|
+
dividline: true,
|
|
170
|
+
// 线条样式
|
|
171
|
+
borderStyle: {},
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
imageStyles: {
|
|
176
|
+
type: Object,
|
|
177
|
+
default() {
|
|
178
|
+
return {
|
|
179
|
+
width: 'auto',
|
|
180
|
+
height: 'auto',
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
readonly: {
|
|
185
|
+
type: Boolean,
|
|
186
|
+
default: false,
|
|
187
|
+
},
|
|
188
|
+
returnType: {
|
|
189
|
+
type: String,
|
|
190
|
+
default: 'array',
|
|
191
|
+
},
|
|
192
|
+
sizeType: {
|
|
193
|
+
type: Array,
|
|
194
|
+
default() {
|
|
195
|
+
return ['original', 'compressed'];
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
sourceType: {
|
|
199
|
+
type: Array,
|
|
200
|
+
default() {
|
|
201
|
+
return ['album', 'camera'];
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
data() {
|
|
206
|
+
return {
|
|
207
|
+
files: [],
|
|
208
|
+
localValue: [],
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
watch: {
|
|
212
|
+
// #ifndef VUE3
|
|
213
|
+
value: {
|
|
214
|
+
handler(newVal, oldVal) {
|
|
215
|
+
this.setValue(newVal, oldVal);
|
|
216
|
+
},
|
|
217
|
+
immediate: true,
|
|
218
|
+
},
|
|
219
|
+
// #endif
|
|
220
|
+
// #ifdef VUE3
|
|
221
|
+
modelValue: {
|
|
222
|
+
handler(newVal, oldVal) {
|
|
223
|
+
this.setValue(newVal, oldVal);
|
|
224
|
+
},
|
|
225
|
+
immediate: true,
|
|
226
|
+
},
|
|
227
|
+
// #endif
|
|
228
|
+
},
|
|
229
|
+
computed: {
|
|
230
|
+
filesList() {
|
|
231
|
+
let files = [];
|
|
232
|
+
this.files.forEach((v) => {
|
|
233
|
+
files.push(v);
|
|
234
|
+
});
|
|
235
|
+
return files;
|
|
236
|
+
},
|
|
237
|
+
showType() {
|
|
238
|
+
if (this.fileMediatype === 'image') {
|
|
239
|
+
return this.mode;
|
|
240
|
+
}
|
|
241
|
+
return 'list';
|
|
242
|
+
},
|
|
243
|
+
limitLength() {
|
|
244
|
+
if (this.returnType === 'object') {
|
|
245
|
+
return 1;
|
|
246
|
+
}
|
|
247
|
+
if (!this.limit) {
|
|
248
|
+
return 1;
|
|
249
|
+
}
|
|
250
|
+
if (this.limit >= 9) {
|
|
251
|
+
return 9;
|
|
252
|
+
}
|
|
253
|
+
return this.limit;
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
created() {
|
|
257
|
+
// TODO 兼容不开通服务空间的情况
|
|
258
|
+
if (!(uniCloud.config && uniCloud.config.provider)) {
|
|
259
|
+
this.noSpace = true;
|
|
260
|
+
uniCloud.chooseAndUploadFile = chooseAndUploadFile;
|
|
261
|
+
}
|
|
262
|
+
this.form = this.getForm('uniForms');
|
|
263
|
+
this.formItem = this.getForm('uniFormsItem');
|
|
264
|
+
if (this.form && this.formItem) {
|
|
265
|
+
if (this.formItem.name) {
|
|
266
|
+
this.rename = this.formItem.name;
|
|
267
|
+
this.form.inputChildrens.push(this);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
methods: {
|
|
272
|
+
/**
|
|
273
|
+
* 公开用户使用,清空文件
|
|
274
|
+
* @param {Object} index
|
|
275
|
+
*/
|
|
276
|
+
clearFiles(index) {
|
|
277
|
+
if (index !== 0 && !index) {
|
|
278
|
+
this.files = [];
|
|
279
|
+
this.$nextTick(() => {
|
|
280
|
+
this.setEmit();
|
|
281
|
+
});
|
|
282
|
+
} else {
|
|
283
|
+
this.files.splice(index, 1);
|
|
284
|
+
}
|
|
285
|
+
this.$nextTick(() => {
|
|
286
|
+
this.setEmit();
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
/**
|
|
290
|
+
* 公开用户使用,继续上传
|
|
291
|
+
*/
|
|
292
|
+
upload() {
|
|
293
|
+
let files = [];
|
|
294
|
+
this.files.forEach((v, index) => {
|
|
295
|
+
if (v.status === 'ready' || v.status === 'error') {
|
|
296
|
+
files.push(Object.assign({}, v));
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
return this.uploadFiles(files);
|
|
300
|
+
},
|
|
301
|
+
async setValue(newVal, oldVal) {
|
|
302
|
+
const newData = async (v) => {
|
|
303
|
+
const reg = /cloud:\/\/([\w.]+\/?)\S*/;
|
|
304
|
+
let url = '';
|
|
305
|
+
if (v.fileID) {
|
|
306
|
+
url = v.fileID;
|
|
307
|
+
} else {
|
|
308
|
+
url = v.url;
|
|
309
|
+
}
|
|
310
|
+
if (reg.test(url)) {
|
|
311
|
+
v.fileID = url;
|
|
312
|
+
v.url = await this.getTempFileURL(url);
|
|
313
|
+
}
|
|
314
|
+
if (v.url) v.path = v.url;
|
|
315
|
+
return v;
|
|
316
|
+
};
|
|
317
|
+
if (this.returnType === 'object') {
|
|
318
|
+
if (newVal) {
|
|
319
|
+
await newData(newVal);
|
|
320
|
+
} else {
|
|
321
|
+
newVal = {};
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
if (!newVal) newVal = [];
|
|
325
|
+
for (let i = 0; i < newVal.length; i++) {
|
|
326
|
+
let v = newVal[i];
|
|
327
|
+
await newData(v);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
this.localValue = newVal;
|
|
331
|
+
if (this.form && this.formItem && !this.is_reset) {
|
|
332
|
+
this.is_reset = false;
|
|
333
|
+
this.formItem.setValue(this.localValue);
|
|
334
|
+
}
|
|
335
|
+
let filesData = Object.keys(newVal).length > 0 ? newVal : [];
|
|
336
|
+
this.files = [].concat(filesData);
|
|
337
|
+
},
|
|
334
338
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
339
|
+
/**
|
|
340
|
+
* 选择文件
|
|
341
|
+
*/
|
|
342
|
+
choose() {
|
|
343
|
+
if (this.disabled) return;
|
|
344
|
+
if (this.files.length >= Number(this.limitLength) && this.showType !== 'grid' && this.returnType === 'array') {
|
|
345
|
+
uni.showToast({
|
|
346
|
+
title: `您最多选择 ${this.limitLength} 个文件`,
|
|
347
|
+
icon: 'none',
|
|
348
|
+
});
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
this.chooseFiles();
|
|
352
|
+
},
|
|
346
353
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
354
|
+
/**
|
|
355
|
+
* 选择文件并上传
|
|
356
|
+
*/
|
|
357
|
+
chooseFiles() {
|
|
358
|
+
const _extname = get_extname(this.fileExtname);
|
|
359
|
+
// 获取后缀
|
|
360
|
+
uniCloud
|
|
361
|
+
.chooseAndUploadFile({
|
|
362
|
+
type: this.fileMediatype,
|
|
363
|
+
compressed: false,
|
|
364
|
+
sizeType: this.sizeType,
|
|
365
|
+
sourceType: this.sourceType,
|
|
366
|
+
// TODO 如果为空,video 有问题
|
|
367
|
+
extension: _extname.length > 0 ? _extname : undefined,
|
|
368
|
+
count: this.limitLength - this.files.length, //默认9
|
|
369
|
+
onChooseFile: this.chooseFileCallback,
|
|
370
|
+
onUploadProgress: (progressEvent) => {
|
|
371
|
+
this.setProgress(progressEvent, progressEvent.index);
|
|
372
|
+
},
|
|
373
|
+
})
|
|
374
|
+
.then((result) => {
|
|
375
|
+
this.setSuccessAndError(result.tempFiles);
|
|
376
|
+
})
|
|
377
|
+
.catch((err) => {
|
|
378
|
+
console.log('选择失败', err);
|
|
379
|
+
});
|
|
380
|
+
},
|
|
374
381
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (is_one) {
|
|
387
|
-
this.files = []
|
|
388
|
-
}
|
|
382
|
+
/**
|
|
383
|
+
* 选择文件回调
|
|
384
|
+
* @param {Object} res
|
|
385
|
+
*/
|
|
386
|
+
async chooseFileCallback(res) {
|
|
387
|
+
const _extname = get_extname(this.fileExtname);
|
|
388
|
+
const is_one = (Number(this.limitLength) === 1 && this.disablePreview && !this.disabled) || this.returnType === 'object';
|
|
389
|
+
// 如果这有一个文件 ,需要清空本地缓存数据
|
|
390
|
+
if (is_one) {
|
|
391
|
+
this.files = [];
|
|
392
|
+
}
|
|
389
393
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
filePaths = res.tempFilePaths
|
|
396
|
-
files = res.tempFiles
|
|
397
|
-
}
|
|
394
|
+
let { filePaths, files } = get_files_and_is_max(res, _extname);
|
|
395
|
+
if (!(_extname && _extname.length > 0)) {
|
|
396
|
+
filePaths = res.tempFilePaths;
|
|
397
|
+
files = res.tempFiles;
|
|
398
|
+
}
|
|
398
399
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
400
|
+
let currentData = [];
|
|
401
|
+
for (let i = 0; i < files.length; i++) {
|
|
402
|
+
if (this.limitLength - this.files.length <= 0) break;
|
|
403
|
+
files[i].uuid = Date.now();
|
|
404
|
+
let filedata = await get_file_data(files[i], this.fileMediatype);
|
|
405
|
+
filedata.progress = 0;
|
|
406
|
+
filedata.status = 'ready';
|
|
407
|
+
this.files.push(filedata);
|
|
408
|
+
currentData.push({
|
|
409
|
+
...filedata,
|
|
410
|
+
file: files[i],
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
this.$emit('select', {
|
|
414
|
+
tempFiles: currentData,
|
|
415
|
+
tempFilePaths: filePaths,
|
|
416
|
+
});
|
|
417
|
+
res.tempFiles = files;
|
|
418
|
+
// 停止自动上传
|
|
419
|
+
if (!this.autoUpload || this.noSpace) {
|
|
420
|
+
res.tempFiles = [];
|
|
421
|
+
}
|
|
422
|
+
},
|
|
422
423
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
424
|
+
/**
|
|
425
|
+
* 批传
|
|
426
|
+
* @param {Object} e
|
|
427
|
+
*/
|
|
428
|
+
uploadFiles(files) {
|
|
429
|
+
files = [].concat(files);
|
|
430
|
+
return uploadCloudFiles
|
|
431
|
+
.call(this, files, 5, (res) => {
|
|
432
|
+
this.setProgress(res, res.index, true);
|
|
433
|
+
})
|
|
434
|
+
.then((result) => {
|
|
435
|
+
this.setSuccessAndError(result);
|
|
436
|
+
return result;
|
|
437
|
+
})
|
|
438
|
+
.catch((err) => {
|
|
439
|
+
console.log(err);
|
|
440
|
+
});
|
|
441
|
+
},
|
|
440
442
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
443
|
+
/**
|
|
444
|
+
* 成功或失败
|
|
445
|
+
*/
|
|
446
|
+
async setSuccessAndError(res, fn) {
|
|
447
|
+
let successData = [];
|
|
448
|
+
let errorData = [];
|
|
449
|
+
let tempFilePath = [];
|
|
450
|
+
let errorTempFilePath = [];
|
|
451
|
+
for (let i = 0; i < res.length; i++) {
|
|
452
|
+
const item = res[i];
|
|
453
|
+
const index = item.uuid ? this.files.findIndex((p) => p.uuid === item.uuid) : item.index;
|
|
452
454
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
455
|
+
if (index === -1 || !this.files) break;
|
|
456
|
+
if (item.errMsg === 'request:fail') {
|
|
457
|
+
this.files[index].url = item.path;
|
|
458
|
+
this.files[index].status = 'error';
|
|
459
|
+
this.files[index].errMsg = item.errMsg;
|
|
460
|
+
// this.files[index].progress = -1
|
|
461
|
+
errorData.push(this.files[index]);
|
|
462
|
+
errorTempFilePath.push(this.files[index].url);
|
|
463
|
+
} else {
|
|
464
|
+
this.files[index].errMsg = '';
|
|
465
|
+
this.files[index].fileID = item.url;
|
|
466
|
+
const reg = /cloud:\/\/([\w.]+\/?)\S*/;
|
|
467
|
+
if (reg.test(item.url)) {
|
|
468
|
+
this.files[index].url = await this.getTempFileURL(item.url);
|
|
469
|
+
} else {
|
|
470
|
+
this.files[index].url = item.url;
|
|
471
|
+
}
|
|
470
472
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
473
|
+
this.files[index].status = 'success';
|
|
474
|
+
this.files[index].progress += 1;
|
|
475
|
+
successData.push(this.files[index]);
|
|
476
|
+
tempFilePath.push(this.files[index].fileID);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
477
479
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
480
|
+
if (successData.length > 0) {
|
|
481
|
+
this.setEmit();
|
|
482
|
+
// 状态改变返回
|
|
483
|
+
this.$emit('success', {
|
|
484
|
+
tempFiles: this.backObject(successData),
|
|
485
|
+
tempFilePaths: tempFilePath,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
486
488
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
489
|
+
if (errorData.length > 0) {
|
|
490
|
+
this.$emit('fail', {
|
|
491
|
+
tempFiles: this.backObject(errorData),
|
|
492
|
+
tempFilePaths: errorTempFilePath,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
},
|
|
494
496
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
497
|
+
/**
|
|
498
|
+
* 获取进度
|
|
499
|
+
* @param {Object} progressEvent
|
|
500
|
+
* @param {Object} index
|
|
501
|
+
* @param {Object} type
|
|
502
|
+
*/
|
|
503
|
+
setProgress(progressEvent, index, type) {
|
|
504
|
+
const fileLenth = this.files.length;
|
|
505
|
+
const percentNum = (index / fileLenth) * 100;
|
|
506
|
+
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
|
|
507
|
+
let idx = index;
|
|
508
|
+
if (!type) {
|
|
509
|
+
idx = this.files.findIndex((p) => p.uuid === progressEvent.tempFile.uuid);
|
|
510
|
+
}
|
|
511
|
+
if (idx === -1 || !this.files[idx]) return;
|
|
512
|
+
// fix by mehaotian 100 就会消失,-1 是为了让进度条消失
|
|
513
|
+
this.files[idx].progress = percentCompleted - 1;
|
|
514
|
+
// 上传中
|
|
515
|
+
this.$emit('progress', {
|
|
516
|
+
index: idx,
|
|
517
|
+
progress: parseInt(percentCompleted),
|
|
518
|
+
tempFile: this.files[idx],
|
|
519
|
+
});
|
|
520
|
+
},
|
|
519
521
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
522
|
+
/**
|
|
523
|
+
* 删除文件
|
|
524
|
+
* @param {Object} index
|
|
525
|
+
*/
|
|
526
|
+
delFile(index) {
|
|
527
|
+
this.$emit('delete', {
|
|
528
|
+
tempFile: this.files[index],
|
|
529
|
+
tempFilePath: this.files[index].url,
|
|
530
|
+
});
|
|
531
|
+
this.files.splice(index, 1);
|
|
532
|
+
this.$nextTick(() => {
|
|
533
|
+
this.setEmit();
|
|
534
|
+
});
|
|
535
|
+
},
|
|
534
536
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
537
|
+
/**
|
|
538
|
+
* 获取文件名和后缀
|
|
539
|
+
* @param {Object} name
|
|
540
|
+
*/
|
|
541
|
+
getFileExt(name) {
|
|
542
|
+
const last_len = name.lastIndexOf('.');
|
|
543
|
+
const len = name.length;
|
|
544
|
+
return {
|
|
545
|
+
name: name.substring(0, last_len),
|
|
546
|
+
ext: name.substring(last_len + 1, len),
|
|
547
|
+
};
|
|
548
|
+
},
|
|
547
549
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
550
|
+
/**
|
|
551
|
+
* 处理返回事件
|
|
552
|
+
*/
|
|
553
|
+
setEmit() {
|
|
554
|
+
let data = [];
|
|
555
|
+
if (this.returnType === 'object') {
|
|
556
|
+
data = this.backObject(this.files)[0];
|
|
557
|
+
this.localValue = data ? data : null;
|
|
558
|
+
} else {
|
|
559
|
+
data = this.backObject(this.files);
|
|
560
|
+
if (!this.localValue) {
|
|
561
|
+
this.localValue = [];
|
|
562
|
+
}
|
|
563
|
+
this.localValue = [...data];
|
|
564
|
+
}
|
|
565
|
+
// #ifdef VUE3
|
|
566
|
+
this.$emit('update:modelValue', this.localValue);
|
|
567
|
+
// #endif
|
|
568
|
+
// #ifndef VUE3
|
|
569
|
+
this.$emit('input', this.localValue);
|
|
570
|
+
// #endif
|
|
571
|
+
},
|
|
570
572
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
573
|
+
/**
|
|
574
|
+
* 处理返回参数
|
|
575
|
+
* @param {Object} files
|
|
576
|
+
*/
|
|
577
|
+
backObject(files) {
|
|
578
|
+
let newFilesData = [];
|
|
579
|
+
files.forEach((v) => {
|
|
580
|
+
newFilesData.push({
|
|
581
|
+
extname: v.extname,
|
|
582
|
+
fileType: v.fileType,
|
|
583
|
+
image: v.image,
|
|
584
|
+
name: v.name,
|
|
585
|
+
path: v.path,
|
|
586
|
+
size: v.size,
|
|
587
|
+
fileID: v.fileID,
|
|
588
|
+
url: v.url,
|
|
589
|
+
// 修改删除一个文件后不能再上传的bug, #694
|
|
590
|
+
uuid: v.uuid,
|
|
591
|
+
status: v.status,
|
|
592
|
+
cloudPath: v.cloudPath,
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
return newFilesData;
|
|
596
|
+
},
|
|
597
|
+
async getTempFileURL(fileList) {
|
|
598
|
+
fileList = {
|
|
599
|
+
fileList: [].concat(fileList),
|
|
600
|
+
};
|
|
601
|
+
const urls = await uniCloud.getTempFileURL(fileList);
|
|
602
|
+
return urls.fileList[0].tempFileURL || '';
|
|
603
|
+
},
|
|
604
|
+
/**
|
|
605
|
+
* 获取父元素实例
|
|
606
|
+
*/
|
|
607
|
+
getForm(name = 'uniForms') {
|
|
608
|
+
let parent = this.$parent;
|
|
609
|
+
let parentName = parent.$options.name;
|
|
610
|
+
while (parentName !== name) {
|
|
611
|
+
parent = parent.$parent;
|
|
612
|
+
if (!parent) return false;
|
|
613
|
+
parentName = parent.$options.name;
|
|
614
|
+
}
|
|
615
|
+
return parent;
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
};
|
|
617
619
|
</script>
|
|
618
620
|
|
|
619
621
|
<style>
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
622
|
+
.uni-file-picker {
|
|
623
|
+
/* #ifndef APP-NVUE */
|
|
624
|
+
box-sizing: border-box;
|
|
625
|
+
overflow: hidden;
|
|
626
|
+
width: 100%;
|
|
627
|
+
/* #endif */
|
|
628
|
+
flex: 1;
|
|
629
|
+
}
|
|
628
630
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
631
|
+
.uni-file-picker__header {
|
|
632
|
+
padding-top: 5px;
|
|
633
|
+
padding-bottom: 10px;
|
|
634
|
+
/* #ifndef APP-NVUE */
|
|
635
|
+
display: flex;
|
|
636
|
+
/* #endif */
|
|
637
|
+
justify-content: space-between;
|
|
638
|
+
}
|
|
637
639
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
640
|
+
.file-title {
|
|
641
|
+
font-size: 14px;
|
|
642
|
+
color: #333;
|
|
643
|
+
}
|
|
642
644
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
645
|
+
.file-count {
|
|
646
|
+
font-size: 14px;
|
|
647
|
+
color: #999;
|
|
648
|
+
}
|
|
647
649
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
650
|
+
.is-add {
|
|
651
|
+
/* #ifndef APP-NVUE */
|
|
652
|
+
display: flex;
|
|
653
|
+
/* #endif */
|
|
654
|
+
align-items: center;
|
|
655
|
+
justify-content: center;
|
|
656
|
+
}
|
|
655
657
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
658
|
+
.icon-add {
|
|
659
|
+
width: 50px;
|
|
660
|
+
height: 5px;
|
|
661
|
+
background-color: #f1f1f1;
|
|
662
|
+
border-radius: 2px;
|
|
663
|
+
}
|
|
662
664
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
665
|
+
.rotate {
|
|
666
|
+
position: absolute;
|
|
667
|
+
transform: rotate(90deg);
|
|
668
|
+
}
|
|
667
669
|
</style>
|