web打包问题
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<title>招标管理系统</title>
|
||||
|
||||
<!-- 加载运行时配置(必须在其他脚本之前加载) -->
|
||||
<script src="/app-config.js"></script>
|
||||
<script src="/app-config.local.js"></script>
|
||||
|
||||
<!-- Import Maps 配置 - 引用共享模块 -->
|
||||
<script type="importmap">
|
||||
|
||||
60
urbanLifelineWeb/packages/bidding/public/app-config.local.js
Normal file
60
urbanLifelineWeb/packages/bidding/public/app-config.local.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @description 本地开发环境配置文件
|
||||
* 用于 dev 和 preview 模式
|
||||
*/
|
||||
|
||||
window.APP_RUNTIME_CONFIG = {
|
||||
// 环境标识
|
||||
env: 'production',
|
||||
|
||||
// API 配置
|
||||
api: {
|
||||
baseUrl: 'https://org.xyzh.yslg/api',
|
||||
timeout: 30000
|
||||
},
|
||||
|
||||
// 应用基础路径
|
||||
baseUrl: '/bidding/',
|
||||
|
||||
// 文件配置
|
||||
file: {
|
||||
downloadUrl: 'https://org.xyzh.yslg/api/urban-lifeline/file/download/',
|
||||
uploadUrl: 'https://org.xyzh.yslg/api/urban-lifeline/file/upload',
|
||||
maxSize: {
|
||||
image: 5,
|
||||
video: 100,
|
||||
document: 10
|
||||
},
|
||||
acceptTypes: {
|
||||
image: 'image/*',
|
||||
video: 'video/*',
|
||||
document: '.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx'
|
||||
}
|
||||
},
|
||||
|
||||
// Token 配置
|
||||
token: {
|
||||
key: 'token',
|
||||
refreshThreshold: 300000
|
||||
},
|
||||
|
||||
// 公共资源路径
|
||||
publicImgPath: '/bidding/img',
|
||||
publicWebPath: '/bidding',
|
||||
|
||||
// 单点登录配置
|
||||
sso: {
|
||||
platformUrl: 'https://org.xyzh.yslg/platform/',
|
||||
workcaseUrl: 'https://org.xyzh.yslg/workcase/',
|
||||
biddingUrl: 'https://org.xyzh.yslg/bidding/'
|
||||
},
|
||||
|
||||
// AES 加密密钥(本地开发用,生产环境需要替换)
|
||||
aesSecretKey: 'MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=',
|
||||
|
||||
// 功能开关
|
||||
features: {
|
||||
enableDebug: true,
|
||||
enableMockData: false
|
||||
}
|
||||
};
|
||||
@@ -5,7 +5,6 @@ import 'element-plus/dist/index.css'
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router/'
|
||||
import { AES_SECRET_KEY } from './config'
|
||||
|
||||
// 导入需要的 Lucide 图标
|
||||
import {
|
||||
|
||||
@@ -9,17 +9,19 @@
|
||||
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
import {
|
||||
generateSimpleRoutes,
|
||||
loadViewsFromStorage,
|
||||
type RouteGeneratorConfig,
|
||||
type GenerateSimpleRoutesOptions
|
||||
} from 'shared/utils/route'
|
||||
import type { TbSysViewDTO } from 'shared/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import router from './index'
|
||||
import { SidebarLayout, BlankLayout, SubSidebarLayout } from '@/layouts'
|
||||
|
||||
// 动态导入 shared 模块(避免顶层 import 阻塞)
|
||||
async function loadSharedModules() {
|
||||
const [routeUtils, types] = await Promise.all([
|
||||
import('shared/utils/route'),
|
||||
import('shared/types')
|
||||
])
|
||||
return { routeUtils, types }
|
||||
}
|
||||
|
||||
// Bidding 布局组件映射
|
||||
const biddingLayoutMap: Record<string, () => Promise<any>> = {
|
||||
'SidebarLayout': () => Promise.resolve({ default: SidebarLayout }),
|
||||
@@ -67,7 +69,7 @@ function viewLoader(componentPath: string): (() => Promise<any>) | null {
|
||||
}
|
||||
|
||||
// Bidding 路由生成器配置
|
||||
const routeConfig: RouteGeneratorConfig = {
|
||||
const routeConfig: any = {
|
||||
layoutMap: biddingLayoutMap,
|
||||
viewLoader,
|
||||
notFoundComponent: () => import('vue').then(({ h }) => ({
|
||||
@@ -78,7 +80,7 @@ const routeConfig: RouteGeneratorConfig = {
|
||||
}
|
||||
|
||||
// Bidding 路由生成选项
|
||||
const routeOptions: GenerateSimpleRoutesOptions = {
|
||||
const routeOptions: any = {
|
||||
asRootChildren: false, // 直接作为根级路由,不是某个布局的子路由
|
||||
iframePlaceholder: () => import('shared/components').then(m => ({ default: m.IframeView })),
|
||||
verbose: true // 启用详细日志
|
||||
@@ -88,17 +90,19 @@ const routeOptions: GenerateSimpleRoutesOptions = {
|
||||
* 添加动态路由(Bidding 特定)
|
||||
* @param views 视图列表(用作菜单)
|
||||
*/
|
||||
export function addDynamicRoutes(views: TbSysViewDTO[]) {
|
||||
export async function addDynamicRoutes(views: any[]) {
|
||||
if (!views || views.length === 0) {
|
||||
console.warn('[Bidding] addDynamicRoutes: 视图列表为空')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('[Bidding] addDynamicRoutes: 开始添加动态路由,视图数量:', views.length)
|
||||
console.log('[Bidding] addDynamicRoutes: 路由配置:', routeConfig)
|
||||
console.log('[Bidding] addDynamicRoutes: 路由选项:', routeOptions)
|
||||
|
||||
try {
|
||||
// 动态加载 shared 模块
|
||||
const { routeUtils } = await loadSharedModules()
|
||||
const { generateSimpleRoutes } = routeUtils
|
||||
|
||||
// 使用 shared 中的通用方法生成路由
|
||||
const routes = generateSimpleRoutes(views, routeConfig, routeOptions)
|
||||
|
||||
@@ -120,10 +124,14 @@ export function addDynamicRoutes(views: TbSysViewDTO[]) {
|
||||
* 使用 shared 中的通用 loadViewsFromStorage 方法
|
||||
* 筛选出 service='bidding' 的视图
|
||||
*/
|
||||
export function loadRoutesFromStorage(): boolean {
|
||||
export async function loadRoutesFromStorage(): Promise<boolean> {
|
||||
try {
|
||||
console.log('[Bidding] loadRoutesFromStorage: 开始加载动态路由')
|
||||
|
||||
// 动态加载 shared 模块
|
||||
const { routeUtils } = await loadSharedModules()
|
||||
const { loadViewsFromStorage } = routeUtils
|
||||
|
||||
// 使用 shared 中的通用方法加载视图数据
|
||||
const allViews = loadViewsFromStorage('loginDomain', 'userViews')
|
||||
|
||||
@@ -131,7 +139,7 @@ export function loadRoutesFromStorage(): boolean {
|
||||
|
||||
if (allViews) {
|
||||
// 过滤出 bidding 服务的视图
|
||||
const biddingViews = allViews.filter((view: TbSysViewDTO) =>
|
||||
const biddingViews = allViews.filter((view: any) =>
|
||||
view.service === 'bidding'
|
||||
)
|
||||
|
||||
@@ -143,7 +151,7 @@ export function loadRoutesFromStorage(): boolean {
|
||||
}
|
||||
|
||||
// 使用 Bidding 的 addDynamicRoutes 添加路由
|
||||
addDynamicRoutes(biddingViews)
|
||||
await addDynamicRoutes(biddingViews)
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
|
||||
// @ts-ignore
|
||||
import { TokenManager } from 'shared/api'
|
||||
// @ts-ignore
|
||||
import { APP_CONFIG } from 'shared/config'
|
||||
// @ts-ignore
|
||||
// @ts-ignore - 动态导入,避免顶层 import 阻塞
|
||||
import { loadRoutesFromStorage } from './dynamicRoute'
|
||||
|
||||
// 同步检查 token(直接读取 localStorage,避免导入 shared 模块)
|
||||
function hasTokenSync(): boolean {
|
||||
const token = localStorage.getItem('token')
|
||||
return !!token && token.length > 0
|
||||
}
|
||||
|
||||
// bidding应用的动态路由会根据layout字段自动添加,不需要预定义Root布局
|
||||
const routes: RouteRecordRaw[] = []
|
||||
|
||||
@@ -18,7 +20,7 @@ const router = createRouter({
|
||||
let dynamicRoutesLoaded = false
|
||||
|
||||
// 路由守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
console.log('[Bidding Router] 路由守卫触发:', {
|
||||
to: to.path,
|
||||
from: from.path,
|
||||
@@ -32,7 +34,7 @@ router.beforeEach((to, from, next) => {
|
||||
|
||||
// 检查是否需要登录
|
||||
const requiresAuth = to.meta.requiresAuth !== false
|
||||
const hasToken = TokenManager.hasToken()
|
||||
const hasToken = hasTokenSync()
|
||||
|
||||
console.log('[Bidding Router] 认证检查:', {
|
||||
requiresAuth,
|
||||
@@ -66,19 +68,24 @@ router.beforeEach((to, from, next) => {
|
||||
})
|
||||
|
||||
dynamicRoutesLoaded = true
|
||||
const loaded = loadRoutesFromStorage?.()
|
||||
|
||||
console.log('[Bidding Router] 动态路由加载结果:', loaded)
|
||||
console.log('[Bidding Router] 当前路径:', to.path)
|
||||
console.log('[Bidding Router] 所有路由:', router.getRoutes().map(r => r.path))
|
||||
|
||||
if (loaded) {
|
||||
// 动态路由加载成功,重新导航以匹配新添加的路由
|
||||
console.log('[Bidding Router] 动态路由加载成功,重新导航到:', to.path)
|
||||
next({ ...to, replace: true })
|
||||
return
|
||||
} else {
|
||||
console.warn('[Bidding Router] 动态路由加载失败')
|
||||
try {
|
||||
const loaded = await loadRoutesFromStorage?.()
|
||||
|
||||
console.log('[Bidding Router] 动态路由加载结果:', loaded)
|
||||
console.log('[Bidding Router] 当前路径:', to.path)
|
||||
console.log('[Bidding Router] 所有路由:', router.getRoutes().map(r => r.path))
|
||||
|
||||
if (loaded) {
|
||||
// 动态路由加载成功,重新导航以匹配新添加的路由
|
||||
console.log('[Bidding Router] 动态路由加载成功,重新导航到:', to.path)
|
||||
next({ ...to, replace: true })
|
||||
return
|
||||
} else {
|
||||
console.warn('[Bidding Router] 动态路由加载失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Bidding Router] 动态路由加载异常:', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,14 +90,30 @@ export default defineConfig(({ mode }) => {
|
||||
build: {
|
||||
target: 'esnext',
|
||||
outDir: 'dist',
|
||||
sourcemap: true,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
'vue-vendor': ['vue', 'vue-router', 'pinia'],
|
||||
'element-plus': ['element-plus']
|
||||
sourcemap: true
|
||||
// 注意:不要使用 manualChunks 分割 vue/vue-router/element-plus
|
||||
// 因为它们已经在 Module Federation 的 shared 中声明
|
||||
// 同时使用会导致循环依赖死锁
|
||||
},
|
||||
|
||||
preview: {
|
||||
port: 7002,
|
||||
host: true,
|
||||
cors: true,
|
||||
https: (() => {
|
||||
try {
|
||||
return {
|
||||
key: fs.readFileSync('C:/Users/FK05/443/localhost+3-key.pem'),
|
||||
cert: fs.readFileSync('C:/Users/FK05/443/localhost+3.pem')
|
||||
}
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
})(),
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Content-Type, Authorization'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user