Commit eba987bb authored by 贺世双's avatar 贺世双

调整上传功能

parent 3a35d60d
......@@ -58,6 +58,10 @@ export function uploadImg(data, fileType = "image") {
export function downloadImg(data) {
return downloadFile("/api/doc/download", data);
}
// 获取文件名
export function findFileName(filePath) {
return Request(`/api/doc/download/${filePath}`, {}, 'GET',{}, false)
}
//获取基础订单信息--订舱委托
export function getOrderBaseList(data) {
......
......@@ -3,6 +3,7 @@ import compress from '../utils/compress'
let uploadFile = async (api, filePath, fileType, header = {}) => {
header = {
"content-type": "application/json",
'Cookie': 'XSRF-TOKEN=' + uni.getStorageSync(`${TokenPrefix}_XSRFToken`) || '',
"X-XSRF-TOKEN": uni.getStorageSync(`${TokenPrefix}_XSRFToken`) || '',
"Authorization": uni.getStorageSync(`${TokenPrefix}_token`) || '',
......@@ -11,10 +12,11 @@ let uploadFile = async (api, filePath, fileType, header = {}) => {
title: '上传中',
})
// #ifdef H5
if(fileType === 'image'){
filePath = await compress(filePath) //图片压缩
}
// #endif
return new Promise((reslove, reject) => {
api = APIPrefix + api
uni.uploadFile({
......@@ -31,6 +33,8 @@ let uploadFile = async (api, filePath, fileType, header = {}) => {
header,
success: (res) => {
uni.hideLoading()
console.log('22===============')
console.log(res.header)
if (res.data.reCode == 401 || res.data.reCode == -1) {
let app = getApp()
uni.showToast({
......
......@@ -279,7 +279,12 @@
})
return;
}
if(this.formData.occur_time){
this.formData.occur_time= this.formatDate(this.formData.occur_time)
}
const imgInstance = this.$refs.myUploadImg //获取图片上传实例
imgInstance.uploadImage(images => {
this.formData.abnormal_file=images;
var baseData = {
"aux": {
"rows":rows,
......@@ -300,6 +305,8 @@
}, 1500)
}
})
})
},
......
......@@ -91,7 +91,7 @@
</template>
<script>
import {getAbnormaCostBaseAll ,
import {getAbnormaCostBaseAll,downloadImg,findFileName,
getCurrencyAll} from '../../api/apiList.js'
export default {
name: 'abnormalEventDetail',
......@@ -140,6 +140,7 @@
ficationViewEnums: {'cost_classification': ""},
rateViewEnums: {'rate_item': ""},
currencyViewEnums: {'currency': ""},
imgs:[],
}
},
onLoad(options) {
......@@ -290,9 +291,7 @@
const imgInstance = this.$refs.myUploadImg //获取图片上传实例
const remarkInstance = this.$refs.myRemark;//备注
this.formData.remark = remarkInstance.value;
imgInstance.uploadImage(images => {
})
const allData = getApp().globalData.all;//所有的明细
var totle=0;
if(allData.length>0){
......@@ -347,7 +346,11 @@
}else if(cost == 'difference'){
this.formData.cost_classification_label= '补差费用'
}
imgInstance.uploadImage(images => {
this.formData.files = images;
getApp().globalData.tableData = this.formData;
})
setTimeout(() => {
uni.navigateBack()
}, 1500)
......@@ -410,6 +413,34 @@
}
this.showPopup = !this.showPopup
},
//文件预览Demo
async onPreviewFile(datas){
const _this = this
const aa = [
'940507a5acc6ed1771b8f411d749d20586f96ac6.pdf',
]
console.log('111=================')
console.log(aa)
console.log(datas)
uni.showLoading({
title: '下载中',
})
let files = [] //文件列表
console.log('2333----------------')
for (let file of datas) {
console.log(file)
const res = await findFileName(file) //获取文件名,小程序可通过DownloadFile接口所返回res直接获取,无需额外调用
// const oldFileName = res.header["Content-Disposition"].split("=")[1]; //解析文件名, 注意["Content-Disposition"]大小写
// const fileName = decodeURIComponent(oldFileName.split("UTF-8''")[1])//解码&解码类型
const fileType = file.split('.')[1] //截取文件名后缀,获取文件类型
files.push({fileId: file, filePath, fileName: 'test', fileType})
}
uni.hideLoading()
uni.navigateTo({
url: `/subpkg/previewFile/previewFile?files=${JSON.stringify(files)}`,
})
},
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment