6 changed files with 60 additions and 45 deletions
-
1src/components/blogs/header/NavigateMenu.vue
-
78src/components/blogs/leftsite/CataloGue.vue
-
4src/stores/index.ts
-
1src/views/blog/ContentDetail.vue
-
2src/views/blog/blogcontent/BlogListView.vue
-
3src/views/blog/diarycontent/DiaryListView.vue
@ -1,42 +1,54 @@ |
|||||
<template> |
<template> |
||||
<div> |
|
||||
<div class="catalogue" v-for="anchor in titles" :style="{ padding: `4px 0 4px ${anchor.indent * 20}px` }" |
|
||||
@click="handleAnchorClick(anchor)" :key="anchor.lineIndex"> |
|
||||
<a style="cursor: pointer">{{ anchor.title }}</a> |
|
||||
</div> |
|
||||
|
<a-card title="目录列表" hoverable :bordered="false"> |
||||
|
<div class="catalogue" v-for="anchor in titles" :style="{ padding: `4px 0 4px ${anchor.indent * 20}px` }" |
||||
|
@click="handleAnchorClick(anchor)" @mouseover="handleMouseOver" @mouseleave="handleMouseLeave" |
||||
|
:key="anchor.lineIndex"> |
||||
|
<a class="link">{{ anchor.title }}</a> |
||||
</div> |
</div> |
||||
</template> |
|
||||
|
</a-card> |
||||
|
</template> |
||||
|
|
||||
<script setup lang="ts"> |
|
||||
import { computed } from 'vue'; |
|
||||
import { useContentStore } from '@/stores/index'; |
|
||||
|
<script setup lang="ts"> |
||||
|
import { computed,ref } from 'vue'; |
||||
|
import { useContentStore } from '@/stores/index'; |
||||
|
|
||||
const store = useContentStore(); |
|
||||
|
const store = useContentStore(); |
||||
|
const titles = computed(() => store.titles); |
||||
|
|
||||
const titles = computed(() => store.titles); |
|
||||
|
const handleAnchorClick = (anchor: { title: string; lineIndex: string }) => { |
||||
|
const heading = document.querySelector(`[data-v-md-line="${anchor.lineIndex}"]`); |
||||
|
|
||||
const handleAnchorClick = (anchor: { title: string; lineIndex: string }) => { |
|
||||
const heading = document.querySelector(`[data-v-md-line="${anchor.lineIndex}"]`); |
|
||||
|
if (heading) { |
||||
|
heading.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
||||
|
} else { |
||||
|
const observer = new MutationObserver((mutations, obs) => { |
||||
|
const heading = document.querySelector(`[data-v-md-line="${anchor.lineIndex}"]`); |
||||
|
if (heading) { |
||||
|
heading.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
||||
|
obs.disconnect(); |
||||
|
} |
||||
|
}); |
||||
|
const container = document.querySelector('#content-container') as HTMLElement; |
||||
|
observer.observe(container, { childList: true, subtree: true }); |
||||
|
} |
||||
|
}; |
||||
|
const handleMouseOver = (event: any) => { |
||||
|
const target = event.currentTarget as HTMLElement; |
||||
|
target.style.backgroundColor = '#f0f0f0'; |
||||
|
target.style.color = '#bd5b5b'; |
||||
|
} |
||||
|
|
||||
if (heading) { |
|
||||
heading.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
|
||||
} else { |
|
||||
const observer = new MutationObserver((mutations, obs) => { |
|
||||
const heading = document.querySelector(`[data-v-md-line="${anchor.lineIndex}"]`); |
|
||||
if (heading) { |
|
||||
heading.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
|
||||
obs.disconnect(); |
|
||||
} |
|
||||
}); |
|
||||
const container = document.querySelector('#content-container') as HTMLElement; |
|
||||
observer.observe(container, { childList: true, subtree: true }); |
|
||||
} |
|
||||
}; |
|
||||
</script> |
|
||||
|
const handleMouseLeave = (event: any) => { |
||||
|
const target = event.currentTarget as HTMLElement; |
||||
|
target.style.backgroundColor = '' |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
<style scoped> |
|
||||
.catalogue { |
|
||||
cursor: pointer; |
|
||||
} |
|
||||
</style> |
|
||||
|
<style scoped> |
||||
|
|
||||
|
.link{ |
||||
|
cursor: pointer; |
||||
|
color: rgb(115, 78, 34); |
||||
|
/* background-color: #bd5b5b; */ |
||||
|
} |
||||
|
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue