xuxy
2024-06-25 d1bb68d9f9054bbf87cd84956d3240c71d8e370c
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
<template>
    <view class="main-container user-container">
        <!--         <view>
            我的
        </view> -->
        <!-- 背景图 -->
        <view class="top-bg" :style="{'padding-top':(StatusBar)+'px','line-height':CustomBar+'rpx' }">
            <view class="title" style="position: relative;"  @click="changedefaulttype">
                我<uni-icons type="settings"></uni-icons>
                <!-- <view style="position: absolute;left: 32rpx;top: 0;">
                    <uni-icons type="settings" @click="changedefaulttype"></uni-icons>
                </view> -->
            </view>
            <view class="icons">
                <image class="icon1" src="../../static/imgs/user/usr-icon1.png" mode="aspectFit"></image>
                <image class="icon2" src="../../static/imgs/home/home-shop-top-icon.png" mode="aspectFit"></image>
            </view>
            <view class="flex m-20 user-info" @click="goto('/pages/user/user-info/user-info',true)"
                v-if="currentInfo&&(currentInfo.id)">
                <!-- 头像 -->
                <image class="user-icon" v-if="!currentInfo.picture" src="../../static/imgs/home/home-shop-top-icon.png"
                    mode="aspectFit"></image>
                <image class="user-icon" v-if="currentInfo.picture" :src="currentInfo.picture" mode="aspectFit"></image>
 
                <view class="name">
                    {{currentInfo.nickName || '-'}}
                </view>
                <uni-icons class="right-icon" type="right"></uni-icons>
            </view>
            <view class="flex m-20 user-info" v-else @click="toLogin">
                <!-- <button open-type="getUserInfo" style="background-color: #fff" @tap="getUserProfile"
                    class="title-bold h2">{{'请点击授权登录~'}}</button> -->
                前往登录
            </view>
 
 
        </view>
 
 
 
        <view style="padding-bottom:200rpx">
        </view>
        <bussincess-footer flg="1"></bussincess-footer>
 
    </view>
</template>
 
<script>
    import storage from '@/plugins/storage.js'
 
    export default {
        data() {
            return {
                CustomBar: uni.getStorageSync('CustomBar'),
                StatusBar: uni.getStorageSync('StatusBar'),
                // StatusBar:0
            };
        },
        created() {
            console.log('created bu')
 
        },
        mounted() {
            console.log('mounted bu')
 
        },
        methods: {
            toLogin() {
                uni.navigateTo({
                    url: '/pages/home/rider-login/rider-login'
                })
            },
            async changedefaulttype() {
                await this.$message.confirm('前往学生端吗?')
                //清空数据
                const res = await this.$store.dispatch('logout');
 
                uni.reLaunch({
                    url: '/pages/user/user'
                })
            },
            async getUserProfile(e) {
                const res = await wx.getUserProfile({
                    desc: '用于完善会员资料',
                });
                console.log(res);
                this.login_Wx(res.userInfo.avatarUrl, res.userInfo.nickName)
            },
            login_Wx(imgurl, nickname) {
                //获取openId
                // /wx/jscode2session
                const tmp = this;
                this.$message.showLoading()
                this.openid = this.$storage.getItem('openid');
                this.tel = this.$storage.getItem('tel');
                console.log('info,info,info,info,info,info', this.openid, this.tel);
                if (!!this.openid && !!this.tel) {
                    // this.login = true;
                } else {
                    // this.login = false;
                    console.log('wx.login');
                    wx.login({
                        success: async res => {
                            if (res.code) {
                                //微信登录成功 已拿到code
                                // tmp.login = true;
                                // tmp.jsCode = res.code; //保存获取到的code
                                console.log('abcd', res.code);
                                // this.$http.request('post',`/api/login/wechat`,{data:{code:tmp.jsCode}})
                                this.$storage.setItem('jsCode', res.code);
                                const res2 = await wx.getUserInfo();
                                console.log('res', res2);
 
                                await this.$store.dispatch('loginwx', {
                                    code: res.code,
                                    imgurl: imgurl,
                                    nickname: nickname
                                });
                                tmp.$message.hideLoading()
 
                                this.$forceUpdate()
                            } else {
                                tmp.$message.hideLoading()
                                tmp.$message.showToast('微信登录失败');
 
                            }
                        },
                        error: res => {
                            console.log('wx.login error', res);
                            tmp.$message.hideLoading()
 
                            tmp.$message.showToast('微信授权失败');
                        }
                    });
                }
            },
 
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "./user.scss";
</style>