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

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>
<view class="cu-tabbar-height"></view> <view class="cu-tabbar-height"></view>
</scroll-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"> <uni-drawer ref="showHiddenWindow" mode="right" :mask-click="true">
<scroll-view scroll-y="true" style="height: 100vh;"> <scroll-view scroll-y="true" style="height: 100vh;">
<view class="de-drawer"> <view class="de-drawer">
@ -46,8 +47,7 @@
</view> </view>
<view class="cu-form-group"> <view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub"> <view class="grid col-4 grid-square flex-sub">
<!-- 循环展示隐患图片因为只允许一张故使用v-if控制 --> <view class="bg-img" v-if="liveImgs.length > 0"
<view class="bg-img" v-if="liveImgs.length > 0" @tap="ViewImage"
:data-url="liveImgs[0].FILEPATH"> :data-url="liveImgs[0].FILEPATH">
<image :src="liveImgs[0].IMGFILES_ID ? (baseImgPath + liveImgs[0].FILEPATH) : liveImgs[0].FILEPATH" mode="aspectFill"></image> <image :src="liveImgs[0].IMGFILES_ID ? (baseImgPath + liveImgs[0].FILEPATH) : liveImgs[0].FILEPATH" mode="aspectFill"></image>
<!-- 删除图片按钮 --> <!-- 删除图片按钮 -->
@ -63,7 +63,7 @@
</view> </view>
</view> </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> <view class="title">签字</view>
<button class="cu-btn bg-green shadow" @tap="modalShow = true" data-target="Modal">手写签字</button> <button class="cu-btn bg-green shadow" @tap="modalShow = true" data-target="Modal">手写签字</button>
</view> </view>
@ -184,14 +184,58 @@
sizeType: ['original', 'compressed'], sizeType: ['original', 'compressed'],
sourceType: ['camera'], sourceType: ['camera'],
success: (res) => { success: (res) => {
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 = { let img = {
IMGFILES_ID: '', IMGFILES_ID: '',
FILEPATH: res.tempFilePaths[0] FILEPATH: res.tempFilePath // 使
}; };
_this.liveImgs = [img]; _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() { DelImg() {
var _this = this; var _this = this;
uni.showModal({ uni.showModal({
@ -229,18 +273,14 @@
}, },
submitMeetingAttendance(permissionID) { submitMeetingAttendance(permissionID) {
var _this = this; var _this = this;
if (this.liveImgs.length === 0 || this.signImgList.length === 0) { if (this.signImgList.length === 0) {
uni.showToast({ uni.showToast({
title: '请上传实时照片和签字图片', title: '请上传签字图片',
icon: 'none' icon: 'none'
}); });
return; return;
} }
this.permissionID = permissionID; this.permissionID = permissionID;
setTimeout(()=>{
this.$refs['authpup'].open();
},200)
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'gcj02',
geocode: true, 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}`; 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.longitude = res.longitude;
_this.latitude = res.latitude; _this.latitude = res.latitude;
// //
uni.showLoading({ const uploadTasks = [];
title: '提交中...' _this.signImgList.forEach(signImg => {
uploadTasks.push(_this.uploadFilePromise(signImg.filePath, 'signPhoto', locationAddress));
}); });
Promise.all(uploadTasks).then(() => {
uni.uploadFile({ //
url: basePath + '/app/safetymeeting/edit', uni.showToast({
filePath:_this.liveImgs[0].FILEPATH, title: '全部上传成功',
name: 'livePhoto', icon: 'success'
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(); _this.getData();
} else { _this.$refs.showHiddenWindow.close();
}).catch(error => {
uni.showToast({ uni.showToast({
title: '提交失败: ' + data.message, title: '上传出错: ' + error,
icon: 'none' icon: 'none'
}); });
}
},
fail: () => {
uni.showToast({
title: '上传失败',
icon: 'none'
});
},
complete: () => {
uni.hideLoading();
}
}); });
}, },
fail: function () { fail: function () {
@ -299,49 +317,75 @@
} }
}); });
}, },
uploadFilePromise(filePath, name, locationAddress) {
// return new Promise((resolve, reject) => {
formData(latitude, longitude) {
uni.showLoading({
title: '提交中...'
});
const livePhotoPath =baseImgPath + this.liveImgs[0].FILEPATH;
const signPhotoPath = this.signImgList[0].filePath;
uni.uploadFile({ uni.uploadFile({
url: basePath + '/app/safetymeeting/edit', url: basePath + '/app/safetymeeting/edit',
filePath: livePhotoPath, filePath: filePath,
name: 'livePhoto', name: name,
formData: { formData: {
SAFETY_MEETING_ID: this.SAFETY_MEETING_ID, SAFETY_MEETING_ID: this.SAFETY_MEETING_ID,
SIGNATUREPICTURE: this.SIGNATUREPICTURE,
ATTENDANCE_STATUS: '1', ATTENDANCE_STATUS: '1',
LATITUDE: this.latitude,
LONGITUDE: this.longitude,
LOCATIONADDRESS: locationAddress
}, },
success: uploadRes => { success: uploadRes => {
const data = JSON.parse(uploadRes.data); const data = JSON.parse(uploadRes.data);
uni.hideLoading();
if (data.result === 'success') { if (data.result === 'success') {
uni.showToast({ resolve(data);
title: '提交成功',
icon: 'success'
});
this.$refs.showHiddenWindow.close();
} else { } else {
uni.showToast({ reject(data.message);
title: '提交失败: ' + data.message,
icon: 'none'
});
} }
}, },
fail: () => { fail: () => {
uni.hideLoading(); reject('上传失败');
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() { addMeeting() {
if (this.$refs.showHiddenWindow) { if (this.$refs.showHiddenWindow) {
// //