Commit 33e2cd6b52f392604f4ed392fad6c6ffd888ab66

Authored by loveumiko
1 parent edf25625

fix: 修改看板管理未显示更新时间,物模型未显示名称

1 1 <script lang="ts" setup>
2   - import { computed, ref, watch } from 'vue';
  2 + import { computed, ref, toRaw, watch } from 'vue';
3 3 import { BasicInfoForm } from './components/BasicInfoForm';
4 4 import { ModalParamsType } from '/#/utils';
5 5 import { BasicModal, useModalInner } from '/@/components/Modal';
... ... @@ -134,12 +134,13 @@
134 134 oldCategory !== category &&
135 135 firstEnter;
136 136
137   - firstEnter = true;
138   -
139 137 dataSource.value = unref(dataSource).map((item) => ({
140 138 ...item,
141 139 ...(needReset ? { attribute: null } : {}),
142   - componentInfo: { ...unref(getComponentConfig).persetOption, ...item.componentInfo },
  140 + componentInfo: {
  141 + ...toRaw(unref(getComponentConfig).persetOption),
  142 + ...(firstEnter ? {} : item.componentInfo),
  143 + },
143 144 }));
144 145
145 146 if ((window as any).requestIdleCallback as unknown as boolean) {
... ... @@ -154,6 +155,8 @@
154 155 setFormValues({ dataSource: unref(dataSource) } as WidgetDataType);
155 156 }, 500);
156 157 }
  158 +
  159 + firstEnter = true;
157 160 }
158 161 }
159 162 );
... ...
... ... @@ -5,6 +5,6 @@ const componentKeys = useComponentKeys('LateralNumericalControl');
5 5
6 6 export const LateralNumericalControlConfig: ConfigType = {
7 7 ...componentKeys,
8   - title: '控制组件1',
  8 + title: '控制组件4',
9 9 package: PackagesCategoryEnum.CONTROL,
10 10 };
... ...
... ... @@ -152,7 +152,9 @@
152 152 unref(getDesign).dataSource.map((item, index) => ({
153 153 value: 30,
154 154 name: `${
155   - item.showDeviceName ? item.deviceRename || item.deviceName + '-' + item.attribute : ''
  155 + item.showDeviceName
  156 + ? (item.deviceRename || item.deviceName) + '-' + (item.attributeRename || item.attribute)
  157 + : ''
156 158 }`,
157 159 attribute: item.attribute,
158 160 id: item.id,
... ... @@ -274,10 +276,11 @@
274 276 const { forEachGroupMessage } = useReceiveMessage();
275 277 const { getNumberValue } = useReceiveValue();
276 278 const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
277   - forEachGroupMessage(message, deviceId, attribute, (attribute, value) => {
  279 + forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
278 280 series.value.forEach((item) => {
279 281 if (item.id === deviceId && item.attribute === attribute) {
280 282 item.value = getNumberValue(value);
  283 + time.value = timespan;
281 284 }
282 285 });
283 286 });
... ...
  1 +import cloneDeep from 'lodash-es/cloneDeep';
  2 +import { SwitchSignalLightConfig } from '.';
  3 +import {
  4 + ConfigType,
  5 + CreateComponentType,
  6 + PublicComponentOptions,
  7 + PublicPresetOptions,
  8 +} from '/@/views/visual/packages/index.type';
  9 +import { PublicConfigClass, componentInitConfig } from '/@/views/visual/packages/publicConfig';
  10 +import { ComponentConfigFieldEnum } from '/@/views/visual/packages/enum';
  11 +
  12 +export const option: PublicPresetOptions = {
  13 + [ComponentConfigFieldEnum.OPEN_COLOR]: '#30f230',
  14 + [ComponentConfigFieldEnum.CLOSE_COLOR]: '#eeeeee',
  15 + [ComponentConfigFieldEnum.SHOW_DEVICE_NAME]: true,
  16 +};
  17 +
  18 +export default class Config extends PublicConfigClass implements CreateComponentType {
  19 + public key: string = SwitchSignalLightConfig.key;
  20 +
  21 + public attr = { ...componentInitConfig };
  22 +
  23 + public componentConfig: ConfigType = cloneDeep(SwitchSignalLightConfig);
  24 +
  25 + public persetOption = cloneDeep(option);
  26 +
  27 + public option: PublicComponentOptions;
  28 +
  29 + constructor(option: PublicComponentOptions) {
  30 + super();
  31 + this.option = { ...option };
  32 + }
  33 +}
... ...
  1 +<script lang="ts" setup>
  2 + import { ComponentConfigFieldEnum } from '/@/views/visual/packages/enum';
  3 + import { useForm, BasicForm } from '/@/components/Form';
  4 + import { PublicFormInstaceType } from '/@/views/visual/dataSourceBindPanel/index.type';
  5 + import { option } from './config';
  6 +
  7 + const [register, { getFieldsValue, setFieldsValue, resetFields }] = useForm({
  8 + schemas: [
  9 + {
  10 + field: ComponentConfigFieldEnum.OPEN_COLOR,
  11 + label: 'ON颜色',
  12 + component: 'ColorPicker',
  13 + changeEvent: 'update:value',
  14 + componentProps: {
  15 + defaultValue: option.openColor,
  16 + },
  17 + },
  18 + {
  19 + field: ComponentConfigFieldEnum.CLOSE_COLOR,
  20 + label: 'OFF颜色',
  21 + component: 'ColorPicker',
  22 + changeEvent: 'update:value',
  23 + componentProps: {
  24 + defaultValue: option.closeColor,
  25 + },
  26 + },
  27 + {
  28 + field: ComponentConfigFieldEnum.SHOW_DEVICE_NAME,
  29 + label: '显示设备名称',
  30 + component: 'Checkbox',
  31 + defaultValue: option.showDeviceName,
  32 + },
  33 + ],
  34 + showActionButtonGroup: false,
  35 + labelWidth: 120,
  36 + baseColProps: {
  37 + span: 12,
  38 + },
  39 + });
  40 +
  41 + const getFormValues = () => {
  42 + return getFieldsValue();
  43 + };
  44 +
  45 + const setFormValues = (data: Recordable) => {
  46 + return setFieldsValue(data);
  47 + };
  48 +
  49 + defineExpose({
  50 + getFormValues,
  51 + setFormValues,
  52 + resetFormValues: resetFields,
  53 + } as PublicFormInstaceType);
  54 +</script>
  55 +
  56 +<template>
  57 + <BasicForm @register="register" />
  58 +</template>
... ...
  1 +<script lang="ts" setup>
  2 + import { commonDataSourceSchemas } from '../../../config/common.config';
  3 + import { BasicForm, useForm } from '/@/components/Form';
  4 + import { PublicFormInstaceType } from '/@/views/visual/dataSourceBindPanel/index.type';
  5 +
  6 + const [register, { getFieldsValue, setFieldsValue, validate, resetFields }] = useForm({
  7 + labelWidth: 0,
  8 + showActionButtonGroup: false,
  9 + layout: 'horizontal',
  10 + labelCol: { span: 0 },
  11 + schemas: commonDataSourceSchemas(),
  12 + });
  13 +
  14 + const getFormValues = () => {
  15 + return getFieldsValue();
  16 + };
  17 +
  18 + const setFormValues = (record: Recordable) => {
  19 + return setFieldsValue(record);
  20 + };
  21 +
  22 + defineExpose({
  23 + getFormValues,
  24 + setFormValues,
  25 + validate,
  26 + resetFormValues: resetFields,
  27 + } as PublicFormInstaceType);
  28 +</script>
  29 +
  30 +<template>
  31 + <BasicForm @register="register" />
  32 +</template>
... ...
  1 +// import { ComponentEnum, ComponentNameEnum } from '../index.type';
  2 +import { useComponentKeys } from '/@/views/visual/packages/hook/useComponentKeys';
  3 +import { ConfigType, PackagesCategoryEnum } from '/@/views/visual/packages/index.type';
  4 +
  5 +const componentKeys = useComponentKeys('SwitchSignalLight');
  6 +export const SwitchSignalLightConfig: ConfigType = {
  7 + ...componentKeys,
  8 + // title: ComponentNameEnum.TEXT_COMPONENT_1,
  9 + title: '开关量信号灯',
  10 + package: PackagesCategoryEnum.OTHER,
  11 +};
... ...
  1 +<script lang="ts" setup>
  2 + import { ComponentPropsConfigType, DataFetchUpdateFn } from '/@/views/visual/packages/index.type';
  3 + import { option } from './config';
  4 + import { useComponentScale } from '/@/views/visual/packages/hook/useComponentScale';
  5 + import { useDataFetch } from '/@/views/visual/packages/hook/useSocket';
  6 + import { computed } from 'vue';
  7 + import { ref, onMounted, unref } from 'vue';
  8 + import { useIntervalFn } from '@vueuse/core';
  9 + import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
  10 + import { useReceiveValue } from '../../../hook/useReceiveValue';
  11 +
  12 + const props = defineProps<{
  13 + config: ComponentPropsConfigType<typeof option>;
  14 + }>();
  15 +
  16 + const isOpenClose = ref<boolean>(true);
  17 +
  18 + const getDesign = computed(() => {
  19 + const { persetOption = {}, option } = props.config;
  20 + const {
  21 + openColor: persetOpenColor,
  22 + closeColor: persetCloseColor,
  23 + showDeviceName: persetShowDeviceName,
  24 + } = persetOption || {};
  25 + const { componentInfo } = option;
  26 +
  27 + const { openColor, closeColor, showDeviceName } = componentInfo || {};
  28 + return {
  29 + openColor: openColor ?? persetOpenColor,
  30 + closeColor: closeColor ?? persetCloseColor,
  31 + showDeviceName: showDeviceName ?? persetShowDeviceName,
  32 + };
  33 + });
  34 +
  35 + const randomFn = () => {
  36 + useIntervalFn(() => {
  37 + isOpenClose.value = !unref(isOpenClose);
  38 + }, 2000);
  39 + };
  40 + const { getNumberValue } = useReceiveValue();
  41 + const updateFn: DataFetchUpdateFn = (message, attribute) => {
  42 + const { data = {} } = message;
  43 + const [latest] = data[attribute] || [];
  44 + const [_, value] = latest;
  45 + isOpenClose.value = Boolean(getNumberValue(value));
  46 + };
  47 +
  48 + onMounted(() => {
  49 + !props.config.option.uuid && randomFn();
  50 + });
  51 +
  52 + useDataFetch(props, updateFn);
  53 +
  54 + const { getScale } = useComponentScale(props);
  55 +</script>
  56 +
  57 +<template>
  58 + <main :style="getScale" class="w-full h-full flex flex-col justify-center items-center">
  59 + <DeviceName :config="config" class="text-center" />
  60 + <div
  61 + :style="{
  62 + '--open-color': getDesign.openColor,
  63 + '--close-color': getDesign.closeColor,
  64 + }"
  65 + :class="isOpenClose ? 'switch_open' : 'switch_close'"
  66 + ></div>
  67 + </main>
  68 +</template>
  69 +<style lang="less" scoped>
  70 + .switch_open {
  71 + background: var(--open-color);
  72 + box-shadow: var(--open-color) 0 0 10px 3px;
  73 + width: 60px;
  74 + height: 60px;
  75 + border-radius: 50%;
  76 + margin: 10px 0;
  77 + }
  78 +
  79 + .switch_close {
  80 + background-color: var(--close-color);
  81 + box-shadow: none;
  82 + width: 42.023px;
  83 + height: 42.023px;
  84 + border-radius: 50%;
  85 + margin: 10px 0;
  86 + }
  87 +</style>
... ...
1 1 import { MonitorVideoConfig } from './MonitorVideo';
2 2 import { PictureConfig } from './Picture';
  3 +import { SwitchSignalLightConfig } from './SwitchSignalLight';
3 4
4   -export const OtherList = [MonitorVideoConfig, PictureConfig];
  5 +export const OtherList = [MonitorVideoConfig, PictureConfig, SwitchSignalLightConfig];
... ...
... ... @@ -19,7 +19,7 @@ export enum GradientColor {
19 19 }
20 20 export const option: PublicPresetOptions = {
21 21 multipleDataSourceComponent: true,
22   - [ComponentConfigFieldEnum.FONT_COLOR]: '#FD7347',
  22 + [ComponentConfigFieldEnum.FONT_COLOR]: '#5470c6',
23 23 [ComponentConfigFieldEnum.SHOW_DEVICE_NAME]: false,
24 24 [ComponentConfigFieldEnum.UNIT]: '℃',
25 25 };
... ...
... ... @@ -59,12 +59,23 @@
59 59 unref(getDesign).dataSource.map((item) => ({
60 60 value: 0,
61 61 name: `${
62   - item.showDeviceName ? item.deviceRename || item.deviceName + '-' + item.attribute : ''
  62 + item.showDeviceName
  63 + ? (item.deviceRename || item.deviceName) + '-' + (item.attributeRename || item.attribute)
  64 + : ''
63 65 }`,
64 66 attribute: item.attribute,
65 67 id: item.id,
  68 + itemStyle: {
  69 + color: item.fontColor,
  70 + },
  71 + tooltip: {
  72 + valueFormatter(value) {
  73 + return `${value} ${item.unit ?? ''}`;
  74 + },
  75 + },
66 76 }))
67 77 );
  78 + // console.log(unref(series), 'series');
68 79
69 80 const options = (): EChartsOption => {
70 81 // getStageColor(gradientInfo);
... ... @@ -133,10 +144,11 @@
133 144 const { forEachGroupMessage } = useReceiveMessage();
134 145 const { getNumberValue } = useReceiveValue();
135 146 const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
136   - forEachGroupMessage(message, deviceId, attribute, (attribute, value) => {
  147 + forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
137 148 series.value.forEach((item) => {
138 149 if (item.id === deviceId && item.attribute === attribute) {
139 150 item.value = getNumberValue(value);
  151 + time.value = timespan;
140 152 }
141 153 });
142 154 });
... ...
... ... @@ -19,7 +19,7 @@ export enum GradientColor {
19 19 }
20 20 export const option: PublicPresetOptions = {
21 21 multipleDataSourceComponent: true,
22   - [ComponentConfigFieldEnum.FONT_COLOR]: '#FD7347',
  22 + [ComponentConfigFieldEnum.FONT_COLOR]: '#5470c6',
23 23 [ComponentConfigFieldEnum.SHOW_DEVICE_NAME]: false,
24 24 [ComponentConfigFieldEnum.UNIT]: '℃',
25 25 };
... ...
... ... @@ -133,15 +133,10 @@
133 133 const series = ref(
134 134 unref(getDesign).dataSource.map((item) => ({
135 135 value: 0,
136   - // name: `${
137   - // item.showDeviceName
138   - // ? item.deviceRename
139   - // ? item.deviceRename
140   - // : item.deviceName + '-' + item.attribute
141   - // : ''
142   - // }`,
143 136 name: `${
144   - item.showDeviceName ? item.deviceRename || item.deviceName + '-' + item.attribute : ''
  137 + item.showDeviceName
  138 + ? (item.deviceRename || item.deviceName) + '-' + (item.attributeRename || item.attribute)
  139 + : ''
145 140 }`,
146 141 itemStyle: { color: item.fontColor },
147 142 attribute: item.attribute,
... ... @@ -155,10 +150,12 @@
155 150 );
156 151
157 152 const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
158   - forEachGroupMessage(message, deviceId, attribute, (attribute, value) => {
  153 + // console.log(unref(series), 'series', unref(getDesign).dataSource);
  154 + forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
159 155 series.value.forEach((item) => {
160 156 if (item.id === deviceId && item.attribute === attribute) {
161 157 item.value = getNumberValue(value);
  158 + time.value = timespan;
162 159 }
163 160 });
164 161 });
... ... @@ -175,7 +172,6 @@
175 172 show: false,
176 173 },
177 174 };
178   - // console.log([...toRaw(unref(series)), option], 'series');
179 175 updateChart([...toRaw(unref(series)), option]);
180 176 };
181 177
... ...
... ... @@ -9,6 +9,7 @@
9 9 import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
10 10 import { unref } from 'vue';
11 11 import { onMounted } from 'vue';
  12 + import { UpdateTime } from '/@/views/visual/commonComponents/UpdateTime';
12 13 import { useReceiveMessage } from '../../../hook/useReceiveMessage';
13 14 import { buildUUID } from '/@/utils/uuid';
14 15 import { useReceiveValue } from '../../../hook/useReceiveValue';
... ... @@ -17,6 +18,8 @@
17 18 config: ComponentPropsConfigType<typeof option>;
18 19 }>();
19 20
  21 + const time = ref<Nullable<number>>(null);
  22 +
20 23 interface PercentType {
21 24 value?: number;
22 25 fontColor: string;
... ... @@ -49,15 +52,6 @@
49 52 attribute: '3',
50 53 id: buildUUID(),
51 54 },
52   - {
53   - value: 49,
54   - fontColor: '#2196F3',
55   - backgroundColor: '#2196F3',
56   - unit: '℃',
57   - deviceName: '温度',
58   - attribute: '2',
59   - id: buildUUID(),
60   - },
61 55 ];
62 56
63 57 const getDesign = computed(() => {
... ... @@ -93,10 +87,11 @@
93 87
94 88 const { getNumberValue } = useReceiveValue();
95 89 const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
96   - forEachGroupMessage(message, deviceId, attribute, (attribute, value) => {
  90 + forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
97 91 percentList.value.forEach((item) => {
98 92 if (item.id === deviceId && item.attribute === attribute) {
99 93 item.value = getNumberValue(value);
  94 + time.value = timespan;
100 95 }
101 96 });
102 97 });
... ... @@ -111,10 +106,18 @@
111 106 <main class="w-full h-full flex flex-col justify-center">
112 107 <DeviceName :config="config" />
113 108
114   - <div v-for="item in percentList" :key="item.id" class="flex flex-col ml-3 mr-3 items-stretch">
  109 + <div
  110 + v-for="item in percentList"
  111 + :key="item.id"
  112 + class="mt-2 flex flex-col ml-3 mr-3 items-stretch"
  113 + >
115 114 <div class="flex justify-between">
116 115 <div class="text-gray-500 text-lg truncate" :style="{ color: item.fontColor }">
117   - {{ item.deviceRename || item.deviceName + '-' + item.attribute || '温度' }}
  116 + {{
  117 + (item.deviceRename || item.deviceName) +
  118 + '-' +
  119 + (item.attributeRename || item.attribute) || '温度'
  120 + }}
118 121 </div>
119 122 <span class="text-lg" :style="{ color: item.fontColor }"
120 123 >{{ item.value }} {{ item.unit }}</span
... ... @@ -131,6 +134,7 @@
131 134 /> -->
132 135 </div>
133 136 </div>
  137 + <UpdateTime :time="time" />
134 138 </main>
135 139 </template>
136 140 <style lang="less" scoped>
... ...
... ... @@ -5,6 +5,7 @@
5 5 import { useMultipleDataFetch } from '/@/views/visual/packages/hook/useSocket';
6 6 import { ref, unref } from 'vue';
7 7 import { SvgIcon } from '/@/components/Icon';
  8 + import { UpdateTime } from '/@/views/visual/commonComponents/UpdateTime';
8 9 import { computed } from 'vue';
9 10 import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
10 11 import { useReceiveMessage } from '../../../hook/useReceiveMessage';
... ... @@ -14,6 +15,8 @@
14 15 config: ComponentPropsConfigType<typeof option>;
15 16 }>();
16 17
  18 + const time = ref<Nullable<number>>(null);
  19 +
17 20 const getDesign = computed(() => {
18 21 const { persetOption = {}, option } = props.config;
19 22 const { dataSource = [] } = option || {};
... ... @@ -78,23 +81,11 @@
78 81
79 82 const updateFn: MultipleDataFetchUpdateFn = (message, deviceId, attribute) => {
80 83 // console.log(unref(getDesign).dataSource, 'dataSource');
81   - forEachGroupMessage(message, deviceId, attribute, (attribute, value) => {
82   - // unref(getDesign).dataSource.forEach((item) => {
83   - // if (item.id === deviceId && item.attribute === attribute) {
84   - // svgList.value = unref(getDesign).dataSource.map((item) => {
85   - // return {
86   - // value: getNumberValue(value),
87   - // name: item.deviceRename || item.deviceName,
88   - // icon: item.icon,
89   - // unit: item.unit,
90   - // fontColor: item.fontColor,
91   - // iconColor: item.iconColor,
92   - // };
93   - // });
94   - // }
  84 + forEachGroupMessage(message, deviceId, attribute, (attribute, value, timespan) => {
95 85 updateSvgList.value.forEach((item) => {
96 86 if (item.id === deviceId && item.attribute === attribute) {
97 87 item.value = getNumberValue(value);
  88 + time.value = timespan;
98 89 }
99 90 });
100 91 // });
... ... @@ -139,7 +130,9 @@
139 130 />
140 131
141 132 <div class="text-gray-500 text-lg truncate ml-6">{{
142   - item.deviceRename || item.deviceName || '温度'
  133 + item.deviceRename ||
  134 + item.deviceName + '-' + (item.attributeRename || item.attribute) ||
  135 + '温度'
143 136 }}</div>
144 137 </div>
145 138
... ... @@ -148,5 +141,6 @@
148 141 <span>{{ item.unit }} </span>
149 142 </h1>
150 143 </div>
  144 + <UpdateTime :time="time" />
151 145 </main>
152 146 </template>
... ...