1414 <div class =" main-banner-menus-container" >
1515 <div class =" main-banner-menus" >
1616 <span
17- v-for =" item in menus"
17+ v-for =" item in currentLocal. menus"
1818 :key =" item.name"
1919 :class =" [
2020 'main-banner-menu-item',
119119 </div >
120120 </span >
121121
122+ <!-- switch theme -->
123+ <span class =" main-banner-menu-item" >
124+ <div
125+ v-click-outside ="
126+ () => (showThemeDropdown = false)
127+ "
128+ class =" switch-theme-container"
129+ >
130+ <span
131+ class =" switch-theme"
132+ @click ="
133+ showThemeDropdown = !showThemeDropdown
134+ "
135+ >
136+ {{ currentLocal.docTheme }}
137+ <i class =" icon iconfont icon-dropdown" />
138+ </span >
139+ <div
140+ class =" switch-theme-dropdown-pannel"
141+ :class ="
142+ showThemeDropdown
143+ ? 'dropdown-pannel-show'
144+ : ''
145+ "
146+ >
147+ <span
148+ v-for =" item in currentLocal.switchDocThemeOptions"
149+ :key =" item.value"
150+ :class =" [
151+ 'dropdown-item',
152+ {
153+ active:
154+ item.value ===
155+ currentDocTheme,
156+ },
157+ ]"
158+ @click.stop =" themeChange(item)"
159+ >
160+ {{ item.label }}
161+ </span >
162+ </div >
163+ </div >
164+ </span >
165+
122166 <span class =" main-banner-menu-item" >
123167 <a
124168 class =" main-banner-menu-link"
139183</template >
140184
141185<script >
186+ import { getDocTheme , setDocTheme } from " @/utils/cookies" ;
142187import locale from " ./locale" ;
143188import I18nMixins from " ./mixins/i18n-mixins" ;
144189import ThemeSwitchMixins from " ./mixins/theme-switch-mixins.js" ;
@@ -159,16 +204,23 @@ export default {
159204 { value: " en" , label: " English" },
160205 { value: " zh" , label: " 简体中文" },
161206 ],
207+ // show lang dropdown
162208 showLangDropdown: false ,
163- // switch version option
209+ // switch version option,
164210 switchVersionOptions: [],
165211 showVersionDropdown: false ,
212+ // show theme dropdown
213+ showThemeDropdown: false ,
214+ // default doc theme
215+ defalutDocTheme: " default" ,
216+ // current doc theme
217+ currentDocTheme: " " ,
166218 };
167219 },
168220 computed: {
169- // menus
170- menus () {
171- return locale[this .currentDocLang ][ " menus " ] ;
221+ // current local
222+ currentLocal () {
223+ return locale[this .currentDocLang ];
172224 },
173225
174226 // show logo
@@ -213,6 +265,21 @@ export default {
213265 this .showLangDropdown = false ;
214266 }, 150 );
215267 },
268+ // theme change
269+ themeChange ({ value }) {
270+ setDocTheme (value);
271+ this .showThemeDropdown = false ;
272+
273+ if (window .env === " dev" ) {
274+ setTimeout (() => {
275+ window .location .reload ();
276+ });
277+ } else {
278+ this .switchThemeMix (value).finally (() => {
279+ // this.loadingInstance.close();
280+ });
281+ }
282+ },
216283 // version change
217284 versionChange (item ) {
218285 const { protocol , host , pathname , hash } = window .location ;
@@ -250,11 +317,23 @@ export default {
250317 }
251318 return result;
252319 },
320+ // init theme
321+ initDocTheme () {
322+ this .currentDocTheme = getDocTheme () ?? this .defalutDocTheme ;
323+ // 初始化
324+ if (window .env != " dev" ) {
325+ this .switchThemeMix (this .currentDocTheme );
326+ }
327+ console .log (" current doc theme ::" , this .currentDocTheme );
328+ },
253329 },
254330 created () {
255331 getVersions ().then (({ data }) => {
256332 this .switchVersionOptions = data;
257333 });
258334 },
335+ mounted () {
336+ this .initDocTheme ();
337+ },
259338};
260339< / script>
0 commit comments