zhaojs
2023-06-10 69ea24e8fdfb41fc48c3fdb8c444645c13b1bbc4
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<template>
    <view class="setting-wrapper wrapperLayer colCen">
        <titleBar :titleText='"设置"' :pageForm='"setting"'></titleBar>
        <view class="body-container colCen">
            <view class="userSet-content infoContainer colCen">
                <view class="keyvalueBox rowCenBet borderBox" @tap="goPage('./modifyInfo')">
                    <view class="leftKey">
                        个人信息
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode=""></image>
                        </view>
                    </view>
                </view>
                <!-- <view class="keyvalueBox rowCenBet borderBox" @tap="goPage('./myAddress')">
                    <view class="leftKey">
                        地址管理
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode=""></image>
                        </view>
                    </view>
                </view> -->
                <view class="keyvalueBox rowCenBet borderBox" @click="('accountSecurity')">
                    <view class="leftKey">
                        注册时间
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            {{user.createtime}}
                        </view>
                    </view>
                </view>
            </view>
    
            <view class="infoContainer" style="margin-top: 20rpx;">
                <view class="keyvalueBox rowCenBet borderBox" @tap="goUrl('./bindingZFB')">
                    <view class="leftKey">
                        支付宝绑定
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            {{user.zfb_account?user.zfb_account:"未授权"}}
                        </view>
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode=""></image>
                        </view>
                    </view>
                </view>
                <view class="keyvalueBox rowCenBet borderBox" @tap="wxbinding()">
                    <view class="leftKey">
                        微信绑定
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            {{user.bindingWechat?'已绑定':''}}
                        </view>
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode=""></image>
                        </view>
                    </view>
                </view>
                <view class="keyvalueBox rowCenBet borderBox" @tap="bindingTB()">
                    <view class="leftKey">
                        淘宝绑定
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            {{user.tb_account?user.tb_account:"未授权"}}
                        </view>
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode=""></image>
                        </view>
                    </view>
                </view>
            </view>
    
            <view class="message-content infoContainer colCen" style="margin-top: 20rpx;">
                <view class="keyvalueBox rowCenBet borderBox" @click="goUrl('../../login/modifyPass')">
                    <view class="leftKey">
                        修改密码
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            修改
                        </view>
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode=""></image>
                        </view>
                    </view>
                </view>
                <view class="keyvalueBox rowCenBet borderBox" @click="openModel('clean')">
                    <view class="leftKey">
                        清除缓存
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            {{storageSize}}
                        </view>
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode="aspectFill"></image>
                        </view>
                    </view>
                </view>
                <view class="keyvalueBox rowCenBet borderBox">
                    <view class="leftKey">
                        <view>个性化商品推荐</view><span>(关闭将降低商品推荐与个人喜好的相关度)</span>
                    </view>
                    <view class="rightvalue rowCen">
                        <u-switch v-model="checked" @change="change"></u-switch>
                    </view>
                </view>
                <view class="keyvalueBox rowCenBet borderBox" @click="cancellation()">
                    <view class="leftKey">
                        账号注销<span>(账户注销后无法恢复,请谨慎操作)</span>
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode="aspectFill"></image>
                        </view>
                    </view>
                </view>
            </view>
    
            <view class="about-us infoContainer colCen" style="margin-top: 20rpx;">
                <view class="keyvalueBox rowCenBet borderBox" @click="goUrl('./aboutUs')">
                    <view class="leftKey">
                        关于我们
                    </view>
                    <view class="rightvalue rowCen">
                        <view class="rightText">
                            <!-- #ifdef APP-PLUS -->
                            {{version}}
                            <!-- #endif -->
                        </view>
                        <view class="arrow-icon defIcon">
                            <image src="../../../static/images/goods/arrow.png" mode="aspectFill"></image>
                        </view>
                    </view>
                </view>
            </view>
    
            <view class="logOut rowCenCen" @click="openModel('logout')">
                <view class="outText">
                    退出登录
                </view>
            </view>
        </view>
    
        <!-- 模态窗 -->
        <u-popup v-model="empowerModel" mode="center" border-radius="12">
            <empowerModel @closemodel='closeMdl' @updataInfo='updataUser'></empowerModel>
        </u-popup>
        <u-modal v-model="showModel" show-cancel-button :content="content" @confirm="confirm" :async-close="true">
        </u-modal>
        <u-toast ref="uToast" />
    </view>
</template>
 
<script>
    import empowerModel from '../../../components/empowerModel.vue'
    import util from '../../../utils/utils.js'
    import titleBar from '@/components/backTitlebar.vue'
    const plug = uni.requireNativePlugin('xiguazhu-baichuan');
    export default {
        components: {
            empowerModel,
            titleBar
        },
        data() {
            return {
                checked: true,
                modelType: '',
                showModel: false,
                empowerModel: false,
                content: '',
                storageSize: '',
 
                user: '',
 
                // #ifdef APP-PLUS
                version: plus.runtime.version
                // #endif
            }
        },
        onShow() {
            // #ifdef APP-PLUS
            this.getStorageSize()
            // #endif
            this.updataUser()
            this.getuserInfo()
            this.checked = uni.getStorageSync('open_like_recommend') == 1 ? true : false;
        },
        methods: {
            change(status) {
                if(status){
                    uni.setStorageSync('open_like_recommend',1);
                    this.checked = true;
                }else{
                    uni.setStorageSync('open_like_recommend',2);
                    this.checked = false;
                }
            },
            cancellation(){
                    uni.navigateTo({
                        url:"cancellation"
                    })
            },
            closeMdl() {
                this.showModel = false
                this.empowerModel = false
            },
            getuserInfo() {
                var that = this;
                this.$u.api.getUserInfo({}).then(e => {
                    that.user = e.data.userinfo;
                    util.setCache('userInfo', e.data.userinfo)
                }).catch(function (err) {
                    console.log(err)
                })
            },
            updataUser() {
                this.user = util.getCacheSync('userInfo')
            },
            getStorageSize() {
                let that = this;
                plus.cache.calculate(function(size) { //size是多少个字节单位是b
                    console.log(size);
                    //做下面相应的处理
                    if (size < 1024) {
                        that.storageSize = size + 'B';
                    } else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
                        that.storageSize = Math.floor(size / 1024 * 100) / 100 + 'KB';
                    } else if (size / 1024 / 1024 >= 1) {
                        that.storageSize = Math.floor(size / 1024 / 1024 * 100) / 100 + 'M';
                    }
                });
            },
 
            clearCache() {
                let that = this;
                let os = plus.os.name;
                console.log(os);
                if (os == 'Android') {
                    let main = plus.android.runtimeMainActivity();
                    let sdRoot = main.getCacheDir();
                    let files = plus.android.invoke(sdRoot, "listFiles");
                    let len = files.length;
                    for (let i = 0; i < len; i++) {
                        let filePath = '' + files[i]; // 没有找到合适的方法获取路径,这样写可以转成文件路径  
                        plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
                            if (entry.isDirectory) {
                                entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录  
                                    that.$refs.uToast.show({
                                        title: '清除缓存成功~',
                                        type: 'default',
                                        position: 'bottom'
                                    })
                                    that.getStorageSize(); // 重新计算缓存  
                                }, function(e) {
                                    console.log(e.message)
                                });
                            } else {
                                entry.remove();
                            }
                        }, function(e) {
                            console.log('文件路径读取失败')
                        });
                    }
                } else { // ios  
                    plus.cache.clear(function() {
                        that.$refs.uToast.show({
                            title: '清除缓存成功~',
                            type: 'default',
                            position: 'bottom'
                        })
                        that.getStorageSize();
                    });
                }
            },
 
            wxbinding() {
                if (this.user.bindingWechat) {
                    this.openModel('Unbundling')
                } else {
                    this.wxlogin()
                }
            },
 
            wxlogin() {
                var that = this;
                uni.getProvider({
                    service: 'oauth',
                    success: othres => {
                        console.log(othres.provider)
                        if (~othres.provider.indexOf('weixin')) {
                            uni.login({
                                provider: 'weixin',
                                success: (loginRes) => {
                                    console.log(loginRes);
                                    uni.setStorageSync('openId', loginRes.authResult.openid)
                                    uni.getUserInfo({
                                        provider: 'weixin',
                                        success: infoRes => {
                                            console.log('-------获取微信用户所有-----',
                                                infoRes)
                                            uni.setStorageSync('wxUserInfo', infoRes
                                                .userInfo)
                                            that.$u.api.bindWechat({
                                                avatar: infoRes.userInfo
                                                    .avatar,
                                                gender: infoRes.userInfo
                                                    .gender,
                                                nickName: infoRes.userInfo
                                                    .nickName,
                                                openId: loginRes.authResult
                                                    .openid
                                            }).then(e => {
                                                console.log(e)
                                                if(e.code == 1)return that.$alert(e.msg);
                                                that.getuserInfo()
                                            }).catch(function (err) {
                                                
                                            })
                                        }
                                    });
                                },
                                fail: err => {
                                    console.log(err);
                                    uni.showToast({
                                        title: '微信授权登录失败!',
                                        icon: 'none'
                                    })
                                }
                            })
                        }
                    }
                })
            },
 
            bindingTB() {
                if (this.user.tb_account) {} else {
                    this.empowerModel = true
                }
            },
 
            goUrl(url) {
                uni.navigateTo({
                    url: url
                })
            },
 
            openModel(type) {
                this.modelType = type;
                if (this.modelType == 'clean') {
                    this.content = '确定要清除缓存吗?';
                    this.showModel = true;
                } else if (this.modelType == 'logout') {
                    this.content = '确定要退出当前账号吗?';
                    this.showModel = true;
                } else if (this.modelType == 'Unbundling') {
                    this.content = '确定要解除微信绑定吗?';
                    this.showModel = true;
                }
            },
 
            confirm() {
                if (this.modelType == 'clean') {
                    this.modelType = '';
                    this.content = '';
                    this.clearCache();
                    this.showModel = false;
                } else if (this.modelType == 'logout') {
                    this.showModel = false;
                    try {
                        uni.removeStorageSync('userInfo');
                        uni.removeStorageSync('userData');
                        uni.reLaunch({
                            url: '../../login/wxlogin'
                        })
                    } catch (e) {
                        // error
                    }
                } else if (this.modelType == 'Unbundling') {
                    var that = this;
                    that.$u.api.unboundWechat({}).then(e => {
                        that.showModel = false
                        that.getuserInfo()
                        uni.showToast({
                            title: '已解除微信绑定',
                            icon: 'none'
                        })
                    }).catch(function (err) {
                        console.log(err)
                    })
                    // this.$http.post('member/unboundWechat').then(res => {
                    //     console.log(res);
                    //     this.showModel = false
                    //     this.getuserInfo()
                    //     uni.showToast({
                    //         title: '已解除微信绑定',
                    //         icon: 'none'
                    //     })
                    // })
                }
            },
 
            goPage(url) {
                uni.navigateTo({
                    url: url
                })
            }
        }
    }
</script>
 
<style lang="scss">
    .setting-wrapper {
        .body-container {
            width: 100%;
            margin-top: 20rpx;
 
            .infoContainer {
                width: 100%;
                background-color: #FFFFFF;
 
                .keyvalueBox {
                    width: 100%;
                    height: 100rpx;
                    border-bottom: 1rpx solid #F2F2F2;
                    padding: 0 30rpx;
 
                    .leftKey {
                        font-size: 28rpx;
                        font-weight: 500;
                        color: #333333;
 
                        span {
                            font-size: 24rpx;
                            font-weight: 500;
                            color: #999999;
                        }
                    }
 
                    .rightvalue {
                        .rightText {
                            font-size: 24rpx;
                            font-weight: 400;
                            color: #999999;
                            margin-right: 15rpx;
                        }
 
                        .arrow-icon {
                            width: 10rpx;
                            height: 18rpx;
                        }
                    }
                }
            }
 
            .logOut {
                width: 100%;
                height: 100rpx;
                margin-top: 20rpx;
                background-color: #FFFFFF;
 
                .outText {
                    font-size: 28rpx;
                    font-weight: 500;
                    color: #333333;
                }
            }
        }
    }
</style>