wuyouming666
2025-03-26 54398271dd26caf3b66b9ef2deff3af0277243d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
  <div ref="layoutPanel" :class="panelClass" :style="panelStyle">
    <div v-for="(layout, layoutIndex) in layouts" :key="layoutIndex" class="layout-wrapper">
      <!-- 布局信息标签 -->
      <div class="layout-info" :style="layoutInfoStyle(layoutIndex)">
         {{ getCurrentRectInfo(layoutIndex) }}
      </div>
 
      <!-- 布局容器 -->
      <div class="layout-container" :style="layoutContainerStyle(layoutIndex)">
        <div v-for="(rect, rectIndex) in layout.rects" :key="rectIndex"
             :ref="(el) => { if (el) rectsElements[layoutIndex + '-' + rectIndex] = el }"
             :class="rectClass"
             :style="rectStyle(rect, layoutIndex)"
             @click="handleRectClick(layoutIndex, rectIndex)">
          <div v-if="!rect.isRemain" class="rect-content">
            <div class="size">{{ rect.w }}×{{ rect.h }}</div>
            <div class="jia-hao">{{ rect.JiaHao }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { ref, reactive, onMounted, onUnmounted } from 'vue';
 
const props = defineProps({
  layoutData: { type: Object, required: true },
  gw: { type: Number, default: 1000 },
  gh: { type: Number, default: 1000 },
  style: { type: String, default: 'width:1000px;height:600px;display:block;background:gray' }
});
 
const emit = defineEmits(['rectClicked']);
const layoutPanel = ref(null);
const rectsElements = ref({});
const focusIndex = ref(null);
const layouts = ref([]);
const panelClass = ref('');
const panelStyle = ref(props.style);
const rectClass = ref('layout-rect');
 
const layoutContainerStyle = (layoutIndex) => {
  const containerWidth = (props.gw - 210) / 2;
  const containerHeight = (props.gh - 100) / 3;
  const x = (layoutIndex % 2) * (containerWidth + 50);
  const y = Math.floor(layoutIndex / 2) * (containerHeight + 50);
  return {
    position: 'absolute',
    left: `${x}px`,
    top: `${y}px`,
    width: `${containerWidth}px`,
    height: `${containerHeight}px`,
    overflow: 'visible',
    border: '1px solid #ccc',
    background: '#fff'
  };
};
 
const layoutInfoStyle = (layoutIndex) => {
  const containerWidth = (props.gw - 210) / 2;
  const containerHeight = (props.gh - 100) / 3;
  const x = (layoutIndex % 2) * (containerWidth + 50);
  const y = Math.floor(layoutIndex / 2) * (containerHeight + 50);
  return {
    position: 'absolute',
    left: `${x}px`,
    top: `${y - 45}px`,
    background: 'none',
    textAlign: 'center',
    zIndex: 1000
  };
};
 
const rectStyle = (rect, layoutIndex) => {
  const layout = layouts.value[layoutIndex];
  const containerWidth = (props.gw - 100) / 2;
  const containerHeight = (props.gh - 100) / 3;
  const scale = Math.min(
    containerWidth / layout.width,
    containerHeight / layout.height
  );
  return {
    position: 'absolute',
    left: `${rect.x * scale}px`,
    top: `${rect.y * scale}px`,
    width: `${rect.w * scale}px`,
    height: `${rect.h * scale}px`,
    backgroundColor: rect.isRemain ? '#f0f0f0' : '#a0d8ef',
    border: '1px solid #000',
    cursor: 'pointer'
  };
};
 
const handleRectClick = (layoutIndex, rectIndex) => {
  focusIndex.value = { layoutIndex, rectIndex };
  emit('rectClicked', layoutIndex, rectIndex);
};
 
const getCurrentRectInfo = (layoutIndex) => {
  const layout = layouts.value[layoutIndex];
  const rect = layout.rects[focusIndex.value?.rectIndex || 0];
  if (!rect) return '';
  const totalRects = layouts.value.length;
  const currentRectIndex = layoutIndex+1;
  const width = layout.width;
  const height = layout.height;
  const percentage = ((rect.w / layout.width) * 100).toFixed(1) + '%';
  return `${currentRectIndex}/${totalRects} ${width}×${height} ×1 ${percentage}`;
};
 
const updateLayout = () => {
  if (!layoutPanel.value) return;
  layouts.value = props.layoutData.Layouts;
};
 
onMounted(() => {
   setTimeout(updateLayout, 500);
});
 
onUnmounted(() => {
  rectsElements.value = {};
});
 
 
</script>
 
<style scoped>
.layout-wrapper {
  position: relative;
  margin-top: 50px;
}
 
.layout-container {
  position: relative;
  overflow: visible;
}
 
.layout-info {
  color: #444;
  font-size: 12px;
  background-color: #ffffff;
  padding: 5px 10px;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  font-weight: bold;
}
 
.rect-content {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  padding: 5px;
}
 
.size {
  grid-row: 1;
  grid-column: 1;
  color: #444;
  font-size: 12px;
}
 
.jia-hao {
  grid-row: 2;
  grid-column: 1;
  margin: auto;
  font-size: 14px;
  font-weight: bold;
}
</style>