105 lines
3.0 KiB
Vue
105 lines
3.0 KiB
Vue
<template>
|
|
<!--
|
|
Ported from legacy henza_admin/src/views/branch/login.vue — the branch-mode
|
|
sign-in. A different layout from the admin login (centred logo, no split
|
|
illustration panel), but the same auth action underneath.
|
|
|
|
Legacy's right-hand illustration panel is COMMENTED OUT and stays absent.
|
|
-->
|
|
<div class="flex gap-6 w-full justify-center h-screen branch-login-page">
|
|
<div class="flex flex-col h-screen items-center justify-center">
|
|
<img
|
|
src="../../assets/images/logo/henza-icon.svg"
|
|
width="150"
|
|
alt="login"
|
|
class="mx-auto mb-5"
|
|
/>
|
|
|
|
<a-form layout="vertical" class="login-form" @submit.prevent="handleSubmit">
|
|
<a-form-item
|
|
label="نام کاربری"
|
|
class="w-full"
|
|
:validate-status="err.phone ? 'error' : ''"
|
|
:help="err.phone"
|
|
>
|
|
<a-input v-model:value="form.phone" size="large" />
|
|
</a-form-item>
|
|
|
|
<a-form-item
|
|
label="رمز عبور"
|
|
class="w-full"
|
|
:validate-status="err.password ? 'error' : ''"
|
|
:help="err.password"
|
|
>
|
|
<a-input-password
|
|
v-model:value="form.password"
|
|
size="large"
|
|
@press-enter="handleSubmit"
|
|
/>
|
|
</a-form-item>
|
|
|
|
<a-button
|
|
size="large"
|
|
type="primary"
|
|
class="mt-8 w-full"
|
|
:loading="loading"
|
|
@click="handleSubmit"
|
|
>
|
|
ورود
|
|
</a-button>
|
|
</a-form>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { reactive, ref } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { message } from 'ant-design-vue';
|
|
import { useAuthStore } from '../../stores/auth';
|
|
|
|
const router = useRouter();
|
|
const auth = useAuthStore();
|
|
|
|
const loading = ref(false);
|
|
const form = reactive({ phone: '', password: '' });
|
|
const err = reactive<Record<string, string>>({});
|
|
|
|
async function handleSubmit() {
|
|
Object.keys(err).forEach((k) => delete err[k]);
|
|
if (!form.phone) err.phone = 'نام کاربری را وارد نمایید';
|
|
if (!form.password) err.password = 'رمز عبور را وارد نمایید';
|
|
if (Object.keys(err).length) return;
|
|
|
|
try {
|
|
loading.value = true;
|
|
await auth.login({ phone: form.phone, password: form.password });
|
|
// legacy did a hard window.location.href = '/branch/dashboard'; a router
|
|
// push reaches the same route without discarding the populated store.
|
|
await router.push('/dashboard');
|
|
} catch (e) {
|
|
console.log(e);
|
|
message.error('خطا در ورود');
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.branch-login-page {
|
|
display: flex;
|
|
width: 100%;
|
|
justify-content: center;
|
|
min-height: 100vh;
|
|
}
|
|
.flex-col { flex-direction: column; }
|
|
.justify-center { justify-content: center; }
|
|
.h-screen { min-height: 100vh; }
|
|
.gap-6 { gap: 1.5rem; }
|
|
.mx-auto { margin: 0 auto; }
|
|
.mb-5 { margin-bottom: 1.25rem; }
|
|
.mt-8 { margin-top: 2rem; }
|
|
.login-form { width: 320px; max-width: 90vw; }
|
|
</style>
|