图片和文件上传优化

This commit is contained in:
kerwincui
2022-06-05 14:51:10 +08:00
parent ba128edd40
commit 12b88d2a93
4 changed files with 7 additions and 27 deletions

View File

@@ -18,22 +18,3 @@ export function register(data) {
data: data
})
}
// 下载文件
export function download(resource) {
var url = baseURL + "/iot/tool/download?fileName=" + encodeURI(resource);
axios({
method: 'get',
url: url,
responseType: 'blob',
headers: { 'Authorization': 'Bearer ' + getToken() }
}).then(async (res) => {
const isLogin = await blobValidate(res.data);
if (isLogin) {
const blob = new Blob([res.data])
saveAs(blob, decodeURI(res.headers['download-filename']))
} else {
Message.error('无效的会话,或者会话已过期,请重新登录。');
}
})
}

View File

@@ -70,7 +70,7 @@ export default {
data() {
return {
baseUrl: process.env.VUE_APP_BASE_API,
uploadFileUrl: process.env.VUE_APP_BASE_API + "/iot/tool/upload", // 上传的图片服务器地址
uploadFileUrl: process.env.VUE_APP_BASE_API + "/iot/tool/upload", // 上传文件服务器地址
headers: {
Authorization: "Bearer " + getToken(),
},

View File

@@ -124,7 +124,7 @@ export default {
},
// 上传成功回调
handleUploadSuccess(res) {
this.fileList.push({ name: res.fileName, url: process.env.VUE_APP_BASE_API + "/iot/tool/download?fileName="+res.fileName });
this.fileList.push({ name: res.fileName, url: process.env.VUE_APP_BASE_API +res.fileName });
this.$emit("input", this.listToString(this.fileList));
this.loading.close();
},

View File

@@ -77,9 +77,6 @@
</template>
<script>
import {
download
} from '@/api/iot/tool'
import fileUpload from '../../../components/FileUpload/index'
import {
listShortProduct
@@ -133,7 +130,9 @@ export default {
isSys: null,
},
// 表单参数
form: {},
form: {
version: 1.0
},
// 表单校验
rules: {
firmwareName: [{
@@ -213,7 +212,7 @@ export default {
tenantId: null,
tenantName: null,
isSys: null,
version: null,
version: 1.0,
filePath: null,
delFlag: null,
createBy: null,
@@ -329,7 +328,7 @@ export default {
},
// 文件下载处理
handleDownload(row) {
download(row.filePath);
window.open(process.env.VUE_APP_BASE_API+row.filePath);
}
},