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 { useChatStore } from '@/stores/modules/chat';
import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
export default {
setup(props, { emit, expose }) {
const chatStore = useChatStore();
const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const keyWord = ref('');
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise);
const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const handleSearch = () => {
chatStore.setSearchValue(keyWord.value);

View File

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

View File

@ -1,16 +1,14 @@
<template>
<div class="navbar-wrap px-24px">
<div class="w-full h-full relative flex justify-between">
<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 class="flex-1"> -->
<MiddleSide v-if="!isHomeRoute"/>
<MiddleSide v-if="!isHomeRoute" />
<!-- </div> -->
<RightSide :isAgentRoute="isAgentRoute" v-if="userStore.isLogin"/>
<RightSide :isAgentRoute="isAgentRoute" v-if="userStore.isLogin" />
</div>
</div>
</template>
@ -19,13 +17,15 @@ import MiddleSide from './components/middle-side';
import RightSide from './components/right-side';
import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
import { handleUserHome } from '@/utils/user.ts';
import router from '@/router';
const route = useRoute();
const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise);
const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const isAgentRoute = computed(() => {
return route.meta?.isAgentRoute;
});
@ -39,8 +39,8 @@ const onLogoClick = () => {
handleUserHome();
} else {
router.push({
name: 'Trial'
})
name: 'Trial',
});
}
};
</script>

View File

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

View File

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

View File

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

View File

@ -15,6 +15,18 @@ export function goUserLogin(query?: any) {
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 () => {
const enterpriseStore = useEnterpriseStore();
// const sidebarStore = useSidebarStore();
@ -29,12 +41,14 @@ export async function initApp() {
const userStore = useUserStore();
const chatStore = useChatStore();
const sidebarStore = useSidebarStore();
const enterpriseStore = useEnterpriseStore();
await userStore.getUserInfo(); // 初始化用户信息
if (!userStore.isOpenEnterprise) return;
if (!enterpriseStore.isOpenEnterprise) return;
await getUserEnterpriseInfo(); // 初始化企业信息、navbar菜单、允许访问的路由
await chatStore.getAgentInfo(); // 初始化智能体信息
// await chatStore.getAgentInfo(); // 初始化智能体信息
sidebarStore.startUnreadInfoPolling(); // 初始化未读信息
}
@ -46,13 +60,10 @@ export async function handleUserLogin() {
handleUserHome();
}
// 首页
export function handleUserHome(params?: any) {
router.push({ name: 'Home', params });
}
// 登出处理
export function handleUserLogout() {
goUserLogin();
const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const sidebarStore = useSidebarStore();
@ -66,6 +77,4 @@ export function handleUserLogout() {
sidebarStore.stopUnreadInfoPolling(); // 清除未读消息
sidebarStore.clearActiveMenuKey(); // 清除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 { useEnterpriseStore } from '@/stores/modules/enterprise';
import { handleUserLogin } from '@/utils/user';
import router from '@/router';
import { useRoute } from 'vue-router';
import icon1 from '@/assets/img/login/icon-close.png';
@ -265,9 +264,6 @@ const onTabChange = () => {
const getProfileInfo = async () => {
const { code, data } = await fetchProfileInfo();
if (code === 200) {
userStore.setUserInfo(data);
// 已开通
if (userStore.isOpenEnterprise) {
const enterprises = data['enterprises'];
mobileNumber.value = data['mobile'];
accounts.value = enterprises;
@ -281,9 +277,6 @@ const getProfileInfo = async () => {
selectAccountModalRef.value.open();
}
}
} else {
router.push({ name: 'Trial' });
}
}
};

View File

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

View File

@ -65,7 +65,7 @@
</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">
<img :src="icon2" width="96" height="96" class="mb-8px" />
<p class="cts !text-18px !lh-26px mb-8px">您的试用申请已提交</p>
@ -87,7 +87,7 @@
</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">
<img :src="icon1" width="96" height="96" class="mb-8px" />
<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 { handleUserHome } from '@/utils/user';
import { useUserStore } from '@/stores';
import { useEnterpriseStore } from '@/stores/modules/enterprise';
import icon1 from './img/icon-info.png';
import icon2 from './img/icon-check.png';
@ -130,6 +131,8 @@ type Status = 0 | 1 | 2 | 3 | 4;
const router = useRouter();
const userStore = useUserStore();
const enterpriseStore = useEnterpriseStore();
const formRef = ref();
const submitting = ref(false);
// const status = ref<Status>(1);
@ -178,12 +181,13 @@ const formRules = {
};
const primary_enterprise = computed(() => userStore.userInfo?.primary_enterprise);
const hasOpenEnterprise = computed(() => userStore.isOpenEnterprise);
const hasOpenEnterprise = computed(() => enterpriseStore.isOpenEnterprise);
const trialingStepsItems = computed(() => {
return [
{
title: '提交申请',
description: exactFormatTime(primary_enterprise.value?.created_at),
description: exactFormatTime(enterpriseStore.enterpriseInfo?.created_at),
},
{
title: '人工审核',
@ -199,7 +203,7 @@ const trialEndStepsItems = computed(() => {
return [
{
title: '提交申请',
description: exactFormatTime(primary_enterprise.value?.created_at),
description: exactFormatTime(enterpriseStore.enterpriseInfo?.created_at),
},
{
title: '人工审核',