Commit 30d58ef16e09755b1f5b6d0a0b20ada7a481e06d

Authored by ww
1 parent 298b67ed

feat: add sliding switch component && switch with icon component

src/views/visual/board/components/ControlComponent/SlidingSwitch.vue renamed from src/views/visual/board/components/Other/SlidingSwitch.vue
... ... @@ -40,12 +40,9 @@
40 40 .slider {
41 41 width: 80px;
42 42 height: 40px;
  43 + display: flex;
  44 + align-items: center;
43 45 box-sizing: border-box;
44   - position: absolute;
45   - top: 0;
46   - left: 0;
47   - right: 0;
48   - bottom: 0;
49 46 border: 2px solid #ecf0f3;
50 47 border-radius: 20px;
51 48 box-shadow: -2px -2px 8px #fff, -2px -2px 12px hsl(0deg 0% 100% / 50%),
... ... @@ -57,15 +54,14 @@
57 54 }
58 55
59 56 .slider::after {
60   - position: absolute;
61 57 cursor: pointer;
62 58 display: block;
63 59 content: '';
64 60 width: 24px;
65 61 height: 24px;
66 62 border-radius: 50%;
67   - top: 6px;
68   - left: 6px;
  63 + margin-left: 6px;
  64 + margin-right: 6px;
69 65 background-color: #ecf0f3;
70 66 box-shadow: -2px -2px 8px #fff, -2px -2px 12px hsl(0deg 0% 100% / 50%),
71 67 inset 2px 2px 4px hsl(0deg 0% 100% / 10%), 2px 2px 8px rgb(0 0 0 / 30%);
... ... @@ -80,13 +76,16 @@
80 76 input:checked ~ .slider::after {
81 77 transform: translateX(35px);
82 78 }
  79 +
83 80 input:not(:checked) ~ .on {
84 81 opacity: 0;
85   - transform: translateX(0px);
  82 + transform: translateX(0);
86 83 }
87 84
88 85 .on,
89 86 .off {
  87 + position: absolute;
  88 + top: 0;
90 89 display: inline-block;
91 90 margin-left: 3px;
92 91 width: 34px;
... ... @@ -97,7 +96,9 @@
97 96 .on {
98 97 color: #039be5;
99 98 }
  99 +
100 100 .off {
  101 + right: 6px;
101 102 color: #999;
102 103 }
103 104 }
... ...
  1 +<script lang="ts" setup>
  2 + import { Switch } from 'ant-design-vue';
  3 + import { computed } from 'vue';
  4 + import { DEFAULT_RADIO_RECORD, fontSize, RadioRecord } from '../../detail/config/util';
  5 + import SvgIcon from '/@/components/Icon/src/SvgIcon.vue';
  6 + import {
  7 + ControlComponentDefaultConfig,
  8 + ControlComponentValue,
  9 + ControlComponentLayout,
  10 + } from './control.config';
  11 + const props = withDefaults(
  12 + defineProps<{
  13 + layout?: ControlComponentLayout;
  14 + value?: ControlComponentValue;
  15 + radio?: RadioRecord;
  16 + }>(),
  17 + {
  18 + value: () => ControlComponentDefaultConfig,
  19 + }
  20 + );
  21 + const getRadio = computed(() => {
  22 + return props.radio || DEFAULT_RADIO_RECORD;
  23 + });
  24 +</script>
  25 +
  26 +<template>
  27 + <div class="flex items-center w-full h-full p-4">
  28 + <div class="flex-auto flex truncate">
  29 + <SvgIcon
  30 + :name="props.value?.icon!"
  31 + prefix="iconfont"
  32 + :style="{
  33 + color: props.value?.iconColor,
  34 + width: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }),
  35 + height: fontSize({ radioRecord: getRadio, basic: 30, min: 16 }),
  36 + }"
  37 + />
  38 + <span class="flex-auto mx-4 flex items-center truncate inline-block">属性名</span>
  39 + </div>
  40 + <Switch />
  41 + </div>
  42 +</template>
... ...
src/views/visual/board/components/ControlComponent/control.config.ts renamed from src/views/visual/board/components/ControlComponent/toggleSwitch.config.ts
1 1 import { DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
2 2
3   -export interface ToggleSwitchValue {
  3 +export interface ControlComponentLayout {
  4 + [key: string]: any;
  5 +}
  6 +
  7 +export interface ControlComponentValue {
4 8 value?: boolean;
  9 + name?: string;
  10 + icon?: string;
  11 + iconColor?: string;
5 12 }
6 13
  14 +export const ControlComponentDefaultConfig: ControlComponentValue = {
  15 + icon: 'shuiwen',
  16 + iconColor: '#367BFF',
  17 +};
  18 +
7 19 export const transformControlConfig = (
8 20 _ComponentConfig: Recordable,
9 21 _record: DataComponentRecord,
10 22 dataSourceRecord: DataSource
11 23 ) => {
12 24 return {
13   - value: dataSourceRecord.componentInfo.value,
  25 + value: {
  26 + value: dataSourceRecord.componentInfo.value,
  27 + icon: dataSourceRecord.componentInfo.icon,
  28 + } as ControlComponentValue,
14 29 };
15 30 };
... ...
1 1 import { Component } from 'vue';
2   -import TextComponent from './TextComponent/TextComponent.vue';
3 2 import {
4 3 TextComponent1Config,
5 4 TextComponent3Config,
... ... @@ -9,8 +8,6 @@ import {
9 8 transformTextComponentConfig,
10 9 } from './TextComponent/config';
11 10 import { ComponentInfo, DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
12   -import DashBoardComponent from './InstrumentComponent/DashBoardComponent.vue';
13   -import PictureComponent from './PictureComponent/PictureComponent.vue';
14 11 import { transformPictureConfig } from './PictureComponent/pictureComponent.config';
15 12 import {
16 13 DashboardComponentLayout,
... ... @@ -20,10 +17,16 @@ import {
20 17 instrumentComponent2,
21 18 transformDashboardComponentConfig,
22 19 } from './InstrumentComponent/dashBoardComponent.config';
23   -import DigitalDashBoard from './InstrumentComponent/DigitalDashBoard.vue';
24 20 import { DigitalComponentDefaultConfig } from './InstrumentComponent/digitalDashBoard.config';
  21 +import { transformControlConfig } from './ControlComponent/control.config';
  22 +
  23 +import TextComponent from './TextComponent/TextComponent.vue';
  24 +import DashBoardComponent from './InstrumentComponent/DashBoardComponent.vue';
  25 +import PictureComponent from './PictureComponent/PictureComponent.vue';
  26 +import DigitalDashBoard from './InstrumentComponent/DigitalDashBoard.vue';
25 27 import ToggleSwitch from './ControlComponent/ToggleSwitch.vue';
26   -import { transformControlConfig } from './ControlComponent/toggleSwitch.config';
  28 +import SlidingSwitch from './ControlComponent/SlidingSwitch.vue';
  29 +import SwitchWithIcon from './ControlComponent/SwitchWithIcon.vue';
27 30
28 31 export enum FrontComponentCategory {
29 32 TEXT = 'text',
... ... @@ -52,6 +55,8 @@ export enum FrontComponent {
52 55 DIGITAL_DASHBOARD_COMPONENT = 'digital-dashboard-component',
53 56 PICTURE_COMPONENT_1 = 'picture-component-1',
54 57 CONTROL_COMPONENT_TOGGLE_SWITCH = 'control-component-toggle-switch',
  58 + CONTROL_COMPONENT_SWITCH_WITH_ICON = 'control-component-switch-with-icon',
  59 + CONTROL_COMPONENT_SLIDING_SWITCH = 'control-component-sliding-switch',
55 60 }
56 61
57 62 export interface ComponentConfig {
... ... @@ -138,6 +143,20 @@ frontComponentMap.set(FrontComponent.PICTURE_COMPONENT_1, {
138 143 transformConfig: transformPictureConfig,
139 144 });
140 145
  146 +frontComponentMap.set(FrontComponent.CONTROL_COMPONENT_SWITCH_WITH_ICON, {
  147 + Component: SwitchWithIcon,
  148 + ComponentKey: FrontComponent.CONTROL_COMPONENT_SWITCH_WITH_ICON,
  149 + ComponentCategory: FrontComponentCategory.CONTROL,
  150 + transformConfig: transformControlConfig,
  151 +});
  152 +
  153 +frontComponentMap.set(FrontComponent.CONTROL_COMPONENT_SLIDING_SWITCH, {
  154 + Component: SlidingSwitch,
  155 + ComponentKey: FrontComponent.CONTROL_COMPONENT_SLIDING_SWITCH,
  156 + ComponentCategory: FrontComponentCategory.CONTROL,
  157 + transformConfig: transformControlConfig,
  158 +});
  159 +
141 160 frontComponentMap.set(FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH, {
142 161 Component: ToggleSwitch,
143 162 ComponentKey: FrontComponent.CONTROL_COMPONENT_TOGGLE_SWITCH,
... ...
... ... @@ -2,7 +2,7 @@
2 2 import { CopyOutlined, DeleteOutlined, SettingOutlined } from '@ant-design/icons-vue';
3 3 import { Tooltip, Button } from 'ant-design-vue';
4 4 import { FormActionType, useForm } from '/@/components/Form';
5   - import { basicSchema, dataSourceSchema } from '../config/basicConfiguration';
  5 + import { basicSchema } from '../config/basicConfiguration';
6 6 import BasicForm from '/@/components/Form/src/BasicForm.vue';
7 7 import { ref, shallowReactive, unref, nextTick, watch } from 'vue';
8 8 import VisualOptionsModal from './VisualOptionsModal.vue';
... ... @@ -13,6 +13,7 @@
13 13 import { DataBoardLayoutInfo } from '../../types/type';
14 14 import { FrontComponent } from '../../components/help';
15 15 import { computed } from '@vue/reactivity';
  16 + import BasicDataSourceForm from './DataSourceForm/BasicDataSourceForm.vue';
16 17
17 18 type DataSourceFormEL = { [key: string]: Nullable<FormActionType> };
18 19
... ... @@ -196,17 +197,7 @@
196 197 选择设备
197 198 </div>
198 199 <div class="pl-2 flex-auto">
199   - <BasicForm
200   - :ref="(el) => setFormEl(el, item.id)"
201   - :schemas="dataSourceSchema"
202   - class="w-full flex-1 data-source-form"
203   - :show-action-button-group="false"
204   - :row-props="{
205   - gutter: 10,
206   - }"
207   - layout="inline"
208   - :label-col="{ span: 0 }"
209   - />
  200 + <BasicDataSourceForm :ref="(el) => setFormEl(el, item.id)" />
210 201 </div>
211 202 <div class="flex justify-center gap-3 w-24">
212 203 <Tooltip title="复制">
... ...
  1 +<script lang="ts" setup>
  2 + import { ref } from 'vue';
  3 + import { dataSourceSchema } from '../../config/basicConfiguration';
  4 + import { FormActionType } from '/@/components/Form';
  5 + import BasicForm from '/@/components/Form/src/BasicForm.vue';
  6 + const formEl = ref<Nullable<FormActionType>>(null);
  7 +
  8 + defineExpose({ formActionType: formEl });
  9 +</script>
  10 +
  11 +<template>
  12 + <BasicForm
  13 + ref="formEl"
  14 + :schemas="dataSourceSchema"
  15 + class="w-full flex-1 data-source-form"
  16 + :show-action-button-group="false"
  17 + :row-props="{
  18 + gutter: 10,
  19 + }"
  20 + layout="inline"
  21 + :label-col="{ span: 0 }"
  22 + />
  23 +</template>
... ...
... ... @@ -185,6 +185,10 @@
185 185 openModal(true, { isEdit: false });
186 186 };
187 187
  188 + onMounted(() => {
  189 + handleOpenCreatePanel();
  190 + });
  191 +
188 192 const getLayoutInfo = () => {
189 193 return unref(dataBoardList).map((item) => {
190 194 return {
... ...