|
|
@@ -4,13 +4,12 @@
|
|
|
<i class="icon iconfont icon-waterValve valve" :style="{ fontSize: `${props.iconSize}px` }">
|
|
|
<div :class="pointerClass" :style="pointerStyle"></div>
|
|
|
</i>
|
|
|
- <div class="title" :style="titleStyle">{{ title }}</div>
|
|
|
- <slot></slot>
|
|
|
+ <div class="title" ref="titleRef" :style="titleStyle">{{ title }}</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { defineProps, computed } from 'vue'
|
|
|
+import { defineProps, computed, ref, onMounted, watch, nextTick } from 'vue'
|
|
|
const props = defineProps({
|
|
|
title: {
|
|
|
type: String,
|
|
|
@@ -43,6 +42,37 @@ const props = defineProps({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+const titleRef = ref(null)
|
|
|
+const topValue = ref('122%') // 默认值
|
|
|
+// 初次挂载时获取宽度
|
|
|
+onMounted(() => {
|
|
|
+ updateTop()
|
|
|
+})
|
|
|
+
|
|
|
+// 如果 rotateAngle 或 title 变化,可能需要更新 top
|
|
|
+watch(() => [props.rotateAngle, props.title], () => {
|
|
|
+ updateTop()
|
|
|
+})
|
|
|
+// 获取实际 DOM 宽度并计算 top
|
|
|
+const updateTop = () => {
|
|
|
+ nextTick(() => {
|
|
|
+ const el = titleRef.value
|
|
|
+ if (el) {
|
|
|
+ const height = el.offsetWidth
|
|
|
+ // 根据高度偏移一定值
|
|
|
+ topValue.value = props.rotateAngle == 0? topValue.value : `calc(92% + ${height/2}px)`
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 计算 titleStyle 标题样式
|
|
|
+const titleStyle = computed(() => {
|
|
|
+ return {
|
|
|
+ transform: `translate(-50%, -50%) rotate(${-props.rotateAngle}deg)`,
|
|
|
+ top: topValue.value,
|
|
|
+ }
|
|
|
+})
|
|
|
|
|
|
|
|
|
// 计算 pointer 的 class
|
|
|
@@ -59,27 +89,22 @@ const pointerClass = computed(() => {
|
|
|
if (props.valveCloseSignalStatus) {
|
|
|
return 'pointer_close'
|
|
|
} else {
|
|
|
- return props.valveOpenObj?.value ? 'pointer_to_open' : 'pointer_to_close'
|
|
|
+ return props.valveOpenObj ? 'pointer_to_open' : 'pointer_to_close'
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// 计算 titleStyle
|
|
|
-const titleStyle = computed(() => {
|
|
|
- return {
|
|
|
- transform: `rotate(${-props.rotateAngle}deg)`,
|
|
|
- }
|
|
|
-})
|
|
|
|
|
|
+// 计算 pointerStyle指针样式
|
|
|
const pointerStyle = computed(() => {
|
|
|
- return {
|
|
|
- borderRadius: '4px',
|
|
|
- width: `${props.iconSize * 0.16}px`,
|
|
|
- height: `${props.iconSize * 0.506}px`,
|
|
|
- position: 'absolute',
|
|
|
- left: '43%',
|
|
|
- top: '41.4%',
|
|
|
- }
|
|
|
+ return {
|
|
|
+ borderRadius: '4px',
|
|
|
+ width: `${props.iconSize * 0.16}px`,
|
|
|
+ height: `${props.iconSize * 0.506}px`,
|
|
|
+ position: 'absolute',
|
|
|
+ left: '43%',
|
|
|
+ top: '41.4%',
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
|
|
|
@@ -96,8 +121,9 @@ const pointerStyle = computed(() => {
|
|
|
.title {
|
|
|
color: #C7D2E0;
|
|
|
position: absolute;
|
|
|
- top: 100%;
|
|
|
- left: 29%;
|
|
|
+ // top: 122%;
|
|
|
+ left: 50%;
|
|
|
+ z-index: 10;
|
|
|
}
|
|
|
|
|
|
.valve {
|