Upload3.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <Alert message="嵌入表单,加入resultFiled自定义返回值" />
  3. <BasicForm @register="registerCustom" class="my-5" />
  4. </template>
  5. <script setup lang="ts">
  6. import { uploadApi } from '@/api/sys/upload';
  7. import { useMessage } from '@/hooks/web/useMessage';
  8. const { createMessage } = useMessage();
  9. import { BasicForm, FormSchema, useForm } from '@/components/Form';
  10. import { Alert } from 'ant-design-vue';
  11. const schemasCustom: FormSchema[] = [
  12. {
  13. field: 'field3',
  14. component: 'Upload',
  15. label: '字段3',
  16. componentProps: {
  17. resultField: 'data3.url',
  18. api: (file, progress) => {
  19. return new Promise((resolve) => {
  20. uploadApi(file, progress).then((uploadApiResponse) => {
  21. resolve({
  22. code: 200,
  23. data3: {
  24. url: uploadApiResponse.data.url,
  25. },
  26. });
  27. });
  28. });
  29. },
  30. },
  31. },
  32. {
  33. field: 'field4',
  34. component: 'ImageUpload',
  35. label: '字段4(ImageUpload)',
  36. colProps: {
  37. span: 8,
  38. },
  39. componentProps: {
  40. resultField: 'data4.url',
  41. api: (file, progress) => {
  42. return new Promise((resolve) => {
  43. uploadApi(file, progress).then((uploadApiResponse) => {
  44. resolve({
  45. code: 200,
  46. data4: {
  47. url: uploadApiResponse.data.url,
  48. },
  49. });
  50. });
  51. });
  52. },
  53. },
  54. },
  55. ];
  56. const [registerCustom, { getFieldsValue: getFieldsValueCustom }] = useForm({
  57. labelWidth: 160,
  58. schemas: schemasCustom,
  59. actionColOptions: {
  60. span: 18,
  61. },
  62. submitFunc: () => {
  63. return new Promise((resolve) => {
  64. console.log(getFieldsValueCustom());
  65. resolve();
  66. createMessage.success(`请到控制台查看结果`);
  67. });
  68. },
  69. });
  70. </script>
  71. <style scoped></style>