refactor(chat + workspace): chat和workspace重构,子路由、懒加载等
This commit is contained in:
1 parent
0a647a0b79
commit
1f1f7236b0
57 files changed
+4356
-3798
No files matched your search
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* features/auth/api/user.api.ts
|
||||
* 用户域 HTTP API:资料、请假、密码重置、Agent 列表等。
|
||||
*/
|
||||
import { getAuthHeaders } from '@/utils/auth';
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
|
||||
const auth = () => ({ headers: getAuthHeaders() });
|
||||
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
||||
|
||||
export const getUserProfile = () => requestJson<Record<string, any>>('/api/user/profile', auth());
|
||||
|
||||
export interface LeaveBalanceResult {
|
||||
has_balance: boolean;
|
||||
leave_type_label: string;
|
||||
year: number;
|
||||
total_hours: number | null;
|
||||
used_hours: number | null;
|
||||
remaining_hours: number | null;
|
||||
}
|
||||
|
||||
export const getLeaveBalance = (leaveType: string) =>
|
||||
requestJson<LeaveBalanceResult>(`/api/user/leave-balance?leave_type=${encodeURIComponent(leaveType)}`, auth());
|
||||
|
||||
export interface LeaveWorkflowSubmitResult {
|
||||
request_id?: string;
|
||||
submitted_at?: string;
|
||||
request_name?: string;
|
||||
}
|
||||
|
||||
export const submitLeaveWorkflow = (form: Record<string, any>) =>
|
||||
requestJson<LeaveWorkflowSubmitResult>('/api/user/leave-workflow/submit', {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify(form),
|
||||
});
|
||||
|
||||
export const resetPasswordConfirm = (token: string, newPassword: string) =>
|
||||
requestJson('/api/user/reset-password-confirm', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token, new_password: newPassword }),
|
||||
});
|
||||
|
||||
export const getUserAgent = (agentId: number) =>
|
||||
requestJson<Record<string, any>>(`/api/user/agents/${agentId}`, auth());
|
||||
|
||||
export const listUserAgents = () => requestJson<any[]>('/api/agents', auth());
|
||||
|
||||
export const listAgentGuides = (agentId: number) => requestJson<any[]>(`/api/agents/${agentId}/guides`, auth());
|
||||
@@ -0,0 +1,195 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/auth/components/LoginModals.vue
|
||||
* 登录相关弹窗:找回密码、公告详情、企微登录/绑定提示、注册。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Lock, User, X } from 'lucide-vue-next';
|
||||
import { formatWecomFieldLabel } from '@/utils/wecom';
|
||||
import { LOGIN_KEY } from '../composables/login.context';
|
||||
|
||||
const { t } = useI18n();
|
||||
const lk = inject(LOGIN_KEY)! as any;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div
|
||||
v-if="lk.showForgotPasswordModal"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.showForgotPasswordModal = false"
|
||||
>
|
||||
<div class="dialog-panel max-w-md animate-slide-up">
|
||||
<div class="dialog-header dialog-header--compact relative border-0 pb-0">
|
||||
<div class="flex-1" />
|
||||
<button type="button" class="btn-icon-ds" :aria-label="$t('admin.close')" @click="lk.showForgotPasswordModal = false">
|
||||
<X class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body pt-0 text-center">
|
||||
<div class="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-xl bg-brand-100 text-brand-600">
|
||||
<Lock class="w-6 h-6" />
|
||||
</div>
|
||||
<h3 class="text-xl font-bold text-primary">{{ $t('login.forgotPassword') }}</h3>
|
||||
<p class="mt-2 text-sm text-muted">{{ $t('login.forgotPasswordDesc') }}</p>
|
||||
<div class="mt-6 space-y-2 text-left">
|
||||
<label class="label-field ml-1">{{ $t('register.email') }}</label>
|
||||
<input v-model="lk.forgotPasswordForm.email" :placeholder="$t('register.email')" class="input-field" @keyup.enter="lk.handleForgotPassword" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" @click="lk.showForgotPasswordModal = false" class="btn-secondary flex-1">{{ $t('register.cancel') }}</button>
|
||||
<button type="button" @click="lk.handleForgotPassword" class="btn-primary flex-1">{{ $t('login.findPassword') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="lk.showAnnouncementModal && lk.selectedAnnouncement"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.showAnnouncementModal = false"
|
||||
>
|
||||
<div class="dialog-panel max-w-2xl max-h-[85vh] animate-slide-up">
|
||||
<div class="dialog-header">
|
||||
<div class="min-w-0">
|
||||
<span class="inline-flex rounded-full bg-brand-50 px-2 py-1 text-xs font-bold text-brand-600">{{ new Date(lk.selectedAnnouncement.created_at).toLocaleDateString() }}</span>
|
||||
<h3 class="mt-2 text-2xl font-bold text-primary">{{ lk.selectedAnnouncement.title }}</h3>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" :aria-label="$t('admin.close')" @click="lk.showAnnouncementModal = false">
|
||||
<X class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body">
|
||||
<p class="whitespace-pre-wrap leading-relaxed text-secondary">{{ lk.selectedAnnouncement.content }}</p>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" @click="lk.showAnnouncementModal = false" class="btn-primary">
|
||||
{{ $t('admin.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="lk.wecomLoginDialog"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.wecomLoginDialog = null"
|
||||
>
|
||||
<div class="dialog-panel max-w-lg animate-slide-up">
|
||||
<div class="dialog-header dialog-header--compact">
|
||||
<div class="flex items-start gap-3 min-w-0">
|
||||
<div class="flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-amber-100 text-amber-700">
|
||||
<Lock class="w-6 h-6" />
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-xl font-bold text-primary">{{ lk.wecomLoginDialog.title }}</h3>
|
||||
<p class="mt-2 text-sm leading-6 text-secondary">{{ lk.wecomLoginDialog.summary }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" :aria-label="$t('admin.close')" @click="lk.wecomLoginDialog = null">
|
||||
<X class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="lk.wecomLoginDialog?.details?.length || lk.wecomLoginDialog?.technical"
|
||||
class="dialog-body border-t-0 pt-0 space-y-4"
|
||||
>
|
||||
<div v-if="lk.wecomLoginDialog?.details?.length" class="rounded-2xl border border-default bg-surface-soft/80 px-4 py-4 space-y-3">
|
||||
<p v-for="(detail, index) in lk.wecomLoginDialog.details" :key="`${detail}-${index}`" class="text-sm leading-6 text-secondary">
|
||||
{{ detail }}
|
||||
</p>
|
||||
</div>
|
||||
<p v-if="lk.wecomLoginDialog.technical" class="break-all text-xs text-muted">
|
||||
{{ $t('login.wecomTechnicalInfo', { detail: lk.wecomLoginDialog.technical }) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" @click="lk.wecomLoginDialog = null" class="btn-secondary">{{ $t('admin.close') }}</button>
|
||||
<button type="button" @click="lk.wecomLoginDialog = null; lk.handleWecomLogin()" class="btn-primary" :disabled="lk.isWecomLoggingIn">
|
||||
{{ $t('login.wecomRetry') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="lk.wecomBindPrompt"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.wecomBindPrompt = null"
|
||||
>
|
||||
<div class="dialog-panel max-w-lg animate-slide-up">
|
||||
<div class="dialog-header dialog-header--compact">
|
||||
<div class="flex items-start gap-3 min-w-0">
|
||||
<div class="mb-0 flex h-12 w-12 shrink-0 items-center justify-center rounded-xl bg-blue-100 text-blue-700">
|
||||
<User class="w-6 h-6" />
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-xl font-bold text-primary">{{ $t('login.wecomBindPromptTitle') }}</h3>
|
||||
<p class="mt-2 text-sm leading-6 text-secondary">
|
||||
{{ $t('login.wecomBindPromptDesc', { name: lk.wecomBindPrompt.wecom_name || '-' }) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds shrink-0" :aria-label="$t('admin.close')" @click="lk.wecomBindPrompt = null">
|
||||
<X class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body space-y-4 border-t-0 pt-0">
|
||||
<div>
|
||||
<label class="label-field mb-1.5 block">{{ $t('login.wecomBindField') }}</label>
|
||||
<select v-model="lk.wecomBindPrompt.field" class="input-field">
|
||||
<option v-for="field in lk.wecomBindPrompt.allowed_fields" :key="field" :value="field">
|
||||
{{ formatWecomFieldLabel(field, t) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label-field mb-1.5 block">{{ $t('login.wecomBindValue') }}</label>
|
||||
<input
|
||||
v-model="lk.wecomBindPrompt.value"
|
||||
class="input-field"
|
||||
:placeholder="$t('login.wecomBindValuePlaceholder', { field: formatWecomFieldLabel(lk.wecomBindPrompt.field, t) })"
|
||||
@keyup.enter="lk.submitWecomCompleteBind"
|
||||
/>
|
||||
</div>
|
||||
<p class="text-xs leading-5 text-muted">{{ $t('login.wecomBindPromptHint') }}</p>
|
||||
<p v-if="lk.wecomBindPrompt.error" class="text-sm leading-6 text-red-600">{{ lk.wecomBindPrompt.error }}</p>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" @click="lk.wecomBindPrompt = null" class="btn-secondary">{{ $t('admin.close') }}</button>
|
||||
<button type="button" @click="lk.submitWecomCompleteBind" class="btn-primary" :disabled="lk.wecomBindPrompt.submitting">
|
||||
{{ lk.wecomBindPrompt.submitting ? $t('login.wecomConnecting') : $t('login.wecomBindSubmit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="lk.showRegisterModal"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.showRegisterModal = false"
|
||||
>
|
||||
<div class="dialog-panel max-w-md animate-slide-up">
|
||||
<div class="dialog-header">
|
||||
<h3 class="section-title">{{ $t('register.title') }}</h3>
|
||||
<button type="button" class="btn-icon-ds" :aria-label="$t('admin.close')" @click="lk.showRegisterModal = false">
|
||||
<X class="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body space-y-4">
|
||||
<input v-model="lk.registerForm.real_name" :placeholder="$t('register.fields.realName')" class="input-field" />
|
||||
<input v-model="lk.registerForm.employee_id" :placeholder="$t('register.fields.employeeId')" class="input-field" />
|
||||
<input v-model="lk.registerForm.phone_number" :placeholder="$t('register.fields.phone')" class="input-field" />
|
||||
<input v-model="lk.registerForm.username" :placeholder="$t('register.username')" class="input-field" />
|
||||
<input v-model="lk.registerForm.email" :placeholder="$t('register.email')" class="input-field" />
|
||||
<input v-model="lk.registerForm.password" type="password" :placeholder="$t('register.password')" class="input-field" />
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
<button type="button" @click="lk.showRegisterModal = false" class="btn-secondary">{{ $t('register.cancel') }}</button>
|
||||
<button type="button" @click="lk.handleRegister" class="btn-primary">{{ $t('register.submit') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,109 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/auth/components/LoginPage.vue
|
||||
* 登录页主内容:营销文案、公告列表与用户名/密码/企微登录表单。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { Bot, Megaphone } from 'lucide-vue-next';
|
||||
import { LOGIN_KEY } from '../composables/login.context';
|
||||
|
||||
const lk = inject(LOGIN_KEY)! as any;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="lk.isLoading" class="animate-pulse space-y-8">
|
||||
<div class="h-48 bg-gray-200 rounded-2xl"></div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<div class="h-40 bg-gray-200 rounded-2xl"></div>
|
||||
<div class="h-40 bg-gray-200 rounded-2xl"></div>
|
||||
<div class="h-40 bg-gray-200 rounded-2xl"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
class="relative min-h-[calc(100vh-4rem)] overflow-hidden rounded-[2rem] flex items-center justify-center"
|
||||
:style="lk.loginBackgroundStyle"
|
||||
>
|
||||
<div class="absolute inset-0 bg-white/55 backdrop-blur-[1px]"></div>
|
||||
<div class="relative z-10 w-full max-w-6xl grid grid-cols-1 lg:grid-cols-2 gap-12 items-center p-4">
|
||||
<div class="hidden lg:block space-y-8 animate-slide-up">
|
||||
<h1 class="text-5xl font-bold text-black leading-tight drop-shadow-sm">
|
||||
{{ $t('landing.hero.prefix') }} <br/>
|
||||
<span class="text-transparent bg-clip-text bg-gradient-to-r from-[#005a9c] to-[#7a1fd0] drop-shadow-sm">{{ $t('landing.hero.highlight') }}</span>
|
||||
</h1>
|
||||
<p class="text-lg text-primary max-w-md leading-relaxed font-semibold drop-shadow-sm">
|
||||
{{ $t('landing.hero.subtitle') }}
|
||||
</p>
|
||||
|
||||
<div v-if="lk.announcements.length > 0" class="bg-white/70 backdrop-blur-sm rounded-2xl border border-default p-6 shadow-sm">
|
||||
<h3 class="text-sm font-bold text-slate-950 mb-4 flex items-center gap-2">
|
||||
<Megaphone class="w-4 h-4 text-brand-600" />
|
||||
{{ $t('login.announcements') }}
|
||||
</h3>
|
||||
<div class="space-y-3">
|
||||
<div
|
||||
v-for="ann in lk.announcements.slice(0, 3)"
|
||||
:key="ann.id"
|
||||
class="group cursor-pointer hover:bg-white/50 p-2 rounded-lg transition-colors"
|
||||
@click="lk.openAnnouncement(ann)"
|
||||
>
|
||||
<div class="flex justify-between items-start gap-2">
|
||||
<h4 class="text-sm font-semibold text-primary group-hover:text-brand-800 line-clamp-1">{{ ann.title }}</h4>
|
||||
<span class="text-[10px] text-muted whitespace-nowrap">{{ new Date(ann.created_at).toLocaleDateString() }}</span>
|
||||
</div>
|
||||
<p class="text-xs text-secondary line-clamp-2 mt-1">{{ ann.content }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full max-w-md mx-auto">
|
||||
<div class="bg-white/90 backdrop-blur-xl rounded-3xl border border-white/20 shadow-2xl shadow-brand-900/10 p-8 md:p-10 animate-fade-in relative overflow-hidden">
|
||||
<div class="absolute top-0 left-0 w-full h-1.5 bg-gradient-to-r from-brand-500 to-purple-600"></div>
|
||||
|
||||
<div class="text-center mb-8">
|
||||
<div class="w-12 h-12 bg-brand-600 rounded-xl mx-auto flex items-center justify-center text-white shadow-lg shadow-brand-600/30 mb-4 lg:hidden">
|
||||
<Bot class="w-7 h-7" />
|
||||
</div>
|
||||
<h2 class="text-2xl font-bold text-primary">{{ $t('login.submit') }}</h2>
|
||||
<p class="text-secondary text-sm mt-2">{{ $t('login.subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-primary uppercase ml-1">{{ $t('login.username') }}</label>
|
||||
<input v-model="lk.loginUsername" type="text" class="input-field" :placeholder="$t('login.placeholder.username')" @keyup.enter="lk.handleLogin" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-primary uppercase ml-1">{{ $t('login.password') }}</label>
|
||||
<input v-model="lk.loginPassword" type="password" class="input-field" :placeholder="$t('login.placeholder.password')" @keyup.enter="lk.handleLogin" />
|
||||
</div>
|
||||
|
||||
<button type="button" @click="lk.handleLogin" class="btn-primary w-full py-3 text-base shadow-brand-500/40 hover:shadow-brand-500/50 transform hover:-translate-y-0.5 transition-all mt-4">
|
||||
{{ $t('login.submit') }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
v-if="lk.config.auth?.wecom?.enabled && (!lk.config.auth?.wecom?.loginViaCasdoor || lk.config.auth?.casdoor?.enabled)"
|
||||
@click="lk.handleWecomLogin"
|
||||
:disabled="lk.isWecomLoggingIn"
|
||||
class="btn-secondary w-full py-3 text-base mt-3 disabled:opacity-60 disabled:cursor-not-allowed"
|
||||
>
|
||||
{{ lk.isWecomLoggingIn ? $t('login.wecomConnecting') : $t('login.wecomLogin') }}
|
||||
</button>
|
||||
|
||||
<div class="flex justify-between items-center pt-4 mt-2 border-t border-subtle/50">
|
||||
<button type="button" @click="lk.showForgotPasswordModal = true" class="text-sm text-secondary hover:text-brand-700 transition-colors">
|
||||
{{ $t('login.forgotPassword') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* features/auth/composables/login.context.ts
|
||||
* 登录页 provide/inject 上下文类型与注入 key。
|
||||
*/
|
||||
import type { InjectionKey } from 'vue';
|
||||
import type { useLogin } from './useLogin';
|
||||
|
||||
export type LoginContext = ReturnType<typeof useLogin>;
|
||||
export const LOGIN_KEY: InjectionKey<LoginContext> = Symbol('login');
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* features/auth/composables/login.deps.ts
|
||||
* 登录页 composables 共享依赖(i18n、路由、主题、消息等)。
|
||||
*/
|
||||
import type { ComputedRef, WritableComputedRef } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router';
|
||||
import type { useMessage } from '@/composables/useMessage';
|
||||
import type { ThemePreference } from '@/composables/useTheme';
|
||||
|
||||
export interface LoginDeps {
|
||||
t: ComposerTranslation;
|
||||
locale: WritableComputedRef<string>;
|
||||
msg: ReturnType<typeof useMessage>;
|
||||
router: Router;
|
||||
route: RouteLocationNormalizedLoaded;
|
||||
setThemePreference: (pref: ThemePreference) => void;
|
||||
appliedTheme: ComputedRef<ThemePreference>;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* features/auth/composables/useLogin.ts
|
||||
* 登录页编排层:组合认证、公告展示与 OAuth 回调,provide 给 LoginView 子组件。
|
||||
*/
|
||||
import { onMounted, reactive } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { config } from '@/config';
|
||||
import { useTheme } from '@/composables/useTheme';
|
||||
import { useMessage } from '@/composables/useMessage';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import loginBg from '@/assets/login-bg.png';
|
||||
import { DEFAULT_POST_LOGIN_AGENT_ID } from '@/features/workspace/types/workspace.types';
|
||||
import { useWorkspaceLocale } from '@/features/workspace/composables/useWorkspaceLocale';
|
||||
import { useLoginAuth } from './useLoginAuth';
|
||||
import { useLoginLanding } from './useLoginLanding';
|
||||
|
||||
export function useLogin() {
|
||||
const { t, locale } = useI18n();
|
||||
const msg = useMessage();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const { setThemePreference, appliedTheme } = useTheme();
|
||||
|
||||
const deps = { t, locale, msg, router, route, setThemePreference, appliedTheme };
|
||||
const landing = useLoginLanding();
|
||||
|
||||
const completePasswordLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
await router.replace(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||
};
|
||||
|
||||
const completeOAuthLogin = async () => {
|
||||
authStore.syncFromStorage();
|
||||
await router.replace('/workspace/applications');
|
||||
};
|
||||
|
||||
const loginAuth = useLoginAuth(deps, { completePasswordLogin, completeOAuthLogin });
|
||||
const localeApi = useWorkspaceLocale(deps);
|
||||
|
||||
const loginBackgroundStyle = {
|
||||
backgroundImage: `url(${loginBg})`,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
localeApi.loadLanguagePreference();
|
||||
void landing.fetchAnnouncements();
|
||||
|
||||
const handledCasdoor = await loginAuth.tryCasdoorCallbackLogin();
|
||||
if (handledCasdoor) return;
|
||||
|
||||
const handledWecom = await loginAuth.tryWecomCallbackLogin();
|
||||
if (handledWecom) return;
|
||||
|
||||
authStore.syncFromStorage();
|
||||
if (authStore.isLoggedIn) {
|
||||
await router.replace('/workspace/applications');
|
||||
return;
|
||||
}
|
||||
|
||||
await landing.fetchPublicAgents();
|
||||
landing.isLoading.value = false;
|
||||
});
|
||||
|
||||
return reactive({
|
||||
config,
|
||||
msg,
|
||||
loginBackgroundStyle,
|
||||
...localeApi,
|
||||
...landing,
|
||||
...loginAuth,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
/**
|
||||
* features/auth/composables/useLoginAuth.ts
|
||||
* 登录表单、企微/Casdoor OAuth 回调、注册与找回密码逻辑。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { config } from '@/config';
|
||||
import { resolveCasdoorErrorMessage } from '@/utils/casdoor';
|
||||
import {
|
||||
buildWecomLoginDialogContent,
|
||||
normalizeWecomMatchRules,
|
||||
type WecomMatchField,
|
||||
} from '@/utils/wecom';
|
||||
import { saveAuthUser } from '@/utils/auth';
|
||||
import { BusinessError, requestJson } from '@/api/client';
|
||||
import { DEFAULT_POST_LOGIN_AGENT_ID } from '@/features/workspace/types/workspace.types';
|
||||
import type { WecomBindPromptState, WecomLoginDialogContent } from '@/features/workspace/types/workspace.types';
|
||||
import type { LoginDeps } from './login.deps';
|
||||
|
||||
interface LoginAuthOptions {
|
||||
completePasswordLogin: () => Promise<void>;
|
||||
completeOAuthLogin: () => Promise<void>;
|
||||
}
|
||||
|
||||
const LOGIN_CALLBACK_PATHS = ['/login', '/workspace'] as const;
|
||||
|
||||
function isLoginCallbackPath(path: string, extraPaths: string[] = []): boolean {
|
||||
return LOGIN_CALLBACK_PATHS.includes(path as (typeof LOGIN_CALLBACK_PATHS)[number])
|
||||
|| extraPaths.includes(path);
|
||||
}
|
||||
|
||||
export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
const { t, msg } = deps;
|
||||
const { completePasswordLogin, completeOAuthLogin } = options;
|
||||
|
||||
const loginUsername = ref('');
|
||||
const loginPassword = ref('');
|
||||
const rememberMe = ref(false);
|
||||
const showRegisterModal = ref(false);
|
||||
const showForgotPasswordModal = ref(false);
|
||||
const registerForm = ref({
|
||||
username: '',
|
||||
password: '',
|
||||
email: '',
|
||||
real_name: '',
|
||||
employee_id: '',
|
||||
phone_number: '',
|
||||
});
|
||||
const forgotPasswordForm = ref({ email: '' });
|
||||
const isWecomLoggingIn = ref(false);
|
||||
const wecomLoginDialog = ref<WecomLoginDialogContent | null>(null);
|
||||
const wecomBindPrompt = ref<WecomBindPromptState | null>(null);
|
||||
|
||||
const clearWecomCallbackQuery = () => {
|
||||
const nextUrl = `${window.location.pathname}${window.location.hash || ''}`;
|
||||
window.history.replaceState({}, '', nextUrl);
|
||||
};
|
||||
|
||||
const persistLoginUser = (user: Record<string, unknown>) => {
|
||||
saveAuthUser({ ...(user || {}) }, rememberMe.value);
|
||||
};
|
||||
|
||||
const handleForgotPassword = async () => {
|
||||
if (!forgotPasswordForm.value.email) {
|
||||
msg.warning(t('register.emailRequired'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await requestJson('/api/user/reset-password-by-email', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(forgotPasswordForm.value),
|
||||
});
|
||||
msg.success(t('login.passwordResetEmailSent'));
|
||||
showForgotPasswordModal.value = false;
|
||||
forgotPasswordForm.value = { email: '' };
|
||||
} catch (e) {
|
||||
console.error('Password reset error', e);
|
||||
msg.error((e as Error)?.message || t('login.passwordResetRequestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogin = async (event?: Event) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
|
||||
if (!loginUsername.value.trim()) {
|
||||
msg.warning(t('login.usernameRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const loginMode = String(config.auth?.loginMode || 'casdoor').toLowerCase();
|
||||
const isCasdoorMode = loginMode === 'casdoor';
|
||||
const loginApi = isCasdoorMode
|
||||
? (config.auth?.casdoor?.passwordLoginApi || '/api/user/casdoor/password-login')
|
||||
: '/api/user/login';
|
||||
const user = await requestJson<Record<string, unknown>>(loginApi, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username: loginUsername.value.trim(),
|
||||
password: loginPassword.value,
|
||||
}),
|
||||
});
|
||||
|
||||
persistLoginUser(user);
|
||||
await completePasswordLogin();
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
const rawError = String(err.message || '');
|
||||
let errorText = resolveCasdoorErrorMessage(err, t);
|
||||
if (rawError === 'User not found') errorText = t('login.userNotFound');
|
||||
if (rawError === 'Incorrect password') errorText = t('login.incorrectPassword');
|
||||
if (rawError === 'Account is disabled') errorText = t('login.accountDisabled');
|
||||
if (rawError === 'Database connection failed') errorText = t('login.dbConnectionFailed');
|
||||
if (rawError === 'Internal server error') errorText = t('login.internalError');
|
||||
console.error(e);
|
||||
msg.error(errorText || t('login.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const tryCasdoorCallbackLogin = async () => {
|
||||
if (!config.auth?.casdoor?.enabled) return false;
|
||||
const casdoorPath = config.auth.casdoor.callbackPath || '/casdoor-callback';
|
||||
const path = window.location.pathname;
|
||||
if (!isLoginCallbackPath(path, [casdoorPath])) return false;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const code = params.get('code');
|
||||
const state = params.get('state');
|
||||
if (!code) return false;
|
||||
|
||||
const expectedState = sessionStorage.getItem('hxops_casdoor_state');
|
||||
const shouldStrictCheck = !!expectedState && !!state && !String(state).startsWith('hxops_casdoor_v1.');
|
||||
if (shouldStrictCheck && state !== expectedState) {
|
||||
msg.error(t('login.casdoorErrors.stateExpired'));
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
const api = config.auth.casdoor.loginApi || '/api/user/casdoor/login';
|
||||
const data = await requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
persistLoginUser(data);
|
||||
sessionStorage.removeItem('hxops_casdoor_state');
|
||||
await completeOAuthLogin();
|
||||
return true;
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
console.error(e);
|
||||
msg.error(resolveCasdoorErrorMessage(err, t));
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const handleWecomLogin = async () => {
|
||||
if (!config.auth?.wecom?.enabled) return;
|
||||
const wecomCfg = config.auth.wecom as { loginViaCasdoor?: boolean; callbackPath?: string; authorizeApi?: string };
|
||||
const viaCasdoor = Boolean(wecomCfg?.loginViaCasdoor);
|
||||
try {
|
||||
if (viaCasdoor) {
|
||||
if (!config.auth?.casdoor?.enabled) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
}
|
||||
const callbackPath = config.auth.casdoor.callbackPath || '/casdoor-callback';
|
||||
const redirectUri = `${window.location.origin}${callbackPath}`;
|
||||
const api = config.auth.casdoor.authorizeApi || '/api/user/casdoor/authorize-url';
|
||||
const qs = new URLSearchParams({ redirect_uri: redirectUri, default_provider: 'wecom' });
|
||||
const hint = (config.auth.casdoor as { wecomProviderHint?: string }).wecomProviderHint?.trim();
|
||||
if (hint) qs.set('provider_hint', hint);
|
||||
const data = await requestJson<{ url?: string; state?: string }>(`${api}?${qs.toString()}`);
|
||||
if (!data?.url) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
}
|
||||
if (data.state) sessionStorage.setItem('hxops_casdoor_state', data.state);
|
||||
window.location.href = data.url;
|
||||
return;
|
||||
}
|
||||
|
||||
const callbackPath = wecomCfg.callbackPath || '/login';
|
||||
const redirectUri = `${window.location.origin}${callbackPath}`;
|
||||
const api = wecomCfg.authorizeApi || '/api/user/wecom/authorize-url';
|
||||
const data = await requestJson<{ url?: string; state?: string }>(
|
||||
`${api}?redirect_uri=${encodeURIComponent(redirectUri)}`,
|
||||
);
|
||||
if (!data?.url) {
|
||||
msg.error(t('login.wecomStartFailed'));
|
||||
return;
|
||||
}
|
||||
if (data.state) sessionStorage.setItem('hxops_wecom_state', data.state);
|
||||
window.location.href = data.url;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error)?.message || t('login.wecomStartFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const openWecomLoginDialog = (payload: Record<string, unknown>) => {
|
||||
wecomLoginDialog.value = buildWecomLoginDialogContent(payload, t);
|
||||
};
|
||||
|
||||
const openWecomBindPrompt = (payload: Record<string, unknown>) => {
|
||||
const allowedFields = normalizeWecomMatchRules(payload.allowed_fields).fields;
|
||||
const fallbackFields: WecomMatchField[] = ['employee_id', 'mobile', 'email'];
|
||||
const fields: WecomMatchField[] = allowedFields.length ? allowedFields : fallbackFields;
|
||||
wecomBindPrompt.value = {
|
||||
binding_token: String(payload.binding_token || ''),
|
||||
allowed_fields: fields,
|
||||
wecom_name: String(payload.wecom_name || ''),
|
||||
field: fields[0] || 'employee_id',
|
||||
value: '',
|
||||
submitting: false,
|
||||
error: '',
|
||||
};
|
||||
};
|
||||
|
||||
const formatWecomBindPromptError = (payload: Record<string, unknown>) => {
|
||||
const errorCode = String(payload.error_code || '');
|
||||
if (errorCode === 'WECOM_BIND_INPUT_NOT_FOUND') return t('login.wecomBindInputNotFound');
|
||||
if (errorCode === 'WECOM_BIND_INPUT_AMBIGUOUS') return t('login.wecomBindInputAmbiguous');
|
||||
if (errorCode === 'WECOM_BIND_SESSION_EXPIRED') return t('login.wecomBindSessionExpired');
|
||||
if (errorCode === 'WECOM_BIND_CONFLICT') return t('login.wecomBindConflict');
|
||||
if (errorCode === 'WECOM_BIND_FIELD_NOT_ALLOWED') return t('login.wecomBindFieldNotAllowed');
|
||||
if (errorCode === 'WECOM_BIND_INPUT_VALUE_REQUIRED') return t('login.wecomBindValueRequired');
|
||||
if (String(payload.error || '').includes('Account is disabled')) return t('login.wecomAccountDisabled');
|
||||
return String(payload.error || t('login.wecomLoginFailed'));
|
||||
};
|
||||
|
||||
const submitWecomCompleteBind = async () => {
|
||||
if (!wecomBindPrompt.value) return;
|
||||
if (!wecomBindPrompt.value.value.trim()) {
|
||||
wecomBindPrompt.value.error = t('login.wecomBindValueRequired');
|
||||
return;
|
||||
}
|
||||
wecomBindPrompt.value.submitting = true;
|
||||
wecomBindPrompt.value.error = '';
|
||||
try {
|
||||
const api = config.auth.wecom.completeBindApi || '/api/user/wecom/complete-bind';
|
||||
const data = await requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
binding_token: wecomBindPrompt.value.binding_token,
|
||||
field: wecomBindPrompt.value.field,
|
||||
value: wecomBindPrompt.value.value.trim(),
|
||||
}),
|
||||
});
|
||||
wecomLoginDialog.value = null;
|
||||
persistLoginUser(data);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
wecomBindPrompt.value = null;
|
||||
await completeOAuthLogin();
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
if (wecomBindPrompt.value) {
|
||||
const errorPayload = { error: err.message, error_code: err.code };
|
||||
wecomBindPrompt.value.error = formatWecomBindPromptError(errorPayload);
|
||||
if (String(err.code || '') === 'WECOM_BIND_SESSION_EXPIRED') {
|
||||
openWecomLoginDialog(errorPayload);
|
||||
wecomBindPrompt.value = null;
|
||||
}
|
||||
}
|
||||
console.error(e);
|
||||
} finally {
|
||||
if (wecomBindPrompt.value) wecomBindPrompt.value.submitting = false;
|
||||
}
|
||||
};
|
||||
|
||||
const tryWecomCallbackLogin = async () => {
|
||||
if (!config.auth?.wecom?.enabled) return false;
|
||||
if ((config.auth.wecom as { loginViaCasdoor?: boolean }).loginViaCasdoor) return false;
|
||||
const wecomPath = config.auth.wecom.callbackPath || '/login';
|
||||
const path = window.location.pathname;
|
||||
if (path !== wecomPath && !isLoginCallbackPath(path)) return false;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const code = params.get('code');
|
||||
const state = params.get('state');
|
||||
if (!code) return false;
|
||||
|
||||
const expectedState = sessionStorage.getItem('hxops_wecom_state');
|
||||
if (expectedState && state && state !== expectedState) {
|
||||
msg.error(t('login.wecomInvalidState'));
|
||||
openWecomLoginDialog({ error: 'Invalid or expired WeCom state' });
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
}
|
||||
|
||||
isWecomLoggingIn.value = true;
|
||||
try {
|
||||
const api = config.auth.wecom.loginApi || '/api/user/wecom/login';
|
||||
const data = await requestJson<Record<string, unknown>>(api, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, state }),
|
||||
});
|
||||
wecomLoginDialog.value = null;
|
||||
persistLoginUser(data);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
await completeOAuthLogin();
|
||||
return true;
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
const rawError = String(err.message || '');
|
||||
const errorCode = String(err.code || '');
|
||||
let friendly = rawError || t('login.wecomLoginFailed');
|
||||
if (rawError.includes('Invalid or expired WeCom state')) friendly = t('login.wecomStateExpired');
|
||||
else if (rawError.includes('bind WeCom account') || rawError.includes('No linked account found')) {
|
||||
friendly = t('login.wecomBindRequired');
|
||||
} else if (rawError.includes('Account is disabled')) friendly = t('login.wecomAccountDisabled');
|
||||
console.error(e);
|
||||
msg.error(friendly);
|
||||
sessionStorage.removeItem('hxops_wecom_state');
|
||||
if (errorCode === 'WECOM_BIND_INPUT_REQUIRED') {
|
||||
openWecomBindPrompt({ error: rawError, error_code: errorCode });
|
||||
} else {
|
||||
openWecomLoginDialog({ error: rawError || t('login.wecomLoginFailed'), error_code: errorCode });
|
||||
}
|
||||
clearWecomCallbackQuery();
|
||||
return true;
|
||||
} finally {
|
||||
isWecomLoggingIn.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegister = async () => {
|
||||
const form = registerForm.value;
|
||||
if (!form.username || !form.password || !form.real_name || !form.employee_id || !form.phone_number) {
|
||||
msg.warning(t('register.inputError'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await requestJson('/api/user/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form),
|
||||
});
|
||||
msg.success(t('register.success'));
|
||||
showRegisterModal.value = false;
|
||||
registerForm.value = {
|
||||
username: '',
|
||||
password: '',
|
||||
email: '',
|
||||
real_name: '',
|
||||
employee_id: '',
|
||||
phone_number: '',
|
||||
};
|
||||
} catch (e) {
|
||||
console.error('Register error:', e);
|
||||
msg.error((e as Error)?.message || t('register.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
loginUsername,
|
||||
loginPassword,
|
||||
rememberMe,
|
||||
showRegisterModal,
|
||||
showForgotPasswordModal,
|
||||
registerForm,
|
||||
forgotPasswordForm,
|
||||
isWecomLoggingIn,
|
||||
wecomLoginDialog,
|
||||
wecomBindPrompt,
|
||||
clearWecomCallbackQuery,
|
||||
handleForgotPassword,
|
||||
handleLogin,
|
||||
tryCasdoorCallbackLogin,
|
||||
handleWecomLogin,
|
||||
submitWecomCompleteBind,
|
||||
tryWecomCallbackLogin,
|
||||
handleRegister,
|
||||
DEFAULT_POST_LOGIN_AGENT_ID,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* features/auth/composables/useLoginLanding.ts
|
||||
* 登录页营销区:公告列表、公开 Agent 与公告弹窗状态。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { requestJson } from '@/api/client';
|
||||
import type { WorkspaceAgent, WorkspaceAnnouncement } from '@/features/workspace/types/workspace.types';
|
||||
|
||||
export function useLoginLanding() {
|
||||
const isLoading = ref(true);
|
||||
const announcements = ref<WorkspaceAnnouncement[]>([]);
|
||||
const publicAgents = ref<WorkspaceAgent[]>([]);
|
||||
const showAnnouncementModal = ref(false);
|
||||
const selectedAnnouncement = ref<WorkspaceAnnouncement | null>(null);
|
||||
|
||||
const fetchAnnouncements = async () => {
|
||||
try {
|
||||
announcements.value = await requestJson<WorkspaceAnnouncement[]>('/api/user/announcements');
|
||||
} catch (e) {
|
||||
console.error('Failed to load announcements', e);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPublicAgents = async () => {
|
||||
try {
|
||||
publicAgents.value = await requestJson<WorkspaceAgent[]>('/api/agents/public');
|
||||
} catch {
|
||||
publicAgents.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const openAnnouncement = (ann: WorkspaceAnnouncement) => {
|
||||
selectedAnnouncement.value = ann;
|
||||
showAnnouncementModal.value = true;
|
||||
};
|
||||
|
||||
return {
|
||||
isLoading,
|
||||
announcements,
|
||||
publicAgents,
|
||||
showAnnouncementModal,
|
||||
selectedAnnouncement,
|
||||
fetchAnnouncements,
|
||||
fetchPublicAgents,
|
||||
openAnnouncement,
|
||||
};
|
||||
}
|
||||
@@ -1,2 +1,18 @@
|
||||
/**
|
||||
* features/auth/index.ts
|
||||
* 认证 feature 对外导出:store、登录 composable、用户 API。
|
||||
*/
|
||||
export { useAuthStore, bindAuthStoreSync } from './stores/auth.store';
|
||||
export { useAuth } from './composables/useAuth';
|
||||
export { useLogin } from './composables/useLogin';
|
||||
export {
|
||||
getUserProfile,
|
||||
getLeaveBalance,
|
||||
submitLeaveWorkflow,
|
||||
resetPasswordConfirm,
|
||||
getUserAgent,
|
||||
listUserAgents,
|
||||
listAgentGuides,
|
||||
type LeaveBalanceResult,
|
||||
type LeaveWorkflowSubmitResult,
|
||||
} from './api/user.api';
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/auth/views/LoginView.vue
|
||||
* 登录页路由入口:MarketingShell + useLogin provide + LoginPage/LoginModals。
|
||||
*/
|
||||
import { provide } from 'vue';
|
||||
import ThemeToggleButton from '@/components/ThemeToggleButton.vue';
|
||||
import LocaleToggleButton from '@/components/LocaleToggleButton.vue';
|
||||
import MarketingShell from '@/layouts/MarketingShell.vue';
|
||||
import LoginPage from '../components/LoginPage.vue';
|
||||
import LoginModals from '../components/LoginModals.vue';
|
||||
import { useLogin } from '../composables/useLogin';
|
||||
import { LOGIN_KEY } from '../composables/login.context';
|
||||
|
||||
const login = useLogin();
|
||||
provide(LOGIN_KEY, login);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<MarketingShell>
|
||||
<template #tools>
|
||||
<ThemeToggleButton />
|
||||
<LocaleToggleButton />
|
||||
</template>
|
||||
<LoginPage />
|
||||
<LoginModals />
|
||||
</MarketingShell>
|
||||
</template>
|
||||
@@ -0,0 +1,96 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/auth/views/ResetPasswordView.vue
|
||||
* 邮件链接重置密码页(/reset-password?token=...)。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { Lock, AlertCircle, CheckCircle } from 'lucide-vue-next';
|
||||
import MinimalShell from '@/layouts/MinimalShell.vue';
|
||||
import { resetPasswordConfirm } from '@/features/auth/api/user.api';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const token = ref(route.query.token as string || '');
|
||||
const password = ref('');
|
||||
const confirmPassword = ref('');
|
||||
const isLoading = ref(false);
|
||||
const status = ref<'idle' | 'success' | 'error'>('idle');
|
||||
const message = ref('');
|
||||
|
||||
const handleReset = async () => {
|
||||
if (!password.value || !confirmPassword.value) {
|
||||
message.value = 'Please fill in all fields';
|
||||
status.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.value !== confirmPassword.value) {
|
||||
message.value = 'Passwords do not match';
|
||||
status.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
status.value = 'idle';
|
||||
message.value = '';
|
||||
|
||||
try {
|
||||
await resetPasswordConfirm(token.value, password.value);
|
||||
status.value = 'success';
|
||||
message.value = 'Password reset successfully! Redirecting to login...';
|
||||
setTimeout(() => {
|
||||
router.push('/');
|
||||
}, 3000);
|
||||
} catch (e) {
|
||||
status.value = 'error';
|
||||
message.value = (e as Error).message || 'Failed to reset password';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<MinimalShell>
|
||||
<div class="text-center mb-8">
|
||||
<div class="w-12 h-12 bg-brand-100 rounded-xl mx-auto flex items-center justify-center text-brand-600 mb-4">
|
||||
<Lock class="w-6 h-6" />
|
||||
</div>
|
||||
<h2 class="page-title">Reset Password</h2>
|
||||
<p class="section-desc mt-2">Enter your new password below</p>
|
||||
</div>
|
||||
|
||||
<div v-if="status === 'success'" class="alert-ds alert-success mb-6">
|
||||
<CheckCircle class="w-5 h-5 shrink-0" />
|
||||
<div>{{ message }}</div>
|
||||
</div>
|
||||
|
||||
<div v-if="status === 'error'" class="alert-ds alert-error mb-6">
|
||||
<AlertCircle class="w-5 h-5 shrink-0" />
|
||||
<div>{{ message }}</div>
|
||||
</div>
|
||||
|
||||
<form v-if="status !== 'success'" @submit.prevent="handleReset" class="space-y-5">
|
||||
<div>
|
||||
<label class="label-field mb-1.5 block">New Password</label>
|
||||
<input v-model="password" type="password" class="input-field" placeholder="Enter new password" required />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label-field mb-1.5 block">Confirm Password</label>
|
||||
<input v-model="confirmPassword" type="password" class="input-field" placeholder="Confirm new password" required />
|
||||
</div>
|
||||
|
||||
<button type="submit" :disabled="isLoading" class="btn-primary w-full py-3 flex justify-center items-center gap-2">
|
||||
<div v-if="isLoading" class="animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-white"></div>
|
||||
<span>{{ isLoading ? 'Resetting...' : 'Reset Password' }}</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 text-center">
|
||||
<router-link to="/" class="text-sm font-medium text-muted hover:text-secondary">Back to Login</router-link>
|
||||
</div>
|
||||
</MinimalShell>
|
||||
</template>
|
||||
Reference in new issue
Block a user