安全例会优化->实时照片添加水印,实时照片和签字图片上传优化

dev
WenShiJun 2024-03-11 18:08:35 +08:00
parent 5be53f55b0
commit 081d0dab1d
1 changed files with 138 additions and 94 deletions

View File

@ -38,6 +38,7 @@
</view>
<view class="cu-tabbar-height"></view>
</scroll-view>
<canvas style="width: 300px; height: 150px; position: absolute; top: -9999px;" canvas-id="watermarkCanvas"></canvas>
<uni-drawer ref="showHiddenWindow" mode="right" :mask-click="true">
<scroll-view scroll-y="true" style="height: 100vh;">
<view class="de-drawer">
@ -46,8 +47,7 @@
</view>
<view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub">
<!-- 循环展示隐患图片因为只允许一张故使用v-if控制 -->
<view class="bg-img" v-if="liveImgs.length > 0" @tap="ViewImage"
<view class="bg-img" v-if="liveImgs.length > 0"
:data-url="liveImgs[0].FILEPATH">
<image :src="liveImgs[0].IMGFILES_ID ? (baseImgPath + liveImgs[0].FILEPATH) : liveImgs[0].FILEPATH" mode="aspectFill"></image>
<!-- 删除图片按钮 -->
@ -63,7 +63,7 @@
</view>
</view>
</view>
<view class="cu-form-group" style="border: none;" v-if="!forbidEdit">
<view class="cu-form-group" style="border: none;">
<view class="title">签字</view>
<button class="cu-btn bg-green shadow" @tap="modalShow = true" data-target="Modal">手写签字</button>
</view>
@ -184,14 +184,58 @@
sizeType: ['original', 'compressed'],
sourceType: ['camera'],
success: (res) => {
let img = {
IMGFILES_ID: '',
FILEPATH: res.tempFilePaths[0]
};
_this.liveImgs = [img];
const tempFilePath = res.tempFilePaths[0];
uni.getLocation({
type: 'gcj02',
geocode: true,
success: function (locationRes) {
const locationAddress = `${locationRes.address.province}${locationRes.address.city}${locationRes.address.district}${locationRes.address.street}${locationRes.address.streetNum}${locationRes.address.poiName}`;
//
const ctx = uni.createCanvasContext('watermarkCanvas', _this);
ctx.drawImage(tempFilePath, 0, 0, 300, 150); //
ctx.setFontSize(20); //
ctx.setFillStyle('red'); //
ctx.setFontSize(10); //
//
ctx.fillText(`用户名: ${loginUser.NAME}`, 10, 120); //
ctx.fillText(`当前位置: ${locationAddress}`, 10, 130); //
ctx.draw(false, () => {
//
uni.canvasToTempFilePath({
canvasId: 'watermarkCanvas',
success: function(res) {
let img = {
IMGFILES_ID: '',
FILEPATH: res.tempFilePath // 使
};
_this.liveImgs = [img];
_this.uploadFilePromise(img.FILEPATH, 'livePhoto', locationAddress)
.then(() => {
uni.showToast({
title: '实时照片上传成功',
icon: 'success'
});
}).catch(error => {
uni.showToast({
title: '实时照片上传失败: ' + error,
icon: 'none'
});
});
}
}, _this);
});
},
fail: function () {
uni.showToast({
title: '获取位置信息失败',
icon: 'none'
});
}
});
}
});
},
DelImg() {
var _this = this;
uni.showModal({
@ -229,18 +273,14 @@
},
submitMeetingAttendance(permissionID) {
var _this = this;
if (this.liveImgs.length === 0 || this.signImgList.length === 0) {
if (this.signImgList.length === 0) {
uni.showToast({
title: '请上传实时照片和签字图片',
title: '请上传签字图片',
icon: 'none'
});
return;
}
this.permissionID = permissionID;
setTimeout(()=>{
this.$refs['authpup'].open();
},200)
uni.getLocation({
type: 'gcj02',
geocode: true,
@ -248,47 +288,25 @@
const locationAddress = `${res.address.province}${res.address.city}${res.address.district}${res.address.street}${res.address.streetNum}${res.address.poiName}`;
_this.longitude = res.longitude;
_this.latitude = res.latitude;
//
uni.showLoading({
title: '提交中...'
//
const uploadTasks = [];
_this.signImgList.forEach(signImg => {
uploadTasks.push(_this.uploadFilePromise(signImg.filePath, 'signPhoto', locationAddress));
});
uni.uploadFile({
url: basePath + '/app/safetymeeting/edit',
filePath:_this.liveImgs[0].FILEPATH,
name: 'livePhoto',
formData: {
SAFETY_MEETING_ID: _this.SAFETY_MEETING_ID,
SIGNATUREPICTURE: _this.SIGNATUREPICTURE,
ATTENDANCE_STATUS: '1',
LATITUDE: _this.longitude, //
LONGITUDE: _this.latitude, //
LOCATIONADDRESS: locationAddress
},
success: uploadRes => {
//
const data = JSON.parse(uploadRes.data);
if (data.result === 'success') {
//
_this.$refs.showHiddenWindow.close();
//
_this.getData();
} else {
uni.showToast({
title: '提交失败: ' + data.message,
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '上传失败',
icon: 'none'
});
},
complete: () => {
uni.hideLoading();
}
Promise.all(uploadTasks).then(() => {
//
uni.showToast({
title: '全部上传成功',
icon: 'success'
});
//
_this.getData();
_this.$refs.showHiddenWindow.close();
}).catch(error => {
uni.showToast({
title: '上传出错: ' + error,
icon: 'none'
});
});
},
fail: function () {
@ -299,49 +317,75 @@
}
});
},
//
formData(latitude, longitude) {
uni.showLoading({
title: '提交中...'
});
const livePhotoPath =baseImgPath + this.liveImgs[0].FILEPATH;
const signPhotoPath = this.signImgList[0].filePath;
uni.uploadFile({
url: basePath + '/app/safetymeeting/edit',
filePath: livePhotoPath,
name: 'livePhoto',
formData: {
SAFETY_MEETING_ID: this.SAFETY_MEETING_ID,
SIGNATUREPICTURE: this.SIGNATUREPICTURE,
ATTENDANCE_STATUS: '1',
},
success: uploadRes => {
const data = JSON.parse(uploadRes.data);
uni.hideLoading();
if (data.result === 'success') {
uni.showToast({
title: '提交成功',
icon: 'success'
});
this.$refs.showHiddenWindow.close();
} else {
uni.showToast({
title: '提交失败: ' + data.message,
icon: 'none'
});
uploadFilePromise(filePath, name, locationAddress) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: basePath + '/app/safetymeeting/edit',
filePath: filePath,
name: name,
formData: {
SAFETY_MEETING_ID: this.SAFETY_MEETING_ID,
ATTENDANCE_STATUS: '1',
LATITUDE: this.latitude,
LONGITUDE: this.longitude,
LOCATIONADDRESS: locationAddress
},
success: uploadRes => {
const data = JSON.parse(uploadRes.data);
if (data.result === 'success') {
resolve(data);
} else {
reject(data.message);
}
},
fail: () => {
reject('上传失败');
}
},
fail: () => {
uni.hideLoading();
uni.showToast({
title: '上传失败',
icon: 'none'
});
}
});
});
},
//
// formData(latitude, longitude) {
// uni.showLoading({
// title: '...'
// });
// const livePhotoPath =baseImgPath + this.liveImgs[0].FILEPATH;
// const signPhotoPath = this.signImgList[0].filePath;
//
// uni.uploadFile({
// url: basePath + '/app/safetymeeting/edit',
// filePath: livePhotoPath,
// name: 'livePhoto',
// formData: {
// SAFETY_MEETING_ID: this.SAFETY_MEETING_ID,
// SIGNATUREPICTURE: this.SIGNATUREPICTURE,
// ATTENDANCE_STATUS: '1',
// },
// success: uploadRes => {
// const data = JSON.parse(uploadRes.data);
// uni.hideLoading();
// if (data.result === 'success') {
// uni.showToast({
// title: '',
// icon: 'success'
// });
// this.$refs.showHiddenWindow.close();
// } else {
// uni.showToast({
// title: ': ' + data.message,
// icon: 'none'
// });
// }
// },
// fail: () => {
// uni.hideLoading();
// uni.showToast({
// title: '',
// icon: 'none'
// });
// }
// });
// },
addMeeting() {
if (this.$refs.showHiddenWindow) {
//