Blame view

src/views/demo/comp/upload/index.vue 1.53 KB
jq authored
1
<template>
2
  <PageWrapper title="上传组件示例">
3
4
5
6
7
8
    <a-alert message="基础示例" class="my-5"></a-alert>
    <BasicUpload :maxSize="20" :maxNumber="10" @change="handleChange" :api="uploadApi" />

    <a-alert message="嵌入表单,加入表单校验" class="my-5"></a-alert>

    <BasicForm @register="register" />
9
  </PageWrapper>
jq authored
10
11
</template>
<script lang="ts">
12
  import { defineComponent } from 'vue';
13
14
15
  import { BasicUpload } from '/@/components/Upload';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
16
  import { PageWrapper } from '/@/components/Page';
vben authored
17
  import { Alert } from 'ant-design-vue';
jq authored
18
19
20
21
22
23
  import { uploadApi } from '/@/api/sys/upload';

  const schemas: FormSchema[] = [
    {
      field: 'field1',
24
      component: 'Upload',
25
26
27
28
      label: '字段1',
      colProps: {
        span: 8,
      },
29
30
31
      rules: [{ required: true, message: '请选择上传文件' }],
      componentProps: {
        api: uploadApi,
32
33
34
      },
    },
  ];
jq authored
35
  export default defineComponent({
vben authored
36
    components: { BasicUpload, BasicForm, PageWrapper, [Alert.name]: Alert },
jq authored
37
    setup() {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
      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
53
54
55
    },
  });
</script>