diff --git a/src/components/TagsView/src/TagsView.vue b/src/components/TagsView/src/TagsView.vue index 7d52ab441..6c1af07e2 100644 --- a/src/components/TagsView/src/TagsView.vue +++ b/src/components/TagsView/src/TagsView.vue @@ -1,7 +1,7 @@ @@ -152,12 +260,14 @@ watch(
- +
+
- +
{{ t(item?.meta?.title as string) }} @@ -358,9 +469,8 @@ watch( position: relative; top: 2px; height: calc(~'100% - 4px'); - padding: 0 15px; + // padding: 0 15px; font-size: 12px; - line-height: calc(~'var( - -tags-view-height) - 4px'); cursor: pointer; border: 1px solid #d9d9d9; diff --git a/src/hooks/event/useScrollTo.ts b/src/hooks/event/useScrollTo.ts new file mode 100644 index 000000000..74fd673c8 --- /dev/null +++ b/src/hooks/event/useScrollTo.ts @@ -0,0 +1,62 @@ +import { ref, unref } from 'vue' + +export interface ScrollToParams { + el: HTMLElement + to: number + position: string + duration?: number + callback?: () => void +} + +const easeInOutQuad = (t: number, b: number, c: number, d: number) => { + t /= d / 2 + if (t < 1) { + return (c / 2) * t * t + b + } + t-- + return (-c / 2) * (t * (t - 2) - 1) + b +} +const move = (el: HTMLElement, position: string, amount: number) => { + el[position] = amount +} + +export function useScrollTo({ + el, + position = 'scrollLeft', + to, + duration = 500, + callback +}: ScrollToParams) { + const isActiveRef = ref(false) + const start = el[position] + const change = to - start + const increment = 20 + let currentTime = 0 + + function animateScroll() { + if (!unref(isActiveRef)) { + return + } + currentTime += increment + const val = easeInOutQuad(currentTime, start, change, duration) + move(el, position, val) + if (currentTime < duration && unref(isActiveRef)) { + requestAnimationFrame(animateScroll) + } else { + if (callback) { + callback() + } + } + } + + function run() { + isActiveRef.value = true + animateScroll() + } + + function stop() { + isActiveRef.value = false + } + + return { start: run, stop } +} diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index ec9d8eb09..22ca1a59a 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -53,7 +53,6 @@ export const usePermissionStore = defineStore({ // 直接读取静态路由表 routerMap = cloneDeep(asyncRouterMap) } - console.log(routerMap) // 动态路由,404一定要放到最后面 this.addRouters = routerMap.concat([ { diff --git a/src/store/modules/tagsView.ts b/src/store/modules/tagsView.ts index 66a779c70..51cb06cfd 100644 --- a/src/store/modules/tagsView.ts +++ b/src/store/modules/tagsView.ts @@ -124,6 +124,14 @@ export const useTagsViewStore = defineStore({ }) this.addCachedView() } + }, + updateVisitedView(view: RouteLocationNormalizedLoaded) { + for (let v of this.visitedViews) { + if (v.path === view.path) { + v = Object.assign(v, view) + break + } + } } } })