pref: router scroll behavior
This commit is contained in:
parent
3522321a00
commit
96f41e2ef2
|
@ -62,7 +62,7 @@ const handleRefreshPage = () => location.reload()
|
||||||
<div class="editor-advance">
|
<div class="editor-advance">
|
||||||
<div class="editor-advance-title">
|
<div class="editor-advance-title">
|
||||||
<Transition mode="out-in" name="slide-up">
|
<Transition mode="out-in" name="slide-up">
|
||||||
<span v-if="!isRefreshPage"> 编辑器模式 </span>
|
<span v-if="!isRefreshPage"> 编辑器配置 </span>
|
||||||
<span
|
<span
|
||||||
@click="handleRefreshPage"
|
@click="handleRefreshPage"
|
||||||
class="refresh"
|
class="refresh"
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import { defineAsyncComponent, computed, ref, onBeforeMount } from 'vue'
|
||||||
defineAsyncComponent,
|
|
||||||
computed,
|
|
||||||
ref,
|
|
||||||
onBeforeMount,
|
|
||||||
onBeforeUnmount,
|
|
||||||
onMounted,
|
|
||||||
} from 'vue'
|
|
||||||
import { QuillEditor } from '@vueup/vue-quill'
|
import { QuillEditor } from '@vueup/vue-quill'
|
||||||
|
|
||||||
// 自定义 quill 的两个主题,第二个主题暂时懒得动
|
// 自定义 quill 的两个主题,第二个主题暂时懒得动
|
||||||
|
@ -51,7 +44,7 @@ const props = defineProps<{
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
// 编辑器实例
|
// 编辑器实例
|
||||||
const editorRef = ref()
|
const editorRef = ref<typeof QuillEditor>()
|
||||||
|
|
||||||
// 编辑器的高度
|
// 编辑器的高度
|
||||||
const editorHeightStyle = computed(
|
const editorHeightStyle = computed(
|
||||||
|
@ -75,18 +68,6 @@ const editorOptions = {
|
||||||
// 编辑器实例创建时
|
// 编辑器实例创建时
|
||||||
const onEditorReady = () => {}
|
const onEditorReady = () => {}
|
||||||
|
|
||||||
// 工具栏相关配置
|
|
||||||
const toolbarOptions = {
|
|
||||||
container: [
|
|
||||||
['bold', 'italic', 'underline', 'strike'],
|
|
||||||
['markdown'], // Add this.
|
|
||||||
],
|
|
||||||
handlers: {
|
|
||||||
// Add this.
|
|
||||||
markdown: function () {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// 挂载之前载入数据,如果不保存,则不载入
|
// 挂载之前载入数据,如果不保存,则不载入
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
if (isSave.value) {
|
if (isSave.value) {
|
||||||
|
@ -97,18 +78,18 @@ onBeforeMount(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// 编辑器文本改变时自动保存数据
|
// 编辑器文本改变时自动保存数据
|
||||||
const handleTextChange = () => {
|
const handleTextChange = async () => {
|
||||||
// 创建一个防抖处理函数
|
// 创建一个防抖处理函数
|
||||||
const debouncedUpdateContent = debounce(() => {
|
const debouncedUpdateContent = debounce(() => {
|
||||||
// 过滤 xss
|
// 过滤 xss
|
||||||
content.value = DOMPurify.sanitize(editorRef.value.getHTML())
|
content.value = DOMPurify.sanitize(editorRef.value?.getHTML())
|
||||||
}, 1007)
|
}, 1007)
|
||||||
|
|
||||||
// 调用防抖处理函数,会在延迟时间内只执行一次更新操作
|
// 调用防抖处理函数,会在延迟时间内只执行一次更新操作
|
||||||
debouncedUpdateContent()
|
debouncedUpdateContent()
|
||||||
|
|
||||||
// 计算用户输入了多少个字符
|
// 计算用户输入了多少个字符
|
||||||
const length = computed(() => editorRef.value.getText().trim().length)
|
const length = computed(() => editorRef.value?.getText().trim().length)
|
||||||
textCount.value = length.value
|
textCount.value = length.value
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -5,6 +5,13 @@ import { asyncRoutes } from './router'
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(import.meta.env.BASE_URL),
|
history: createWebHistory(import.meta.env.BASE_URL),
|
||||||
routes: [...constantRoutes, ...asyncRoutes] as RouteRecordRaw[],
|
routes: [...constantRoutes, ...asyncRoutes] as RouteRecordRaw[],
|
||||||
|
scrollBehavior(to, from, savedPosition) {
|
||||||
|
if (savedPosition) {
|
||||||
|
return savedPosition
|
||||||
|
} else {
|
||||||
|
return { top: 0, behavior: 'smooth' }
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export function resetRouter() {
|
export function resetRouter() {
|
||||||
|
|
|
@ -94,9 +94,6 @@ watch(
|
||||||
/* 确保将离开的元素从布局流中删除
|
/* 确保将离开的元素从布局流中删除
|
||||||
以便能够正确地计算移动的动画。 */
|
以便能够正确地计算移动的动画。 */
|
||||||
.list-leave-active {
|
.list-leave-active {
|
||||||
/** 宽度为单个话题总宽度减去用户部分的宽度
|
|
||||||
这里为 2 + 5 + 60 + 5 + 2 = 74px */
|
|
||||||
width: calc(100% - 74px);
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue