config.vue
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script lang="ts" setup>
  import { ComponentConfigFieldEnum } from '/@/views/visual/packages/enum';
  import { useForm, BasicForm } from '/@/components/Form';
  import { PublicFormInstaceType } from '/@/views/visual/dataSourceBindPanel/index.type';
  import { option } from './config';
  import { nextTick } from 'vue';
  const [register, { getFieldsValue, setFieldsValue, resetFields }] = useForm({
    schemas: [
      {
        field: ComponentConfigFieldEnum.FONT_COLOR,
        label: '数值字体颜色',
        component: 'ColorPicker',
        changeEvent: 'update:value',
        componentProps: {
          defaultValue: option.fontColor,
        },
      },
      {
        field: ComponentConfigFieldEnum.BACKGROUND_COLOR,
        label: '进度条背景色',
        component: 'ColorPicker',
        changeEvent: 'update:value',
        componentProps: {
          defaultValue: option.backgroundColor,
        },
      },
      {
        field: ComponentConfigFieldEnum.VALUE_SIZE,
        label: '数值字体大小',
        component: 'InputNumber',
        defaultValue: 20,
        componentProps: {
          min: 0,
          max: 100,
          formatter: (e) => {
            const value = e?.toString().replace(/^0/g, '');
            if (value) {
              return value.replace(/^0/g, '');
            } else {
              return 0;
            }
          },
        },
      },
      {
        field: ComponentConfigFieldEnum.FONT_SIZE,
        label: '文本字体大小',
        component: 'InputNumber',
        defaultValue: 14,
        componentProps: {
          min: 0,
          max: 100,
          formatter: (e) => {
            const value = e?.toString().replace(/^0/g, '');
            if (value) {
              return value.replace(/^0/g, '');
            } else {
              return 0;
            }
          },
        },
      },
      {
        field: ComponentConfigFieldEnum.MAX_NUMBER,
        label: '最大值',
        component: 'InputNumber',
        defaultValue: 100,
        componentProps: ({ formActionType }) => {
          const { setFieldsValue } = formActionType;
          return {
            placeholder: '请输入最大值',
            min: 100,
            onChange: async (e) => {
              if (!e) {
                await nextTick();
                setFieldsValue({
                  [ComponentConfigFieldEnum.MAX_NUMBER]: 100,
                });
              }
            },
          };
        },
      },
      {
        field: ComponentConfigFieldEnum.UNIT,
        label: '数值单位',
        component: 'Input',
        defaultValue: option.unit,
      },
      // {
      //   field: ComponentConfigFieldEnum.SHOW_DEVICE_NAME,
      //   label: '显示设备名称',
      //   component: 'Checkbox',
      // },
    ],
    showActionButtonGroup: false,
    labelWidth: 120,
    baseColProps: {
      span: 12,
    },
  });
  const getFormValues = () => {
    return getFieldsValue();
  };
  const setFormValues = (data: Recordable) => {
    return setFieldsValue(data);
  };
  defineExpose({
    getFormValues,
    setFormValues,
    resetFormValues: resetFields,
  } as PublicFormInstaceType);
</script>
<template>
  <BasicForm @register="register" />
</template>