@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,325 @@
1
+ <template>
2
+ <view class="uni-file-picker__files">
3
+ <view v-if="!readonly" class="files-button" @click="choose">
4
+ <slot></slot>
5
+ </view>
6
+ <!-- :class="{'is-text-box':showType === 'list'}" -->
7
+ <view v-if="list.length > 0" class="uni-file-picker__lists is-text-box" :style="borderStyle">
8
+ <!-- ,'is-list-card':showType === 'list-card' -->
9
+
10
+ <view class="uni-file-picker__lists-box" v-for="(item ,index) in list" :key="index" :class="{
11
+ 'files-border':index !== 0 && styles.dividline}"
12
+ :style="index !== 0 && styles.dividline &&borderLineStyle">
13
+ <view class="uni-file-picker__item">
14
+ <!-- :class="{'is-text-image':showType === 'list'}" -->
15
+ <!-- <view class="files__image is-text-image">
16
+ <image class="header-image" :src="item.logo" mode="aspectFit"></image>
17
+ </view> -->
18
+ <view class="files__name">{{item.name}}</view>
19
+ <view v-if="delIcon&&!readonly" class="icon-del-box icon-files" @click="delFile(index)">
20
+ <view class="icon-del icon-files"></view>
21
+ <view class="icon-del rotate"></view>
22
+ </view>
23
+ </view>
24
+ <view v-if="(item.progress && item.progress !== 100) ||item.progress===0 " class="file-picker__progress">
25
+ <progress class="file-picker__progress-item" :percent="item.progress === -1?0:item.progress" stroke-width="4"
26
+ :backgroundColor="item.errMsg?'#ff5a5f':'#EBEBEB'" />
27
+ </view>
28
+ <view v-if="item.status === 'error'" class="file-picker__mask" @click.stop="uploadFiles(item,index)">
29
+ 点击重试
30
+ </view>
31
+ </view>
32
+
33
+ </view>
34
+ </view>
35
+ </template>
36
+
37
+ <script>
38
+ export default {
39
+ name: "uploadFile",
40
+ emits:['uploadFiles','choose','delFile'],
41
+ props: {
42
+ filesList: {
43
+ type: Array,
44
+ default () {
45
+ return []
46
+ }
47
+ },
48
+ delIcon: {
49
+ type: Boolean,
50
+ default: true
51
+ },
52
+ limit: {
53
+ type: [Number, String],
54
+ default: 9
55
+ },
56
+ showType: {
57
+ type: String,
58
+ default: ''
59
+ },
60
+ listStyles: {
61
+ type: Object,
62
+ default () {
63
+ return {
64
+ // 是否显示边框
65
+ border: true,
66
+ // 是否显示分隔线
67
+ dividline: true,
68
+ // 线条样式
69
+ borderStyle: {}
70
+ }
71
+ }
72
+ },
73
+ readonly:{
74
+ type:Boolean,
75
+ default:false
76
+ }
77
+ },
78
+ computed: {
79
+ list() {
80
+ let files = []
81
+ this.filesList.forEach(v => {
82
+ files.push(v)
83
+ })
84
+ return files
85
+ },
86
+ styles() {
87
+ let styles = {
88
+ border: true,
89
+ dividline: true,
90
+ 'border-style': {}
91
+ }
92
+ return Object.assign(styles, this.listStyles)
93
+ },
94
+ borderStyle() {
95
+ let {
96
+ borderStyle,
97
+ border
98
+ } = this.styles
99
+ let obj = {}
100
+ if (!border) {
101
+ obj.border = 'none'
102
+ } else {
103
+ let width = (borderStyle && borderStyle.width) || 1
104
+ width = this.value2px(width)
105
+ let radius = (borderStyle && borderStyle.radius) || 5
106
+ radius = this.value2px(radius)
107
+ obj = {
108
+ 'border-width': width,
109
+ 'border-style': (borderStyle && borderStyle.style) || 'solid',
110
+ 'border-color': (borderStyle && borderStyle.color) || '#eee',
111
+ 'border-radius': radius
112
+ }
113
+ }
114
+ let classles = ''
115
+ for (let i in obj) {
116
+ classles += `${i}:${obj[i]};`
117
+ }
118
+ return classles
119
+ },
120
+ borderLineStyle() {
121
+ let obj = {}
122
+ let {
123
+ borderStyle
124
+ } = this.styles
125
+ if (borderStyle && borderStyle.color) {
126
+ obj['border-color'] = borderStyle.color
127
+ }
128
+ if (borderStyle && borderStyle.width) {
129
+ let width = borderStyle && borderStyle.width || 1
130
+ let style = borderStyle && borderStyle.style || 0
131
+ if (typeof width === 'number') {
132
+ width += 'px'
133
+ } else {
134
+ width = width.indexOf('px') ? width : width + 'px'
135
+ }
136
+ obj['border-width'] = width
137
+
138
+ if (typeof style === 'number') {
139
+ style += 'px'
140
+ } else {
141
+ style = style.indexOf('px') ? style : style + 'px'
142
+ }
143
+ obj['border-top-style'] = style
144
+ }
145
+ let classles = ''
146
+ for (let i in obj) {
147
+ classles += `${i}:${obj[i]};`
148
+ }
149
+ return classles
150
+ }
151
+ },
152
+
153
+ methods: {
154
+ uploadFiles(item, index) {
155
+ this.$emit("uploadFiles", {
156
+ item,
157
+ index
158
+ })
159
+ },
160
+ choose() {
161
+ this.$emit("choose")
162
+ },
163
+ delFile(index) {
164
+ this.$emit('delFile', index)
165
+ },
166
+ value2px(value) {
167
+ if (typeof value === 'number') {
168
+ value += 'px'
169
+ } else {
170
+ value = value.indexOf('px') !== -1 ? value : value + 'px'
171
+ }
172
+ return value
173
+ }
174
+ }
175
+ }
176
+ </script>
177
+
178
+ <style lang="scss">
179
+ .uni-file-picker__files {
180
+ /* #ifndef APP-NVUE */
181
+ display: flex;
182
+ /* #endif */
183
+ flex-direction: column;
184
+ justify-content: flex-start;
185
+ }
186
+
187
+ .files-button {
188
+ // border: 1px red solid;
189
+ }
190
+
191
+ .uni-file-picker__lists {
192
+ position: relative;
193
+ margin-top: 5px;
194
+ overflow: hidden;
195
+ }
196
+
197
+ .file-picker__mask {
198
+ /* #ifndef APP-NVUE */
199
+ display: flex;
200
+ /* #endif */
201
+ justify-content: center;
202
+ align-items: center;
203
+ position: absolute;
204
+ right: 0;
205
+ top: 0;
206
+ bottom: 0;
207
+ left: 0;
208
+ color: #fff;
209
+ font-size: 14px;
210
+ background-color: rgba(0, 0, 0, 0.4);
211
+ }
212
+
213
+ .uni-file-picker__lists-box {
214
+ position: relative;
215
+ }
216
+
217
+ .uni-file-picker__item {
218
+ /* #ifndef APP-NVUE */
219
+ display: flex;
220
+ /* #endif */
221
+ align-items: center;
222
+ padding: 8px 10px;
223
+ padding-right: 5px;
224
+ padding-left: 10px;
225
+ }
226
+
227
+ .files-border {
228
+ border-top: 1px #eee solid;
229
+ }
230
+
231
+ .files__name {
232
+ flex: 1;
233
+ font-size: 14px;
234
+ color: #666;
235
+ margin-right: 25px;
236
+ /* #ifndef APP-NVUE */
237
+ word-break: break-all;
238
+ word-wrap: break-word;
239
+ /* #endif */
240
+ }
241
+
242
+ .icon-files {
243
+ /* #ifndef APP-NVUE */
244
+ position: static;
245
+ background-color: initial;
246
+ /* #endif */
247
+ }
248
+
249
+ // .icon-files .icon-del {
250
+ // background-color: #333;
251
+ // width: 12px;
252
+ // height: 1px;
253
+ // }
254
+
255
+
256
+ .is-list-card {
257
+ border: 1px #eee solid;
258
+ margin-bottom: 5px;
259
+ border-radius: 5px;
260
+ box-shadow: 0 0 2px 0px rgba(0, 0, 0, 0.1);
261
+ padding: 5px;
262
+ }
263
+
264
+ .files__image {
265
+ width: 40px;
266
+ height: 40px;
267
+ margin-right: 10px;
268
+ }
269
+
270
+ .header-image {
271
+ width: 100%;
272
+ height: 100%;
273
+ }
274
+
275
+ .is-text-box {
276
+ border: 1px #eee solid;
277
+ border-radius: 5px;
278
+ }
279
+
280
+ .is-text-image {
281
+ width: 25px;
282
+ height: 25px;
283
+ margin-left: 5px;
284
+ }
285
+
286
+ .rotate {
287
+ position: absolute;
288
+ transform: rotate(90deg);
289
+ }
290
+
291
+ .icon-del-box {
292
+ /* #ifndef APP-NVUE */
293
+ display: flex;
294
+ margin: auto 0;
295
+ /* #endif */
296
+ align-items: center;
297
+ justify-content: center;
298
+ position: absolute;
299
+ top: 0px;
300
+ bottom: 0;
301
+ right: 5px;
302
+ height: 26px;
303
+ width: 26px;
304
+ // border-radius: 50%;
305
+ // background-color: rgba(0, 0, 0, 0.5);
306
+ z-index: 2;
307
+ transform: rotate(-45deg);
308
+ }
309
+
310
+ .icon-del {
311
+ width: 15px;
312
+ height: 1px;
313
+ background-color: #333;
314
+ // border-radius: 1px;
315
+ }
316
+
317
+ /* #ifdef H5 */
318
+ @media all and (min-width: 768px) {
319
+ .uni-file-picker__files {
320
+ max-width: 375px;
321
+ }
322
+ }
323
+
324
+ /* #endif */
325
+ </style>
@@ -0,0 +1,292 @@
1
+ <template>
2
+ <view class="uni-file-picker__container">
3
+ <view class="file-picker__box" v-for="(item,index) in filesList" :key="index" :style="boxStyle">
4
+ <view class="file-picker__box-content" :style="borderStyle">
5
+ <image class="file-image" :src="item.url" mode="aspectFill" @click.stop="prviewImage(item,index)"></image>
6
+ <view v-if="delIcon && !readonly" class="icon-del-box" @click.stop="delFile(index)">
7
+ <view class="icon-del"></view>
8
+ <view class="icon-del rotate"></view>
9
+ </view>
10
+ <view v-if="(item.progress && item.progress !== 100) ||item.progress===0 " class="file-picker__progress">
11
+ <progress class="file-picker__progress-item" :percent="item.progress === -1?0:item.progress" stroke-width="4"
12
+ :backgroundColor="item.errMsg?'#ff5a5f':'#EBEBEB'" />
13
+ </view>
14
+ <view v-if="item.errMsg" class="file-picker__mask" @click.stop="uploadFiles(item,index)">
15
+ 点击重试
16
+ </view>
17
+ </view>
18
+ </view>
19
+ <view v-if="filesList.length < limit && !readonly" class="file-picker__box" :style="boxStyle">
20
+ <view class="file-picker__box-content is-add" :style="borderStyle" @click="choose">
21
+ <slot>
22
+ <view class="icon-add"></view>
23
+ <view class="icon-add rotate"></view>
24
+ </slot>
25
+ </view>
26
+ </view>
27
+ </view>
28
+ </template>
29
+
30
+ <script>
31
+ export default {
32
+ name: "uploadImage",
33
+ emits:['uploadFiles','choose','delFile'],
34
+ props: {
35
+ filesList: {
36
+ type: Array,
37
+ default () {
38
+ return []
39
+ }
40
+ },
41
+ disabled:{
42
+ type: Boolean,
43
+ default: false
44
+ },
45
+ disablePreview: {
46
+ type: Boolean,
47
+ default: false
48
+ },
49
+ limit: {
50
+ type: [Number, String],
51
+ default: 9
52
+ },
53
+ imageStyles: {
54
+ type: Object,
55
+ default () {
56
+ return {
57
+ width: 'auto',
58
+ height: 'auto',
59
+ border: {}
60
+ }
61
+ }
62
+ },
63
+ delIcon: {
64
+ type: Boolean,
65
+ default: true
66
+ },
67
+ readonly:{
68
+ type:Boolean,
69
+ default:false
70
+ }
71
+ },
72
+ computed: {
73
+ styles() {
74
+ let styles = {
75
+ width: 'auto',
76
+ height: 'auto',
77
+ border: {}
78
+ }
79
+ return Object.assign(styles, this.imageStyles)
80
+ },
81
+ boxStyle() {
82
+ const {
83
+ width = 'auto',
84
+ height = 'auto'
85
+ } = this.styles
86
+ let obj = {}
87
+ if (height === 'auto') {
88
+ if (width !== 'auto') {
89
+ obj.height = this.value2px(width)
90
+ obj['padding-top'] = 0
91
+ } else {
92
+ obj.height = 0
93
+ }
94
+ } else {
95
+ obj.height = this.value2px(height)
96
+ obj['padding-top'] = 0
97
+ }
98
+
99
+ if (width === 'auto') {
100
+ if (height !== 'auto') {
101
+ obj.width = this.value2px(height)
102
+ } else {
103
+ obj.width = '33.3%'
104
+ }
105
+ } else {
106
+ obj.width = this.value2px(width)
107
+ }
108
+
109
+ let classles = ''
110
+ for(let i in obj){
111
+ classles+= `${i}:${obj[i]};`
112
+ }
113
+ return classles
114
+ },
115
+ borderStyle() {
116
+ let {
117
+ border
118
+ } = this.styles
119
+ let obj = {}
120
+ const widthDefaultValue = 1
121
+ const radiusDefaultValue = 3
122
+ if (typeof border === 'boolean') {
123
+ obj.border = border ? '1px #eee solid' : 'none'
124
+ } else {
125
+ let width = (border && border.width) || widthDefaultValue
126
+ width = this.value2px(width)
127
+ let radius = (border && border.radius) || radiusDefaultValue
128
+ radius = this.value2px(radius)
129
+ obj = {
130
+ 'border-width': width,
131
+ 'border-style': (border && border.style) || 'solid',
132
+ 'border-color': (border && border.color) || '#eee',
133
+ 'border-radius': radius
134
+ }
135
+ }
136
+ let classles = ''
137
+ for(let i in obj){
138
+ classles+= `${i}:${obj[i]};`
139
+ }
140
+ return classles
141
+ }
142
+ },
143
+ methods: {
144
+ uploadFiles(item, index) {
145
+ this.$emit("uploadFiles", item)
146
+ },
147
+ choose() {
148
+ this.$emit("choose")
149
+ },
150
+ delFile(index) {
151
+ this.$emit('delFile', index)
152
+ },
153
+ prviewImage(img, index) {
154
+ let urls = []
155
+ if(Number(this.limit) === 1&&this.disablePreview&&!this.disabled){
156
+ this.$emit("choose")
157
+ }
158
+ if(this.disablePreview) return
159
+ this.filesList.forEach(i => {
160
+ urls.push(i.url)
161
+ })
162
+
163
+ uni.previewImage({
164
+ urls: urls,
165
+ current: index
166
+ });
167
+ },
168
+ value2px(value) {
169
+ if (typeof value === 'number') {
170
+ value += 'px'
171
+ } else {
172
+ if (value.indexOf('%') === -1) {
173
+ value = value.indexOf('px') !== -1 ? value : value + 'px'
174
+ }
175
+ }
176
+ return value
177
+ }
178
+ }
179
+ }
180
+ </script>
181
+
182
+ <style lang="scss">
183
+ .uni-file-picker__container {
184
+ /* #ifndef APP-NVUE */
185
+ display: flex;
186
+ box-sizing: border-box;
187
+ /* #endif */
188
+ flex-wrap: wrap;
189
+ margin: -5px;
190
+ }
191
+
192
+ .file-picker__box {
193
+ position: relative;
194
+ // flex: 0 0 33.3%;
195
+ width: 33.3%;
196
+ height: 0;
197
+ padding-top: 33.33%;
198
+ /* #ifndef APP-NVUE */
199
+ box-sizing: border-box;
200
+ /* #endif */
201
+ }
202
+
203
+ .file-picker__box-content {
204
+ position: absolute;
205
+ top: 0;
206
+ right: 0;
207
+ bottom: 0;
208
+ left: 0;
209
+ margin: 5px;
210
+ border: 1px #eee solid;
211
+ border-radius: 5px;
212
+ overflow: hidden;
213
+ }
214
+
215
+ .file-picker__progress {
216
+ position: absolute;
217
+ bottom: 0;
218
+ left: 0;
219
+ right: 0;
220
+ /* border: 1px red solid; */
221
+ z-index: 2;
222
+ }
223
+
224
+ .file-picker__progress-item {
225
+ width: 100%;
226
+ }
227
+
228
+ .file-picker__mask {
229
+ /* #ifndef APP-NVUE */
230
+ display: flex;
231
+ /* #endif */
232
+ justify-content: center;
233
+ align-items: center;
234
+ position: absolute;
235
+ right: 0;
236
+ top: 0;
237
+ bottom: 0;
238
+ left: 0;
239
+ color: #fff;
240
+ font-size: 12px;
241
+ background-color: rgba(0, 0, 0, 0.4);
242
+ }
243
+
244
+ .file-image {
245
+ width: 100%;
246
+ height: 100%;
247
+ }
248
+
249
+ .is-add {
250
+ /* #ifndef APP-NVUE */
251
+ display: flex;
252
+ /* #endif */
253
+ align-items: center;
254
+ justify-content: center;
255
+ }
256
+
257
+ .icon-add {
258
+ width: 50px;
259
+ height: 5px;
260
+ background-color: #f1f1f1;
261
+ border-radius: 2px;
262
+ }
263
+
264
+ .rotate {
265
+ position: absolute;
266
+ transform: rotate(90deg);
267
+ }
268
+
269
+ .icon-del-box {
270
+ /* #ifndef APP-NVUE */
271
+ display: flex;
272
+ /* #endif */
273
+ align-items: center;
274
+ justify-content: center;
275
+ position: absolute;
276
+ top: 3px;
277
+ right: 3px;
278
+ height: 26px;
279
+ width: 26px;
280
+ border-radius: 50%;
281
+ background-color: rgba(0, 0, 0, 0.5);
282
+ z-index: 2;
283
+ transform: rotate(-45deg);
284
+ }
285
+
286
+ .icon-del {
287
+ width: 15px;
288
+ height: 2px;
289
+ background-color: #fff;
290
+ border-radius: 2px;
291
+ }
292
+ </style>
@@ -0,0 +1,109 @@
1
+ /**
2
+ * 获取文件名和后缀
3
+ * @param {String} name
4
+ */
5
+ export const get_file_ext = (name) => {
6
+ const last_len = name.lastIndexOf('.')
7
+ const len = name.length
8
+ return {
9
+ name: name.substring(0, last_len),
10
+ ext: name.substring(last_len + 1, len)
11
+ }
12
+ }
13
+
14
+ /**
15
+ * 获取扩展名
16
+ * @param {Array} fileExtname
17
+ */
18
+ export const get_extname = (fileExtname) => {
19
+ if (!Array.isArray(fileExtname)) {
20
+ let extname = fileExtname.replace(/(\[|\])/g, '')
21
+ return extname.split(',')
22
+ } else {
23
+ return fileExtname
24
+ }
25
+ return []
26
+ }
27
+
28
+ /**
29
+ * 获取文件和检测是否可选
30
+ */
31
+ export const get_files_and_is_max = (res, _extname) => {
32
+ let filePaths = []
33
+ let files = []
34
+ if(!_extname || _extname.length === 0){
35
+ return {
36
+ filePaths,
37
+ files
38
+ }
39
+ }
40
+ res.tempFiles.forEach(v => {
41
+ let fileFullName = get_file_ext(v.name)
42
+ const extname = fileFullName.ext.toLowerCase()
43
+ if (_extname.indexOf(extname) !== -1) {
44
+ files.push(v)
45
+ filePaths.push(v.path)
46
+ }
47
+ })
48
+ if (files.length !== res.tempFiles.length) {
49
+ uni.showToast({
50
+ title: `当前选择了${res.tempFiles.length}个文件 ,${res.tempFiles.length - files.length} 个文件格式不正确`,
51
+ icon: 'none',
52
+ duration: 5000
53
+ })
54
+ }
55
+
56
+ return {
57
+ filePaths,
58
+ files
59
+ }
60
+ }
61
+
62
+
63
+ /**
64
+ * 获取图片信息
65
+ * @param {Object} filepath
66
+ */
67
+ export const get_file_info = (filepath) => {
68
+ return new Promise((resolve, reject) => {
69
+ uni.getImageInfo({
70
+ src: filepath,
71
+ success(res) {
72
+ resolve(res)
73
+ },
74
+ fail(err) {
75
+ reject(err)
76
+ }
77
+ })
78
+ })
79
+ }
80
+ /**
81
+ * 获取封装数据
82
+ */
83
+ export const get_file_data = async (files, type = 'image') => {
84
+ // 最终需要上传数据库的数据
85
+ let fileFullName = get_file_ext(files.name)
86
+ const extname = fileFullName.ext.toLowerCase()
87
+ let filedata = {
88
+ name: files.name,
89
+ uuid: files.uuid,
90
+ extname: extname || '',
91
+ cloudPath: files.cloudPath,
92
+ fileType: files.fileType,
93
+ url: files.path || files.path,
94
+ size: files.size, //单位是字节
95
+ image: {},
96
+ path: files.path,
97
+ video: {}
98
+ }
99
+ if (type === 'image') {
100
+ const imageinfo = await get_file_info(files.path)
101
+ delete filedata.video
102
+ filedata.image.width = imageinfo.width
103
+ filedata.image.height = imageinfo.height
104
+ filedata.image.location = imageinfo.path
105
+ } else {
106
+ delete filedata.image
107
+ }
108
+ return filedata
109
+ }