zzzz
2024-04-25 129535fe29ba25a1f40b90fcf5bc7606ea127a67
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>
  <div>
    <van-popup
      v-model="settingDialog"
      position="bottom"
      :style="{ height: '35%' }"
      @close="popClose"
    >
      <div
        class="lang_box"
        v-for="(item, index) in actions"
        :key="index"
        @click="qkclick(item)"
      >
        <div
          :class="$i18n.locale == item.lang ? 'lang_box_txt' : 'lang_box_txta'"
        >
          {{ item.text }}
        </div>
      </div>
    </van-popup>
  </div>
</template>
 
<script>
/*
 *name onChange
 *回应外面
 *
 * */
export default {
  data() {
    return {
      settingDialog: false,
      language: "",
      // 多语言配置
      actions: [
        {
          text: "English",
          lang: "en",
        },
        {
          text: "简体中文",
          lang: "zh-CN",
        },
        { text: "हिंदी", lang: "hi" },
        {
          text: "Deutsch",
          lang: "de",
        }, //德语
        {
          text: "Français",
          lang: "fr",
        }, //法语
        {
          text: "日本語にほんご",
          lang: "ja",
        },
      ],
    };
  },
  mounted() {
    this.$emit(
      "onChange",
      this.getText(window.localStorage.getItem("language"))
    );
  },
  methods: {
    getText(val = "hi") {
      let arr = this.actions.filter((item) => item.lang === val);
      return arr[0].text;
    },
    qkclick(e) {
      this.settingDialog = false;
      window.localStorage.setItem("language", e.lang);
      this.$i18n.locale = e.lang;
      this.$emit("onChange", e.text);
    },
    popClose() {
      this.settingDialog = false;
    },
  },
};
</script>
 
<style>
.lang_box_txta {
  width: 100%;
  height: 100px;
  text-align: center;
  line-height: 100px;
  border-bottom: 1px solid #ecf5ff;
}
.lang_box_txt {
  width: 100%;
  height: 100px;
  text-align: center;
  line-height: 100px;
  border-bottom: 1px solid #ecf5ff;
  color: #2196f3;
}
.lang_box {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.btn_s_box {
  border: none;
  background: #409eff;
  color: #fff;
  height: 70px;
  width: 100%;
  line-height: 70px;
  font-size: 16px;
  text-align: center;
  border-radius: 15px;
  font-weight: 600;
  margin: 40px 20px 0 20px;
}
</style>