78 lines
2.6 KiB
Vue
78 lines
2.6 KiB
Vue
<script setup lang="ts">
|
|
import {
|
|
Button,
|
|
Description,
|
|
FieldError,
|
|
FieldGroup,
|
|
Fieldset,
|
|
FieldsetLegend,
|
|
FieldsetActions,
|
|
Form,
|
|
Input,
|
|
Label,
|
|
TextArea,
|
|
TextField,
|
|
} 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)}`;
|
|
}
|
|
const shell =
|
|
"rounded-xl border border-border/70 bg-linear-to-b from-neutral-50/90 to-white p-4 ring-1 ring-black/5 dark:from-neutral-900/80 dark:to-neutral-900 dark:ring-white/10";
|
|
const fieldClass =
|
|
"rounded-xl border border-border/80 bg-surface shadow-sm ring-1 ring-black/5 transition-[box-shadow,border-color] focus-visible:ring-2 focus-visible:ring-neutral-400/25 dark:ring-white/10 dark:focus-visible:ring-neutral-500/30";
|
|
</script>
|
|
<template>
|
|
<Form class="w-full max-w-96" @submit.prevent="submit">
|
|
<Fieldset :class="shell">
|
|
<FieldsetLegend
|
|
class="font-medium text-neutral-800 dark:text-neutral-100"
|
|
>
|
|
个人资料设置
|
|
</FieldsetLegend>
|
|
<Description class="text-neutral-600 dark:text-neutral-400">
|
|
更新你的个人资料信息。
|
|
</Description>
|
|
<FieldGroup>
|
|
<TextField is-required name="name" :validate="validateName">
|
|
<Label>姓名</Label>
|
|
<Input :class="fieldClass" placeholder="John Doe" />
|
|
<FieldError />
|
|
</TextField>
|
|
<TextField is-required name="email" type="email">
|
|
<Label>邮箱</Label>
|
|
<Input :class="fieldClass" placeholder="john@example.com" />
|
|
<FieldError />
|
|
</TextField>
|
|
<TextField is-required name="bio" :validate="validateBio">
|
|
<Label>简介</Label>
|
|
<TextArea :class="fieldClass" placeholder="介绍一下你自己…" />
|
|
<Description>至少 10 个字符</Description>
|
|
<FieldError />
|
|
</TextField>
|
|
</FieldGroup>
|
|
<FieldsetActions>
|
|
<Button type="submit">
|
|
<IconDeviceFloppy aria-hidden="true" />
|
|
保存更改
|
|
</Button>
|
|
<Button type="reset" variant="secondary" @click="result = ''">
|
|
取消
|
|
</Button>
|
|
</FieldsetActions>
|
|
</Fieldset>
|
|
<p v-if="result" class="text-sm text-muted" role="status">{{ result }}</p>
|
|
</Form>
|
|
</template>
|