语言切换
Showing
3 changed files
with
22 additions
and
7 deletions
| ... | @@ -4,15 +4,17 @@ | ... | @@ -4,15 +4,17 @@ |
| 4 | </template> | 4 | </template> |
| 5 | 5 | ||
| 6 | <script setup> | 6 | <script setup> |
| 7 | import { nextTick, onMounted, watch } from 'vue' | 7 | import { nextTick, onMounted, watch} from 'vue' |
| 8 | import { handleThemeStyle } from '@/utils/theme' | 8 | import { handleThemeStyle } from '@/utils/theme' |
| 9 | import useSettingsStore from '@/store/modules/settings' | 9 | import useSettingsStore from '@/store/modules/settings' |
| 10 | import ResetPwd from '@/views/system/user/profile/components/resetPwd' | 10 | import ResetPwd from '@/views/system/user/profile/components/resetPwd' |
| 11 | import useUserStore from '@/store/modules/user' | 11 | import useUserStore from '@/store/modules/user' |
| 12 | import { getCurrentInstance } from '@vue/runtime-core' | 12 | import { getCurrentInstance } from '@vue/runtime-core' |
| 13 | import {useStorage} from "@vueuse/core"; | ||
| 13 | 14 | ||
| 14 | const userStore = useUserStore() | 15 | const userStore = useUserStore() |
| 15 | const { proxy } = getCurrentInstance() | 16 | const { proxy } = getCurrentInstance() |
| 17 | const language= useStorage('language',0) | ||
| 16 | 18 | ||
| 17 | onMounted(() => { | 19 | onMounted(() => { |
| 18 | document.body.style.setProperty('--el-color-primary', '#453DEA') | 20 | document.body.style.setProperty('--el-color-primary', '#453DEA') |
| ... | @@ -24,6 +26,10 @@ onMounted(() => { | ... | @@ -24,6 +26,10 @@ onMounted(() => { |
| 24 | }) | 26 | }) |
| 25 | }) | 27 | }) |
| 26 | 28 | ||
| 29 | watch(language,(val)=>{ | ||
| 30 | location.reload() | ||
| 31 | }) | ||
| 32 | |||
| 27 | // watch(() => userStore.user?.changePassFlag, (val) => { | 33 | // watch(() => userStore.user?.changePassFlag, (val) => { |
| 28 | // if (val === '1') { | 34 | // if (val === '1') { |
| 29 | // proxy.$modal.confirm('密码长期未更新,请及时更新').then(() => { | 35 | // proxy.$modal.confirm('密码长期未更新,请及时更新').then(() => { | ... | ... |
| ... | @@ -124,6 +124,8 @@ import Captcha from './captcha' | ... | @@ -124,6 +124,8 @@ import Captcha from './captcha' |
| 124 | import CaptchaSms from './captchaSms' | 124 | import CaptchaSms from './captchaSms' |
| 125 | import cache from '@/plugins/cache' | 125 | import cache from '@/plugins/cache' |
| 126 | import locale from 'element-plus/lib/locale/lang/zh-cn' | 126 | import locale from 'element-plus/lib/locale/lang/zh-cn' |
| 127 | import {useStorage} from "@vueuse/core"; | ||
| 128 | |||
| 127 | const router = useRouter() | 129 | const router = useRouter() |
| 128 | const route = useRoute() | 130 | const route = useRoute() |
| 129 | const { proxy } = getCurrentInstance() | 131 | const { proxy } = getCurrentInstance() |
| ... | @@ -134,6 +136,9 @@ const loginForm = ref({}) | ... | @@ -134,6 +136,9 @@ const loginForm = ref({}) |
| 134 | const drawer = ref(false) | 136 | const drawer = ref(false) |
| 135 | const mode = ref('horizontal') | 137 | const mode = ref('horizontal') |
| 136 | const language = ref(cache.local.get('language') || 0) | 138 | const language = ref(cache.local.get('language') || 0) |
| 139 | const language2 = useStorage('language', 0) | ||
| 140 | |||
| 141 | |||
| 137 | onMounted(() => { | 142 | onMounted(() => { |
| 138 | console.log(window.location.href) | 143 | console.log(window.location.href) |
| 139 | if (useUserStore().user) { | 144 | if (useUserStore().user) { |
| ... | @@ -159,9 +164,9 @@ onMounted(() => { | ... | @@ -159,9 +164,9 @@ onMounted(() => { |
| 159 | // console.log(activeIndex.value) | 164 | // console.log(activeIndex.value) |
| 160 | }) | 165 | }) |
| 161 | function changeLanguage(n) { | 166 | function changeLanguage(n) { |
| 162 | // language.value = n | 167 | proxy.$modal.loading() |
| 163 | cache.local.set('language', n) | 168 | language2.value = n |
| 164 | location.reload() | 169 | // cache.local.set('language', n) |
| 165 | } | 170 | } |
| 166 | function showDrawer() { | 171 | function showDrawer() { |
| 167 | drawer.value = true | 172 | drawer.value = true | ... | ... |
| ... | @@ -95,6 +95,8 @@ import Captcha from './captcha' | ... | @@ -95,6 +95,8 @@ import Captcha from './captcha' |
| 95 | import CaptchaSms from './captchaSms' | 95 | import CaptchaSms from './captchaSms' |
| 96 | import cache from '@/plugins/cache' | 96 | import cache from '@/plugins/cache' |
| 97 | import locale from 'element-plus/lib/locale/lang/zh-cn' | 97 | import locale from 'element-plus/lib/locale/lang/zh-cn' |
| 98 | import {useStorage} from "@vueuse/core/index"; | ||
| 99 | |||
| 98 | const router = useRouter() | 100 | const router = useRouter() |
| 99 | const route = useRoute() | 101 | const route = useRoute() |
| 100 | const { proxy } = getCurrentInstance() | 102 | const { proxy } = getCurrentInstance() |
| ... | @@ -105,6 +107,8 @@ const loginForm = ref({}) | ... | @@ -105,6 +107,8 @@ const loginForm = ref({}) |
| 105 | const drawer = ref(false) | 107 | const drawer = ref(false) |
| 106 | const mode = ref('horizontal') | 108 | const mode = ref('horizontal') |
| 107 | const language = ref(cache.local.get('language') || 0) | 109 | const language = ref(cache.local.get('language') || 0) |
| 110 | const language2 = useStorage('language', 0) | ||
| 111 | |||
| 108 | onMounted(() => { | 112 | onMounted(() => { |
| 109 | console.log(window.location.href) | 113 | console.log(window.location.href) |
| 110 | if (useUserStore().user) { | 114 | if (useUserStore().user) { |
| ... | @@ -130,9 +134,9 @@ onMounted(() => { | ... | @@ -130,9 +134,9 @@ onMounted(() => { |
| 130 | // console.log(activeIndex.value) | 134 | // console.log(activeIndex.value) |
| 131 | }) | 135 | }) |
| 132 | function changeLanguage(n) { | 136 | function changeLanguage(n) { |
| 133 | // language.value = n | 137 | proxy.$modal.loading() |
| 134 | cache.local.set('language', n) | 138 | language2.value = n |
| 135 | location.reload() | 139 | // cache.local.set('language', n) |
| 136 | } | 140 | } |
| 137 | function showDrawer() { | 141 | function showDrawer() { |
| 138 | drawer.value = true | 142 | drawer.value = true | ... | ... |
-
Please register or sign in to post a comment