LangeSelect.vue
2.68 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
<el-dropdown v-if="!login" trigger="click" class="international" @command="handleSetLanguage">
<div>
<span class="el-dropdown-link">
{{language}}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="zh_CN">简体</el-dropdown-item>
<el-dropdown-item command="zh_TW">繁體</el-dropdown-item>
<el-dropdown-item command="en_US">English</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<div v-else class="login-change">
<div class="item" v-for="(item, idx) in lans" :key="idx"
:style="{
color: language === item.label ? '#69C0FF' : '#fff',
marginRight: idx === 2 ? 0 : '32px'
}" @click="handleSetLanguage(item.key)">{{ item.name }}</div>
</div>
</template>
<script>
export default {
inject: ["reload"],
props: {
login: Boolean
},
data() {
return {
language: "",
lans: [
{
name: '简体中文',
label: '简体',
key: 'zh_CN'
},
{
name: '繁體中文',
label: '繁體',
key: 'zh_TW'
},
{
name: 'English',
label: 'English',
key: 'en_US'
}
]
};
},
mounted() {
this.$nextTick(()=>{
setTimeout(()=>{
let _lang = "";
_lang = localStorage.getItem("lang");
this.$i18n.locale = _lang;
this.getLanguage(_lang);
document.title = this.$t('login.platformName')
},1000)
})
},
methods: {
handleSetLanguage(lang) {
this.$i18n.locale = lang;
localStorage.setItem("lang", lang);
this.reload();
this.getLanguage(lang);
},
getLanguage(val) {
document.title = this.$t('login.platformName')
if (val === "zh_CN" || val === "mall_CN") {
this.language = "简体";
}
if (val === "en_US") {
this.language = "English";
}
if (val === "zh_TW") {
this.language = "繁體";
}
},
}
};
</script>
<style>
.international .el-dropdown-link {
cursor: pointer;
color: #fff;
font-size: 14px;
margin-left: 20px;
margin-right: 20px;
}
.el-icon-arrow-down {
font-size: 14px;
}
.en-class {
padding-left: 0.6rem !important;
}
.en-icon {
left: 250px;
}
</style>
<style scoped>
.international-icon {
font-size: 20px;
cursor: pointer;
vertical-align: -5px !important;
}
.login-change {
display: flex;
}
.login-change .item {
font-size: 15px;
line-height: 18px;
cursor: pointer;
}
@media only screen and (max-width: 1280px) {
.international .el-dropdown-link {
font-size: 13px;
margin-left: 10px;
}
}
</style>