|
@@ -2,19 +2,26 @@ |
|
@@ -2,19 +2,26 @@ |
2
|
import { ComponentPropsConfigType, DataFetchUpdateFn } from '/@/views/visual/packages/index.type';
|
2
|
import { ComponentPropsConfigType, DataFetchUpdateFn } from '/@/views/visual/packages/index.type';
|
3
|
import { option } from './config';
|
3
|
import { option } from './config';
|
4
|
import { useDataFetch } from '/@/views/visual/packages/hook/useSocket';
|
4
|
import { useDataFetch } from '/@/views/visual/packages/hook/useSocket';
|
5
|
- import { Slider } from 'ant-design-vue';
|
|
|
6
|
- import { computed, ref } from 'vue';
|
5
|
+ import { Slider, Spin } from 'ant-design-vue';
|
|
|
6
|
+ import { computed, ref, unref } from 'vue';
|
7
|
import { useComponentScale } from '../../../hook/useComponentScale';
|
7
|
import { useComponentScale } from '../../../hook/useComponentScale';
|
8
|
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
|
8
|
import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
|
|
|
9
|
+ import { useSendCommand } from '../../../hook/useSendCommand';
|
|
|
10
|
+ // import { useDebounceFn } from '@vueuse/core';
|
|
|
11
|
+ // import { simpleDebounce } from '/@/utils/common/compUtils';
|
|
|
12
|
+ import { useReceiveValue } from '../../../hook/useReceiveValue';
|
9
|
|
13
|
|
10
|
const props = defineProps<{
|
14
|
const props = defineProps<{
|
11
|
config: ComponentPropsConfigType<typeof option>;
|
15
|
config: ComponentPropsConfigType<typeof option>;
|
12
|
}>();
|
16
|
}>();
|
13
|
|
17
|
|
14
|
const sliderValue = ref<number>(33);
|
18
|
const sliderValue = ref<number>(33);
|
|
|
19
|
+ const oldSliderValue = ref<number>(33);
|
15
|
const sMin = ref<number>(0);
|
20
|
const sMin = ref<number>(0);
|
16
|
const sMax = ref<number>(100);
|
21
|
const sMax = ref<number>(100);
|
17
|
|
22
|
|
|
|
23
|
+ const { loading, sendCommand } = useSendCommand();
|
|
|
24
|
+
|
18
|
const getDesign = computed(() => {
|
25
|
const getDesign = computed(() => {
|
19
|
const { option, persetOption } = props.config;
|
26
|
const { option, persetOption } = props.config;
|
20
|
const { componentInfo, attribute, attributeRename } = option;
|
27
|
const { componentInfo, attribute, attributeRename } = option;
|
|
@@ -28,10 +35,32 @@ |
|
@@ -28,10 +35,32 @@ |
28
|
};
|
35
|
};
|
29
|
});
|
36
|
});
|
30
|
|
37
|
|
31
|
- const handleChange = async () => {};
|
38
|
+ const index = ref<number>(0);
|
|
|
39
|
+
|
|
|
40
|
+ const handleChange = async (e) => {
|
|
|
41
|
+ console.log(e);
|
|
|
42
|
+ index.value++;
|
|
|
43
|
+ if (index.value == 1) {
|
|
|
44
|
+ oldSliderValue.value = unref(sliderValue);
|
|
|
45
|
+ }
|
|
|
46
|
+ sliderValue.value = e;
|
|
|
47
|
+ };
|
|
|
48
|
+
|
|
|
49
|
+ // const debounceChanage = useDebounceFn(handleChange, 1);
|
|
|
50
|
+
|
|
|
51
|
+ const handleAfterChange = async (e) => {
|
|
|
52
|
+ const flag = await sendCommand(props.config.option, unref(sliderValue));
|
|
|
53
|
+ flag
|
|
|
54
|
+ ? ((sliderValue.value = e), (oldSliderValue.value = sliderValue.value), (index.value = 0))
|
|
|
55
|
+ : (sliderValue.value = unref(oldSliderValue));
|
|
|
56
|
+ };
|
32
|
|
57
|
|
33
|
- const updateFn: DataFetchUpdateFn = () => {
|
|
|
34
|
- // console.log(message, 'message', attribute, 'attribute');
|
58
|
+ const { getNumberValue } = useReceiveValue();
|
|
|
59
|
+ const updateFn: DataFetchUpdateFn = (message, attribute) => {
|
|
|
60
|
+ const { data = {} } = message;
|
|
|
61
|
+ const [latest] = data[attribute] || [];
|
|
|
62
|
+ const [_, value] = latest;
|
|
|
63
|
+ sliderValue.value = getNumberValue(value);
|
35
|
};
|
64
|
};
|
36
|
|
65
|
|
37
|
useDataFetch(props, updateFn);
|
66
|
useDataFetch(props, updateFn);
|
|
@@ -42,28 +71,31 @@ |
|
@@ -42,28 +71,31 @@ |
42
|
<main class="w-full h-full flex flex-col justify-center">
|
71
|
<main class="w-full h-full flex flex-col justify-center">
|
43
|
<DeviceName :config="config" class="text-center" />
|
72
|
<DeviceName :config="config" class="text-center" />
|
44
|
<main :style="getScale">
|
73
|
<main :style="getScale">
|
45
|
- <div class="flex flex-col ml-11 mr-11">
|
|
|
46
|
- <span
|
|
|
47
|
- :style="{ color: getDesign.fontColor }"
|
|
|
48
|
- class="font-bold text-xl mt-3 truncate text-center"
|
|
|
49
|
- >{{ sliderValue }}</span
|
|
|
50
|
- >
|
|
|
51
|
- <Slider
|
|
|
52
|
- :style="{ '--slider-color': getDesign.controlBarColor }"
|
|
|
53
|
- class="no-drag"
|
|
|
54
|
- v-model:value="sliderValue"
|
|
|
55
|
- :min="sMin"
|
|
|
56
|
- :max="sMax"
|
|
|
57
|
- @change="handleChange"
|
|
|
58
|
- />
|
74
|
+ <Spin :spinning="loading" class="w-full h-full">
|
|
|
75
|
+ <div class="flex flex-col ml-11 mr-11 w-full">
|
|
|
76
|
+ <span
|
|
|
77
|
+ :style="{ color: getDesign.fontColor }"
|
|
|
78
|
+ class="font-bold text-xl mt-3 truncate text-center"
|
|
|
79
|
+ >{{ sliderValue }}</span
|
|
|
80
|
+ >
|
|
|
81
|
+ <Slider
|
|
|
82
|
+ :style="{ '--slider-color': getDesign.controlBarColor }"
|
|
|
83
|
+ class="no-drag"
|
|
|
84
|
+ :value="sliderValue"
|
|
|
85
|
+ :min="sMin"
|
|
|
86
|
+ :max="sMax"
|
|
|
87
|
+ @change="handleChange"
|
|
|
88
|
+ @afterChange="handleAfterChange"
|
|
|
89
|
+ />
|
59
|
|
90
|
|
60
|
- <span
|
|
|
61
|
- :style="{ color: getDesign.fontColor }"
|
|
|
62
|
- class="mt-3 truncate font-bold text-xs text-center"
|
|
|
63
|
- >
|
|
|
64
|
- {{ getDesign.attribute || '设备1' }}
|
|
|
65
|
- </span>
|
|
|
66
|
- </div>
|
91
|
+ <span
|
|
|
92
|
+ :style="{ color: getDesign.fontColor }"
|
|
|
93
|
+ class="mt-3 truncate font-bold text-xs text-center"
|
|
|
94
|
+ >
|
|
|
95
|
+ {{ getDesign.attribute || '设备1' }}
|
|
|
96
|
+ </span>
|
|
|
97
|
+ </div>
|
|
|
98
|
+ </Spin>
|
67
|
</main>
|
99
|
</main>
|
68
|
</main>
|
100
|
</main>
|
69
|
</template>
|
101
|
</template>
|