会议室预约添加时间被占用的提醒以及修改下载pdf的功能

This commit is contained in:
Leo_Ding 2025-09-10 10:32:29 +08:00
parent 092c32a56d
commit 554c35e9c5
7 changed files with 432 additions and 48 deletions

View File

@ -13,7 +13,7 @@
</view> </view>
</view> </view>
</view> </view>
<text class="note">电子印章必须为透明底的PNG格式其他格式将不被接受</text> <!-- <text class="note">电子印章必须为透明底的PNG格式其他格式将不被接受</text> -->
</view> </view>
</template> </template>

View File

@ -0,0 +1,192 @@
<script>
import { BASE_URL, IMAGE_BASE_URL } from '@/utils/config';
export default {
data() {
return {
imagePath: '',
processedImage: '',
isCanvasReady: false,
ctx: null // canvas
}
},
mounted() {
// canvas
this.$nextTick(() => {
setTimeout(() => {
this.ctx = uni.createCanvasContext('myCanvas', this);
console.log('Canvas上下文初始化完成');
}, 100);
});
},
methods: {
//
uploadImage() {
const that = this;
uni.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success: function(res) {
that.imagePath = res.tempFilePaths[0];
that.drawImageToCanvas();
}
});
},
// Canvas
drawImageToCanvas() {
const that = this;
// ctx
if (!this.ctx) {
this.ctx = uni.createCanvasContext('myCanvas', this);
}
// Canvas
this.ctx.clearRect(0, 0, 300, 300);
//
uni.getImageInfo({
src: that.imagePath,
success: function(res) {
that.ctx.drawImage(res.path, 0, 0, 300, 300);
that.ctx.draw(true, () => {
console.log('图片绘制完成');
that.isCanvasReady = true;
// Canvas
setTimeout(() => {
uni.showToast({
title: '图片已加载,可以处理',
icon: 'success'
});
}, 200);
});
},
fail: function(err) {
console.error('获取图片信息失败', err);
}
});
},
//
processImage() {
if (!this.isCanvasReady) {
uni.showToast({
title: '请先上传图片',
icon: 'none'
});
return;
}
const that = this;
uni.showLoading({
title: '处理中...',
mask: true
});
// Canvas
setTimeout(() => {
// Canvas
uni.canvasGetImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: 300,
height: 300,
success: function(res) {
const data = res.data;
//
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
//
if (r > 200 && g > 200 && b > 200) {
data[i + 3] = 0; // Alpha0
}
}
// Canvas
uni.canvasPutImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: 300,
height: 300,
data: data,
success: function() {
// Canvas
that.canvasToImage();
},
fail: function(err) {
uni.hideLoading();
console.error('像素数据放回失败', err);
}
});
},
fail: function(err) {
uni.hideLoading();
console.error('获取像素数据失败', err);
// canvas
that.checkCanvasStatus();
}
});
}, 500); // 500ms
},
// Canvas
checkCanvasStatus() {
const query = uni.createSelectorQuery().in(this);
query.select('#myCanvas')
.boundingClientRect()
.exec((res) => {
if (res[0]) {
console.log('Canvas元素信息:', res[0]);
} else {
console.log('Canvas元素未找到');
}
});
},
// Canvas
canvasToImage() {
const that = this;
//
setTimeout(() => {
uni.canvasToTempFilePath({
canvasId: 'myCanvas',
success: function(res) {
that.processedImage = res.tempFilePath;
uni.hideLoading();
console.log("处理后的图片路径:", res.tempFilePath);
//
that.$emit('image-processed', res.tempFilePath);
},
fail: function(err) {
uni.hideLoading();
console.error('Canvas转换失败', err);
}
});
}, 300);
},
//
reinitializeCanvas() {
this.ctx = null;
this.isCanvasReady = false;
this.$nextTick(() => {
setTimeout(() => {
this.ctx = uni.createCanvasContext('myCanvas', this);
console.log('Canvas重新初始化完成');
}, 100);
});
}
}
}
</script>

165
pages/ceshi/index.vue Normal file
View File

@ -0,0 +1,165 @@
<template>
<view class="container">
<canvas canvas-id="myCanvas" style="width: 300px; height: 300px;"></canvas>
<button @tap="uploadImage">上传印章图片</button>
<button @tap="processImage" v-if="imagePath">处理图片</button>
<image :src="processedImage" v-if="processedImage" mode="widthFix"></image>
</view>
</template>
<script>
import { BASE_URL,IMAGE_BASE_URL } from '@/utils/config';
export default {
data() {
return {
imagePath: '',
processedImage: ''
}
},
methods: {
//
uploadImage() {
const that = this;
uni.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success: function (res) {
that.imagePath = res.tempFilePaths[0];
that.drawImageToCanvas();
}
});
},
// Canvas
drawImageToCanvas() {
const that = this;
const ctx = uni.createCanvasContext('myCanvas', this);
// Canvas
ctx.clearRect(0, 0, 300, 300);
//
uni.getImageInfo({
src: that.imagePath,
success: function (res) {
ctx.drawImage(res.path, 0, 0, 300, 300);
ctx.draw(false, () => {
console.log('图片绘制完成');
});
}
});
},
//
processImage() {
const that = this;
const ctx = uni.createCanvasContext('myCanvas', this);
// Canvas
uni.canvasGetImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: 300,
height: 300,
success: function(res) {
const data = res.data;
//
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
//
if (r > 200 && g > 200 && b > 200) {
data[i + 3] = 0; // Alpha0
}
}
// Canvas
uni.canvasPutImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: 300,
height: 300,
data: data,
success: function() {
// Canvas
that.canvasToImage();
}
});
}
});
},
// Canvas
canvasToImage() {
const that = this;
uni.canvasToTempFilePath({
canvasId: 'myCanvas',
success: function(res) {
that.processedImage = res.tempFilePath;
const fileList = [{
url: res.tempFilePath,
status: 'uploading'
}];
console.log("==fileList",fileList)
// 4.
that.uploadFile(fileList[0]);
//
console.log('处理后的图片路径:', res.tempFilePath);
},
fail: function(err) {
console.error('Canvas转换失败', err);
}
});
},
async uploadFile(file) {
try {
await new Promise((resolve, reject) => {
uni.uploadFile({
url: `${IMAGE_BASE_URL}/api/v1/upload`,
filePath: file.url,
name: 'file',
header: {
'Authorization': `Bearer ${uni.getStorageSync('token')}`,
'Content-Type': 'multipart/form-data'
},
success: (uploadRes) => {
try {
const data = JSON.parse(uploadRes.data);
if (data.success) {
resolve(data.data);
} else {
reject(data.message || '上传失败');
}
} catch (e) {
reject('解析响应失败');
}
},
fail: (err) => reject(err)
});
});
} catch (err) {
console.error('上传失败:', err);
const index = this.fileList.findIndex(f => f.url === file.url);
if (index !== -1) {
this.$set(this.fileList, index, {
...file,
status: 'failed',
error: err.message || err
});
}
uni.showToast({
title: `上传失败: ${err.message || err}`,
icon: 'none'
});
throw err;
}
},
}
}
</script>

View File

@ -3,60 +3,77 @@
<view class="doc-content"> <view class="doc-content">
<view class="doc-file" v-for="item of docList" @click="downLoadFile(item)"> <view class="doc-file" v-for="item of docList" @click="downLoadFile(item)">
<image src="/static/imgs/word.png" alt="" srcset="" class="doc-img"/> <image src="/static/imgs/PDF.png" alt="" srcset="" class="doc-img" />
<view class="doc-name">{{item.name}}</view> <view class="doc-name">{{item.name}}</view>
</view> </view>
<view style="margin-top: 20px;"> <view style="margin-top: 20px;">
<u-button shape="circle" type="primary" @click="reback()" >返回</u-button> <u-button shape="circle" type="primary" @click="reback()">返回</u-button>
</view> </view>
</view> </view>
<u-modal :show="show" title="提示" @confirm="show=false"> <u-modal :show="show" title="提示" @confirm="show=false">
<view>预约完成请致电社区并关注预约记录留意审核状态谢谢</view> <view>
<view style="padding: 5px;font-size: 16px;line-height: 23px;">
预约完成请致电社区并关注预约记录留意审核状态谢谢
</view>
<view v-if="warnMsg" style="line-height: 21px;font-size: 14px;border-radius: 5px; padding: 5px;background: #ffac31;color: #ffffff;">{{warnMsg}}</view>
</view>
</u-modal> </u-modal>
</view> </view>
</template> </template>
<script> <script>
import {IMAGE_BASE_URL,BASE_URL} from '@/utils/config'; import {
import {downloadPdfFiles} from '@/utils/download.js' IMAGE_BASE_URL,
export default{ BASE_URL
data(){ } from '@/utils/config';
return{ import {
docList:[], downloadPdfFiles
content:'预约完成,请致电社区,并关注预约记录留意审核状态,谢谢!', } from '@/utils/download.js'
show:false, export default {
nameList:{ data() {
'applyPdf':'申请表申请表申请表申请表申请表申请表申请表申请表申请表申请表', return {
'covenantPdf':'协议书' docList: [],
content: '预约完成,请致电社区,并关注预约记录留意审核状态,谢谢!',
show: false,
warnMsg: '',
nameList: {
'applyPdf': '申请表申请表申请表申请表申请表申请表申请表申请表申请表申请表',
'covenantPdf': '协议书'
} }
} }
}, },
onLoad(option) { onLoad(option) {
this.show=true this.show = true
const obj=JSON.parse(option.files) const obj = JSON.parse(option.files)
this.docList=[ this.warnMsg = obj.warnMsg
{name:obj.applyPdfName,url:BASE_URL+obj.covenantPdf}, this.docList = [{
{name:obj.covenantPdfName,url:BASE_URL+obj.applyPdf}, name: obj.applyPdfName,
url: BASE_URL + obj.covenantPdf
},
{
name: obj.covenantPdfName,
url: BASE_URL + obj.applyPdf
},
] ]
}, },
methods:{ methods: {
handleBack() { handleBack() {
// //
uni.redirectTo({ uni.redirectTo({
url: `/pages/meetingList/index` url: `/pages/meetingList/index`
}) })
}, },
async downLoadFile(fileUrl){ async downLoadFile(fileUrl) {
const result = await downloadPdfFiles(fileUrl); const result = await downloadPdfFiles(fileUrl);
if(result.success==true){ if (result.success == true) {
// uni.navigateTo({ // uni.navigateTo({
// url: `/pages/meetingList/index` // url: `/pages/meetingList/index`
// }); // });
} }
}, },
reback(){ reback() {
uni.reLaunch({ uni.reLaunch({
url: `/pages/meetingList/index` url: `/pages/meetingList/index`
}) })
} }
} }
@ -64,35 +81,42 @@
</script> </script>
<style scoped> <style scoped>
.doc-page{ .doc-page {
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
/* margin: 10rpx; */ /* margin: 10rpx; */
} }
.doc-content{
.doc-content {
margin: 10px; margin: 10px;
} }
.doc-file{
.doc-file {
padding: 20rpx 10rpx; padding: 20rpx 10rpx;
display: flex; display: flex;
align-items: center; align-items: center;
/* margin: 10px; */ /* margin: 10px; */
/* border-bottom: 1px solid #c9c9c9; */ /* border-bottom: 1px solid #c9c9c9; */
} }
.doc-file:not(:last-child){
.doc-file:not(:last-child) {
border-bottom: 1px solid #c9c9c9; border-bottom: 1px solid #c9c9c9;
} }
.doc-img{
width: 35px; .doc-img {
height: 35px; width: 25px;
height: 28px;
} }
.doc-name{
.doc-name {
padding: 0 5px;
flex: 1; flex: 1;
color: #666666; color: #666666;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
.nav-bar { .nav-bar {
display: flex; display: flex;
align-items: center; align-items: center;
@ -101,13 +125,13 @@
border-bottom: 1px solid #f5f5f5; border-bottom: 1px solid #f5f5f5;
margin-top: 84rpx; margin-top: 84rpx;
} }
.nav-left { .nav-left {
display: flex; display: flex;
align-items: center; align-items: center;
margin-right: 10px; margin-right: 10px;
} }
.nav-title { .nav-title {
flex: 1; flex: 1;
text-align: center; text-align: center;

View File

@ -229,9 +229,12 @@
} from '@/utils/dict.js' } from '@/utils/dict.js'
import gxsign from '../../components/sign/sign.vue'; import gxsign from '../../components/sign/sign.vue';
import gxUpload from '../../components/gx-upload.vue'; import gxUpload from '../../components/gx-upload.vue';
// import processImage from '../../components/process-image.vue'
import instructionVue from '../../components/instruction.vue'; import instructionVue from '../../components/instruction.vue';
export default { export default {
components: { components: {
// processImage,
instructionVue, instructionVue,
gxUpload, gxUpload,
gxsign gxsign
@ -631,7 +634,7 @@
endTime: this.endTime, endTime: this.endTime,
counter: this.counter, counter: this.counter,
num: this.num, num: this.num,
applyType:1 applyType:this.applyType
} }
await this.validateObject(userApplyInfo, this.applyRules) await this.validateObject(userApplyInfo, this.applyRules)
const applyInfo = Object.assign(bookingInfo, userApplyInfo) const applyInfo = Object.assign(bookingInfo, userApplyInfo)
@ -656,7 +659,7 @@
counter: this.counter, counter: this.counter,
num: this.num, num: this.num,
stampUrl: this.stampUrl, stampUrl: this.stampUrl,
applyType:2 applyType:this.applyType
} }
await this.validateObject(userApplyInfo, this.applyRules) await this.validateObject(userApplyInfo, this.applyRules)
const app = getApp() const app = getApp()

BIN
static/imgs/PDF.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -51,7 +51,7 @@ export const downloadPdfFiles = (file, showLoading = true) => {
// 下载完成后自动打开 // 下载完成后自动打开
wx.openDocument({ wx.openDocument({
filePath: res.tempFilePath, filePath: res.tempFilePath,
fileType: 'docx', fileType: 'pdf',
showMenu: true,// 显示Android分享菜单 showMenu: true,// 显示Android分享菜单
success: () => { success: () => {
console.log(`${file.name} 打开成功`); console.log(`${file.name} 打开成功`);