更新网站架构
This commit is contained in:
parent
b6294200a7
commit
8a33f6cd9f
@ -1,6 +1,5 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { constantRoute, registerDynamicRoutes } from './routes';
|
||||
import { getHeadMenu } from '@/api/index';
|
||||
|
||||
// 先创建路由,但不立即匹配
|
||||
const router = createRouter({
|
||||
@ -25,21 +24,6 @@ export async function loadAndRegisterRoutes() {
|
||||
return routesLoadingPromise;
|
||||
}
|
||||
|
||||
// 开始加载
|
||||
routesLoadingPromise = (async () => {
|
||||
try {
|
||||
const response = await getHeadMenu();
|
||||
if (response.code === 200 && response.data) {
|
||||
registerDynamicRoutes(router, response.data);
|
||||
routesLoaded = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load menus and register routes:', error);
|
||||
} finally {
|
||||
routesLoadingPromise = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return routesLoadingPromise;
|
||||
}
|
||||
|
||||
@ -47,9 +31,7 @@ export async function loadAndRegisterRoutes() {
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
// 如果路由还未加载,先加载路由
|
||||
if (!routesLoaded) {
|
||||
if (!routesLoadingPromise) {
|
||||
routesLoadingPromise = loadAndRegisterRoutes();
|
||||
}
|
||||
|
||||
// 等待路由加载完成
|
||||
await routesLoadingPromise;
|
||||
|
||||
|
||||
@ -18,12 +18,11 @@
|
||||
import { ref, onMounted } from 'vue'
|
||||
import axios from 'axios'
|
||||
|
||||
const API_BASE = 'http://localhost:8000'
|
||||
const VITE_API_BASE_URL = import.meta.env.VITE_API_BASE_URL
|
||||
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const iframeSrc = ref('')
|
||||
const siteData = ref<Record<string, any>>({})
|
||||
|
||||
const fetchData = async () => {
|
||||
loading.value = true
|
||||
@ -31,12 +30,11 @@ const fetchData = async () => {
|
||||
|
||||
try {
|
||||
// 直接用 axios 测试
|
||||
const res = await axios.get(`${API_BASE}/index/init`)
|
||||
const res = await axios.get(`${VITE_API_BASE_URL}/index/init`)
|
||||
console.log('API响应:', res.data)
|
||||
|
||||
if (res.data.code === 200) {
|
||||
iframeSrc.value = API_BASE + res.data.data.theme_path
|
||||
siteData.value = res.data.data.data || {}
|
||||
iframeSrc.value = VITE_API_BASE_URL + res.data.data.theme_path
|
||||
console.log('iframe地址:', iframeSrc.value)
|
||||
} else {
|
||||
error.value = res.data.msg || '获取模板失败'
|
||||
@ -50,13 +48,7 @@ const fetchData = async () => {
|
||||
}
|
||||
|
||||
const onLoad = () => {
|
||||
const iframe = document.querySelector('.theme-iframe') as HTMLIFrameElement
|
||||
if (iframe?.contentWindow) {
|
||||
iframe.contentWindow.postMessage({
|
||||
type: 'SET_SITE_DATA',
|
||||
data: { ...siteData.value, _t: Date.now() }
|
||||
}, '*')
|
||||
}
|
||||
console.log('模板加载完成')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@ -585,6 +585,12 @@ onMounted(async () => {
|
||||
line-height: 25px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
:deep(span) {
|
||||
padding: 3px 4px;
|
||||
margin:5px;
|
||||
border-radius:4px;
|
||||
}
|
||||
}
|
||||
|
||||
.theend {
|
||||
|
||||
@ -43,7 +43,7 @@
|
||||
v-if="footerData && footerData.logow"
|
||||
:src="getenvurl(footerData.logow)"
|
||||
alt="logo"
|
||||
>
|
||||
/>
|
||||
</div>
|
||||
<div class="footer-column">
|
||||
<div class="title">订阅我们</div>
|
||||
@ -54,8 +54,16 @@
|
||||
<div class="footer-bottom" v-if="footerData">
|
||||
<div class="left">
|
||||
<span class="mr-3">{{ footerData.description }}</span>
|
||||
<span class="mr-3">{{ footerData.companyname }} {{ footerData.copyright }}</span>
|
||||
<span class="mr-3"><a href="https://beian.miit.gov.cn/" target="_blank">{{ footerData.icp }}</a></span>
|
||||
<span class="mr-3">
|
||||
{{ footerData.companyname }} {{
|
||||
footerData.copyright
|
||||
}}
|
||||
</span>
|
||||
<span class="mr-3">
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">
|
||||
{{ footerData.icp }}
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="right">
|
||||
<span>法律声明 | 隐私条款</span>
|
||||
@ -92,7 +100,7 @@ const handleScroll = () => {
|
||||
const goToTop = () => {
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth'
|
||||
behavior: 'smooth',
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user