perf: 登录逻辑调整

This commit is contained in:
rd
2025-09-11 12:04:54 +08:00
parent 44e1ea9a06
commit 7e6e086098
11 changed files with 103 additions and 104 deletions

View File

@ -3,15 +3,17 @@ import { Input } from 'ant-design-vue';
// import { handleUserHome } from '@/utils/user.ts'; // import { handleUserHome } from '@/utils/user.ts';
import { useChatStore } from '@/stores/modules/chat'; import { useChatStore } from '@/stores/modules/chat';
import { useUserStore } from '@/stores'; import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
export default { export default {
setup(props, { emit, expose }) { setup(props, { emit, expose }) {
const chatStore = useChatStore(); const chatStore = useChatStore();
const userStore = useUserStore(); const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const keyWord = ref(''); const keyWord = ref('');
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise); const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const handleSearch = () => { const handleSearch = () => {
chatStore.setSearchValue(keyWord.value); chatStore.setSearchValue(keyWord.value);

View File

@ -98,7 +98,7 @@ const route = useRoute();
const router = useRouter(); const router = useRouter();
const hasUnreadInfo = computed(() => sideBarStore.unreadInfo.length); const hasUnreadInfo = computed(() => sideBarStore.unreadInfo.length);
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise); const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const exitAccountModalRef = ref(null); const exitAccountModalRef = ref(null);
const downloadCenterModalRef = ref(null); const downloadCenterModalRef = ref(null);

View File

@ -1,16 +1,14 @@
<template> <template>
<div class="navbar-wrap px-24px"> <div class="navbar-wrap px-24px">
<div class="w-full h-full relative flex justify-between"> <div class="w-full h-full relative flex justify-between">
<div class="left-wrap flex items-center cursor-pointer" @click="onLogoClick"> <div class="left-wrap flex items-center cursor-pointer" @click="onLogoClick">
<img src="@/assets/img/icon-logo.png" alt="" width="96" height="24"/> <img src="@/assets/img/icon-logo.png" alt="" width="96" height="24" />
</div> </div>
<!-- <div class="flex-1"> --> <!-- <div class="flex-1"> -->
<MiddleSide v-if="!isHomeRoute"/> <MiddleSide v-if="!isHomeRoute" />
<!-- </div> --> <!-- </div> -->
<RightSide :isAgentRoute="isAgentRoute" v-if="userStore.isLogin"/> <RightSide :isAgentRoute="isAgentRoute" v-if="userStore.isLogin" />
</div> </div>
</div> </div>
</template> </template>
@ -19,13 +17,15 @@ import MiddleSide from './components/middle-side';
import RightSide from './components/right-side'; import RightSide from './components/right-side';
import { useUserStore } from '@/stores'; import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
import { handleUserHome } from '@/utils/user.ts'; import { handleUserHome } from '@/utils/user.ts';
import router from '@/router'; import router from '@/router';
const route = useRoute(); const route = useRoute();
const userStore = useUserStore(); const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise); const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const isAgentRoute = computed(() => { const isAgentRoute = computed(() => {
return route.meta?.isAgentRoute; return route.meta?.isAgentRoute;
}); });
@ -39,8 +39,8 @@ const onLogoClick = () => {
handleUserHome(); handleUserHome();
} else { } else {
router.push({ router.push({
name: 'Trial' name: 'Trial',
}) });
} }
}; };
</script> </script>

View File

@ -8,6 +8,7 @@ import { useSidebarStore } from '@/stores/modules/side-bar';
import type { typeMenuItem } from './menu-list'; import type { typeMenuItem } from './menu-list';
import { MENU_LIST } from './menu-list'; import { MENU_LIST } from './menu-list';
import { handleUserHome } from '@/utils/user'; import { handleUserHome } from '@/utils/user';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
import icon1 from '@/assets/img/agent/icon1.png'; import icon1 from '@/assets/img/agent/icon1.png';
@ -21,6 +22,7 @@ export default defineComponent({
const sidebarStore = useSidebarStore(); const sidebarStore = useSidebarStore();
const appStore = useAppStore(); const appStore = useAppStore();
const userStore = useUserStore(); const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
// const currentMenuList = ref<typeMenuItem[]>([]); // const currentMenuList = ref<typeMenuItem[]>([]);
const currentMenuModInfo = ref<typeMenuItem>({}); const currentMenuModInfo = ref<typeMenuItem>({});
@ -30,7 +32,7 @@ export default defineComponent({
const isHomeRoute = computed(() => currentRouteName.value === 'Home'); const isHomeRoute = computed(() => currentRouteName.value === 'Home');
const showAiSearch = computed(() => !route.meta?.hideAiSearch); const showAiSearch = computed(() => !route.meta?.hideAiSearch);
const currentMenuList = computed(() => sidebarStore.currentMenuList); const currentMenuList = computed(() => sidebarStore.currentMenuList);
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise); const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const collapsed = computed(() => { const collapsed = computed(() => {
return sidebarStore.menuCollapse; return sidebarStore.menuCollapse;

View File

@ -1,13 +1,13 @@
import { useUserStore } from '@/stores/modules/user'; // import { useUserStore } from '@/stores/modules/user';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
export function checkRoutePermission(routeName: string) { export function checkRoutePermission(routeName: string) {
const enterpriseStore = useEnterpriseStore();
const userStore = useUserStore();
if (!routeName) return false; if (!routeName) return false;
if (!userStore.isOpenEnterprise) { if (!enterpriseStore.isOpenEnterprise) {
return false return false;
} }
return true; return true;

View File

@ -1,7 +1,5 @@
import { fetchEnterpriseInfo } from '@/api/all/login'; import { fetchEnterpriseInfo } from '@/api/all/login';
import { useSidebarStore } from '@/stores/modules/side-bar'; import { glsWithCatch, slsWithCatch } from '@/utils/stroage';
import { useUserStore } from '@/stores/modules/user';
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
interface EnterpriseInfo { interface EnterpriseInfo {
id: number | string; id: number | string;
@ -11,6 +9,8 @@ interface EnterpriseInfo {
sub_account_quota: number; sub_account_quota: number;
used_sub_account_count: number; used_sub_account_count: number;
permissions: string[]; permissions: string[];
[key: string]: any;
} }
interface EnterpriseState { interface EnterpriseState {
@ -21,6 +21,12 @@ export const useEnterpriseStore = defineStore('enterprise', {
state: (): EnterpriseState => ({ state: (): EnterpriseState => ({
enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null, enterpriseInfo: (glsWithCatch('enterpriseInfo') && JSON.parse(glsWithCatch('enterpriseInfo') as string)) || null,
}), }),
getters: {
// 企业已开通/试用中
isOpenEnterprise(): boolean {
return [1, 2].includes(this.enterpriseInfo?.subscribe_status);
},
},
actions: { actions: {
setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) { setEnterpriseInfo(enterpriseInfo: EnterpriseInfo) {
this.enterpriseInfo = enterpriseInfo; this.enterpriseInfo = enterpriseInfo;

View File

@ -39,10 +39,6 @@ export const useUserStore = defineStore('user', {
isLogin(): boolean { isLogin(): boolean {
return !!this.token; return !!this.token;
}, },
// 是否开通企业
isOpenEnterprise(): boolean {
return [1, 2].includes(this.userInfo?.primary_enterprise?.subscribe_status);
},
}, },
actions: { actions: {
// 设置 Token // 设置 Token

View File

@ -15,6 +15,18 @@ export function goUserLogin(query?: any) {
router.push({ name: 'UserLogin', query }); router.push({ name: 'UserLogin', query });
} }
// 首页
export function handleUserHome(params?: any) {
const enterpriseStore = useEnterpriseStore();
console.log(enterpriseStore.enterpriseInfo);
// 已开通
if (enterpriseStore.isOpenEnterprise) {
router.push({ name: 'Home', params });
} else {
router.push({ name: 'Trial' });
}
}
export const getUserEnterpriseInfo = async () => { export const getUserEnterpriseInfo = async () => {
const enterpriseStore = useEnterpriseStore(); const enterpriseStore = useEnterpriseStore();
// const sidebarStore = useSidebarStore(); // const sidebarStore = useSidebarStore();
@ -29,12 +41,14 @@ export async function initApp() {
const userStore = useUserStore(); const userStore = useUserStore();
const chatStore = useChatStore(); const chatStore = useChatStore();
const sidebarStore = useSidebarStore(); const sidebarStore = useSidebarStore();
const enterpriseStore = useEnterpriseStore();
await userStore.getUserInfo(); // 初始化用户信息 await userStore.getUserInfo(); // 初始化用户信息
if (!userStore.isOpenEnterprise) return; if (!enterpriseStore.isOpenEnterprise) return;
await getUserEnterpriseInfo(); // 初始化企业信息、navbar菜单、允许访问的路由 await getUserEnterpriseInfo(); // 初始化企业信息、navbar菜单、允许访问的路由
await chatStore.getAgentInfo(); // 初始化智能体信息 // await chatStore.getAgentInfo(); // 初始化智能体信息
sidebarStore.startUnreadInfoPolling(); // 初始化未读信息 sidebarStore.startUnreadInfoPolling(); // 初始化未读信息
} }
@ -46,13 +60,10 @@ export async function handleUserLogin() {
handleUserHome(); handleUserHome();
} }
// 首页
export function handleUserHome(params?: any) {
router.push({ name: 'Home', params });
}
// 登出处理 // 登出处理
export function handleUserLogout() { export function handleUserLogout() {
goUserLogin();
const userStore = useUserStore(); const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore(); const enterpriseStore = useEnterpriseStore();
const sidebarStore = useSidebarStore(); const sidebarStore = useSidebarStore();
@ -66,6 +77,4 @@ export function handleUserLogout() {
sidebarStore.stopUnreadInfoPolling(); // 清除未读消息 sidebarStore.stopUnreadInfoPolling(); // 清除未读消息
sidebarStore.clearActiveMenuKey(); // 清除active菜单id sidebarStore.clearActiveMenuKey(); // 清除active菜单id
sidebarStore.clearMenuCollapse(); // 清除active菜单id sidebarStore.clearMenuCollapse(); // 清除active菜单id
goUserLogin();
} }

View File

@ -108,7 +108,6 @@ import { computed, onUnmounted, reactive, ref } from 'vue';
import { useUserStore } from '@/stores'; import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise'; import { useEnterpriseStore } from '@/stores/modules/enterprise';
import { handleUserLogin } from '@/utils/user'; import { handleUserLogin } from '@/utils/user';
import router from '@/router';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import icon1 from '@/assets/img/login/icon-close.png'; import icon1 from '@/assets/img/login/icon-close.png';
@ -265,24 +264,18 @@ const onTabChange = () => {
const getProfileInfo = async () => { const getProfileInfo = async () => {
const { code, data } = await fetchProfileInfo(); const { code, data } = await fetchProfileInfo();
if (code === 200) { if (code === 200) {
userStore.setUserInfo(data); const enterprises = data['enterprises'];
// 已开通 mobileNumber.value = data['mobile'];
if (userStore.isOpenEnterprise) { accounts.value = enterprises;
const enterprises = data['enterprises'];
mobileNumber.value = data['mobile'];
accounts.value = enterprises;
if (enterprises.length > 0) { if (enterprises.length > 0) {
enterpriseStore.setEnterpriseInfo(data.enterprises[0]); enterpriseStore.setEnterpriseInfo(data.enterprises[0]);
if (enterprises.length === 1) { if (enterprises.length === 1) {
handleUserLogin(); handleUserLogin();
} else { } else {
// 多个企业时候需要弹窗让用户选择企业 // 多个企业时候需要弹窗让用户选择企业
selectAccountModalRef.value.open(); selectAccountModalRef.value.open();
}
} }
} else {
router.push({ name: 'Trial' });
} }
} }
}; };

View File

@ -85,37 +85,30 @@
</template> </template>
<script setup lang="js"> <script setup lang="js">
import { import { Button, Checkbox, Form, FormItem, Input, message, Tabs, Typography } from 'ant-design-vue';
Checkbox,
Modal,
Button,
Form,
FormItem,
Input,
Space,
message,
Typography,
Card,
List,
Tabs,
} from 'ant-design-vue';
const { Link } = Typography;
const { TabPane } = Tabs;
import PuzzleVerification from '../PuzzleVerification.vue'; import PuzzleVerification from '../PuzzleVerification.vue';
import SelectAccountModal from '../select-account-modal/index.vue'; import SelectAccountModal from '../select-account-modal/index.vue';
import { postClearRateLimiter } from '@/api/all/common'; import { postClearRateLimiter } from '@/api/all/common';
import { postRegisterCaptcha,postForgetPasswordCaptcha, fetchProfileInfo, postRegister, postForgetPassword } from '@/api/all/login'; import {
fetchProfileInfo,
postForgetPassword,
postForgetPasswordCaptcha,
postRegister,
postRegisterCaptcha,
} from '@/api/all/login';
import { joinEnterpriseByInviteCode } from '@/api/all'; import { joinEnterpriseByInviteCode } from '@/api/all';
import { ref, reactive, onUnmounted, computed } from 'vue'; import { computed, onUnmounted, ref } from 'vue';
import { useUserStore } from '@/stores'; import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise'; import { useEnterpriseStore } from '@/stores/modules/enterprise';
import { handleUserLogin, goUserLogin } from '@/utils/user'; import { handleUserLogin } from '@/utils/user';
import router from '@/router';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import icon1 from '@/assets/img/login/icon-close.png'; import icon1 from '@/assets/img/login/icon-close.png';
import icon2 from '@/assets/img/login/icon-open.png'; import icon2 from '@/assets/img/login/icon-open.png';
const { Link } = Typography;
const { TabPane } = Tabs;
const setPageType = inject('setPageType'); const setPageType = inject('setPageType');
const pageType = inject('pageType'); const pageType = inject('pageType');
@ -173,9 +166,9 @@ const formRules = {
// if (value.length < 6) { // if (value.length < 6) {
// return Promise.reject('密码长度不能小于6位'); // return Promise.reject('密码长度不能小于6位');
// } // }
if(formData.value.confirm_password) { if (formData.value.confirm_password) {
formRef.value.validateFields('confirm_password'); formRef.value.validateFields('confirm_password');
} }
return Promise.resolve(); return Promise.resolve();
}, },
trigger: ['blur'], trigger: ['blur'],
@ -268,7 +261,7 @@ const getCaptcha = async () => {
const fn = isResetPassword.value ? postForgetPasswordCaptcha : postRegisterCaptcha; const fn = isResetPassword.value ? postForgetPasswordCaptcha : postRegisterCaptcha;
const { code, message: msg } = await fn({ mobile: formData.value.mobile }); const { code, message: msg } = await fn({ mobile: formData.value.mobile });
if (code === 200) { if (code === 200) {
startCountdown() startCountdown();
message.success(msg); message.success(msg);
} }
} catch (error) { } catch (error) {
@ -293,26 +286,19 @@ const handleVerificationSubmit = async () => {
const getProfileInfo = async () => { const getProfileInfo = async () => {
const { code, data } = await fetchProfileInfo(); const { code, data } = await fetchProfileInfo();
if (code === 200) { if (code === 200) {
userStore.setUserInfo(data); const enterprises = data['enterprises'];
mobileNumber.value = data['mobile'];
accounts.value = enterprises;
// 已开通 if (enterprises.length > 0) {
if (userStore.isOpenEnterprise) { enterpriseStore.setEnterpriseInfo(data.enterprises[0]);
const enterprises = data['enterprises']; if (enterprises.length === 1) {
mobileNumber.value = data['mobile']; setTimeout(() => {
accounts.value = enterprises; handleUserLogin();
}, 1500);
if (enterprises.length > 0) { } else {
enterpriseStore.setEnterpriseInfo(data.enterprises[0]); selectAccountModalRef.value.open();
if (enterprises.length === 1) {
setTimeout(() => {
handleUserLogin();
}, 1500);
} else {
selectAccountModalRef.value.open();
}
} }
} else {
router.push({name: 'Trial'})
} }
} }
}; };
@ -342,13 +328,14 @@ const handleSubmit = async () => {
if (code === 200) { if (code === 200) {
message.success(isResetPassword.value ? '重置成功' : '注册成功'); message.success(isResetPassword.value ? '重置成功' : '注册成功');
// 注册成功后跳转登录页 // 注册成功后跳转登录页
if(!isResetPassword.value) { if (!isResetPassword.value) {
setTimeout(() => { setTimeout(() => {
setPageType('loginForm'); setPageType('loginForm');
}, 1500); }, 1500);
return; return;
}; }
;
userStore.setToken(data.access_token); userStore.setToken(data.access_token);
@ -378,7 +365,7 @@ const startCountdown = () => {
timer.value = setInterval(() => { timer.value = setInterval(() => {
countdown.value--; countdown.value--;
if (countdown.value <= 0) { if (countdown.value <= 0) {
clearInterval(timer.value ); clearInterval(timer.value);
timer.value = null; timer.value = null;
} }
}, 1000); }, 1000);

View File

@ -65,7 +65,7 @@
</section> </section>
<!-- 建立商务联系中 --> <!-- 建立商务联系中 -->
<section class="w-full" v-if="primary_enterprise?.audit_status === 1"> <section class="w-full" v-if="enterpriseStore.enterpriseInfo?.audit_status === 1">
<div class="rounded-16px bg-#fff px-36px pt-80px pb-60px flex flex-col items-center"> <div class="rounded-16px bg-#fff px-36px pt-80px pb-60px flex flex-col items-center">
<img :src="icon2" width="96" height="96" class="mb-8px" /> <img :src="icon2" width="96" height="96" class="mb-8px" />
<p class="cts !text-18px !lh-26px mb-8px">您的试用申请已提交</p> <p class="cts !text-18px !lh-26px mb-8px">您的试用申请已提交</p>
@ -87,7 +87,7 @@
</section> </section>
<!-- 试用到期 --> <!-- 试用到期 -->
<section class="w-full" v-if="primary_enterprise?.subscribe_status === 4"> <section class="w-full" v-if="enterpriseStore.enterpriseInfo?.subscribe_status === 4">
<div class="rounded-16px bg-#fff px-36px pt-80px pb-60px flex flex-col items-center"> <div class="rounded-16px bg-#fff px-36px pt-80px pb-60px flex flex-col items-center">
<img :src="icon1" width="96" height="96" class="mb-8px" /> <img :src="icon1" width="96" height="96" class="mb-8px" />
<p class="cts !text-18px !lh-26px mb-8px">试用已到期</p> <p class="cts !text-18px !lh-26px mb-8px">试用已到期</p>
@ -121,6 +121,7 @@ import { postCreateEnterprises } from '@/api/all/login';
import { exactFormatTime } from '@/utils/tools'; import { exactFormatTime } from '@/utils/tools';
import { handleUserHome } from '@/utils/user'; import { handleUserHome } from '@/utils/user';
import { useUserStore } from '@/stores'; import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
import icon1 from './img/icon-info.png'; import icon1 from './img/icon-info.png';
import icon2 from './img/icon-check.png'; import icon2 from './img/icon-check.png';
@ -130,6 +131,8 @@ type Status = 0 | 1 | 2 | 3 | 4;
const router = useRouter(); const router = useRouter();
const userStore = useUserStore(); const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const formRef = ref(); const formRef = ref();
const submitting = ref(false); const submitting = ref(false);
// const status = ref<Status>(1); // const status = ref<Status>(1);
@ -178,12 +181,13 @@ const formRules = {
}; };
const primary_enterprise = computed(() => userStore.userInfo?.primary_enterprise); const primary_enterprise = computed(() => userStore.userInfo?.primary_enterprise);
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise); const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const trialingStepsItems = computed(() => { const trialingStepsItems = computed(() => {
return [ return [
{ {
title: '提交申请', title: '提交申请',
description: exactFormatTime(primary_enterprise.value?.created_at), description: exactFormatTime(enterpriseStore.enterpriseInfo?.created_at),
}, },
{ {
title: '人工审核', title: '人工审核',
@ -199,7 +203,7 @@ const trialEndStepsItems = computed(() => {
return [ return [
{ {
title: '提交申请', title: '提交申请',
description: exactFormatTime(primary_enterprise.value?.created_at), description: exactFormatTime(enterpriseStore.enterpriseInfo?.created_at),
}, },
{ {
title: '人工审核', title: '人工审核',