Compare commits

..

1 Commits

Author SHA1 Message Date
460e1d0e31 Revert "async load page component" (lost timi-tdesign-pc style)
This reverts commit aef44a528a.
2025-07-23 00:18:42 +08:00
2 changed files with 19 additions and 13 deletions

View File

@ -1,3 +1,6 @@
import IndexLayout from "@/layout/IndexLayout.vue";
import ArticleDetail from "@/views/ArticleDetail.vue";
import ArticleIndex from "@/views/ArticleIndex.vue";
import { createRouter, createWebHistory } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
export default createRouter({ export default createRouter({
@ -6,22 +9,22 @@ export default createRouter({
{ {
path: "/", path: "/",
name: "Index", name: "Index",
component: () => import("@/layout/IndexLayout.vue"), component: IndexLayout,
children: [ children: [
{ {
path: "/", path: "/",
name: "ArticleIndex", name: "ArticleIndex",
component: () => import("@/views/ArticleIndex.vue") component: ArticleIndex
}, },
{ {
path: "/aid:id.html", path: "/aid:id.html",
name: "ArticleDetail", name: "ArticleDetail",
component: () => import("@/views/ArticleDetail.vue") component: ArticleDetail
}, },
{ {
path: "/about", path: "/about",
name: "About", name: "About",
component: () => import("@/views/ArticleDetail.vue") component: ArticleDetail
} }
] ]
} }

View File

@ -38,6 +38,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ArticleAPI, ArticleView, Icon } from "timi-web"; import { ArticleAPI, ArticleView, Icon } from "timi-web";
import ArticleAbout from "@/components/article/template/ArticleAbout.vue";
import ArticleMusic from "@/components/article/template/ArticleMusic.vue";
import ArticlePublic from "@/components/article/template/ArticlePublic.vue";
import ArticleSoftware from "@/components/article/template/ArticleSoftware.vue";
import { type Component } from "vue"; import { type Component } from "vue";
const route = useRoute(); const route = useRoute();
@ -45,20 +49,19 @@ const router = useRouter();
const article = ref<ArticleView<any>>(); const article = ref<ArticleView<any>>();
const template = ref<Component | null>(null); const template = ref<Component | null>(null);
const templates: Record<string, () => Promise<Component>> = { const templates: Record<string, Component> = {
ABOUT: () => import("@/components/article/template/ArticleAbout.vue"), ABOUT: ArticleAbout,
MUSIC: () => import("@/components/article/template/ArticleMusic.vue"), MUSIC: ArticleMusic,
PUBLIC: () => import("@/components/article/template/ArticlePublic.vue"), PUBLIC: ArticlePublic,
SOFTWARE: () => import("@/components/article/template/ArticleSoftware.vue") SOFTWARE: ArticleSoftware
}; };
const isAboutRoute = computed(() => route.name === "About"); const isAboutRoute = computed(() => route.name === "About");
watch(article, () => { watch(article, () => {
if (!article.value) { if (article.value) {
return; const key = isAboutRoute.value ? "ABOUT" : article.value.type;
template.value = markRaw(templates[key]);
} }
const loader = templates[isAboutRoute.value ? "ABOUT" : article.value.type];
template.value = defineAsyncComponent(loader);
}); });
onMounted(async () => { onMounted(async () => {