Commit 49580d56eab7abaca894f76fed15832131ab239f

Authored by xp.Huang
2 parents 3d1bafd3 066e6183

Merge branch 'fix/components-lateralNumericalControl' into 'main_dev'

fix: 修改控制组件滑块

See merge request yunteng/thingskit-front!697
... ... @@ -2,19 +2,24 @@
2 2 import { ComponentPropsConfigType, DataFetchUpdateFn } from '/@/views/visual/packages/index.type';
3 3 import { option } from './config';
4 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 7 import { useComponentScale } from '../../../hook/useComponentScale';
8 8 import { DeviceName } from '/@/views/visual/commonComponents/DeviceName';
  9 + import { useSendCommand } from '../../../hook/useSendCommand';
  10 + import { useReceiveValue } from '../../../hook/useReceiveValue';
9 11
10 12 const props = defineProps<{
11 13 config: ComponentPropsConfigType<typeof option>;
12 14 }>();
13 15
14 16 const sliderValue = ref<number>(33);
  17 + const oldSliderValue = ref<number>(33);
15 18 const sMin = ref<number>(0);
16 19 const sMax = ref<number>(100);
17 20
  21 + const { loading, sendCommand } = useSendCommand();
  22 +
18 23 const getDesign = computed(() => {
19 24 const { option, persetOption } = props.config;
20 25 const { componentInfo, attribute, attributeRename } = option;
... ... @@ -28,10 +33,29 @@
28 33 };
29 34 });
30 35
31   - const handleChange = async () => {};
  36 + const index = ref<number>(0);
  37 +
  38 + const handleChange = async (e) => {
  39 + index.value++;
  40 + if (index.value == 1) {
  41 + oldSliderValue.value = unref(sliderValue);
  42 + }
  43 + sliderValue.value = e;
  44 + };
  45 +
  46 + const handleAfterChange = async (e) => {
  47 + const flag = await sendCommand(props.config.option, unref(sliderValue));
  48 + flag
  49 + ? ((sliderValue.value = e), (oldSliderValue.value = sliderValue.value), (index.value = 0))
  50 + : (sliderValue.value = unref(oldSliderValue));
  51 + };
32 52
33   - const updateFn: DataFetchUpdateFn = () => {
34   - // console.log(message, 'message', attribute, 'attribute');
  53 + const { getNumberValue } = useReceiveValue();
  54 + const updateFn: DataFetchUpdateFn = (message, attribute) => {
  55 + const { data = {} } = message;
  56 + const [latest] = data[attribute] || [];
  57 + const [_, value] = latest;
  58 + sliderValue.value = getNumberValue(value);
35 59 };
36 60
37 61 useDataFetch(props, updateFn);
... ... @@ -42,28 +66,31 @@
42 66 <main class="w-full h-full flex flex-col justify-center">
43 67 <DeviceName :config="config" class="text-center" />
44 68 <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   - />
  69 + <Spin :spinning="loading" class="w-full h-full">
  70 + <div class="flex flex-col ml-11 mr-11 w-full">
  71 + <span
  72 + :style="{ color: getDesign.fontColor }"
  73 + class="font-bold text-xl mt-3 truncate text-center"
  74 + >{{ sliderValue }}</span
  75 + >
  76 + <Slider
  77 + :style="{ '--slider-color': getDesign.controlBarColor }"
  78 + class="no-drag"
  79 + :value="sliderValue"
  80 + :min="sMin"
  81 + :max="sMax"
  82 + @change="handleChange"
  83 + @afterChange="handleAfterChange"
  84 + />
59 85
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>
  86 + <span
  87 + :style="{ color: getDesign.fontColor }"
  88 + class="mt-3 truncate font-bold text-xs text-center"
  89 + >
  90 + {{ getDesign.attribute || '设备1' }}
  91 + </span>
  92 + </div>
  93 + </Spin>
67 94 </main>
68 95 </main>
69 96 </template>
... ...
... ... @@ -244,7 +244,9 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
244 244 return await getDeviceAttribute({
245 245 deviceProfileId,
246 246 dataType:
247   - isControlComponent(category!) || isBooleanComponent(unref(selectWidgetKeys))
  247 + (isControlComponent(category!) &&
  248 + unref(selectWidgetKeys).componentKey !== 'LateralNumericalControl') ||
  249 + isBooleanComponent(unref(selectWidgetKeys))
248 250 ? DataTypeEnum.IS_BOOL
249 251 : undefined,
250 252 });
... ...