style 简历匹配职位的点击emit
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<view class="container">
|
||||
<!-- 用于承载 PIXI 的 Canvas -->
|
||||
<!-- #ifdef H5 -->
|
||||
<view id="matchCanvas" class="match-canvas"></view>
|
||||
<view id="matchCanvas" class="match-canvas" @click="handleCanvasClick"></view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef H5 -->
|
||||
<canvas type="webgl" id="matchCanvas" canvas-id="matchCanvas" class="match-canvas" />
|
||||
@@ -14,7 +14,9 @@
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import * as PIXI from "pixi.js";
|
||||
|
||||
const appRef = ref(null); // 存储 PIXI 应用实例
|
||||
const appRef = ref(null);
|
||||
const tagsContainer = ref(null); // 标签容器
|
||||
const emit = defineEmits(["tag-click"]);
|
||||
|
||||
// 名称、颜色、大小、位置(角度、半径)
|
||||
const mockTags = [
|
||||
@@ -147,9 +149,10 @@ onMounted(async () => {
|
||||
|
||||
canvas.appendChild(app.view);
|
||||
|
||||
// 标签容器(
|
||||
const tagsContainer = new PIXI.Container();
|
||||
app.stage.addChild(tagsContainer);
|
||||
// 标签容器
|
||||
const container = new PIXI.Container();
|
||||
tagsContainer.value = container;
|
||||
app.stage.addChild(container);
|
||||
|
||||
// 存储已放置标签的信息
|
||||
const placedTags = [];
|
||||
@@ -185,11 +188,17 @@ onMounted(async () => {
|
||||
tag.y = originalY + Math.sin(floatOffset) * floatRange;
|
||||
});
|
||||
|
||||
tagsContainer.addChild(tag);
|
||||
placedTags.push({ ...tagData, bounds: tag.getBounds() });
|
||||
container.addChild(tag);
|
||||
placedTags.push({
|
||||
...tagData,
|
||||
bounds: tag.getBounds(),
|
||||
angle,
|
||||
radius,
|
||||
tailRotation,
|
||||
tagInstance: tag, // 保存标签实例
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 创建拖尾
|
||||
function createCometTail(bgColor, tailRotation, tag) {
|
||||
const tailGroup = new PIXI.Container();
|
||||
@@ -319,6 +328,54 @@ function createTag(tagData, x, y, placedTags, app, index) {
|
||||
return tagGroup;
|
||||
}
|
||||
|
||||
//点击事件
|
||||
const handleCanvasClick = (event) => {
|
||||
if (!appRef.value || !tagsContainer.value) return;
|
||||
|
||||
const canvas = document.getElementById("matchCanvas");
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
|
||||
let clientX, clientY;
|
||||
|
||||
if (event.touches && event.touches.length > 0) {
|
||||
// 移动端事件
|
||||
clientX = event.touches[0].clientX;
|
||||
clientY = event.touches[0].clientY;
|
||||
} else {
|
||||
// PC端事件
|
||||
clientX = event.clientX;
|
||||
clientY = event.clientY;
|
||||
}
|
||||
|
||||
// 点击位置相对于Canvas的坐标
|
||||
const x = clientX - rect.left;
|
||||
const y = clientY - rect.top;
|
||||
|
||||
for (let i = 0; i < mockTags.length; i++) {
|
||||
const tag = tagsContainer.value.children[i];
|
||||
if (!tag) continue;
|
||||
|
||||
// 获取标签边界
|
||||
const bounds = tag.getBounds();
|
||||
|
||||
// 缩小点击范围 上下左右各3
|
||||
const shrinkAmount = 3;
|
||||
const innerBounds = {
|
||||
x: bounds.x + shrinkAmount,
|
||||
y: bounds.y + shrinkAmount,
|
||||
width: bounds.width - shrinkAmount * 2,
|
||||
height: bounds.height - shrinkAmount * 2,
|
||||
};
|
||||
|
||||
// 检查点击位置是否在缩小后的标签边界内
|
||||
if (x >= innerBounds.x && x <= innerBounds.x + innerBounds.width && y >= innerBounds.y && y <= innerBounds.y + innerBounds.height) {
|
||||
// 找到对应标签
|
||||
const tagData = mockTags[i];
|
||||
emit("tag-click", tagData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
onUnmounted(() => {
|
||||
if (appRef.value) {
|
||||
appRef.value.destroy(true, true);
|
||||
|
||||
Reference in New Issue
Block a user