@kengic/uni 0.3.2-beta.10

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.
Files changed (166) hide show
  1. package/README.md +1 -0
  2. package/dist/index.css +1 -0
  3. package/dist/kengic-uni.js +5 -0
  4. package/dist/src/consts/i18n/en.d.ts +45 -0
  5. package/dist/src/consts/i18n/index.d.ts +90 -0
  6. package/dist/src/consts/i18n/zh_CN.d.ts +45 -0
  7. package/dist/src/consts/index.d.ts +1 -0
  8. package/dist/src/index.d.ts +2 -0
  9. package/dist/src/utils/index.d.ts +1 -0
  10. package/dist/src/utils/kg.util.d.ts +5 -0
  11. package/dist/uni-ui/index.ts +11 -0
  12. package/dist/uni-ui/uni-badge/uni-badge.vue +253 -0
  13. package/dist/uni-ui/uni-breadcrumb/uni-breadcrumb.vue +41 -0
  14. package/dist/uni-ui/uni-breadcrumb-item/uni-breadcrumb-item.vue +121 -0
  15. package/dist/uni-ui/uni-calendar/calendar.js +546 -0
  16. package/dist/uni-ui/uni-calendar/i18n/en.json +12 -0
  17. package/dist/uni-ui/uni-calendar/i18n/index.js +8 -0
  18. package/dist/uni-ui/uni-calendar/i18n/zh-Hans.json +12 -0
  19. package/dist/uni-ui/uni-calendar/i18n/zh-Hant.json +12 -0
  20. package/dist/uni-ui/uni-calendar/uni-calendar-item.vue +187 -0
  21. package/dist/uni-ui/uni-calendar/uni-calendar.vue +566 -0
  22. package/dist/uni-ui/uni-calendar/util.js +360 -0
  23. package/dist/uni-ui/uni-card/uni-card.vue +281 -0
  24. package/dist/uni-ui/uni-col/uni-col.vue +317 -0
  25. package/dist/uni-ui/uni-collapse/uni-collapse.vue +147 -0
  26. package/dist/uni-ui/uni-collapse-item/uni-collapse-item.vue +402 -0
  27. package/dist/uni-ui/uni-combox/uni-combox.vue +294 -0
  28. package/dist/uni-ui/uni-countdown/i18n/en.json +6 -0
  29. package/dist/uni-ui/uni-countdown/i18n/index.js +8 -0
  30. package/dist/uni-ui/uni-countdown/i18n/zh-Hans.json +6 -0
  31. package/dist/uni-ui/uni-countdown/i18n/zh-Hant.json +6 -0
  32. package/dist/uni-ui/uni-countdown/uni-countdown.vue +267 -0
  33. package/dist/uni-ui/uni-data-checkbox/uni-data-checkbox.vue +821 -0
  34. package/dist/uni-ui/uni-data-picker/keypress.js +45 -0
  35. package/dist/uni-ui/uni-data-picker/uni-data-picker.vue +551 -0
  36. package/dist/uni-ui/uni-data-pickerview/uni-data-picker.js +622 -0
  37. package/dist/uni-ui/uni-data-pickerview/uni-data-pickerview.vue +323 -0
  38. package/dist/uni-ui/uni-data-select/uni-data-select.vue +517 -0
  39. package/dist/uni-ui/uni-dateformat/date-format.js +200 -0
  40. package/dist/uni-ui/uni-dateformat/uni-dateformat.vue +88 -0
  41. package/dist/uni-ui/uni-datetime-picker/calendar-item.vue +177 -0
  42. package/dist/uni-ui/uni-datetime-picker/calendar.vue +928 -0
  43. package/dist/uni-ui/uni-datetime-picker/i18n/en.json +22 -0
  44. package/dist/uni-ui/uni-datetime-picker/i18n/index.js +8 -0
  45. package/dist/uni-ui/uni-datetime-picker/i18n/zh-Hans.json +22 -0
  46. package/dist/uni-ui/uni-datetime-picker/i18n/zh-Hant.json +22 -0
  47. package/dist/uni-ui/uni-datetime-picker/time-picker.vue +934 -0
  48. package/dist/uni-ui/uni-datetime-picker/uni-datetime-picker.vue +1026 -0
  49. package/dist/uni-ui/uni-datetime-picker/util.js +403 -0
  50. package/dist/uni-ui/uni-drawer/keypress.js +45 -0
  51. package/dist/uni-ui/uni-drawer/uni-drawer.vue +181 -0
  52. package/dist/uni-ui/uni-easyinput/common.js +56 -0
  53. package/dist/uni-ui/uni-easyinput/uni-easyinput.vue +660 -0
  54. package/dist/uni-ui/uni-fab/uni-fab.vue +491 -0
  55. package/dist/uni-ui/uni-fav/i18n/en.json +4 -0
  56. package/dist/uni-ui/uni-fav/i18n/index.js +8 -0
  57. package/dist/uni-ui/uni-fav/i18n/zh-Hans.json +4 -0
  58. package/dist/uni-ui/uni-fav/i18n/zh-Hant.json +4 -0
  59. package/dist/uni-ui/uni-fav/uni-fav.vue +161 -0
  60. package/dist/uni-ui/uni-file-picker/choose-and-upload-file.js +224 -0
  61. package/dist/uni-ui/uni-file-picker/uni-file-picker.vue +667 -0
  62. package/dist/uni-ui/uni-file-picker/upload-file.vue +325 -0
  63. package/dist/uni-ui/uni-file-picker/upload-image.vue +292 -0
  64. package/dist/uni-ui/uni-file-picker/utils.js +109 -0
  65. package/dist/uni-ui/uni-forms/uni-forms.vue +398 -0
  66. package/dist/uni-ui/uni-forms/utils.js +293 -0
  67. package/dist/uni-ui/uni-forms/validate.js +486 -0
  68. package/dist/uni-ui/uni-forms-item/uni-forms-item.vue +601 -0
  69. package/dist/uni-ui/uni-goods-nav/i18n/en.json +6 -0
  70. package/dist/uni-ui/uni-goods-nav/i18n/index.js +8 -0
  71. package/dist/uni-ui/uni-goods-nav/i18n/zh-Hans.json +6 -0
  72. package/dist/uni-ui/uni-goods-nav/i18n/zh-Hant.json +6 -0
  73. package/dist/uni-ui/uni-goods-nav/uni-goods-nav.vue +229 -0
  74. package/dist/uni-ui/uni-grid/uni-grid.vue +143 -0
  75. package/dist/uni-ui/uni-grid-item/uni-grid-item.vue +129 -0
  76. package/dist/uni-ui/uni-group/uni-group.vue +134 -0
  77. package/dist/uni-ui/uni-icons/icons.js +1169 -0
  78. package/dist/uni-ui/uni-icons/uni-icons.vue +96 -0
  79. package/dist/uni-ui/uni-icons/uniicons.css +663 -0
  80. package/dist/uni-ui/uni-icons/uniicons.ttf +0 -0
  81. package/dist/uni-ui/uni-indexed-list/uni-indexed-list-item.vue +144 -0
  82. package/dist/uni-ui/uni-indexed-list/uni-indexed-list.vue +367 -0
  83. package/dist/uni-ui/uni-link/uni-link.vue +128 -0
  84. package/dist/uni-ui/uni-list/uni-list.vue +123 -0
  85. package/dist/uni-ui/uni-list/uni-refresh.vue +65 -0
  86. package/dist/uni-ui/uni-list/uni-refresh.wxs +87 -0
  87. package/dist/uni-ui/uni-list-ad/uni-list-ad.vue +107 -0
  88. package/dist/uni-ui/uni-list-chat/uni-list-chat.scss +58 -0
  89. package/dist/uni-ui/uni-list-chat/uni-list-chat.vue +593 -0
  90. package/dist/uni-ui/uni-list-item/uni-list-item.vue +534 -0
  91. package/dist/uni-ui/uni-load-more/i18n/en.json +5 -0
  92. package/dist/uni-ui/uni-load-more/i18n/index.js +8 -0
  93. package/dist/uni-ui/uni-load-more/i18n/zh-Hans.json +5 -0
  94. package/dist/uni-ui/uni-load-more/i18n/zh-Hant.json +5 -0
  95. package/dist/uni-ui/uni-load-more/uni-load-more.vue +399 -0
  96. package/dist/uni-ui/uni-nav-bar/uni-nav-bar.vue +357 -0
  97. package/dist/uni-ui/uni-nav-bar/uni-status-bar.vue +24 -0
  98. package/dist/uni-ui/uni-notice-bar/uni-notice-bar.vue +426 -0
  99. package/dist/uni-ui/uni-number-box/uni-number-box.vue +221 -0
  100. package/dist/uni-ui/uni-pagination/i18n/en.json +5 -0
  101. package/dist/uni-ui/uni-pagination/i18n/es.json +5 -0
  102. package/dist/uni-ui/uni-pagination/i18n/fr.json +5 -0
  103. package/dist/uni-ui/uni-pagination/i18n/index.js +12 -0
  104. package/dist/uni-ui/uni-pagination/i18n/zh-Hans.json +5 -0
  105. package/dist/uni-ui/uni-pagination/i18n/zh-Hant.json +5 -0
  106. package/dist/uni-ui/uni-pagination/uni-pagination.vue +465 -0
  107. package/dist/uni-ui/uni-popup/i18n/en.json +7 -0
  108. package/dist/uni-ui/uni-popup/i18n/index.js +9 -0
  109. package/dist/uni-ui/uni-popup/i18n/zh-Hans.json +7 -0
  110. package/dist/uni-ui/uni-popup/i18n/zh-Hant.json +7 -0
  111. package/dist/uni-ui/uni-popup/keypress.js +45 -0
  112. package/dist/uni-ui/uni-popup/popup.js +23 -0
  113. package/dist/uni-ui/uni-popup/uni-popup.vue +464 -0
  114. package/dist/uni-ui/uni-popup-dialog/keypress.js +45 -0
  115. package/dist/uni-ui/uni-popup-dialog/uni-popup-dialog.vue +275 -0
  116. package/dist/uni-ui/uni-popup-message/uni-popup-message.vue +143 -0
  117. package/dist/uni-ui/uni-popup-share/uni-popup-share.vue +187 -0
  118. package/dist/uni-ui/uni-rate/uni-rate.vue +365 -0
  119. package/dist/uni-ui/uni-row/uni-row.vue +190 -0
  120. package/dist/uni-ui/uni-scss/changelog.md +8 -0
  121. package/dist/uni-ui/uni-scss/index.scss +1 -0
  122. package/dist/uni-ui/uni-scss/package.json +82 -0
  123. package/dist/uni-ui/uni-scss/readme.md +4 -0
  124. package/dist/uni-ui/uni-scss/styles/index.scss +7 -0
  125. package/dist/uni-ui/uni-scss/styles/setting/_border.scss +3 -0
  126. package/dist/uni-ui/uni-scss/styles/setting/_color.scss +66 -0
  127. package/dist/uni-ui/uni-scss/styles/setting/_radius.scss +55 -0
  128. package/dist/uni-ui/uni-scss/styles/setting/_space.scss +56 -0
  129. package/dist/uni-ui/uni-scss/styles/setting/_styles.scss +167 -0
  130. package/dist/uni-ui/uni-scss/styles/setting/_text.scss +24 -0
  131. package/dist/uni-ui/uni-scss/styles/setting/_variables.scss +146 -0
  132. package/dist/uni-ui/uni-scss/styles/tools/functions.scss +19 -0
  133. package/dist/uni-ui/uni-scss/theme.scss +31 -0
  134. package/dist/uni-ui/uni-scss/variables.scss +62 -0
  135. package/dist/uni-ui/uni-search-bar/i18n/en.json +4 -0
  136. package/dist/uni-ui/uni-search-bar/i18n/index.js +8 -0
  137. package/dist/uni-ui/uni-search-bar/i18n/zh-Hans.json +4 -0
  138. package/dist/uni-ui/uni-search-bar/i18n/zh-Hant.json +4 -0
  139. package/dist/uni-ui/uni-search-bar/uni-search-bar.vue +298 -0
  140. package/dist/uni-ui/uni-section/uni-section.vue +167 -0
  141. package/dist/uni-ui/uni-segmented-control/uni-segmented-control.vue +145 -0
  142. package/dist/uni-ui/uni-steps/uni-steps.vue +269 -0
  143. package/dist/uni-ui/uni-swipe-action/uni-swipe-action.vue +60 -0
  144. package/dist/uni-ui/uni-swipe-action-item/bindingx.js +302 -0
  145. package/dist/uni-ui/uni-swipe-action-item/isPC.js +12 -0
  146. package/dist/uni-ui/uni-swipe-action-item/mpalipay.js +195 -0
  147. package/dist/uni-ui/uni-swipe-action-item/mpother.js +260 -0
  148. package/dist/uni-ui/uni-swipe-action-item/mpwxs.js +84 -0
  149. package/dist/uni-ui/uni-swipe-action-item/render.js +270 -0
  150. package/dist/uni-ui/uni-swipe-action-item/uni-swipe-action-item.vue +347 -0
  151. package/dist/uni-ui/uni-swipe-action-item/wx.wxs +341 -0
  152. package/dist/uni-ui/uni-swiper-dot/uni-swiper-dot.vue +218 -0
  153. package/dist/uni-ui/uni-table/uni-table.vue +455 -0
  154. package/dist/uni-ui/uni-tag/uni-tag.vue +252 -0
  155. package/dist/uni-ui/uni-tbody/uni-tbody.vue +29 -0
  156. package/dist/uni-ui/uni-td/uni-td.vue +90 -0
  157. package/dist/uni-ui/uni-th/filter-dropdown.vue +511 -0
  158. package/dist/uni-ui/uni-th/uni-th.vue +285 -0
  159. package/dist/uni-ui/uni-thead/uni-thead.vue +129 -0
  160. package/dist/uni-ui/uni-title/uni-title.vue +171 -0
  161. package/dist/uni-ui/uni-tooltip/uni-tooltip.vue +68 -0
  162. package/dist/uni-ui/uni-tr/table-checkbox.vue +179 -0
  163. package/dist/uni-ui/uni-tr/uni-tr.vue +171 -0
  164. package/dist/uni-ui/uni-transition/createAnimation.js +131 -0
  165. package/dist/uni-ui/uni-transition/uni-transition.vue +281 -0
  166. package/package.json +90 -0
@@ -0,0 +1,667 @@
1
+ <template>
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 v-if="fileMediatype === 'image' && showType === 'grid'" :readonly="readonly"
8
+ :image-styles="imageStyles" :files-list="filesList" :limit="limitLength" :disablePreview="disablePreview"
9
+ :delIcon="delIcon" @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile">
10
+ <slot>
11
+ <view class="is-add">
12
+ <view class="icon-add"></view>
13
+ <view class="icon-add rotate"></view>
14
+ </view>
15
+ </slot>
16
+ </upload-image>
17
+ <upload-file v-if="fileMediatype !== 'image' || showType !== 'grid'" :readonly="readonly"
18
+ :list-styles="listStyles" :files-list="filesList" :showType="showType" :delIcon="delIcon"
19
+ @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile">
20
+ <slot><button type="primary" size="mini">选择文件</button></slot>
21
+ </upload-file>
22
+ </view>
23
+ </template>
24
+
25
+ <script>
26
+ import {
27
+ chooseAndUploadFile,
28
+ uploadCloudFiles
29
+ } from './choose-and-upload-file.js'
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
100
+
101
+ // #ifndef VUE3
102
+ value: {
103
+ type: [Array, Object],
104
+ default () {
105
+ return []
106
+ }
107
+ },
108
+ // #endif
109
+
110
+ disabled: {
111
+ type: Boolean,
112
+ default: false
113
+ },
114
+ disablePreview: {
115
+ type: Boolean,
116
+ default: false
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
+ },
329
+
330
+ /**
331
+ * 选择文件
332
+ */
333
+ choose() {
334
+
335
+ if (this.disabled) return
336
+ if (this.files.length >= Number(this.limitLength) && this.showType !== 'grid' && this.returnType ===
337
+ 'array') {
338
+ uni.showToast({
339
+ title: `您最多选择 ${this.limitLength} 个文件`,
340
+ icon: 'none'
341
+ })
342
+ return
343
+ }
344
+ this.chooseFiles()
345
+ },
346
+
347
+ /**
348
+ * 选择文件并上传
349
+ */
350
+ chooseFiles() {
351
+ const _extname = get_extname(this.fileExtname)
352
+ // 获取后缀
353
+ uniCloud
354
+ .chooseAndUploadFile({
355
+ type: this.fileMediatype,
356
+ compressed: false,
357
+ sizeType: this.sizeType,
358
+ sourceType: this.sourceType,
359
+ // TODO 如果为空,video 有问题
360
+ extension: _extname.length > 0 ? _extname : undefined,
361
+ count: this.limitLength - this.files.length, //默认9
362
+ onChooseFile: this.chooseFileCallback,
363
+ onUploadProgress: progressEvent => {
364
+ this.setProgress(progressEvent, progressEvent.index)
365
+ }
366
+ })
367
+ .then(result => {
368
+ this.setSuccessAndError(result.tempFiles)
369
+ })
370
+ .catch(err => {
371
+ console.log('选择失败', err)
372
+ })
373
+ },
374
+
375
+ /**
376
+ * 选择文件回调
377
+ * @param {Object} res
378
+ */
379
+ async chooseFileCallback(res) {
380
+ const _extname = get_extname(this.fileExtname)
381
+ const is_one = (Number(this.limitLength) === 1 &&
382
+ this.disablePreview &&
383
+ !this.disabled) ||
384
+ this.returnType === 'object'
385
+ // 如果这有一个文件 ,需要清空本地缓存数据
386
+ if (is_one) {
387
+ this.files = []
388
+ }
389
+
390
+ let {
391
+ filePaths,
392
+ files
393
+ } = get_files_and_is_max(res, _extname)
394
+ if (!(_extname && _extname.length > 0)) {
395
+ filePaths = res.tempFilePaths
396
+ files = res.tempFiles
397
+ }
398
+
399
+ let currentData = []
400
+ for (let i = 0; i < files.length; i++) {
401
+ if (this.limitLength - this.files.length <= 0) break
402
+ files[i].uuid = Date.now()
403
+ let filedata = await get_file_data(files[i], this.fileMediatype)
404
+ filedata.progress = 0
405
+ filedata.status = 'ready'
406
+ this.files.push(filedata)
407
+ currentData.push({
408
+ ...filedata,
409
+ file: files[i]
410
+ })
411
+ }
412
+ this.$emit('select', {
413
+ tempFiles: currentData,
414
+ tempFilePaths: filePaths
415
+ })
416
+ res.tempFiles = files
417
+ // 停止自动上传
418
+ if (!this.autoUpload || this.noSpace) {
419
+ res.tempFiles = []
420
+ }
421
+ },
422
+
423
+ /**
424
+ * 批传
425
+ * @param {Object} e
426
+ */
427
+ uploadFiles(files) {
428
+ files = [].concat(files)
429
+ return uploadCloudFiles.call(this, files, 5, res => {
430
+ this.setProgress(res, res.index, true)
431
+ })
432
+ .then(result => {
433
+ this.setSuccessAndError(result)
434
+ return result;
435
+ })
436
+ .catch(err => {
437
+ console.log(err)
438
+ })
439
+ },
440
+
441
+ /**
442
+ * 成功或失败
443
+ */
444
+ async setSuccessAndError(res, fn) {
445
+ let successData = []
446
+ let errorData = []
447
+ let tempFilePath = []
448
+ let errorTempFilePath = []
449
+ for (let i = 0; i < res.length; i++) {
450
+ const item = res[i]
451
+ const index = item.uuid ? this.files.findIndex(p => p.uuid === item.uuid) : item.index
452
+
453
+ if (index === -1 || !this.files) break
454
+ if (item.errMsg === 'request:fail') {
455
+ this.files[index].url = item.path
456
+ this.files[index].status = 'error'
457
+ this.files[index].errMsg = item.errMsg
458
+ // this.files[index].progress = -1
459
+ errorData.push(this.files[index])
460
+ errorTempFilePath.push(this.files[index].url)
461
+ } else {
462
+ this.files[index].errMsg = ''
463
+ this.files[index].fileID = item.url
464
+ const reg = /cloud:\/\/([\w.]+\/?)\S*/
465
+ if (reg.test(item.url)) {
466
+ this.files[index].url = await this.getTempFileURL(item.url)
467
+ }else{
468
+ this.files[index].url = item.url
469
+ }
470
+
471
+ this.files[index].status = 'success'
472
+ this.files[index].progress += 1
473
+ successData.push(this.files[index])
474
+ tempFilePath.push(this.files[index].fileID)
475
+ }
476
+ }
477
+
478
+ if (successData.length > 0) {
479
+ this.setEmit()
480
+ // 状态改变返回
481
+ this.$emit('success', {
482
+ tempFiles: this.backObject(successData),
483
+ tempFilePaths: tempFilePath
484
+ })
485
+ }
486
+
487
+ if (errorData.length > 0) {
488
+ this.$emit('fail', {
489
+ tempFiles: this.backObject(errorData),
490
+ tempFilePaths: errorTempFilePath
491
+ })
492
+ }
493
+ },
494
+
495
+ /**
496
+ * 获取进度
497
+ * @param {Object} progressEvent
498
+ * @param {Object} index
499
+ * @param {Object} type
500
+ */
501
+ setProgress(progressEvent, index, type) {
502
+ const fileLenth = this.files.length
503
+ const percentNum = (index / fileLenth) * 100
504
+ const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
505
+ let idx = index
506
+ if (!type) {
507
+ idx = this.files.findIndex(p => p.uuid === progressEvent.tempFile.uuid)
508
+ }
509
+ if (idx === -1 || !this.files[idx]) return
510
+ // fix by mehaotian 100 就会消失,-1 是为了让进度条消失
511
+ this.files[idx].progress = percentCompleted - 1
512
+ // 上传中
513
+ this.$emit('progress', {
514
+ index: idx,
515
+ progress: parseInt(percentCompleted),
516
+ tempFile: this.files[idx]
517
+ })
518
+ },
519
+
520
+ /**
521
+ * 删除文件
522
+ * @param {Object} index
523
+ */
524
+ delFile(index) {
525
+ this.$emit('delete', {
526
+ tempFile: this.files[index],
527
+ tempFilePath: this.files[index].url
528
+ })
529
+ this.files.splice(index, 1)
530
+ this.$nextTick(() => {
531
+ this.setEmit()
532
+ })
533
+ },
534
+
535
+ /**
536
+ * 获取文件名和后缀
537
+ * @param {Object} name
538
+ */
539
+ getFileExt(name) {
540
+ const last_len = name.lastIndexOf('.')
541
+ const len = name.length
542
+ return {
543
+ name: name.substring(0, last_len),
544
+ ext: name.substring(last_len + 1, len)
545
+ }
546
+ },
547
+
548
+ /**
549
+ * 处理返回事件
550
+ */
551
+ setEmit() {
552
+ let data = []
553
+ if (this.returnType === 'object') {
554
+ data = this.backObject(this.files)[0]
555
+ this.localValue = data?data:null
556
+ } else {
557
+ data = this.backObject(this.files)
558
+ if (!this.localValue) {
559
+ this.localValue = []
560
+ }
561
+ this.localValue = [...data]
562
+ }
563
+ // #ifdef VUE3
564
+ this.$emit('update:modelValue', this.localValue)
565
+ // #endif
566
+ // #ifndef VUE3
567
+ this.$emit('input', this.localValue)
568
+ // #endif
569
+ },
570
+
571
+ /**
572
+ * 处理返回参数
573
+ * @param {Object} files
574
+ */
575
+ backObject(files) {
576
+ let newFilesData = []
577
+ files.forEach(v => {
578
+ newFilesData.push({
579
+ extname: v.extname,
580
+ fileType: v.fileType,
581
+ image: v.image,
582
+ name: v.name,
583
+ path: v.path,
584
+ size: v.size,
585
+ fileID:v.fileID,
586
+ url: v.url,
587
+ // 修改删除一个文件后不能再上传的bug, #694
588
+ uuid: v.uuid,
589
+ status: v.status,
590
+ cloudPath: v.cloudPath
591
+ })
592
+ })
593
+ return newFilesData
594
+ },
595
+ async getTempFileURL(fileList) {
596
+ fileList = {
597
+ fileList: [].concat(fileList)
598
+ }
599
+ const urls = await uniCloud.getTempFileURL(fileList)
600
+ return urls.fileList[0].tempFileURL || ''
601
+ },
602
+ /**
603
+ * 获取父元素实例
604
+ */
605
+ getForm(name = 'uniForms') {
606
+ let parent = this.$parent;
607
+ let parentName = parent.$options.name;
608
+ while (parentName !== name) {
609
+ parent = parent.$parent;
610
+ if (!parent) return false;
611
+ parentName = parent.$options.name;
612
+ }
613
+ return parent;
614
+ }
615
+ }
616
+ }
617
+ </script>
618
+
619
+ <style>
620
+ .uni-file-picker {
621
+ /* #ifndef APP-NVUE */
622
+ box-sizing: border-box;
623
+ overflow: hidden;
624
+ width: 100%;
625
+ /* #endif */
626
+ flex: 1;
627
+ }
628
+
629
+ .uni-file-picker__header {
630
+ padding-top: 5px;
631
+ padding-bottom: 10px;
632
+ /* #ifndef APP-NVUE */
633
+ display: flex;
634
+ /* #endif */
635
+ justify-content: space-between;
636
+ }
637
+
638
+ .file-title {
639
+ font-size: 14px;
640
+ color: #333;
641
+ }
642
+
643
+ .file-count {
644
+ font-size: 14px;
645
+ color: #999;
646
+ }
647
+
648
+ .is-add {
649
+ /* #ifndef APP-NVUE */
650
+ display: flex;
651
+ /* #endif */
652
+ align-items: center;
653
+ justify-content: center;
654
+ }
655
+
656
+ .icon-add {
657
+ width: 50px;
658
+ height: 5px;
659
+ background-color: #f1f1f1;
660
+ border-radius: 2px;
661
+ }
662
+
663
+ .rotate {
664
+ position: absolute;
665
+ transform: rotate(90deg);
666
+ }
667
+ </style>