Compare commits

...

3 Commits

Author SHA1 Message Date
zhaoruhui 57c87f41c7 修改配置文件 3 months ago
zhaoruhui 0913aa20c3 修改配置文件 3 months ago
zhaoruhui 1ca18f1e5c 修改配置文件 3 months ago
  1. 2
      .env.production
  2. 13
      pages/landingDetail.html
  3. 13
      pages/landingList.html
  4. 13
      pages/landingManagement.html
  5. 88
      src/main.js
  6. 73
      vite.config.js

2
.env.production

@ -2,4 +2,4 @@
VITE_APP_ENV=production
# 生产环境 API
VITE_API_BASE_URL=https://your-production-domain.com
VITE_API_BASE_URL=https://dbqb.nfdxy.net/activityApi

13
pages/landingDetail.html

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>landingDetail</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

13
pages/landingList.html

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>landingList</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

13
pages/landingManagement.html

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>landingManagement</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

88
src/main.js

@ -1,15 +1,87 @@
// src/main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
const app = createApp(App)
// 获取当前页面名称
function getCurrentPage() {
const path = window.location.pathname
console.log('Current path:', path)
app.use(router)
app.use(ElementPlus, {
locale: zhCn
})
let page = 'landingList' // 默认页面
app.mount('#app')
if (path.includes('/pages/')) {
page = path.split('/pages/').pop().replace('.html', '')
} else if (path.endsWith('.html')) {
page = path.split('/').pop().replace('.html', '')
}
console.log('Detected page:', page)
return page
}
// 动态加载对应的 Vue 组件
async function bootstrap() {
const pageName = getCurrentPage()
console.log('Loading page:', pageName)
try {
// 动态导入所有 admin 目录下的 Vue 文件
const modules = import.meta.glob('./views/admin/*.vue')
const modulePath = `./views/admin/${pageName}.vue`
console.log('Looking for module:', modulePath)
console.log('Available modules:', Object.keys(modules))
if (modules[modulePath]) {
const module = await modules[modulePath]()
console.log('Module loaded successfully')
// 创建并挂载应用
const app = createApp(module.default)
app.use(ElementPlus, {
locale: zhCn
})
app.mount('#app')
console.log('App mounted successfully')
} else {
console.error(`Page ${pageName} not found`)
// 显示错误页面
const app = createApp({
template: `
<div style="padding: 50px; text-align: center;">
<h1>页面未找到</h1>
<p>页面 ${pageName} 不存在</p>
<p>可用页面: ${Object.keys(modules).map(m => m.replace('./views/admin/', '').replace('.vue', '')).join(', ')}</p>
</div>
`
})
app.use(ElementPlus, { locale: zhCn })
app.mount('#app')
}
} catch (error) {
console.error('Failed to load page:', error)
// 显示错误信息
const app = createApp({
template: `
<div style="padding: 20px; color: red;">
<h2>页面加载失败</h2>
<p>错误: ${error.message}</p>
<p>请检查控制台获取详细信息</p>
</div>
`
})
app.mount('#app')
}
}
// 启动应用
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', bootstrap)
} else {
bootstrap()
}

73
vite.config.js

@ -1,18 +1,69 @@
import { fileURLToPath, URL } from 'node:url'
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import { resolve } from 'path'
import { readdirSync, existsSync, mkdirSync } from 'fs'
function createHTMLFiles() {
const viewsDir = './src/views/admin'
const vueFiles = readdirSync(viewsDir).filter(file => file.endsWith('.vue'))
const input = {}
vueFiles.forEach(file => {
const pageName = file.replace('.vue', '')
const htmlFileName = `${pageName}.html`
// 创建正确的 HTML 内容,使用相对路径
const htmlContent = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${pageName}</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>`
// 确保目录存在
if (!existsSync('./src')) {
mkdirSync('./src')
}
// 将 HTML 文件写入 src 目录
writeFileSync(resolve(__dirname, 'src', htmlFileName), htmlContent)
input[pageName] = resolve(__dirname, 'src', htmlFileName)
})
return input
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
plugins: [vue()],
base: './',
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
...createHTMLFiles()
}
},
assetsDir: '',
emptyOutDir: true,
// 添加 chunk 大小警告限制
chunkSizeWarningLimit: 1000
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
'@': resolve(__dirname, 'src')
}
},
})
preview: {
port: 4173,
host: true,
open: '/landingManagement.html'
}
})
Loading…
Cancel
Save