95 lines
3.2 KiB
Vue
95 lines
3.2 KiB
Vue
<script setup lang="ts">
|
||
import { ref, useId } from "vue";
|
||
import {
|
||
Button,
|
||
Input,
|
||
Label,
|
||
Modal,
|
||
ModalBackdrop,
|
||
ModalBody,
|
||
ModalClose,
|
||
ModalCloseTrigger,
|
||
ModalContainer,
|
||
ModalDialog,
|
||
ModalFooter,
|
||
ModalHeader,
|
||
ModalHeading,
|
||
ModalIcon,
|
||
Surface,
|
||
TextField,
|
||
useOverlayState,
|
||
} from "@heroui-vue/components";
|
||
import { IconMail as Envelope } from "@tabler/icons-vue";
|
||
const state = useOverlayState();
|
||
const formId = useId();
|
||
const result = ref<Record<string, FormDataEntryValue>>();
|
||
function submit(event: SubmitEvent) {
|
||
result.value = Object.fromEntries(
|
||
new FormData(event.currentTarget as HTMLFormElement),
|
||
);
|
||
state.close();
|
||
}
|
||
</script>
|
||
<template>
|
||
<div>
|
||
<Modal :state="state">
|
||
<Button variant="secondary">打开联系表单</Button>
|
||
<ModalBackdrop>
|
||
<ModalContainer placement="auto">
|
||
<ModalDialog class="sm:max-w-md">
|
||
<ModalCloseTrigger></ModalCloseTrigger>
|
||
<ModalHeader>
|
||
<ModalIcon class="bg-accent-soft text-accent-soft-foreground">
|
||
<Envelope aria-hidden="true" class="size-5"></Envelope>
|
||
</ModalIcon>
|
||
<ModalHeading>联系我们</ModalHeading>
|
||
<p class="mt-1.5 text-sm leading-5 text-muted">
|
||
填写下方表单,我们会尽快回复。在移动端弹出键盘时,模态框会自动适配。
|
||
</p>
|
||
</ModalHeader>
|
||
<ModalBody class="p-6">
|
||
<Surface variant="default">
|
||
<form
|
||
:id="formId"
|
||
class="flex flex-col gap-4"
|
||
@submit.prevent="submit"
|
||
>
|
||
<TextField class="w-full" name="name" type="text">
|
||
<Label>姓名</Label>
|
||
<Input placeholder="输入你的姓名"></Input>
|
||
</TextField>
|
||
<TextField class="w-full" name="email" type="email">
|
||
<Label>邮箱</Label>
|
||
<Input placeholder="输入你的邮箱"></Input>
|
||
</TextField>
|
||
<TextField class="w-full" name="phone" type="tel">
|
||
<Label>电话</Label>
|
||
<Input placeholder="输入你的电话号码"></Input>
|
||
</TextField>
|
||
<TextField class="w-full" name="company">
|
||
<Label>公司</Label>
|
||
<Input placeholder="输入公司名称"></Input>
|
||
</TextField>
|
||
<TextField class="w-full" name="message">
|
||
<Label>留言</Label>
|
||
<Input placeholder="输入留言内容"></Input>
|
||
</TextField>
|
||
</form>
|
||
</Surface>
|
||
</ModalBody>
|
||
<ModalFooter>
|
||
<ModalClose as-child>
|
||
<Button variant="secondary">取消</Button>
|
||
</ModalClose>
|
||
<Button type="submit" :form="formId">发送消息</Button>
|
||
</ModalFooter>
|
||
</ModalDialog>
|
||
</ModalContainer>
|
||
</ModalBackdrop>
|
||
</Modal>
|
||
<p v-if="result" role="status" class="mt-3 text-sm text-muted">
|
||
已记录表单:{{ result }}
|
||
</p>
|
||
</div>
|
||
</template>
|