feat: Initialize core frontend application structure, including layouts, authentication pages, and common UI components.

This commit is contained in:
supalerk-ar66 2026-01-26 09:27:31 +07:00
parent ae84e7e879
commit 69eb60f901
16 changed files with 1178 additions and 1396 deletions

View file

@ -3,6 +3,7 @@
* @file register.vue
* @description User Registration Page.
* Features a multi-step style form (though currently single view) for creating a new account.
* Updated to match the Dark Theme design.
*/
definePageMeta({
@ -15,11 +16,12 @@ useHead({
});
const router = useRouter();
const { register } = useAuth(); // Import register from useAuth
const { register } = useAuth();
const { errors, validate, clearFieldError } = useFormValidation();
const isLoading = ref(false);
const showPassword = ref(false);
const showConfirmPassword = ref(false);
const registerForm = reactive({
prefix: "นาย",
@ -32,7 +34,6 @@ const registerForm = reactive({
confirmPassword: "",
});
const registerRules = {
username: {
rules: {
@ -88,58 +89,63 @@ const registerRules = {
},
};
const onUsernameInput = (val: string) => {
registerForm.username = val;
if (/[\u0E00-\u0E7F]/.test(val)) {
const prefixOptions = ['นาย', 'นาง', 'นางสาว']
// handlers
const onUsernameInput = (val: string | number | null) => {
const value = String(val || '')
registerForm.username = value;
if (/[\u0E00-\u0E7F]/.test(value)) {
errors.value.username = 'ห้ามใส่ภาษาไทย';
} else {
// Only clear if the error is specifically about Thai chars,
// otherwise we might clear minLength errors undesirably
if (errors.value.username === 'ห้ามใส่ภาษาไทย') {
clearFieldError('username');
}
if (errors.value.username === 'ห้ามใส่ภาษาไทย') clearFieldError('username');
}
};
const onPhoneInput = (val: string) => {
registerForm.phone = val;
if (/\D/.test(val)) {
const onPhoneInput = (val: string | number | null) => {
const value = String(val || '')
registerForm.phone = value;
if (/\D/.test(value)) {
errors.value.phone = 'กรุณากรอกเฉพาะตัวเลข';
} else {
if (errors.value.phone === 'กรุณากรอกเฉพาะตัวเลข') clearFieldError('phone');
}
};
const onEmailInput = (val: string) => {
registerForm.email = val;
if (/[\u0E00-\u0E7F]/.test(val)) {
const onEmailInput = (val: string | number | null) => {
const value = String(val || '')
registerForm.email = value;
if (/[\u0E00-\u0E7F]/.test(value)) {
errors.value.email = 'ห้ามใส่ภาษาไทย';
} else {
if (errors.value.email === 'ห้ามใส่ภาษาไทย') clearFieldError('email');
}
};
const onPasswordInput = (val: string) => {
registerForm.password = val;
if (/[\u0E00-\u0E7F]/.test(val)) {
const onPasswordInput = (val: string | number | null) => {
const value = String(val || '')
registerForm.password = value;
if (/[\u0E00-\u0E7F]/.test(value)) {
errors.value.password = 'ห้ามใส่ภาษาไทย';
} else {
if (errors.value.password === 'ห้ามใส่ภาษาไทย') clearFieldError('password');
}
};
const onFirstNameInput = (val: string) => {
registerForm.firstName = val;
if (/\d/.test(val)) {
const onFirstNameInput = (val: string | number | null) => {
const value = String(val || '')
registerForm.firstName = value;
if (/\d/.test(value)) {
errors.value.firstName = 'ห้ามใส่ตัวเลข';
} else {
if (errors.value.firstName === 'ห้ามใส่ตัวเลข') clearFieldError('firstName');
}
};
const onLastNameInput = (val: string) => {
registerForm.lastName = val;
if (/\d/.test(val)) {
const onLastNameInput = (val: string | number | null) => {
const value = String(val || '')
registerForm.lastName = value;
if (/\d/.test(value)) {
errors.value.lastName = 'ห้ามใส่ตัวเลข';
} else {
if (errors.value.lastName === 'ห้ามใส่ตัวเลข') clearFieldError('lastName');
@ -151,7 +157,6 @@ const handleRegister = async () => {
isLoading.value = true;
// Map prefix to { th, en }
const prefixMap: Record<string, string> = {
'นาย': 'Mr.',
'นาง': 'Mrs.',
@ -185,183 +190,235 @@ const handleRegister = async () => {
</script>
<template>
<div class="card auth-card" style="width: 100%; max-width: 480px">
<!-- Loading Overlay -->
<LoadingSpinner v-if="isLoading" full-page text="กำลังดำเนินการ..." />
<div class="flex items-center justify-center min-h-screen bg-slate-900 font-inter p-4 relative overflow-hidden">
<!-- Background Decoration -->
<div class="absolute top-[-20%] left-[-10%] w-[600px] h-[600px] bg-blue-600/5 rounded-full blur-[120px] pointer-events-none"></div>
<div class="absolute bottom-[-20%] right-[-10%] w-[600px] h-[600px] bg-indigo-600/5 rounded-full blur-[120px] pointer-events-none"></div>
<!-- Title Area -->
<div class="text-center mb-8">
<h1 class="text-3xl font-bold text-white mb-2">e-Learning Platform</h1>
<p class="text-gray-400 text-sm">
นดอนรบกล! กรณากรอกขอมลของค
</p>
</div>
<q-card class="w-full max-w-[740px] shadow-2xl rounded-2xl bg-slate-800 text-white border border-slate-700 relative z-10 q-pa-xl">
<form @submit.prevent="handleRegister">
<FormInput
:model-value="registerForm.username"
label="ชื่อผู้ใช้"
placeholder="username"
:error="errors.username"
required
class="dark-form-input"
@update:model-value="onUsernameInput"
/>
<FormInput
:model-value="registerForm.email"
label="อีเมล"
type="email"
placeholder="student@example.com"
:error="errors.email"
required
class="dark-form-input"
@update:model-value="onEmailInput"
/>
<FormInput
:model-value="registerForm.password"
label="รหัสผ่าน"
type="password"
placeholder="สร้างรหัสผ่าน (อย่างน้อย 8 ตัวอักษร)"
:error="errors.password"
required
class="dark-form-input"
@update:model-value="onPasswordInput"
/>
<FormInput
v-model="registerForm.confirmPassword"
label="ยืนยันรหัสผ่าน"
type="password"
placeholder="ยืนยันรหัสผ่านอีกครั้ง"
:error="errors.confirmPassword"
required
class="dark-form-input"
@update:model-value="clearFieldError('confirmPassword')"
/>
<div class="grid-12" style="gap: 16px; margin-bottom: 0">
<div class="col-span-4">
<label class="input-label text-gray-300">คำนำหน</label>
<select
v-model="registerForm.prefix"
class="input-field dark-input"
style="height: 42px"
>
<option value="นาย">นาย</option>
<option value="นาง">นาง</option>
<option value="นางสาว">นางสาว</option>
</select>
</div>
<div class="col-span-8">
<FormInput
:model-value="registerForm.firstName"
label="ชื่อ"
placeholder=""
:error="errors.firstName"
required
class="dark-form-input"
@update:model-value="onFirstNameInput"
/>
<!-- Header -->
<div class="flex flex-col items-center mb-10">
<div class="w-14 h-14 bg-white text-blue-600 rounded-2xl flex items-center justify-center font-extrabold text-3xl mb-6 shadow-lg shadow-white/10">
E
</div>
<h1 class="text-3xl font-bold text-white mb-3">e-Learning Platform</h1>
<p class="text-slate-400 text-base">สรางบญชใชงานใหม</p>
</div>
<FormInput
:model-value="registerForm.lastName"
label="นามสกุล"
placeholder=""
:error="errors.lastName"
required
class="dark-form-input"
@update:model-value="onLastNameInput"
/>
<form @submit.prevent="handleRegister" class="flex flex-col gap-5">
<!-- Username -->
<div>
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">อผใช <span class="text-red-500">*</span></div>
<q-input
:model-value="registerForm.username"
outlined
dense
dark
placeholder="username"
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.username"
:error-message="errors.username"
@update:model-value="onUsernameInput"
hide-bottom-space
/>
</div>
<FormInput
:model-value="registerForm.phone"
label="เบอร์โทรศัพท์"
type="tel"
placeholder=""
:error="errors.phone"
required
class="dark-form-input"
@update:model-value="onPhoneInput"
/>
<!-- Email -->
<div>
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">เมล <span class="text-red-500">*</span></div>
<q-input
:model-value="registerForm.email"
outlined
dense
dark
type="email"
placeholder="student@example.com"
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.email"
:error-message="errors.email"
@update:model-value="onEmailInput"
hide-bottom-space
/>
</div>
<button
type="submit"
class="btn btn-primary w-full mb-4 mt-2"
:disabled="isLoading"
style="height: 44px; font-size: 16px"
>
<LoadingSpinner v-if="isLoading" size="sm" />
<span v-else>สร้างบัญชี</span>
</button>
<!-- Password -->
<div>
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">รหสผาน <span class="text-red-500">*</span></div>
<q-input
:model-value="registerForm.password"
outlined
dense
dark
:type="showPassword ? 'text' : 'password'"
placeholder="สร้างรหัสผ่าน (อย่างน้อย 8 ตัวอักษร)"
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.password"
:error-message="errors.password"
@update:model-value="onPasswordInput"
hide-bottom-space
>
<template v-slot:append>
<q-icon
:name="showPassword ? 'visibility_off' : 'visibility'"
class="cursor-pointer text-slate-400 hover:text-white transition-colors"
@click="showPassword = !showPassword"
/>
</template>
</q-input>
</div>
<div class="text-center mt-6 text-sm">
<span class="text-muted">ญชอยแล? </span>
<NuxtLink to="/auth/login" class="font-bold text-primary hover:underline">เขาสระบบ</NuxtLink>
</div>
</form>
<!-- Confirm Password -->
<div>
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">นยนรหสผาน <span class="text-red-500">*</span></div>
<q-input
v-model="registerForm.confirmPassword"
outlined
dense
dark
:type="showConfirmPassword ? 'text' : 'password'"
placeholder="ยืนยันรหัสผ่านอีกครั้ง"
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.confirmPassword"
:error-message="errors.confirmPassword"
@update:model-value="clearFieldError('confirmPassword')"
hide-bottom-space
>
<template v-slot:append>
<q-icon
:name="showConfirmPassword ? 'visibility_off' : 'visibility'"
class="cursor-pointer text-slate-400 hover:text-white transition-colors"
@click="showConfirmPassword = !showConfirmPassword"
/>
</template>
</q-input>
</div>
<!-- Name Section -->
<div class="grid grid-cols-12 gap-4">
<!-- Prefix -->
<div class="col-span-4">
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">คำนำหน</div>
<q-select
v-model="registerForm.prefix"
:options="prefixOptions"
outlined
dense
dark
class="rounded-lg custom-dark-input"
color="primary"
options-cover
/>
</div>
<!-- First Name -->
<div class="col-span-8">
<div class="text-base font-semibold text-slate-300 mb-2 ml-1"> <span class="text-red-500">*</span></div>
<q-input
:model-value="registerForm.firstName"
outlined
dense
dark
placeholder=""
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.firstName"
:error-message="errors.firstName"
@update:model-value="onFirstNameInput"
hide-bottom-space
/>
</div>
</div>
<!-- Last Name -->
<div>
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">นามสก <span class="text-red-500">*</span></div>
<q-input
:model-value="registerForm.lastName"
outlined
dense
dark
placeholder=""
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.lastName"
:error-message="errors.lastName"
@update:model-value="onLastNameInput"
hide-bottom-space
/>
</div>
<!-- Phone -->
<div>
<div class="text-base font-semibold text-slate-300 mb-2 ml-1">เบอรโทรศพท <span class="text-red-500">*</span></div>
<q-input
:model-value="registerForm.phone"
outlined
dense
dark
type="tel"
placeholder=""
class="rounded-lg custom-dark-input"
color="primary"
:error="!!errors.phone"
:error-message="errors.phone"
@update:model-value="onPhoneInput"
hide-bottom-space
/>
</div>
<!-- Submit Button -->
<q-btn
type="submit"
unelevated
rounded
color="primary"
class="w-full h-12 text-lg font-bold shadow-lg shadow-blue-500/20 bg-blue-600 hover:bg-blue-500 mt-4"
:loading="isLoading"
>
สรางบญช
<template v-slot:loading>
<q-spinner-dots color="white" />
</template>
</q-btn>
<!-- Login Link -->
<div class="text-center pt-6 border-t border-slate-700 mt-2 text-base text-slate-400">
ญชอยแล?
<NuxtLink to="/auth/login" class="font-bold text-blue-400 hover:text-blue-300 transition-colors ml-1">
เขาสระบบ
</NuxtLink>
</div>
</form>
</q-card>
</div>
</template>
<style scoped>
/* Force Dark Theme for Card */
.auth-card {
background-color: #1e293b; /* Slate 800 */
border-color: transparent;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5),
0 2px 4px -1px rgba(0, 0, 0, 0.06);
color: #f8fafc;
.font-inter {
font-family: 'Inter', 'Prompt', sans-serif;
}
/* Input Overrides for Dark Mode integration within this page */
.dark-input {
background-color: #334155; /* Slate 700 */
border-color: #475569; /* Slate 600 */
color: #f1f5f9;
/* Custom dark input styling */
.custom-dark-input :deep(.q-field__control) {
background: #334155 !important;
border-radius: 8px;
}
.dark-input:focus {
.custom-dark-input :deep(.q-field__control:before) {
border-color: #475569;
}
.custom-dark-input :deep(.q-field--focused .q-field__control:after) {
border-color: #3b82f6;
outline: none;
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
/* Deep selector for FormInput component internals */
:deep(.input-field) {
background-color: #334155 !important;
border-color: #475569 !important;
color: #f1f5f9 !important;
}
:deep(.input-field::placeholder) {
color: #94a3b8;
}
:deep(.input-label) {
color: #cbd5e1 !important;
}
:deep(.input-label span.required-mark) {
color: #ef4444;
}
/* Select option styling */
option {
background-color: #334155;
/* Adjust QSelect to match */
.custom-dark-input :deep(.q-field__native) {
color: white;
}
</style>
<style>
/*
Global Override for Auth Layout Background on this page context.
Ensures the entire page background matches the design requirement.
*/
.auth-shell {
background-color: #0f172a !important; /* Slate 900 */
}
</style>