cuiqian2004
8 天以前 30311cd24ee3b1567ffafac002494bb67feda657
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<template>
    <view class="pages-my">
        <view class="group">
            <view class="item line"  @click="clickAppVersion">
                <view>App版本:</view>
                <view class="right">{{app_version}}</view>
                <a>
                    <uni-icons class="icon" type="right" size="24" color="#888"></uni-icons>
                </a>
            </view>
            <view class="item line" @click="clickLanguage">
                <view>语言切换:</view>
                <view class="right">{{languageStr}}</view>
                <a >
                    <uni-icons class="icon" type="right" size="24" color="#888"></uni-icons>
                </a>
            </view>
 
            <!--     <view class="item line">
                <view>隐私政策:</view>
                <view class="right"></view>
                <a @click="clickPrivacyPolicy">
                    <uni-icons class="icon" type="right" size="24"></uni-icons>
                </a>
            </view>
            <view class="item line">
                <view>备份车辆与共享:</view>
                <view class="right"></view>
                <a @click="clickBackupVehicleShare">
                    <uni-icons class="icon" type="right" size="24"></uni-icons>
                </a>
            </view>
         -->
            <view class="item line" @click="clickClearCache">
                <view>清楚缓存:</view>
                <view class="right">{{cacheSizeStr}}</view>
                <a >
                    <uni-icons class="icon" type="right" size="24" color="#888"></uni-icons>
                </a>
            </view>
            <view class="item line"  @click="clickHelp">
                <view>帮助与反馈:</view>
                <view class="right"></view>
                <a>
                    <uni-icons class="icon" type="right" size="24" color="#888"></uni-icons>
                </a>
            </view>
            <!--             <view class="item">
                <view>用户协议:</view>
                <view class="right"></view>
                <a @click="clickUserAgreement">
                    <uni-icons class="icon" type="right" size="24"  color="#888"></uni-icons>
                </a>
            </view> -->
        </view>
 
        <view class="button-group">
            <!--     <button class="button" @click="clickModifyPassword">修改密码</button>
            <button class="button" @click="clickChangeAccount">切换账号</button> -->
            <a-button class="button" type="ghost" @click="clickExitAccount">退出登录</a-button>
        </view>
        <view>
            <uni-popup ref="refPopupMenu" background-color="transparent" maskBackgroundColor="rgba(0, 0, 0, 0.2)">
                <view class="popup-content" @click="closeMenu">
                    <picker-view class="popup-content-view" :indicator-style="indicatorStyle" :value="[langIndex]"
                        @change="bindLanguageChange">
                        <picker-view-column>
                            <view class="item" v-for="(item,index) in langList" :key="index">{{item.name}}</view>
                        </picker-view-column>
 
                    </picker-view>
                </view>
            </uni-popup>
        </view>
    </view>
</template>
<script>
    import {
        session,
        showToast,
        showModal
    } from "@/comm/utils.js"
    import {
        Button
    } from 'antd-mobile-vue-next'
    export default {
        name: "PagesMy",
        components: {
            'a-button': Button
        },
        data() {
            return {
                indicatorStyle: `height: 75rpx;`,
                app_version: "1.0.0",
                backup_vehicle_share: "",
                langIndex: 0,
                cache_size: 5000000,
                langList: [{
                    value: "zh-Hans",
                    name: "中文简体"
                }, {
                    value: "zh-Hant",
                    name: "中文繁体"
                }, {
                    value: "en",
                    name: "English"
                }],
            }
        },
        onLoad() {
            // this.loadData()
 
        },
        computed: {
            cacheSizeStr() {
                let size = 0
                if (this.cache_size < 1024) {
                    size = Math.round(this.cache_size * 100)
                    return `${size/100} KB`
                } else if (this.cache_size < 1024 * 1024) {
                    size = Math.round(this.cache_size * 100 / 1024)
                    return `${size/100} MB`
                } else {
                    size = Math.round(this.cache_size * 100 / (1024 * 1024 * 1024))
                    return `${size/100} GB`
                }
            },
            languageStr() {
                if (this.langIndex > -1) {
                    return this.langList[this.langIndex].name || ""
                }
 
 
            }
 
        },
        onTabItemTap() {
            this.loadData()
        },
        methods: {
            setData(obj) {
                let that = this;
                let keys = [];
                let val, data;
 
                Object.keys(obj).forEach(function(key) {
                    keys = key.split(".");
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2, index) {
                        if (index + 1 == keys.length) {
                            that.$set(data, key2, val);
                        } else {
                            if (!data[key2]) {
                                that.$set(data, key2, {});
                            }
                        }
                        data = data[key2];
                    });
                });
            },
            loadData() {
                const _this = this
 
                const language = uni.getLocale()
                this.langIndex = this.langList.findIndex((a) => a.value == language)
 
                this.loadCache()
                // #ifdef APP-PLUS
                plus.runtime.getProperty(plus.runtime.appid, (info) => {
                    // console.log(info);
                    _this.setData({
                        app_version: info.version
                    })
                });
                //#endif
            },
            loadCache() {
                const _this = this
                uni.getStorageInfo({
                    success: (res) => {
                        _this.setData({
                            cache_size: res.currentSize
                        })
                        console.log('当前缓存大小:', res, 'KB');
                    },
                    fail: (err) => {
                        console.error('获取缓存信息失败:', err);
                    },
                    complete: () => {
                        console.log('缓存信息获取完成');
                    },
                });
            },
            bindLanguageChange(e) {
                console.log(e)
                const val = e.detail.value
                this.langIndex = val[0]
                uni.setLocale(this.langList[this.langIndex].value)
            },
            closeMenu() {
                this.$refs.refPopupMenu.close()
            },
            clickAppVersion() {
                uni.navigateTo({
                    url: "/pages/my/version-update"
                })
            },
            clickPrivacyPolicy() {
 
            },
            clickBackupVehicleShare() {
 
            },
            clickLanguage() {
 
                this.$refs.refPopupMenu.open("right")
            },
            clickClearCache() {
                try {
                    let list = session.getValue("vehicles") || []
                    const info = session.getValue("login_info")
                    uni.clearStorageSync();
                    session.setValue("vehicles", list)
                    session.setValue("login_info", info)
                    showToast("清除缓存成功!")
                    this.loadCache()
                } catch (e) {
                    // error
                }
            },
            clickHelp() {
                uni.navigateTo({
                    url: "/pages/my/help-feedback"
                })
            },
            clickUserAgreement() {
 
            },
    
            clickModifyPassword() {
 
            },
            clickChangeAccount() {
 
            },
            clickExitAccount() {
                uni.reLaunch({
                    url: "/pages/login/index"
                })
            },
 
        }
    }
</script>
 
<style lang="scss">
    .pages-my {
        display: flex;
        width: 750rpx;
        height: 100vh;
        flex-direction: column;
 
        .group {
            width: calc(100% - 40rpx);
            border: 2rpx solid #ccc;
            border-radius: 20rpx;
            margin: 20rpx;
            padding: 0 10rpx;
            display: flex;
            flex-direction: column;
            background-color: #fff;
 
            .item {
                width: 100%;
                padding: 20rpx 10rpx;
                display: flex;
                flex-direction: row;
                align-items: center;
 
                .right {
                    flex: 1;
                    text-align: right;
                    color: #888;
                }
            }
 
            .line {
                border-bottom: 2rpx solid #ccc;
            }
        }
 
 
        .button-group {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            font-size: 30rpx !important;
 
            .am-button {
                border-radius: 30px;
            }
 
            .am-button-ghost {
                border: 1px solid red !important;
                color: red !important;
 
            }
        }
 
        .button {
            margin: auto;
            margin-top: 20rpx;
            border-radius: 4rpx;
            width: 500rpx;
        }
 
        .popup-content {
            display: flex;
            justify-content: center;
            flex-direction: column;
            background-color: transparent;
        }
 
        .popup-content-view {
            width: 150px;
            height: 150px;
            border-radius: 10rpx;
            padding: 10rpx 20rpx;
            background-color: #fff;
            margin-top: 100px;
            margin-right: 50px;
 
            .item {
                line-height: 75rpx;
                text-align: center;
                border: 0;
 
            }
        }
 
 
    }
</style>