|
@@ -1,15 +1,45 @@
|
|
<template>
|
|
<template>
|
|
<div class="max-w-screen-xl content my-0 mx-auto text-size-base overflow-hidden">
|
|
<div class="max-w-screen-xl content my-0 mx-auto text-size-base overflow-hidden">
|
|
- <div v-if="detail" class="mt-[100px]">
|
|
|
|
|
|
+ <div v-if="detail">
|
|
|
|
+ <div class="breadcrumb my-[30px] pb-[20px] bb-1px_#EBEBEB" role="navigation">
|
|
|
|
+ <n-breadcrumb separator=">" v-if="breadcrumb">
|
|
|
|
+ <!-- {{ breadcrumb }}-->
|
|
|
|
+ <template v-for="(bread, index) in breadcrumb" :key="index">
|
|
|
|
+ <n-breadcrumb-item :clickable="false"> {{ bread.title }}</n-breadcrumb-item>
|
|
|
|
+ </template>
|
|
|
|
+ </n-breadcrumb>
|
|
|
|
+ </div>
|
|
|
|
+ <div v-if="currentCate">
|
|
|
|
+ <n-h2 class="mb-10"> {{ currentCate.title }}</n-h2>
|
|
|
|
+ </div>
|
|
<div class="w-full flex flex-row flex-nowrap">
|
|
<div class="w-full flex flex-row flex-nowrap">
|
|
- <div class="flex-basis-[240px] flex-grow-0 flex-shrink-0">
|
|
|
|
- <n-collapse accordion class="br-1px_#EBEBEB py-[10px]">
|
|
|
|
- <template v-for="(cate, index) in mainCategories.children" :key="index">
|
|
|
|
- <n-collapse-item :title="cate.title" :name="cate.title">
|
|
|
|
- <div class="px-4">{{ cate.title }}</div>
|
|
|
|
- </n-collapse-item>
|
|
|
|
- </template>
|
|
|
|
- </n-collapse>
|
|
|
|
|
|
+ <div class="flex-basis-[240px] flex-grow-0 flex-shrink-0 br-1px_#EBEBEB">
|
|
|
|
+ <n-tree
|
|
|
|
+ class="left-tree"
|
|
|
|
+ v-if="mainCategories.children"
|
|
|
|
+ block-line
|
|
|
|
+ :data="mainCategories.children"
|
|
|
|
+ :default-expanded-keys="defaultExpandedKeys"
|
|
|
|
+ :node-props="nodeProps"
|
|
|
|
+ key-field="id"
|
|
|
|
+ label-field="title"
|
|
|
|
+ children-field="children"
|
|
|
|
+ selectable
|
|
|
|
+ />
|
|
|
|
+ <!-- <n-collapse class="br-1px_#EBEBEB py-[10px]">-->
|
|
|
|
+ <!-- <template v-for="(cate, index) in mainCategories.children" :key="index">-->
|
|
|
|
+ <!-- <n-collapse-item :title="cate.title" :name="cate.title">-->
|
|
|
|
+ <!-- <n-collapse v-if="cate.children">-->
|
|
|
|
+ <!-- <template v-for="(cateChild, cIndex) in cate.children" :key="cIndex">-->
|
|
|
|
+ <!-- <n-collapse-item :title="cateChild.title" :name="cateChild.title">-->
|
|
|
|
+ <!-- <div class="px-6">{{ cateChild.title }}</div>-->
|
|
|
|
+ <!-- </n-collapse-item>-->
|
|
|
|
+ <!-- </template>-->
|
|
|
|
+ <!-- </n-collapse>-->
|
|
|
|
+ <!-- <div class="px-6" v-else>{{ cate.title }}</div>-->
|
|
|
|
+ <!-- </n-collapse-item>-->
|
|
|
|
+ <!-- </template>-->
|
|
|
|
+ <!-- </n-collapse>-->
|
|
</div>
|
|
</div>
|
|
<div class="flex-1 w-[calc(100%-80px)] px-[40px] mb-[120px] overflow-hidden">
|
|
<div class="flex-1 w-[calc(100%-80px)] px-[40px] mb-[120px] overflow-hidden">
|
|
<div class="bb-1px_#EBEBEB color-[#999999]">
|
|
<div class="bb-1px_#EBEBEB color-[#999999]">
|
|
@@ -36,8 +66,6 @@
|
|
>
|
|
>
|
|
</n-anchor-link>
|
|
</n-anchor-link>
|
|
</n-anchor>
|
|
</n-anchor>
|
|
-
|
|
|
|
- <!--{{ mainContents }}-->
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -62,21 +90,47 @@ import {
|
|
getArticleDetail,
|
|
getArticleDetail,
|
|
getArticleCount,
|
|
getArticleCount,
|
|
getCategoryTree,
|
|
getCategoryTree,
|
|
|
|
+ getArticlesByCateId,
|
|
} from '@/api'
|
|
} from '@/api'
|
|
-import { htmlToTree, createAnchorNames, dayjs } from '@/utils'
|
|
|
|
-import { NH1, NH4, NCollapse, NCollapseItem, NAnchor, NAnchorLink } from 'naive-ui'
|
|
|
|
|
|
+import { htmlToTree, createAnchorNames, dayjs, findNodeById, findBreadcrumbPath } from '@/utils'
|
|
|
|
+import { NH1, NH2, NH4, NBreadcrumb, NBreadcrumbItem, NTree, NAnchor, NAnchorLink } from 'naive-ui'
|
|
|
|
+import type { TreeOption } from 'naive-ui'
|
|
|
|
|
|
const route = useRoute()
|
|
const route = useRoute()
|
|
|
|
+const router = useRouter()
|
|
|
|
|
|
const params = route.params as {
|
|
const params = route.params as {
|
|
id?: number
|
|
id?: number
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+const breadcrumb = ref<CategoryItem[]>([])
|
|
console.log('route', route)
|
|
console.log('route', route)
|
|
const detail = ref<ArticleDetailType | undefined>()
|
|
const detail = ref<ArticleDetailType | undefined>()
|
|
const mainContents = ref<ArticleDetailMenuType[]>([])
|
|
const mainContents = ref<ArticleDetailMenuType[]>([])
|
|
-
|
|
|
|
|
|
+const currentCate = ref<CategoryItem | undefined>()
|
|
const mainCategories = ref<CategoryItem[]>([])
|
|
const mainCategories = ref<CategoryItem[]>([])
|
|
|
|
+const defaultExpandedKeys = ref<number[]>([])
|
|
|
|
+
|
|
|
|
+const nodeProps = ({ option }: { option: TreeOption }) => {
|
|
|
|
+ return {
|
|
|
|
+ async onClick() {
|
|
|
|
+ // window.$message.info(`[Click] ${option.title},[ID] ${option.id} `)
|
|
|
|
+ const res = await getArticlesByCateId(+(option.id as string))
|
|
|
|
+ // console.log(res.data)
|
|
|
|
+ if (res.data && res.data.length > 0) {
|
|
|
|
+ const articleId = res.data[0].id
|
|
|
|
+ console.log('articleId', articleId)
|
|
|
|
+ // location.reload()
|
|
|
|
+ router.replace(`/showdoc/${articleId}`)
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ location.reload()
|
|
|
|
+ }, 500)
|
|
|
|
+ } else {
|
|
|
|
+ window.$message.info(`当前类别没有相关联的文章!`)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
const html = document.querySelector('.content-html')
|
|
const html = document.querySelector('.content-html')
|
|
@@ -100,6 +154,15 @@ watchEffect(() => {
|
|
const res = await getCategoryTree(detail.value.categoryId)
|
|
const res = await getCategoryTree(detail.value.categoryId)
|
|
if (res.data) {
|
|
if (res.data) {
|
|
mainCategories.value = res.data as CategoryItem[]
|
|
mainCategories.value = res.data as CategoryItem[]
|
|
|
|
+ if (mainCategories.value) {
|
|
|
|
+ currentCate.value = findNodeById(
|
|
|
|
+ [mainCategories.value],
|
|
|
|
+ detail.value.categoryId,
|
|
|
|
+ ) as unknown as CategoryItem
|
|
|
|
+ defaultExpandedKeys.value = [currentCate.value.parentId]
|
|
|
|
+ breadcrumb.value = findBreadcrumbPath([mainCategories.value], detail.value.categoryId)
|
|
|
|
+ // console.log('breadcrumb', breadcrumb.value)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -113,4 +176,15 @@ watchEffect(() => {
|
|
width: 100% !important;
|
|
width: 100% !important;
|
|
height: auto;
|
|
height: auto;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+:deep(.left-tree) {
|
|
|
|
+ --n-node-content-height: 40px !important;
|
|
|
|
+ //--n-node-color-hover: rgba(6,97,201,0.06) !important;
|
|
|
|
+ //border-right: 1px solid #e5e7eb;
|
|
|
|
+
|
|
|
|
+ .n-tree-node-wrapper {
|
|
|
|
+ width: 240px;
|
|
|
|
+ font-size: 16px;
|
|
|
|
+ }
|
|
|
|
+}
|
|
</style>
|
|
</style>
|