Blame view

src/views/demo/comp/upload/index.vue 1.55 KB
jq authored
1
<template>
2
  <PageWrapper title="上传组件示例">
vben authored
3
4
5
6
7
8
9
10
    <a-alert message="基础示例" />
    <BasicUpload
      :maxSize="20"
      :maxNumber="10"
      @change="handleChange"
      :api="uploadApi"
      class="my-5"
    />
11
vben authored
12
    <a-alert message="嵌入表单,加入表单校验" />
13
vben authored
14
    <BasicForm @register="register" class="my-5" />
15
  </PageWrapper>
jq authored
16
17
</template>
<script lang="ts">
18
  import { defineComponent } from 'vue';
19
20
21
  import { BasicUpload } from '/@/components/Upload';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
22
  import { PageWrapper } from '/@/components/Page';
vben authored
23
  import { Alert } from 'ant-design-vue';
24
25
26
27
28
  import { uploadApi } from '/@/api/sys/upload';

  const schemas: FormSchema[] = [
    {
      field: 'field1',
29
      component: 'Upload',
30
31
32
33
      label: '字段1',
      colProps: {
        span: 8,
      },
34
35
36
      rules: [{ required: true, message: '请选择上传文件' }],
      componentProps: {
        api: uploadApi,
37
38
39
      },
    },
  ];
jq authored
40
  export default defineComponent({
vben authored
41
    components: { BasicUpload, BasicForm, PageWrapper, [Alert.name]: Alert },
jq authored
42
    setup() {
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
      const { createMessage } = useMessage();
      const [register] = useForm({
        labelWidth: 120,
        schemas,
        actionColOptions: {
          span: 16,
        },
      });
      return {
        handleChange: (list: string[]) => {
          createMessage.info(`已上传文件${JSON.stringify(list)}`);
        },
        uploadApi,
        register,
      };
jq authored
58
59
60
    },
  });
</script>