Commit b5d3bd7b by Lin

feat: 组件/配置封装/页面样式对齐

1 parent 6e991caf
Showing 21 changed files with 262 additions and 183 deletions
<template>
<div class="card-list w-full flex flex-nowrap justify-between gap-6">
<div class="card-item h-[182px] w-[202.5px] rounded-[10px] box-border shadow-[0_4px_12px_0_#525b6629]" v-for="(item, index) in data" :key="index">
<img class="rounded-t-[10px]" :src="getImageUrl(item.iconUrl)" alt="background">
<div class="card-item-bottom h-[102.5px] w-full pl-[16px] pr-[16px]">
<p class="text-[#2f3133] text-sm font-medium mb-1 leading-[22px] ">{{ item.name }}</p>
<div class="flex justify-between" v-for="value in item.desc">
<p class="h-[6px] w-[6px] bg-[#1956FE] rounded-[3px] mt-[6px]"></p>
<p class="w-[158.5px] text-[#565C66] text-xs leading-[18px]">{{value}}</p>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { getImageUrl } from '@/utils/assets';
interface DataItem {
iconUrl: string;
name: string;
desc: string[];
}
const props = defineProps({
data: {
type: Array as PropType<DataItem[]>,
required: true,
},
});
</script>
...@@ -63,7 +63,7 @@ async function render(props: QiankunProps = {}) { ...@@ -63,7 +63,7 @@ async function render(props: QiankunProps = {}) {
// 将 GSC Request 管理器挂载到全局属性,方便组件使用 // 将 GSC Request 管理器挂载到全局属性,方便组件使用
app.config.globalProperties.$gscRequest = gscRequestManager; app.config.globalProperties.$gscRequest = gscRequestManager;
console.log('[子应用] GSC Request 管理器已初始化并挂载'); // console.log('[子应用] GSC Request 管理器已初始化并挂载');
} catch (error) { } catch (error) {
console.error('[子应用] GSC Request 管理器初始化失败:', error); console.error('[子应用] GSC Request 管理器初始化失败:', error);
} }
...@@ -94,7 +94,7 @@ if (!qiankunWindow.__POWERED_BY_QIANKUN__) { ...@@ -94,7 +94,7 @@ if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
* 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子 * 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子
*/ */
export async function bootstrap() { export async function bootstrap() {
console.log('[Vue3 微应用钩子] bootstrap'); // console.log('[Vue3 微应用钩子] bootstrap');
} }
/** /**
...@@ -102,7 +102,7 @@ export async function bootstrap() { ...@@ -102,7 +102,7 @@ export async function bootstrap() {
* 应用每次进入都会调用 mount 方法,通常在这里触发应用的渲染方法 * 应用每次进入都会调用 mount 方法,通常在这里触发应用的渲染方法
*/ */
export async function mount(props: QiankunProps) { export async function mount(props: QiankunProps) {
console.log('Vue3 微应用钩子 mount', props); // console.log('Vue3 微应用钩子 mount', props);
render(props); render(props);
} }
...@@ -111,7 +111,6 @@ export async function mount(props: QiankunProps) { ...@@ -111,7 +111,6 @@ export async function mount(props: QiankunProps) {
* 应用每次切出/卸载都会调用 unmount 方法 * 应用每次切出/卸载都会调用 unmount 方法
*/ */
export async function unmount(props: QiankunProps) { export async function unmount(props: QiankunProps) {
console.log('[Vue3 微应用] unmount', props);
// 销毁通信管理器 // 销毁通信管理器
if (qiankunWindow.__POWERED_BY_QIANKUN__) { if (qiankunWindow.__POWERED_BY_QIANKUN__) {
...@@ -137,7 +136,7 @@ export async function unmount(props: QiankunProps) { ...@@ -137,7 +136,7 @@ export async function unmount(props: QiankunProps) {
* 主应用向子应用下发新的props时触发 * 主应用向子应用下发新的props时触发
*/ */
export async function update(props: QiankunProps) { export async function update(props: QiankunProps) {
console.log('[Vue3 微应用] update', props); // console.log('[Vue3 微应用] update', props);
} }
// 使用 vite-plugin-qiankun 提供的渲染函数 // 使用 vite-plugin-qiankun 提供的渲染函数
......
...@@ -102,7 +102,7 @@ export function createRouter(base: string = '/'): Router { ...@@ -102,7 +102,7 @@ export function createRouter(base: string = '/'): Router {
}); });
router.afterEach((to, from) => { router.afterEach((to, from) => {
console.log('[Vue3 微应用] 路由切换:', from.path, '->', to.path); // console.log('[Vue3 微应用] 路由切换:', from.path, '->', to.path);
}); });
return router; return router;
......
...@@ -31,7 +31,6 @@ class GscRequestManager { ...@@ -31,7 +31,6 @@ class GscRequestManager {
try { try {
if (this.getGscRequestFn) { if (this.getGscRequestFn) {
this.requestInstance = await this.getGscRequestFn(); this.requestInstance = await this.getGscRequestFn();
console.log('[GSC Request] 实例初始化成功');
} }
} catch (error) { } catch (error) {
console.error('[GSC Request] 实例初始化失败:', error); console.error('[GSC Request] 实例初始化失败:', error);
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<div class="grid grid-cols-3 gap-x-8 gap-y-4"> <div class="grid grid-cols-3 gap-x-8 gap-y-4">
<div class="w-[278px] h-[94px] rounded-[10px] bg-white shadow-[0_4px_12px_0_#525b6629] flex items-start p-[16px]" v-for="(item, index) in roleTypes" :key="index"> <div class="w-[278px] h-[94px] rounded-[10px] bg-white shadow-[0_4px_12px_0_#525b6629] flex items-start p-[16px]" v-for="(item, index) in roleTypes" :key="index">
<div class="shrink-0 w-[38px] h-[38px] rounded-lg overflow-hidden mr-[12px] bg-gray-50 flex items-center justify-center"> <div class="shrink-0 w-[38px] h-[38px] rounded-lg overflow-hidden mr-[12px] bg-gray-50 flex items-center justify-center">
<img src="/images/icon-agentic-role01.png" alt="头像" class="w-full h-full object-cover" /> <img :src="getImageUrl(item.iconUrl)" alt="头像" class="w-full h-full object-cover" />
</div> </div>
<div class="flex-1 flex flex-col justify-start min-w-0"> <div class="flex-1 flex flex-col justify-start min-w-0">
<p class="text-[#2f3133] text-sm font-medium mb-1 leading-[22px] ">{{item.name}}</p> <p class="text-[#2f3133] text-sm font-medium mb-1 leading-[22px] ">{{item.name}}</p>
...@@ -51,18 +51,7 @@ ...@@ -51,18 +51,7 @@
<!-- ================= 4. 核心功能 ================= --> <!-- ================= 4. 核心功能 ================= -->
<section class="mt-[48px]"> <section class="mt-[48px]">
<CustomHeaderTitle title="核心功能"/> <CustomHeaderTitle title="核心功能"/>
<div class="card-list flex flex-wrap justify-between gap-5"> <CustomCardList :data="coreFunctions" />
<div class="card-item h-[182px] w-[202.5px] rounded-[10px] box-border shadow-[0_4px_12px_0_#525b6629]" v-for="(item, index) in processedCoreFunctions" :key="index">
<img class="rounded-t-[10px]" :src="item.iconUrl" alt="background">
<div class="card-item-bottom h-[102.5px] w-full pl-[16px] pr-[16px]">
<p class="text-[#2f3133] text-sm font-medium mb-1 leading-[22px] ">{{ item.name }}</p>
<div class="flex justify-between">
<p class="h-[6px] w-[6px] bg-[#1956FE] rounded-[3px] mt-[6px]"></p>
<p class="w-[158.5px] text-[#565C66] text-xs leading-[18px]">{{ item.desc }}</p>
</div>
</div>
</div>
</div>
</section> </section>
</div> </div>
...@@ -97,26 +86,32 @@ const workflowSteps = [ ...@@ -97,26 +86,32 @@ const workflowSteps = [
const roleTypes = [ const roleTypes = [
{ {
name: '独裁型客户', name: '独裁型客户',
iconUrl: '/images/icon-agentic-role01.png',
desc: '具有强烈的控制欲,决策迅速,注重效率,对产品细节要求高' desc: '具有强烈的控制欲,决策迅速,注重效率,对产品细节要求高'
}, },
{ {
name: '人际型客户', name: '人际型客户',
iconUrl: '/images/icon-agentic-role02.png',
desc: '注重人际关系,友好健谈,容易建立信任,但决策可能受情感影响' desc: '注重人际关系,友好健谈,容易建立信任,但决策可能受情感影响'
}, },
{ {
name: '犹豫型客户', name: '犹豫型客户',
iconUrl: '/images/icon-agentic-role03.png',
desc: '顾虑较多,决策缓慢,需要更多的产品信息和客户见证' desc: '顾虑较多,决策缓慢,需要更多的产品信息和客户见证'
}, },
{ {
name: '沉默型客户', name: '沉默型客户',
iconUrl: '/images/icon-agentic-role04.png',
desc: '不善言辞,需要引导,决策谨慎,注重产品可靠性和口碑' desc: '不善言辞,需要引导,决策谨慎,注重产品可靠性和口碑'
}, },
{ {
name: '分析型客户', name: '分析型客户',
iconUrl: '/images/icon-agentic-role05.png',
desc: '理性思考,注重数据和事实,决策过程长,需要充分的信息支持' desc: '理性思考,注重数据和事实,决策过程长,需要充分的信息支持'
}, },
{ {
name: '价格型客户', name: '价格型客户',
iconUrl: '/images/icon-agentic-role06.png',
desc: '对价格敏感,追求性价比,注重产品优惠和折扣' desc: '对价格敏感,追求性价比,注重产品优惠和折扣'
} }
]; ];
...@@ -124,32 +119,26 @@ const coreFunctions = [ ...@@ -124,32 +119,26 @@ const coreFunctions = [
{ {
name: '岗位助理配置', name: '岗位助理配置',
iconUrl: '/images/icon-agentic-core01.png', iconUrl: '/images/icon-agentic-core01.png',
desc: '无需复杂配置,可直接与岗位助理系统对接,自动获取相关岗位信息' desc: ['无需复杂配置,可直接与岗位助理系统对接,自动获取相关岗位信息']
}, },
{ {
name: '智能体编排', name: '智能体编排',
iconUrl: '/images/icon-agentic-core02.png', iconUrl: '/images/icon-agentic-core02.png',
desc: '支持与其他智能体协同工作,如培训智能体、质检智能体等,形成完整的训练体系' desc: ['支持与其他智能体协同工作,如培训智能体、质检智能体等,形成完整的训练体系']
}, },
{ {
name: '实时反馈', name: '实时反馈',
iconUrl: '/images/icon-agentic-core03.png', iconUrl: '/images/icon-agentic-core03.png',
desc: '提供即时的对话分析和改进建议,帮助员工快速提升技能' desc: ['提供即时的对话分析和改进建议,帮助员工快速提升技能']
}, },
{ {
name: '学习记录追踪', name: '学习记录追踪',
iconUrl: '/images/icon-agentic-core04.png', iconUrl: '/images/icon-agentic-core04.png',
desc: '记录员工的训练历史和进步情况,生成学习报告和能力评估' desc: ['记录员工的训练历史和进步情况,生成学习报告和能力评估']
} }
]; ];
// 处理核心功能数据,确保图片 URL 使用子应用自己的域名
const processedCoreFunctions = computed(() => {
return coreFunctions.map(item => ({
...item,
iconUrl: getImageUrl(item.iconUrl)
}))
})
</script> </script>
<style scoped> <style scoped>
......
<template> <template>
<div class="min-h-screen bg-white text-gray-800 font-sans p-6"> <div class="min-h-screen bg-white text-gray-800 font-sans pl-[24px]">
<div class="max-w-7xl mx-auto space-y-10"> <div class="max-w-7xl mx-auto space-y-10">
<!-- ================= 1. 智能体概况 (Agent Overview) ================= --> <!-- ================= 1. 智能体概况 (Agent Overview) ================= -->
......
...@@ -66,19 +66,7 @@ ...@@ -66,19 +66,7 @@
<!-- ================= 4. 核心功能 ================= --> <!-- ================= 4. 核心功能 ================= -->
<section class="mt-[48px]"> <section class="mt-[48px]">
<CustomHeaderTitle title="核心功能"/> <CustomHeaderTitle title="核心功能"/>
<CustomCardList :data="coreFunctions" />
<div class="card-list flex flex-wrap justify-between gap-[16px]">
<div class="card-item min-h-[182px] w-[202.5px] rounded-[10px] box-border shadow-[0_4px_12px_0_#525b6629]" v-for="(item, index) in processedCoreFunctions" :key="index">
<img class="rounded-t-[10px]" :src="item.iconUrl" alt="background" srcset="">
<div class="card-item-bottom min-h-[102.5px] w-full pl-[16px] pr-[16px]">
<p class="text-[#2f3133] text-sm font-medium mb-1 leading-[22px] ">{{item.name}}</p>
<div class="flex justify-between" v-for="value in item.desc">
<p class="h-[6px] w-[6px] bg-[#1956FE] rounded-[3px] mt-[6px]"></p>
<p class="w-[158.5px] text-[#565C66] text-xs leading-[18px]">{{value}}</p>
</div>
</div>
</div>
</div>
</section> </section>
</div> </div>
......
...@@ -32,19 +32,7 @@ ...@@ -32,19 +32,7 @@
<!-- ================= 4. 核心功能 ================= --> <!-- ================= 4. 核心功能 ================= -->
<section class="mt-[48px]"> <section class="mt-[48px]">
<CustomHeaderTitle title="核心功能"/> <CustomHeaderTitle title="核心功能"/>
<CustomCardList :data="coreFunctions" />
<div class="card-list flex flex-wrap justify-between gap-[16px]">
<div class="card-item h-[182px] w-[202.5px] rounded-[10px] box-border shadow-[0_4px_12px_0_#525b6629]" v-for="(item, index) in processedCoreFunctions" :key="index">
<img class="rounded-t-[10px]" :src="item.iconUrl" alt="background">
<div class="card-item-bottom h-[102.5px] w-full pl-[16px] pr-[16px]">
<p class="text-[#2f3133] text-sm font-medium mb-1 leading-[22px] ">{{ item.name }}</p>
<div class="flex justify-between">
<p class="h-[6px] w-[6px] bg-[#1956FE] rounded-[3px] mt-[6px]"></p>
<p class="w-[158.5px] text-[#565C66] text-xs leading-[18px]">{{ item.desc }}</p>
</div>
</div>
</div>
</div>
</section> </section>
<section> <section>
...@@ -155,22 +143,22 @@ const coreFunctions = [ ...@@ -155,22 +143,22 @@ const coreFunctions = [
{ {
name: '岗位助理配置', name: '岗位助理配置',
iconUrl: '/images/icon-agentic-core01.png', iconUrl: '/images/icon-agentic-core01.png',
desc: '无需复杂配置,可直接与岗位助理系统对接,自动获取相关岗位信息' desc: ['无需复杂配置,可直接与岗位助理系统对接,自动获取相关岗位信息']
}, },
{ {
name: '智能体编排', name: '智能体编排',
iconUrl: '/images/icon-agentic-core02.png', iconUrl: '/images/icon-agentic-core02.png',
desc: '支持与其他智能体协同工作,如培训智能体、质检智能体等,形成完整的训练体系' desc: ['支持与其他智能体协同工作,如培训智能体、质检智能体等,形成完整的训练体系']
}, },
{ {
name: '实时反馈', name: '实时反馈',
iconUrl: '/images/icon-agentic-core03.png', iconUrl: '/images/icon-agentic-core03.png',
desc: '提供即时的对话分析和改进建议,帮助员工快速提升技能' desc: ['提供即时的对话分析和改进建议,帮助员工快速提升技能']
}, },
{ {
name: '学习记录追踪', name: '学习记录追踪',
iconUrl: '/images/icon-agentic-core04.png', iconUrl: '/images/icon-agentic-core04.png',
desc: '记录员工的训练历史和进步情况,生成学习报告和能力评估' desc: ['记录员工的训练历史和进步情况,生成学习报告和能力评估']
} }
]; ];
const getTrainingPlanList = async () => { const getTrainingPlanList = async () => {
......
...@@ -30,7 +30,11 @@ function initConfigReadyPromise() { ...@@ -30,7 +30,11 @@ function initConfigReadyPromise() {
} }
return configReadyPromise; return configReadyPromise;
} }
export async function fetchMicroAppConfig(): Promise<any> {
const response = await fetch(ROUTER_URL);
const result = await response.json();
return result;
}
/** /**
* 获取 GSC API 请求实例 * 获取 GSC API 请求实例
* @returns Request 实例,如果未初始化则返回 null * @returns Request 实例,如果未初始化则返回 null
...@@ -87,9 +91,8 @@ export async function fetchConfig(): Promise<any> { ...@@ -87,9 +91,8 @@ export async function fetchConfig(): Promise<any> {
events: { events: {
error: (error: any, requestConfig: any) => { error: (error: any, requestConfig: any) => {
console.error('[配置中心] GSC API 错误:', error, requestConfig); console.error('[配置中心] GSC API 错误:', error, requestConfig);
// 检查错误信息中是否包含 401 状态码 // 检查错误信息中是否包含 401 状态码
const errorMessage = error?.message || error?.toString() || String(error); const errorMessage = error?.msg || error?.message || error?.toString() || String(error);
if (errorMessage.includes('401')) { if (errorMessage.includes('401')) {
ElMessage.error('登录已过期,请重新登录'); ElMessage.error('登录已过期,请重新登录');
clearAuth(); clearAuth();
...@@ -97,11 +100,12 @@ export async function fetchConfig(): Promise<any> { ...@@ -97,11 +100,12 @@ export async function fetchConfig(): Promise<any> {
if (window.location.pathname !== '/login') { if (window.location.pathname !== '/login') {
window.location.href = '/login'; window.location.href = '/login';
} }
return; }else{
ElMessage.error(errorMessage);
} }
}, },
logout: (response: any, requestConfig: any) => { logout: (response: any, requestConfig: any) => {
console.log('[配置中心] GSC API 登出:', response, requestConfig); // console.log('[配置中心] GSC API 登出:', response, requestConfig);
}, },
}, },
}); });
...@@ -133,46 +137,20 @@ export async function fetchConfig(): Promise<any> { ...@@ -133,46 +137,20 @@ export async function fetchConfig(): Promise<any> {
} else { } else {
console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例'); console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例');
// 即使没有 GSC 配置,也要 resolve Promise,避免 waitForConfigReady 一直等待
if (configReadyResolve) {
configReadyResolve();
configReadyResolve = null;
}
} }
// if (gscConfig) {
// // 创建请求实例,存储在模块级变量中,不挂载到 window
// gscApiInstance = new Request({
// ...gscConfig,
// session: {
// requiresSession: false,
// sessionId: 'd5629aee-28c7-4def-a8fa-95d76c978dc7',
// },
// headers: {
// 'Authorization': '237f1ca886db4a0fbde44ef446ec74bb',
// 'X-App-Version': '1.0.0'
// },
// events: {
// error: (error: any, requestConfig: any) => {
// console.error('[配置中心] GSC API 错误:', error, requestConfig);
// },
// logout: (response: any, requestConfig: any) => {
// console.log('[配置中心] GSC API 登出:', response, requestConfig);
// },
// },
// // Sentry 配置
// // sentry: {
// // enable: true, // 是否启用Sentry错误上报
// // dsn: 'https://ace1d827739e4229887b78468bd8a385@sentry.glsx.com.cn/48'
// // }
// });
// // 通知配置已就绪
// if (configReadyResolve) {
// configReadyResolve();
// configReadyResolve = null;
// }
// } else {
// console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例');
// }
return configData; return configData;
} catch (error) { } catch (error) {
console.error('[配置中心] 获取配置失败:', error); console.error('[配置中心] 获取配置失败:', error);
// 配置加载失败时,也要 resolve Promise,避免 waitForConfigReady 一直等待
if (configReadyResolve) {
configReadyResolve();
configReadyResolve = null;
}
throw error; throw error;
} }
} }
...@@ -189,7 +167,6 @@ export async function fetchRouterConfig(): Promise<any> { ...@@ -189,7 +167,6 @@ export async function fetchRouterConfig(): Promise<any> {
const response = await fetch(ROUTER_URL); const response = await fetch(ROUTER_URL);
const result = await response.json(); const result = await response.json();
routerConfig = result; routerConfig = result;
console.log('[配置中心] 路由配置响应结果:', result);
return result; return result;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* GSC 请求封装 * GSC 请求封装
* Authorization 通过请求拦截器统一处理,无需手动添加 * Authorization 通过请求拦截器统一处理,无需手动添加
*/ */
import { getGscApi } from './center'; import { getGscApi, waitForConfigReady } from './center';
/** /**
* GSC POST 请求 * GSC POST 请求
...@@ -10,18 +10,33 @@ import { getGscApi } from './center'; ...@@ -10,18 +10,33 @@ import { getGscApi } from './center';
* @param data 请求数据 * @param data 请求数据
* @param config 请求配置(可选) * @param config 请求配置(可选)
*/ */
export const gscPost = (url: string, data: any, config: any = {}) => { export const gscPost = async (url: string, data: any, config: any = {}) => {
// 如果 GSC API 实例未初始化,等待配置加载完成
const gscApi = getGscApi(); const gscApi = getGscApi();
if (!gscApi) { if (!gscApi) {
const error = new Error( try {
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成', // 等待配置加载完成
); await waitForConfigReady();
console.error(error); // 再次尝试获取 GSC API 实例
return Promise.reject(error); const retryGscApi = getGscApi();
if (!retryGscApi) {
const error = new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成且包含 GSC 配置',
);
console.error(error);
return Promise.reject(error);
}
return retryGscApi.post(url, data, config);
} catch (error) {
console.error('[GSC请求] 等待配置加载失败:', error);
return Promise.reject(
new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成',
),
);
}
} }
console.log('[GSC请求] 发起请求:', url, data);
return gscApi.post(url, data, config); return gscApi.post(url, data, config);
}; };
...@@ -30,18 +45,33 @@ export const gscPost = (url: string, data: any, config: any = {}) => { ...@@ -30,18 +45,33 @@ export const gscPost = (url: string, data: any, config: any = {}) => {
* @param url 请求地址 * @param url 请求地址
* @param config 请求配置(可选) * @param config 请求配置(可选)
*/ */
export const gscGet = (url: string, config: any = {}) => { export const gscGet = async (url: string, config: any = {}) => {
// 如果 GSC API 实例未初始化,等待配置加载完成
const gscApi = getGscApi(); const gscApi = getGscApi();
if (!gscApi) { if (!gscApi) {
const error = new Error( try {
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成', // 等待配置加载完成
); await waitForConfigReady();
console.error(error); // 再次尝试获取 GSC API 实例
return Promise.reject(error); const retryGscApi = getGscApi();
if (!retryGscApi) {
const error = new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成且包含 GSC 配置',
);
console.error(error);
return Promise.reject(error);
}
return retryGscApi.get(url, config);
} catch (error) {
console.error('[GSC请求] 等待配置加载失败:', error);
return Promise.reject(
new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成',
),
);
}
} }
console.log('[GSC请求] 发起请求:', url);
return gscApi.get(url, config); return gscApi.get(url, config);
}; };
......
...@@ -75,11 +75,7 @@ const breadcrumbs = computed<BreadcrumbItem[]>(() => { ...@@ -75,11 +75,7 @@ const breadcrumbs = computed<BreadcrumbItem[]>(() => {
// 如果不在首页,添加当前路由的面包屑 // 如果不在首页,添加当前路由的面包屑
if (route.path !== '/home' && route.path !== '/') { if (route.path !== '/home' && route.path !== '/') {
const paths = getMenuParentPaths(allMenus.value, route.path); const paths = getMenuParentPaths(allMenus.value, route.path);
console.log(
'路由调用',
paths,
menuStore.isMenusLoaded ? '动态菜单' : '默认菜单',
);
// 根据路径找到对应的菜单项 // 根据路径找到对应的菜单项
paths.forEach((path) => { paths.forEach((path) => {
......
import type { MicroAppConfig } from './types'; // 微应用配置类型 import type { MicroAppConfig } from './types'; // 微应用配置类型
import { getGscApi, waitForConfigReady } from '@/config/center'; import { getGscApi, waitForConfigReady, fetchMicroAppConfig} from '@/config/center';
import { createSubAppAdapter } from './subAppAdapter'; // 微应用统一通信适配器 import { createSubAppAdapter } from './subAppAdapter'; // 微应用统一通信适配器
import { transformRemoteConfigToQiankunConfig } from './configTransformer';
/** // 微应用配置列表(初始为空,后续动态加载)
* 微应用配置列表 export let microApps: MicroAppConfig[] = [
* 根据环境自动切换微应用地址
*/
export const microApps: MicroAppConfig[] = [
{ {
name: 'subapp-vue', name: 'subapp-vue',
entry: getAppEntry('subapp-vue', 'http://192.168.1.93:8081'), entry: getAppEntry('subapp-vue', 'http://192.168.1.93:8081'),
...@@ -32,8 +29,26 @@ export const microApps: MicroAppConfig[] = [ ...@@ -32,8 +29,26 @@ export const microApps: MicroAppConfig[] = [
}, },
}, },
}, },
]; ];;
// 默认配置(作为降级方案)
const defaultMicroApps: MicroAppConfig[] = [];
/**
* 加载并设置微应用配置
*/
export async function loadMicroAppConfig(): Promise<void> {
try {
const remoteConfig = await fetchMicroAppConfig();
microApps = transformRemoteConfigToQiankunConfig(remoteConfig.data?.microApps);
// 如果远程配置为空,使用默认配置
if (microApps.length === 0) {
microApps = defaultMicroApps;
}
} catch (error) {
console.error('[微前端配置] 配置加载失败,使用默认配置:', error);
microApps = defaultMicroApps;
}
}
/** /**
* 获取微应用入口地址 * 获取微应用入口地址
* @param appName 应用名称 * @param appName 应用名称
......
...@@ -132,7 +132,6 @@ class CommunicationManager { ...@@ -132,7 +132,6 @@ class CommunicationManager {
// 监听状态变化,同步更新本地副本 // 监听状态变化,同步更新本地副本
this.actions.onGlobalStateChange((state, prev) => { this.actions.onGlobalStateChange((state, prev) => {
console.log('[基座通信] 全局状态变化:', state, prev);
// 更新本地状态副本 // 更新本地状态副本
this.currentState = state as GlobalState; this.currentState = state as GlobalState;
...@@ -143,7 +142,6 @@ class CommunicationManager { ...@@ -143,7 +142,6 @@ class CommunicationManager {
}); });
}); });
console.log('[基座通信] 通信管理器初始化完成');
} }
/** /**
...@@ -186,7 +184,6 @@ class CommunicationManager { ...@@ -186,7 +184,6 @@ class CommunicationManager {
// 同步到 qiankun 全局状态(只传入变化的部分) // 同步到 qiankun 全局状态(只传入变化的部分)
this.actions.setGlobalState(state); this.actions.setGlobalState(state);
console.log('[基座通信] 全局状态已更新:', state);
} else { } else {
console.warn('[基座通信] 通信管理器未初始化'); console.warn('[基座通信] 通信管理器未初始化');
} }
...@@ -222,7 +219,6 @@ class CommunicationManager { ...@@ -222,7 +219,6 @@ class CommunicationManager {
timestamp: Date.now(), timestamp: Date.now(),
}, },
}); });
console.log('[基座通信] 当前菜单已更新:', menu);
} }
/** /**
......
import type { MicroAppConfig } from './types';
import { getGscApi, waitForConfigReady } from '@/config/center';
import { createSubAppAdapter } from './subAppAdapter';
/**
* 远程微应用配置项
*/
interface RemoteMicroApp {
name: string;
entry: string | RemoteAppEntry;
container: string;
activeRule: string;
props?: Record<string, any>;
enabled?: boolean;
}
/**
* 远程应用入口配置(支持多环境)
*/
interface RemoteAppEntry {
development?: string;
production?: string;
test?: string;
default: string;
}
/**
* 解析应用入口地址
* 根据当前环境选择对应的入口地址
*/
function resolveEntry(entry: string | RemoteAppEntry): string {
// 如果是字符串,直接返回
if (typeof entry === 'string') {
return entry;
}
// 获取当前环境
const env = (import.meta as any).env?.MODE || 'development';
// 根据环境选择对应的地址
const entryUrl =
entry[env as keyof RemoteAppEntry] ||
entry.default ||
'';
if (!entryUrl) {
return entry.default || '';
}
return entryUrl;
}
/**
* 转换远程配置为 qiankun 配置
* @param remoteMicroApps 远程微应用配置数组
*/
export function transformRemoteConfigToQiankunConfig(
remoteMicroApps?: RemoteMicroApp[],
): MicroAppConfig[] {
// 如果没有传入配置或为空数组,返回空数组
if (!remoteMicroApps || remoteMicroApps.length === 0) {
console.warn('[微前端配置] 远程微应用配置为空');
return [];
}
return remoteMicroApps
.filter((app) => app.enabled !== false) // 过滤未启用的应用
.map((remoteApp) => {
const resolvedEntry = resolveEntry(remoteApp.entry);
return {
name: remoteApp.name,
entry: resolvedEntry,
container: remoteApp.container,
activeRule: remoteApp.activeRule,
props: {
// 保留远程配置的 props
...remoteApp.props,
// 动态注入运行时依赖
communicationManager: createSubAppAdapter(),
getGscRequest: async () => {
await waitForConfigReady();
const requestInstance = getGscApi();
if (!requestInstance) {
throw new Error(
'[微应用] GSC Request 实例未初始化',
);
}
return requestInstance;
},
},
};
});
}
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
} from 'qiankun'; } from 'qiankun';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { microApps } from './apps'; // 微应用信息配置 import { microApps, loadMicroAppConfig } from './apps'; // 微应用信息配置
import { communicationManager } from './communication'; // 通信管理器 import { communicationManager } from './communication'; // 通信管理器
import { microAppLifecycles } from './lifecycles'; // 微应用生命周期钩子 import { microAppLifecycles } from './lifecycles'; // 微应用生命周期钩子
...@@ -38,7 +38,9 @@ const qiankunConfig = { ...@@ -38,7 +38,9 @@ const qiankunConfig = {
/** /**
* 初始化并启动 qiankun * 初始化并启动 qiankun
*/ */
export function setupQiankun() { export async function setupQiankun() {
// 先加载微应用配置(包含运行时依赖注入)
await loadMicroAppConfig();
// 1. 初始化通信管理器 // 1. 初始化通信管理器
communicationManager.init(); communicationManager.init();
registerMicroApps(microApps, microAppLifecycles); registerMicroApps(microApps, microAppLifecycles);
...@@ -48,7 +50,6 @@ export function setupQiankun() { ...@@ -48,7 +50,6 @@ export function setupQiankun() {
// 可以在这里做一些全局错误处理 // 可以在这里做一些全局错误处理
// 例如:错误上报、错误提示等 // 例如:错误上报、错误提示等
const { message } = event as any; const { message } = event as any;
console.log(message);
if (message && message.includes('died in status')) { if (message && message.includes('died in status')) {
console.error('[qiankun] 微应用加载失败,请检查微应用是否正常运行'); console.error('[qiankun] 微应用加载失败,请检查微应用是否正常运行');
// 显示错误弹框提示 // 显示错误弹框提示
......
...@@ -8,7 +8,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = { ...@@ -8,7 +8,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = {
* 微应用加载前 * 微应用加载前
*/ */
beforeLoad: async (app) => { beforeLoad: async (app) => {
console.log('[qiankun] before load', app.name);
// 显示加载状态 // 显示加载状态
try { try {
...@@ -24,7 +23,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = { ...@@ -24,7 +23,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = {
* 微应用挂载前 * 微应用挂载前
*/ */
beforeMount: async (app) => { beforeMount: async (app) => {
console.log('[qiankun] before mount', app.name);
// 确保主应用的数据已准备好并同步到全局状态 // 确保主应用的数据已准备好并同步到全局状态
try { try {
...@@ -48,8 +46,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = { ...@@ -48,8 +46,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = {
* 微应用挂载后 * 微应用挂载后
*/ */
afterMount: async (app) => { afterMount: async (app) => {
console.log('[qiankun] after mount', app.name);
// 隐藏加载状态 // 隐藏加载状态
try { try {
const { useAppStore } = await import('@/stores'); const { useAppStore } = await import('@/stores');
...@@ -64,8 +60,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = { ...@@ -64,8 +60,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = {
* 微应用卸载前 * 微应用卸载前
*/ */
beforeUnmount: async (app) => { beforeUnmount: async (app) => {
console.log('[qiankun] before unmount', app.name);
// 可以在这里做一些卸载前的清理工作 // 可以在这里做一些卸载前的清理工作
// 例如:保存状态、显示卸载动画等 // 例如:保存状态、显示卸载动画等
}, },
...@@ -74,8 +68,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = { ...@@ -74,8 +68,6 @@ export const microAppLifecycles: FrameworkLifeCycles<any> = {
* 微应用卸载后 * 微应用卸载后
*/ */
afterUnmount: async (app) => { afterUnmount: async (app) => {
console.log('[qiankun] after unmount', app.name);
// 确保清除加载状态 // 确保清除加载状态
try { try {
const { useAppStore } = await import('@/stores'); const { useAppStore } = await import('@/stores');
......
...@@ -57,18 +57,18 @@ const routes: RouteRecordRaw[] = [ ...@@ -57,18 +57,18 @@ const routes: RouteRecordRaw[] = [
}, },
], ],
}, },
// ==================== 404 页面 ====================
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('@/views/NotFound.vue'),
meta: {
title: '页面未找到',
requiresAuth: false,
},
},
], ],
}, },
// ==================== 404 页面 ====================
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('@/views/NotFound.vue'),
meta: {
title: '',
requiresAuth: false,
},
},
]; ];
const router = createRouter({ const router = createRouter({
...@@ -239,12 +239,10 @@ router.beforeEach(async (to, _from, next) => { ...@@ -239,12 +239,10 @@ router.beforeEach(async (to, _from, next) => {
if (isMatched) { if (isMatched) {
// 路由已匹配,重新导航到目标路径 // 路由已匹配,重新导航到目标路径
console.log('[路由守卫] 动态路由加载完成,重新导航到:', to.path);
next({ path: to.path, replace: true }); next({ path: to.path, replace: true });
return; return;
} else { } else {
// 确实不存在,显示404页面 // 确实不存在,显示404页面
console.log('[路由守卫] 动态路由加载完成,但路由不存在,显示404页面');
next(); next();
return; return;
} }
...@@ -328,7 +326,7 @@ router.beforeEach(async (to, _from, next) => { ...@@ -328,7 +326,7 @@ router.beforeEach(async (to, _from, next) => {
*/ */
router.afterEach((to, from) => { router.afterEach((to, from) => {
// 路由跳转完成后的处理 // 路由跳转完成后的处理
console.log(`[路由] 从 ${from.path} 跳转到 ${to.path}`); // console.log(`[路由] 从 ${from.path} 跳转到 ${to.path}`);
}); });
/** /**
...@@ -337,7 +335,6 @@ router.afterEach((to, from) => { ...@@ -337,7 +335,6 @@ router.afterEach((to, from) => {
*/ */
async function syncDataToQiankun(userStore: any): Promise<void> { async function syncDataToQiankun(userStore: any): Promise<void> {
try { try {
console.log('[路由守卫] 准备进入微应用,同步数据到 qiankun 全局状态');
// 同步用户信息 // 同步用户信息
if (userStore.userInfo) { if (userStore.userInfo) {
......
...@@ -133,11 +133,9 @@ export const useUserStore = defineStore('user', () => { ...@@ -133,11 +133,9 @@ export const useUserStore = defineStore('user', () => {
role: roles.value[0] || 'user', role: roles.value[0] || 'user',
permissions: permissions.value, permissions: permissions.value,
}); });
console.log('[用户Store] 用户信息已同步到 qiankun 全局状态');
} else { } else {
// 用户退出时,清空全局状态中的用户信息 // 用户退出时,清空全局状态中的用户信息
communicationManager.updateUser(null); communicationManager.updateUser(null);
console.log('[用户Store] 用户信息已清空');
} }
}) })
.catch((error) => { .catch((error) => {
......
...@@ -6,7 +6,6 @@ import { onMounted, onUnmounted, ref } from 'vue'; ...@@ -6,7 +6,6 @@ import { onMounted, onUnmounted, ref } from 'vue';
// 按需引入 @venus/common-ui-vue 组件库的按钮组件 // 按需引入 @venus/common-ui-vue 组件库的按钮组件
import { GLButton } from '@venus/common-ui-vue'; import { GLButton } from '@venus/common-ui-vue';
import { getdataBoard } from '@/api/test';
import { waitForConfigReady } from '@/config/center'; import { waitForConfigReady } from '@/config/center';
import { broadcast, communicationManager, microApps } from '@/qiankun'; import { broadcast, communicationManager, microApps } from '@/qiankun';
import { import {
...@@ -36,16 +35,7 @@ const clickCount = ref(0); ...@@ -36,16 +35,7 @@ const clickCount = ref(0);
onMounted(async () => { onMounted(async () => {
try { try {
await waitForConfigReady(); await waitForConfigReady();
console.log('[Home] 配置已就绪,开始请求数据看板...');
const res = await getdataBoard({
merchantNos: '',
dateType: '1',
startDate: '',
endDate: '',
});
console.log('[Home] 数据看板请求成功:', res);
} catch (error: any) { } catch (error: any) {
console.error('[Home] 数据看板请求失败:', error);
} }
// 获取当前全局状态 // 获取当前全局状态
globalState.value = communicationManager.getGlobalState(); globalState.value = communicationManager.getGlobalState();
......
...@@ -113,7 +113,6 @@ const handleLogin = async () => { ...@@ -113,7 +113,6 @@ const handleLogin = async () => {
} }
}; };
const rsaEncrypt = (data: any, publicKeyBase64: any) => { const rsaEncrypt = (data: any, publicKeyBase64: any) => {
console.log('publicKeyBase64', publicKeyBase64);
try { try {
const encrypt = new JSEncrypt(); const encrypt = new JSEncrypt();
// 将Base64公钥转换为PEM格式 // 将Base64公钥转换为PEM格式
...@@ -136,7 +135,6 @@ const rsaEncrypt = (data: any, publicKeyBase64: any) => { ...@@ -136,7 +135,6 @@ const rsaEncrypt = (data: any, publicKeyBase64: any) => {
const refreshCaptcha = async () => { const refreshCaptcha = async () => {
try { try {
const result = await getCaptcha({}); const result = await getCaptcha({});
console.log('getCaptcha', result);
if (result?.captchaImg) { if (result?.captchaImg) {
captchaUrl.value = result?.captchaImg; captchaUrl.value = result?.captchaImg;
} }
......
...@@ -24,8 +24,9 @@ const goHome = () => { ...@@ -24,8 +24,9 @@ const goHome = () => {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
min-height: 100vh; height: 100%;
background: linear-gradient(135deg, #fff 0%, #fff 100%); padding: 60px 20px;
background: #fff;
} }
.not-found-content { .not-found-content {
...@@ -57,17 +58,18 @@ const goHome = () => { ...@@ -57,17 +58,18 @@ const goHome = () => {
padding: 12px 32px; padding: 12px 32px;
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;
color: #000; color: #fff;
cursor: pointer; cursor: pointer;
background: #fff; background: #1956fe;
border: none; border: none;
border-radius: 24px; border-radius: 24px;
box-shadow: 0 4px 12px rgb(0 0 0 / 15%); box-shadow: 0 4px 12px rgb(31 86 254 / 25%);
transition: all 0.3s; transition: all 0.3s;
} }
.back-button:hover { .back-button:hover {
box-shadow: 0 6px 16px rgb(0 0 0 / 20%); background: #1443d8;
box-shadow: 0 6px 16px rgb(31 86 254 / 35%);
transform: translateY(-2px); transform: translateY(-2px);
} }
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!