cuiqian2004
2024-09-27 6a6229d218b31219b260c250a10ee58e51f56587
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
<template>
    <view class="uni-page-login-language">
        <view class="uni-line" v-for="item in langList" :key='item.value' @click="clickLanguage(item.value)"><text
                class="name">{{item.name }}</text> <uni-icons v-if="curLang==item.value " type="checkmarkempty"
                :size="20"></uni-icons> </view>
    </view>
</template>
 
<script>
    import utils from "@/js/utils.js"
    export default {
        data() {
            return {
                langList: [{
                        value: "zh-Hans",
                        name: "中文简体"
                    }, {
                        value: "zh-Hant",
                        name: "中文繁体"
                    }, {
                        value: "en",
                        name: "English"
                    },
                    {
                        value: "es",
                        name: "Español"
                    }
                ],
                curLang: "",
                oldLang: "",
            }
        },
        methods: {
            clickLanguage(lang) {
                this.curLang = lang
                const _this = this
                uni.setLocale(lang)
                // this.$i18n.locale =lang;
 
            },
            translateSys(t) {
                if (typeof this.$t == "function") return this.$t(`sys.${t}`)
                else return t;
            },
        },
        onLoad() {
    
            this.curLang = uni.getLocale()
            this.oldLang = this.curLang
        },
        onUnload() {
            if (this.oldLang != this.curLang) {
                uni.reLaunch({
                    url: '/pages/login/index'
                });
            }
        }
    }
</script>
 
<style lang="scss">
    .uni-page-login-language {
        display: flex;
        width: 720rpx;
        flex-direction: column !important;
        padding: 15rpx;
 
        .uni-line {
            padding: 15rpx 5rpx;
            border-bottom: 1px solid #e8eaec;
            display: flex;
            flex-direction: row;
 
            .name {
                flex: 1;
            }
 
        }
    }
</style>