feat: 创建企业逻辑对接

This commit is contained in:
rd
2025-09-10 17:57:42 +08:00
parent 25f74691c6
commit 32bc0c4b95
8 changed files with 90 additions and 50 deletions

View File

@ -31,10 +31,9 @@ const redTheme = {
const init = async () => { const init = async () => {
const { isLogin } = userStore; const { isLogin } = userStore;
// 已开通
if (isLogin) { if (isLogin) {
await initApp(); await initApp();
sidebarStore.startUnreadInfoPolling();
} else { } else {
sidebarStore.stopUnreadInfoPolling(); sidebarStore.stopUnreadInfoPolling();
} }
@ -42,6 +41,7 @@ const init = async () => {
onMounted(() => { onMounted(() => {
init(); init();
// 监听全局未处理错误 // 监听全局未处理错误
window.addEventListener('unhandledrejection', (event) => { window.addEventListener('unhandledrejection', (event) => {
event.preventDefault(); event.preventDefault();

View File

@ -71,4 +71,19 @@ export const postForgetPasswordCaptcha = (params = {}) => {
// 忘记密码 // 忘记密码
export const postForgetPassword = (params = {}) => { export const postForgetPassword = (params = {}) => {
return Http.post('/v1/users/forget-password', params); return Http.post('/v1/users/forget-password', params);
};
// 创建企业
export const postCreateEnterprises = (params = {}) => {
return Http.post('/v1/enterprises', params);
};
// 获取我的企业列表
export const getMyEnterprises = () => {
return Http.get('/v1/me/enterprises');
};
// 获取我的主企业信息
export const getMyPrimaryEnterprise = () => {
return Http.get('/v1/me/primary-enterprise');
}; };

View File

@ -1,7 +1,7 @@
import router from '@/router'; import router from '@/router';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { fetchProfileInfo } from '@/api/all/login'; import { fetchProfileInfo } from '@/api/all/login';
import { useSidebarStore } from '@/stores/modules/side-bar'; // import { useSidebarStore } from '@/stores/modules/side-bar';
import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage'; import { glsWithCatch, slsWithCatch, rlsWithCatch } from '@/utils/stroage';
interface UserInfo { interface UserInfo {
@ -10,6 +10,8 @@ interface UserInfo {
head_image: String; head_image: String;
current_enterprise_id: number; current_enterprise_id: number;
mobile: string; mobile: string;
primary_enterprise: any; // 主企业信息
[key: string]: any;
// 添加其他用户属性... // 添加其他用户属性...
} }
@ -37,6 +39,10 @@ export const useUserStore = defineStore('user', {
isLogin(): boolean { isLogin(): boolean {
return !!this.token; return !!this.token;
}, },
// 是否开通企业
isOpenEnterprise(): boolean {
return this.userInfo?.primary_enterprise?.subscribe_status === 1;
},
}, },
actions: { actions: {
// 设置 Token // 设置 Token

View File

@ -27,20 +27,21 @@ export const getUserEnterpriseInfo = async () => {
export async function initApp() { export async function initApp() {
const userStore = useUserStore(); const userStore = useUserStore();
const chatStore = useChatStore(); const chatStore = useChatStore();
const sidebarStore = useSidebarStore();
await chatStore.getAgentInfo(); // 初始化智能体信息
await userStore.getUserInfo(); // 初始化用户信息 await userStore.getUserInfo(); // 初始化用户信息
if (!userStore.isOpenEnterprise) return;
await getUserEnterpriseInfo(); // 初始化企业信息、navbar菜单、允许访问的路由 await getUserEnterpriseInfo(); // 初始化企业信息、navbar菜单、允许访问的路由
await chatStore.getAgentInfo(); // 初始化智能体信息
sidebarStore.startUnreadInfoPolling(); // 初始化未读信息
} }
// 登录处理 // 登录处理
export async function handleUserLogin() { export async function handleUserLogin() {
const sidebarStore = useSidebarStore();
await initApp(); await initApp();
sidebarStore.startUnreadInfoPolling(); // 初始化未读信息
handleUserHome(); handleUserHome();
} }

View File

@ -277,18 +277,23 @@ const onTabChange = () => {
const getProfileInfo = async () => { const getProfileInfo = async () => {
const { code, data } = await fetchProfileInfo(); const { code, data } = await fetchProfileInfo();
if (code === 200) { if (code === 200) {
let enterprises = data['enterprises']; // 已开通
mobileNumber.value = data['mobile']; if (data.primary_enterprise?.subscribe_status === 1) {
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'})
} }
} }
}; };
@ -312,7 +317,6 @@ const handleSubmit = async () => {
const _fn = isCaptchaLogin.value ? fetchAuthorizationsCaptcha : postLoginPassword; const _fn = isCaptchaLogin.value ? fetchAuthorizationsCaptcha : postLoginPassword;
const { code, data, message: errorInfo } = await _fn(loginForm); const { code, data, message: errorInfo } = await _fn(loginForm);
console.log(code, errorInfo);
if (code === 10001) { if (code === 10001) {
errMsg.value = errorInfo; errMsg.value = errorInfo;
return; return;

View File

@ -293,19 +293,24 @@ 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) {
let enterprises = data['enterprises']; // 已开通
mobileNumber.value = data['mobile']; if (data.primary_enterprise?.subscribe_status === 1) {
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) {
setTimeout(() => { setTimeout(() => {
handleUserLogin(); handleUserLogin();
}, 1500); }, 1500);
} else { } else {
selectAccountModalRef.value.open(); selectAccountModalRef.value.open();
}
} }
} else {
router.push({name: 'Trial'})
} }
} }
}; };

View File

@ -3,7 +3,7 @@
<Layout.Header class="header-wrap"> <Layout.Header class="header-wrap">
<div class="h-full px-24px"> <div class="h-full px-24px">
<div class="w-full h-full relative flex justify-between"> <div class="w-full h-full relative flex justify-between">
<div class="flex items-center cursor-pointer" @click="handleUserHome"> <div class="flex items-center">
<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>
<RightSide /> <RightSide />
@ -13,7 +13,7 @@
<Layout class="flex trial-content items-center"> <Layout class="flex trial-content items-center">
<div class="w-800px"> <div class="w-800px">
<!-- 未建联 --> <!-- 未建联 -->
<section class="w-full" v-if="status === 1"> <section class="w-full" v-if="!primary_enterprise">
<div class="rounded-16px mb-16px bg-#fff px-24px py-16px flex justify-between"> <div class="rounded-16px mb-16px bg-#fff px-24px py-16px flex justify-between">
<div class="flex items-center"> <div class="flex items-center">
<span class="cts !text-18px !lh-26px !color-#000 mr-8px">申请试用</span> <span class="cts !text-18px !lh-26px !color-#000 mr-8px">申请试用</span>
@ -25,18 +25,18 @@
<div class="rounded-16px mb-16px bg-#fff p-24px"> <div class="rounded-16px mb-16px bg-#fff p-24px">
<p class="cts !text-16px !lh-24px !color-#000 mb-32px">基本信息</p> <p class="cts !text-16px !lh-24px !color-#000 mb-32px">基本信息</p>
<Form ref="formRef" :model="formData" :rules="formRules" layout="vertical" class="w-full form-wrap"> <Form ref="formRef" :model="formData" :rules="formRules" layout="vertical" class="w-full form-wrap">
<FormItem name="name" label="联系人"> <FormItem name="contact" label="联系人">
<Input <Input
v-model:value="formData.name" v-model:value="formData.contact"
placeholder="请输入您的姓名" placeholder="请输入您的姓名"
size="large" size="large"
allowClear allowClear
class="w-500px" class="w-500px"
/> />
</FormItem> </FormItem>
<FormItem name="company_name" label="公司名称"> <FormItem name="name" label="公司名称">
<Input <Input
v-model:value="formData.company_name" v-model:value="formData.name"
placeholder="请输入您的公司名称,个人用户写无" placeholder="请输入您的公司名称,个人用户写无"
size="large" size="large"
allowClear allowClear
@ -65,7 +65,7 @@
</section> </section>
<!-- 建立商务联系中 --> <!-- 建立商务联系中 -->
<section class="w-full" v-if="status === 2"> <section class="w-full" v-if="primary_enterprise.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="status === 3"> <section class="w-full" v-if="primary_enterprise.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>
@ -115,24 +115,28 @@
<script setup lang="ts"> <script setup lang="ts">
import { Layout, Form, Button, FormItem, Input, Steps } from 'ant-design-vue'; import { Layout, Form, Button, FormItem, Input, Steps } from 'ant-design-vue';
import RightSide from '@/layouts/components/navbar/components/right-side/index.vue'; import RightSide from '@/layouts/components/navbar/components/right-side/index.vue';
import { postCreateEnterprises } from '@/api/all/login';
import { exactFormatTime } from '@/utils/tools';
import { handleUserHome } from '@/utils/user'; import { handleUserHome } from '@/utils/user';
import { useUserStore } from '@/stores';
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';
type Status = 1 | 2 | 3; // 0-未开通1-已开通2-试用中3-已到期4-试用结束
type Status = 0 | 1 | 2 | 3 | 4;
const userStore = useUserStore();
const formRef = ref(); const formRef = ref();
const submitting = ref(false); const submitting = ref(false);
const status = ref<Status>(1); // const status = ref<Status>(1);
const formData = ref({ const formData = ref({
mobile: '', mobile: '',
contact: '',
name: '', name: '',
company_name: '',
}); });
const formRules = { const formRules = {
name: { contact: {
required: true, required: true,
trigger: ['blur'], trigger: ['blur'],
@ -144,7 +148,7 @@ const formRules = {
} }
}, },
}, },
company_name: { name: {
required: true, required: true,
trigger: ['blur'], trigger: ['blur'],
@ -170,11 +174,13 @@ const formRules = {
}, },
}; };
const primary_enterprise = computed(() => userStore.userInfo?.primary_enterprise);
const trialingStepsItems = computed(() => { const trialingStepsItems = computed(() => {
return [ return [
{ {
title: '提交申请', title: '提交申请',
description: '2025/09/01 12:00:00', description: exactFormatTime(primary_enterprise.value?.created_at),
}, },
{ {
title: '人工审核', title: '人工审核',
@ -190,7 +196,7 @@ const trialEndStepsItems = computed(() => {
return [ return [
{ {
title: '提交申请', title: '提交申请',
description: '2025/09/01 12:00:00', description: exactFormatTime(primary_enterprise.value?.created_at),
}, },
{ {
title: '人工审核', title: '人工审核',
@ -207,8 +213,11 @@ const handleSubmit = async () => {
submitting.value = true; submitting.value = true;
formRef.value formRef.value
.validate() .validate()
.then(() => { .then(async () => {
console.log('验证通过'); const { code } = await postCreateEnterprises(formData.value);
if (code === 200) {
userStore.getUserInfo();
}
}) })
.finally(() => { .finally(() => {
submitting.value = false; submitting.value = false;

View File

@ -43,7 +43,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
'/api': { '/api': {
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''), rewrite: (path) => path.replace(/^\/api/, ''),
target: 'https://lingjiapi.lvfunai.com/api', target: 'http://192.168.40.12/api',
}, },
}, },
}, },