Commit 411ff42a authored by xinzhedeai's avatar xinzhedeai

图片上传变更

parent bf06eacd
...@@ -61,7 +61,7 @@ var http2 = { ...@@ -61,7 +61,7 @@ var http2 = {
console.log('vaildInterfacefn响应解密', sm2_decrypt_result) console.log('vaildInterfacefn响应解密', sm2_decrypt_result)
if(!sm2_decrypt_result){ // 解密为空字符串 if(!sm2_decrypt_result){ // 解密为空字符串
fn && fn(null) fn && fn(null, 'decrypt')
return return
} }
......
...@@ -85,76 +85,105 @@ window.addEventListener("load", function() { ...@@ -85,76 +85,105 @@ window.addEventListener("load", function() {
location.href = this.previewUrl + '/' + this.filePathList[0] location.href = this.previewUrl + '/' + this.filePathList[0]
}, },
beforeRead(file) { beforeRead(file) {
if (file.size > (2.5 * 1024 * 1024)) { if(!['image/png','image/jpeg','image/jpg', 'application/pdf'].includes(file.type)){
vant.Dialog.alert({
title: '信息提示',
message: '文件格式不正确'
})
return;
}
if (file.size > (10 * 1024 * 1024)) {
vant.Dialog.alert({ vant.Dialog.alert({
title: '信息提示', title: '信息提示',
message: '文件大小不可超过2.5M' message: '文件大小不可超过10M'
}) })
return false; return false;
} }
return true; return true;
}, },
// console.log('afterRead', file)
// // 文件读取完成后的处理逻辑
// const formData = new FormData();
// formData.append('file', file.file); // 通过FormData构建要上传的文件数据
// formData.append('modelName', 'dangerjob');
// // 发送HTTP POST请求
// fetch(this.previewUrl + '/api/common/upload', {
// method: 'POST',
// body: formData
// })
// .then(response => {
// if (response.ok) {
// return response.json();
// }
// throw new Error('Network response was not ok.');
// })
// .then(data => {
// console.log(data); // 处理后端返回的数据
// // 可根据后端返回的数据做进一步处理,如显示上传成功信息等
// this.filePathList = data.body ? [data.body] : []
// })
// .catch(error => {
// console.error('There has been a problem with your fetch operation:', error);
// });
// },
// afterRead
// beforeRead
afterRead(file) { // 调用爱山东中台系统,将数据流传递过去 afterRead(file) { // 调用爱山东中台系统,将数据流传递过去
// gemhoUtil.setCookie('uploading', 'Y')
vant.Toast.loading({ vant.Toast.loading({
message: '正在处理...', message: '正在处理...',
forbidClick: true, forbidClick: true,
loadingType: 'spinner', loadingType: 'spinner',
}); });
http2.post({ // 文件读取完成后的处理逻辑
serviceId: API_KEY_MAP["upload"]['id'], const formData = new FormData();
interfacePublicKey: API_KEY_MAP["upload"]["publicKey"], formData.append('file', file.file); // 通过FormData构建要上传的文件数据
interfacePrivateKey: API_KEY_MAP["upload"]["privateKey"], formData.append('biz_content',SM.encrypt('dangerjob', API_KEY_MAP["upload"]["publicKey"]));
reqParams: {
modelName: 'dangerjob', // 发送HTTP POST请求
}, fetch(BASE_URL + '/api/common/upload', {
fileList: [{ method: 'POST',
fileName: 'file', body: formData
file: file.file })
}] .then(response => {
}, (res) => { if (response.ok) {
// gemhoUtil.setCookie('uploading', 'N') return response.json();
if (res) { }
console.log('接口回调数据', JSON.parse(res)) throw new Error('Network response was not ok.');
var result = JSON.parse(res) })
if (result.body && result.body.indexOf('dangerjob') > -1) { .then(value => {
this.filePathList = [result.body] console.log(value); // 处理后端返回的数据
} else { if(value){ // 返回信息不为空,则进行解密操作
this.filePathList = [] let sm2_encrypt_result = value // 后台返回待解密内容
let sm2_decrypt_result = sm2_Decrypt(sm2_encrypt_result, API_KEY_MAP["upload"]["privateKey"],)
if(!sm2_decrypt_result){ // 如果解密后的值为空字符串则重新上传图片
this.afterRead(file)
return
}
console.log('upload响应解密', sm2_decrypt_result)
const decryptRes = JSON.parse(sm2_decrypt_result)
if(decryptRes.code === 400 || decryptRes.code === 401 || decryptRes.status === 401){
vant.Dialog.alert({
title: '信息提示',
message: decryptRes.msg,
})
return
} }
this.filePathList = decryptRes.body ? [decryptRes.body] : []
// 可根据后端返回的数据做进一步处理,如显示上传成功信息等
vant.Toast.clear() vant.Toast.clear()
}else{
this.afterRead(file)
} }
}) })
.catch(error => {
// console.error('There has been a problem with your fetch operation:', error);
});
}, },
// afterRead(file) { // 调用爱山东中台系统,将数据流传递过去
// vant.Toast.loading({
// message: '正在处理...',
// forbidClick: true,
// loadingType: 'spinner',
// });
// http2.post({
// serviceId: API_KEY_MAP["upload"]['id'],
// interfacePublicKey: API_KEY_MAP["upload"]["publicKey"],
// interfacePrivateKey: API_KEY_MAP["upload"]["privateKey"],
// reqParams: {
// modelName: 'dangerjob',
// },
// fileList: [{
// fileName: 'file',
// file: file.file
// }]
// }, (res) => {
// // gemhoUtil.setCookie('uploading', 'N')
// if (res) {
// console.log('接口回调数据', JSON.parse(res))
// var result = JSON.parse(res)
// if (result.body && result.body.indexOf('dangerjob') > -1) {
// this.filePathList = [result.body]
// } else {
// this.filePathList = []
// }
// vant.Toast.clear()
// }
// })
// },
resetData() { resetData() {
// 使用 Object.assign 来重写 this.$data,以达到重置 data 的目的 // 使用 Object.assign 来重写 this.$data,以达到重置 data 的目的
Object.assign(this.$data, this.$options.data.call(this)); Object.assign(this.$data, this.$options.data.call(this));
...@@ -178,7 +207,11 @@ window.addEventListener("load", function() { ...@@ -178,7 +207,11 @@ window.addEventListener("load", function() {
id: gemhoUtil.getParameter('dwId'), id: gemhoUtil.getParameter('dwId'),
} }
}, (res) => { }, (res) => {
if(!res){ // 中台返回为undefined 重新请求
vant.Toast.clear()
this.detail()
return
}
if (res) { if (res) {
console.log('接口回调数据', JSON.parse(res)) console.log('接口回调数据', JSON.parse(res))
vant.Toast.clear() vant.Toast.clear()
...@@ -225,8 +258,12 @@ window.addEventListener("load", function() { ...@@ -225,8 +258,12 @@ window.addEventListener("load", function() {
interfacePublicKey: API_KEY_MAP["dw-list-detail"]["publicKey"], interfacePublicKey: API_KEY_MAP["dw-list-detail"]["publicKey"],
interfacePrivateKey: API_KEY_MAP["dw-list-detail"]["privateKey"], interfacePrivateKey: API_KEY_MAP["dw-list-detail"]["privateKey"],
reqParams: this.form reqParams: this.form
}, (res) => { }, (res, type) => {
if(!res && !type){ // 如果是中台接口返回为undefined,则重新发起请求
vant.Toast.clear()
this.submit()
return
}
if (res) { if (res) {
console.log('添加结果', res) console.log('添加结果', res)
vant.Toast({ vant.Toast({
......
...@@ -93,6 +93,8 @@ window.addEventListener("load", function() { ...@@ -93,6 +93,8 @@ window.addEventListener("load", function() {
// location.reload() // location.reload()
// } // }
history.back() history.back()
}else{
this.submit()
} }
}) })
}, },
...@@ -102,76 +104,105 @@ window.addEventListener("load", function() { ...@@ -102,76 +104,105 @@ window.addEventListener("load", function() {
// return true; // 返回 true 继续上传,返回 false 中止上传 // return true; // 返回 true 继续上传,返回 false 中止上传
// }, // },
beforeRead(file) { beforeRead(file) {
if (file.size > (2.5*1024*1024)) { if(!['image/png','image/jpeg','image/jpg'].includes(file.type)){
vant.Dialog.alert({
title: '信息提示',
message: '文件格式不正确'
})
return;
}
if (file.size > (10*1024*1024)) {
vant.Dialog.alert({ vant.Dialog.alert({
title: '信息提示', title: '信息提示',
message: '文件大小不可超过2.5M' message: '文件大小不可超过10M'
}) })
return false; return false;
} }
return true; return true;
}, },
afterRead(file) {
// 获取文件流,调用网关中台接口,获取文件全路径url
console.log('afterRead',file)
vant.Toast.loading({
message: '正在处理...',
forbidClick: true,
loadingType: 'spinner',
});
http2.post({
serviceId: API_KEY_MAP["upload"]['id'],
interfacePublicKey: API_KEY_MAP["upload"]["publicKey"],
interfacePrivateKey: API_KEY_MAP["upload"]["privateKey"],
reqParams: {
modelName: 'emergencydrill',
},
fileList: [{
fileName: 'file',
file: file.file
}]
}, (res) => {
// gemhoUtil.setCookie('uploading', 'N')
if(res){
console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res)
if(result.body && result.body.indexOf('emergencydrill') > -1){
this.filePathList = [result.body]
}else{
this.filePathList = []
}
vant.Toast.clear()
}
})
},
// afterRead(file) { // afterRead(file) {
// // 获取文件流,调用网关中台接口,获取文件全路径url
// console.log('afterRead',file) // console.log('afterRead',file)
// // 文件读取完成后的处理逻辑
// const formData = new FormData();
// formData.append('file', file.file); // 通过FormData构建要上传的文件数据
// formData.append('modelName', 'emergencydrill');
// // 发送HTTP POST请求 // vant.Toast.loading({
// fetch(this.previewUrl + '/api/common/upload', { // message: '正在处理...',
// method: 'POST', // forbidClick: true,
// body: formData // loadingType: 'spinner',
// }) // });
// .then(response => { // http2.post({
// if (response.ok) { // serviceId: API_KEY_MAP["upload"]['id'],
// return response.json(); // interfacePublicKey: API_KEY_MAP["upload"]["publicKey"],
// interfacePrivateKey: API_KEY_MAP["upload"]["privateKey"],
// reqParams: {
// modelName: 'emergencydrill',
// },
// fileList: [{
// fileName: 'file',
// file: file.file
// }]
// }, (res) => {
// // gemhoUtil.setCookie('uploading', 'N')
// if(res){
// console.log('接口回调数据', JSON.parse(res))
// var result = JSON.parse(res)
// if(result.body && result.body.indexOf('emergencydrill') > -1){
// this.filePathList = [result.body]
// }else{
// this.filePathList = []
// } // }
// throw new Error('Network response was not ok.'); // vant.Toast.clear()
// }) // }
// .then(data => { // })
// console.log(data); // 处理后端返回的数据
// // 可根据后端返回的数据做进一步处理,如显示上传成功信息等
// this.filePathList = data.body ? [data.body] : []
// })
// .catch(error => {
// console.error('There has been a problem with your fetch operation:', error);
// });
// }, // },
afterRead(file) { // 调用爱山东中台系统,将数据流传递过去
vant.Toast.loading({
message: '正在处理...',
forbidClick: true,
loadingType: 'spinner',
});
// 文件读取完成后的处理逻辑
const formData = new FormData();
formData.append('file', file.file); // 通过FormData构建要上传的文件数据
formData.append('biz_content',SM.encrypt('emergencydrill', API_KEY_MAP["upload"]["publicKey"]));
// 发送HTTP POST请求
fetch(BASE_URL + '/api/common/upload', {
method: 'POST',
body: formData
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then(value => {
console.log(value); // 处理后端返回的数据
if(value){ // 返回信息不为空,则进行解密操作
let sm2_encrypt_result = value // 后台返回待解密内容
let sm2_decrypt_result = sm2_Decrypt(sm2_encrypt_result, API_KEY_MAP["upload"]["privateKey"],)
if(!sm2_decrypt_result){ // 如果解密后的值为空字符串则重新上传图片
vant.Toast.clear()
this.afterRead(file)
return
}
console.log('upload响应解密', sm2_decrypt_result)
const decryptRes = JSON.parse(sm2_decrypt_result)
if(decryptRes.code === 400 || decryptRes.code === 401 || decryptRes.status === 401){
vant.Dialog.alert({
title: '信息提示',
message: decryptRes.msg,
})
return
}
this.filePathList = decryptRes.body ? [decryptRes.body] : []
vant.Toast.clear()
}
})
.catch(error => {
// console.error('There has been a problem with your fetch operation:', error);
});
},
showPopup(popupType) { showPopup(popupType) {
if (!this.disabled) { if (!this.disabled) {
this[popupType] = true this[popupType] = true
...@@ -198,7 +229,11 @@ window.addEventListener("load", function() { ...@@ -198,7 +229,11 @@ window.addEventListener("load", function() {
planId: gemhoUtil.getParameter('planId'), planId: gemhoUtil.getParameter('planId'),
} }
}, (res) => { }, (res) => {
if(!res){ // 中台返回为undefined 重新请求
vant.Toast.clear()
this.detail()
return
}
if(res){ if(res){
console.log('接口回调数据', JSON.parse(res)) console.log('接口回调数据', JSON.parse(res))
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<p class="list-status-tag"> <p class="list-status-tag">
<van-tag :type="item.completionStatus==1?'primary':'warning'" size="mini">{{item.completionStatus==1 ? '完成': '未完成'}}</van-tag> <van-tag :type="item.completionStatus==1?'primary':'warning'" size="mini">{{item.completionStatus==1 ? '完成': '未完成'}}</van-tag>
</p> </p>
<p class=""> <p class="" style="width: 5.5rem;">
计划名称:{{item.planName}} 计划名称:{{item.planName}}
</p> </p>
<p class=""> <p class="">
......
...@@ -53,6 +53,24 @@ window.addEventListener("load", function() { ...@@ -53,6 +53,24 @@ window.addEventListener("load", function() {
} }
}, },
methods: { methods: {
beforeRead(file) {
if(!['image/png','image/jpeg','image/jpg'].includes(file.type)){
vant.Dialog.alert({
title: '信息提示',
message: '文件格式不正确'
})
return;
}
console.log('beforeRead', file.size)
if (file.size > (10 * 1024 * 1024)) {
vant.Dialog.alert({
title: '信息提示',
message: '文件大小不可超过10M'
})
return false;
}
return true;
},
detail(){ detail(){
vant.Toast.loading({ vant.Toast.loading({
message: '加载中...', message: '加载中...',
...@@ -71,10 +89,13 @@ window.addEventListener("load", function() { ...@@ -71,10 +89,13 @@ window.addEventListener("load", function() {
sort: 'hdId,desc', sort: 'hdId,desc',
} }
}, (res) => { }, (res) => {
if(!res){ // 中台返回为undefined 重新请求
vant.Toast.clear()
this.detail()
return
}
if(res){ if(res){
// console.log('接口回调数据', JSON.parse(res)) console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res) var result = JSON.parse(res)
this.loading = false; // 加载状态结束 this.loading = false; // 加载状态结束
...@@ -108,37 +129,90 @@ window.addEventListener("load", function() { ...@@ -108,37 +129,90 @@ window.addEventListener("load", function() {
forbidClick: true, forbidClick: true,
loadingType: 'spinner', loadingType: 'spinner',
}); });
http2.post({ const formData = new FormData();
serviceId: API_KEY_MAP["yh-list-detail"]['id'], formData.append('hdRectificationPic', this.fileList[0].file); // 通过FormData构建要上传的文件数据
interfacePublicKey: API_KEY_MAP["yh-list-detail"]["publicKey"], formData.append('biz_content', SM.encrypt(this.form.hdId, API_KEY_MAP["yh-list-detail"]["publicKey"]));
interfacePrivateKey: API_KEY_MAP["yh-list-detail"]["privateKey"],
reqParams: { // 发送HTTP POST请求
hdId: this.form.hdId, fetch(BASE_URL + '/api/thHiddenDanger/update', {
method: 'POST',
headers: {
Authorization: gemhoUtil.getCookie('token')
}, },
fileList: [{ body: formData
fileName: 'hdRectificationPic', })
file: this.fileList[0].file .then(response => {
}] if (response.ok) {
}, (res) => { return response.json();
}
throw new Error('Network response was not ok.');
})
.then(value => {
console.log(value); // 处理后端返回的数据
if(value){ // 返回信息不为空,则进行解密操作
let sm2_encrypt_result = value // 后台返回待解密内容
let sm2_decrypt_result = sm2_Decrypt(sm2_encrypt_result, API_KEY_MAP["yh-list-detail"]["privateKey"],)
console.log('yh-list-detail响应解密', sm2_decrypt_result)
const decryptRes = JSON.parse(sm2_decrypt_result)
if(decryptRes.code === 400 || decryptRes.code === 401 || decryptRes.status === 401){
vant.Dialog.alert({
title: '信息提示',
message: decryptRes.msg,
})
return
}
// 可根据后端返回的数据做进一步处理,如显示上传成功信息等
gemhoUtil.navigatePage('./yh-list.html', '操作完成,页面跳转中...')
}
})
.catch(error => {
// console.error('There has been a problem with your fetch operation:', error);
});
},
// submit() {
// if (!this.fileList.length) {
// vant.Dialog.alert({
// message: '没有整改照片',
// })
// return
// }
// vant.Toast.loading({
// message: '正在处理...',
// forbidClick: true,
// loadingType: 'spinner',
// });
// http2.post({
// serviceId: API_KEY_MAP["yh-list-detail"]['id'],
// interfacePublicKey: API_KEY_MAP["yh-list-detail"]["publicKey"],
// interfacePrivateKey: API_KEY_MAP["yh-list-detail"]["privateKey"],
// reqParams: {
// hdId: this.form.hdId,
// },
// fileList: [{
// fileName: 'hdRectificationPic',
// file: this.fileList[0].file
// }]
// }, (res) => {
if(res){ // if(res){
// console.log('接口回调数据', JSON.parse(res)) // // console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res) // var result = JSON.parse(res)
this.loading = false; // 加载状态结束 // this.loading = false; // 加载状态结束
// console.log('响应结果', result) // // console.log('响应结果', result)
// vant.Toast.clear() // // vant.Toast.clear()
// vant.Toast({ // // vant.Toast({
// message: '操作完成', // // message: '操作完成',
// }) // // })
// location.href="./yh-list.html" // // location.href="./yh-list.html"
gemhoUtil.navigatePage('./yh-list.html', '操作完成,页面跳转中...') // // gemhoUtil.navigatePage('./yh-list.html', '操作完成,页面跳转中...')
} // }
}) // })
}, // },
}, },
}); });
}); });
\ No newline at end of file
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