2025-05-08 17:27:47 +08:00

98 lines
3.8 KiB
JavaScript

"use strict";
const common_vendor = require("./common/vendor.js");
const _sfc_main = {
__name: "index",
setup(__props) {
common_vendor.ref(375);
common_vendor.ref(400);
const instance = common_vendor.getCurrentInstance();
const scale = common_vendor.ref(1);
const offsetX = common_vendor.ref(0);
const offsetY = common_vendor.ref(0);
const lastDistance = common_vendor.ref(-1);
const startX = common_vendor.ref(0);
const startY = common_vendor.ref(0);
const isDragging = common_vendor.ref(false);
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.scale(scale.value, scale.value);
const res = await common_vendor.index.getImageInfo({
src: imgUrl.value
});
ctx.drawImage(res.path, 0, 0);
ctx.draw();
}
const handleTouchStart = (e) => {
common_vendor.index.__f__("log", "at pages/index/index.vue:93", "handleTouchStart");
if (e.touches.length === 1) {
startX.value = e.touches[0].clientX - offsetX.value;
startY.value = e.touches[0].clientY - offsetY.value;
isDragging.value = true;
} 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;
lastDistance.value = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}
};
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;
} 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));
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 = () => {
common_vendor.index.__f__("log", "at pages/index/index.vue:136", "handleTouchEnd");
lastDistance.value = -1;
isDragging.value = false;
};
const handleDraw = () => {
draw();
};
common_vendor.onReady(() => {
common_vendor.index.__f__("log", "at pages/index/index.vue:153", "onReadyonReady");
common_vendor.index.downloadFile({
url: imgUrl.value,
success: function(sres) {
common_vendor.index.__f__("log", "at pages/index/index.vue:157", 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);
}
});
});
return (_ctx, _cache) => {
return {
a: common_vendor.o(handleTouchStart),
b: common_vendor.o(handleTouchMove),
c: common_vendor.o(handleTouchEnd),
d: "1000px",
e: "800px",
f: `translate(${offsetX.value}px, ${offsetY.value}px) scale(${scale.value})`,
g: common_vendor.o(handleDraw)
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]);
exports.MiniProgramPage = MiniProgramPage;
//# sourceMappingURL=../.sourcemap/mp-weixin/index.js.map