135 lines
3.6 KiB
Vue
135 lines
3.6 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from "vue";
|
|
import {
|
|
TextField,
|
|
SearchField,
|
|
SearchFieldGroup,
|
|
SearchFieldInput,
|
|
SearchFieldClearButton,
|
|
Form,
|
|
Label,
|
|
Input,
|
|
FieldError,
|
|
InputOTP,
|
|
InputOTPGroup,
|
|
InputOTPSlot,
|
|
} from "@heroui-vue/components";
|
|
const local = ref(["字段错误"]),
|
|
server = ref({ name: "Form错误" });
|
|
const mounted = ref(false),
|
|
accepted = ref(true),
|
|
disabled = ref(false),
|
|
readonly = ref(false);
|
|
const otp = ref(""),
|
|
completes = ref<string[]>([]),
|
|
proposals = ref<string[]>([]);
|
|
const align = ref<"left" | "center" | "right">("left");
|
|
const strip = (text: string) => text.replaceAll("-", "");
|
|
</script>
|
|
<template>
|
|
<main style="padding: 24px; display: grid; gap: 20px">
|
|
<Form :validation-errors="server">
|
|
<TextField
|
|
v-slot="state"
|
|
auto-focus
|
|
name="name"
|
|
:validation-errors="local"
|
|
>
|
|
<Label>姓名</Label>
|
|
<Input />
|
|
<button type="button">字段内按钮</button>
|
|
<output id="field-state">
|
|
{{
|
|
JSON.stringify({
|
|
value: state.value,
|
|
within: state.isFocusWithin,
|
|
visible: state.isFocusVisible,
|
|
})
|
|
}}
|
|
</output>
|
|
<FieldError v-slot="errors">
|
|
{{ errors.validationErrors.join("|") }} /
|
|
{{ errors.validationDetails?.customError }}
|
|
</FieldError>
|
|
</TextField>
|
|
<SearchField v-slot="state" name="query">
|
|
<Label>搜索</Label>
|
|
<SearchFieldGroup>
|
|
<SearchFieldInput />
|
|
<SearchFieldClearButton />
|
|
</SearchFieldGroup>
|
|
<output id="search-value">{{ state.value }}</output>
|
|
</SearchField>
|
|
<button type="reset">重置字段</button>
|
|
<button
|
|
type="button"
|
|
@click="
|
|
local = ['新字段错误'];
|
|
server = { name: '新Form错误' };
|
|
"
|
|
>
|
|
新错误响应
|
|
</button>
|
|
</Form>
|
|
<div>
|
|
<button @click="mounted = true">挂载验证码</button>
|
|
<label>
|
|
<input v-model="accepted" type="checkbox" />
|
|
接受验证码
|
|
</label>
|
|
<label>
|
|
<input v-model="disabled" type="checkbox" />
|
|
禁用验证码
|
|
</label>
|
|
<label>
|
|
<input v-model="readonly" type="checkbox" />
|
|
只读验证码
|
|
</label>
|
|
<label>
|
|
输入对齐
|
|
<select v-model="align">
|
|
<option>left</option>
|
|
<option>center</option>
|
|
<option>right</option>
|
|
</select>
|
|
</label>
|
|
</div>
|
|
<Form @submit.prevent>
|
|
<InputOTP
|
|
v-if="mounted"
|
|
:model-value="otp"
|
|
:max-length="4"
|
|
auto-focus
|
|
required
|
|
aria-label="验证码"
|
|
name="code"
|
|
:is-disabled="disabled"
|
|
:is-read-only="readonly"
|
|
:text-align="align"
|
|
:paste-transformer="strip"
|
|
pattern="^\d+$"
|
|
@update:model-value="
|
|
proposals.push($event);
|
|
accepted && (otp = $event);
|
|
"
|
|
@complete="completes.push($event)"
|
|
>
|
|
<InputOTPGroup>
|
|
<InputOTPSlot v-for="index in 4" :key="index" :index="index - 1" />
|
|
</InputOTPGroup>
|
|
<FieldError v-slot="state">
|
|
{{ state.validationErrors.join("|") }} / missing={{
|
|
state.validationDetails?.valueMissing
|
|
}}
|
|
</FieldError>
|
|
</InputOTP>
|
|
<button type="submit">校验验证码</button>
|
|
<button type="reset">重置验证码</button>
|
|
<button type="button" @click="otp = ''">清空验证码</button>
|
|
</Form>
|
|
<output id="otp-state">
|
|
{{ JSON.stringify({ value: otp, completes, proposals }) }}
|
|
</output>
|
|
</main>
|
|
</template>
|