Commit 36e69e2d2c36db405570523eb1de6fef3e720268

Authored by xp.Huang
2 parents b823113d 460a6b4e

Merge branch 'fix/DEFECT-1888' into 'main_dev'

fix: 修复引用模板创建组态时图表组件不显示设备名称

See merge request yunteng/thingskit-scada!215
... ... @@ -111,7 +111,7 @@ const handleSave = async () => {
111 111 if (operationPassword.checked)
112 112 await validatePassword()
113 113 if (contentDataStore.getIsTemplate)// 判断组态是不是模板
114   - dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null }
  114 + dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null, deviceName: null }
115 115 await saveNodeAllData({ dataSourceJson, eventJson: { ...eventJson, OPERATION_PASSWORD: unref(getCellInfo).category === PackageCategoryEnum.CONTROL ? operationPassword : undefined }, actJson })
116 116 createMessage.success('操作成功')
117 117 savePageContent()
... ...
... ... @@ -34,7 +34,7 @@ const handleSubmit = async () => {
34 34 const formValues = unref(dataSourceFormRef)?.getFieldsValue()
35 35 let dataSourceJson = formValues
36 36 if (contentDataStore.getIsTemplate)
37   - dataSourceJson = { ...formValues, deviceProfileId: formValues?.deviceProfileTemplateId, deviceId: null }
  37 + dataSourceJson = { ...formValues, deviceProfileId: formValues?.deviceProfileTemplateId, deviceId: null, deviceName: null }
38 38
39 39 saveNodeAllData({ dataSourceJson: { ...dataSourceJson, circularFlowMeterOption: unref(colorConfig) } })
40 40 createMessage.success('保存成功~')
... ...
... ... @@ -9,6 +9,7 @@ import { useOnMessage } from '@/core/Library/hook/useOnMessage'
9 9 import type { NodeDataDataSourceJsonType } from '@/api/node/model'
10 10 import { useLatestMessageValue } from '@/core/Library/hook/useLatestMessageValue'
11 11 import { useContentDataStore } from '@/store/modules/contentData'
  12 +import { useProductsStore } from '@/store/modules/products'
12 13
13 14 const props = defineProps<{
14 15 config: CreateComponentType
... ... @@ -24,6 +25,8 @@ const chartElRef = ref<Nullable<HTMLDivElement>>()
24 25
25 26 const chartInstance = ref<Nullable<ECharts>>()
26 27
  28 +const productsStore = useProductsStore()
  29 +
27 30 function initChartInstance() {
28 31 const { dataSourceJson } = unref(getCurrentNodeData) || {}
29 32 const { circularFlowMeterOption } = dataSourceJson || {}
... ... @@ -34,11 +37,13 @@ function initChartInstance() {
34 37 const { onMessage } = useOnMessage({
35 38 onReceiveDataSourceMessage(commandSource, message) {
36 39 const { data } = commandSource
37   - const { attr } = data as NodeDataDataSourceJsonType
38   - const { latestValue } = useLatestMessageValue(message.data, attr)
  40 + const { attr, deviceName, deviceProfileId } = data as NodeDataDataSourceJsonType
  41 +
  42 + const { functionName } = productsStore.getObjectModelByIdWithIdentifier(deviceProfileId, (attr) as string) || {}
  43 + const { latestValue } = useLatestMessageValue(message.data, (attr as string))
39 44 unref(chartInstance)?.setOption({
40 45 title: {
41   - // text: `${deviceName || ''}-${attrInfo.name || ''}`,
  46 + text: `${deviceName || ''} - ${functionName || ''}`,
42 47 },
43 48 series: [{
44 49 data: getSetValue(Number(latestValue)),
... ...
... ... @@ -45,7 +45,7 @@ const handleSubmit = async () => {
45 45 const values = getFieldsValue()
46 46 let dataSourceJson = value
47 47 if (contentDataStore.getIsTemplate)
48   - dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null }
  48 + dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null, deviceName: null }
49 49
50 50 await saveNodeAllData({ dataSourceJson: { ...dataSourceJson, attr: typeof value.attr == 'string' ? [value.attr] : value.attr, chartOption: { ...values } } })
51 51 savePageContent()
... ...
... ... @@ -42,7 +42,7 @@ const handleSubmit = async () => {
42 42 const values = getFieldsValue()
43 43 let dataSourceJson = value
44 44 if (contentDataStore.getIsTemplate)
45   - dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null }
  45 + dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null, deviceName: null }
46 46
47 47 await saveNodeAllData({ dataSourceJson: { ...dataSourceJson, chartOption: values } })
48 48 createMessage.success('操作成功~')
... ... @@ -55,9 +55,9 @@ const handleSubmit = async () => {
55 55
56 56 const handleSetFormValues = async () => {
57 57 const { dataSourceJson } = unref(getNodeData) || {}
58   - const { deviceId, attr, chartOption, deviceProfileId, deviceProfileTemplateId } = dataSourceJson || {}
  58 + const { deviceId, attr, chartOption, deviceProfileId, deviceProfileTemplateId, deviceName } = dataSourceJson || {}
59 59 await nextTick()
60   - unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, deviceProfileTemplateId })
  60 + unref(dataSourceElRef)?.setFieldsValue({ deviceId, attr, deviceProfileId, deviceName, deviceProfileTemplateId })
61 61 setFieldsValue({ ...chartOption })
62 62 }
63 63
... ...
... ... @@ -10,6 +10,7 @@ import type { CommandSource } from '@/core/websocket/processor'
10 10 import type { NodeDataDataSourceJsonType } from '@/api/node/model'
11 11 import type { SubscriptionUpdateMsg } from '@/core/websocket/type/message'
12 12 import { useContentDataStore } from '@/store/modules/contentData'
  13 +import { useProductsStore } from '@/store/modules/products'
13 14
14 15 const props = defineProps<{
15 16 config: CreateComponentType
... ... @@ -23,6 +24,8 @@ const chartInstance = ref<Nullable<ECharts>>()
23 24
24 25 const contentDataStore = useContentDataStore()
25 26
  27 +const productsStore = useProductsStore()
  28 +
26 29 function initChartInstance() {
27 30 chartInstance.value = init(unref(chartElRef))
28 31 const currentNodeData = unref(contentDataStore.getCurrentNodeDataById(props.config))
... ... @@ -36,15 +39,16 @@ onMounted(() => {
36 39
37 40 const onReceiveDataSourceMessage = (commandSource: CommandSource, message: SubscriptionUpdateMsg) => {
38 41 const { data } = commandSource
39   - const { attr } = data as NodeDataDataSourceJsonType
40   - const { latestValue } = useLatestMessageValue(message.data, attr)
  42 + const { attr, deviceName, deviceProfileId } = data as NodeDataDataSourceJsonType
  43 + const { functionName } = productsStore.getObjectModelByIdWithIdentifier(deviceProfileId, (attr) as string) || {}
  44 + const { latestValue } = useLatestMessageValue(message.data, (attr as string))
41 45 unref(chartInstance)?.setOption({
42 46 series: [{
43 47 data: [{ value: latestValue }],
44 48
45 49 }],
46 50 title: {
47   - // text: `${deviceName || ''}-${attrInfo.name || ''}`,
  51 + text: `${deviceName || ''}- ${functionName || ''} `,
48 52 },
49 53 } as EChartsOption)
50 54 }
... ...
... ... @@ -54,7 +54,7 @@ const handleSubmit = async () => {
54 54 const values = getFieldsValue()
55 55 let dataSourceJson = value
56 56 if (contentDataStore.getIsTemplate)
57   - dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null }
  57 + dataSourceJson = { ...value, deviceProfileId: value?.deviceProfileTemplateId, deviceId: null, deviceName: null }
58 58
59 59 saveNodeAllData({ dataSourceJson: { ...dataSourceJson, attr: typeof value.attr == 'string' ? [value.attr] : value.attr, chartOption: { ...values } } })
60 60 createMessage.success('操作成功~')
... ...
... ... @@ -34,7 +34,7 @@ const handleSubmit = async () => {
34 34 const formValues = unref(dataSourceFormRef)?.getFieldsValue()
35 35 let dataSourceJson = formValues
36 36 if (contentDataStore.getIsTemplate)
37   - dataSourceJson = { ...formValues, deviceProfileId: formValues?.deviceProfileTemplateId, deviceId: null }
  37 + dataSourceJson = { ...formValues, deviceProfileId: formValues?.deviceProfileTemplateId, deviceId: null, deviceName: null }
38 38
39 39 await saveNodeAllData({ dataSourceJson: { ...dataSourceJson, rectFlowMeterOption: unref(colorConfig) } })
40 40 createMessage.success('保存成功')
... ...
... ... @@ -9,6 +9,7 @@ import { useOnMessage } from '@/core/Library/hook/useOnMessage'
9 9 import type { NodeDataDataSourceJsonType } from '@/api/node/model'
10 10 import { useLatestMessageValue } from '@/core/Library/hook/useLatestMessageValue'
11 11 import { useContentDataStore } from '@/store/modules/contentData'
  12 +import { useProductsStore } from '@/store/modules/products'
12 13
13 14 const props = defineProps<{
14 15 config: CreateComponentType
... ... @@ -22,6 +23,8 @@ const getCellBounds = computed(() => props.config.cellBounds || { width: 300, he
22 23
23 24 const chartElRef = ref<Nullable<HTMLDivElement>>()
24 25
  26 +const productsStore = useProductsStore()
  27 +
25 28 const chartInstance = ref<Nullable<ECharts>>()
26 29
27 30 function initChartInstance() {
... ... @@ -34,11 +37,12 @@ function initChartInstance() {
34 37 const { onMessage } = useOnMessage({
35 38 onReceiveDataSourceMessage(commandSource, message) {
36 39 const { data } = commandSource
37   - const { attr } = data as NodeDataDataSourceJsonType
38   - const { latestValue } = useLatestMessageValue(message.data, attr)
  40 + const { attr, deviceName, deviceProfileId } = data as NodeDataDataSourceJsonType
  41 + const { functionName } = productsStore.getObjectModelByIdWithIdentifier(deviceProfileId, (attr as string)) || {}
  42 + const { latestValue } = useLatestMessageValue(message.data, (attr as string))
39 43 unref(chartInstance)?.setOption({
40 44 title: {
41   - // text: `${deviceName || ''}-${attrInfo.name || ''}`,
  45 + text: `${deviceName || ''} - ${functionName || ''}`,
42 46 },
43 47 series: [{
44 48 data: getSetValue(Number(latestValue)),
... ...
... ... @@ -7,6 +7,7 @@ import type { CreateComponentType, RenderComponentExposeType } from '@/core/Libr
7 7 import type { NodeDataDataSourceJsonType } from '@/api/node/model'
8 8 import { useLatestMessageValue } from '@/core/Library/hook/useLatestMessageValue'
9 9 import { useOnMessage } from '@/core/Library/hook/useOnMessage'
  10 +import { useProductsStore } from '@/store/modules/products'
10 11
11 12 const props = defineProps<{
12 13 config: CreateComponentType
... ... @@ -18,6 +19,8 @@ const chartElRef = ref<Nullable<HTMLDivElement>>()
18 19
19 20 const chartInstance = ref<Nullable<ECharts>>()
20 21
  22 +const productsStore = useProductsStore()
  23 +
21 24 function initChartInstance() {
22 25 chartInstance.value = init(unref(chartElRef))
23 26 chartInstance.value.setOption(getDefaultOption)
... ... @@ -26,11 +29,12 @@ function initChartInstance() {
26 29 const { onMessage } = useOnMessage({
27 30 onReceiveDataSourceMessage(commandSource, message) {
28 31 const { data } = commandSource
29   - const { attr } = data as NodeDataDataSourceJsonType
30   - const { latestValue } = useLatestMessageValue(message.data, attr)
  32 + const { attr, deviceName, deviceProfileId } = data as NodeDataDataSourceJsonType
  33 + const { functionName } = productsStore.getObjectModelByIdWithIdentifier(deviceProfileId, (attr as string)) || {}
  34 + const { latestValue } = useLatestMessageValue(message.data, (attr as string))
31 35 unref(chartInstance)?.setOption({
32 36 title: {
33   - // text: `${deviceName || ''}-${attrInfo.name || ''}`,
  37 + text: `${deviceName || ''} - ${functionName || ''}`,
34 38 },
35 39 series: [{
36 40 data: [{
... ...