bri-components 1.6.4 → 1.6.5

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.4",
3
+ "version": "1.6.5",
4
4
  "author": "dengshanghui",
5
5
  "description": "a component lib for vue project",
6
6
  "main": "src/index.js",
@@ -205,7 +205,7 @@
205
205
  handleEditName (fileItem) {
206
206
  this.$https({
207
207
  url: {
208
- ...this.computedUrlModule,
208
+ ...this.finalUrlModule,
209
209
  name: "updateFileName"
210
210
  },
211
211
  params: fileItem
@@ -231,18 +231,18 @@
231
231
  }
232
232
  },
233
233
 
234
- handleChange (e) {
235
- if (e.target.files) {
236
- this.dealUpload(e.target.files);
234
+ handleChange (event) {
235
+ if (event.target.files) {
236
+ this.dealUpload(event.target.files);
237
237
  this.$refs.input.value = null;
238
238
  }
239
239
  },
240
- handleDrop (e) {
240
+ handleDrop (event) {
241
241
  this.dragOver = false;
242
- this.dealUpload(e.dataTransfer.files);
242
+ this.dealUpload(event.dataTransfer.files);
243
243
  },
244
- handlePaste (e) {
245
- this.dealUpload(e.clipboardData.files);
244
+ handlePaste (event) {
245
+ this.dealUpload(event.clipboardData.files);
246
246
  },
247
247
  dealUpload (files) {
248
248
  if (!this.disabled) {
@@ -5,14 +5,14 @@
5
5
  class="BriUploadImage-set"
6
6
  >
7
7
  <div
8
- v-if="curVal || propsObj._default || percent"
8
+ v-if="curVal || selfPropsObj._default || percent"
9
9
  :class="{
10
10
  'BriUploadImage-set-img': true,
11
11
  'BriUploadImage-set-avatar': isAvatar
12
12
  }"
13
13
  :style="{
14
- backgroundImage: `url(${$imageResize(curVal || propsObj._default, imageResizeConfig)})`,
15
- borderRadius: propsObj.radius ? '50%' : ''
14
+ backgroundImage: `url(${$imageResize(curVal || selfPropsObj._default, imageResizeConfig)})`,
15
+ borderRadius: useBorderRadius ? '50%' : ''
16
16
  }"
17
17
  >
18
18
  <img
@@ -60,10 +60,10 @@
60
60
  <Button type="default">点击上传</Button>
61
61
  <input
62
62
  id="fileupload"
63
- class="file"
64
- :accept="acceptType"
65
- :type="inputType"
66
- @change="setImage"
63
+ class="wrap-input"
64
+ :accept="accept"
65
+ :type="uploadType"
66
+ @change="handleChange"
67
67
  />
68
68
  </div>
69
69
  </div>
@@ -76,7 +76,7 @@
76
76
  @on-visible-change="visibleChange"
77
77
  >
78
78
  <dsh-cropper
79
- ref="cropper"
79
+ ref="cropperDom"
80
80
  class="BriUploadImage-cropper"
81
81
  :src="imgSrc"
82
82
  alt="Source Image"
@@ -114,30 +114,11 @@
114
114
  default () {
115
115
  return {};
116
116
  }
117
- },
118
-
119
- isAvatar: {
120
- type: Boolean,
121
- default: false
122
- },
123
- // 上传的是阿里云还是本地
124
- requestOssType: {
125
- type: String,
126
- default: "default",
127
- validator (val) {
128
- // "default"代表阿里云
129
- return ["default", "local"].includes(val);
130
- }
131
- },
132
- // 阿里云上传方式
133
- ossType: {
134
- type: String,
135
- default: "binaryMultipartUpload"
136
117
  }
137
118
  },
138
119
  data () {
139
120
  return {
140
- inputType: "file",
121
+ uploadType: "file",
141
122
 
142
123
  // 头像
143
124
  avatarModal: false,
@@ -163,6 +144,15 @@
163
144
  computed: {
164
145
  selfPropsObj () {
165
146
  return {
147
+ _accept: [],
148
+ _isAvatar: false, // 是否是头像
149
+ _canAction: false, // 是否使用操作图标
150
+ _cropper: false, // 使用裁剪
151
+ _useBorderRadius: false, // 用圆角
152
+
153
+ _requestOssType: "", //
154
+ _aliOssType: "binaryMultipartUpload", // 阿里云上传方式
155
+
166
156
  ...this.propsObj
167
157
  };
168
158
  },
@@ -172,10 +162,21 @@
172
162
  controlName () {
173
163
  return this.selfPropsObj._name;
174
164
  },
175
- // 使用操作图标
165
+ accept () {
166
+ return this.selfPropsObj._accept.map(type => `.${type}`).join() || "*";
167
+ },
168
+ isAvatar () {
169
+ return this.selfPropsObj._isAvatar;
170
+ },
176
171
  canAction () {
177
172
  return this.selfPropsObj._canAction;
178
173
  },
174
+ isCropper () {
175
+ return this.selfPropsObj._cropper;
176
+ },
177
+ useBorderRadius () {
178
+ return this.selfPropsObj._useBorderRadius;
179
+ },
179
180
  imageResizeConfig () {
180
181
  return this.selfPropsObj._imageResizeConfig || {
181
182
  m: "fixed",
@@ -183,11 +184,8 @@
183
184
  h: 100
184
185
  };
185
186
  },
186
- finalRequestOssType () {
187
- return this.selfPropsObj._requestOssType || this.requestOssType;
188
- },
189
- acceptType () {
190
- return this.selfPropsObj._acceptType || "*";
187
+ requestOssType () {
188
+ return this.selfPropsObj._requestOssType;
191
189
  },
192
190
 
193
191
  modalPropsObj () {
@@ -209,56 +207,65 @@
209
207
  },
210
208
  created () {},
211
209
  methods: {
212
- setImage (e) {
213
- if (e.target.files.length) {
214
- const file = e.target.files[0];
210
+ handleChange (event) {
211
+ if (event.target.files.length) {
212
+ const file = event.target.files[0];
213
+
215
214
  if (!file.type.includes("image/")) {
216
215
  this.$Message.error("请选择一张图片");
217
216
  }
218
217
  else if (typeof FileReader !== "function") {
219
- this.$Message.error("Sorry, FileReader API not supported");
218
+ this.$Message.error("Sorry, FileReader API not supported!");
220
219
  }
221
220
  else {
222
221
  const reader = new FileReader();
223
- if (this.propsObj._kind === "uploadImage" && !this.propsObj.cropper) {
222
+ // 使用裁剪
223
+ if (this.isCropper) {
224
224
  reader.onload = (event) => {
225
- this.inputType = "text";
226
- this.dealPostImage(event.target.result); // event.target.result是base64格式
225
+ this.uploadType = "text";
226
+ this.imgSrc = event.target.result;
227
+ this.$refs.cropperDom.replace(event.target.result); // event.target.result是base64格式
227
228
  };
228
229
  reader.readAsDataURL(file);
230
+
231
+ this.openAvatarModal();
229
232
  }
230
- // 使用裁剪
231
233
  else {
232
234
  reader.onload = (event) => {
233
- this.inputType = "text";
234
- this.imgSrc = event.target.result;
235
- this.$refs.cropper.replace(event.target.result); // event.target.result是base64格式
235
+ this.uploadType = "text";
236
+ this.dealPostImage(event.target.result); // event.target.result是base64格式
236
237
  };
237
238
  reader.readAsDataURL(file);
238
-
239
- this.openAvatarModal();
240
239
  }
241
240
  }
242
241
  }
243
242
  },
244
243
  // 提交裁剪后的图片
245
244
  submitCropImage () {
246
- this.cropImage();
247
- this.dealPostImage(this.cropImg);
245
+ const cropImg = this.$refs.cropperDom.getCroppedCanvas().toDataURL(); // base64格式
246
+ this.dealPostImage(cropImg);
248
247
 
249
248
  this.closeAvatarModal();
250
249
  },
250
+ successCb (response, res) {
251
+ this.curVal = res.data.downloadUrl;
252
+ this.$emit("change", res);
253
+ },
254
+ handleError (err) {
255
+ alert(err);
256
+ },
251
257
 
252
258
  // 获取裁剪的图片
253
259
  cropImage () {
254
260
  // get image data for post processing, e.g. upload or setting image src
255
- this.cropImg = this.$refs.cropper.getCroppedCanvas().toDataURL(); // base64格式
261
+ this.cropImg = this.$refs.cropperDom.getCroppedCanvas().toDataURL(); // base64格式
256
262
  },
257
263
  // 处理图片的提交
258
264
  dealPostImage (data) {
259
- // local好像是minio在用
260
- if (this.finalRequestOssType === "local") {
261
- // base64转文件
265
+ // 本地上传
266
+ if (this.requestOssType === "local") {
267
+ const imgFile = this.dataURLtoFile(data, ""); // 将图片Base64转成文件
268
+ this.handlePost(imgFile); // object类型
262
269
  // {
263
270
  // lastModified: 1752065308269
264
271
  // name: ".png"
@@ -266,16 +273,14 @@
266
273
  // type: "image/png"
267
274
  // webkitRelativePath: ""
268
275
  // }
269
- const imgFile = this.dataURLtoFile(data, "");
270
- this.handlePost(imgFile);
271
- // console.dir(imgFile); // object类型
272
- } else {
276
+ }
277
+ // 阿里上传用
278
+ else {
273
279
  const dataBuffer = Buffer.from(data.split(",")[1], "base64");
274
- this.handlePost(dataBuffer);
275
- // console.dir(dataBuffer); // object类型
280
+ this.handlePost(dataBuffer); // object类型
276
281
  }
277
282
  },
278
- // 将图片Base64 转成文件
283
+ // 将图片Base64转成文件
279
284
  dataURLtoFile (dataurl, filename) {
280
285
  // 获取文件扩展名称
281
286
  let arr = dataurl.split(",");
@@ -290,14 +295,6 @@
290
295
  return new File([u8arr], `${filename}.${extension}`, { type: mime });
291
296
  },
292
297
 
293
- successCb (response, res) {
294
- this.curVal = res.data.downloadUrl;
295
- this.$emit("change", res);
296
- },
297
- handleError (err) {
298
- alert(err);
299
- },
300
-
301
298
  // 点击文件预览
302
299
  handlePreview (file) {
303
300
  let viewerImage = this.$refs.viewerImage;
@@ -313,7 +310,7 @@
313
310
  },
314
311
  // 点击文件删除 - fileList服务器的数据列表
315
312
  handleRemove (file) {
316
- this.inputType = "file"; // 删除后可以重新上传
313
+ this.uploadType = "file"; // 删除后可以重新上传
317
314
  this.curVal = "";
318
315
  this.change(this.value);
319
316
  },
@@ -332,7 +329,7 @@
332
329
  // 头像模态框状态变化,关闭后改变input框类型,保证上传能够连续上传同一张图片
333
330
  visibleChange (bool) {
334
331
  if (!bool) {
335
- this.inputType = "file";
332
+ this.uploadType = "file";
336
333
  }
337
334
  }
338
335
  }
@@ -408,7 +405,7 @@
408
405
  left: 0;
409
406
  }
410
407
 
411
- .file {
408
+ &-input {
412
409
  position: absolute;
413
410
  bottom: 0;
414
411
  left: 0;
@@ -4,24 +4,7 @@ const minio = require("minio");
4
4
  const stream = require("stream");
5
5
 
6
6
  export default {
7
- props: {
8
- groupKey: {
9
- type: String
10
- },
11
- urlModule: {
12
- type: Object,
13
- default: function () {
14
- return {
15
- module: "file",
16
- name: "ossToken"
17
- };
18
- }
19
- },
20
- ossType: {
21
- type: String,
22
- default: "multipartUpload"
23
- }
24
- },
7
+ props: {},
25
8
  data () {
26
9
  return {
27
10
  percent: 0,
@@ -30,18 +13,22 @@ export default {
30
13
  },
31
14
  created () { },
32
15
  computed: {
33
- computedGroupKey () {
34
- return this.propsObj.groupKey || this.groupKey;
16
+ finalUrlModule () {
17
+ return this.selfPropsObj.urlModule || {
18
+ module: "file",
19
+ name: "ossToken"
20
+ };
35
21
  },
36
- computedUrlModule () {
37
- return this.propsObj.urlModule || this.urlModule;
22
+ uploadGroupKey () {
23
+ return this.selfPropsObj.groupKey;
38
24
  },
39
- computedOssType () {
40
- return this.propsObj.ossType || this.ossType;
25
+ aliOssType () {
26
+ return this.selfPropsObj._aliOssType || "multipartUpload";
41
27
  },
42
28
  archiveKey () {
43
- return this.propsObj._archiveKey || [];
29
+ return this.selfPropsObj._archiveKey || [];
44
30
  },
31
+
45
32
  percentColor () {
46
33
  return Number(this.percent) === 100 ? "#5cb85c" : "#6090ed";
47
34
  }
@@ -49,16 +36,17 @@ export default {
49
36
  methods: {
50
37
  handlePost (file, callback) {
51
38
  this.$https({
52
- url: this.computedUrlModule,
39
+ url: this.finalUrlModule,
53
40
  params: {},
54
41
  callback: res => {
55
- this.inputType = "file";
42
+ this.uploadType = "file";
43
+
56
44
  if (res.ossType === "ali-oss") {
57
45
  // 上传到阿里云res
58
- if (this.computedOssType === "binaryMultipartUpload") {
46
+ if (this.aliOssType === "binaryMultipartUpload") {
59
47
  this.binaryMultipartUpload(file, res, callback);
60
48
  }
61
- else if (this.computedOssType === "multipartUpload") {
49
+ else if (this.aliOssType === "multipartUpload") {
62
50
  this.multipartUpload(file, res, callback);
63
51
  }
64
52
  }
@@ -71,7 +59,6 @@ export default {
71
59
  else {
72
60
  console.log(`请开发这种类型‘${res.ossType}’的上传模式`);
73
61
  }
74
-
75
62
  }
76
63
  });
77
64
  },
@@ -84,7 +71,7 @@ export default {
84
71
  headers: {
85
72
  filetoken: res.filetoken,
86
73
  filebody: JSON.stringify({
87
- groupKey: this.computedGroupKey,
74
+ groupKey: this.uploadGroupKey,
88
75
  archiveKey: this.archiveKey[this.archiveKey.length - 1]
89
76
  })
90
77
  },
@@ -186,7 +173,7 @@ export default {
186
173
  path: remoteName,
187
174
  bucket: res.ossConfig.bucket,
188
175
  filetoken: res.filetoken,
189
- groupKey: this.computedGroupKey,
176
+ groupKey: this.uploadGroupKey,
190
177
  archiveKey: this.archiveKey[this.archiveKey.length - 1]
191
178
  };
192
179
  axios.post(res.ossHost + res.confirmPath, { ...callbackBody })
@@ -235,10 +222,9 @@ export default {
235
222
  path: remoteName,
236
223
  bucket: res.ossConfig.bucket,
237
224
  filetoken: res.filetoken,
238
- groupKey: this.computedGroupKey,
225
+ groupKey: this.uploadGroupKey,
239
226
  archiveKey: this.archiveKey[this.archiveKey.length - 1]
240
227
  };
241
-
242
228
  let ossCallback = {
243
229
  callbackUrl: res.ossHost + res.confirmPath,
244
230
  callbackBodyType: "application/json",
@@ -258,31 +244,34 @@ export default {
258
244
  refreshSTSTokenInterval: 3600 * 1000
259
245
  };
260
246
 
261
- new Oss(newOss).multipartUpload(remoteName, file, {
262
- progress: (percentage) => {
263
- this.inProgress(Number((percentage * 100).toFixed(1)));
264
- this.handleProgress && this.handleProgress(percentage, file);
265
- },
266
- headers: {
267
- "x-oss-callback": this.base64Encode(JSON.stringify(ossCallback)),
268
- "Content-Disposition": type === "pdf" ? `inline;filename=${encodeURI(file.name)}` : `attachment;filename=${encodeURI(file.name)}`
269
- }
270
- }).then(response => {
271
- this.uploadSuccess = true;
272
- this.percent = 100;
273
- setTimeout(() => {
247
+ new Oss(newOss)
248
+ .multipartUpload(remoteName, file, {
249
+ progress: (percentage) => {
250
+ this.inProgress(Number((percentage * 100).toFixed(1)));
251
+ this.handleProgress && this.handleProgress(percentage, file);
252
+ },
253
+ headers: {
254
+ "x-oss-callback": this.base64Encode(JSON.stringify(ossCallback)),
255
+ "Content-Disposition": type === "pdf" ? `inline;filename=${encodeURI(file.name)}` : `attachment;filename=${encodeURI(file.name)}`
256
+ }
257
+ })
258
+ .then(response => {
259
+ this.uploadSuccess = true;
260
+ this.percent = 100;
261
+ setTimeout(() => {
262
+ this.uploadSuccess = false;
263
+ this.percent = 0;
264
+ }, 500);
265
+
266
+ this.successCb && this.successCb(response, response.data, file);
267
+ callback && callback(response.data);
268
+ })
269
+ .catch((err, response) => {
274
270
  this.uploadSuccess = false;
275
271
  this.percent = 0;
276
- }, 500);
277
-
278
- this.successCb && this.successCb(response, response.data, file);
279
- callback && callback(response.data);
280
- }).catch((err, response) => {
281
- this.uploadSuccess = false;
282
- this.percent = 0;
283
272
 
284
- this.handleError && this.handleError(err, response, file);
285
- callback && callback(err);
273
+ this.handleError && this.handleError(err, response, file);
274
+ callback && callback(err);
286
275
  });
287
276
  },
288
277
  // bri-upload-image 用的是这种方式
@@ -297,10 +286,9 @@ export default {
297
286
  path: remoteName,
298
287
  bucket: res.ossConfig.bucket,
299
288
  filetoken: res.filetoken,
300
- groupKey: this.computedGroupKey,
289
+ groupKey: this.uploadGroupKey,
301
290
  archiveKey: this.archiveKey[this.archiveKey.length - 1]
302
291
  };
303
-
304
292
  let ossCallback = {
305
293
  callbackUrl: res.ossHost + res.confirmPath,
306
294
  callbackBodyType: "application/json",
@@ -320,41 +308,42 @@ export default {
320
308
  refreshSTSTokenInterval: 3600 * 1000
321
309
  };
322
310
 
323
- new Oss(newOss).multipartUpload(remoteName, file, {
324
- progress: (percentage) => {
325
- this.inProgress(Number((percentage * 100).toFixed(1)));
326
- this.handleProgress && this.handleProgress(percentage, file);
327
- },
328
- headers: {
329
- "x-oss-callback": this.base64Encode(JSON.stringify(ossCallback)),
330
- "Content-Disposition": type === "pdf" ? `inline;filename=${encodeURI(file.name)}` : `attachment;filename=${encodeURI(file.name)}`
331
- }
332
- }).then(response => {
333
- this.uploadSuccess = true;
334
- this.percent = 100;
335
- setTimeout(() => {
311
+ new Oss(newOss)
312
+ .multipartUpload(remoteName, file, {
313
+ progress: (percentage) => {
314
+ this.inProgress(Number((percentage * 100).toFixed(1)));
315
+ this.handleProgress && this.handleProgress(percentage, file);
316
+ },
317
+ headers: {
318
+ "x-oss-callback": this.base64Encode(JSON.stringify(ossCallback)),
319
+ "Content-Disposition": type === "pdf" ? `inline;filename=${encodeURI(file.name)}` : `attachment;filename=${encodeURI(file.name)}`
320
+ }
321
+ })
322
+ .then(response => {
323
+ this.uploadSuccess = true;
324
+ this.percent = 100;
325
+ setTimeout(() => {
326
+ this.uploadSuccess = false;
327
+ this.percent = 0;
328
+ }, 500);
329
+
330
+ this.successCb && this.successCb(response, response.data, file);
331
+ callback && callback(response.data);
332
+ })
333
+ .catch((err, response) => {
336
334
  this.uploadSuccess = false;
337
335
  this.percent = 0;
338
- }, 500);
339
336
 
340
- this.successCb && this.successCb(response, response.data, file);
341
- callback && callback(response.data);
342
- }).catch((err, response) => {
343
- this.uploadSuccess = false;
344
- this.percent = 0;
345
-
346
- this.handleError && this.handleError(err, response, file);
347
- callback && callback(err);
337
+ this.handleError && this.handleError(err, response, file);
338
+ callback && callback(err);
348
339
  });
349
340
  },
350
341
 
351
342
  // 处理上传进度
352
343
  inProgress (percent) {
353
- if (percent === 100 && !this.uploadSuccess) {
354
- this.percent = 99.9;
355
- } else {
356
- this.percent = percent;
357
- }
344
+ this.percent = percent === 100 && !this.uploadSuccess
345
+ ? 99.9
346
+ : percent;
358
347
 
359
348
  if (this.percent >= 100) {
360
349
  this.percent = 100;
@@ -106,7 +106,7 @@
106
106
  let that = this;
107
107
  let editor = new E(this.$refs.toolbar, this.$refs.editor);
108
108
  editor.config.uploadImgShowBase64 = false; // base 64 存储图片
109
- let url = this.$getRequests(this.computedUrlModule);
109
+ let url = this.$getRequests(this.finalUrlModule);
110
110
  editor.config.uploadImgServer = `${location.origin}${config.apiUrl}${url}`;// 配置服务器端地址(自己更换为自己项目的服务器)
111
111
  editor.config.uploadImgHeaders = this.propsObj._headers || { authtoken: sessionStorage.getItem("authtoken") }; // 自定义 header
112
112
  editor.config.uploadFileName = "file_stream"; // 后端接受上传文件的参数名