mali-applet-ui 0.2.78 → 0.2.80

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.
@@ -64,6 +64,7 @@ export default {
64
64
  .ml-dict-type {
65
65
  display: inline-block;
66
66
  padding: 0 4rpx;
67
+ vertical-align: middle;
67
68
  &+.ml-dict-type {
68
69
  margin-left: 20rpx;
69
70
  }
@@ -257,6 +257,9 @@ export default {
257
257
  width: 100%;
258
258
  padding: 10rpx 0;
259
259
  }
260
+ .ml-form-item-default-content {
261
+ vertical-align: middle;
262
+ }
260
263
  .ml-form-item-content-error {
261
264
  position: absolute;
262
265
  left: 0;
@@ -50,10 +50,6 @@ export default {
50
50
  align: String,
51
51
  border: Boolean,
52
52
  type: String,
53
- maxLength: {
54
- type: Number,
55
- default: 12
56
- },
57
53
  min: [String, Number],
58
54
  max: [String, Number],
59
55
  step: [String, Number],
@@ -89,6 +85,12 @@ export default {
89
85
  isFromReadonly () {
90
86
  return this.form ? this.form.readonly : false
91
87
  },
88
+ maxLength () {
89
+ if (this.type === 'integer') {
90
+ return this.maxNum ? `${this.maxNum}`.length : 9
91
+ }
92
+ return this.maxNum ? (`${this.maxNum}`.length + 3) : 12
93
+ },
92
94
  minNum () {
93
95
  if (XEUtils.isNumber(this.min) || this.min) {
94
96
  return XEUtils.toNumber(this.min || 0)
@@ -129,8 +131,8 @@ export default {
129
131
  return { status: true, value: this.inpVal }
130
132
  }
131
133
  const numVal = XEUtils.toNumber(XEUtils.toValueString(this.inpVal).slice(0, this.maxLength))
132
- if (this.type === 'integer' && !/^[0-9]$/.test(numVal)) {
133
- const value = XEUtils.toInteger(numVal)
134
+ if (this.type === 'integer' && !/^[0-9]+$/.test(numVal)) {
135
+ const value = this.maxNum ? Math.max(this.maxNum, XEUtils.toInteger(numVal)) : XEUtils.toInteger(numVal)
134
136
  this.$emit('input', value)
135
137
  return { status: false, value: value }
136
138
  }
@@ -66,6 +66,7 @@ export default {
66
66
  .ml-text {
67
67
  display: inline-block;
68
68
  padding: 0 4rpx;
69
+ vertical-align: middle;
69
70
  &.is-underline {
70
71
  text-decoration: underline;
71
72
  // #ifdef H5
@@ -95,6 +95,9 @@ export default {
95
95
  },
96
96
  computed: {
97
97
  isFromReadonly () {
98
+ if (this.readonly) {
99
+ return true
100
+ }
98
101
  return this.form ? this.form.readonly : false
99
102
  }
100
103
  },
@@ -178,7 +178,7 @@ export default {
178
178
  },
179
179
  loadList () {
180
180
  if (this.simpleValue) {
181
- this.fileList = this.urlList.map(url => {
181
+ this.fileList = (this.urlList || []).map(url => {
182
182
  const name = this.getUrlName(url)
183
183
  const obj = {
184
184
  id: null,
@@ -197,7 +197,7 @@ export default {
197
197
  this.isUpdate = true
198
198
  this.$emit('input', this.fileList)
199
199
  } else {
200
- this.fileList = this.value.map(item => {
200
+ this.fileList = (this.value || []).map(item => {
201
201
  item.tempPath = this.getUrl(item)
202
202
  return item
203
203
  })
@@ -299,7 +299,7 @@ export default {
299
299
  },
300
300
  previewDocs (item) {
301
301
  // 仅支持文档和图片
302
- if (previewTypes.includes(item[this.typeField])) {
302
+ if (this.previewTypes.includes(item[this.typeField])) {
303
303
  uni.downloadFile({
304
304
  url: this.getUrl(item),
305
305
  success: (downRes) => {
@@ -308,7 +308,7 @@ export default {
308
308
  filePath: downRes.tempFilePath,
309
309
  showMenu: true,
310
310
  success () {},
311
- fail () {
311
+ fail: () => {
312
312
  uni.showModal({
313
313
  content: '打开失败',
314
314
  showCancel: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "0.2.78",
3
+ "version": "0.2.80",
4
4
  "description": "码里云小程序组件库",
5
5
  "scripts": {
6
6
  "release": "node script/release.js && npm publish"
@@ -1,410 +0,0 @@
1
- <template>
2
- <view class="ml-upload" :class="[className || '']">
3
- <view v-if="isFromReadonly">
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
- props: {
35
- value: {
36
- type: Array,
37
- default: () => ([])
38
- },
39
- urlList: {
40
- type: Array,
41
- default: () => ([])
42
- },
43
- simpleValue: {
44
- type: Boolean,
45
- default: false
46
- },
47
- readonly: {
48
- type: Boolean,
49
- default: false
50
- },
51
- limit: {
52
- type: Number,
53
- default: 9
54
- },
55
- className: String,
56
- mediatype: {
57
- type: String,
58
- default: 'all'
59
- },
60
- params: {
61
- type: Object,
62
- default: () => ({})
63
- },
64
- fileProps: {
65
- type: Object,
66
- default: () => ({})
67
- },
68
- getFileUrl: Function,
69
- uploadFile: Function,
70
- removeFile: Function
71
- },
72
- inject: {
73
- currVM: {
74
- from: '$pageVM',
75
- default: null
76
- },
77
- form: {
78
- from: 'mlForm',
79
- default: null
80
- }
81
- },
82
- data () {
83
- return {
84
- fileList: [],
85
- selectUniFileList: [],
86
- imageStyles: {
87
- // "height": 60, // 边框高度
88
- // "width": 60, // 边框宽度
89
- // "border":{ // 如果为 Boolean 值,可以控制边框显示与否
90
- // "color":"transparent", // 边框颜色
91
- // "width":"1px", // 边框宽度
92
- // "style":"solid", // 边框样式
93
- // }
94
- },
95
- imgTypes: ['png', 'jpg']
96
- }
97
- },
98
- computed: {
99
- isFromReadonly () {
100
- if (this.readonly) {
101
- return true
102
- }
103
- return this.form ? this.form.readonly : false
104
- },
105
- imageList () {
106
- return this.value ? this.value.filter(item => this.imgTypes.includes(item[this.typeField])) : []
107
- },
108
- fieldMaps () {
109
- return { ...globalStore.upload.fileProps, ...this.fileProps }
110
- },
111
- urlField () {
112
- return this.fieldMaps.fileUrl || 'fileUrl'
113
- },
114
- typeField () {
115
- return this.fieldMaps.fileType || 'fileType'
116
- },
117
- nameField () {
118
- return this.fieldMaps.fileName || 'fileName'
119
- }
120
- },
121
- watch: {
122
- value (val) {
123
- if (!this.isUpdate) {
124
- this.isUpdate = true
125
- this.loadList()
126
- }
127
- },
128
- urlList () {
129
- this.loadList()
130
- }
131
- },
132
- created () {
133
- this.loadList()
134
- },
135
- methods: {
136
- loadList () {
137
- if (this.simpleValue) {
138
- this.fileList = this.urlList.map(url => {
139
- const name = this.getUrlName(url)
140
- const obj = {
141
- id: null,
142
- [this.nameField]: name,
143
- [this.typeField]: this.getSuffix(name),
144
- [this.urlField]: url
145
- }
146
- return {
147
- id: null,
148
- [this.nameField]: name,
149
- [this.typeField]: this.getSuffix(name),
150
- [this.urlField]: url,
151
- tempPath: this.getUrl(obj)
152
- }
153
- })
154
- this.selectUniFileList = this.urlList.map(url => {
155
- const name = this.getUrlName(url)
156
- const extname = this.getSuffix(name)
157
- const obj = {
158
- [this.nameField]: name,
159
- [this.typeField]: extname,
160
- [this.urlField]: url
161
- }
162
- return {
163
- ...obj,
164
- name: name,
165
- extname: extname,
166
- url: this.getUrl(obj)
167
- }
168
- })
169
- this.isUpdate = true
170
- this.$emit('input', this.fileList)
171
- } else {
172
- this.fileList = this.value.map(item => {
173
- item.tempPath = this.getUrl(item)
174
- return item
175
- })
176
- this.selectUniFileList = this.value.map(item => {
177
- return {
178
- ...item,
179
- name: item[this.nameField],
180
- extname: item[this.typeField],
181
- url: this.getUrl(item)
182
- }
183
- })
184
- }
185
- },
186
- updateModel () {
187
- const urlList = this.fileList.map(item => item[this.urlField])
188
- this.$emit('update:urlList', urlList)
189
- this.$emit('input', this.fileList)
190
- this.$emit('change', { value: this.simpleValue ? urlList : this.fileList })
191
- },
192
- async selectFile (e) {
193
- const { tempFiles } = e
194
- if (this.$loading) {
195
- this.$loading.show('上传中')
196
- }
197
- const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
198
- Promise.all(
199
- tempFiles.map(file => {
200
- const fileSuffix = this.getSuffix(file.name)
201
- if (uploadMethod) {
202
- return Promise.resolve(
203
- uploadMethod.call(this.currVM, {
204
- file,
205
- params: this.params
206
- })
207
- ).then(res => {
208
- const item = {
209
- ...res,
210
- [this.nameField]: res[this.nameField] || file.name,
211
- [this.typeField]: res[this.typeField] || fileSuffix,
212
- tempPath: file.path
213
- }
214
- this.selectUniFileList.push(file)
215
- this.fileList.push(item)
216
- this.isUpdate = true
217
- this.updateModel()
218
- })
219
- } else {
220
- const item = {
221
- [this.nameField]: file.name,
222
- [this.typeField]: file.extname,
223
- [this.urlField]: file.path,
224
- tempPath: file.path
225
- }
226
- this.selectUniFileList.push(file)
227
- this.fileList.push(item)
228
- this.isUpdate = true
229
- this.updateModel()
230
- }
231
- })
232
- ).then(res => {
233
- if (this.$loading) {
234
- this.$loading.hide()
235
- }
236
- }).catch((e) => {
237
- if (this.$loading) {
238
- this.$loading.hide()
239
- }
240
- })
241
- },
242
- removeEvent (e) {
243
- const { tempFilePath } = e
244
- const item = this.fileList.find(item => item.tempPath === tempFilePath)
245
- this.selectUniFileList = this.selectUniFileList.filter(item => item.url !== tempFilePath)
246
- this.fileList = this.fileList.filter(item => item.tempPath !== tempFilePath)
247
- const removeMethod = this.removeFile ? this.removeFile : (globalStore.upload ? globalStore.upload.removeFile : null)
248
- if (!item) {
249
- console.error('删除出错!!!')
250
- }
251
- if (item && !item.id) {
252
- if (removeMethod) {
253
- removeMethod.call(this.currVM, {
254
- item,
255
- params: this.params
256
- })
257
- }
258
- }
259
- this.isUpdate = true
260
- this.updateModel()
261
- },
262
- getUrl (item) {
263
- const getFileMethod = this.getFileUrl ? this.getFileUrl : (globalStore.upload ? globalStore.upload.getFileUrl : null)
264
- if (getFileMethod) {
265
- return getFileMethod.call(this.currVM, {
266
- item,
267
- params: this.params
268
- })
269
- }
270
- return item[this.urlField]
271
- },
272
- getUrlName (url) {
273
- const urlRest = XEUtils.parseUrl(url)
274
- return urlRest.pathname.split('/').slice(-1)[0] || ''
275
- },
276
- getSuffix (filename) {
277
- const pos = filename.lastIndexOf('.')
278
- let suffix = ''
279
- if (pos !== -1) {
280
- suffix = filename.substring(pos + 1)
281
- }
282
- return suffix
283
- },
284
- previewEvent (item, index) {
285
- if (this.previewStatus) {
286
- return
287
- }
288
- this.previewStatus = true
289
- Promise.all(
290
- this.value.map(item => {
291
- return new Promise((resolve) => {
292
- uni.downloadFile({
293
- url: this.getUrl(item),
294
- success: (downRes) => {
295
- resolve({
296
- url: downRes.tempFilePath
297
- })
298
- },
299
- fail () {
300
- resolve({
301
- url: ''
302
- })
303
- }
304
- })
305
- })
306
- })
307
- ).then(res => {
308
- uni.previewImage({
309
- current: index,
310
- urls: res.map(item => item.url)
311
- })
312
- this.previewStatus = false
313
- })
314
- },
315
- previewImg (item) {
316
- uni.downloadFile({
317
- url: this.getUrl(item),
318
- success: (downRes) => {
319
- uni.previewImage({
320
- urls: [
321
- downRes.tempFilePath
322
- ],
323
- longPressActions: {
324
- itemList: ['保存图片']
325
- }
326
- })
327
- }
328
- })
329
- },
330
- downloadEvent (item) {
331
- uni.downloadFile({
332
- url: this.getUrl(item),
333
- success: (downRes) => {
334
- // 仅支持类型
335
- if (['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx'].includes(item[this.typeField])) {
336
- uni.openDocument({
337
- filePath: downRes.tempFilePath,
338
- showMenu: true,
339
- success (saveRes) {
340
- },
341
- fail () {
342
- uni.showModal({
343
- content: '打开失败',
344
- showCancel: false
345
- });
346
- }
347
- })
348
- } else if (['png', 'jpg'].includes(item[this.typeField])) {
349
- this.previewImg(item)
350
- } else {
351
- uni.saveFile({
352
- tempFilePath: downRes.tempFilePath,
353
- success: function(res) {
354
- uni.showToast({
355
- icon: 'none',
356
- mask: true,
357
- title: '文件已保存:' + res.savedFilePath, //保存路径
358
- duration: 3000,
359
- })
360
- }
361
- })
362
-
363
- }
364
- },
365
- fail () {
366
- uni.showModal({
367
- content: '下载失败',
368
- showCancel: false
369
- });
370
- }
371
- })
372
- }
373
- }
374
- }
375
- </script>
376
-
377
- <style lang="scss">
378
- .ml-upload{
379
- margin: 20rpx 0;
380
- background: #fff;
381
- }
382
- .ml-upload-image-list {
383
- .ml-upload-file-item {
384
- display: inline-block;
385
- width: 140rpx;
386
- height: 140rpx;
387
- padding: 0 10rpx;
388
- }
389
- .ml-upload-file-img {
390
- width: 100%;
391
- height: 100%;
392
- }
393
- }
394
- .ml-upload-file-list {
395
- display: block;
396
- .ml-upload-file-item {
397
- border: 1rpx solid rgba(39, 42, 48, 0.0200);
398
- background-color: rgba(39, 42, 48, 0.0200);
399
- margin: 10rpx 0;
400
- border-radius: $ml-border-radius;
401
- padding: 20rpx;
402
- }
403
- .ml-upload-file-name {
404
- width: 600rpx;
405
- overflow: hidden;
406
- text-overflow: ellipsis;
407
- white-space: nowrap;
408
- }
409
- }
410
- </style>