Commit 4f903a93 by Lin

feat:智能体平台页面开发/交互完善

1 parent 23711638
Showing 78 changed files with 1337 additions and 552 deletions
/// <reference types="vite/client" />
// / <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue';
......@@ -26,19 +26,19 @@ declare module 'glsk-common' {
}
export class Http {
constructor(config: HttpConfig);
[key: string]: any;
constructor(config: HttpConfig);
}
}
declare module 'glsk-toolkit' {
export class Request {
[key: string]: any;
constructor(config: any);
post(url: string, data?: any, config?: any): Promise<any>;
delete(url: string, config?: any): Promise<any>;
get(url: string, config?: any): Promise<any>;
post(url: string, data?: any, config?: any): Promise<any>;
put(url: string, data?: any, config?: any): Promise<any>;
delete(url: string, config?: any): Promise<any>;
[key: string]: any;
}
}
......
......@@ -10,12 +10,12 @@
"type-check": "vue-tsc --noEmit"
},
"dependencies": {
"@venus/common-ui-vue": "workspace:*",
"@element-plus/icons-vue": "catalog:",
"glsk-toolkit": "catalog:",
"@venus/common-ui-vue": "workspace:*",
"@vueuse/core": "catalog:",
"axios": "catalog:",
"element-plus": "catalog:",
"glsk-toolkit": "catalog:",
"pinia": "catalog:",
"qiankun": "catalog:",
"vue": "catalog:",
......
import gscPost from '@/config/gscrequest'
import gscPost from '@/config/gscrequest';
// 数据看板指标统计
export function getdataBoard(data: any) {
console.log("SSSSS");
return gscPost("/dataBoard/index", data)
console.log('SSSSS');
return gscPost('/dataBoard/index', data);
}
......@@ -9,14 +9,15 @@ import { Request } from 'glsk-toolkit';
let baseConfig: any = {};
// GSC API 请求实例(模块级单例,不挂载到 window)
let gscApiInstance: Request | null = null;
let gscApiInstance: null | Request = null;
// 配置加载完成的 Promise
let configReadyPromise: Promise<void> | null = null;
let configReadyPromise: null | Promise<void> = null;
let configReadyResolve: (() => void) | null = null;
// 配置请求 URL
const CONFIG_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config';
const CONFIG_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config';
// 初始化配置就绪 Promise
function initConfigReadyPromise() {
......@@ -32,7 +33,7 @@ function initConfigReadyPromise() {
* 获取 GSC API 请求实例
* @returns Request 实例,如果未初始化则返回 null
*/
export function getGscApi(): Request | null {
export function getGscApi(): null | Request {
return gscApiInstance;
}
......@@ -57,17 +58,17 @@ export function waitForConfigReady(): Promise<void> {
export async function fetchConfig(): Promise<any> {
// 初始化配置就绪 Promise
initConfigReadyPromise();
try {
const response = await fetch(CONFIG_URL);
const result = await response.json();
const { code, data } = result;
console.log('[配置中心] 响应结果:', code, result);
// 根据 code 决定使用的配置数据
const configData = code === '200' ? data : result;
if (code === '200') {
console.log('[配置中心] 配置数据:', data);
baseConfig = data;
......@@ -77,7 +78,7 @@ export async function fetchConfig(): Promise<any> {
baseConfig = result;
window.$fetchConfig = result;
}
// 统一初始化 GSC API(无论 code 是什么,只要有配置就初始化)
const gscConfig = configData?.gsc || configData;
if (gscConfig) {
......@@ -97,12 +98,12 @@ export async function fetchConfig(): Promise<any> {
},
},
});
console.log('[配置中心] GSC API 实例创建成功:', gscApiInstance);
// 为了向后兼容,同时挂载到 window(可选,如果不需要可以删除)
// window.$gscApi = gscApiInstance;
// 通知配置已就绪
if (configReadyResolve) {
configReadyResolve();
......@@ -111,7 +112,7 @@ export async function fetchConfig(): Promise<any> {
} else {
console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例');
}
return configData;
} catch (error) {
console.error('[配置中心] 获取配置失败:', error);
......@@ -137,4 +138,3 @@ export function setConfig(config: any): void {
// 导出配置数据(只读)
export { baseConfig };
......@@ -5,13 +5,15 @@ import { getGscApi } from './center';
export const gscPost = (url: string, data: any, _config = {}) => {
const gscApi = getGscApi();
if (!gscApi) {
const error = new Error('[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成');
const error = new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成',
);
console.error(error);
return Promise.reject(error);
}
console.log('[GSC请求] 发起请求:', url, data);
return gscApi.post(url, data, _config);
};
......
......@@ -8,6 +8,7 @@ import { setupQiankun } from './qiankun';
import router from './router';
import { useAppStore, useUserStore } from './stores';
import { getToken } from './utils/auth';
import './style.css';
// 创建应用实例
......@@ -97,4 +98,3 @@ fetchConfig()
});
});
});
import type { MicroAppConfig } from './types'; //微应用配置类型
import type { MicroAppConfig } from './types'; // 微应用配置类型
import { createSubAppAdapter } from './subAppAdapter'; //微应用统一通信适配器
import { createSubAppAdapter } from './subAppAdapter'; // 微应用统一通信适配器
/**
* 微应用配置列表
......
......@@ -69,11 +69,8 @@ export {
export { broadcast, communicationManager } from './communication';
export type { GlobalState, Notification } from './communication';
export { microAppLifecycles } from './lifecycles';
export * from './types';
export * from './utils';
// 导出子应用适配器相关类型和函数
export { createSubAppAdapter } from './subAppAdapter';
export type {
QiankunProps,
SubAppCommunicationManager,
} from './subAppAdapter';
export type { QiankunProps, SubAppCommunicationManager } from './subAppAdapter';
export * from './types';
export * from './utils';
import type { GlobalState, Notification } from './communication';
import { communicationManager } from './communication';
/**
......@@ -66,10 +67,36 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
private currentState: GlobalState | null = null;
private listeners: Array<(state: GlobalState, prev: GlobalState) => void> =
[];
private props: QiankunProps | null = null;
private props: null | QiankunProps = null;
private unsubscribe: (() => void) | null = null;
/**
* 销毁通信管理器
*/
destroy() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
}
this.listeners = [];
this.props = null;
this.currentState = null;
console.log('[子应用通信适配器] 通信管理器已销毁');
}
/**
* 获取当前全局状态
*/
getCurrentState(): GlobalState | null {
// 优先返回缓存的状态
if (this.currentState) {
return this.currentState;
}
// 如果没有缓存,从基座获取
return communicationManager.getGlobalState();
}
/**
* 初始化通信管理器
* @param props qiankun 传递的 props
*/
......@@ -119,18 +146,6 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
}
/**
* 获取当前全局状态
*/
getCurrentState(): GlobalState | null {
// 优先返回缓存的状态
if (this.currentState) {
return this.currentState;
}
// 如果没有缓存,从基座获取
return communicationManager.getGlobalState();
}
/**
* 监听全局状态变化
* @param callback 回调函数
* @returns 取消监听的函数
......@@ -142,9 +157,7 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
// 如果已经有缓存的状态,立即调用一次回调
if (this.currentState) {
console.log(
'[子应用通信适配器] 立即触发回调,使用缓存的全局状态',
);
console.log('[子应用通信适配器] 立即触发回调,使用缓存的全局状态');
callback(this.currentState, {} as GlobalState);
}
......@@ -157,22 +170,6 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
}
/**
* 设置全局状态(向基座发送数据)
* @param state 要更新的状态
*/
setGlobalState(state: Partial<GlobalState>) {
// 通过基座的通信管理器设置状态
communicationManager.setGlobalState(state);
// 同时通过 qiankun 的 props 设置(如果可用)
if (this.props?.setGlobalState) {
this.props.setGlobalState(state);
}
console.log('[子应用通信适配器] 全局状态已更新:', state);
}
/**
* 向基座发送通知
* @param notification 通知消息
*/
......@@ -185,17 +182,19 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
}
/**
* 销毁通信管理器
* 设置全局状态(向基座发送数据)
* @param state 要更新的状态
*/
destroy() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
setGlobalState(state: Partial<GlobalState>) {
// 通过基座的通信管理器设置状态
communicationManager.setGlobalState(state);
// 同时通过 qiankun 的 props 设置(如果可用)
if (this.props?.setGlobalState) {
this.props.setGlobalState(state);
}
this.listeners = [];
this.props = null;
this.currentState = null;
console.log('[子应用通信适配器] 通信管理器已销毁');
console.log('[子应用通信适配器] 全局状态已更新:', state);
}
}
......@@ -206,4 +205,3 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
export function createSubAppAdapter(): SubAppCommunicationManager {
return new SubAppCommunicationAdapter();
}
......@@ -71,7 +71,7 @@ export const useUserStore = defineStore('user', () => {
permissions.value = [];
roles.value = [];
removeToken();
console.log("退出");
console.log('退出');
// 同步清空 qiankun 全局状态中的用户信息
syncUserToQiankun();
}
......
......@@ -2,14 +2,16 @@
* Axios 请求封装
*/
import axios, {
type AxiosError,
type AxiosInstance,
type AxiosRequestConfig,
type AxiosResponse,
type InternalAxiosRequestConfig,
import type {
AxiosError,
AxiosInstance,
AxiosRequestConfig,
AxiosResponse,
InternalAxiosRequestConfig,
} from 'axios';
import axios from 'axios';
import { clearAuth, getToken } from './auth';
// 创建 axios 实例
......@@ -129,9 +131,7 @@ const handleUnauthorized = () => {
* 通用请求方法
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export const request = <T = any>(
config: AxiosRequestConfig,
): Promise<T> => {
export const request = <T = any>(config: AxiosRequestConfig): Promise<T> => {
return service.request<T, T>(config) as Promise<T>;
};
......
......@@ -2,9 +2,11 @@
import type { GlobalState } from '@/qiankun';
import { onMounted, onUnmounted, ref } from 'vue';
// 按需引入 @venus/common-ui-vue 组件库的按钮组件
import { GLButton } from '@venus/common-ui-vue';
import { getdataBoard } from "@/api/test"
import { getdataBoard } from '@/api/test';
import { waitForConfigReady } from '@/config/center';
import { broadcast, communicationManager, microApps } from '@/qiankun';
import {
......@@ -37,11 +39,16 @@ onMounted(async () => {
try {
await waitForConfigReady();
console.log('[Home] 配置已就绪,开始请求数据看板...');
const res = await getdataBoard({merchantNos: '', dateType: '1', startDate: '', endDate: ''});
const res = await getdataBoard({
merchantNos: '',
dateType: '1',
startDate: '',
endDate: '',
});
console.log('[Home] 数据看板请求成功:', res);
} catch (err: any) {
console.error('[Home] 数据看板请求失败:', err);
} catch (error: any) {
console.error('[Home] 数据看板请求失败:', error);
}
// 获取当前全局状态
globalState.value = communicationManager.getGlobalState();
......@@ -246,9 +253,11 @@ const handleDebounceClick = () => {
<div class="state-label">👤 当前用户</div>
<div class="state-value">
<span class="user-avatar">{{ globalState.user?.avatar }}</span>
<span>{{ globalState.user?.name }} ({{
<span
>{{ globalState.user?.name }} ({{
globalState.user?.role
}})</span>
}})</span
>
</div>
</div>
......@@ -369,7 +378,9 @@ const handleDebounceClick = () => {
<div class="notification-title">{{ notification.title }}</div>
<div class="notification-message">{{ notification.message }}</div>
<div class="notification-meta">
<span v-if="notification.from" class="notification-from">来自: {{ notification.from }}</span>
<span v-if="notification.from" class="notification-from"
>来自: {{ notification.from }}</span
>
<span class="notification-time">{{
formatTime(notification.timestamp)
}}</span>
......@@ -398,13 +409,16 @@ const handleDebounceClick = () => {
<h4>💡 使用说明</h4>
<ul>
<li>
<strong>全局状态:</strong>主应用和微应用共享的状态,任何一方修改都会实时同步。
<strong>全局状态:</strong
>主应用和微应用共享的状态,任何一方修改都会实时同步。
</li>
<li>
<strong>消息通知:</strong>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
<strong>消息通知:</strong
>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
</li>
<li>
<strong>实时监听:</strong>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
<strong>实时监听:</strong
>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
</li>
<li>
<strong>微应用接入:</strong>微应用通过 props 接收 actions,可以调用
......
......@@ -14,8 +14,8 @@
"paths": {
"@/*": ["src/*"]
},
"typeRoots": ["../../node_modules/@types", "./node_modules/@types"],
"resolveJsonModule": true,
"typeRoots": ["../../node_modules/@types", "./node_modules/@types"],
"allowImportingTsExtensions": true,
"allowJs": true,
......
......@@ -19,7 +19,7 @@ let app: null | VueApp<Element> = null;
let router: any = null;
// 存储 qiankun 传递的 props,供组件使用
export let qiankunProps: QiankunProps | null = null;
export let qiankunProps: null | QiankunProps = null;
/**
* 渲染函数
......@@ -27,7 +27,7 @@ export let qiankunProps: QiankunProps | null = null;
*/
async function render(props: QiankunProps = {}) {
const { container } = props;
// 存储 props 供组件使用
qiankunProps = props;
......
......@@ -11,15 +11,15 @@
"type-check": "vue-tsc --noEmit"
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@venus/tailwind-config": "workspace:*",
"@vueuse/core": "catalog:",
"axios": "catalog:",
"element-plus": "^2.9.1",
"@element-plus/icons-vue": "^2.3.1",
"pinia": "catalog:",
"tailwindcss": "catalog:",
"vue": "catalog:",
"vue-router": "catalog:",
"tailwindcss": "catalog:"
"vue-router": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
......
import postcssConfig from '@venus/tailwind-config/postcss';
export default postcssConfig;
export { default } from '@venus/tailwind-config/postcss';
......@@ -7,19 +7,20 @@ onMounted(() => {
</script>
<template>
<main class="app-main">
<router-view v-slot="{ Component }">
<transition name="fade" mode="out-in">
<component :is="Component" />
</transition>
</router-view>
</main>
<main class="app-main">
<router-view v-slot="{ Component }">
<transition name="fade" mode="out-in">
<component :is="Component" />
</transition>
</router-view>
</main>
</template>
<style scoped>
.app-main {
flex: 1;
}
/* 路由过渡动画 */
.fade-enter-active,
.fade-leave-active {
......
......@@ -4,18 +4,17 @@ import type { App as VueApp } from 'vue';
import { createApp } from 'vue';
import ElementPlus from 'element-plus';
import { createPinia } from 'pinia';
import {
qiankunWindow,
renderWithQiankun,
} from 'vite-plugin-qiankun/dist/helper';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import App from './App.vue';
import { createRouter } from './router';
import 'element-plus/dist/index.css';
import './style.css';
let app: null | VueApp<Element> = null;
......
......@@ -28,6 +28,14 @@ const routes: RouteRecordRaw[] = [
},
},
{
path: '/manageagentic',
name: 'ManageAgentic',
component: () => import('@/views/ManageAgentic/index.vue'),
meta: {
title: '智能体管理',
},
},
{
path: '/assistant/add',
name: 'AssistantAdd',
component: () => import('@/views/Assistant/add.vue'),
......
......@@ -91,7 +91,6 @@ class SubAppCommunicationManager {
if (props.onGlobalStateChange) {
const unsubscribeFn = props.onGlobalStateChange(
(state: GlobalState, prev: GlobalState) => {
// 缓存当前状态
this.currentState = state;
......@@ -165,7 +164,7 @@ class SubAppCommunicationManager {
setGlobalState(state: Partial<GlobalState>) {
if (this.props?.setGlobalState) {
this.props.setGlobalState(state);
}
}
}
}
......
<script setup>
import { ref, reactive, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { Plus } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { computed, onMounted, reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter()
import { Plus } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
const router = useRouter();
// --- 1. 状态定义 ---
const loading = ref(false)
const selectedIds = ref([])
const loading = ref(false);
const selectedIds = ref([]);
// 搜索表单
const searchForm = reactive({
name: '',
status: '' // 空字符串代表全部,true/false代表具体状态
})
status: '', // 空字符串代表全部,true/false代表具体状态
});
// 分页配置
const pagination = reactive({
currentPage: 1,
pageSize: 10
})
pageSize: 10,
});
// 原始数据(模拟数据库)
const allData = ref([])
const allData = ref([]);
// --- 2. 模拟数据生成 ---
const initMockData = () => {
......@@ -31,122 +32,125 @@ const initMockData = () => {
{ name: '销售顾问AI', department: '深圳旗舰店销售部', status: true },
{ name: '客服助手', department: '客户服务中心', status: true },
{ name: '培训导师', department: '人力资源部', status: false },
]
const list = []
];
const list = [];
for (let i = 0; i < 101; i++) {
const template = baseData[i % 3]
const template = baseData[i % 3];
list.push({
id: i + 1,
name: `${template.name} ${i + 1}`, // 加上序号区分
department: template.department,
createTime: '2025-10-25 10:30:00',
status: i % 5 === 0 ? false : true, // 随机一些状态
statusLoading: false
})
status: i % 5 !== 0, // 随机一些状态
statusLoading: false,
});
}
allData.value = list
}
allData.value = list;
};
onMounted(() => {
initMockData()
})
initMockData();
});
// --- 3. 数据处理逻辑 (前端模拟后端查询) ---
// 经过搜索过滤后的总数据
const filteredData = computed(() => {
return allData.value.filter(item => {
const matchName = item.name.includes(searchForm.name)
const matchStatus = searchForm.status === '' || item.status === searchForm.status
return matchName && matchStatus
})
})
return allData.value.filter((item) => {
const matchName = item.name.includes(searchForm.name);
const matchStatus =
searchForm.status === '' || item.status === searchForm.status;
return matchName && matchStatus;
});
});
// 过滤后的总条数
const filteredTotal = computed(() => filteredData.value.length)
const filteredTotal = computed(() => filteredData.value.length);
// 当前页显示的数据(切片)
const currentPageData = computed(() => {
const start = (pagination.currentPage - 1) * pagination.pageSize
const end = start + pagination.pageSize
return filteredData.value.slice(start, end)
})
const start = (pagination.currentPage - 1) * pagination.pageSize;
const end = start + pagination.pageSize;
return filteredData.value.slice(start, end);
});
// --- 4. 事件处理 ---
// 查询
const handleSearch = () => {
pagination.currentPage = 1 // 查询时重置到第一页
ElMessage.success('查询成功')
}
pagination.currentPage = 1; // 查询时重置到第一页
ElMessage.success('查询成功');
};
// 重置
const handleReset = () => {
searchForm.name = ''
searchForm.status = ''
pagination.currentPage = 1
ElMessage.info('已重置搜索条件')
}
searchForm.name = '';
searchForm.status = '';
pagination.currentPage = 1;
ElMessage.info('已重置搜索条件');
};
// 表格多选
const handleSelectionChange = (selection) => {
selectedIds.value = selection.map(item => item.id)
}
selectedIds.value = selection.map((item) => item.id);
};
// 状态切换
const handleStatusChange = (row) => {
row.statusLoading = true
row.statusLoading = true;
// 模拟API请求延迟
setTimeout(() => {
row.statusLoading = false
ElMessage.success(`${row.name} 状态已更新为:${row.status ? '启用' : '禁用'}`)
}, 500)
}
row.statusLoading = false;
ElMessage.success(
`${row.name} 状态已更新为:${row.status ? '启用' : '禁用'}`,
);
}, 500);
};
// 新增
const handleAdd = () => {
router.push('/assistant/add')
}
router.push('/assistant/add');
};
// 编辑
const handleEdit = (row) => {
router.push(`/assistant/edit/${row.id}`)
}
router.push(`/assistant/edit/${row.id}`);
};
// 分页事件
const handleSizeChange = (val) => {
pagination.pageSize = val
pagination.currentPage = 1
}
pagination.pageSize = val;
pagination.currentPage = 1;
};
const handleCurrentChange = (val) => {
pagination.currentPage = val
}
pagination.currentPage = val;
};
</script>
<template>
<div class="p-5 bg-white min-h-screen">
<div class="min-h-screen bg-white p-5">
<!-- 1. 顶部标题 -->
<h2 class="text-lg font-semibold mb-5 text-[#303133]">岗位助理配置</h2>
<h2 class="mb-5 text-lg font-semibold text-[#303133]">岗位助理配置</h2>
<!-- 2. 搜索区域 -->
<div class="mb-5">
<el-form :inline="true" :model="searchForm" class="search-form">
<el-form-item label="智能体名称">
<el-input
v-model="searchForm.name"
placeholder="请输入"
clearable
<el-input
v-model="searchForm.name"
placeholder="请输入"
clearable
style="width: 220px"
@keyup.enter="handleSearch"
/>
</el-form-item>
<el-form-item label="状态">
<el-select
v-model="searchForm.status"
placeholder="全部"
clearable
<el-select
v-model="searchForm.status"
placeholder="全部"
clearable
style="width: 220px"
>
<el-option label="全部" value="" />
......@@ -162,12 +166,14 @@ const handleCurrentChange = (val) => {
</div>
<!-- 3. 操作栏 (左侧选中统计,右侧新增按钮) -->
<div class="flex justify-between items-center mb-4">
<div class="mb-4 flex items-center justify-between">
<div class="left-panel">
<span class="text-sm text-[#909399]">已选 {{ selectedIds.length }} 项</span>
</div>
<div class="right-panel">
<el-button type="primary" :icon="Plus" @click="handleAdd">新增智能体</el-button>
<el-button type="primary" :icon="Plus" @click="handleAdd">
新增智能体
</el-button>
</div>
</div>
......@@ -180,13 +186,13 @@ const handleCurrentChange = (val) => {
v-loading="loading"
>
<el-table-column type="selection" width="55" />
<el-table-column prop="name" label="智能体名称" min-width="150" />
<el-table-column prop="department" label="岗位关联" min-width="180" />
<el-table-column prop="createTime" label="创建时间" min-width="180" />
<el-table-column label="状态" min-width="120">
<template #default="scope">
<div class="flex items-center gap-2.5">
......@@ -194,24 +200,32 @@ const handleCurrentChange = (val) => {
v-model="scope.row.status"
:loading="scope.row.statusLoading"
@change="handleStatusChange(scope.row)"
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
style="
--el-switch-on-color: #13ce66;
--el-switch-off-color: #ff4949;
"
/>
<span class="text-sm" :class="scope.row.status ? 'text-[#303133]' : 'text-[#909399]'">
<span
class="text-sm"
:class="scope.row.status ? 'text-[#303133]' : 'text-[#909399]'"
>
{{ scope.row.status ? '启用' : '禁用' }}
</span>
</div>
</template>
</el-table-column>
<el-table-column label="操作" width="100" fixed="right">
<template #default="scope">
<el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>
<el-button link type="primary" @click="handleEdit(scope.row)">
编辑
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 5. 分页区域 -->
<div class="mt-5 flex justify-between items-center">
<div class="mt-5 flex items-center justify-between">
<div class="text-sm text-[#606266]">共 {{ filteredTotal }} 项数据</div>
<el-pagination
v-model:current-page="pagination.currentPage"
......@@ -229,7 +243,7 @@ const handleCurrentChange = (val) => {
<style scoped>
/* Element Plus 表单项样式覆盖 - 使用 !important 确保优先级 */
.search-form :deep(.el-form-item) {
margin-bottom: 0;
margin-right: 20px;
margin-bottom: 0;
}
</style>
......@@ -80,7 +80,7 @@ const sendNotification = async () => {
// 清空表单
notificationForm.title = '';
notificationForm.message = '';
} catch (error) {
} catch {
addLog('error', '发送通知失败');
}
};
......@@ -136,7 +136,7 @@ onMounted(async () => {
});
addLog('init', '通信管理器初始化成功');
} catch (error) {
} catch {
addLog('error', '通信管理器初始化失败');
}
}
......@@ -161,9 +161,7 @@ onMounted(async () => {
<h3>独立模式运行</h3>
<p>当前子应用运行在独立模式下,通信功能不可用。</p>
<p>
请通过基座访问以体验完整的通信功能:<code
>http://localhost:8080/subapp-vue/communication</code
>
请通过基座访问以体验完整的通信功能:<code>http://localhost:8080/subapp-vue/communication</code>
</p>
</div>
</div>
......
<template>
<div class="mx-auto max-w-6xl space-y-12 pb-20">
<!-- 1. 智能体概况 -->
<section>
<SectionTitle title="智能体概况" />
<div
class="mt-4 flex gap-5 rounded-lg border border-gray-100 bg-[#fafafa] p-6"
>
<div
class="flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-[#2ccdce] text-white shadow-sm"
>
<ChatDotRound class="h-7 w-7" />
</div>
<div>
<div class="mb-2 flex items-center gap-2">
<h2 class="text-lg font-bold text-gray-900">对练智能体</h2>
<span class="text-sm font-light text-gray-500"
>销售和客服对话训练</span
>
</div>
<p class="text-justify text-sm leading-relaxed text-gray-600">
对练智能体是一个专业的对话训练助手,能够模拟不同类型的客户角色,帮助销售人员和客服人员提升沟通技巧、产品介绍能力和问题解决能力。通过与智能体的反复练习,员工可以在实际工作中更加从容应对各种客户场景。
</p>
</div>
</div>
</section>
<!-- 2. 工作流程 -->
<section>
<SectionTitle title="工作流程" />
<div class="mt-6 pl-2">
<div class="relative space-y-8">
<!-- 连接线 -->
<div
class="absolute bottom-4 left-[15px] top-4 -z-10 w-0.5 bg-gray-200"
></div>
<div
v-for="(step, idx) in steps"
:key="idx"
class="group flex items-start gap-6"
>
<!-- 序号球 -->
<div
class="z-10 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[#e8f3ff] text-sm font-bold text-[#165dff] ring-4 ring-white"
>
{{ idx + 1 }}
</div>
<!-- 内容 -->
<div class="pt-1">
<h3 class="mb-1 text-base font-medium text-gray-900">
{{ step.title }}
</h3>
<p class="text-sm text-gray-500">{{ step.desc }}</p>
</div>
</div>
</div>
</div>
</section>
<!-- 3. 客户角色类型 -->
<section>
<SectionTitle title="客户角色类型" />
<div
class="mt-6 grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3"
>
<div
v-for="(role, idx) in roles"
:key="idx"
class="flex cursor-default items-start gap-4 rounded-xl border border-gray-100 bg-white p-5 transition-all duration-300 hover:border-blue-100 hover:shadow-lg"
>
<!-- 头像 (使用 Unsplash 随机商务人像) -->
<div class="relative shrink-0">
<img
:src="role.avatar"
class="h-12 w-12 rounded-lg bg-gray-200 object-cover shadow-sm"
alt="Avatar"
/>
</div>
<div>
<h4 class="mb-2 text-[15px] font-bold text-gray-900">
{{ role.name }}
</h4>
<p class="text-xs leading-relaxed text-gray-500">
{{ role.desc }}
</p>
</div>
</div>
</div>
</section>
<!-- 4. 核心功能 -->
<section>
<SectionTitle title="核心功能" />
<div
class="mt-6 grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-4"
>
<div
v-for="(feature, idx) in features"
:key="idx"
class="group flex flex-col overflow-hidden rounded-2xl border border-gray-100 bg-[#fcfcfc] transition-all duration-300 hover:shadow-lg"
>
<!-- 顶部示意图区域 (CSS 模拟 UI) -->
<div
class="relative flex h-32 items-center justify-center overflow-hidden bg-gradient-to-b from-blue-50 to-[#fcfcfc] p-4"
>
<!-- 装饰圆圈/方块 -->
<div
class="absolute left-0 top-0 h-full w-full bg-[radial-gradient(#3b82f6_1px,transparent_1px)] opacity-30 [background-size:16px_16px]"
></div>
<!-- 模拟的 UI 组件 -->
<div
class="relative z-10 flex w-full max-w-[140px] transform items-center justify-center gap-3 rounded-xl border border-white bg-white/80 p-3 shadow-sm backdrop-blur-sm transition-transform duration-500 group-hover:scale-105"
>
<component :is="feature.icon" class="h-8 w-8 text-blue-500" />
<div class="flex-1 space-y-1.5">
<div class="h-2 w-3/4 rounded-full bg-blue-100"></div>
<div class="h-2 w-full rounded-full bg-gray-100"></div>
</div>
</div>
</div>
<!-- 文本区域 -->
<div class="p-5 pt-2">
<h4 class="mb-3 text-[15px] font-bold text-gray-900">
{{ feature.title }}
</h4>
<ul class="space-y-1">
<li
v-for="(txt, i) in feature.points"
:key="i"
class="flex items-start text-xs leading-5 text-gray-500"
>
<span class="mr-1.5 scale-150 transform text-blue-500"
>•</span
>
{{ txt }}
</li>
</ul>
</div>
</div>
</div>
</section>
</div>
</template>
<script setup>
import {
ChatDotRound,
Cpu,
DataAnalysis,
Monitor,
Notebook,
Reading,
TrendCharts,
UserFilled,
} from '@element-plus/icons-vue';
// 简单的标题组件
const SectionTitle = {
props: ['title'],
template: `
<div class="flex items-center gap-2">
<div class="w-1 h-4 bg-[#165dff] rounded-full"></div>
<h2 class="text-base font-bold text-gray-900">{{ title }}</h2>
</div>
`,
};
// 数据源:步骤
const steps = [
{
title: '外部指令输入',
desc: '支持输入对练主题、产品信息、客户画像等指令,智能体根据指令生成相应的对话场景',
},
{
title: '对练目标设定',
desc: '可设置具体的训练目标,如产品介绍、异议处理、促成交易等,智能体据此调整对话策略',
},
{
title: '通过标准设定',
desc: '系统内置练习通过标准,包括对话流畅度、产品知识准确性、应对技巧等多维度评估',
},
{
title: '会话场景生成',
desc: '智能体自动生成符合设定目标的对话场景,包括初始问题、常见异议和特殊情况',
},
{
title: '移动端H5练习',
desc: '员工可在移动端H5页面进行对话练习,获得即时反馈和改进建议',
},
];
// 数据源:角色 (头像使用在线占位符)
const roles = [
{
name: '独裁型客户',
desc: '具有强烈的控制欲,决策迅速,注重效率,对产品细节要求高',
avatar:
'https://images.unsplash.com/photo-1560250097-0b93528c311a?w=100&h=100&fit=crop',
},
{
name: '人际型客户',
desc: '注重人际关系,友好健谈,容易建立信任,但决策可能受情感影响',
avatar:
'https://images.unsplash.com/photo-1573496359-07742d95c2b0?w=100&h=100&fit=crop',
},
{
name: '犹豫型客户',
desc: '顾虑较多,决策缓慢,需要更多的产品信息和客户见证',
avatar:
'https://images.unsplash.com/photo-1580489944761-15a19d654956?w=100&h=100&fit=crop',
},
{
name: '沉默型客户',
desc: '不善言辞,需要引导,决策谨慎,注重产品可靠性和口碑',
avatar:
'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=100&h=100&fit=crop',
},
{
name: '分析型客户',
desc: '理性思考,注重数据和事实,决策过程长,需要充分的信息支持',
avatar:
'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=100&h=100&fit=crop',
},
{
name: '价格型客户',
desc: '对价格敏感,追求性价比,注重产品优惠和折扣',
avatar:
'https://images.unsplash.com/photo-1633332755192-727a05c4013d?w=100&h=100&fit=crop',
},
];
// 数据源:核心功能
const features = [
{
title: '岗位助理配置',
points: ['无需复杂配置,可直接与岗位助理系统对接,自动获取相关岗位信息'],
icon: UserFilled,
},
{
title: '智能体编排',
points: [
'支持与其他智能体协同工作,如培训智能体、质检智能体等,形成完整的训练体系',
],
icon: Cpu,
},
{
title: '实时反馈',
points: ['提供即时的对话分析和改进建议,帮助员工快速提升技能'],
icon: DataAnalysis,
},
{
title: '学习记录追踪',
points: ['记录员工的训练历史和进步情况,生成学习报告和能力评估'],
icon: Notebook,
},
];
</script>
<style scoped>
</style>
<template>
<div class="min-h-screen bg-white text-gray-800 font-sans p-6">
<div class="max-w-7xl mx-auto space-y-10">
<!-- ================= 1. 智能体概况 (Agent Overview) ================= -->
<section>
<!-- 标题头 -->
<div class="flex items-center mb-4">
<div class="w-1 h-4 bg-blue-600 rounded-sm mr-2"></div>
<h2 class="text-lg font-bold text-gray-900">智能体概况</h2>
</div>
<!-- 卡片内容 -->
<div class="bg-gray-50/50 border border-gray-100 rounded-lg p-6 flex items-start shadow-sm hover:shadow-md transition-shadow">
<!-- 图标 (使用 SVG 模拟设计图中的盾牌图标) -->
<div class="flex-shrink-0 mr-4">
<div class="w-12 h-12 bg-blue-500 rounded-full flex items-center justify-center text-white shadow-blue-200 shadow-lg">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12c0 1.268-.63 2.39-1.593 3.068a3.745 3.745 0 01-1.043 3.296 3.745 3.745 0 01-3.296 1.043A3.745 3.745 0 0112 21c-1.268 0-2.39-.63-3.068-1.593a3.746 3.746 0 01-3.296-1.043 3.745 3.745 0 01-1.043-3.296A3.745 3.745 0 013 12c0-1.268.63-2.39 1.593-3.068a3.745 3.745 0 011.043-3.296 3.746 3.746 0 013.296-1.043A3.746 3.746 0 0112 3c1.268 0 2.39.63 3.068 1.593a3.746 3.746 0 013.296 1.043 3.746 3.746 0 011.043 3.296A3.745 3.745 0 0121 12z" />
</svg>
</div>
</div>
<!-- 文本内容 -->
<div>
<div class="flex items-center space-x-2 mb-1">
<h3 class="text-base font-bold text-gray-900">质检智能体</h3>
<span class="text-sm text-gray-400 font-normal">对话质量检测和评估</span>
</div>
<p class="text-sm text-gray-500 leading-relaxed max-w-4xl">
质检智能体是一个专业的对话质量评估工具,能够对客服和销售人员的对话进行多维度分析,识别话术合规性、服务态度、专业知识等方面的问题,并提供改进建议,帮助企业提升整体服务质量。
</p>
</div>
</div>
</section>
<!-- ================= 2. 工作流程 (Workflow) ================= -->
<section>
<div class="flex items-center mb-6">
<div class="w-1 h-4 bg-blue-600 rounded-sm mr-2"></div>
<h2 class="text-lg font-bold text-gray-900">工作流程</h2>
</div>
<div class="pl-2">
<div v-for="(step, index) in workflowSteps" :key="index" class="relative pb-8 last:pb-0">
<!-- 连接线 -->
<div v-if="index !== workflowSteps.length - 1" class="absolute top-8 left-3.5 -ml-px h-full w-0.5 bg-gray-200" aria-hidden="true"></div>
<div class="relative flex items-start group">
<!-- 步骤数字 -->
<span class="h-7 w-7 flex items-center justify-center rounded-full bg-blue-50 border border-blue-100 ring-4 ring-white">
<span class="text-blue-600 text-sm font-bold">{{ index + 1 }}</span>
</span>
<!-- 步骤内容 -->
<div class="ml-4 min-w-0 flex-1">
<h4 class="text-sm font-medium text-gray-900 mb-1">{{ step.title }}</h4>
<p class="text-sm text-gray-400">{{ step.desc }}</p>
</div>
</div>
</div>
</div>
</section>
<!-- ================= 3. 质检规则管理 (Rule Management) ================= -->
<section>
<div class="flex items-center mb-4">
<div class="w-1 h-4 bg-blue-600 rounded-sm mr-2"></div>
<h2 class="text-lg font-bold text-gray-900">质检规则管理</h2>
</div>
<!-- 表格工具栏 -->
<div class="flex justify-between items-center mb-4 bg-white">
<span class="text-sm text-gray-500">已选 0 项</span>
<el-button type="primary" :icon="Plus">创建规则</el-button>
</div>
<!-- 规则表格 -->
<el-table
:data="rulesData"
style="width: 100%"
:header-cell-style="{ background: '#f5f7fa', color: '#606266', fontWeight: '500' }"
class="custom-table mb-4"
>
<!-- 这里的多选框为了还原 UI 暂时隐藏,如需要可添加 type="selection" -->
<el-table-column prop="name" label="规则名称" min-width="150" />
<el-table-column prop="desc" label="描述" min-width="400" />
<el-table-column label="操作" width="150" align="right">
<template #default>
<el-button link type="primary">编辑</el-button>
<el-button link type="primary">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<div class="flex justify-between items-center text-gray-500 text-sm">
<span>共 101 项数据</span>
<el-pagination
v-model:current-page="rulesPage.current"
v-model:page-size="rulesPage.size"
:page-sizes="[5, 10, 20]"
layout="sizes, prev, pager, next, slot, jumper"
:total="101"
background
>
<template #default>
<span class="ml-2">页</span>
</template>
</el-pagination>
</div>
</section>
<!-- ================= 4. 质检模板管理 (Template Management) ================= -->
<section>
<div class="flex items-center mb-4">
<div class="w-1 h-4 bg-blue-600 rounded-sm mr-2"></div>
<h2 class="text-lg font-bold text-gray-900">质检模板管理</h2>
</div>
<!-- 模板工具栏 -->
<div class="flex justify-between items-center mb-4">
<span class="text-sm text-gray-500">已选 0 项</span>
<el-button type="primary" :icon="Plus">创建模板</el-button>
</div>
<!-- 模板表格 -->
<el-table
:data="templatesData"
style="width: 100%"
:header-cell-style="{ background: '#f5f7fa', color: '#606266', fontWeight: '500' }"
class="custom-table mb-4"
>
<el-table-column prop="name" label="模板名称" min-width="150" />
<el-table-column prop="desc" label="描述" min-width="400" />
<el-table-column label="操作" width="150" align="right">
<template #default>
<el-button link type="primary">编辑</el-button>
<el-button link type="primary">删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 (为了还原视觉,这里保持与上面一致) -->
<div class="flex justify-between items-center text-gray-500 text-sm">
<span>共 101 项数据</span>
<el-pagination
v-model:current-page="templatePage.current"
v-model:page-size="templatePage.size"
:page-sizes="[10, 20, 30]"
layout="sizes, prev, pager, next, slot, jumper"
:total="101"
background
>
<template #default>
<span class="ml-2">页</span>
</template>
</el-pagination>
</div>
</section>
</div>
</div>
</template>
<script setup lang="ts">
import { reactive } from 'vue';
import { Plus } from '@element-plus/icons-vue';
// --- 数据部分 ---
// 1. 工作流程数据
const workflowSteps = [
{
title: '接收录音文件',
desc: '系统接收客服或销售与客户的通话录音文件,支持多种音频格式'
},
{
title: '文字转义',
desc: '将录音内容自动转换为文字,提取关键信息和对话要点'
},
{
title: '指定质检模板',
desc: '根据业务需求选择或创建适合的质检模板,设定评估维度和标准'
},
{
title: '输出质检结果',
desc: '智能分析对话内容,生成详细的质检报告,包括得分、问题点和改进建议'
}
];
// 2. 规则管理数据
const rulesData = [
{
name: '开场白完整性',
desc: '检查客服是否使用标准开场白,包含问候语、自我介绍和服务意愿'
},
{
name: '产品信息准确性',
desc: '检查客服提供的产品信息是否准确,无错误或误导性描述'
},
{
name: '服务态度评分',
desc: '评估客服在对话中的语气、用词和耐心程度'
}
];
const rulesPage = reactive({
current: 1,
size: 5
});
// 3. 模板管理数据
const templatesData = [
{
name: '标准客服对话模板',
desc: '日常客户咨询服务'
},
{
name: '销售转化模板',
desc: '产品销售场景'
}
];
const templatePage = reactive({
current: 1,
size: 10
});
</script>
<style scoped>
/*
自定义 Element Plus 样式覆盖
用于精细还原设计图中的线条和间距
*/
:deep(.el-table) {
--el-table-header-bg-color: #f5f7fa;
--el-table-border-color: #ebeef5;
}
:deep(.el-table th.el-table__cell) {
padding: 12px 0;
}
:deep(.el-button--primary) {
--el-button-bg-color: #2563eb; /* Tailwind blue-600 */
--el-button-border-color: #2563eb;
}
:deep(.el-button--primary:hover) {
--el-button-bg-color: #1d4ed8; /* Tailwind blue-700 */
--el-button-border-color: #1d4ed8;
}
/* 链接按钮样式调整 */
:deep(.el-button.is-link) {
padding: 0 8px;
font-weight: normal;
}
/* 分页样式微调 */
:deep(.el-pagination) {
--el-pagination-font-size: 13px;
font-weight: normal;
}
:deep(.el-input__wrapper) {
box-shadow: 0 0 0 1px #dcdfe6 inset;
}
</style>
<template>
<div>
<h1>复盘智能体</h1>
</div>
</template>
<script setup>
</script>
<style scoped>
</style>
<template>
<div>
<h1>培训智能体</h1>
</div>
</template>
<script setup>
</script>
<style scoped>
</style>
<script setup>
import { ref } from 'vue';
import {
ChatDotRound,
Cpu,
DataAnalysis,
Monitor,
Notebook,
Reading,
TrendCharts,
UserFilled,
} from '@element-plus/icons-vue';
import AgenticQuality from './components/agenticQuality.vue';
import AgenticPractice from './components/agenticPractice.vue';
import AgenticReplay from './components/agenticReplay.vue';
import AgenticTrain from './components/agenticTrain.vue';
// 状态
const activeMenu = ref(1);
// 数据源:侧边栏
const sidebarItems = [
{
icon: Monitor,
title: '质检智能体',
desc: '对话质量检测和评估',
color: 'bg-blue-500',
activeColor: 'bg-blue-500',
},
{
icon: ChatDotRound,
title: '对练智能体',
desc: '销售和客服对话训练',
color: 'bg-[#2ccdce]',
activeColor: 'bg-[#2ccdce]',
},
{
icon: TrendCharts,
title: '复盘智能体',
desc: '对话过程分析和总结',
color: 'bg-orange-400',
activeColor: 'bg-orange-400',
},
{
icon: Reading,
title: '培训智能体',
desc: '员工产品知识培训',
color: 'bg-indigo-500',
activeColor: 'bg-indigo-500',
},
];
</script>
<template>
<div class="flex h-screen w-full bg-[#fcfcfc] text-[#1d2129]">
<!-- 左侧侧边栏 -->
<aside
class="flex h-full w-[280px] flex-shrink-0 flex-col border-r border-gray-100 bg-white"
>
<div class="p-6">
<h1 class="text-lg font-bold tracking-wide text-gray-900">
智能体管理
</h1>
</div>
<div class="flex-1 space-y-2 overflow-y-auto px-4">
<div class="px-4 py-2 text-sm text-gray-500">智能体列表</div>
<div
v-for="(item, index) in sidebarItems"
:key="index"
@click="activeMenu = index"
class="group flex cursor-pointer items-center rounded-xl p-4 transition-all duration-200"
:class="activeMenu === index ? 'bg-[#eef6ff]' : 'hover:bg-gray-50'"
>
<!-- 图标容器 -->
<div
class="mr-4 flex h-10 w-10 shrink-0 items-center justify-center rounded-full transition-colors"
:class="activeMenu === index ? item.activeColor : item.color"
>
<component :is="item.icon" class="h-5 w-5 text-white" />
</div>
<!-- 文本 -->
<div class="flex flex-col">
<span
class="mb-0.5 text-base font-medium"
:class="activeMenu === index ? 'text-gray-900' : 'text-gray-700'"
>
{{ item.title }}
</span>
<span class="text-xs font-light text-gray-400">{{
item.desc
}}</span>
</div>
</div>
</div>
</aside>
<!-- 右侧主要内容区 -->
<main class="h-full flex-1 overflow-y-auto scroll-smooth bg-white p-8">
<AgenticQuality v-if="activeMenu === 0" />
<AgenticPractice v-if="activeMenu === 1" />
<AgenticReplay v-if="activeMenu === 2" />
<AgenticTrain v-if="activeMenu === 3" />
</main>
</div>
</template>
<style>
/* 隐藏默认滚动条但保持可滚动,提升美观度 (可选) */
main::-webkit-scrollbar {
width: 6px;
}
main::-webkit-scrollbar-track {
background: transparent;
}
main::-webkit-scrollbar-thumb {
background-color: #e5e7eb;
border-radius: 20px;
}
</style>
import tailwindConfig from '@venus/tailwind-config';
export default tailwindConfig;
export { default } from '@venus/tailwind-config';
......@@ -16,6 +16,7 @@
},
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"allowJs": true,
/* Linting */
"strict": true,
......@@ -27,5 +28,12 @@
"skipLibCheck": true
},
"references": [{ "path": "./tsconfig.node.json" }],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
"include": [
"env.d.ts",
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"src/**/*.js"
]
}
/// <reference types="vite/client" />
// / <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue';
......@@ -26,19 +26,19 @@ declare module 'glsk-common' {
}
export class Http {
constructor(config: HttpConfig);
[key: string]: any;
constructor(config: HttpConfig);
}
}
declare module 'glsk-toolkit' {
export class Request {
[key: string]: any;
constructor(config: any);
post(url: string, data?: any, config?: any): Promise<any>;
delete(url: string, config?: any): Promise<any>;
get(url: string, config?: any): Promise<any>;
post(url: string, data?: any, config?: any): Promise<any>;
put(url: string, data?: any, config?: any): Promise<any>;
delete(url: string, config?: any): Promise<any>;
[key: string]: any;
}
}
......
......@@ -10,12 +10,12 @@
"type-check": "vue-tsc --noEmit"
},
"dependencies": {
"@venus/common-ui-vue": "workspace:*",
"@element-plus/icons-vue": "catalog:",
"glsk-toolkit": "catalog:",
"@venus/common-ui-vue": "workspace:*",
"@vueuse/core": "catalog:",
"axios": "catalog:",
"element-plus": "catalog:",
"glsk-toolkit": "catalog:",
"pinia": "catalog:",
"qiankun": "catalog:",
"vue": "catalog:",
......@@ -33,4 +33,3 @@
"vue-tsc": "catalog:"
}
}
<script setup lang="ts">
</script>
<script setup lang="ts"></script>
<template>
<div id="main-app">
......
export * from './route';
/**
* API 统一导出
*/
export * from './user';
export * from './route';
/**
* 路由和菜单相关 API
*/
import type { ApiResponse } from '@/types/api';
import type { MenuItem, TopMenuItem } from '@/types/menu';
import type { RouteRecordRaw } from 'vue-router';
const ROUTER_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
const ROUTER_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
// import { get } from '@/utils/request'; // 取消注释以使用真实 API
/**
......@@ -36,20 +37,20 @@ export interface RouteConfig {
export interface MenuConfig {
/** 顶部菜单列表 */
topMenus: Array<{
icon?: string;
id: string;
title: string;
path: string;
icon?: string;
sidebarMenus: Array<{
id: string;
title: string;
path: string;
children?: MenuConfig['topMenus'][0]['sidebarMenus'];
icon?: string;
id: string;
level?: number;
parentId?: string;
children?: MenuConfig['topMenus'][0]['sidebarMenus'];
meta?: MenuItem['meta'];
parentId?: string;
path: string;
title: string;
}>;
title: string;
}>;
/** 路由配置列表 */
routes: RouteConfig[];
......@@ -62,7 +63,7 @@ export interface MenuConfig {
export const getRouteConfig = async () => {
// TODO: 替换为实际的 API 端点
// 示例:return get<ApiResponse<MenuConfig>>('/api/routes/menus');
// 临时返回模拟数据,实际使用时需要替换为真实 API
// return Promise.resolve({
// code: 200,
......@@ -109,8 +110,8 @@ export function transformRouteConfig(config: RouteConfig): RouteRecordRaw {
* 将 API 返回的菜单配置转换为菜单格式
*/
export function transformMenuConfig(config: MenuConfig): {
topMenus: TopMenuItem[];
routes: RouteRecordRaw[];
topMenus: TopMenuItem[];
} {
const topMenus: TopMenuItem[] = config.topMenus.map((topMenu) => ({
id: topMenu.id,
......@@ -138,10 +139,7 @@ function transformSidebarMenus(
icon: menu.icon,
level: menu.level,
parentId: menu.parentId,
children: menu.children
? transformSidebarMenus(menu.children)
: undefined,
children: menu.children ? transformSidebarMenus(menu.children) : undefined,
meta: menu.meta,
}));
}
import gscPost from '@/config/gscrequest'
import gscPost from '@/config/gscrequest';
// 数据看板指标统计
export function getdataBoard(data: any) {
return gscPost("/dataBoard/indexs", data)
return gscPost('/dataBoard/indexs', data);
}
......@@ -33,8 +33,8 @@ const appStore = useAppStore();
.loading-content {
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
align-items: center;
}
.loading-spinner {
......@@ -72,4 +72,3 @@ const appStore = useAppStore();
opacity: 0;
}
</style>
......@@ -9,15 +9,17 @@ import { Request } from 'glsk-toolkit';
let baseConfig: any = {};
let routerConfig: any = {};
// GSC API 请求实例(模块级单例,不挂载到 window)
let gscApiInstance: Request | null = null;
let gscApiInstance: null | Request = null;
// 配置加载完成的 Promise
let configReadyPromise: Promise<void> | null = null;
let configReadyPromise: null | Promise<void> = null;
let configReadyResolve: (() => void) | null = null;
// 配置请求 URL
const CONFIG_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config';
const ROUTER_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
const CONFIG_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config';
const ROUTER_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
// 初始化配置就绪 Promise
function initConfigReadyPromise() {
......@@ -33,7 +35,7 @@ function initConfigReadyPromise() {
* 获取 GSC API 请求实例
* @returns Request 实例,如果未初始化则返回 null
*/
export function getGscApi(): Request | null {
export function getGscApi(): null | Request {
return gscApiInstance;
}
......@@ -58,7 +60,7 @@ export function waitForConfigReady(): Promise<void> {
export async function fetchConfig(): Promise<any> {
// 初始化配置就绪 Promise
initConfigReadyPromise();
try {
const response = await fetch(CONFIG_URL);
const result = await response.json();
......@@ -90,12 +92,12 @@ export async function fetchConfig(): Promise<any> {
// dsn: 'https://ace1d827739e4229887b78468bd8a385@sentry.glsx.com.cn/48'
// }
});
console.log('[配置中心] GSC API 实例创建成功:', gscApiInstance);
// 为了向后兼容,同时挂载到 window(可选,如果不需要可以删除)
// window.$gscApi = gscApiInstance;
// 通知配置已就绪
if (configReadyResolve) {
configReadyResolve();
......@@ -104,7 +106,7 @@ export async function fetchConfig(): Promise<any> {
} else {
console.warn('[配置中心] 未找到 GSC 配置,无法初始化 API 实例');
}
return configData;
} catch (error) {
console.error('[配置中心] 获取配置失败:', error);
......@@ -142,4 +144,3 @@ export function setConfig(config: any): void {
// 导出配置数据(只读)
export { baseConfig };
......@@ -5,13 +5,15 @@ import { getGscApi } from './center';
export const gscPost = (url: string, data: any, _config = {}) => {
const gscApi = getGscApi();
if (!gscApi) {
const error = new Error('[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成');
const error = new Error(
'[GSC请求] GSC API 实例未初始化,请确保配置中心已加载完成',
);
console.error(error);
return Promise.reject(error);
}
console.log('[GSC请求] 发起请求:', url, data);
return gscApi.post(url, data, _config);
};
......
......@@ -7,23 +7,19 @@ import type { MenuItem, TopMenuItem } from '@/types/menu';
*/
// 首页侧边栏菜单
export const homeMenus: MenuItem[] = [
];
export const homeMenus: MenuItem[] = [];
// Vue 微应用侧边栏菜单(多级嵌套示例)
// 支持一级、二级、三级菜单嵌套结构
// 注意:此配置仅作为后备方案,实际菜单将从 API 动态获取
export const vueAppMenus: MenuItem[] = [
];
export const vueAppMenus: MenuItem[] = [];
/**
* 默认顶部导航菜单配置
* 每个顶部菜单可以关联不同的侧边栏菜单
* 注意:实际菜单将从 API 动态获取,此配置仅作为后备方案
*/
export const defaultTopMenus: TopMenuItem[] = [
];
export const defaultTopMenus: TopMenuItem[] = [];
/**
* 根据路径获取对应的侧边栏菜单
......
<script setup lang="ts">
import type { BreadcrumbItem, MenuItem } from '@/types/menu';
import { computed, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { defaultTopMenus, getMenuParentPaths } from '@/config/menus';
import { microApps } from '@/qiankun/apps';
import { communicationManager } from '@/qiankun/communication';
import { useMenuStore } from '@/stores';
import { Download } from '@element-plus/icons-vue';
import Breadcrumb from './components/Breadcrumb.vue';
import NotificationCenter from './components/NotificationCenter.vue';
import SidebarMenuItem from './components/SidebarMenuItem.vue';
import UserInfo from './components/UserInfo.vue';
import { Download } from '@element-plus/icons-vue';
import { getMenuParentPaths, defaultTopMenus } from '@/config/menus';
import { microApps } from '@/qiankun/apps';
import { communicationManager } from '@/qiankun/communication';
import { useMenuStore } from '@/stores';
const router = useRouter();
const route = useRoute();
const menuStore = useMenuStore();
// 应用名称(从环境变量读取)
const appName ='汽车销售智能体';
const appName = '汽车销售智能体';
// 展开的菜单项 keys
const expandedKeys = ref<Set<string>>(new Set());
......@@ -57,7 +60,6 @@ const getActiveTopMenuId = (path: string): string => {
return '';
};
// 面包屑导航
const breadcrumbs = computed<BreadcrumbItem[]>(() => {
const crumbs: BreadcrumbItem[] = [{ title: '首页', path: '/home' }];
......@@ -65,8 +67,12 @@ const breadcrumbs = computed<BreadcrumbItem[]>(() => {
// 如果不在首页,添加当前路由的面包屑
if (route.path !== '/home' && route.path !== '/') {
const paths = getMenuParentPaths(allMenus.value, route.path);
console.log("路由调用", paths, menuStore.isMenusLoaded ? '动态菜单' : '默认菜单');
console.log(
'路由调用',
paths,
menuStore.isMenusLoaded ? '动态菜单' : '默认菜单',
);
// 根据路径找到对应的菜单项
paths.forEach((path) => {
const menu = findMenuByPath(allMenus.value, path);
......@@ -98,7 +104,6 @@ function findMenuByPath(menus: MenuItem[], path: string): MenuItem | null {
return null;
}
// 菜单点击事件
const handleMenuClick = (menu: MenuItem) => {
// 判断是否为微应用路由
......@@ -182,14 +187,15 @@ watch(
<aside class="layout-sidebar">
<!-- Logo和标题 -->
<div class="sidebar-header">
<div class="logo">
</div>
<div class="logo"></div>
<div class="title">{{ appName }}</div>
</div>
<div class="sidebar-menu">
<!-- 直接渲染所有侧边栏菜单,不显示 topMenus 分组标题 -->
<template v-for="topMenu in topMenus" :key="topMenu.id">
<template v-if="topMenu.sidebarMenus && topMenu.sidebarMenus.length > 0">
<template
v-if="topMenu.sidebarMenus && topMenu.sidebarMenus.length > 0"
>
<template v-for="item in topMenu.sidebarMenus" :key="item.id">
<SidebarMenuItem
:menu="item"
......@@ -213,7 +219,7 @@ watch(
</div>
<div class="header-right">
<div class="top-tools">
<el-icon size="16" style="margin-right: 6px;"><Download /></el-icon>
<el-icon size="16" style="margin-right: 6px"><Download /></el-icon>
<span>下载中心</span>
</div>
<NotificationCenter />
......@@ -223,7 +229,6 @@ watch(
<!-- 内容区域 -->
<section class="layout-content">
<!-- 微应用内容 -->
<div class="content-wrapper">
<router-view v-slot="{ Component, route: viewRoute }">
......@@ -258,22 +263,23 @@ watch(
flex-shrink: 0;
width: 228px;
overflow-y: auto;
background: #F7F8F9;
font-size: 14px;
background: #f7f8f9;
border-radius: 4px;
box-shadow: 0 2px 8px rgb(0 0 0 / 6%);
font-size: 14px;
.sidebar-header {
width: 228px;
height: 56px;
display: flex;
gap: 8px;
align-items: center;
color: #0d162a;
width: 228px;
height: 56px;
padding-left: 24px;
font-size: 20px;
font-weight: 600;
background: #FFFFFF;
color: #0d162a;
background: #fff;
border-right: 1px solid #f2f4f7;
padding-left: 24px;
}
}
......@@ -304,10 +310,6 @@ watch(
flex: 0 0 auto;
}
.logo {
}
.logo-icon {
font-size: 24px;
}
......@@ -361,7 +363,7 @@ watch(
}
.menu-group-title.active {
color: #1956FE;
color: #1956fe;
}
.group-icon {
......@@ -386,16 +388,17 @@ watch(
border-radius: 4px;
box-shadow: 0 2px 8px rgb(0 0 0 / 6%);
}
.top-tools {
position: relative;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16px;
font-size: 12px;
cursor: pointer;
border-radius: 50%;
transition: background-color 0.2s;
font-size: 12px;
margin-right: 16px;
}
/* 过渡动画 */
......
<script setup lang="ts">
import type { BreadcrumbItem } from '@/types/menu';
import { useRouter } from 'vue-router';
defineProps<{
......@@ -8,7 +9,11 @@ defineProps<{
const router = useRouter();
const handleBreadcrumbClick = (crumb: BreadcrumbItem, index: number, breadcrumbs: BreadcrumbItem[]) => {
const handleBreadcrumbClick = (
crumb: BreadcrumbItem,
index: number,
breadcrumbs: BreadcrumbItem[],
) => {
if (crumb.path && index < breadcrumbs.length - 1) {
router.push(crumb.path);
}
......@@ -27,10 +32,9 @@ const handleBreadcrumbClick = (crumb: BreadcrumbItem, index: number, breadcrumbs
>
{{ crumb.title }}
</span>
<span
v-if="index < breadcrumbs.length - 1"
class="breadcrumb-separator"
>/</span>
<span v-if="index < breadcrumbs.length - 1" class="breadcrumb-separator"
>/</span
>
</template>
</div>
</template>
......@@ -64,4 +68,3 @@ const handleBreadcrumbClick = (crumb: BreadcrumbItem, index: number, breadcrumbs
color: #999;
}
</style>
......@@ -84,7 +84,7 @@ onUnmounted(() => {
<div class="notification-badge" @click="togglePanel">
<!-- <span class="icon">🔔</span> -->
<span v-if="unreadCount > 0" class="badge">{{ unreadCount }}</span>
<el-icon size="16" style="margin-right: 6px;"><Bell /></el-icon>
<el-icon size="16" style="margin-right: 6px"><Bell /></el-icon>
<span>消息通知</span>
</div>
......@@ -116,9 +116,7 @@ onUnmounted(() => {
<div class="notification-title">{{ notification.title }}</div>
<div class="notification-message">{{ notification.message }}</div>
<div class="notification-meta">
<span v-if="notification.from" class="from"
>来自: {{ notification.from }}</span
>
<span v-if="notification.from" class="from">来自: {{ notification.from }}</span>
<span class="time">{{
formatTime(notification.timestamp)
}}</span>
......@@ -152,10 +150,10 @@ onUnmounted(() => {
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
cursor: pointer;
border-radius: 50%;
transition: background-color 0.2s;
font-size: 12px;
}
.notification-badge:hover {
......
......@@ -3,8 +3,9 @@ import type { MenuItem } from '@/types/menu';
import { computed } from 'vue';
import { ArrowDown, ArrowRight } from '@element-plus/icons-vue';
import SidebarMenuItem from './SidebarMenuItem.vue';
import { ArrowDown,ArrowRight } from '@element-plus/icons-vue';
interface Props {
menu: MenuItem;
......@@ -31,15 +32,18 @@ const isExpanded = computed(() => {
// 递归检查菜单或其子菜单是否激活
const checkMenuActive = (menu: MenuItem): boolean => {
// 当前菜单路径匹配
if (props.activePath === menu.path || props.activePath.startsWith(`${menu.path}/`)) {
if (
props.activePath === menu.path ||
props.activePath.startsWith(`${menu.path}/`)
) {
return true;
}
// 如果有子菜单,递归检查子菜单是否有激活的
if (menu.children && menu.children.length > 0) {
return menu.children.some((child) => checkMenuActive(child));
}
return false;
};
......@@ -75,13 +79,14 @@ const handleToggle = () => {
}"
@click="handleClick"
>
<!-- 菜单图标 -->
<span v-if="menu.icon && (menu.level == 1)" class="menu-icon">{{ menu.icon || '' }}</span>
<span v-if="menu.icon && menu.level == 1" class="menu-icon">{{
menu.icon || ''
}}</span>
<!-- 菜单标题 -->
<span class="menu-title">{{ menu.title }}</span>
<!-- 展开/收起图标 -->
<span v-if="hasChildren" class="expand-icon" @click.stop="handleToggle">
<el-icon v-if="isExpanded"><ArrowDown /></el-icon>
......@@ -123,12 +128,11 @@ const handleToggle = () => {
gap: 8px;
align-items: center;
padding: 8px 16px;
margin-top: 8px;
color: #333;
cursor: pointer;
user-select: none;
transition: all 0.3s;
margin-top: 8px;
}
/* 层级缩进 */
......@@ -152,12 +156,12 @@ const handleToggle = () => {
}
.menu-item-content:hover {
color: #1956FE;
color: #1956fe;
background-color: #f5f5f5;
}
.menu-item-content.active {
color: #1956FE;
color: #1956fe;
}
/* 一级菜单选中样式:仅改变文字颜色,无背景色和边框 */
......@@ -177,8 +181,8 @@ const handleToggle = () => {
.menu-item-content.level-2.active,
.menu-item-content.level-3.active,
.menu-item-content.level-4.active {
background-color: #e8f0ff;
border-radius: 6px;
background-color: #E8F0FF;
}
.menu-item-content.level-2.active::before,
......@@ -206,7 +210,7 @@ const handleToggle = () => {
width: 20px;
height: 20px;
font-size: 16px;
background: #1956FE;
background: #1956fe;
}
.menu-title {
......@@ -230,8 +234,8 @@ const handleToggle = () => {
}
.submenu {
overflow: hidden;
padding-left: 3px;
overflow: hidden;
}
/* 子菜单展开动画 */
......@@ -256,6 +260,7 @@ const handleToggle = () => {
/* 有子菜单的项目样式 */
.menu-item-content.has-children {
/* 样式已通过其他选择器定义 */
}
/* 二级菜单样式 */
......
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useUserStore } from '@/stores';
const router = useRouter();
const userStore = useUserStore();
......@@ -13,8 +15,8 @@ const showConfirmDialog = ref(false);
// 切换下拉菜单
const toggleDropdown = () => {
console.log("toggleDropdown");
console.log('toggleDropdown');
showDropdown.value = !showDropdown.value;
};
......@@ -201,42 +203,43 @@ onUnmounted(() => {
position: relative;
padding: 8px;
}
.user-info-card {
position: relative;
padding: 8px 12px;
display: flex;
justify-content: center;
align-items: center;
gap: 6px;
align-items: center;
justify-content: center;
padding: 8px 12px;
cursor: pointer;
border-radius: 6px;
transition: all 0.2s;
}
.user-info-card:hover {
background: rgba(0, 0, 0, 0.04);
background: rgb(0 0 0 / 4%);
}
.user-info-card .avatar {
flex-shrink: 0;
width: 28px;
height: 28px;
opacity: 1;
background: #e6efff;
border-radius: 50%;
flex-shrink: 0;
opacity: 1;
}
.user-info-card .name {
color: #777c85;
font-size: 12px;
color: #777c85;
white-space: nowrap;
}
.user-info-card .dropdown-icon {
flex-shrink: 0;
font-size: 10px;
color: #8c8c8c;
transition: transform 0.3s;
flex-shrink: 0;
}
.user-info:hover .dropdown-icon {
......@@ -312,11 +315,11 @@ onUnmounted(() => {
right: 0;
z-index: 1000;
min-width: 280px;
overflow: hidden;
background: white;
border-radius: 8px;
box-shadow: 0 8px 24px rgb(0 0 0 / 15%);
animation: dropdown-slide-in 0.2s ease-out;
overflow: hidden;
}
.dropdown-header {
......
......@@ -2,13 +2,14 @@ import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './App.vue';
import { getRouteConfig, transformMenuConfig } from './api/route';
import App from './App.vue';
import { fetchConfig, getConfig } from './config/center';
import { setupQiankun } from './qiankun';
import router, { addLayoutRoutes } from './router';
import { useAppStore, useMenuStore, useUserStore } from './stores';
import { getToken } from './utils/auth';
import './style.css';
// 创建应用实例
......@@ -29,19 +30,19 @@ app.use(router);
async function loadDynamicRoutes() {
try {
const menuStore = useMenuStore();
// 如果已经加载过,则不再重复加载
if (menuStore.isMenusLoaded) return;
// 调用 API 获取路由和菜单配置
const response = await getRouteConfig();
if (response.code === 200 && response.data) {
const { topMenus, routes } = transformMenuConfig(response.data);
// 更新菜单 store
menuStore.setTopMenus(topMenus);
// 动态添加路由到 Layout 的 children 中
if (routes.length > 0) {
addLayoutRoutes(routes);
......@@ -49,7 +50,10 @@ async function loadDynamicRoutes() {
}
}
} catch (error) {
console.error('[基座] 加载动态路由和菜单配置失败将使用默认菜单配置:', error);
console.error(
'[基座] 加载动态路由和菜单配置失败将使用默认菜单配置:',
error,
);
}
}
......@@ -104,7 +108,7 @@ function setupStoreSync() {
// 获取配置中心配置
fetchConfig()
.then((config) => {
console.log('[基座] 当前配置数据:', getConfig(),config);
console.log('[基座] 当前配置数据:', getConfig(), config);
})
.catch((error) => {
console.error('[基座] 配置中心配置获取失败:', error);
......@@ -125,4 +129,3 @@ fetchConfig()
});
});
});
import type { MicroAppConfig } from './types'; //微应用配置类型
import type { MicroAppConfig } from './types'; // 微应用配置类型
import { createSubAppAdapter } from './subAppAdapter'; //微应用统一通信适配器
import { createSubAppAdapter } from './subAppAdapter'; // 微应用统一通信适配器
/**
* 微应用配置列表
......@@ -10,14 +10,14 @@ export const microApps: MicroAppConfig[] = [
{
name: 'subapp-vue',
entry: getAppEntry('subapp-vue', 'http://192.168.1.93:8081'),
// entry: getAppEntry('subapp-vue', 'http://192.168.10.36:8081'),
// entry: getAppEntry('subapp-vue', 'http://192.168.10.36:8081'),
container: '#subapp-container',
activeRule: '/subapp-vue',
props: {
routerBase: '/subapp-vue',
communicationManager: createSubAppAdapter(),
},
}
},
];
/**
......
......@@ -69,11 +69,8 @@ export {
export { broadcast, communicationManager } from './communication';
export type { GlobalState, Notification } from './communication';
export { microAppLifecycles } from './lifecycles';
export * from './types';
export * from './utils';
// 导出子应用适配器相关类型和函数
export { createSubAppAdapter } from './subAppAdapter';
export type {
QiankunProps,
SubAppCommunicationManager,
} from './subAppAdapter';
export type { QiankunProps, SubAppCommunicationManager } from './subAppAdapter';
export * from './types';
export * from './utils';
import type { GlobalState, Notification } from './communication';
import { communicationManager } from './communication';
/**
......@@ -66,10 +67,36 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
private currentState: GlobalState | null = null;
private listeners: Array<(state: GlobalState, prev: GlobalState) => void> =
[];
private props: QiankunProps | null = null;
private props: null | QiankunProps = null;
private unsubscribe: (() => void) | null = null;
/**
* 销毁通信管理器
*/
destroy() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
}
this.listeners = [];
this.props = null;
this.currentState = null;
console.log('[子应用通信适配器] 通信管理器已销毁');
}
/**
* 获取当前全局状态
*/
getCurrentState(): GlobalState | null {
// 优先返回缓存的状态
if (this.currentState) {
return this.currentState;
}
// 如果没有缓存,从基座获取
return communicationManager.getGlobalState();
}
/**
* 初始化通信管理器
* @param props qiankun 传递的 props
*/
......@@ -119,18 +146,6 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
}
/**
* 获取当前全局状态
*/
getCurrentState(): GlobalState | null {
// 优先返回缓存的状态
if (this.currentState) {
return this.currentState;
}
// 如果没有缓存,从基座获取
return communicationManager.getGlobalState();
}
/**
* 监听全局状态变化
* @param callback 回调函数
* @returns 取消监听的函数
......@@ -142,9 +157,7 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
// 如果已经有缓存的状态,立即调用一次回调
if (this.currentState) {
console.log(
'[子应用通信适配器] 立即触发回调,使用缓存的全局状态',
);
console.log('[子应用通信适配器] 立即触发回调,使用缓存的全局状态');
callback(this.currentState, {} as GlobalState);
}
......@@ -157,22 +170,6 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
}
/**
* 设置全局状态(向基座发送数据)
* @param state 要更新的状态
*/
setGlobalState(state: Partial<GlobalState>) {
// 通过基座的通信管理器设置状态
communicationManager.setGlobalState(state);
// 同时通过 qiankun 的 props 设置(如果可用)
if (this.props?.setGlobalState) {
this.props.setGlobalState(state);
}
console.log('[子应用通信适配器] 全局状态已更新:', state);
}
/**
* 向基座发送通知
* @param notification 通知消息
*/
......@@ -185,17 +182,19 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
}
/**
* 销毁通信管理器
* 设置全局状态(向基座发送数据)
* @param state 要更新的状态
*/
destroy() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
setGlobalState(state: Partial<GlobalState>) {
// 通过基座的通信管理器设置状态
communicationManager.setGlobalState(state);
// 同时通过 qiankun 的 props 设置(如果可用)
if (this.props?.setGlobalState) {
this.props.setGlobalState(state);
}
this.listeners = [];
this.props = null;
this.currentState = null;
console.log('[子应用通信适配器] 通信管理器已销毁');
console.log('[子应用通信适配器] 全局状态已更新:', state);
}
}
......@@ -206,4 +205,3 @@ class SubAppCommunicationAdapter implements SubAppCommunicationManager {
export function createSubAppAdapter(): SubAppCommunicationManager {
return new SubAppCommunicationAdapter();
}
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import { getRouteConfig, transformMenuConfig } from '@/api/route';
import { getMicroAppByPath } from '@/qiankun/apps';
import { useAppStore, useMenuStore, useUserStore } from '@/stores';
......@@ -52,7 +54,7 @@ const routes: RouteRecordRaw[] = [
level: 2,
requiresAuth: true,
},
}
},
],
},
],
......@@ -82,7 +84,9 @@ const router = createRouter({
export function addRoutes(routes: RouteRecordRaw[], parentName?: string) {
if (parentName) {
// 添加到指定父路由的 children 中
const parentRoute = router.getRoutes().find((route) => route.name === parentName);
const parentRoute = router
.getRoutes()
.find((route) => route.name === parentName);
if (parentRoute) {
routes.forEach((route) => {
router.addRoute(parentName, route);
......@@ -122,7 +126,7 @@ async function loadDynamicRoutes() {
}
const menuStore = useMenuStore();
// 如果已经加载过,则不再重复加载
if (menuStore.isMenusLoaded) {
return;
......@@ -132,13 +136,13 @@ async function loadDynamicRoutes() {
isLoadingRoutes = true;
// 调用 API 获取路由和菜单配置
const response = await getRouteConfig();
if (response.code === 200 && response.data) {
const { topMenus, routes } = transformMenuConfig(response.data);
// 更新菜单 store
menuStore.setTopMenus(topMenus);
// 动态添加路由到 Layout 的 children 中
if (routes.length > 0) {
addLayoutRoutes(routes);
......@@ -146,7 +150,10 @@ async function loadDynamicRoutes() {
}
}
} catch (error) {
console.error('[路由守卫] 加载动态路由和菜单配置失败将使用默认菜单配置:', error);
console.error(
'[路由守卫] 加载动态路由和菜单配置失败将使用默认菜单配置:',
error,
);
} finally {
isLoadingRoutes = false;
}
......@@ -169,7 +176,7 @@ function isPossibleMicroAppPath(path: string): boolean {
async function waitForRoutesAndRematch(targetPath: string): Promise<boolean> {
const appStore = useAppStore();
const menuStore = useMenuStore();
// 如果已经加载过,检查路由是否匹配
if (menuStore.isMenusLoaded) {
const matchedRoutes = router.resolve(targetPath);
......@@ -182,14 +189,14 @@ async function waitForRoutesAndRematch(targetPath: string): Promise<boolean> {
try {
// 等待动态路由加载完成(loadDynamicRoutes 内部有防重复加载逻辑)
await loadDynamicRoutes();
// 等待一小段时间,确保路由已经添加到 router 中
await new Promise(resolve => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 100));
// 检查路由是否已存在
const matchedRoutes = router.resolve(targetPath);
const isMatched = matchedRoutes.name !== 'NotFound';
return isMatched;
} catch (error) {
console.error('[路由守卫] 等待动态路由加载失败:', error);
......@@ -217,25 +224,29 @@ router.beforeEach(async (to, _from, next) => {
const requiresAuth = to.meta.requiresAuth !== false;
// 如果匹配到404路由,检查是否是子应用路由
if (to.name === 'NotFound' && token) {
// 检查当前路径是否可能是子应用路由
if (isPossibleMicroAppPath(to.path)) {
console.log('[路由守卫] 检测到可能的子应用路由,等待动态路由加载:', to.path);
// 等待动态路由加载完成
const isMatched = await waitForRoutesAndRematch(to.path);
if (isMatched) {
// 路由已匹配,重新导航到目标路径
console.log('[路由守卫] 动态路由加载完成,重新导航到:', to.path);
next({ path: to.path, replace: true });
return;
} else {
// 确实不存在,显示404页面
console.log('[路由守卫] 动态路由加载完成,但路由不存在,显示404页面');
next();
return;
}
if (
to.name === 'NotFound' &&
token && // 检查当前路径是否可能是子应用路由
isPossibleMicroAppPath(to.path)
) {
console.log(
'[路由守卫] 检测到可能的子应用路由,等待动态路由加载:',
to.path,
);
// 等待动态路由加载完成
const isMatched = await waitForRoutesAndRematch(to.path);
if (isMatched) {
// 路由已匹配,重新导航到目标路径
console.log('[路由守卫] 动态路由加载完成,重新导航到:', to.path);
next({ path: to.path, replace: true });
return;
} else {
// 确实不存在,显示404页面
console.log('[路由守卫] 动态路由加载完成,但路由不存在,显示404页面');
next();
return;
}
}
......@@ -249,7 +260,7 @@ router.beforeEach(async (to, _from, next) => {
if (userStore.userInfo) {
// 确保动态路由已加载
await loadDynamicRoutes();
// 检查权限
if (to.meta.permissions || to.meta.roles) {
const hasPermission = checkPermission(to, userStore);
......@@ -284,7 +295,7 @@ router.beforeEach(async (to, _from, next) => {
}
next();
} catch (error) {
} catch {
// 获取用户信息失败,清除 token 并跳转到登录页
await userStore.logout();
next({
......
import type { MenuItem, TopMenuItem } from '@/types/menu';
import type { RouteRecordRaw } from 'vue-router';
import { ref } from 'vue';
......@@ -13,7 +14,7 @@ export const useMenuStore = defineStore('menu', () => {
// 动态菜单数据
const topMenus = ref<TopMenuItem[]>([]);
const dynamicRoutes = ref<RouteRecordRaw[]>([]);
// 是否已加载菜单
const isMenusLoaded = ref(false);
......@@ -73,4 +74,3 @@ export const useMenuStore = defineStore('menu', () => {
reset,
};
});
......@@ -71,7 +71,7 @@ export const useUserStore = defineStore('user', () => {
permissions.value = [];
roles.value = [];
removeToken();
console.log("退出");
console.log('退出');
// 同步清空 qiankun 全局状态中的用户信息
syncUserToQiankun();
}
......
// ==================== 样式入口文件 ====================
// 统一导出所有样式变量和 mixins
@import './variables';
@import './mixins';
@use './variables' as *;
@forward './variables';
@use './mixins' as *;
@forward './mixins';
@import './variables';
@use './variables' as *;
// ==================== Mixins ====================
// 输入框焦点效果
......@@ -27,28 +27,31 @@
// Suffix 图标样式
@mixin suffix-icon($size: 14px) {
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: $size;
height: $size;
min-width: $size;
height: $size;
min-height: $size;
color: $text-placeholder;
margin-left: 0;
font-size: $size;
line-height: 1;
color: $text-placeholder;
cursor: pointer;
transition: color 0.3s;
flex-shrink: 0;
line-height: 1;
margin-left: 0;
&:hover { color: $text-primary; }
&:hover {
color: $text-primary;
}
svg, i {
svg,
i {
display: block;
width: $size !important;
height: $size !important;
font-size: $size !important;
line-height: 1;
display: block;
vertical-align: middle;
}
}
......@@ -56,7 +59,10 @@
// 链接悬停效果
@mixin link-hover {
transition: color 0.3s;
&:hover { color: $primary-hover; }
&:hover {
color: $primary-hover;
}
}
// 按钮悬停效果
......@@ -71,4 +77,3 @@
align-items: center;
justify-content: center;
}
......@@ -36,4 +36,3 @@ $error-border: #ffccc7;
// 渐变背景
$btn-gradient: linear-gradient(135deg, #7fd6ff 0%, #026fff 100%);
......@@ -2,14 +2,16 @@
* Axios 请求封装
*/
import axios, {
type AxiosError,
type AxiosInstance,
type AxiosRequestConfig,
type AxiosResponse,
type InternalAxiosRequestConfig,
import type {
AxiosError,
AxiosInstance,
AxiosRequestConfig,
AxiosResponse,
InternalAxiosRequestConfig,
} from 'axios';
import axios from 'axios';
import { clearAuth, getToken } from './auth';
// 创建 axios 实例
......@@ -129,9 +131,7 @@ const handleUnauthorized = () => {
* 通用请求方法
* 注意:响应拦截器已处理数据提取,直接返回 data
*/
export const request = <T = any>(
config: AxiosRequestConfig,
): Promise<T> => {
export const request = <T = any>(config: AxiosRequestConfig): Promise<T> => {
return service.request<T, T>(config) as Promise<T>;
};
......
......@@ -2,9 +2,11 @@
import type { GlobalState } from '@/qiankun';
import { onMounted, onUnmounted, ref } from 'vue';
// 按需引入 @venus/common-ui-vue 组件库的按钮组件
import { GLButton } from '@venus/common-ui-vue';
import { getdataBoard } from "@/api/test"
import { getdataBoard } from '@/api/test';
import { waitForConfigReady } from '@/config/center';
import { broadcast, communicationManager, microApps } from '@/qiankun';
import {
......@@ -24,7 +26,7 @@ const globalState = ref<GlobalState | null>(null);
// 消息输入
const messageTitle = ref('来自主应用的消息');
const messageContent = ref('Hello from Main App!');
const drawer = ref(false)
const drawer = ref(false);
// 监听器的取消函数
let unsubscribe: (() => void) | null = null;
......@@ -35,10 +37,15 @@ onMounted(async () => {
try {
await waitForConfigReady();
console.log('[Home] 配置已就绪,开始请求数据看板...');
const res = await getdataBoard({merchantNos: '', dateType: '1', startDate: '', endDate: ''});
const res = await getdataBoard({
merchantNos: '',
dateType: '1',
startDate: '',
endDate: '',
});
console.log('[Home] 数据看板请求成功:', res);
} catch (err: any) {
console.error('[Home] 数据看板请求失败:', err);
} catch (error: any) {
console.error('[Home] 数据看板请求失败:', error);
}
// 获取当前全局状态
globalState.value = communicationManager.getGlobalState();
......@@ -243,9 +250,11 @@ const handleDebounceClick = () => {
<div class="state-label">👤 当前用户</div>
<div class="state-value">
<span class="user-avatar">{{ globalState.user?.avatar }}</span>
<span>{{ globalState.user?.name }} ({{
<span
>{{ globalState.user?.name }} ({{
globalState.user?.role
}})</span>
}})</span
>
</div>
</div>
......@@ -366,7 +375,9 @@ const handleDebounceClick = () => {
<div class="notification-title">{{ notification.title }}</div>
<div class="notification-message">{{ notification.message }}</div>
<div class="notification-meta">
<span v-if="notification.from" class="notification-from">来自: {{ notification.from }}</span>
<span v-if="notification.from" class="notification-from"
>来自: {{ notification.from }}</span
>
<span class="notification-time">{{
formatTime(notification.timestamp)
}}</span>
......@@ -395,13 +406,16 @@ const handleDebounceClick = () => {
<h4>💡 使用说明</h4>
<ul>
<li>
<strong>全局状态:</strong>主应用和微应用共享的状态,任何一方修改都会实时同步。
<strong>全局状态:</strong
>主应用和微应用共享的状态,任何一方修改都会实时同步。
</li>
<li>
<strong>消息通知:</strong>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
<strong>消息通知:</strong
>主应用可以发送通知给微应用,微应用也可以发送通知给主应用。
</li>
<li>
<strong>实时监听:</strong>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
<strong>实时监听:</strong
>状态变化会实时反映在界面上,打开控制台可以看到详细日志。
</li>
<li>
<strong>微应用接入:</strong>微应用通过 props 接收 actions,可以调用
......
<script setup lang="ts">
import GlobalLoading from '@/components/GlobalLoading.vue';
import { onMounted, onUnmounted } from 'vue';
import { useRoute } from 'vue-router';
import GlobalLoading from '@/components/GlobalLoading.vue';
const route = useRoute();
onMounted(() => {
......
......@@ -25,7 +25,7 @@ const goHome = () => {
align-items: center;
justify-content: center;
min-height: 100vh;
background: linear-gradient(135deg, #ffffff 0%, #ffffff 100%);
background: linear-gradient(135deg, #fff 0%, #fff 100%);
}
.not-found-content {
......@@ -57,7 +57,7 @@ const goHome = () => {
padding: 12px 32px;
font-size: 16px;
font-weight: 500;
color: #000000;
color: #000;
cursor: pointer;
background: #fff;
border: none;
......
......@@ -13,10 +13,12 @@
"moduleResolution": "bundler",
"paths": {
"@/*": ["src/*"],
"@venus/common-ui-vue": ["../../../../packages/common-ui/vue-ui/src/index.ts"]
"@venus/common-ui-vue": [
"../../../../packages/common-ui/vue-ui/src/index.ts"
]
},
"typeRoots": ["../../node_modules/@types", "./node_modules/@types"],
"resolveJsonModule": true,
"typeRoots": ["../../node_modules/@types", "./node_modules/@types"],
"allowImportingTsExtensions": true,
"allowJs": true,
......
import { resolve } from 'node:path';
import type { Plugin } from 'vite';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import AutoImport from 'unplugin-auto-import/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import type { Plugin } from 'vite';
import { defineConfig } from 'vite';
// 获取源码路径
......@@ -22,7 +23,10 @@ function resolveWorkspacePackage(): Plugin {
enforce: 'pre', // 在其他插件之前执行
resolveId(id, importer) {
// 精确匹配包名
if (id === '@venus/common-ui-vue' || id.startsWith('@venus/common-ui-vue/')) {
if (
id === '@venus/common-ui-vue' ||
id.startsWith('@venus/common-ui-vue/')
) {
// 验证文件是否存在
if (existsSync(commonUiSourcePath)) {
return {
......
......@@ -52,6 +52,9 @@
"venus:ls": "pnpm venus ls-templates",
"command:test": "node scripts/build/commandTest.mjs"
},
"dependencies": {
"glsk-toolkit": "catalog:"
},
"devDependencies": {
"@changesets/changelog-github": "catalog:",
"@changesets/cli": "catalog:",
......@@ -119,8 +122,5 @@
"canvas",
"node-gyp"
]
},
"dependencies": {
"glsk-toolkit": "catalog:"
}
}
......@@ -33,10 +33,10 @@
],
"name": "VenusCli"
},
"devDependencies": {
"typescript": "*"
},
"dependencies": {
"@clack/prompts": "catalog:"
},
"devDependencies": {
"typescript": "*"
}
}
......@@ -3,7 +3,9 @@ import fs from 'node:fs';
import fsp from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { cancel, confirm, isCancel, select, text } from '@clack/prompts';
export const version = '0.0.1';
type Flags = Record<string, boolean | string>;
type JsonPrimitive = boolean | null | number | string;
......@@ -129,7 +131,10 @@ function deepMerge(a: JsonValue, b: JsonValue | undefined): JsonValue {
const aValue = aObj[key];
const bValue = bObj[key];
if (bValue !== undefined) {
out[key] = key in aObj && aValue !== undefined ? deepMerge(aValue, bValue) : bValue;
out[key] =
key in aObj && aValue !== undefined
? deepMerge(aValue, bValue)
: bValue;
}
}
return out;
......@@ -181,16 +186,16 @@ async function applyOptionalFeature(
}
interface CreateOptions {
name: string;
template: string;
dir?: string;
root?: string;
eslint?: boolean;
force?: boolean;
name: string;
noInstall?: boolean;
root?: string;
router?: boolean;
store?: boolean;
template: string;
ui?: string;
eslint?: boolean;
force?: boolean;
}
async function executeCreate(options: CreateOptions) {
......@@ -257,11 +262,9 @@ async function executeCreate(options: CreateOptions) {
});
// Apply optional features
if (router)
await applyOptionalFeature(destRoot, tplRoot, 'optional/router');
if (router) await applyOptionalFeature(destRoot, tplRoot, 'optional/router');
if (store) await applyOptionalFeature(destRoot, tplRoot, 'optional/store');
if (eslint)
await applyOptionalFeature(destRoot, tplRoot, 'optional/eslint');
if (eslint) await applyOptionalFeature(destRoot, tplRoot, 'optional/eslint');
if (ui)
await applyOptionalFeature(destRoot, tplRoot, path.join('optional/ui', ui));
......@@ -277,7 +280,7 @@ async function executeCreate(options: CreateOptions) {
packageJson.name = `@venus/${name}`;
await fsp.writeFile(
packageJsonPath,
JSON.stringify(packageJson, null, 2) + '\n',
`${JSON.stringify(packageJson, null, 2)}\n`,
);
}
......@@ -346,7 +349,7 @@ async function runCreateInteractive() {
}
},
});
if(!projectName) {
if (!projectName) {
cancel('项目名称不能为空');
process.exit(0);
}
......@@ -425,7 +428,7 @@ async function runCreateInteractive() {
: __dirname;
const tplRoot = path.resolve(runtimeDir, '../templates', template);
const uiDir = path.join(tplRoot, 'optional', 'ui');
let selectedUi: string | undefined = undefined;
let selectedUi: string | undefined;
if (fs.existsSync(uiDir)) {
const uiOptions = await fsp.readdir(uiDir, { withFileTypes: true });
......@@ -436,10 +439,7 @@ async function runCreateInteractive() {
if (availableUis.length > 0) {
const uiChoice = await select<string>({
message: '请选择 UI 库 (可选):',
options: [
{ value: '', label: '不使用 UI 库' },
...availableUis,
],
options: [{ value: '', label: '不使用 UI 库' }, ...availableUis],
});
if (isCancel(uiChoice) || typeof uiChoice !== 'string') {
......@@ -507,11 +507,9 @@ export async function main() {
if (cmd === 'create') {
// 如果没有提供项目名,则进入交互式模式
const name = process.argv[3];
if (!name || name.startsWith('--')) {
await runCreateInteractive();
} else {
await runCreate(process.argv);
}
await (!name || name.startsWith('--')
? runCreateInteractive()
: runCreate(process.argv));
return;
}
if (cmd === 'build') {
......
/// <reference types="vite/client" />
// / <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue';
......@@ -10,28 +10,35 @@ declare module '*.vue' {
// vue-router 类型声明(模板开发时使用,避免类型错误)
declare module 'vue-router' {
export interface RouteMeta {
title?: string;
[key: string]: unknown;
title?: string;
}
export interface RouteLocationNormalized {
path: string;
name?: string | symbol | null;
meta: RouteMeta;
[key: string]: unknown;
meta: RouteMeta;
name?: null | string | symbol;
path: string;
}
export type NavigationGuardNext = (to?: string | false | void) => void;
export type NavigationGuardNext = (to?: false | string | void) => void;
export interface RouteRecordRaw {
path: string;
name?: string | symbol;
[key: string]: unknown;
component?: unknown;
meta?: RouteMeta;
[key: string]: unknown;
name?: string | symbol;
path: string;
}
export interface Router {
[key: string]: unknown;
afterEach(
guard: (
to: RouteLocationNormalized,
from: RouteLocationNormalized,
) => void,
): () => void;
beforeEach(
guard: (
to: RouteLocationNormalized,
......@@ -39,10 +46,6 @@ declare module 'vue-router' {
next: NavigationGuardNext,
) => void,
): () => void;
afterEach(
guard: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void,
): () => void;
[key: string]: unknown;
}
export function createRouter(options: {
......@@ -53,7 +56,12 @@ declare module 'vue-router' {
export function createWebHistory(base?: string): unknown;
// 导出所有需要的类型
export type { Router, RouteRecordRaw, RouteLocationNormalized, NavigationGuardNext };
export type {
NavigationGuardNext,
RouteLocationNormalized,
Router,
RouteRecordRaw,
};
}
// qiankun 相关类型
......
import type { Router, RouteRecordRaw, RouteLocationNormalized, NavigationGuardNext } from 'vue-router';
import type {
NavigationGuardNext,
RouteLocationNormalized,
Router,
RouteRecordRaw,
} from 'vue-router';
import { createRouter as _createRouter, createWebHistory } from 'vue-router';
......@@ -61,17 +66,25 @@ export function createRouter(base: string = '/'): Router {
});
// 路由守卫
router.beforeEach((to: RouteLocationNormalized, _from: RouteLocationNormalized, next: NavigationGuardNext) => {
// 设置页面标题
if (to.meta.title) {
document.title = `${to.meta.title} - Vue3 微应用`;
}
next();
});
router.beforeEach(
(
to: RouteLocationNormalized,
_from: RouteLocationNormalized,
next: NavigationGuardNext,
) => {
// 设置页面标题
if (to.meta.title) {
document.title = `${to.meta.title} - Vue3 微应用`;
}
next();
},
);
router.afterEach((to: RouteLocationNormalized, from: RouteLocationNormalized) => {
console.log('[Vue3 微应用] 路由切换:', from.path, '->', to.path);
});
router.afterEach(
(to: RouteLocationNormalized, from: RouteLocationNormalized) => {
console.log('[Vue3 微应用] 路由切换:', from.path, '->', to.path);
},
);
return router;
}
......@@ -27,5 +27,11 @@
"skipLibCheck": true
},
"references": [{ "path": "./tsconfig.node.json" }],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "env.d.ts"]
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"env.d.ts"
]
}
<template>
<ElButton v-bind="$attrs">
<template v-for="(_, name) in $slots" :key="name" #[name]="slotData">
<slot :name="name" v-bind="{...slotData}" />
<slot :name="name" v-bind="{ ...slotData }"></slot>
</template>
</ElButton>
</template>
<template>
<ElInput v-bind="$attrs" class="gl-input">
<template v-for="(_, name) in $slots" :key="name" #[name]="slotData">
<slot :name="name" v-bind="{...slotData}" />
<slot :name="name" v-bind="{ ...slotData }"></slot>
</template>
</ElInput>
</template>
......@@ -9,37 +9,37 @@
<style scoped lang="scss">
:deep(.gl-input) {
.el-input__wrapper {
padding: 0;
background: transparent !important;
border: none !important;
box-shadow: none !important;
background: transparent !important;
padding: 0;
&:hover {
box-shadow: none !important;
border: none !important;
box-shadow: none !important;
}
&.is-focus {
box-shadow: none !important;
border: none !important;
box-shadow: none !important;
}
&.is-disabled {
box-shadow: none !important;
border: none !important;
box-shadow: none !important;
}
}
.el-input__inner {
outline: none !important;
background: transparent !important;
border: none !important;
box-shadow: none !important;
background: transparent !important;
outline: none !important;
&:focus {
outline: none !important;
border: none !important;
box-shadow: none !important;
outline: none !important;
}
}
}
......
import type { ButtonProps} from 'element-plus';
import type { ButtonProps } from 'element-plus';
/**
* 按钮组件属性
......
......@@ -8,8 +8,8 @@
import { execSync } from 'node:child_process';
import { existsSync, mkdirSync, rmSync } from 'node:fs';
import { copyFile, readdir, stat } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { copyFile, readdir } from 'node:fs/promises';
import { join } from 'node:path';
// 获取项目根目录
const rootDir = process.cwd();
......@@ -44,7 +44,7 @@ function buildPackage(packageName) {
},
});
console.log(`✅ 项目构建完成: ${packageName}`);
} catch (error) {
} catch {
console.error(`❌ 项目构建失败: ${packageName}`);
process.exit(1);
}
......@@ -67,11 +67,9 @@ async function copyDirectory(src, dest) {
const srcPath = join(src, entry.name);
const destPath = join(dest, entry.name);
if (entry.isDirectory()) {
await copyDirectory(srcPath, destPath);
} else {
await copyFile(srcPath, destPath);
}
await (entry.isDirectory()
? copyDirectory(srcPath, destPath)
: copyFile(srcPath, destPath));
}
}
......@@ -101,7 +99,7 @@ async function findPackagePath(packageName) {
try {
const packageJson = JSON.parse(
await import('node:fs').then((fs) =>
fs.promises.readFile(packageJsonPath, 'utf-8'),
fs.promises.readFile(packageJsonPath, 'utf8'),
),
);
// 检查包名是否匹配
......@@ -112,7 +110,7 @@ async function findPackagePath(packageName) {
) {
return path;
}
} catch (error) {
} catch {
// 忽略 JSON 解析错误
}
}
......@@ -199,4 +197,3 @@ main().catch((error) => {
console.error(`❌ 构建过程中出现错误: ${error.message}`);
process.exit(1);
});
import { exec, execSync } from 'node:child_process';
import { existsSync, mkdirSync, rmSync } from 'node:fs';
import { copyFile, readdir, stat } from 'node:fs/promises';
import { join, resolve } from 'node:path';
/**
* 方案 1: 使用 execSync + encoding(推荐)
......@@ -107,7 +104,11 @@ function testCommandWithFilter() {
const trimmedLine = line.trim();
// 检测适配器名称
if (trimmedLine && !trimmedLine.startsWith(' ') && trimmedLine.includes(':')) {
if (
trimmedLine &&
!trimmedLine.startsWith(' ') &&
trimmedLine.includes(':')
) {
currentAdapter = trimmedLine;
console.log(`\n📶 ${currentAdapter}`);
}
......@@ -118,17 +119,23 @@ function testCommandWithFilter() {
}
// 子网掩码
if (trimmedLine.includes('子网掩码') || trimmedLine.includes('Subnet Mask')) {
if (
trimmedLine.includes('子网掩码') ||
trimmedLine.includes('Subnet Mask')
) {
console.log(` ├─ ${trimmedLine}`);
}
// 默认网关
if (trimmedLine.includes('默认网关') || trimmedLine.includes('Default Gateway')) {
if (
trimmedLine.includes('默认网关') ||
trimmedLine.includes('Default Gateway')
) {
console.log(` └─ ${trimmedLine}`);
}
});
console.log('\n' + '═'.repeat(60));
console.log(`\n${'═'.repeat(60)}`);
return output;
} catch (error) {
......
......@@ -14,7 +14,6 @@ try {
.action(async (command: string, options: { filter?: string }) => {
run({ command, filter: options.filter });
});
项目路径:
// Invalid command
turboRun.on('command:*', () => {
consola.error(colors.red('Invalid command!'));
......
......@@ -36,7 +36,7 @@ export async function run(options: RunOptions) {
let selectPkg: string | symbol;
if (selectPkgs.length > 1) {
console.log("selectPkgs",selectPkgs);
console.log('selectPkgs', selectPkgs);
selectPkg = await select<string>({
message: `Select the app you need to run [${command}]:`,
options: selectPkgs.map((item) => ({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!