Commit 411ff42a authored by xinzhedeai's avatar xinzhedeai

图片上传变更

parent bf06eacd
......@@ -61,7 +61,7 @@ var http2 = {
console.log('vaildInterfacefn响应解密', sm2_decrypt_result)
if(!sm2_decrypt_result){ // 解密为空字符串
fn && fn(null)
fn && fn(null, 'decrypt')
return
}
......
......@@ -85,76 +85,105 @@ window.addEventListener("load", function() {
location.href = this.previewUrl + '/' + this.filePathList[0]
},
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: '文件大小不可超过2.5M'
message: '文件格式不正确'
})
return;
}
if (file.size > (10 * 1024 * 1024)) {
vant.Dialog.alert({
title: '信息提示',
message: '文件大小不可超过10M'
})
return false;
}
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) { // 调用爱山东中台系统,将数据流传递过去
// gemhoUtil.setCookie('uploading', 'Y')
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 = []
// 文件读取完成后的处理逻辑
const formData = new FormData();
formData.append('file', file.file); // 通过FormData构建要上传的文件数据
formData.append('biz_content',SM.encrypt('dangerjob', 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){ // 如果解密后的值为空字符串则重新上传图片
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()
}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() {
// 使用 Object.assign 来重写 this.$data,以达到重置 data 的目的
Object.assign(this.$data, this.$options.data.call(this));
......@@ -178,7 +207,11 @@ window.addEventListener("load", function() {
id: gemhoUtil.getParameter('dwId'),
}
}, (res) => {
if(!res){ // 中台返回为undefined 重新请求
vant.Toast.clear()
this.detail()
return
}
if (res) {
console.log('接口回调数据', JSON.parse(res))
vant.Toast.clear()
......@@ -225,8 +258,12 @@ window.addEventListener("load", function() {
interfacePublicKey: API_KEY_MAP["dw-list-detail"]["publicKey"],
interfacePrivateKey: API_KEY_MAP["dw-list-detail"]["privateKey"],
reqParams: this.form
}, (res) => {
}, (res, type) => {
if(!res && !type){ // 如果是中台接口返回为undefined,则重新发起请求
vant.Toast.clear()
this.submit()
return
}
if (res) {
console.log('添加结果', res)
vant.Toast({
......
......@@ -93,6 +93,8 @@ window.addEventListener("load", function() {
// location.reload()
// }
history.back()
}else{
this.submit()
}
})
},
......@@ -102,76 +104,105 @@ window.addEventListener("load", function() {
// return true; // 返回 true 继续上传,返回 false 中止上传
// },
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({
title: '信息提示',
message: '文件大小不可超过2.5M'
message: '文件大小不可超过10M'
})
return false;
}
return true;
},
afterRead(file) {
// 获取文件流,调用网关中台接口,获取文件全路径url
console.log('afterRead',file)
// 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) { // 调用爱山东中台系统,将数据流传递过去
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 = []
// 文件读取完成后的处理逻辑
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,
})
},
// afterRead(file) {
// console.log('afterRead',file)
// // 文件读取完成后的处理逻辑
// const formData = new FormData();
// formData.append('file', file.file); // 通过FormData构建要上传的文件数据
// formData.append('modelName', 'emergencydrill');
// // 发送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 => {
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) {
if (!this.disabled) {
this[popupType] = true
......@@ -198,7 +229,11 @@ window.addEventListener("load", function() {
planId: gemhoUtil.getParameter('planId'),
}
}, (res) => {
if(!res){ // 中台返回为undefined 重新请求
vant.Toast.clear()
this.detail()
return
}
if(res){
console.log('接口回调数据', JSON.parse(res))
......
......@@ -27,7 +27,7 @@
<p class="list-status-tag">
<van-tag :type="item.completionStatus==1?'primary':'warning'" size="mini">{{item.completionStatus==1 ? '完成': '未完成'}}</van-tag>
</p>
<p class="">
<p class="" style="width: 5.5rem;">
计划名称:{{item.planName}}
</p>
<p class="">
......
......@@ -53,6 +53,24 @@ window.addEventListener("load", function() {
}
},
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(){
vant.Toast.loading({
message: '加载中...',
......@@ -71,10 +89,13 @@ window.addEventListener("load", function() {
sort: 'hdId,desc',
}
}, (res) => {
if(!res){ // 中台返回为undefined 重新请求
vant.Toast.clear()
this.detail()
return
}
if(res){
// console.log('接口回调数据', JSON.parse(res))
console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res)
this.loading = false; // 加载状态结束
......@@ -108,37 +129,90 @@ window.addEventListener("load", function() {
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,
const formData = new FormData();
formData.append('hdRectificationPic', this.fileList[0].file); // 通过FormData构建要上传的文件数据
formData.append('biz_content', SM.encrypt(this.form.hdId, API_KEY_MAP["yh-list-detail"]["publicKey"]));
// 发送HTTP POST请求
fetch(BASE_URL + '/api/thHiddenDanger/update', {
method: 'POST',
headers: {
Authorization: gemhoUtil.getCookie('token')
},
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["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);
});
},
fileList: [{
fileName: 'hdRectificationPic',
file: this.fileList[0].file
}]
}, (res) => {
if(res){
// console.log('接口回调数据', JSON.parse(res))
// 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) => {
var result = JSON.parse(res)
this.loading = false; // 加载状态结束
// if(res){
// // console.log('接口回调数据', JSON.parse(res))
// console.log('响应结果', result)
// var result = JSON.parse(res)
// this.loading = false; // 加载状态结束
// vant.Toast.clear()
// vant.Toast({
// message: '操作完成',
// })
// location.href="./yh-list.html"
gemhoUtil.navigatePage('./yh-list.html', '操作完成,页面跳转中...')
// // console.log('响应结果', result)
}
})
},
// // vant.Toast.clear()
// // vant.Toast({
// // message: '操作完成',
// // })
// // location.href="./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