Commit c52db27e authored by xinzhedeai's avatar xinzhedeai

应急演练模块开发 图片上传处理

parent 992592c0
...@@ -14,6 +14,11 @@ window.onload = function() { ...@@ -14,6 +14,11 @@ window.onload = function() {
} }
function getUserInfo() { function getUserInfo() {
vant.Toast.loading({
message: '授权中...',
forbidClick: true,
loadingType: 'spinner',
});
lightAppJssdk.user.getUserInfoWithEncryptedParamByAppId({ lightAppJssdk.user.getUserInfoWithEncryptedParamByAppId({
appId: "whsdsjzxsfrzdjqwsczptsr", //"gqyjglptxiefn", // 接入方在成功创建应用后自动生成 appId: "whsdsjzxsfrzdjqwsczptsr", //"gqyjglptxiefn", // 接入方在成功创建应用后自动生成
success: function(data) { success: function(data) {
......
...@@ -87,16 +87,16 @@ ...@@ -87,16 +87,16 @@
v-show="showImage" v-show="showImage"
width="100" width="100"
height="100" height="100"
:src="previewUrl+'/' + form.filePathList[0]" :src="previewUrl+'/' + filePathList[0]"
/> />
</div> </div>
<span v-show="showPdf" @click="previewFile">{{ form.filePathList[0] }}</span> <span v-show="showPdf" @click="previewFile">{{ filePathList[0] }}</span>
<span v-show="!disabled" style="font-weight: bold; cursor: pointer;" @click="form.filePathList=[];fileList=[]"> 删除</span> <span v-show="!disabled" style="font-weight: bold; cursor: pointer;" @click="filePathList=[];fileList=[]"> 删除</span>
</van-cell> </van-cell>
</van-cell-group> </van-cell-group>
<!-- :before-read="beforeRead" :max-size="1*1024*1024"--> <!-- :before-read="beforeRead" :max-size="1*1024*1024"-->
<van-cell-group :class="{'disable-van-cell': disabled}" v-show="pageType !== 'detail' && !form.filePathList.length"> <van-cell-group :class="{'disable-van-cell': disabled}" v-show="pageType !== 'detail' && !filePathList.length">
<van-cell>文件:<span style="color: red;">(限制大小2.5M以内)</span> <van-cell>文件:<span style="color: red;">(限制大小2.5M以内,格式png/jpg/jpeg/pdf)</span>
<div style="width: 2.5rem;"> <div style="width: 2.5rem;">
<van-uploader v-model="fileList" <van-uploader v-model="fileList"
accept=".jpg,.jpeg,.png,.pdf" accept=".jpg,.jpeg,.png,.pdf"
......
...@@ -22,9 +22,8 @@ window.addEventListener("load", function() { ...@@ -22,9 +22,8 @@ window.addEventListener("load", function() {
perTel: '', perTel: '',
remark: '', remark: '',
uploadDate: "", uploadDate: "",
filePathList: [] // 'dangerjob/e40eda16-7a86-4a2a-976b-892e17eeed49.pdf'
}, },
filePathList: [], // 'dangerjob/e40eda16-7a86-4a2a-976b-892e17eeed49.pdf'
// 企业id // 企业id
companyId: localStorage.getItem('companyId'), companyId: localStorage.getItem('companyId'),
disabled: false, disabled: false,
...@@ -67,21 +66,21 @@ window.addEventListener("load", function() { ...@@ -67,21 +66,21 @@ window.addEventListener("load", function() {
}, },
computed:{ computed:{
showImage(){ showImage(){
return this.form.filePathList[0] && (this.form.filePathList[0].indexOf('.png')>-1 || this.form.filePathList[0].indexOf('.jpg')>-1 || this.form.filePathList[0].indexOf('.jpeg')>-1) return this.filePathList[0] && (this.filePathList[0].indexOf('.png')>-1 || this.filePathList[0].indexOf('.jpg')>-1 || this.filePathList[0].indexOf('.jpeg')>-1)
}, },
showPdf(){ showPdf(){
return this.form.filePathList[0] && (this.form.filePathList[0].indexOf('.pdf')>-1) return this.filePathList[0] && (this.filePathList[0].indexOf('.pdf')>-1)
}, },
showWrapper(){ showWrapper(){
return this.form.filePathList[0] return this.filePathList[0]
} }
}, },
methods: { methods: {
previewFile(){ previewFile(){
// var src = 'dangerjob/e40eda16-7a86-4a2a-976b-892e17eeed49.pdf' // var src = 'dangerjob/e40eda16-7a86-4a2a-976b-892e17eeed49.pdf'
// location.href = './pdfViewer.html?pdfSrc='+ src // location.href = './pdfViewer.html?pdfSrc='+ src
console.log(this.previewUrl + '/' + this.form.filePathList[0]) console.log(this.previewUrl + '/' + this.filePathList[0])
location.href = this.previewUrl + '/' + this.form.filePathList[0] location.href = this.previewUrl + '/' + this.filePathList[0]
}, },
beforeUpload(file) { beforeUpload(file) {
...@@ -123,7 +122,9 @@ window.addEventListener("load", function() { ...@@ -123,7 +122,9 @@ window.addEventListener("load", function() {
console.log('接口回调数据', JSON.parse(res)) console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res) var result = JSON.parse(res)
if(result.body && result.body.indexOf('dangerjob') > -1){ if(result.body && result.body.indexOf('dangerjob') > -1){
this.form.filePathList = [result.body] this.filePathList = [result.body]
}else{
this.filePathList = []
} }
vant.Toast.clear() vant.Toast.clear()
} }
...@@ -159,7 +160,7 @@ window.addEventListener("load", function() { ...@@ -159,7 +160,7 @@ window.addEventListener("load", function() {
var result = JSON.parse(res) var result = JSON.parse(res)
// this.noticeContent = result.noticeContent // this.noticeContent = result.noticeContent
this.form = result.content[0] this.form = result.content[0]
this.form.filePathList = result.content[0].filePathList || [] this.filePathList = result.content[0].filePathList || []
if(this.form.workTime && this.form.workTime.length){ if(this.form.workTime && this.form.workTime.length){
this.form.startTime = this.form.workTime[0] this.form.startTime = this.form.workTime[0]
this.form.endTime = this.form.workTime[1] this.form.endTime = this.form.workTime[1]
...@@ -188,6 +189,7 @@ window.addEventListener("load", function() { ...@@ -188,6 +189,7 @@ window.addEventListener("load", function() {
} }
// this.form.companyId = this.companyId // this.form.companyId = this.companyId
this.form.workTime = [this.form.startTime, this.form.endTime] this.form.workTime = [this.form.startTime, this.form.endTime]
this.form.filePathList = this.filePathList
vant.Toast.loading({ vant.Toast.loading({
message: '正在处理...', message: '正在处理...',
forbidClick: true, forbidClick: true,
...@@ -205,9 +207,7 @@ window.addEventListener("load", function() { ...@@ -205,9 +207,7 @@ window.addEventListener("load", function() {
vant.Toast({ vant.Toast({
message: '操作成功', message: '操作成功',
}) })
if (!this.form.id) { // 添加时则 history.back()
location.reload()
}
} }
}) })
}, },
......
...@@ -54,31 +54,29 @@ ...@@ -54,31 +54,29 @@
<van-cell-group> <van-cell-group>
<van-field v-model="form.processDescription" :disabled="disabled" label="过程描述" placeholder="" /> <van-field v-model="form.processDescription" :disabled="disabled" label="过程描述" placeholder="" />
</van-cell-group> </van-cell-group>
<van-cell-group :class="{'disable-van-cell': true}" v-show="form.filePathList[0]"> <van-cell-group :class="{'disable-van-cell': true}" v-show="showWrapper">
<van-cell>文件预览: <van-cell>文件预览:
<div style="width: 6.5rem;"> <div style="width: 6.5rem;">
<van-image <van-image
v-show="(form.filePathList[0])"
width="100" width="100"
height="100" height="100"
:src="previewUrl+'/' + form.filePathList[0]" :src="previewUrl+'/' + filePathList[0]"
/> />
</div> </div>
<span v-show="form.filePathList[0] && !disabled" style="font-weight: bold; cursor: pointer;" @click="form.filePathList=[];fileList=[]"> 删除</span> <span v-show="!disabled" style="font-weight: bold; cursor: pointer;" @click="filePathList=[];fileList=[]"> 删除</span>
</van-cell> </van-cell>
</van-cell-group> </van-cell-group>
<van-cell-group :class="{'disable-van-cell': disabled}" v-show="!disabled">
<van-cell-group v-show="!form.filePathList[0]" :class="{'disable-van-cell': disabled}"> <van-cell>文件:<span style="color: red;">(限制大小2.5M以内,格式png/jpg/jpeg)</span>
<van-cell>文件:
<div style="width: 2.5rem;"> <div style="width: 2.5rem;">
<van-uploader v-model="fileList" <van-uploader v-model="fileList"
accept=".jpg,.jpeg,.png" accept=".jpg,.jpeg,.png"
:preview-image="false" :preview-image="false"
:before-upload="beforeUpload" :before-upload="beforeUpload"
:after-read="afterRead" :after-read="afterRead"
:before-read="beforeRead"
:max-count="1" :deletable="!disabled" :preview-full-image="false"> :max-count="1" :preview-full-image="false">
<van-button v-show="!form.filePathList.length" size="mini" icon="plus" type="primary">上传文件</van-button> <van-button size="mini" icon="plus" type="primary">上传文件</van-button>
</van-uploader> </van-uploader>
</div></van-cell> </div></van-cell>
</van-cell-group> </van-cell-group>
......
...@@ -7,6 +7,7 @@ window.addEventListener("load", function() { ...@@ -7,6 +7,7 @@ window.addEventListener("load", function() {
el: '#app', el: '#app',
data() { data() {
return { return {
previewUrl: BASE_URL,
form: { form: {
id: "", id: "",
planName: "", planName: "",
...@@ -15,24 +16,34 @@ window.addEventListener("load", function() { ...@@ -15,24 +16,34 @@ window.addEventListener("load", function() {
// 隐患描述 // 隐患描述
publishDeptName: "", publishDeptName: "",
publishDesc: "", publishDesc: "",
filePathList: [],
completionDate: "", completionDate: "",
issueDescription: "", issueDescription: "",
processDescription: "", processDescription: "",
}, },
filePathList: [],
// 整改日期模态框 // 整改日期模态框
completionDate: '', completionDate: '',
showPopup4completionDate: false, showPopup4completionDate: false,
// companyId: localStorage.getItem('companyId'), // companyId: localStorage.getItem('companyId'),
previewUrl: BASE_URL, // disabled: false,
disabled: false,
fileList: [], fileList: [],
} }
}, },
mounted() { mounted() {
this.detail() this.detail()
}, },
computed:{
showImage(){
return this.filePathList[0]
},
showWrapper(){
return this.filePathList[0]
},
disabled(){
return this.form.completionStatus === 1
}
},
methods: { methods: {
submit() { submit() {
if (!this.form.completionDate) { if (!this.form.completionDate) {
...@@ -53,63 +64,84 @@ window.addEventListener("load", function() { ...@@ -53,63 +64,84 @@ window.addEventListener("load", function() {
}) })
return; return;
} }
var reqParam = {
// companyId: localStorage.getItem('companyId'), vant.Toast.loading({
drillPhotoList: this.form.filePathList, message: '正在处理...',
planId: gemhoUtil.getParameter('planId'), forbidClick: true,
// planName: this.form.planName, loadingType: 'spinner',
processDescription: this.form.processDescription, });
issueDescription: this.form.issueDescription, http2.post({
completionDate: this.form.completionDate serviceId: API_KEY_MAP["emergency-add"]['id'],
} interfacePublicKey: API_KEY_MAP["emergency-add"]["publicKey"],
var url = "/api/enterpriseDrills" interfacePrivateKey: API_KEY_MAP["emergency-add"]["privateKey"],
reqParams: {
http.post(url, reqParam).then((res) => { drillPhotoList: this.filePathList,
console.log('添加结果', res) id: gemhoUtil.getParameter('planId'),
vant.Toast({ processDescription: this.form.processDescription,
message: '操作成功', issueDescription: this.form.issueDescription,
}) completionDate: this.form.completionDate
history.back() },
}, (res) => {
if(res){
console.log('添加结果', res)
vant.Toast({
message: '操作成功',
})
if (!this.form.id) { // 添加时则
location.reload()
}
}
}) })
}, },
// previewFile(){ // 预览图片和下载pdf文件(应急演练主要是图片展示)
// // var src = 'emergencydrill/e40eda16-7a86-4a2a-976b-892e17eeed49.pdf'
// // location.href = './pdfViewer.html?pdfSrc='+ src
// console.log(this.previewUrl + '/' + this.form.filePathList[0])
// location.href = this.previewUrl + '/' + this.form.filePathList[0]
// },
beforeUpload(file) { beforeUpload(file) {
console.log('beforeUpload',file) console.log('beforeUpload',file)
// 在文件上传之前的处理逻辑,例如校验文件大小、文件类型等 // 在文件上传之前的处理逻辑,例如校验文件大小、文件类型等
return true; // 返回 true 继续上传,返回 false 中止上传 return true; // 返回 true 继续上传,返回 false 中止上传
}, },
beforeRead(file) {
if (file.size > (2.5*1024*1024)) {
vant.Dialog.alert({
title: '信息提示',
message: '文件大小不可超过2.5M'
})
return false;
}
return true;
},
afterRead(file) { afterRead(file) {
// 获取文件流,调用网关中台接口,获取文件全路径url // 获取文件流,调用网关中台接口,获取文件全路径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.form.filePathList = data.body ? [data.body] : []
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
}, },
showPopup(popupType) { showPopup(popupType) {
if (!this.disabled) { if (!this.disabled) {
...@@ -122,19 +154,6 @@ window.addEventListener("load", function() { ...@@ -122,19 +154,6 @@ window.addEventListener("load", function() {
this.showPopup4completionDate = false this.showPopup4completionDate = false
}, },
// // 整改后照片
// transferUrl(hdRectificationPic) {
// console.log(hdRectificationPic);
// if (hdRectificationPic) {
// return (
// BASE_URL +
// "/hd_rectification_pic_to_verify" +
// hdRectificationPic.split("hd_rectification_pic_to_verify")[1]
// );
// } else {
// return null;
// }
// },
detail(){ detail(){
vant.Toast.loading({ vant.Toast.loading({
message: '加载中...', message: '加载中...',
...@@ -165,7 +184,7 @@ window.addEventListener("load", function() { ...@@ -165,7 +184,7 @@ window.addEventListener("load", function() {
}else{ }else{
this.disabled = false this.disabled = false
} }
this.form.filePathList = this.form.drillPhotoList || []; this.filePathList = this.form.drillPhotoList || [];
vant.Toast.clear() vant.Toast.clear()
} }
}) })
......
...@@ -20,56 +20,60 @@ window.addEventListener("load", function() { ...@@ -20,56 +20,60 @@ window.addEventListener("load", function() {
this.getList() this.getList()
}, },
methods: { methods: {
detail(item){ detail(item) {
gemhoUtil.navigatePage('./emergency-detail.html?planId='+item.id) gemhoUtil.navigatePage('./emergency-detail.html?planId=' + item.id)
}, },
resetSearchForm(){ resetSearchForm() {
this.page = 0 this.page = 0
this.size = 20 this.size = 20
this.total = 0 this.total = 0
this.list = [] this.list = []
this.finished = false; this.finished = false;
}, },
onClear(){ onClear() {
this.resetSearchForm() this.resetSearchForm()
this.getList() this.getList()
}, },
onSearch(val){ onSearch(val) {
this.resetSearchForm() this.resetSearchForm()
console.log('search', val) console.log('search', val)
this.getList() this.getList()
}, },
getList(){ getList() {
// if(this.loading){ // if(this.loading){
// return // return
// } // }
// this.loading = true // this.loading = true
setTimeout(() => { setTimeout(() => {
http2.post({ http2.post({
serviceId: API_KEY_MAP["emergency"]['id'], serviceId: API_KEY_MAP["emergency"]['id'],
interfacePublicKey: API_KEY_MAP["emergency"]["publicKey"], interfacePublicKey: API_KEY_MAP["emergency"][
interfacePrivateKey: API_KEY_MAP["emergency"]["privateKey"], "publicKey"
reqParams: { ],
page: this.page++,// 每次请求增加下一页 interfacePrivateKey: API_KEY_MAP["emergency"][
size: this.size, "privateKey"
planName: this.planName, ],
} reqParams: {
}, (res) => { page: this.page++, // 每次请求增加下一页
size: this.size,
if(res){ planName: this.planName,
console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res).body
this.loading = false; // 加载状态结束
this.list.push(...result.content);
this.total = result.totalElements
if(this.page*this.size >= this.total){
this.finished = true; // 下滑不在刷新数据
} }
} }, (res) => {
this.loading = false
}) if (res) {
console.log('接口回调数据', JSON.parse(res))
var result = JSON.parse(res).body
this.loading = false; // 加载状态结束
this.list.push(...result.content);
this.total = result.totalElements
if (this.page * this.size >= this.total) {
this.finished = true; // 下滑不在刷新数据
}
}
this.loading = false
})
}, 0) }, 0)
} }
}, },
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<body> <body>
<div id="app"> <div id="app">
<div class="content" v-cloak> <div class="content" v-cloak>
<van-list v-model:loading="loading" :offset="10" :finished="finished" finished-text="没有更多了" @load="getList" :immediate-check="false"> <van-list v-model:loading="loading" :offset="10" :finished="finished" finished-text="没有更多了" @load="getList"c>
<van-cell v-for="(item, index) in list" :key="item"> <van-cell v-for="(item, index) in list" :key="item">
<div class="list-item-wrapper" @click="detail(index)"> <div class="list-item-wrapper" @click="detail(index)">
<p class=""> <p class="">
......
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