bri-components 1.6.7 → 1.6.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bri-components",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "author": "dengshanghui",
5
5
  "description": "a component lib for vue project",
6
6
  "main": "src/index.js",
@@ -12,40 +12,47 @@
12
12
  :class="{
13
13
  [prefixCls]: true,
14
14
  'BriUpload': true,
15
+ [`BriUpload-${showMode}`]: true,
15
16
  'BriUpload-disabled': canEdit && disabled,
16
17
  'BriUpload-readonly': !canEdit,
17
18
  'BriUpload-unit': !canEdit && isInTable,
18
- [`BriUpload-${showMode}`]: true,
19
+ [`control-show-${showStatusMode}${isTagShow ? '-tag' : ''}`]: isDetailShow
19
20
  }"
20
21
  @click="clickUpload"
21
- @drop.prevent="handleDrop"
22
- @paste="handlePaste"
22
+ @drop.prevent="dropCb"
23
+ @paste="pasteCb"
23
24
  @dragover.prevent="dragOver = true"
24
25
  @dragleave.prevent="dragOver = false"
25
26
  >
26
- <!-- 编辑 -->
27
+ <!-- 上传部分 -->
27
28
  <div
28
- v-if="!disabled"
29
- :class="classes"
29
+ v-if="!disabled && !(maxNum === 1 && curValList.length)"
30
+ :class="{
31
+ [`${prefixCls}`]: true,
32
+ [`${prefixCls}-select`]: useType === 'select',
33
+ [`${prefixCls}-drag`]: useType === 'drag',
34
+ [`${prefixCls}-dragOver`]: useType === 'drag' && dragOver,
35
+ wrapper: true
36
+ }"
30
37
  >
31
38
  <input
32
39
  ref="input"
33
40
  :class="[prefixCls + '-input']"
34
41
  type="file"
35
- :accept="accept"
42
+ :accept="acceptStr"
36
43
  :multiple="multipleMode"
37
- :disabled="disabled || percent > 0"
44
+ :disabled="uploadDisabled"
38
45
  :webkitdirectory="false"
39
- @change="handleChange"
46
+ @change="changeCb"
40
47
  >
41
48
 
42
- <!-- 上传按钮 -->
49
+ <!-- 按钮 -->
43
50
  <slot>
44
- <div :class="`BriUpload-${showMode}-add`">
45
- <!-- 上传 -->
51
+ <div class="add">
52
+ <!-- 上传过程 -->
46
53
  <i-circle
47
54
  v-if="percent"
48
- :class="`BriUpload-${showMode}-circle`"
55
+ class="add-circle"
49
56
  :percent="percent"
50
57
  :stroke-color="percentColor"
51
58
  >
@@ -54,8 +61,12 @@
54
61
  v-if="Number(percent) === 100"
55
62
  type="ios-checkmark"
56
63
  ></Icon>
64
+
57
65
  <!-- 上传中 -->
58
- <span v-else-if="showMode === 'old'">
66
+ <span
67
+ v-else
68
+ class="add-circle-title"
69
+ >
59
70
  {{ percent }}%
60
71
  </span>
61
72
  </i-circle>
@@ -63,11 +74,15 @@
63
74
  <!-- 未上传 -->
64
75
  <template v-else>
65
76
  <dsh-icons
66
- :list="$getOperationList([subType === 'image' ? 'add' : 'upload'])"
77
+ item-class="add-upload-icon"
78
+ :list="$getOperationList(['upload'])"
67
79
  @click="clickUpload"
68
80
  ></dsh-icons>
69
81
 
70
- <span v-if="showMode !== 'inline'">
82
+ <span
83
+ v-if="!showMode.includes('inline')"
84
+ class="add-upload-title"
85
+ >
71
86
  点击上传{{ subTypeName }}
72
87
  </span>
73
88
  </template>
@@ -75,20 +90,20 @@
75
90
  </slot>
76
91
  </div>
77
92
 
78
- <!-- 编辑和查看 列表 -->
79
- <slot name="list">
93
+ <!-- 文件列表 -->
94
+ <slot
95
+ v-if="!(maxNum === 1 && !curValList.length)"
96
+ name="list"
97
+ >
80
98
  <upload-list
81
- :class="{
82
- ...commonClass,
83
- 'bri-control-edit': false
84
- }"
85
- :showMode="showMode"
99
+ class="BriUpload-list"
100
+ :mode="showMode"
86
101
  :canEdit="!disabled"
87
102
  :files="curValList"
88
103
  :propsObj="propsObj"
89
- :emptyShowVal="emptyShowVal"
104
+ :listPadding="!isInTable ? '16px' : undefined"
90
105
  :isShowEditIcon="isShowEditIcon"
91
- @click.native.stop="0"
106
+ :emptyShowVal="emptyShowVal"
92
107
  @deleteItem="clickDeteItem"
93
108
  @editItemName="handleEditName"
94
109
  ></upload-list>
@@ -97,11 +112,11 @@
97
112
  </template>
98
113
 
99
114
  <script>
115
+ import { fileTypes } from "../../../../data/index.js";
100
116
  import controlMixin from "../../mixins/controlMixin.js";
101
117
  import uploadMixin from "./uploadMixin.js";
102
118
  import BriUploadImage from "./BriUploadImage.vue";
103
119
  import uploadList from "./uploadList.vue";
104
- import { fileTypes } from "../../../../data/index.js";
105
120
 
106
121
  export default {
107
122
  name: "BriUpload",
@@ -133,20 +148,47 @@
133
148
  selfPropsObj () {
134
149
  return {
135
150
  _fileType: "file", // "file", "image", "video"
136
- _showMode: this.isHeightAuto ? "old" : "inline", // 宽度为100%、且不在表格字段里的 显示老版
151
+ _accept: [], // 限制只能传那些文件类型,_accept有值的话,还会根据_fileType包含的类型再过滤下
152
+ _maxNum: undefined, // 上传文件的最大数量
137
153
 
138
- _multiple: true, // 默认多选
154
+ _inTableStyle: "fold", // 单元格内的展示方式
139
155
  _useType: "drag", // "drag", "select"
140
156
  _maxSize: 1024 * 1024 * 2, // 根据四局要求,限制文件为2G
141
- _format: [],
142
- _accept: [], // 限制只能传那些文件类型,_accept有值的话,_fileType就没用了
143
157
 
144
158
  ...this.propsObj,
145
- ...this.commonDealPropsObj
159
+ ...this.commonDealPropsObj,
160
+
161
+ // 默认多选
162
+ _multiple: typeof this.propsObj._maxNum === "number"
163
+ ? this.propsObj._maxNum !== 1
164
+ : true
146
165
  };
147
166
  },
167
+ useType () {
168
+ return this.selfPropsObj._useType;
169
+ },
170
+ maxNum () {
171
+ return this.selfPropsObj._maxNum || 0; // 可以为0,为0代表数量随便选
172
+ },
173
+ maxSize () {
174
+ return this.selfPropsObj._maxSize;
175
+ },
176
+ accepts () {
177
+ return this.selfPropsObj._accept;
178
+ },
148
179
  subType () {
149
- return this.selfPropsObj._fileType || "file";
180
+ const imageFormats = this.getTypeFormats("image");
181
+ const videoFormats = this.getTypeFormats("video");
182
+
183
+ return ["file"].includes(this.selfPropsObj._fileType)
184
+ ? this.accepts.length
185
+ ? this.accepts.every(format => imageFormats.includes(format))
186
+ ? "image"
187
+ : this.accepts.every(format => videoFormats.includes(format))
188
+ ? "video"
189
+ : "file"
190
+ : "file"
191
+ : this.selfPropsObj._fileType;
150
192
  },
151
193
  subTypeName () {
152
194
  return this.subType === "image"
@@ -155,47 +197,40 @@
155
197
  ? "视频"
156
198
  : "文件";
157
199
  },
158
- showMode () {
159
- return this.isInTable
160
- ? this.selfPropsObj._inTableStyle === "list" && this.disabled
161
- ? "tableList"
162
- : "inline"
163
- : this.selfPropsObj._showMode;
164
- },
165
- useType () {
166
- return this.selfPropsObj._useType;
200
+ // 限制文件格式
201
+ acceptFormats () {
202
+ const allFormats = this.getTypeFormats("file");
203
+ const subTypeHasFormats = this.getTypeFormats(this.subType);
204
+
205
+ return this.accepts.length
206
+ // _fileTyp为非“file”时处理:如果_accept传了,需要过滤保证严谨,不在fileTypes.json里的类型,直接留下;在json里的,属于subType所包含的文件类型留下,其他的过滤掉(排除误传的影响)
207
+ ? !["file"].includes(this.selfPropsObj._fileType)
208
+ ? this.accepts.filter(format => !allFormats.includes(format) || subTypeHasFormats.includes(format))
209
+ : this.accepts
210
+ : subTypeHasFormats;
167
211
  },
168
- format () {
169
- return this.selfPropsObj._format;
212
+ acceptStr () {
213
+ return this.acceptFormats.map(format => `.${format}`).join();
170
214
  },
171
- maxSize () {
172
- return this.selfPropsObj._maxSize;
215
+ showMode () {
216
+ return this.isHeightAuto && this.maxNum === 1 && !this.isInTable
217
+ ? "single"
218
+ : this.isInTable
219
+ ? this.selfPropsObj._inTableStyle === "list" && this.disabled
220
+ ? this.subType === "image" ? "imageinline" : "file"
221
+ : this.subType === "image" ? "imageinline" : "fileinline"
222
+ : this.isHeightAuto
223
+ ? this.subType === "image" ? "image" : "file"
224
+ : this.subType === "image" ? "imageinline" : "fileinline";
173
225
  },
174
- // 限制文件格式
175
- accept () {
176
- const types = this.selfPropsObj._accept.length
177
- ? this.selfPropsObj._accept
178
- : (
179
- this.subType === "file"
180
- ? fileTypes
181
- : fileTypes.filter(fileTypeItem => fileTypeItem.type === this.subType)
182
- ).map(fileTypeItem => fileTypeItem._key);
183
-
184
- return types.map(type => `.${type}`).join();
226
+
227
+ uploadDisabled () {
228
+ return this.disabled || this.percent > 0;
185
229
  },
186
230
  isShowEditIcon () {
187
231
  // 因为编辑name 需要这三个参数,因此没有这三个参数时不显示此按钮
188
232
  return this.compKey && this.appKey && this.modKey &&
189
233
  !!(this.$getHttpPathMap({}).file && this.$getHttpPathMap({}).file.updateFileName);
190
- },
191
- classes () {
192
- return {
193
- [`${this.prefixCls}`]: true,
194
- [`${this.prefixCls}-select`]: this.useType === "select",
195
- [`${this.prefixCls}-drag`]: this.useType === "drag",
196
- [`${this.prefixCls}-dragOver`]: this.useType === "drag" && this.dragOver,
197
- [`BriUpload-${this.showMode}-wrapper`]: true
198
- };
199
234
  }
200
235
  },
201
236
  created () {},
@@ -210,65 +245,75 @@
210
245
  }
211
246
  });
212
247
  },
213
- handleEditName (fileItem) {
214
- this.$https({
215
- url: {
216
- ...this.finalUrlModule,
217
- name: "updateFileName"
218
- },
219
- params: fileItem
220
- });
221
- },
222
- successCb (res, data) {
223
- if (data.res === 0) {
224
- if (this.multipleMode) {
225
- this.curValList = [
226
- ...this.curValList,
227
- data.data
228
- ];
229
- } else {
230
- this.curValList = [
231
- data.data
232
- ];
233
- }
234
- } else {
235
- this.$Message.error({
236
- content: `操作失败!${this.$getMsgText(data.msg)}`,
237
- duration: 4
238
- });
239
- }
240
- },
241
-
242
248
  clickUpload () {
243
- if (!this.disabled) {
249
+ if (!this.uploadDisabled) {
244
250
  this.$refs.input.click();
245
251
  }
246
252
  },
247
- handleChange (event) {
253
+
254
+ changeCb (event) {
248
255
  if (event.target.files) {
249
256
  this.dealUpload(event.target.files);
250
257
  this.$refs.input.value = null;
251
258
  }
252
259
  },
253
- handleDrop (event) {
260
+ dropCb (event) {
254
261
  this.dragOver = false;
255
262
  this.dealUpload(event.dataTransfer.files);
256
263
  },
257
- handlePaste (event) {
264
+ pasteCb (event) {
258
265
  this.dealUpload(event.clipboardData.files);
259
266
  },
260
267
  dealUpload (files) {
261
- if (!this.disabled) {
262
- let postFiles = this.multipleMode ? [...files] : [...files].slice(0, 1);
263
- postFiles.forEach(fileItem => {
264
- if (
265
- (!this.format.length || this.format.some(item => item.toLocaleLowerCase() === fileItem.name.split(".").pop().toLocaleLowerCase())) &&
266
- (fileItem.size <= this.maxSize * 1024)
267
- ) {
268
+ if (!this.uploadDisabled) {
269
+ [...files].slice(-this.maxNum).forEach(fileItem => {
270
+ if (!this.acceptFormats.some(fileFormat => fileFormat.toLocaleLowerCase() === fileItem.name.split(".").pop().toLocaleLowerCase())) {
271
+ this.$Message.error({
272
+ content: `“${fileItem.name}”文件格式不符合要求!`,
273
+ duration: 3
274
+ });
275
+ }
276
+ else if (fileItem.size > this.maxSize * 1024) {
277
+ this.$Message.error({
278
+ content: `“${fileItem.name}”文件大小不符合要求!`,
279
+ duration: 3
280
+ });
281
+ }
282
+ else {
268
283
  this.handlePost(fileItem);
269
284
  }
270
285
  });
271
286
  }
287
+ },
288
+ successCb (res, data) {
289
+ if (data.res === 0) {
290
+ this.curValList = [
291
+ ...this.curValList,
292
+ data.data
293
+ ].slice(-this.maxNum);
294
+ } else {
295
+ this.$Message.error({
296
+ content: `操作失败!${this.$getMsgText(data.msg)}`,
297
+ duration: 3
298
+ });
299
+ }
300
+ },
301
+
302
+ handleEditName (fileItem) {
303
+ this.$https({
304
+ url: {
305
+ ...this.finalUrlModule,
306
+ name: "updateFileName"
307
+ },
308
+ params: fileItem
309
+ });
310
+ },
311
+ getTypeFormats (subType = "file") {
312
+ return subType === "file"
313
+ ? fileTypes.map(fileTypeItem => fileTypeItem._key)
314
+ : fileTypes
315
+ .filter(fileTypeItem => fileTypeItem.type === subType)
316
+ .map(fileTypeItem => fileTypeItem._key);
272
317
  }
273
318
  }
274
319
  };
@@ -283,103 +328,146 @@
283
328
  background-color: @white;
284
329
  overflow: hidden;
285
330
  position: relative;
331
+ display: flex;
332
+ flex-direction: row;
286
333
 
287
- &-old,
288
- &-new,
289
- &-inline {
290
- display: flex;
334
+ .wrapper {
335
+ border: none!important;
336
+ border-radius: 0px !important;
291
337
 
292
- &-wrapper {
293
- border: none!important;
294
- border-radius: 0px !important;
338
+ .add {
339
+ .dsh-flex-col-center-center();
340
+ cursor: pointer;
341
+ position: relative;
342
+
343
+ &-circle {
344
+ position: absolute;
345
+ top: 0;
346
+ left: 0;
347
+ bottom: 0;
348
+ right: 0;
349
+ margin: auto;
350
+ border-radius: 50%;
351
+ }
295
352
 
296
353
  &:hover {
297
- border: none;
354
+ color: @themeColor;
355
+ background-color: @theme-focus;
298
356
  }
299
357
  }
300
358
 
301
- &-add {
302
- .dsh-flex-col-center-center();
303
- cursor: pointer;
304
- position: relative;
359
+ &:hover {
360
+ border: none;
305
361
  }
362
+ }
306
363
 
307
- &-circle {
308
- position: absolute;
309
- top: 0;
310
- left: 0;
311
- bottom: 0;
312
- right: 0;
313
- margin: auto;
314
- border-radius: 50%;
315
- }
364
+ &-list {
365
+ flex: 1;
366
+ min-width: 0px;
316
367
  }
317
368
 
318
- &-old {
319
- overflow: hidden;
369
+ &-single {
370
+ .wrapper {
371
+ width: 100%;
320
372
 
321
- &-wrapper {
322
- min-width: 120px;
323
- height: 100%;
324
- margin: 16px 0px 16px 16px;
325
- }
373
+ .add {
374
+ width: 100%;
375
+ height: 100%;
376
+ color: @themeColor;
326
377
 
327
- &-add {
328
- width: 120px;
329
- height: 120px;
330
- border: 1px @borderColor dashed;
331
- border-radius: @borderRadius;
332
- color: @themeColor;
378
+ &-circle {
379
+ width: 60px!important;
380
+ height: 60px!important;
381
+ background-color: @inputBg-readonly;
382
+ color: @themeColor;
333
383
 
334
- &:hover {
335
- border-color: @themeColor;
336
- background-color: @theme-focus;
384
+ &-title {
385
+ font-size: 18px;
386
+ }
387
+
388
+ i {
389
+ color: @scuess-color;
390
+ font-size: 50px;
391
+ }
392
+ }
393
+
394
+ &-upload {
395
+ &-title {
396
+ margin-top: 5px;
397
+ font-size: 16px;
398
+ }
399
+ }
337
400
  }
338
401
  }
402
+ }
339
403
 
340
- &-circle {
341
- width: 50px!important;
342
- height: 50px!important;
343
- background-color: @inputBg-readonly;
344
- color: @themeColor;
404
+ &-image,
405
+ &-file {
406
+ .wrapper {
407
+ width: 136px;
408
+ padding: 16px 0px 16px 16px;
409
+
410
+ .add {
411
+ width: 100%;
412
+ height: 100%;
413
+ border: 1px @borderColor dashed;
414
+ border-radius: @borderRadius;
415
+ color: @themeColor;
345
416
 
346
- i {
347
- color: @scuess-color;
348
- font-size: 40px;
417
+ &-circle {
418
+ width: 50px!important;
419
+ height: 50px!important;
420
+ background-color: @inputBg-readonly;
421
+ color: @themeColor;
422
+
423
+ &-title {
424
+ font-size: 16px;
425
+ }
426
+
427
+ i {
428
+ color: @scuess-color;
429
+ font-size: 40px;
430
+ }
431
+ }
432
+
433
+ &:hover {
434
+ border: 1px @themeColor dashed;
435
+ }
349
436
  }
350
437
  }
351
438
  }
352
439
 
353
- &-new,
354
- &-inline {
355
- &-wrapper {
356
- min-width: 32px;
440
+ &-imageinline,
441
+ &-fileinline {
442
+ .wrapper {
443
+ width: 32px;
357
444
  height: 32px;
358
445
  line-height: 32px;
359
446
  background-color: @border-readonly;
360
- }
361
447
 
362
- &-add {
363
- height: 32px;
364
- border: none;
365
- border-radius: 0px;
366
- background-color: @btn-hover;
367
- color: @textColor;
368
-
369
- &:hover {
370
- color: @themeColor;
371
- background-color: @theme-focus;
372
- }
373
- }
374
-
375
- &-circle {
376
- width: 24px!important;
377
- height: 24px!important;
378
- background-color: #f4f5fa;
448
+ .add {
449
+ width: 100%;
450
+ height: 100%;
451
+ border: none;
452
+ border-radius: 0px;
453
+ background-color: @btn-hover;
454
+ color: @textColor;
455
+
456
+ &-circle {
457
+ width: 24px!important;
458
+ height: 24px!important;
459
+ background-color: #f4f5fa;
460
+
461
+ &-title {
462
+ display: none; // 圈太小,字超出了,先不显示
463
+ font-size: 12px;
464
+ }
379
465
 
380
- i {
381
- color: @scuess-color;
382
- font-size: 24px;
466
+ i {
467
+ color: @scuess-color;
468
+ font-size: 24px;
469
+ }
470
+ }
383
471
  }
384
472
  }
385
473
  }
@@ -388,42 +476,14 @@
388
476
  border: none;
389
477
  border-radius: 0px;
390
478
  background-color: transparent;
391
-
392
- .uploadList {
393
- &-old {
394
- margin: 0px;
395
- }
396
-
397
- &-list {
398
- .item {
399
- flex: 0 0 80px;
400
- height: 80px;
401
- }
402
- }
403
- }
404
479
  }
405
480
 
406
481
  &-disabled {
407
482
  .bri-control-disabled();
408
483
 
409
484
  .uploadList {
410
- &-old {
411
- margin: 0px;
412
- }
413
-
414
- &-list {
415
- .item {
416
- flex: 0 0 80px;
417
- height: 80px;
418
- }
419
- }
420
-
421
- &-nodata {
422
- color: @placeholder-disabled-color;
423
- text-indent: 7px;
424
- text-align: left;
425
- }
426
- &-inline-nodata {
485
+ &-nodata,
486
+ &-nodata-inline {
427
487
  color: @placeholder-disabled-color;
428
488
  }
429
489
  }
@@ -431,10 +491,24 @@
431
491
 
432
492
  &-unit {
433
493
  .uploadList {
434
- &-inline-nodata {
494
+ &-nodata,
495
+ &-nodata-inline {
435
496
  .bri-control-nodata();
436
497
  }
437
498
  }
438
499
  }
439
500
  }
440
501
  </style>
502
+ <style lang="less">
503
+ .BriUpload {
504
+ &-single {
505
+ .add {
506
+ &-upload {
507
+ &-icon {
508
+ font-size: 32px!important;
509
+ }
510
+ }
511
+ }
512
+ }
513
+ }
514
+ </style>