Compare commits

...

3 Commits

Author SHA1 Message Date
7aacf24705 1 2025-05-08 17:39:58 +08:00
0a3db13862 1 2025-05-08 17:36:20 +08:00
9fc632a79d 1 2025-05-08 17:30:13 +08:00
7 changed files with 135 additions and 226 deletions

View File

@ -1,28 +0,0 @@
{
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index_step4",
"style": {
"navigationBarTitleText": "step"
}
},{
"path": "pages/index/step2",
"style": {
"navigationBarTitleText": "fu"
}
},{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"uniIdRouter": {}
}

View File

@ -1,53 +0,0 @@
<template>
<view>
<!-- 定义canvas画布 // canvas200x200 -->
<canvas canvas-id="canvas" id="canvas" style="width: 200px; height: 200px;border: 1px solid red;" :width="canvasWidth" :height="canvasHeight"></canvas>
<!-- 添加一个按钮用于触发绘图 -->
<button @click="handleDraw">跳转step2</button>
</view>
</template>
<script setup>
import { ref, onMounted ,getCurrentInstance } from 'vue'
const canvasWidth = ref(200) // Canvas
const canvasHeight = ref(200) // Canvas
const instance = getCurrentInstance()
//
function draw() {
const ctx = uni.createCanvasContext('canvas',instance) // canvas
console.log(ctx,'12');
//
ctx.beginPath() //
ctx.arc(100, 100, 80, 0, Math.PI * 2) // (100, 100)80
ctx.setFillStyle('rgba(100, 220, 0, 1)') //
ctx.fill() //
//
ctx.beginPath() //
ctx.arc(100, 100, 75, 0, Math.PI * 2) // (100, 100)60
ctx.setFillStyle('white') //
ctx.fill() //
ctx.draw()
}
//
const handleDraw = () => {
uni.navigateTo({
url:'/pages/index/step2'
})
draw(); //
}
onMounted(() => {
draw()
// Canvas
})
</script>
<style scoped>
button {
margin-top: 10px;
}
</style>

View File

@ -1,125 +0,0 @@
<template>
<view>
<!-- 定义canvas画布 // canvas200x200 -->
<canvas @touchstart="handleCanvasTouch" canvas-id="canvas" id="canvas"
style="border: 1px solid red;height: 600px;width: 100vw;"></canvas>
<!-- 添加一个按钮用于触发绘图 -->
<button @click="handleDraw">点击绘制圆形</button>
</view>
</template>
<script setup>
import {
ref,
onMounted,
getCurrentInstance
} from 'vue'
const canvasWidth = ref(375) // Canvas
const canvasHeight = ref(400) // Canvas
const instance = getCurrentInstance()
//
const blocks = ref([{
x: 50,
y: 50,
width: 100,
height: 100,
color: 'red',
message: '点击了红色方块'
},
{
x: 200,
y: 50,
width: 100,
height: 100,
color: 'blue',
message: '点击了蓝色方块'
},
{
x: 50,
y: 200,
width: 100,
height: 100,
color: 'green',
message: '点击了绿色方块'
},
{
x: 200,
y: 200,
width: 100,
height: 100,
color: 'yellow',
message: '点击了黄色方块'
},
{
x: 350,
y: 50,
width: 100,
height: 100,
color: 'purple',
message: '点击了紫色方块'
},
])
async function draw() {
const imgUrl = "https://assets.sx25.troyrc.com/sx25/images/events/XBDT.jpg"
const ctx = uni.createCanvasContext('canvas', instance) // canvas
const res = await uni.getImageInfo({
src: imgUrl,
})
console.log(res, 'res');
ctx.drawImage(res.path, 0, 0, canvasWidth.value, canvasHeight.value);
// 5
//
blocks.value.forEach((block) => {
ctx.beginPath();
ctx.fillStyle = block.color;
ctx.rect(block.x, block.y, block.width, block.height);
ctx.fill();
});
ctx.draw()
}
// canvas
function handleCanvasTouch(event) {
//
const x = event.touches[0].x;
const y = event.touches[0].y;
// 5
//
blocks.value.forEach((block) => {
if (x >= block.x && x <= block.x + block.width && y >= block.y && y <= block.y + block.height) {
uni.showModal({
title: '提示',
content: block.message,
showCancel: true, //
success: (res) => {
if (res.confirm) {
console.log('用户点击了“确定”按钮');
} else if (res.cancel) {
console.log('用户点击了“取消”按钮');
}
},
});
}
});
}
//
const handleDraw = () => {
draw(); //
}
onMounted(() => {
draw()
// Canvas
})
</script>
<style scoped>
button {
margin-top: 10px;
}
</style>

View File

@ -1,17 +0,0 @@
<template>
<view>
<indexstep2></indexstep2>
</view>
</template>
<script setup>
import indexstep2 from "./index.vue"
import {
ref
} from 'vue'
</script>
<style scoped>
</style>

View File

@ -2,9 +2,9 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const common_vendor = require("./common/vendor.js");
if (!Math) {
"./pages/index/index.js";
"./pages/index/index_step4.js";
"./pages/index/step2.js";
"./pages/index/index.js";
}
const _sfc_main = {
onLaunch: function() {

View File

@ -1,8 +1,8 @@
{
"pages": [
"pages/index/index",
"pages/index/index_step4",
"pages/index/step2",
"pages/index/index"
"pages/index/step2"
],
"window": {
"navigationBarTextStyle": "black",

View File

@ -3,6 +3,112 @@ const common_vendor = require("./common/vendor.js");
const _sfc_main = {
__name: "index",
setup(__props) {
<<<<<<< HEAD
const translateX = common_vendor.ref(0);
const translateY = common_vendor.ref(0);
const scale = common_vendor.ref(1);
const canvasWidth = common_vendor.ref(375);
const canvasHeight = common_vendor.ref(400);
const instance = common_vendor.getCurrentInstance();
const blocks = common_vendor.ref([{
points: [
{
x: 50,
y: 50
},
// 左下角点
{
x: 150,
y: 50
},
// 右下角点
{
x: 200,
y: 100
},
// 右上角点
{
x: 100,
y: 100
}
// 左上角点
],
message: "点击了四边形",
type: "quadrilateral"
}]);
async function draw() {
const imgUrl = "https://assets.sx25.troyrc.com/sx25/images/events/XBDT.jpg";
const ctx = common_vendor.index.createCanvasContext("canvas", instance);
ctx.translate(translateX.value, translateY.value);
ctx.scale(scale.value, scale.value);
const res = await common_vendor.index.getImageInfo({
src: imgUrl
});
ctx.drawImage(res.path, 0, 0, canvasWidth.value, canvasHeight.value);
blocks.value.forEach((block) => {
ctx.beginPath();
ctx.fillStyle = block.color;
switch (block.type) {
case "quadrilateral":
ctx.moveTo(block.points[0].x, block.points[0].y);
for (let i = 1; i < block.points.length; i++) {
ctx.lineTo(block.points[i].x, block.points[i].y);
}
ctx.closePath();
break;
}
ctx.stroke();
});
ctx.draw();
}
function handleCanvasTouchMove(event) {
if (event.touches.length === 1) {
translateX.value += event.touches[0].x - event.touches[0].startX;
translateY.value += event.touches[0].y - event.touches[0].startY;
} else if (event.touches.length === 2) {
const distance1 = Math.sqrt(
(event.touches[0].x - event.touches[1].x) ** 2 + (event.touches[0].y - event.touches[1].y) ** 2
);
const distance2 = Math.sqrt(
(event.touches[0].startX - event.touches[1].startX) ** 2 + (event.touches[0].startY - event.touches[1].startY) ** 2
);
scale.value *= distance1 / distance2;
}
draw();
}
function handleCanvasTouchEnd(event) {
event.touches.forEach((touch) => {
touch.startX = touch.x;
touch.startY = touch.y;
});
}
function handleCanvasTouch(event) {
const x = event.touches[0].x;
const y = event.touches[0].y;
blocks.value.forEach((block) => {
if (isPointInQuadrilateral(x, y, block.points)) {
common_vendor.index.showModal({
title: "提示",
content: block.message,
showCancel: true,
// 显示取消按钮
success: (res) => {
if (res.confirm) {
common_vendor.index.__f__("log", "at pages/index/index.vue:128", "用户点击了“确定”按钮");
} else if (res.cancel) {
common_vendor.index.__f__("log", "at pages/index/index.vue:130", "用户点击了“取消”按钮");
}
}
});
}
});
}
const handleDraw = () => {
draw();
};
common_vendor.onMounted(() => {
draw();
=======
common_vendor.ref(375);
common_vendor.ref(400);
const instance = common_vendor.getCurrentInstance();
@ -78,9 +184,34 @@ const _sfc_main = {
common_vendor.index.__f__("log", "at pages/index/index.vue:161", "fres", fres);
}
});
>>>>>>> c224ee0a440c37a515ef0081348c5d861d979aee
});
function isPointInQuadrilateral(px, py, points) {
let inside = false;
const n = points.length;
let p1 = points[0];
for (let i = 1; i <= n; i++) {
let p2 = points[i % n];
if (py > Math.min(p1.y, p2.y) && py <= Math.max(p1.y, p2.y) && px <= Math.max(p1.x, p2.x)) {
if (p1.y !== p2.y) {
let xinters = (py - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
if (p1.x === p2.x || px <= xinters) {
inside = !inside;
}
}
}
p1 = p2;
}
return inside;
}
return (_ctx, _cache) => {
return {
<<<<<<< HEAD
a: common_vendor.o(handleCanvasTouch),
b: common_vendor.o(handleCanvasTouchMove),
c: common_vendor.o(handleCanvasTouchEnd),
d: common_vendor.o(handleDraw)
=======
a: common_vendor.o(handleTouchStart),
b: common_vendor.o(handleTouchMove),
c: common_vendor.o(handleTouchEnd),
@ -88,6 +219,7 @@ const _sfc_main = {
e: "800px",
f: `translate(${offsetX.value}px, ${offsetY.value}px) scale(${scale.value})`,
g: common_vendor.o(handleDraw)
>>>>>>> c224ee0a440c37a515ef0081348c5d861d979aee
};
};
}