Blame view

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

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