Form 表单

具有数据收集、校验和提交功能的表单,包含单选框、输入框、按钮等元素。

Form 验证

>{}
<template>
  <Form
    class="text-test-page-form"
    label-width="20%"
    label-mark=""
    :model="the.data"
    :rules="the.rules"
    @onEvent="onFormEvent"
  >
    <Field label="开始日期" prop="startDate">
      <DatePicker
        v-model="the.data.startDate"
        type="date"
        placeholder="请选择日期"
      />
      <TimePicker v-model="the.data.startTime" placeholder="请选择日期与时间" />
    </Field>

    <Field label="截止时间" prop="endTime">
      <DatePicker
        v-model="the.data.endTime"
        type="datetime"
        placeholder="请选择日期与时间"
      />
      <Tooltip content="时间选择"></Tooltip>
    </Field>

    <Field>
      <Switch v-model="the.data.bool" @onEvent="onSwitch" />

      <RadioGroup v-model="the.data.bool" :list="the.radioGroupList" />

      <span>
        <Radio v-model="the.data.bool" value="true" name="test-radio-text2" />

        是1

        <Radio v-model="the.data.bool" value="false" name="test-radio-text2" />
        否0
      </span>
    </Field>

    <Field label="密码测试" prop="password">
      <Input
        v-model="the.data.password"
        type="password"
        placeholder="Enter password"
      />
    </Field>
    <Field label="组织ID" prop="ID">
      <Input
        v-model="the.data.ID"
        placeholder="请输入组织ID"
        type="number"
        icon="icon-sousuo"
        @onEvent="onGroupEvent"
      />
    </Field>

    <Field label="外键查询" prop="ID">
      <Input
        v-model="the.data.ID"
        placeholder="请输入ID"
        style="width:12rem"
        type="number"
        icon="icon-sousuo"
        @onEvent="onGroupEvent"
      />
    </Field>

    <Field>
      <Textarea
        v-model="the.url"
        placeholder="请输入多行文本框"
        spellcheck="false"
        rows="3"
      />
    </Field>
    <Field>
      <Textjson
        v-model="the.jsonValue"
        placeholder="请输入json"
        spellcheck="false"
        rows="15"
      />
    </Field>

    <Field label="基础组件选项" tip="测试">
      <Select v-model="the.data.type" @onEvent="onSizeEvent">
        <option
          v-for="(item, index) in the.data.typeList"
          :key="index"
          :value="index"
        >
          {{ item }}
        </option>
      </Select>
    </Field>

    <Field>
      <Checkbox value="all" @onEvent="onCheckEvent" /> 全选
      <Checkbox
        v-for="(item, index) in the.data.typeList"
        :key="index"
        v-model="the.data.typeCk"
        :value="index"
      >
        {{ item }};
      </Checkbox>
    </Field>
    <Field>
      <Button type="primary" long loading @click="btnEvent('save')">
        提交
      </Button>
    </Field>
  </Form>
</template>

<script>
const testdb = [
  { ID: 101, Title: '初始化' },
  { ID: 201, Title: '组织2' },
  { ID: 302, Title: '组织3' },
];

export default {
  setup(props, context) {
    // 使用外挂方式引入,具体查看demo
    const $plus = window.$plus;
    const { reactive } = $plus.vue;

    const the = reactive({
      url: '',
      jsonValue: '',
      radioGroupList: {
        启用: true,
        停止: false,
      },
      data: {
        ID: 123,
        modelID: 0,
        userId: 0,
        name: '',
        password: 'abc',
        type: 2,
        typeCk: [3],
        typeList: ['初始', '正常', '已审', '撤审', '删除'],
        tel: 1890000000,
        startDate: '2020-09-02',
        startTime: '12:51:32',
        endTime: '2020-09-08 12:01',

        bool: false,
      },
      /** 规则 */
      rules: {
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          {
            type: 'string',
            min: 6,
            message: '长度必须大于6位',
            trigger: 'blur',
          },
          { tip: '测试规则提示' },
        ],
      },
      ui: {
        attr: {
          ID: { v: 0, t: 'Int64', c: 'panel', api: '/Api/QF_Group/' },
          modelID: { v: 0, t: 'Int64', c: 'panel', api: '/Api/QF_Model/' },
          userId: { v: 0, t: 'Int64', c: '' },
          type: {
            ls: '0:初始,1:正常,2:已审,3:撤审,4:删除',
          },
          bool: { t: 'bool' },
          tel: { t: 'tel' },
          name: {},
        },
      },
      /** 对话框 */
      modal: {
        title: '请勾选',
        show: false,
      },
      /** 面板 */
      panel: {
        // 数据源地址
        api: '',
        // 返回绑定的主键
        named: '',
        // 查询字段
        field: {},
        // 查询数据
        list: [],
      },
      tag: {
        key: '',
        css: ['default', 'info', 'primary', 'success', 'error', 'warning'],
      },
    });

    const onSizeEvent = (data) => {
      console.log('onSizeEvent', data);
    };

    // 组织点击
    const onGroupEvent = (resp) => {
      console.log('onGroupEvent:', resp);

      switch (resp.cmd) {
        case 'icon':
          // 字段
          the.panel.field = {
            ID: '编号',
            Title: '描述',
          };

          // 数据
          the.panel.list = testdb;
          the.modal.show = true;
          break;

        case 'search':
          // 查询
          break;
      }
    };

    /** 输入事件 */
    const onInputEvent = (resp) => {
      console.log('onInput:', resp);

      // the.panel.api = '/Api/QF_Group/'

      let _api = '';

      if (the.ui.attr && resp.id) {
        _api = the.ui.attr[resp.id].api || '';
      }

      console.log('onInput:' + resp.id, _api);

      the.panel.api = _api;
      the.panel.named = resp.id;
      // the.modal.show = true
    };

    /** 日期触发 */
    const onDateEvent = (resp) => {
      console.log('onDateEvent', resp);
      switch (resp.cmd) {
        case 'InputPlus':
          // 输入框外挂事件
          break;
      }
    };

    /** 面板触发事件 */
    const onPanelEvent = (resp) => {
      console.log('onGroupEvent:', JSON.stringify(resp));

      switch (resp.cmd) {
        case 'checkAll':
          // 全选
          break;
        case 'checked':
          if (resp.item) {
            // 选择的数据选项
            the.data[resp.named] = resp.item.ID;
          }
          // the.modal.show = false
          break;

        case 'close':
          // 关闭窗口
          the.modal.show = false;
          break;
      }
    };

    /** 标签事件 */
    const onTagEvent = (resp) => {
      switch (resp.cmd) {
        case 'close':
          // 关闭
          the.tag.css.splice(parseInt(resp.name), 1);
          break;
        case 'click':
        default:
          console.log('onTagEvent:', resp);
          break;
      }
    };

    const onSwitch = (resp) => {
      console.log('onSwitch:', resp);
    };

    /** 全选 */
    const onCheckEvent = (resp) => {
      console.log('onCheckEvent:', resp);

      //resp.value 是组件自定义绑定值,根据实际应用定义
      if (resp.value === 'all') {
        // 全选
        let _list = [];
        if (resp.checked) {
          // 选中
          for (let i in the.data.typeList) {
            _list.push(i);
          }
        }
        the.data.typeCk = _list;
      }
    };

    /**
     * 回调验证事件
     */
    const onFormEvent = (resp) => {
      //  console.log('onFormEvent', resp)

      switch (resp.cmd) {
        case 'validator':
          // 数据验证
          the.rulesPass = resp.isPass;
          break;
        // case 'enter':
        //   //回车
        //   sendLogin()
        //   break;
      }
    };

    return {
      the,
      onSizeEvent,
      onGroupEvent,
      onInputEvent,
      onPanelEvent,
      onTagEvent,
      onSwitch,
      onCheckEvent,
      onDateEvent,
      onFormEvent,
    };
  },
};
</script>
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
122
123
124
125
126
127
128
129
130
131
132
133
134
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350

Form props

属性说明类型默认值
named组件命名Stringform
model表单数据对象Object
rules表单验证规则 validatorObjectnull
labelMark符号标记String
labelWidth表单域标签宽度String
labelPosition表单域标签的位置,可选值为 left、right、topStringright
inline表单样式,是否水平排列Booleanfalse
showMessage是否显示验证规则提示消息Booleantrue

Field props

Field 默认从属于 Form 子组件规则

属性说明类型默认值
label表单域标签显示文本String
labelMark符号标记String
labelWidth表单域标签宽度String
required是否必填规则Booleanfalse
rules表单字段单个验证规则数组 validatorArray
prop表单验证规则命名String
class标签样式,自定义String-

Rules 表单验证规则

属性说明类型默认值
required是否必填Booleanfalse
type输入类型String-
message提示内容String-
trigger触发方式,可选blurString-
min输入最短长度Number-
value 0.4.8输入的内容

Last Updated: