直接运行手机,模拟器可以
<!-- 完整代码 -->
<template>
<view style="background-image: url(../../../static/img/bgimg.png);background-color: #FFFFFF;" :style="{ height: windowHeight+ 'px' }">
<cu-custom class="cu-custom" bgImage="../../../static/img/bg.png" :isBack="true" :isShow="false" :isMsg="true">
<block slot="backText"></block>
<block slot="content"></block>
</cu-custom>
<view class="cu-card article radius shadow-warp bg-white textCard azry">
<view class="cu-form-group textCont">
<view class='action text-bold'>
<text class='cuIcon-titles text-blue'></text>安装人员
</view>
</view>
</view>
<scroll-view :scroll-top="scrollTop" scroll-y="true" :style="{ height: scrollHeight+ 'px' }" @scrolltoupper="upper"
@scrolltolower="lower" @scroll="scroll">
<!-- 施工人员 -->
<view class="qmcls">
<view class="text-bold">安装人员(签字):
<!-- <xfl-select :list="array" :clearable="false" :showItemNum="5"
:isShow="false" :listShow="false" :isCanInput="false"
:style_Container="'height: 33px; font-size: 14px;width:150px;margin-left:10px;'"
placeholder="请选择" :selectHideType="'hideAll'"
:focusShowList="true" @pchange="change" @input="hidechange">
</xfl-select> -->
</view>
<view class="cu-list grid" style="display: flex;justify-content: start;margin-top: 10px;background-color:transparent;">
<view class="margin-bottom" style="width: 27%;margin-right: 1rem;text-align: center;border: none;" v-for="(tzitem ,index) in azQmList"
:key="index" v-if="index<gridCol*3">
<image class="image radius" style="width: 100%;height: 40px;border: 1px solid #CCCCCC;" :src="tzitem.url" />
</view>
<view class="margin-bottom" style="width: 27%;margin-right: 1rem;text-align: center;border: none;background-color:transparent;" @tap="qm(0)">
<image class="image radius" style="width: 100%;height: 40px;border: 1px solid #CCCCCC;" src="../../../static/img/qm.png" />
</view>
</view>
</view>
<view class="bg-white" style="background-color:transparent;">
<view class="cu-progress round margin-top xs">
<view style="width:100%"></view>
</view>
</view>
<!-- 业主人员 -->
<view class="qmcls">
<view class="text-bold">运检中心(签字):</view>
<view class="text-bold">经核实,以上安装人员符合要求</view>
<view class="cu-list grid" style="display: flex;justify-content: start;margin-top: 10px;background-color:transparent;">
<view class="margin-bottom" style="width: 27%;margin-right: 1rem;text-align: center;border: none;" v-for="(tzitem ,index) in yjQmList"
:key="index" v-if="index<gridCol*3">
<image class="image radius" style="width: 100%;height: 40px;border: 1px solid #CCCCCC;" :src="tzitem.url" />
</view>
<view v-if="yjQmList.length==0" class="margin-bottom" style="width: 27%;margin-right: 1rem;text-align: center;border: none;background-color:transparent;" @tap="qm(1)">
<image class="image radius" style="width: 100%;height: 40px;border: 1px solid #CCCCCC;" src="../../../static/img/qm.png" />
</view>
</view>
</view>
<view class="bg-white" style="background-color:transparent;">
<view class="cu-progress round margin-top xs">
<view style="width:100%"></view>
</view>
</view>
<!-- 监理人员 -->
<view class="qmcls">
<view class="text-bold">监理人员(签字):</view>
<view class="text-bold">全部安装工作均由以上人员按既定分工完成</view>
<view class="cu-list grid" style="display: flex;justify-content: start;margin-top: 10px;background-color:transparent;">
<view class="margin-bottom" style="width: 27%;margin-right: 1rem;text-align: center;border: none;" v-for="(tzitem ,index) in jlQmList"
:key="index" v-if="index<gridCol*3">
<image class="image radius" style="width: 100%;height: 40px;border: 1px solid #CCCCCC;" :src="tzitem.url" />
</view>
<view v-if="jlQmList.length==0" class="margin-bottom" style="width: 27%;margin-right: 1rem;text-align: center;border: none;background-color:transparent;" @tap="qm(2)">
<image class="image radius" style="width: 100%;height: 40px;border: 1px solid #CCCCCC;" src="../../../static/img/qm.png" />
</view>
</view>
</view>
<view style="text-align: right;margin-right: 1.2rem;">
<button class="cu-btn bg-green margin-tb-sm" @tap="editZt(2)">确定</button>
</view>
</scroll-view>
<view class="cu-modal bottom-modal radius" :class="modalName=='bottomModal'?'show':''">
<view class="cu-dialog bg-white">
<view class="cu-bar bg-white text-bold" style="margin: 0 auto;">
<text style="display: flex;justify-content: center;margin-left: 40%;">{{whoqm}}</text>
</view>
<view class="radius" style="height: 20rem;width: 90%;border: 2px solid #DDDDDD;margin: 0 auto;background-color: #F5F5F5;">
<canvas class='firstCanvas ' :class="{firstCanvasC:qmClasss}" canvas-id="firstCanvas" @touchmove='move'
@touchstart='start($event)' @touchend='end' @touchcancel='cancel' @longtap='tap' disable-scroll='true' @error='error'>
<view style="width: 100%;color: #DDDDDD;font-size: 100px;text-align: center;margin: 5rem auto;">{{qmmsg}}</view>
</canvas>
</view>
<view class="cu-bar bg-white">
<button class=" cu-btn text-green line-green shadow btncol" style="margin-left: 1.4rem;width: 40%;" @tap="qmCancle">取消</button>
<button class=" cu-btn bg-green shadow-blur btnbg" style="margin-right: 1.4rem;width: 40%;" @tap="saveQm">确定</button>
</view>
</view>
</view>
<uni-popup id="popupDialog" ref="popupDialog" type="dialog">
<uni-popup-dialog type="error" title="提示" :isShow="false" :content="msg" :before-close="true" @confirm="dialogConfirm"></uni-popup-dialog>
</uni-popup>
</view>
</template>
<script>
var content = null;
var touchs = [];
var canvasw = 0;
var canvash = 0;
import Util from '../../../static/js/util.js'
const url = Util.base_url();
export default {
components: {},
data() {
return {
array: [{
name: 1,
value: '张三'
}, {
name: 2,
value: '李四'
}, {
name: 3,
value: '欧阳王五'
}],
whoqm: '监理签名确认',
qmmsg: '签名',
whoqmzt: 3,
qmClasss: false,
gridCol: 3,
signImage: '',
modalName: null,
azQmList: [],
yjQmList: [],
jlQmList: [],
msg: '',
objid: "",
windowHeight: 0, //实时屏幕高度
scrollHeight:0,
sgdwinfo: {},
userData: {},
swid: '',
scrollTop: 0,
old: {
scrollTop: 0
},
obj:null,
msg:'',
}
},
onReady() {
let _this = this;
uni.getSystemInfo({
//获取设备信息
success(res) {
_this.windowHeight = res.windowHeight;
let query = uni.createSelectorQuery();
query.select('.cu-custom').boundingClientRect();
query.select('.azry').boundingClientRect();
query.exec(res => {
let bgcHeight = res[0].height;
let azryHeight = res[1].height;
_this.scrollHeight = _this.windowHeight - bgcHeight - azryHeight - 10;
});
}
});
},
onLoad(option) {
//获得Canvas的上下文
content = uni.createCanvasContext('firstCanvas')
//设置线的颜色
content.setStrokeStyle("#000")
//设置线的宽度
content.setLineWidth(5)
//设置线两端端点样式更加圆润
content.setLineCap('round')
//设置两条线连接处更加圆润
content.setLineJoin('round')
this.userData = Util.getuserinfo("userInfo");
const item = JSON.parse(decodeURIComponent(option.param));
this.objid = item.objid;
this.obj = item.obj;
console.log("获取工程信息id: " + JSON.stringify(item));
this.gcxxinfo();
},
methods: {
editZt(zt){
let param = {
objid: this.obj.obj_id,
zt:zt,
navBarWho:1
}
this.$myRequest({
method: 'POST',
url: 'wlxx/editZt',
data: param
}).then(res => {
var pages = getCurrentPages();
let prevPage = pages[pages.length - 2]; //上一页页面实例
prevPage.$vm.getwlxxinfo();
uni.navigateBack({
delta: 1
});
}).catch(error => {
console.log(error);
});
},
change(tt) {
console.log(JSON.stringify(tt.orignItem))
},
hidechange(e){},
upper: function(e) {},
lower: function(e) {},
scroll: function(e) {
this.old.scrollTop = e.detail.scrollTop
},
gcxxinfo() {
let param = {
objid: this.obj.swidbm,
fjhz:'azry,yjry,jlry'
}
this.$myRequest({
method: 'POST',
url: 'gcxx/getQmListById',
data: param
}).then(res => {
let qmList = res.data.anList;
qmList.forEach((value) => {
if(value.glid==this.obj.swidbm+"azry"){
this.azQmList.push(value);
}
if(value.glid==this.obj.swidbm+"yjry"){
this.yjQmList.push(value);
}
if(value.glid==this.obj.swidbm+"jlry"){
this.jlQmList.push(value);
}
});
}).catch(error => {
console.log(error);
});
},
qm(qmWho) {
if (qmWho == 0) {
this.whoqm = '安装人员签字';
this.whoqmzt = 0;
}
if (qmWho == 1) {
this.whoqm = '运维检修中心签字';
this.whoqmzt = 1;
}
if (qmWho == 2) {
this.whoqm = '监理人员签字';
this.whoqmzt = 2;
}
this.modalName = "bottomModal";
},
qmCancle() {
this.modalName = null;
this.qmmsg = '签名';
this.qmClasss = true;
//重置签名
var context = uni.createCanvasContext('firstCanvas');
context.stroke()
context.draw()
},
dialogConfirm(done) {
this.$refs.popupDialog.close();
},
saveQm() {
var that = this
that.signImage = "";
uni.canvasToTempFilePath({
canvasId: 'firstCanvas',
success: function(res) {
//设置保存的图片
uni.showToast({
title: '测试签名'
})
that.signImage = res.tempFilePath
var qmImg = {
url: that.signImage
}
return
var qmbq = '';
if (that.whoqmzt == 0) {
qmbq = 'azry';
that.azQmList.push(qmImg);
}
if (that.whoqmzt == 1) {
qmbq = 'yjry';
that.yjQmList.push(qmImg);
}
if (that.whoqmzt == 2) {
qmbq = 'jlry';
that.jlQmList.push(qmImg);
}
that.msg = url + 'fileController/upload'
uni.uploadFile({
url: url + 'fileController/upload',
filePath: res.tempFilePath,
name: 'file',
formData: {
'glId': that.obj.swidbm + qmbq
},
success: (uploadFileRes) => {
let swids = [that.obj.swidbm];
that.modalName = null;
if (that.whoqmzt == 3) {
that.gcxxinfo();
that.$myRequest({
method: 'POST',
url: 'sggl/finish',
data: swids
}).then(res => {
that.modalName = null;
uni.showToast({
title: '确认成功'
})
}).catch(error => {
console.log(error);
});
}
that.qmCancle();
},
fail: (ev) => {
uni.showToast({
title: '失败'+ev
})
},
});
}
})
},
// 画布的触摸移动开始手势响应
start: function(e) {
this.qmmsg = '';
//获取触摸开始的 x,y
let point = {
x: e.touches[0].x,
y: e.touches[0].y,
}
touchs.push(point);
},
// 画布的触摸移动手势响应
move: function(e) {
let point = {
x: e.touches[0].x,
y: e.touches[0].y
}
touchs.push(point)
if (touchs.length >= 2) {
this.draw(touchs)
}
},
// 画布的触摸移动结束手势响应
end: function(e) {
//清空轨迹数组
for (let i = 0; i < touchs.length; i++) {
touchs.pop()
}
},
// 画布的触摸取消响应
cancel: function(e) {
console.log("触摸取消" + e)
},
// 画布的长按手势响应
tap: function(e) {
console.log("长按手势" + e)
},
error: function(e) {
console.log("画布触摸错误" + e)
},
//绘制
draw: function(touchs) {
console.log(111111)
let point1 = touchs[0]
let point2 = touchs[1]
touchs.shift()
content.moveTo(point1.x, point1.y)
content.lineTo(point2.x, point2.y)
content.stroke()
content.draw(false, setTimeout(()=>{
console.log(3)
},300))
// content.draw(true)
},
},
}
</script>
<style>
.qmcls{
width: 100%;
margin-left: 1rem;
margin-top: 1rem;
background-color:transparent;
}
.firstCanvas {
background-color: #F5F5F5;
width: 100%;
height: 100vh;
}
.firstCanvasC {
background-color: #F5F5F5;
width: 100%;
height: 99.9%;
}
</style>
1 个回复
3***@qq.com (作者)
<!-- 完整代码 -->
<template>
<view style="background-image: url(../../../static/img/bgimg.png);background-color: #FFFFFF;" :style="{ height: windowHeight+ 'px' }">
<cu-custom class="cu-custom" bgImage="../../../static/img/bg.png" :isBack="true" :isShow="false" :isMsg="true">
<block slot="backText"></block>
<block slot="content"></block>
</cu-custom>
</template>
<script>
var content = null;
var touchs = [];
var canvasw = 0;
var canvash = 0;
import Util from '../../../static/js/util.js'
const url = Util.base_url();
export default {
components: {},
data() {
return {
array: [{
name: 1,
value: '张三'
}, {
name: 2,
value: '李四'
}, {
name: 3,
value: '欧阳王五'
}],
whoqm: '监理签名确认',
qmmsg: '签名',
whoqmzt: 3,
qmClasss: false,
gridCol: 3,
signImage: '',
modalName: null,
azQmList: [],
yjQmList: [],
jlQmList: [],
msg: '',
objid: "",
windowHeight: 0, //实时屏幕高度
scrollHeight:0,
sgdwinfo: {},
userData: {},
swid: '',
scrollTop: 0,
old: {
scrollTop: 0
},
obj:null,
msg:'',
}
},
onReady() {
let _this = this;
uni.getSystemInfo({
//获取设备信息
success(res) {
_this.windowHeight = res.windowHeight;
let query = uni.createSelectorQuery();
query.select('.cu-custom').boundingClientRect();
query.select('.azry').boundingClientRect();
query.exec(res => {
let bgcHeight = res[0].height;
let azryHeight = res[1].height;
_this.scrollHeight = _this.windowHeight - bgcHeight - azryHeight - 10;
});
}
});
},
onLoad(option) {
//获得Canvas的上下文
content = uni.createCanvasContext('firstCanvas')
//设置线的颜色
content.setStrokeStyle("#000")
//设置线的宽度
content.setLineWidth(5)
//设置线两端端点样式更加圆润
content.setLineCap('round')
//设置两条线连接处更加圆润
content.setLineJoin('round')
</script>
<style>
.qmcls{
width: 100%;
margin-left: 1rem;
margin-top: 1rem;
background-color:transparent;
}
.firstCanvas {
background-color: #F5F5F5;
width: 100%;
height: 100vh;
}
</style>