This commit is contained in:
sunmeng 2025-05-08 18:17:51 +08:00
parent 5664bfdfda
commit c4179dae9d
4 changed files with 103 additions and 74 deletions

View File

@ -38,45 +38,55 @@
const startY = ref(0)
const isDragging = ref(false)
const imgUrl = ref('https://assets.sx25.troyrc.com/sx25/images/events/XBDT.jpg'); // ref
async function draw() {
const ctx = uni.createCanvasContext('canvas', instance);
ctx.save(); //
ctx.translate(offsetX.value, offsetY.value); //
ctx.scale(scale.value, scale.value); //
const res = await uni.getImageInfo({ src: imgUrl.value });
ctx.drawImage(res.path, 0, 0); //
ctx.restore(); //
ctx.draw();
}
async function draw() {
const ctx = uni.createCanvasContext('canvas', instance) // canvas
ctx.scale(scale.value, scale.value);
const res = await uni.getImageInfo({
src: imgUrl.value,
})
ctx.drawImage(res.path, 0, 0);
// async function draw() {
// const ctx = uni.createCanvasContext('canvas', instance) // canvas
// ctx.scale(scale.value, scale.value);
// const res = await uni.getImageInfo({
// src: imgUrl.value,
// })
// ctx.drawImage(res.path, 0, 0);
// ctx.beginPath();
// ctx.moveTo(50, 50); //
// ctx.lineTo(150, 50); //
// ctx.lineTo(200, 100); //
// ctx.lineTo(100, 100); //
// ctx.closePath(); //
// ctx.stroke(); //
// // ctx.beginPath();
// // ctx.moveTo(50, 50); //
// // ctx.lineTo(150, 50); //
// // ctx.lineTo(200, 100); //
// // ctx.lineTo(100, 100); //
// // ctx.closePath(); //
// // ctx.stroke(); //
//
// let xoffset = 0, yoffset = 0, flag = false;
// polygonList.forEach((level, index) => {
// // console.log('level',level)
// ctx.moveTo(level.polygon[0] + xoffset, level.polygon[0] + yoffset)
// level.polygon.forEach((level2,level2Index)=>{
// ctx.beginPath()
// if(level2Index != level.polygon.length ){
// ctx.lineTo(level2 + xoffset, level.polygon[level2Index+1])
// console.log(level2 + xoffset, level.polygon[level2Index+1])
// }else{
// ctx.lineTo(level2 + xoffset, level.polygon[0])
// console.log(level2 + xoffset, level.polygon[0])
// }
// ctx.closePath()
// })
// if(polygonList.length == index){
// flag = true
// }
// })
ctx.draw()
}
// //
// // let xoffset = 0, yoffset = 0, flag = false;
// // polygonList.forEach((level, index) => {
// // // console.log('level',level)
// // ctx.moveTo(level.polygon[0] + xoffset, level.polygon[0] + yoffset)
// // level.polygon.forEach((level2,level2Index)=>{
// // ctx.beginPath()
// // if(level2Index != level.polygon.length ){
// // ctx.lineTo(level2 + xoffset, level.polygon[level2Index+1])
// // console.log(level2 + xoffset, level.polygon[level2Index+1])
// // }else{
// // ctx.lineTo(level2 + xoffset, level.polygon[0])
// // console.log(level2 + xoffset, level.polygon[0])
// // }
// // ctx.closePath()
// // })
// // if(polygonList.length == index){
// // flag = true
// // }
// // })
// ctx.draw()
// }
// canvas
function handleCanvasTouch(event) {
@ -108,28 +118,49 @@
//
const handleTouchMove = (e) => {
console.log('handleTouchMove')
if (e.touches.length === 1 && isDragging.value) {
//
const currentX = e.touches[0].clientX - startX.value
const currentY = e.touches[0].clientY - startY.value
offsetX.value = currentX
offsetY.value = currentY
// ...
offsetX.value = e.touches[0].clientX - startX.value;
offsetY.value = e.touches[0].clientY - startY.value;
} else if (e.touches.length === 2) {
//
const x1 = e.touches[0].clientX
const y1 = e.touches[0].clientY
const x2 = e.touches[1].clientX
const y2 = e.touches[1].clientY
const distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2))
// ...
const x1 = e.touches[0].clientX, y1 = e.touches[0].clientY;
const x2 = e.touches[1].clientX, y2 = e.touches[1].clientY;
const distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
if (lastDistance.value > 0) {
const newScale = scale.value * (distance / lastDistance.value)
scale.value = Math.min(Math.max(newScale, 0.5), 4) //
scale.value = Math.min(Math.max(scale.value * (distance / lastDistance.value), 0.5), 4);
draw(); // Canvas
}
lastDistance.value = distance
lastDistance.value = distance;
}
}
};
// const handleTouchMove = (e) => {
// console.log('handleTouchMove')
// if (e.touches.length === 1 && isDragging.value) {
// //
// const currentX = e.touches[0].clientX - startX.value
// const currentY = e.touches[0].clientY - startY.value
// offsetX.value = currentX
// offsetY.value = currentY
// } else if (e.touches.length === 2) {
// uni.showToast({
// title:''
// })
// //
// const x1 = e.touches[0].clientX
// const y1 = e.touches[0].clientY
// const x2 = e.touches[1].clientX
// const y2 = e.touches[1].clientY
// const distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2))
// if (lastDistance.value > 0) {
// const newScale = scale.value * (distance / lastDistance.value)
// scale.value = Math.min(Math.max(newScale, 0.5), 4) //
// }
// lastDistance.value = distance
// }
// }
//
const handleTouchEnd = () => {
@ -156,7 +187,9 @@
success: function (sres) {
console.log(sres,'sres');
imgUrl.value = sres.tempFilePath || sres.path
draw()
// setInterval(()=>{
draw()
// },16)
},fail:function(fres){
console.log('fres',fres)
}

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}

View File

@ -6789,7 +6789,7 @@ function initOnError() {
function initRuntimeSocketService() {
const hosts = "127.0.0.1,172.10.0.117";
const port = "8090";
const id = "mp-weixin_c9b8fP";
const id = "mp-weixin_VFGAao";
const lazy = typeof swan !== "undefined";
let restoreError = lazy ? () => {
} : initOnError();

View File

@ -16,15 +16,16 @@ const _sfc_main = {
const imgUrl = common_vendor.ref("https://assets.sx25.troyrc.com/sx25/images/events/XBDT.jpg");
async function draw() {
const ctx = common_vendor.index.createCanvasContext("canvas", instance);
ctx.save();
ctx.translate(offsetX.value, offsetY.value);
ctx.scale(scale.value, scale.value);
const res = await common_vendor.index.getImageInfo({
src: imgUrl.value
});
const res = await common_vendor.index.getImageInfo({ src: imgUrl.value });
ctx.drawImage(res.path, 0, 0);
ctx.restore();
ctx.draw();
}
const handleTouchStart = (e) => {
common_vendor.index.__f__("log", "at pages/index/index.vue:93", "handleTouchStart");
common_vendor.index.__f__("log", "at pages/index/index.vue:103", "handleTouchStart");
if (e.touches.length === 1) {
startX.value = e.touches[0].clientX - offsetX.value;
startY.value = e.touches[0].clientY - offsetY.value;
@ -38,27 +39,22 @@ const _sfc_main = {
}
};
const handleTouchMove = (e) => {
common_vendor.index.__f__("log", "at pages/index/index.vue:111", "handleTouchMove");
if (e.touches.length === 1 && isDragging.value) {
const currentX = e.touches[0].clientX - startX.value;
const currentY = e.touches[0].clientY - startY.value;
offsetX.value = currentX;
offsetY.value = currentY;
offsetX.value = e.touches[0].clientX - startX.value;
offsetY.value = e.touches[0].clientY - startY.value;
} else if (e.touches.length === 2) {
const x1 = e.touches[0].clientX;
const y1 = e.touches[0].clientY;
const x2 = e.touches[1].clientX;
const y2 = e.touches[1].clientY;
const x1 = e.touches[0].clientX, y1 = e.touches[0].clientY;
const x2 = e.touches[1].clientX, y2 = e.touches[1].clientY;
const distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
if (lastDistance.value > 0) {
const newScale = scale.value * (distance / lastDistance.value);
scale.value = Math.min(Math.max(newScale, 0.5), 4);
scale.value = Math.min(Math.max(scale.value * (distance / lastDistance.value), 0.5), 4);
draw();
}
lastDistance.value = distance;
}
};
const handleTouchEnd = () => {
common_vendor.index.__f__("log", "at pages/index/index.vue:136", "handleTouchEnd");
common_vendor.index.__f__("log", "at pages/index/index.vue:167", "handleTouchEnd");
lastDistance.value = -1;
isDragging.value = false;
};
@ -66,16 +62,16 @@ const _sfc_main = {
draw();
};
common_vendor.onReady(() => {
common_vendor.index.__f__("log", "at pages/index/index.vue:153", "onReadyonReady");
common_vendor.index.__f__("log", "at pages/index/index.vue:184", "onReadyonReady");
common_vendor.index.downloadFile({
url: imgUrl.value,
success: function(sres) {
common_vendor.index.__f__("log", "at pages/index/index.vue:157", sres, "sres");
common_vendor.index.__f__("log", "at pages/index/index.vue:188", sres, "sres");
imgUrl.value = sres.tempFilePath || sres.path;
draw();
},
fail: function(fres) {
common_vendor.index.__f__("log", "at pages/index/index.vue:161", "fres", fres);
common_vendor.index.__f__("log", "at pages/index/index.vue:194", "fres", fres);
}
});
});