gaoluyang
2026-06-26 4a71c6beb268ba17ca472f45401c8ee97846e97e
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
<script setup lang="ts">
import type { Recordable } from '../../../../../types/src';
 
import type { VbenFormSchema } from '../../../../../@core/ui-kit/form-ui/src';
 
import { computed, reactive } from 'vue';
 
import { $t } from '../../../../../locales/src';
 
import { useVbenForm } from '../../../../../@core/ui-kit/form-ui/src';
import { VbenButton } from '../../../../../@core/ui-kit/shadcn-ui/src';
 
interface Props {
  formSchema?: VbenFormSchema[];
}
 
const props = withDefaults(defineProps<Props>(), {
  formSchema: () => [],
});
 
const emit = defineEmits<{
  submit: [Recordable<any>];
}>();
 
const [Form, formApi] = useVbenForm(
  reactive({
    commonConfig: {
      // 所有表单项
      componentProps: {
        class: 'w-full',
      },
    },
    layout: 'horizontal',
    schema: computed(() => props.formSchema),
    showDefaultActions: false,
  }),
);
 
async function handleSubmit() {
  const { valid } = await formApi.validate();
  const values = await formApi.getValues();
  if (valid) {
    emit('submit', values);
  }
}
 
defineExpose({
  getFormApi: () => formApi,
});
</script>
<template>
  <div @keydown.enter.prevent="handleSubmit">
    <Form />
    <VbenButton type="submit" class="mt-4" @click="handleSubmit">
      {{ $t('profile.updateBasicProfile') }}
    </VbenButton>
  </div>
</template>