Blame view

src/views/demo/form/index.vue 5.22 KB
陈文彬 authored
1
<template>
2
  <PageWrapper title="表单基础示例">
陈文彬 authored
3
4
    <CollapseContainer title="基础示例">
      <BasicForm
5
        autoFocusFirstItem
陈文彬 authored
6
7
8
9
10
11
        :labelWidth="100"
        :schemas="schemas"
        :actionColOptions="{ span: 24 }"
        @submit="handleSubmit"
      />
    </CollapseContainer>
12
  </PageWrapper>
陈文彬 authored
13
14
</template>
<script lang="ts">
15
  import { defineComponent, ref } from 'vue';
陈文彬 authored
16
17
18
  import { BasicForm, FormSchema } from '/@/components/Form/index';
  import { CollapseContainer } from '/@/components/Container/index';
  import { useMessage } from '/@/hooks/web/useMessage';
19
  import { PageWrapper } from '/@/components/Page';
20
21
  import { optionsListApi } from '/@/api/demo/select';
陈文彬 authored
22
23
24
25
26
  const schemas: FormSchema[] = [
    {
      field: 'field1',
      component: 'Input',
      label: '字段1',
27
陈文彬 authored
28
29
30
      colProps: {
        span: 8,
      },
31
32
33
34
35
      // componentProps:{},
      // can func
      componentProps: ({ schema, formModel }) => {
        console.log('form:', schema);
        console.log('formModel:', formModel);
36
37
38
39
40
41
        return {
          placeholder: '自定义placeholder',
          onChange: (e: any) => {
            console.log(e);
          },
        };
陈文彬 authored
42
      },
43
44
45
46
47
48
      renderComponentContent: () => {
        return {
          prefix: () => 'pSlot',
          suffix: () => 'sSlot',
        };
      },
陈文彬 authored
49
50
51
52
    },
    {
      field: 'field2',
      component: 'Input',
53
      label: '带后缀',
54
      defaultValue: '111',
陈文彬 authored
55
56
57
      colProps: {
        span: 8,
      },
58
59
60
61
62
      componentProps: {
        onChange: (e: any) => {
          console.log(e);
        },
      },
63
      suffix: '天',
陈文彬 authored
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
122
123
124
125
126
127
128
129
130
131
132
133
134
    },
    {
      field: 'field3',
      component: 'DatePicker',
      label: '字段3',
      colProps: {
        span: 8,
      },
    },
    {
      field: 'field4',
      component: 'Select',
      label: '字段4',
      colProps: {
        span: 8,
      },
      componentProps: {
        options: [
          {
            label: '选项1',
            value: '1',
            key: '1',
          },
          {
            label: '选项2',
            value: '2',
            key: '2',
          },
        ],
      },
    },
    {
      field: 'field5',
      component: 'CheckboxGroup',
      label: '字段5',
      colProps: {
        span: 8,
      },
      componentProps: {
        options: [
          {
            label: '选项1',
            value: '1',
          },
          {
            label: '选项2',
            value: '2',
          },
        ],
      },
    },
    {
      field: 'field7',
      component: 'RadioGroup',
      label: '字段7',
      colProps: {
        span: 8,
      },
      componentProps: {
        options: [
          {
            label: '选项1',
            value: '1',
          },
          {
            label: '选项2',
            value: '2',
          },
        ],
      },
    },
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
    {
      field: 'field8',
      component: 'Checkbox',
      label: '字段8',
      colProps: {
        span: 8,
      },
      renderComponentContent: 'Check',
    },
    {
      field: 'field9',
      component: 'Switch',
      label: '字段9',
      colProps: {
        span: 8,
      },
    },
    {
      field: 'field10',
      component: 'RadioButtonGroup',
      label: '字段10',
      colProps: {
        span: 8,
      },
      componentProps: {
        options: [
          {
            label: '选项1',
            value: '1',
          },
          {
            label: '选项2',
            value: '2',
          },
        ],
      },
    },
    {
      field: 'field11',
      component: 'Cascader',
      label: '字段11',
      colProps: {
        span: 8,
      },
      componentProps: {
        options: [
          {
            value: 'zhejiang',
            label: 'Zhejiang',
            children: [
              {
                value: 'hangzhou',
                label: 'Hangzhou',
                children: [
                  {
                    value: 'xihu',
                    label: 'West Lake',
                  },
                ],
              },
            ],
          },
          {
            value: 'jiangsu',
            label: 'Jiangsu',
            children: [
              {
                value: 'nanjing',
                label: 'Nanjing',
                children: [
                  {
                    value: 'zhonghuamen',
                    label: 'Zhong Hua Men',
                  },
                ],
              },
            ],
          },
        ],
      },
    },
216
217
218
219
220
221
222
223
224
225
226
227

    {
      field: 'field30',
      component: 'ApiSelect',
      label: '远程下拉',
      required: true,
      componentProps: {
        api: optionsListApi,
      },
      colProps: {
        span: 8,
      },
228
      defaultValue: '0',
229
    },
230
231
232
233
234
235
236
237
238
    {
      field: 'field20',
      component: 'InputNumber',
      label: '字段20',
      required: true,
      colProps: {
        span: 8,
      },
    },
陈文彬 authored
239
240
241
  ];

  export default defineComponent({
242
    components: { BasicForm, CollapseContainer, PageWrapper },
陈文彬 authored
243
    setup() {
244
      const check = ref(null);
陈文彬 authored
245
246
247
248
249
250
      const { createMessage } = useMessage();
      return {
        schemas,
        handleSubmit: (values: any) => {
          createMessage.success('click search,values:' + JSON.stringify(values));
        },
251
        check,
陈文彬 authored
252
253
254
255
      };
    },
  });
</script>