wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<script lang="ts" setup>
import icon_done_outlined from '@/assets/svg/icon_done_outlined.svg'
import { ref, onMounted, reactive } from 'vue'
import { Icon } from '@/components/icon-custom'
import { useUserStoreWithOut } from '@/store/modules/user'
import { usePermissionStoreWithOut } from '@/store/modules/permission'
import { useLocaleStoreWithOut } from '@/store/modules/locale'
import { switchLangApi } from '@/api/user'
const permissionStore = usePermissionStoreWithOut()
const userStore = useUserStoreWithOut()
const localeStore = useLocaleStoreWithOut()
 
const language = ref(null)
const handleSetLanguage = lang => {
  const param = { lang }
  switchLangApi(param).then(res => {
    if (!res.msg) {
      language.value = lang
      userStore.setLanguage(lang)
      permissionStore.$reset()
      window.location.reload()
    }
  })
}
 
const options = reactive([])
 
onMounted(async () => {
  language.value = userStore.getLanguage
  const localeMap = await localeStore.getLocaleMap
  localeMap.forEach(item => {
    const option = { value: item['lang'], name: item['name'] }
    options.push(option)
  })
})
</script>
<template>
  <div class="language-container">
    <div
      v-for="item in options"
      :key="item.value"
      class="language-item"
      :class="{ active: language === item.value }"
      @click="handleSetLanguage(item.value)"
    >
      <span>{{ item.name }}</span>
      <el-icon v-if="language === item.value">
        <Icon name="icon_done_outlined"><icon_done_outlined class="svg-icon" /></Icon>
      </el-icon>
    </div>
  </div>
</template>
 
<style lang="less" scoped>
.language-item {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  &:hover {
    cursor: pointer;
    background-color: #f2f2f2;
  }
}
.active {
  color: var(--ed-color-primary) !important;
}
</style>