Browse Source

feat: fix

gemercheung 6 months ago
parent
commit
16dd4d91ea

+ 1 - 1
packages/web/index.html

@@ -4,7 +4,7 @@
     <meta charset="UTF-8" />
     <link rel="shortcut icon" href="//4dkk.4dage.com/FDKKIMG/icon/kankan_icon.ico">
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-    <title>帮中心</title>
+    <title>帮中心</title>
   </head>
   <body>
     <div id="app"></div>

+ 26 - 5
packages/web/src/components/header.vue

@@ -34,7 +34,7 @@ const { t, locale } = useI18n()
 
 const keySearch = ref('')
 const router = useRouter()
-
+const route = useRoute()
 const options = ref([
   {
     label: t('zh'),
@@ -65,18 +65,39 @@ const searchOptions = computedAsync(
   null, // initial state
 )
 
-
-
 const handleSelect = (key: string) => {
   locale.value = key
   localStorage.setItem('locale', key)
-  location.reload();
 
+  router.replace({
+    name: route.name,
+    query: {
+      lang: key
+    }
+  })
+  setTimeout(() => {
+    location.reload();
+  }, 50)
 }
 onMounted(() => {
-  const localeValue = localStorage.getItem('locale') || 'en'
+  let localeValue = localStorage.getItem('locale') || 'zh'
+  if (route.query.lang) {
+    localeValue = String(route.query.lang)
+    locale.value = localeValue
+    localStorage.setItem('locale', localeValue)
+  }
+
   locale.value = String(localeValue)
   document.title = t('web_title')
+  console.log('route', route)
+  // route.query.lang = localeValue
+  router.replace({
+    name: route.name,
+    query: {
+      lang: localeValue
+    }
+  })
+
 
 })
 const handleAutoSelect = (index: number, list: any[]) => {

+ 27 - 2
packages/web/src/components/subHeader.vue

@@ -17,6 +17,8 @@ import { NDropdown, NButton } from 'naive-ui'
 // import { SearchOutline } from '@vicons/ionicons5'
 
 const { t, locale } = useI18n()
+const router = useRouter()
+const route = useRoute()
 
 const options = ref([
   {
@@ -32,13 +34,36 @@ const options = ref([
 const handleSelect = (key: string) => {
   locale.value = key
   localStorage.setItem('locale', key)
-  location.reload();
+
+  router.replace({
+    name: route.name,
+    query: {
+      lang: key
+    }
+  })
+  setTimeout(() => {
+    location.reload();
+  }, 50)
 
 }
 onMounted(() => {
-  const localeValue = localStorage.getItem('locale') || 'en'
+  let localeValue = localStorage.getItem('locale') || 'zh'
+  if (route.query.lang) {
+    localeValue = String(route.query.lang)
+    locale.value = localeValue
+    localStorage.setItem('locale', localeValue)
+  }
+
   locale.value = String(localeValue)
   document.title = t('web_title')
+  console.log('route', route)
+  // route.query.lang = localeValue
+  router.replace({
+    name: route.name,
+    query: {
+      lang: localeValue
+    }
+  })
 })
 </script>
 <style>