@lambo-design/upload-file 1.0.0-beta.14 → 1.0.0-beta.16

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/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Changelog
2
- ## [1.0.0-beta.14](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.13...@lambo-design/upload-file@1.0.0-beta.14) (2024-04-13)
2
+ ## [1.0.0-beta.16](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.15...@lambo-design/upload-file@1.0.0-beta.16) (2024-05-31)
3
3
 
4
- ## [1.0.0-beta.13](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.12...@lambo-design/upload-file@1.0.0-beta.13) (2024-04-12)
5
4
 
6
- ## 1.0.0-beta.12 (2024-04-12)
5
+ ### Features | 新功能
6
+
7
+ * **upload-file:** 上传文件优化 ([0b71962](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/0b71962bba818f01c573f19eed57bd81e758e1ac))
8
+
9
+ ## [1.0.0-beta.15](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.14...@lambo-design/upload-file@1.0.0-beta.15) (2024-04-18)
10
+
11
+
12
+ ### ✨ Features | 新功能
13
+
14
+ * **@lambo-design/upload-file:** 修改工具类方法引用路径 ([d48b381](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/d48b38109bbdb96b0e21128bf93e5ba85b8248bb))
15
+
16
+ ## [1.0.0-beta.14](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.13...@lambo-design/upload-file@1.0.0-beta.14) (2024-04-13)
17
+
18
+ ## [1.0.0-beta.13](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.12...@lambo-design/upload-file@1.0.0-beta.13) (2024-04-12)
19
+
20
+ ## 1.0.0-beta.12 (2024-04-12)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lambo-design/upload-file",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
@@ -12,8 +12,8 @@
12
12
  "devDependencies": {
13
13
  "axios": "^0.24.0",
14
14
  "axios-cache-plugin": "^0.1.0",
15
- "@lambo-design/shared": "^1.0.0-beta.154",
16
- "@lambo-design/core": "^4.7.1-beta.130"
15
+ "@lambo-design/shared": "^1.0.0-beta.183",
16
+ "@lambo-design/core": "^4.7.1-beta.139"
17
17
  },
18
18
  "scripts": {
19
19
  "release": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
package/src/index.vue CHANGED
@@ -15,13 +15,13 @@
15
15
  :multiple="multiple"
16
16
  :accept="accept"
17
17
  @change="readFile($event, 1)"/>
18
- <div class="upload-file-list" v-if="showFileList && resultList.length > 0">
18
+ <div class="upload-file-list" v-if="showFileList && resultList.length > 0">
19
19
  <List border size="small">
20
20
  <ListItem v-for="item in resultList" :key="item.fileCode">
21
21
  <div span="21">
22
22
  <a :href="item.fileUrl ? item.fileUrl : downloadUrl + item.fileCode">
23
- {{item.fileName}}
24
- <span class="size" style="margin-left: 5px" v-if="item.showSize">({{item.showSize}})</span>
23
+ {{ item.fileName }}
24
+ <span class="size" style="margin-left: 5px" v-if="item.showSize">({{ item.showSize }})</span>
25
25
  </a>
26
26
  </div>
27
27
  <div span="3" style="text-align: right">
@@ -35,9 +35,9 @@
35
35
  </template>
36
36
 
37
37
  <script>
38
- import axios from 'axios';
38
+ import ajax from "@lambo-design/shared/utils/ajax";
39
39
  import config from "@lambo-design/shared/config/config";
40
- import {formatterSizeUnit} from "@lambo-design/shared/utils/date";
40
+ import {formatterSizeUnit} from "@lambo-design/shared/utils/file";
41
41
 
42
42
  export default {
43
43
  components: {},
@@ -102,24 +102,24 @@ export default {
102
102
  default: ''
103
103
  },
104
104
  //上传文件Url
105
- ossFilePutUrl:{
105
+ ossFilePutUrl: {
106
106
  type: String,
107
107
  default: "/oss/file/put"
108
108
  },
109
109
  //获取文件url
110
- ossFileGetUrl:{
111
- type:String,
112
- default:"/oss/file/get/"
110
+ ossFileGetUrl: {
111
+ type: String,
112
+ default: "/oss/file/get/"
113
113
  },
114
114
  //文件预览所需文件流服务host
115
- fileOnlinePreviewHost:{
115
+ fileOnlinePreviewHost: {
116
116
  type: String,
117
117
  default: "http://pub-manage-server:8080"
118
118
  },
119
119
  //预览文件url
120
- ossFilePreviewUrl:{
121
- type:String,
122
- default:"/anon/oss/file/getObjToOutputStream/"
120
+ ossFilePreviewUrl: {
121
+ type: String,
122
+ default: "/anon/oss/file/getObjToOutputStream/"
123
123
  }
124
124
  },
125
125
 
@@ -146,17 +146,16 @@ export default {
146
146
  methods: {
147
147
  UploadFile: function () {
148
148
  this.$refs.uploadInput.click();
149
- this.loading=true;
150
149
  },
151
150
  readFile: function (e, num) {
152
151
  let self = this;
153
152
  //读取文件
154
- // var file = e.target.files[0];
153
+ self.loading = true;
155
154
  for (let file of e.target.files) {
156
- // fileSuffix
157
- var reg = new RegExp("\.(" + this.fileSuffix + ")$", "i");
155
+ const reg = new RegExp("\.(" + this.fileSuffix + ")$", "i");
158
156
  if (!reg.test(file.name)) {
159
157
  alert('文件类型必须是doc,docx,txt,xls,xlsx,jpg,jpeg,png中的一种');
158
+ self.loading = false;
160
159
  return false;
161
160
  } else {
162
161
  self.attachmentFile.fileName = file;
@@ -168,33 +167,31 @@ export default {
168
167
  }
169
168
  }
170
169
  self.attachmentFile.fileType = self.attachmentFile.fileName.name.substring(self.attachmentFile.fileName.name.lastIndexOf(".") + 1);
171
-
172
170
  }
173
- // self.loading = true;
174
- self.loadtoServer();
171
+ self.doUpload();
175
172
  },
176
- loadtoServer: function () {
177
- var self = this;
178
- let inputDOM = this.$refs.uploadInput;
179
- var afile = inputDOM.files;
180
- if (afile.size == 0) {
173
+ doUpload: function () {
174
+ let self = this;
175
+ const allFile = this.$refs.uploadInput.files;
176
+ if (allFile.size === 0) {
181
177
  alert("不能传入空文件");
178
+ self.loading = false;
182
179
  return false;
183
180
  }
184
181
  let formData = new FormData();
185
- for (let file of afile) {
182
+ for (let file of allFile) {
186
183
  formData.append('file', file);
187
184
  }
188
185
  let resultList = [];
189
- let uploadUrl = self.ossServerContext + self.ossFilePutUrl;
190
- let downloadUrl = self.ossServerContext + self.ossFileGetUrl;
191
- axios.post(uploadUrl, formData).then(response => {
192
- if (response.data.code == "1") {
193
- var result = response.data.data;
186
+ const uploadUrl = self.ossServerContext + self.ossFilePutUrl;
187
+ const downloadUrl = self.ossServerContext + self.ossFileGetUrl;
188
+ ajax.post(uploadUrl, formData, { payload: true }).then(response => {
189
+ if (response.data.code === 1) {
190
+ const result = response.data.data;
194
191
  self.loading = false;
195
192
  if (result.length >= 1) {
196
193
  result.forEach(item => {
197
- let tmp = {
194
+ const tmp = {
198
195
  fileUrl: downloadUrl + item.fileId,
199
196
  fileCode: item.fileId,
200
197
  fileName: item.fileName,
@@ -203,7 +200,6 @@ export default {
203
200
  showSize: formatterSizeUnit(item.length),
204
201
  otherParam: self.otherParam
205
202
  };
206
-
207
203
  resultList.push(tmp);
208
204
  self.resultList.push(tmp);
209
205
  });
@@ -226,34 +222,29 @@ export default {
226
222
 
227
223
  encode64(value) {
228
224
  let typeValue = typeof value;
229
- if (typeValue == 'string' || typeValue == 'number') {
225
+ if (typeValue === 'string' || typeValue === 'number') {
230
226
  return window.btoa(
231
- window.encodeURIComponent(value)
232
- .replace(/%([0-9A-F]{2})/g,
233
- function toSolidBytes(match, p1) {
234
- return String.fromCharCode('0x' + p1);
235
- }
236
- )
237
- );
227
+ window.encodeURIComponent(value)
228
+ .replace(/%([0-9A-F]{2})/g,
229
+ function toSolidBytes(match, p1) {
230
+ return String.fromCharCode('0x' + p1);
231
+ }));
238
232
  } else {
239
233
  return value;
240
234
  }
241
235
  },
242
236
  previewFile: function (item) {
243
- var fileCode = item.fileCode;
244
- var fileName = item.fileName;
245
- var fileType = item.fileType;
246
- if(fileCode) {
247
- let url = this.fileOnlinePreviewHost + this.ossServerContext + this.ossFilePreviewUrl + fileCode + "?fullfilename=" + fileName + "." + fileType;
248
- window.open(config.fileOnlinePreviewContext + '/onlinePreview?url='+encodeURIComponent(this.encode64(url)));
237
+ if (item.fileCode) {
238
+ const url = this.fileOnlinePreviewHost + this.ossServerContext + this.ossFilePreviewUrl + item.fileCode + "?fullfilename=" + item.fileName + "." + item.fileType;
239
+ window.open(config.fileOnlinePreviewContext + '/onlinePreview?url=' + encodeURIComponent(this.encode64(url)));
249
240
  }
250
241
  },
251
242
  deleteFile: function (fileCode) {
252
243
  if (fileCode) {
253
- var result = [];
254
- var deletes = []
244
+ let result = [];
245
+ let deletes = []
255
246
  this.resultList.forEach(item => {
256
- if (item.fileCode != fileCode) {
247
+ if (item.fileCode !== fileCode) {
257
248
  result.push(item);
258
249
  } else {
259
250
  deletes.push(item)
@@ -270,8 +261,7 @@ export default {
270
261
  },
271
262
  watch: {
272
263
  fileList: function (value) {
273
- var data = this.fileList;
274
- this.resultList = data;
264
+ this.resultList = this.fileList
275
265
  }
276
266
  }
277
267
  }