index.vue
3.27 KB
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
<template>
<div class="go-text-box">
<div class="content">
<span style="cursor: pointer; white-space: pre-wrap" v-if="link" @click="click">{{ option.dataset }}</span>
<span style="white-space: pre-wrap" v-else>{{ option.dataset }}</span>
</div>
</div>
</template>
<script setup lang="ts">
import { PropType, toRefs, shallowReactive } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { useChartDataFetch } from '@/hooks'
import { useTsl } from '@/hooks/external/useTsl'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { option as configOption } from './config'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType & typeof option>,
required: true
}
})
const { handleDeviceProfileAttributes } = useTsl()
const {
linkHead,
link,
fontColor,
fontSize,
letterSpacing,
paddingY,
paddingX,
textAlign,
borderWidth,
borderColor,
borderRadius,
writingMode,
backgroundColor,
fontWeight,
linkMethod
} = toRefs(props.chartConfig.option)
const option = shallowReactive({
dataset: configOption.dataset
})
//动态请求物模型
const fetchTsl = (entityId: string) => {
return handleDeviceProfileAttributes(entityId)
}
//解构设备和属性参数
const deconstructionParams = (chartConfig: CreateComponentType) => {
const { request } = chartConfig
const { requestParams } = request
const { Params } = requestParams
const { entityId, keys } = Params
return { entityId, keys }
}
//找到枚举值name,属性暂时只选择一个
const findEnumName = (attribute: Recordable[], keys: string[], newData: Recordable) => {
const findCurrentAttr = attribute.find(findAttrItem => findAttrItem.identifier === keys.at(0))?.detail?.dataType
?.specsList
return findCurrentAttr.find(
(findCurrentItem: Recordable) => findCurrentItem.value === Number(newData.data[keys.at(0)!][0][1])
)?.name
}
// 预览更新
useChartDataFetch(props.chartConfig, useChartEditStore, async (newData: string) => {
const { entityId, keys } = deconstructionParams(props.chartConfig) as Recordable
const { attribute } = (await fetchTsl(entityId)) as unknown as Recordable
if (Object.prototype.toString.call(newData) !== '[object Object]') {
option.dataset = newData
} else if ('subscriptionId' in (newData as unknown as Recordable)) {
// ws
option.dataset = findEnumName(attribute, keys, newData as unknown as Recordable) || '暂无数据'
}
})
//打开链接
const click = () => {
const hrefStr = linkHead.value + link.value
if (linkMethod.value === 'open') window.open(hrefStr)
else window.location.href = hrefStr
}
</script>
<style lang="scss" scoped>
@include go('text-box') {
display: flex;
align-items: center;
justify-content: v-bind('textAlign');
.content {
color: v-bind('fontColor');
padding: v-bind('`${paddingY}px ${paddingX}px`');
font-size: v-bind('fontSize + "px"');
letter-spacing: v-bind('letterSpacing + "px"');
writing-mode: v-bind('writingMode');
font-weight: v-bind('fontWeight');
border-style: solid;
border-width: v-bind('borderWidth + "px"');
border-radius: v-bind('borderRadius + "px"');
border-color: v-bind('borderColor');
background-color: v-bind('backgroundColor');
}
}
</style>