75 lines
2.4 KiB
Vue
75 lines
2.4 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
Button,
|
|
Description,
|
|
FieldError,
|
|
FieldGroup,
|
|
Fieldset,
|
|
FieldsetLegend,
|
|
FieldsetActions,
|
|
Form,
|
|
Input,
|
|
Label,
|
|
TextArea,
|
|
TextField,
|
|
Surface,
|
|
} from "@heroui-vue/components";
|
|
import { IconDeviceFloppy } from "@tabler/icons-vue";
|
|
import { ref } from "vue";
|
|
const result = ref("");
|
|
function validateName(value: string) {
|
|
return value.length < 3 ? "姓名至少需要 3 个字符" : null;
|
|
}
|
|
function validateBio(value: string) {
|
|
return value.length < 10 ? "简介至少需要 10 个字符" : null;
|
|
}
|
|
function submit(event: Event) {
|
|
const data = Object.fromEntries(
|
|
new FormData(event.currentTarget as HTMLFormElement),
|
|
);
|
|
result.value = `表单提交成功!${JSON.stringify(data)}`;
|
|
}
|
|
</script>
|
|
<template>
|
|
<div class="flex items-center justify-center rounded-3xl bg-surface p-6">
|
|
<Surface class="w-full min-w-[380px] max-sm:min-w-0">
|
|
<Form @submit.prevent="submit">
|
|
<Fieldset class="w-full">
|
|
<FieldsetLegend>个人资料设置</FieldsetLegend>
|
|
<Description>更新你的个人资料信息。</Description>
|
|
<FieldGroup>
|
|
<TextField is-required name="name" :validate="validateName">
|
|
<Label>姓名</Label>
|
|
<Input variant="secondary" placeholder="John Doe" />
|
|
<FieldError />
|
|
</TextField>
|
|
<TextField is-required name="email" type="email">
|
|
<Label>邮箱</Label>
|
|
<Input variant="secondary" placeholder="john@example.com" />
|
|
<FieldError />
|
|
</TextField>
|
|
<TextField is-required name="bio" :validate="validateBio">
|
|
<Label>简介</Label>
|
|
<TextArea variant="secondary" placeholder="介绍一下你自己…" />
|
|
<Description>至少 10 个字符</Description>
|
|
<FieldError />
|
|
</TextField>
|
|
</FieldGroup>
|
|
<FieldsetActions>
|
|
<Button type="submit">
|
|
<IconDeviceFloppy aria-hidden="true" />
|
|
保存更改
|
|
</Button>
|
|
<Button type="reset" variant="tertiary" @click="result = ''">
|
|
取消
|
|
</Button>
|
|
</FieldsetActions>
|
|
</Fieldset>
|
|
<p v-if="result" class="text-sm text-muted" role="status">
|
|
{{ result }}
|
|
</p>
|
|
</Form>
|
|
</Surface>
|
|
</div>
|
|
</template>
|