18
18
</template >
19
19
<a-col :xxl =" 20" :xl =" 19" :lg =" 18" :md =" 18" :sm =" 24" :xs =" 24" >
20
20
<section :class =" mainContainerClass" >
21
- <router-view />
21
+ <Demo v-if =" isDemo" :pageData =" pageData" :isZhCN =" isZhCN" >
22
+ <component :is =" matchCom" />
23
+ </Demo >
24
+ <router-view v-else />
22
25
<a-affix v-if =" headers.length" class =" toc-affix" :offsetTop =" 20" >
23
26
<a-anchor >
24
27
<a-anchor-link
25
28
v-for =" h in headers"
26
29
:key =" h.title"
27
- :href =" `#${h.title}`"
30
+ :href =" h.href || `#${h.title}`"
28
31
:title =" h.title"
29
32
></a-anchor-link >
30
33
</a-anchor >
39
42
<script lang="ts">
40
43
import { GlobalConfig } from ' @/App.vue' ;
41
44
import { GLOBAL_CONFIG } from ' @/SymbolKey' ;
42
- import { defineComponent , inject , computed } from ' vue' ;
45
+ import { defineComponent , inject , computed , ref , provide , watch } from ' vue' ;
43
46
import { useRoute , useRouter } from ' vue-router' ;
44
47
import Header from ' ./header/index.vue' ;
45
48
import Footer from ' ./Footer.vue' ;
46
49
import Menu from ' ./Menu.vue' ;
47
50
import PrevAndNext from ' ./PrevAndNext.vue' ;
51
+ import Demo from ' ./Demo.vue' ;
48
52
export default defineComponent ({
49
53
name: ' Layout' ,
50
54
setup() {
51
55
const route = useRoute ();
52
56
const router = useRouter ();
53
57
const routes = router .getRoutes ();
58
+ const globalConfig = inject <GlobalConfig >(GLOBAL_CONFIG );
54
59
const menus = computed (() => {
55
60
const path = route .path ;
56
61
const category = path .split (' /' )[1 ];
@@ -59,6 +64,19 @@ export default defineComponent({
59
64
.map (r => ({ ... r .meta , path: r .path .split (' :lang' )[0 ] }));
60
65
});
61
66
67
+ const demos = ref ([]);
68
+
69
+ provide (' addDemosInfo' , info => {
70
+ demos .value .push (info );
71
+ });
72
+
73
+ watch (
74
+ () => route .path ,
75
+ () => {
76
+ demos .value .length = 0 ;
77
+ },
78
+ );
79
+
62
80
const activeMenuItem = computed (() => {
63
81
return route .path .split (' -cn' )[0 ];
64
82
});
@@ -74,25 +92,41 @@ export default defineComponent({
74
92
const matchCom = computed (() => {
75
93
return route .matched [route .matched .length - 1 ]?.components ?.default as any ;
76
94
});
77
- console .log (matchCom );
95
+ const isZhCN = globalConfig .isZhCN ;
96
+ const pageData = computed (() =>
97
+ isDemo .value
98
+ ? matchCom .value [isZhCN .value ? ' CN' : ' US' ]?.pageData
99
+ : matchCom .value ?.pageData ,
100
+ );
78
101
const headers = computed (() => {
79
- return (matchCom .value ?.pageData ?.headers || []).filter (h => h .level === 2 );
102
+ if (isDemo .value ) {
103
+ return [... demos .value , { title: ' API' , href: ' #API' }];
104
+ } else {
105
+ return (pageData .value ?.headers || []).filter (h => h .level === 2 );
106
+ }
80
107
});
81
- const globalConfig = inject <GlobalConfig >(GLOBAL_CONFIG );
82
- return {
83
- isMobile: globalConfig .isMobile ,
84
- isZhCN: globalConfig .isZhCN ,
85
- mainContainerClass: {
108
+
109
+ const mainContainerClass = computed (() => {
110
+ return {
86
111
' main-container' : true ,
87
112
' main-container-component' : isDemo .value ,
88
- },
113
+ };
114
+ });
115
+ return {
116
+ isMobile: globalConfig .isMobile ,
117
+ isZhCN ,
118
+ mainContainerClass ,
89
119
menus ,
90
120
currentMenuIndex ,
91
121
activeMenuItem ,
92
122
headers ,
123
+ isDemo ,
124
+ matchCom ,
125
+ pageData ,
93
126
};
94
127
},
95
128
components: {
129
+ Demo ,
96
130
Header ,
97
131
Footer ,
98
132
Menu ,
0 commit comments