feat(settings): add home content customization and config injection
- Add home_content setting for custom homepage (HTML or iframe URL) - Inject public settings into index.html to eliminate page flash - Support ETag caching with automatic invalidation on settings update - Add Vite plugin for dev mode settings injection - Refactor HomeView to use appStore instead of local API calls
This commit is contained in:
@@ -1,8 +1,39 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, Plugin } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import checker from 'vite-plugin-checker'
|
||||
import { resolve } from 'path'
|
||||
|
||||
/**
|
||||
* Vite 插件:开发模式下注入公开配置到 index.html
|
||||
* 与生产模式的后端注入行为保持一致,消除闪烁
|
||||
*/
|
||||
function injectPublicSettings(): Plugin {
|
||||
const backendUrl = process.env.VITE_DEV_PROXY_TARGET || 'http://localhost:8080'
|
||||
|
||||
return {
|
||||
name: 'inject-public-settings',
|
||||
transformIndexHtml: {
|
||||
order: 'pre',
|
||||
async handler(html) {
|
||||
try {
|
||||
const response = await fetch(`${backendUrl}/api/v1/settings/public`, {
|
||||
signal: AbortSignal.timeout(2000)
|
||||
})
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
if (data.code === 0 && data.data) {
|
||||
const script = `<script>window.__APP_CONFIG__=${JSON.stringify(data.data)};</script>`
|
||||
return html.replace('</head>', `${script}\n</head>`)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[vite] 无法获取公开配置,将回退到 API 调用:', (e as Error).message)
|
||||
}
|
||||
return html
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
@@ -10,7 +41,8 @@ export default defineConfig({
|
||||
checker({
|
||||
typescript: true,
|
||||
vueTsc: true
|
||||
})
|
||||
}),
|
||||
injectPublicSettings()
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Reference in New Issue
Block a user