lw-cdp-ui 1.1.35 → 1.1.37

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.
@@ -78,9 +78,10 @@
78
78
  :accept="_item.accept"
79
79
  :title="_item.label"
80
80
  :parseData="item.parseData"
81
- :disabled="item.options?.disabled"
81
+ :disabled="_item?.disabled"
82
82
  :multiple="_item?.multiple"
83
83
  :limit="_item?.limit"
84
+ :returnFile="_item?.returnFile"
84
85
  :tip="_item?.tip"
85
86
  :apiObj="item.apiObj"></lw-upload>
86
87
  </div>
@@ -92,9 +93,10 @@
92
93
  :accept="_item.accept"
93
94
  :title="_item.label"
94
95
  :parseData="item.parseData"
95
- :disabled="item.options?.disabled"
96
+ :disabled="_item?.disabled"
96
97
  :multiple="_item?.multiple"
97
98
  :limit="_item?.limit"
99
+ :returnFile="_item?.returnFile"
98
100
  :tip="_item?.tip"
99
101
  :apiObj="item.apiObj"></lw-upload>
100
102
  </div>
@@ -60,9 +60,10 @@
60
60
  :accept="_item.accept"
61
61
  :title="_item.label"
62
62
  :parseData="item.parseData"
63
- :disabled="item.options?.disabled"
63
+ :disabled="_item?.disabled"
64
64
  :multiple="_item?.multiple"
65
65
  :limit="_item?.limit"
66
+ :returnFile="_item?.returnFile"
66
67
  :tip="_item?.tip"
67
68
  :apiObj="item.apiObj"></lw-upload>
68
69
 
@@ -1,14 +1,12 @@
1
1
  <template>
2
2
  <div class="lw-upload"
3
3
  :class="{ 'lw-upload-round': round }">
4
-
5
- <div v-if="fileList.length > 0"
6
- class="view-img-list">
4
+ <div class="view-img-list">
7
5
  <template v-for="(f, index) in fileList">
8
6
  <div class="lw-upload__img"
9
7
  :style="style">
10
8
  <el-image class="image"
11
- :src="f"
9
+ :src="getShowValue(f)"
12
10
  :preview-src-list="fileList"
13
11
  fit="cover"
14
12
  hide-on-click-modal
@@ -29,6 +27,36 @@
29
27
  </div>
30
28
  </div>
31
29
  </template>
30
+
31
+ <el-upload v-if="fileList.length < limit"
32
+ class="uploader"
33
+ :style="style"
34
+ ref="uploader"
35
+ :auto-upload="autoUpload"
36
+ :disabled="disabled"
37
+ :show-file-list="showFileList"
38
+ :action="action"
39
+ :name="name"
40
+ :data="data"
41
+ :accept="accept"
42
+ :limit="limit"
43
+ :http-request="request"
44
+ :on-change="change"
45
+ :before-upload="before"
46
+ :on-success="success"
47
+ :on-error="error"
48
+ :on-exceed="handleExceed">
49
+ <slot>
50
+ <div class="el-upload--picture-card">
51
+ <div class="file-empty">
52
+ <el-icon>
53
+ <component :is="icon" />
54
+ </el-icon>
55
+ <h4 v-if="title">{{ title }}</h4>
56
+ </div>
57
+ </div>
58
+ </slot>
59
+ </el-upload>
32
60
  </div>
33
61
 
34
62
  <div v-if="file && file.status != 'success'"
@@ -43,35 +71,6 @@
43
71
  fit="cover"></el-image>
44
72
  </div>
45
73
 
46
- <el-upload v-if="fileList.length < limit"
47
- class="uploader"
48
- :style="style"
49
- ref="uploader"
50
- :auto-upload="autoUpload"
51
- :disabled="disabled"
52
- :show-file-list="showFileList"
53
- :action="action"
54
- :name="name"
55
- :data="data"
56
- :accept="accept"
57
- :limit="limit"
58
- :http-request="request"
59
- :on-change="change"
60
- :before-upload="before"
61
- :on-success="success"
62
- :on-error="error"
63
- :on-exceed="handleExceed">
64
- <slot>
65
- <div class="el-upload--picture-card">
66
- <div class="file-empty">
67
- <el-icon>
68
- <component :is="icon" />
69
- </el-icon>
70
- <h4 v-if="title">{{ title }}</h4>
71
- </div>
72
- </div>
73
- </slot>
74
- </el-upload>
75
74
  <div class="el-upload__tip">
76
75
  {{tip}}
77
76
  </div>
@@ -100,6 +99,7 @@ export default {
100
99
  * @property {Boolean} disabled - 是否禁用上传功能,默认为 false
101
100
  * @property {Boolean} round - 是否显示圆角按钮,默认为 false
102
101
  * @property {Boolean} multiple - 是否多个文件,默认为 false
102
+ * @property {Array} returnFile - 需要返回的字段,例如为 ['url', 'type', 'name'] 第一个参数为图片地址
103
103
  * @property {Function} onSuccess - 上传成功后的回调函数,默认为空函数
104
104
  * @property {Function} parseData - 解析上传响应数据的函数,默认为解析状态码、文件名、图片远程地址和描述字段
105
105
  */
@@ -123,6 +123,19 @@ export default {
123
123
  disabled: { type: Boolean, default: false },
124
124
  round: { type: Boolean, default: false },
125
125
  onSuccess: { type: Function, default: () => { return true } },
126
+ returnFile: { // 单传'url' 就返回数组 传对象映射关系就返回数组对象
127
+ type: [Object, String],
128
+ default: {
129
+ url: 'url', // 第一个就是默认图片字段
130
+ code: 'code',
131
+ fileName: 'fileName',
132
+ src: 'src',
133
+ type: 'type',
134
+ name: 'name',
135
+ size: 'size',
136
+ tempCropperFile: 'tempCropperFile',
137
+ }
138
+ },
126
139
  parseData: {
127
140
  type: Function, default: (res) => {
128
141
  return {
@@ -164,7 +177,7 @@ export default {
164
177
  methods: {
165
178
  newFile(url) {
166
179
  if (this.multiple) {
167
- this.fileList = url
180
+ this.fileList = url || []
168
181
  } else {
169
182
  this.fileList = url ? [url] : []
170
183
  }
@@ -241,9 +254,15 @@ export default {
241
254
  this.$refs.uploader.handleStart(file)
242
255
  },
243
256
  success(res, file) {
257
+ file.type = file.raw.type
244
258
  //释放内存删除blob
245
259
  URL.revokeObjectURL(file.tempFile)
246
260
  delete file.tempFile
261
+ delete file.percentage
262
+ delete file.raw
263
+ delete file.response
264
+ delete file.status
265
+ delete file.uid
247
266
  var os = this.onSuccess(res, file)
248
267
  if (os != undefined && os == false) {
249
268
  this.$nextTick(() => {
@@ -252,9 +271,23 @@ export default {
252
271
  })
253
272
  return false
254
273
  }
255
- var response = this.parseData(res, file)
274
+ var response = this.parseData(res)
256
275
  file.url = response.src
257
- this.fileList.push(file.url)
276
+
277
+ // 自定义返回内容
278
+ let sourceObject = { ...response, ...file }
279
+ if (typeof this.returnFile == 'object') {
280
+ let mappedObject = Object.entries(this.returnFile).reduce((acc, [key, value]) => {
281
+ if (sourceObject[key] !== undefined) {
282
+ acc[value] = sourceObject[key];
283
+ }
284
+ return acc;
285
+ }, {})
286
+ this.fileList.push(mappedObject)
287
+ } else {
288
+ this.fileList.push(sourceObject[this.returnFile])
289
+ }
290
+
258
291
  if (this.multiple) {
259
292
  this.value = this.fileList
260
293
  } else {
@@ -293,6 +326,19 @@ export default {
293
326
  }).catch(err => {
294
327
  param.onError(err)
295
328
  })
329
+ },
330
+ // 获取显示字段内容
331
+ getShowValue(item) {
332
+ if (this.multiple) {
333
+ if (typeof this.returnFile == 'object') {
334
+ console.log(Object.keys(this.returnFile)[0])
335
+ return item[this.returnFile[Object.keys(this.returnFile)[0]]]
336
+ } else {
337
+ return item
338
+ }
339
+ } else {
340
+ return item
341
+ }
296
342
  }
297
343
  }
298
344
  }