111 lines
2.8 KiB
Vue
111 lines
2.8 KiB
Vue
<script setup lang="ts">
|
||||
|
|
import { ref } from 'vue'
|
|||
|
|
import { useRouter } from 'vue-router'
|
|||
|
|
import { useAuthStore } from '@/stores/auth'
|
|||
|
|
import BaseInput from '@/components/ui/BaseInput.vue'
|
|||
|
|
import FormErrorBanner from '@/components/ui/FormErrorBanner.vue'
|
|||
|
|
import BaseButton from '@/components/ui/BaseButton.vue'
|
|||
|
|
import { normalizePhone } from '@/utils/format'
|
|||
|
|
import {
|
|||
|
|
FORM_VALIDATION_SUMMARY,
|
|||
|
|
clearFieldError,
|
|||
|
|
hasFieldErrors,
|
|||
|
|
type FieldErrors,
|
|||
|
|
} from '@/utils/formErrors'
|
|||
|
|
|
|||
|
|
const router = useRouter()
|
|||
|
|
const auth = useAuthStore()
|
|||
|
|
|
|||
|
|
const phone = ref('')
|
|||
|
|
const fieldErrors = ref<FieldErrors>({})
|
|||
|
|
const formError = ref('')
|
|||
|
|
|
|||
|
|
function clearPhoneError() {
|
|||
|
|
fieldErrors.value = clearFieldError(fieldErrors.value, 'phone')
|
|||
|
|
if (!hasFieldErrors(fieldErrors.value)) formError.value = ''
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async function submit() {
|
|||
|
|
fieldErrors.value = {}
|
|||
|
|
formError.value = ''
|
|||
|
|
|
|||
|
|
const normalized = normalizePhone(phone.value)
|
|||
|
|
const errors: FieldErrors = {}
|
|||
|
|
|
|||
|
|
if (!/^09\d{9}$/.test(normalized)) {
|
|||
|
|
errors.phone = 'شماره موبایل معتبر نیست.'
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (hasFieldErrors(errors)) {
|
|||
|
|
fieldErrors.value = errors
|
|||
|
|
formError.value = FORM_VALIDATION_SUMMARY
|
|||
|
|
return
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const result = await auth.requestOtp(normalized, { isRegister: false })
|
|||
|
|
if (result.success) {
|
|||
|
|
router.push({ name: 'otp', query: { phone: normalized, mode: 'login' } })
|
|||
|
|
} else {
|
|||
|
|
formError.value = result.message ?? 'خطا در ارسال کد تأیید.'
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
|
|||
|
|
<template>
|
|||
|
|
<div class="page auth-page">
|
|||
|
|
<div class="page__scroll auth-page__scroll">
|
|||
|
|
<div class="auth-header">
|
|||
|
|
<div class="logo">🧵</div>
|
|||
|
|
<h1 class="page-title">ورود به سامانه</h1>
|
|||
|
|
<p class="page-subtitle">سامانه سفارش عمده پارچه</p>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="card">
|
|||
|
|
<FormErrorBanner :message="formError" />
|
|||
|
|
|
|||
|
|
<BaseInput
|
|||
|
|
v-model="phone"
|
|||
|
|
label="شماره موبایل"
|
|||
|
|
type="tel"
|
|||
|
|
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
|
|||
|
|
:error="fieldErrors.phone"
|
|||
|
|
hint="کد تأیید به این شماره ارسال میشود"
|
|||
|
|
@update:model-value="clearPhoneError"
|
|||
|
|
/>
|
|||
|
|
<BaseButton block :loading="auth.loading" @click="submit">دریافت کد تأیید</BaseButton>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<p class="auth-footer text-center text-sm">
|
|||
|
|
حساب کاربری ندارید؟
|
|||
|
|
<router-link to="/register">ثبتنام</router-link>
|
|||
|
|
</p>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
</template>
|
|||
|
|
|
|||
|
|
<style scoped>
|
|||
|
|
.auth-page {
|
|||
|
|
overflow: hidden;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.auth-page__scroll {
|
|||
|
|
padding-top: 36px;
|
|||
|
|
padding-bottom: 24px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.auth-header {
|
|||
|
|
text-align: center;
|
|||
|
|
margin-bottom: 32px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.logo {
|
|||
|
|
font-size: 3rem;
|
|||
|
|
margin-bottom: 12px;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
.auth-footer {
|
|||
|
|
margin-top: 24px;
|
|||
|
|
color: var(--color-text-muted);
|
|||
|
|
}
|
|||
|
|
</style>
|