| | |
| | | }, |
| | | async toArrayBuffer(file) { |
| | | return new Promise((resolve, reject) => { |
| | | // 读取文件 |
| | | const fileReader = new FileReader(); |
| | | setTimeout(() => { |
| | | fileReader.readAsArrayBuffer(file); |
| | | }); |
| | | fileReader.readAsArrayBuffer(file); |
| | | |
| | | fileReader.onload = (e) => { |
| | | resolve(e.target.result); |
| | | }; |
| | | |
| | | fileReader.onerror = (e) => { |
| | | reject(e); |
| | | }; |
| | | |
| | | // 读取完成 |
| | | // fileReader.onload = (e) => { |
| | | // resolve(e.target?.result); |
| | | // }; |
| | | }); |
| | | }, |
| | | async upFileAsArrayBuffer( |
| | | url, |
| | | file, |
| | | options, |
| | | ){ |
| | | // 读取文件 |
| | | async upFileAsArrayBuffer(url, file, options) { |
| | | const arrayBuffer = await this.toArrayBuffer(file); |
| | | |
| | | // 上传文件 |
| | | return axios({ |
| | | url, |
| | | method: options?.method || 'POST', |
| | | withCredentials: Boolean(options?.withCredentials), |
| | | |
| | | // 二进制数据 |
| | | method: options.method || 'POST', |
| | | withCredentials: Boolean(options.withCredentials), |
| | | data: arrayBuffer, |
| | | |
| | | // 请求头 |
| | | headers: { |
| | | 'Content-Type': 'application/octet-stream', |
| | | 'file-name': encodeURIComponent(options?.fileName || file.name), |
| | | 'file-name': encodeURIComponent(options.fileName || file.name), |
| | | }, |
| | | |
| | | // 上传进度 |
| | | onUploadProgress: ({ total, loaded }) => { |
| | | const onProgress = options?.onProgress; |
| | | if (!isFunction(onProgress)) return; |
| | | |
| | | onProgress({ |
| | | percent: Math.ceil((loaded / total) * 100), |
| | | }); |
| | | const onProgress = options.onProgress; |
| | | if (typeof onProgress === 'function') { |
| | | onProgress({ |
| | | percent: Math.ceil((loaded / total) * 100), |
| | | }); |
| | | } |
| | | }, |
| | | }); |
| | | }, |
| | | uploadFile(e, obj, value) { |
| | | axios.post('http://47.108.239.173:2020/api/oss/new_temp_upload', obj).then(res => { |
| | | if (res.status == 200) { |
| | | this.upFileAsArrayBuffer('http://47.108.239.173:2020/api/oss/upload_file', e.file, { methods: 'POST', fileName: res.data.data }).then(resp => { |
| | | console.log(resp, 'asdasdsad'); |
| | | if (resp.data.status === 0) { |
| | | if (value == 1) { |
| | | this.form.DOFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | console.log(this.fileList1, 'this.fileList1'); |
| | | |
| | | this.upFileAsArrayBuffer('http://47.108.239.173:2020/api/oss/upload_file', e.file).then(resp=>{ |
| | | console.log(resp,'asdasdsad'); |
| | | |
| | | } else if (value == 2) { |
| | | this.form.PUFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | console.log(this.form.PUFileUrl, 'this.form.PUFileUrl'); |
| | | |
| | | } else if (value == 3) { |
| | | this.form.PODFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | } else { |
| | | this.form.otherFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | } |
| | | this.$forceUpdate() |
| | | } |
| | | }) |
| | | // axios.post('http://47.108.239.173:2020/api/oss/upload_file', fileName, { |
| | | // headers: { |
| | | // 'File-Name': res.data.data |
| | | // } |
| | | // }).then(resp => { |
| | | // console.log(resp, value, 'asdasdasdasdas'); |
| | | // if (resp.data.status === 0) { |
| | | // if (value == 1) { |
| | | // this.form.DOFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | // console.log(this.fileList1, 'this.fileList1'); |
| | | |
| | | // } else if (value == 2) { |
| | | // this.form.PUFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | // console.log(this.form.PUFileUrl, 'this.form.PUFileUrl'); |
| | | |
| | | // } else if (value == 3) { |
| | | // this.form.PODFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | // } else { |
| | | // this.form.otherFileUrl = 'http://47.108.239.173:2020/api/oss/download/' + res.data.data |
| | | // } |
| | | // this.$forceUpdate() |
| | | // } |
| | | |
| | | // }) |
| | | } |
| | | }) |
| | | }, |