import { useArticle, useCategory } from "@/modules"; import { css } from "@linaria/core"; import { defineComponent, onMounted, reactive, watch } from "vue"; import { useRoute, useRouter } from "vue-router"; import PageTabs from "./PageTabs"; import { Empty, message } from "ant-design-vue"; export default defineComponent({ setup() { const route = useRoute(); const router = useRouter(); const categoryStore = useCategory(); const articleStore = useArticle(); const state = reactive({ currFloor: {} as any, currMid: {} as any, currTree: {} as any, currBg: "", content: "", loading: true, }); watch( () => categoryStore.listController.state.list, () => { initCategory(); } ); onMounted(() => { initCategory(); initArticle(); }); const initCategory = () => { const id = route.params.id; const currCategory = categoryStore.listController.state.list.find( (e: CategoryItem) => { return e._id == id; } ); if (!currCategory) { if (categoryStore.listController.state.list.length > 0) { router.replace("/404"); } return; } if (currCategory?.pid == "top") { state.currTree = categoryStore.categoryTree.find((e) => { return e._id == id; }); state.currMid = state.currTree.children[0]; if (state.currMid.children && state.currMid.children.length) { const cid = route.query.cid; if (cid) { state.currFloor = state.currMid.children.find((e: any) => { return e._id == cid; }); } else { state.currFloor = state.currMid.children[0]; } } else { state.currFloor = state.currMid; } return; } state.currMid = currCategory; if (currCategory.children && currCategory.children.length) { const cid = route.query.cid; if (cid) { state.currFloor = currCategory.children.find((e: any) => { return e._id == cid; }); } else { state.currFloor = currCategory.children[0]; } } else { state.currFloor = state.currMid; } state.currTree = categoryStore.categoryTree.find((e) => { return e._id == currCategory.pid; }); }; const initArticle = async () => { const aid = route.query.aid; if (!aid) { state.loading = false; return; } const res = await articleStore.listController.itemDetail(aid as string); if (res.errorNo != 200) { message.warn("未查询到数据!"); state.loading = false; return; } state.loading = false; state.content = res.result.content; }; return () => { return (

{state.currTree.name}

{state.currTree.subName}

{!state.loading && !state.content && (
)}
); }; }, }); const page = css` .page_title_box { position: relative; height: 500px; background-position: center; background-repeat: no-repeat; background-size: cover; transition: all 0.2s ease-in-out; &::after { content: ""; position: absolute; bottom: 0; left: 0; width: 100%; height: 220px; background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, #000000 100%); opacity: 0.7; z-index: 1; } .title { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 28px; z-index: 2; h1 { font-size: 36px; font-weight: 400; margin-bottom: 16px; color: #fff; } h2 { margin-bottom: 0; height: 1em; font-size: 14px; font-weight: 300; color: #fff; } } } .page_tabs_box { background-color: #fff; border-bottom: 1px solid #e5e5e5; } .page_content { padding: 50px 0; line-height: 1.5; img { display: inline; } } @media screen and (max-width: 1280px) { .page_title_box { height: 400px; .title { h1 { font-size: 28px; } } } } @media screen and (max-width: 750px) { .page_title_box { height: 320px; .title { h1 { font-size: 24px; } } } } `;