Skip to content

Commit 32c09ab

Browse files
HouLiXieBuRouSkyBird233
authored andcommitted
fix: 跳转高亮修复并抽象出函数,现在每个页面不必要手动 watch;跳转滚动修复
1 parent e1c1530 commit 32c09ab

File tree

6 files changed

+54
-65
lines changed

6 files changed

+54
-65
lines changed

src/App.vue

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const router = useRouter();
1212
router.afterEach((to, from) => {
1313
highBrightnessControllerStore.obj[to.path] =
1414
!highBrightnessControllerStore.obj[to.path];
15+
console.log(highBrightnessControllerStore.obj[to.path], 2);
1516
});
1617
1718
const themeStore = useThemeStore();

src/components/AppSupport.vue

+9-16
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import AppLink from './AppLink.vue';
33
import CategorySecond from '../components/CategorySecond.vue';
44
import highlightElement from '../utils/animation';
5-
import { ref, watch } from 'vue';
6-
import { useHighBrightnessControllerStore } from '../stores/miscellaneous';
5+
import { ref } from 'vue';
76
import { useRoute } from 'vue-router';
7+
import { useHighlightWatch } from '../utils/utils';
88
99
const route = useRoute();
1010
@@ -14,21 +14,14 @@ const props = defineProps({
1414
required: true
1515
}
1616
});
17-
const highBrightnessControllerStore = useHighBrightnessControllerStore();
18-
19-
watch(
20-
() => highBrightnessControllerStore.obj[route.path],
21-
() => {
22-
switch (route.hash) {
23-
case '#support':
24-
highlightElement(support);
25-
break;
26-
}
27-
},
28-
{
29-
flush: 'post'
17+
const switchHash = () => {
18+
switch (route.hash) {
19+
case '#support':
20+
highlightElement(support);
21+
break;
3022
}
31-
);
23+
};
24+
useHighlightWatch(switchHash);
3225
3326
const support = ref();
3427
</script>

src/pages/afterglow/AfterglowIndex.vue

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
<script setup>
2-
import { reactive, ref, watch } from 'vue';
2+
import { reactive, ref } from 'vue';
33
import CategorySecond from '../../components/CategorySecond.vue';
44
import AppH2 from '../../components/AppH2.vue';
55
import { useRoute } from 'vue-router';
66
import highlightElement from '../../utils/animation';
77
import { useHighBrightnessControllerStore } from '../../stores/miscellaneous';
88
import AppSupport from '../../components/AppSupport.vue';
99
import AccordionNavigation from '../../components/AccordionNavigation.vue';
10-
import { onImgLoad, useSeizeSeat } from '../../utils/utils';
10+
import { onImgLoad, useHighlightWatch, useSeizeSeat } from '../../utils/utils';
1111
1212
const route = useRoute();
1313
1414
const features = ref();
1515
16-
const highBrightnessControllerStore = useHighBrightnessControllerStore();
17-
18-
watch(
19-
() => highBrightnessControllerStore.obj[route.path],
20-
() => {
21-
switch (route.hash) {
22-
case '#features':
23-
highlightElement(features);
24-
break;
25-
}
26-
},
27-
{
28-
flush: 'post'
16+
const switchHash = () => {
17+
switch (route.hash) {
18+
case '#features':
19+
highlightElement(features);
20+
break;
2921
}
30-
);
22+
};
23+
useHighlightWatch(switchHash);
3124
3225
const navigationList = [
3326
{

src/pages/aosc-os/AoscIndex.vue

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
<script setup>
2-
import { reactive, ref, watch } from 'vue';
2+
import { reactive, ref } from 'vue';
33
import CategorySecond from '../../components/CategorySecond.vue';
44
import AppH2 from '../../components/AppH2.vue';
55
import { useRoute } from 'vue-router';
66
import highlightElement from '../../utils/animation';
7-
import { useHighBrightnessControllerStore } from '../../stores/miscellaneous';
87
import AppSupport from '../../components/AppSupport.vue';
98
import AccordionNavigation from '../../components/AccordionNavigation.vue';
10-
import { onImgLoad, useSeizeSeat } from '../../utils/utils';
9+
import { onImgLoad, useHighlightWatch, useSeizeSeat } from '../../utils/utils';
1110
1211
const route = useRoute();
1312
1413
const features = ref();
1514
16-
const highBrightnessControllerStore = useHighBrightnessControllerStore();
17-
18-
watch(
19-
() => highBrightnessControllerStore.obj[route.path],
20-
() => {
21-
switch (route.hash) {
22-
case '#features':
23-
highlightElement(features);
24-
break;
25-
}
26-
},
27-
{
28-
flush: 'post'
15+
const switchHash = () => {
16+
switch (route.hash) {
17+
case '#features':
18+
highlightElement(features);
19+
break;
2920
}
30-
);
21+
};
22+
23+
useHighlightWatch(switchHash);
3124
3225
const navigationList = [
3326
{

src/pages/download/DownloadIndex.vue

+5-16
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import CategorySecond from '../../components/CategorySecond.vue';
33
import TitleComponent from './components/TitleComponent.vue';
44
import DownloadButtonGroup from './components/DownloadButtonGroup.vue';
55
import WslDetails from './components/WslDetails.vue';
6-
import { ref, useTemplateRef, watch, computed } from 'vue';
6+
import { ref, useTemplateRef , computed } from 'vue';
77
import DownloadButton from './components/DownloadButton.vue';
88
import { useRoute } from 'vue-router';
99
import useClipboard from 'vue-clipboard3';
1010
import { ElMessage, ElDialog } from 'element-plus';
11-
import { useHighBrightnessControllerStore } from '../../stores/miscellaneous.js';
1211
import { useDownloadPageStore } from '../../stores/download-page.js';
1312
import { highlightElement } from '../../utils/animation.ts';
14-
import { requestGetJson } from '../../utils/utils.js';
13+
import { requestGetJson, useHighlightWatch } from '../../utils/utils.js';
1514
1615
//#region Common
1716
const archGroupInfo = {
@@ -45,8 +44,6 @@ const otherRef = useTemplateRef('otherDownload');
4544
const afterglowRef = useTemplateRef('afterglowDownload');
4645
const omaRef = useTemplateRef('omaDownload');
4746
48-
const highBrightnessControllerStore = useHighBrightnessControllerStore();
49-
5047
const switchHash = () => {
5148
switch (route.hash) {
5249
case '#aosc-os-download':
@@ -63,16 +60,7 @@ const switchHash = () => {
6360
break;
6461
}
6562
};
66-
67-
watch(
68-
() => highBrightnessControllerStore.obj[route.path],
69-
() => {
70-
switchHash();
71-
},
72-
{
73-
flush: 'post'
74-
}
75-
);
63+
useHighlightWatch(switchHash);
7664
//#endregion
7765
7866
//#region remote
@@ -533,6 +521,7 @@ const omaInstallScript = 'curl -sSf https://repo.aosc.io/get-oma.sh | sudo sh';
533521

534522
<!-- Afterglow -->
535523
<div
524+
id="afterglow-download"
536525
ref="afterglowDownload"
537526
class="afterglow-container flex flex-wrap justify-between p-[30px] text-white gap-6">
538527
<TitleComponent
@@ -570,7 +559,7 @@ const omaInstallScript = 'curl -sSf https://repo.aosc.io/get-oma.sh | sudo sh';
570559
<category-second class="highlight" title="实用工具" />
571560

572561
<!-- oma -->
573-
<div ref="omaDownload" class="oma-container p-[30px]">
562+
<div id="oma-download" ref="omaDownload" class="oma-container p-[30px]">
574563
<TitleComponent
575564
title="小熊猫包管理 (oma)"
576565
description="简明好用的 APT 软件包管理界面"

src/utils/utils.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import router from '../router.js';
2+
import { watch } from 'vue';
23
import axios from 'axios';
4+
import { useRoute } from 'vue-router';
35
import { ElMessage } from 'element-plus';
46
import yaml from 'js-yaml';
57
import {
@@ -10,6 +12,7 @@ import {
1012
toValue,
1113
useTemplateRef
1214
} from 'vue';
15+
import { useHighBrightnessControllerStore } from '../stores/miscellaneous.js';
1316

1417
export function getImgUrl(url) {
1518
return new URL(`${url}`, import.meta.url).href;
@@ -178,3 +181,20 @@ export const useSeizeSeat = (refName, proportion, imgHeights, fixedHeight) => {
178181
});
179182
return [observer, imgHeights];
180183
};
184+
185+
export const useHighlightWatch = (switchHash) => {
186+
const highBrightnessControllerStore = useHighBrightnessControllerStore();
187+
const route = useRoute();
188+
watch(
189+
() => highBrightnessControllerStore.obj[route.path.replace(/\/+$/, '')],
190+
() => {
191+
switchHash();
192+
},
193+
{
194+
flush: 'post'
195+
}
196+
);
197+
onMounted(() => {
198+
switchHash();
199+
});
200+
};

0 commit comments

Comments
 (0)