新版本官网优化完成
This commit is contained in:
72
pages/page/[id].vue
Normal file
72
pages/page/[id].vue
Normal file
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<!-- Banner -->
|
||||
<Banner :layout="layout" />
|
||||
<!-- 主体部分 -->
|
||||
<div class="xl:w-screen-xl m-auto py-4 mt-2">
|
||||
<el-page-header :icon="ArrowLeft" @back="goBack">
|
||||
<template #content>
|
||||
<span class="text-large font-600 mr-3"> {{ page.title }} </span>
|
||||
</template>
|
||||
<el-card shadow="hover" class=" my-5">
|
||||
<!-- 内容组件 -->
|
||||
<Content class="content bg-white mt-5" :data="page.design?.content" />
|
||||
</el-card>
|
||||
</el-page-header>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import {useLayout, usePage} from "~/composables/configState";
|
||||
import type {CmsNavigation} from "~/api/cms/cmsNavigation/model";
|
||||
import {getNavIdByParamsId, getViews, paramsId} from "~/utils/common";
|
||||
import Left from "~/components/Left.vue";
|
||||
import { ArrowLeft,View } from '@element-plus/icons-vue'
|
||||
import {getCmsNavigation, listCmsNavigation} from "~/api/cms/cmsNavigation";
|
||||
import Content from "~/components/Content.vue";
|
||||
|
||||
// 引入状态管理
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const navId = ref();
|
||||
const layout = useLayout();
|
||||
const page = usePage();
|
||||
const category = ref<CmsNavigation[]>([]);
|
||||
|
||||
const goBack = () => {
|
||||
router.back();
|
||||
}
|
||||
|
||||
// 加载页面布局
|
||||
const reload = async () => {
|
||||
getCmsNavigation(navId.value).then(data => {
|
||||
page.value = data
|
||||
layout.value.banner = data.banner;
|
||||
// 二级栏目分类
|
||||
if(data.parentId && data.parentId > 0){
|
||||
listCmsNavigation({
|
||||
parentId: data.parentId == 0 ? data.navigationId : data.parentId
|
||||
}).then(list => {
|
||||
category.value = list
|
||||
})
|
||||
}
|
||||
// seo
|
||||
useSeoMeta({
|
||||
description: data.comments || data.title,
|
||||
keywords: data.title,
|
||||
titleTemplate: `${data?.title}` + ' - %s',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
(id) => {
|
||||
navId.value = getNavIdByParamsId(id);
|
||||
reload();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
</style>
|
||||
@@ -1,76 +0,0 @@
|
||||
<template>
|
||||
<!-- Banner -->
|
||||
<Banner :layout="layout" />
|
||||
|
||||
<!-- 简单模式(常规单页面) -->
|
||||
<PageContainer :form="form" :layout="layout" />
|
||||
|
||||
<!-- 高级模式(自定义组件) -->
|
||||
<div class="flex flex-col" v-if="layout?.showLayout">
|
||||
{{ layout }}
|
||||
</div>
|
||||
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import type {ApiResult} from "~/api";
|
||||
import {useServerRequest} from "~/composables/useServerRequest";
|
||||
import {useConfigInfo, useForm, useToken, useWebsite} from "~/composables/configState";
|
||||
import type {BreadcrumbItem} from "~/types/global";
|
||||
import type {Navigation} from "~/api/cms/navigation/model";
|
||||
import {getIdBySpm} from "~/utils/common";
|
||||
import PageContainer from "~/components/PageContainer.vue";
|
||||
|
||||
// 引入状态管理
|
||||
const route = useRoute();
|
||||
const website = useWebsite();
|
||||
const layout = ref<any>();
|
||||
const config = useConfigInfo();
|
||||
const token = useToken();
|
||||
const form = useForm();
|
||||
const breadcrumb = ref<BreadcrumbItem>();
|
||||
|
||||
// 请求数据
|
||||
const reload = async () => {
|
||||
|
||||
// 存在spm(优先级高)
|
||||
const { data: nav } = await useServerRequest<ApiResult<Navigation>>('/cms/cms-navigation/' + getIdBySpm(5))
|
||||
if (nav.value?.data) {
|
||||
form.value = nav.value.data
|
||||
}else{
|
||||
const { data: nav } = await useServerRequest<ApiResult<Navigation>>('/cms/cms-navigation/getNavigationByPath',{query: {path: route.path}})
|
||||
if(nav.value?.data){
|
||||
form.value = nav.value?.data;
|
||||
}
|
||||
}
|
||||
// 页面布局
|
||||
if(form.value?.layout){
|
||||
layout.value = JSON.parse(form.value?.layout)
|
||||
}
|
||||
|
||||
// seo
|
||||
useHead({
|
||||
title: `${form.value.title} - ${website.value.websiteName}`,
|
||||
meta: [{ name: form.value.design?.keywords, content: form.value.design?.description }],
|
||||
bodyAttrs: {
|
||||
class: "page-container",
|
||||
},
|
||||
script: [
|
||||
{
|
||||
children: `console.log(${JSON.stringify(form.value)})`,
|
||||
},
|
||||
],
|
||||
});
|
||||
// 面包屑
|
||||
breadcrumb.value = form.value
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
(path) => {
|
||||
console.log(path,'=>Path')
|
||||
|
||||
reload();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
Reference in New Issue
Block a user