|
|
@@ -11,8 +11,8 @@ export default {
|
|
|
return {
|
|
|
stage: null,
|
|
|
layer: null,
|
|
|
- isSelected:true,//判断是否选中隔离点
|
|
|
- selectedStates: {} // 存储每个图片的选中状态
|
|
|
+ selectedStates: [], // 用于存储每个元素的选中状态
|
|
|
+ selectedText: [] // 用于存储未选中的元素文本
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
@@ -24,7 +24,7 @@ export default {
|
|
|
this.stage = new Konva.Stage({
|
|
|
container: this.$refs.container, // 容器元素
|
|
|
width: 1250,
|
|
|
- height: 770,
|
|
|
+ height: 830,
|
|
|
fill: 'black'
|
|
|
})
|
|
|
|
|
|
@@ -40,7 +40,7 @@ export default {
|
|
|
y: 10,
|
|
|
image: bgImage,
|
|
|
width: 500,
|
|
|
- height: 770,
|
|
|
+ height: 790,
|
|
|
draggable: false
|
|
|
})
|
|
|
this.layer.add(KnovaImage)
|
|
|
@@ -90,68 +90,93 @@ export default {
|
|
|
}.bind(this))
|
|
|
this.stage.draggable(true)
|
|
|
},
|
|
|
- renderGrid( imageSrc, rows, cols, startX, startY, xOffset, yOffset, imageWidth, imageHeight, rectWidth, rectHeight) {
|
|
|
+ renderGrid(imageSrc, rows, cols, startX, startY, xOffset, yOffset, imageWidth, imageHeight, rectWidth, rectHeight) {
|
|
|
+ // 初始化状态数组
|
|
|
+ this.selectedStates = new Array(rows * cols).fill(false);
|
|
|
+
|
|
|
for (let row = 0; row < rows; row++) {
|
|
|
for (let col = 0; col < cols; col++) {
|
|
|
- const x = startX + col * xOffset // 每个图片的 x 轴位置
|
|
|
- const y = startY + row * yOffset // 每个图片的 y 轴位置
|
|
|
- const index = row * cols + col + 1 // 唯一标识的编号
|
|
|
+ const x = startX + col * xOffset;
|
|
|
+ const y = startY + row * yOffset;
|
|
|
+ const index = row * cols + col;
|
|
|
|
|
|
- const point = new Image()
|
|
|
- point.src = imageSrc
|
|
|
+ const point = new Image();
|
|
|
+ point.src = imageSrc;
|
|
|
point.onload = () => {
|
|
|
- // 创建图片
|
|
|
const knovaImage = new Konva.Image({
|
|
|
x: x,
|
|
|
y: y,
|
|
|
image: point,
|
|
|
width: imageWidth,
|
|
|
height: imageHeight,
|
|
|
- draggable: false
|
|
|
- })
|
|
|
- // 状态变量用于追踪当前图片
|
|
|
- // 点击事件
|
|
|
- knovaImage.on('click', () => {
|
|
|
+ draggable: false,
|
|
|
+ });
|
|
|
|
|
|
- console.log(this.isSelected,'isSelected')
|
|
|
- if (this.isSelected) {
|
|
|
- point.src = require('@/assets/images/localSetSelect.jpg'); // 替换成选中的图片
|
|
|
+ knovaImage.on('click', () => {
|
|
|
+ // 切换选中状态
|
|
|
+ this.selectedStates[index] = !this.selectedStates[index];
|
|
|
+
|
|
|
+ // 更新 selectedText 数组
|
|
|
+ if (this.selectedStates[index]) {
|
|
|
+ // 元素被选中,替换成选中的图片
|
|
|
+ point.src = require('@/assets/images/localSetSelect.jpg');
|
|
|
+
|
|
|
+ // 检查是否已经在 selectedText 数组中
|
|
|
+ if (!this.selectedText.some(item => item.value === index + 1)) {
|
|
|
+ // 元素被选中,添加到 selectedText 数组
|
|
|
+ this.selectedText.push({
|
|
|
+ label: `E-${index + 1}`,
|
|
|
+ value: index + 1
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
- point.src = imageSrc; // 恢复成原来的图片
|
|
|
+ // 元素未选中,恢复原图片
|
|
|
+ point.src = imageSrc;
|
|
|
+
|
|
|
+ // 元素未选中,从 selectedText 数组中移除
|
|
|
+ const textIndex = this.selectedText.findIndex(item => item.value === index + 1);
|
|
|
+ if (textIndex !== -1) {
|
|
|
+ this.selectedText.splice(textIndex, 1); // 如果元素在 selectedText 中,移除它
|
|
|
+ }
|
|
|
}
|
|
|
- this.isSelected = !this.isSelected; // 切换状态
|
|
|
+
|
|
|
knovaImage.image(point); // 更新图片
|
|
|
this.layer.draw(); // 重绘图层
|
|
|
+
|
|
|
+ // console.log(this.selectedText, '子组件选中的隔离点');
|
|
|
+
|
|
|
+ // 传递选中的元素文本到父组件
|
|
|
+ this.$emit('selection-changed', this.selectedText);
|
|
|
});
|
|
|
- this.layer.add(knovaImage)
|
|
|
|
|
|
- // 创建矩形框
|
|
|
+
|
|
|
+
|
|
|
+ this.layer.add(knovaImage);
|
|
|
+
|
|
|
const rect = new Konva.Rect({
|
|
|
x: x - 3,
|
|
|
- y: y + imageHeight + 10, // 矩形在图片下方
|
|
|
+ y: y + imageHeight + 10,
|
|
|
width: rectWidth,
|
|
|
height: rectHeight,
|
|
|
cornerRadius: 10,
|
|
|
stroke: 'red',
|
|
|
strokeWidth: 2,
|
|
|
- fill: 'white'
|
|
|
- })
|
|
|
- this.layer.add(rect)
|
|
|
+ fill: 'white',
|
|
|
+ });
|
|
|
+ this.layer.add(rect);
|
|
|
|
|
|
- // 创建文本
|
|
|
const text = new Konva.Text({
|
|
|
- x: x + 12, // 调整文本在矩形内的位置
|
|
|
- y: y + imageHeight + 15, // 在矩形内部居中显示
|
|
|
+ x: x + 12,
|
|
|
+ y: y + imageHeight + 15,
|
|
|
fontSize: 20,
|
|
|
- text: `E-${index}`,
|
|
|
+ text: `E-${index + 1}`,
|
|
|
fontFamily: 'Calibri',
|
|
|
- fill: 'red'
|
|
|
- })
|
|
|
- this.layer.add(text)
|
|
|
+ fill: 'red',
|
|
|
+ });
|
|
|
+ this.layer.add(text);
|
|
|
|
|
|
- // 渲染图层
|
|
|
- this.layer.draw()
|
|
|
- }
|
|
|
+ this.layer.draw();
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
}
|