bri-components 1.6.6 → 1.6.8

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.6",
3
+ "version": "1.6.8",
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,32 +74,36 @@
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'">
71
- 点击上传{{ subType === 'image' ? "图片" : "文件" }}
82
+ <span
83
+ v-if="!showMode.includes('inline')"
84
+ class="add-upload-title"
85
+ >
86
+ 点击上传{{ subTypeName }}
72
87
  </span>
73
88
  </template>
74
89
  </div>
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,129 +148,172 @@
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
  },
148
- subType () {
149
- return this.selfPropsObj._fileType || "file";
150
- },
151
- showMode () {
152
- return this.isInTable
153
- ? this.selfPropsObj._inTableStyle === "list" && this.disabled
154
- ? "tableList"
155
- : "inline"
156
- : this.selfPropsObj._showMode;
157
- },
158
167
  useType () {
159
168
  return this.selfPropsObj._useType;
160
169
  },
161
- format () {
162
- return this.selfPropsObj._format;
170
+ maxNum () {
171
+ return this.selfPropsObj._maxNum || 0; // 可以为0,为0代表数量随便选
163
172
  },
164
173
  maxSize () {
165
174
  return this.selfPropsObj._maxSize;
166
175
  },
176
+ accepts () {
177
+ return this.selfPropsObj._accept;
178
+ },
179
+ subType () {
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;
192
+ },
193
+ subTypeName () {
194
+ return this.subType === "image"
195
+ ? "图片"
196
+ : this.subType === "video"
197
+ ? "视频"
198
+ : "文件";
199
+ },
167
200
  // 限制文件格式
168
- accept () {
169
- const types = this.selfPropsObj._accept.length
170
- ? this.selfPropsObj._accept
171
- : (
172
- this.subType === "file"
173
- ? fileTypes
174
- : fileTypes.filter(fileTypeItem => fileTypeItem.type === this.subType)
175
- ).map(fileTypeItem => fileTypeItem._key);
176
-
177
- return types.map(type => `.${type}`).join();
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;
211
+ },
212
+ acceptStr () {
213
+ return this.acceptFormats.map(format => `.${format}`).join();
214
+ },
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";
225
+ },
226
+
227
+ uploadDisabled () {
228
+ return this.disabled || this.percent > 0;
178
229
  },
179
230
  isShowEditIcon () {
180
231
  // 因为编辑name 需要这三个参数,因此没有这三个参数时不显示此按钮
181
232
  return this.compKey && this.appKey && this.modKey &&
182
233
  !!(this.$getHttpPathMap({}).file && this.$getHttpPathMap({}).file.updateFileName);
183
- },
184
- classes () {
185
- return {
186
- [`${this.prefixCls}`]: true,
187
- [`${this.prefixCls}-select`]: this.useType === "select",
188
- [`${this.prefixCls}-drag`]: this.useType === "drag",
189
- [`${this.prefixCls}-dragOver`]: this.useType === "drag" && this.dragOver,
190
- [`BriUpload-${this.showMode}-wrapper`]: true
191
- };
192
234
  }
193
235
  },
194
236
  created () {},
195
237
  methods: {
196
- clickUpload () {
197
- if (!this.disabled) {
198
- this.$refs.input.click();
199
- }
200
- },
201
238
  clickDeteItem (fileItem, fileIndex) {
202
- this.curValList.splice(fileIndex, 1);
203
- this.curValList = [...this.curValList];
204
- },
205
- handleEditName (fileItem) {
206
- this.$https({
207
- url: {
208
- ...this.finalUrlModule,
209
- name: "updateFileName"
210
- },
211
- params: fileItem
239
+ this.$Modal.confirm({
240
+ title: "提示",
241
+ content: `确定删除${fileItem.name || "此文件"}吗?`,
242
+ onOk: () => {
243
+ this.curValList.splice(fileIndex, 1);
244
+ this.curValList = [...this.curValList];
245
+ }
212
246
  });
213
247
  },
214
- successCb (res, data) {
215
- if (data.res === 0) {
216
- if (this.multipleMode) {
217
- this.curValList = [
218
- ...this.curValList,
219
- data.data
220
- ];
221
- } else {
222
- this.curValList = [
223
- data.data
224
- ];
225
- }
226
- } else {
227
- this.$Message.error({
228
- content: `操作失败!${this.$getMsgText(data.msg)}`,
229
- duration: 4
230
- });
248
+ clickUpload () {
249
+ if (!this.uploadDisabled) {
250
+ this.$refs.input.click();
231
251
  }
232
252
  },
233
253
 
234
- handleChange (event) {
254
+ changeCb (event) {
235
255
  if (event.target.files) {
236
256
  this.dealUpload(event.target.files);
237
257
  this.$refs.input.value = null;
238
258
  }
239
259
  },
240
- handleDrop (event) {
260
+ dropCb (event) {
241
261
  this.dragOver = false;
242
262
  this.dealUpload(event.dataTransfer.files);
243
263
  },
244
- handlePaste (event) {
264
+ pasteCb (event) {
245
265
  this.dealUpload(event.clipboardData.files);
246
266
  },
247
267
  dealUpload (files) {
248
- if (!this.disabled) {
249
- let postFiles = this.multipleMode ? [...files] : [...files].slice(0, 1);
250
- postFiles.forEach(fileItem => {
251
- if (
252
- (!this.format.length || this.format.some(item => item.toLocaleLowerCase() === fileItem.name.split(".").pop().toLocaleLowerCase())) &&
253
- (fileItem.size <= this.maxSize * 1024)
254
- ) {
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 {
255
283
  this.handlePost(fileItem);
256
284
  }
257
285
  });
258
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);
259
317
  }
260
318
  }
261
319
  };
@@ -270,103 +328,146 @@
270
328
  background-color: @white;
271
329
  overflow: hidden;
272
330
  position: relative;
331
+ display: flex;
332
+ flex-direction: row;
333
+
334
+ .wrapper {
335
+ border: none!important;
336
+ border-radius: 0px !important;
273
337
 
274
- &-old,
275
- &-new,
276
- &-inline {
277
- display: flex;
338
+ .add {
339
+ .dsh-flex-col-center-center();
340
+ cursor: pointer;
341
+ position: relative;
278
342
 
279
- &-wrapper {
280
- border: none!important;
281
- border-radius: 0px !important;
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
+ }
282
352
 
283
353
  &:hover {
284
- border: none;
354
+ color: @themeColor;
355
+ background-color: @theme-focus;
285
356
  }
286
357
  }
287
358
 
288
- &-add {
289
- .dsh-flex-col-center-center();
290
- cursor: pointer;
291
- position: relative;
359
+ &:hover {
360
+ border: none;
292
361
  }
362
+ }
293
363
 
294
- &-circle {
295
- position: absolute;
296
- top: 0;
297
- left: 0;
298
- bottom: 0;
299
- right: 0;
300
- margin: auto;
301
- border-radius: 50%;
302
- }
364
+ &-list {
365
+ flex: 1;
366
+ min-width: 0px;
303
367
  }
304
368
 
305
- &-old {
306
- overflow: hidden;
369
+ &-single {
370
+ .wrapper {
371
+ width: 100%;
307
372
 
308
- &-wrapper {
309
- min-width: 120px;
310
- height: 100%;
311
- margin: 16px 0px 16px 16px;
312
- }
373
+ .add {
374
+ width: 100%;
375
+ height: 100%;
376
+ color: @themeColor;
313
377
 
314
- &-add {
315
- width: 120px;
316
- height: 120px;
317
- border: 1px @borderColor dashed;
318
- border-radius: @borderRadius;
319
- color: @themeColor;
378
+ &-circle {
379
+ width: 60px!important;
380
+ height: 60px!important;
381
+ background-color: @inputBg-readonly;
382
+ color: @themeColor;
320
383
 
321
- &:hover {
322
- border-color: @themeColor;
323
- 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
+ }
324
400
  }
325
401
  }
402
+ }
403
+
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;
326
416
 
327
- &-circle {
328
- width: 50px!important;
329
- height: 50px!important;
330
- background-color: @inputBg-readonly;
331
- color: @themeColor;
417
+ &-circle {
418
+ width: 50px!important;
419
+ height: 50px!important;
420
+ background-color: @inputBg-readonly;
421
+ color: @themeColor;
332
422
 
333
- i {
334
- color: @scuess-color;
335
- font-size: 40px;
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
+ }
336
436
  }
337
437
  }
338
438
  }
339
439
 
340
- &-new,
341
- &-inline {
342
- &-wrapper {
343
- min-width: 32px;
440
+ &-imageinline,
441
+ &-fileinline {
442
+ .wrapper {
443
+ width: 32px;
344
444
  height: 32px;
345
445
  line-height: 32px;
346
446
  background-color: @border-readonly;
347
- }
348
447
 
349
- &-add {
350
- height: 32px;
351
- border: none;
352
- border-radius: 0px;
353
- background-color: @btn-hover;
354
- color: @textColor;
355
-
356
- &:hover {
357
- color: @themeColor;
358
- background-color: @theme-focus;
359
- }
360
- }
361
-
362
- &-circle {
363
- width: 24px!important;
364
- height: 24px!important;
365
- 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
+ }
366
465
 
367
- i {
368
- color: @scuess-color;
369
- font-size: 24px;
466
+ i {
467
+ color: @scuess-color;
468
+ font-size: 24px;
469
+ }
470
+ }
370
471
  }
371
472
  }
372
473
  }
@@ -375,42 +476,14 @@
375
476
  border: none;
376
477
  border-radius: 0px;
377
478
  background-color: transparent;
378
-
379
- .uploadList {
380
- &-old {
381
- margin: 0px;
382
- }
383
-
384
- &-list {
385
- .item {
386
- flex: 0 0 80px;
387
- height: 80px;
388
- }
389
- }
390
- }
391
479
  }
392
480
 
393
481
  &-disabled {
394
482
  .bri-control-disabled();
395
483
 
396
484
  .uploadList {
397
- &-old {
398
- margin: 0px;
399
- }
400
-
401
- &-list {
402
- .item {
403
- flex: 0 0 80px;
404
- height: 80px;
405
- }
406
- }
407
-
408
- &-nodata {
409
- color: @placeholder-disabled-color;
410
- text-indent: 7px;
411
- text-align: left;
412
- }
413
- &-inline-nodata {
485
+ &-nodata,
486
+ &-nodata-inline {
414
487
  color: @placeholder-disabled-color;
415
488
  }
416
489
  }
@@ -418,10 +491,24 @@
418
491
 
419
492
  &-unit {
420
493
  .uploadList {
421
- &-inline-nodata {
494
+ &-nodata,
495
+ &-nodata-inline {
422
496
  .bri-control-nodata();
423
497
  }
424
498
  }
425
499
  }
426
500
  }
427
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>