mali-applet-ui 0.0.40 → 0.0.41

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.
@@ -2,7 +2,7 @@
2
2
  <input
3
3
  class="ml-amount-input"
4
4
  v-model="inpVal"
5
- type="text"
5
+ type="digit"
6
6
  :class="[{'is-right': align === 'right', 'is-border': border}, className]"
7
7
  autocomplete="off"
8
8
  :placeholder="placeholder"
@@ -2,7 +2,7 @@
2
2
  <input
3
3
  class="ml-number-input"
4
4
  v-model="inpVal"
5
- type="text"
5
+ :type="type === 'integer' ? 'number' : 'digit'"
6
6
  :class="[className || '', {'is-right': align === 'right', 'is-border': border}]"
7
7
  autocomplete="off"
8
8
  :placeholder="placeholder"
@@ -21,6 +21,7 @@ export default {
21
21
  value: String,
22
22
  align: String,
23
23
  border: Boolean,
24
+ type: String,
24
25
  maxLength: {
25
26
  type: Number,
26
27
  default: 12
@@ -0,0 +1,350 @@
1
+ <template>
2
+ <view class="ml-upload" :class="className">
3
+ <view v-if="readonly">
4
+ <view v-if="mediatype === 'image'" class="ml-upload-image-list">
5
+ <view class="ml-upload-file-item" v-for="(item, index) in value" :key="index">
6
+ <image class="ml-upload-file-img" mode="aspectFill" :src="getUrl(item)" @click="previewEvent(item, index)"></image>
7
+ </view>
8
+ </view>
9
+ <view v-else class="ml-upload-file-list">
10
+ <view class="ml-upload-file-item" v-for="(item, index) in value" :key="index">
11
+ <view class="ml-upload-file-name" @click="downloadEvent(item)">{{ item[nameField] }}</view>
12
+ </view>
13
+ </view>
14
+ </view>
15
+ <uni-file-picker
16
+ v-else
17
+ v-model="selectUniFileList"
18
+ :limit="limit"
19
+ file-mediatype="image"
20
+ :image-styles="imageStyles"
21
+ :auto-upload="false"
22
+ @select="selectFile"
23
+ @delete="removeEvent">
24
+ </uni-file-picker>
25
+ </view>
26
+ </template>
27
+
28
+ <script>
29
+ import XEUtils from 'xe-utils'
30
+ import globalStore from '../../config/store'
31
+
32
+ export default {
33
+ name: 'MlUpload',
34
+ options: {
35
+ virtualHost: true
36
+ },
37
+ props: {
38
+ value: {
39
+ type: Array,
40
+ default: () => ([])
41
+ },
42
+ urlList: {
43
+ type: Array,
44
+ default: () => ([])
45
+ },
46
+ simpleValue: {
47
+ type: Boolean,
48
+ default: false
49
+ },
50
+ readonly: {
51
+ type: Boolean,
52
+ default: false
53
+ },
54
+ limit: {
55
+ type: Number,
56
+ default: 9
57
+ },
58
+ className: String,
59
+ mediatype: {
60
+ type: String,
61
+ default: 'all'
62
+ },
63
+ params: {
64
+ type: Object,
65
+ default: () => ({})
66
+ },
67
+ fileProps: {
68
+ type: Object,
69
+ default: () => ({})
70
+ },
71
+ getFileUrl: Function,
72
+ uploadFile: Function,
73
+ removeFile: Function
74
+ },
75
+ data () {
76
+ return {
77
+ fileList: [],
78
+ selectUniFileList: [],
79
+ imageStyles: {
80
+ // "height": 60, // 边框高度
81
+ // "width": 60, // 边框宽度
82
+ // "border":{ // 如果为 Boolean 值,可以控制边框显示与否
83
+ // "color":"transparent", // 边框颜色
84
+ // "width":"1px", // 边框宽度
85
+ // "style":"solid", // 边框样式
86
+ // }
87
+ },
88
+ imgTypes: ['png', 'jpg']
89
+ }
90
+ },
91
+ computed: {
92
+ imageList () {
93
+ return this.value ? this.value.filter(item => this.imgTypes.includes(item[this.typeField])) : []
94
+ },
95
+ fieldMaps () {
96
+ return { ...globalStore.upload.fileProps, ...this.fileProps }
97
+ },
98
+ urlField () {
99
+ return this.fieldMaps.fileUrl || 'fileUrl'
100
+ },
101
+ typeField () {
102
+ return this.fieldMaps.fileType || 'fileType'
103
+ },
104
+ nameField () {
105
+ return this.fieldMaps.fileName || 'fileName'
106
+ }
107
+ },
108
+ watch: {
109
+ value (val) {
110
+ if (!this.isUpdate) {
111
+ this.isUpdate = true
112
+ this.loadList()
113
+ }
114
+ },
115
+ urlList () {
116
+ this.loadList()
117
+ }
118
+ },
119
+ created () {
120
+ this.loadList()
121
+ },
122
+ methods: {
123
+ loadList () {
124
+ if (this.simpleValue) {
125
+ this.fileList = this.urlList.map(url => {
126
+ const name = this.getUrlName(url)
127
+ return {
128
+ id: null,
129
+ [this.nameField]: name,
130
+ [this.typeField]: this.getSuffix(name),
131
+ [this.urlField]: url,
132
+ tempPath: url
133
+ }
134
+ })
135
+ this.selectUniFileList = this.urlList.map(url => {
136
+ const name = this.getUrlName(url)
137
+ return {
138
+ name: name,
139
+ extname: this.getSuffix(name),
140
+ url: url
141
+ }
142
+ })
143
+ this.isUpdate = true
144
+ this.$emit('input', this.fileList)
145
+ } else {
146
+ this.fileList = this.value.map(item => {
147
+ item.tempPath = item[this.urlField]
148
+ return item
149
+ })
150
+ this.selectUniFileList = this.value.map(item => {
151
+ return {
152
+ name: item[this.nameField],
153
+ extname: item[this.typeField],
154
+ url: item[this.urlField]
155
+ }
156
+ })
157
+ }
158
+ },
159
+ updateModel () {
160
+ this.$emit('update:urlList', this.fileList.map(item => item[this.urlField]))
161
+ this.$emit('input', this.fileList)
162
+ },
163
+ async selectFile (e) {
164
+ const { tempFiles } = e
165
+ uni.showLoading({
166
+ title: "上传中..."
167
+ });
168
+ const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
169
+ await Promise.all(
170
+ tempFiles.map(file => {
171
+ if (uploadMethod) {
172
+ return Promise.resolve(
173
+ uploadMethod({
174
+ file,
175
+ params: this.params
176
+ })
177
+ )
178
+ }
179
+ })
180
+ )
181
+ uni.hideLoading();
182
+ },
183
+ removeEvent (e) {
184
+ const { tempFilePath } = e
185
+ const item = this.fileList.find(item => item.tempPath === tempFilePath)
186
+ this.selectUniFileList = this.selectUniFileList.filter(item => item.url !== tempFilePath)
187
+ this.fileList = this.fileList.filter(item => item.tempPath !== tempFilePath)
188
+ const removeMethod = this.removeFile ? this.removeFile : (globalStore.upload ? globalStore.upload.removeFile : null)
189
+ if (item && !item.id) {
190
+ if (removeMethod) {
191
+ removeMethod({
192
+ item,
193
+ params: this.params
194
+ })
195
+ }
196
+ }
197
+ this.isUpdate = true
198
+ this.updateModel()
199
+ },
200
+ getUrl (item) {
201
+ const getFileMethod = this.getFileUrl ? this.getFileUrl : (globalStore.upload ? globalStore.upload.getFileUrl : null)
202
+ if (getFileMethod) {
203
+ return getFileMethod({
204
+ item,
205
+ params: this.params
206
+ })
207
+ }
208
+ return item[this.urlField]
209
+ },
210
+ getUrlName (url) {
211
+ const urlRest = XEUtils.parseUrl(url)
212
+ return urlRest.pathname.split('/').slice(-1)[0] || ''
213
+ },
214
+ getSuffix (filename) {
215
+ const pos = filename.lastIndexOf('.')
216
+ let suffix = ''
217
+ if (pos !== -1) {
218
+ suffix = filename.substring(pos + 1)
219
+ }
220
+ return suffix
221
+ },
222
+ previewEvent (item, index) {
223
+ if (this.previewStatus) {
224
+ return
225
+ }
226
+ this.previewStatus = true
227
+ Promise.all(
228
+ this.value.map(item => {
229
+ return new Promise((resolve, reject) => {
230
+ uni.downloadFile({
231
+ url: this.getUrl(item),
232
+ success: (downRes) => {
233
+ resolve({
234
+ url: downRes.tempFilePath
235
+ })
236
+ },
237
+ fail () {
238
+ resolve({
239
+ url: ''
240
+ })
241
+ }
242
+ })
243
+ })
244
+ })
245
+ ).then(res => {
246
+ if (typeof wx === 'object') {
247
+ wx.previewMedia({
248
+ current: index,
249
+ sources: res
250
+ })
251
+ }
252
+ this.previewStatus = false
253
+ })
254
+ },
255
+ previewImg (item) {
256
+ uni.downloadFile({
257
+ url: this.getUrl(item),
258
+ success: (downRes) => {
259
+ uni.previewImage({
260
+ urls: [
261
+ downRes.tempFilePath
262
+ ],
263
+ longPressActions: {
264
+ itemList: ['保存图片']
265
+ }
266
+ })
267
+ }
268
+ })
269
+ },
270
+ downloadEvent (item) {
271
+ uni.downloadFile({
272
+ url: this.getUrl(item),
273
+ success: (downRes) => {
274
+ // 仅支持类型
275
+ if (['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx'].includes(item[this.typeField])) {
276
+ uni.openDocument({
277
+ filePath: downRes.tempFilePath,
278
+ showMenu: true,
279
+ success (saveRes) {
280
+ },
281
+ fail () {
282
+ uni.showModal({
283
+ content: '打开失败',
284
+ showCancel: false
285
+ });
286
+ }
287
+ })
288
+ } else if (['png', 'jpg'].includes(item[this.typeField])) {
289
+ this.previewImg(item)
290
+ } else {
291
+ uni.saveFile({
292
+ tempFilePath: downRes.tempFilePath,
293
+ success: function(res) {
294
+ uni.showToast({
295
+ icon: 'none',
296
+ mask: true,
297
+ title: '文件已保存:' + res.savedFilePath, //保存路径
298
+ duration: 3000,
299
+ })
300
+ }
301
+ })
302
+
303
+ }
304
+ },
305
+ fail () {
306
+ uni.showModal({
307
+ content: '下载失败',
308
+ showCancel: false
309
+ });
310
+ }
311
+ })
312
+ }
313
+ }
314
+ }
315
+ </script>
316
+
317
+ <style lang="scss">
318
+ .ml-upload{
319
+ margin: 20rpx 0;
320
+ background: #fff;
321
+ }
322
+ .ml-upload-image-list {
323
+ .ml-upload-file-item {
324
+ display: inline-block;
325
+ width: 210rpx;
326
+ height: 210rpx;
327
+ padding: 0 10rpx;
328
+ }
329
+ .ml-upload-file-img {
330
+ width: 100%;
331
+ height: 100%;
332
+ }
333
+ }
334
+ .ml-upload-file-list {
335
+ display: block;
336
+ .ml-upload-file-item {
337
+ border: 1rpx solid rgba(39, 42, 48, 0.0200);
338
+ background-color: rgba(39, 42, 48, 0.0200);
339
+ margin: 10rpx 0;
340
+ border-radius: 8rpx;
341
+ padding: 20rpx;
342
+ }
343
+ .ml-upload-file-name {
344
+ width: 600rpx;
345
+ overflow: hidden;
346
+ text-overflow: ellipsis;
347
+ white-space: nowrap;
348
+ }
349
+ }
350
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "码里云小程序组件库",
5
5
  "files": [
6
6
  "components",