jiangping
2025-07-17 6b96f204e4083d32996c2943a25e36c15d668bd1
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
<script>
    import { mapState } from 'vuex'
    export default {
        computed: {
            ...mapState(['userInfo','openid'])
        },
        onLaunch: function() {
            var that = this;
            if (!this.openid || this.openid =='') {
                uni.login({
                    provider: 'weixin',
                    success: async function (loginRes) {
                        let { code } = loginRes;
                        let res = await that.$u.api.wxLogin({ code })
                        if (res&& res.code === 200) {
                            that.$store.commit('setToken', res.data.token)
                            that.$store.commit('setOpenid', res.data.openid)
                            that.$store.commit('setUserInfo', res.data.member)
                            that.$isResolve()
                        }
                    }
                });
            } 
        },
        onShow: function() {
            console.log('App Show')
            var that =this
            let res =  this.$u.api.getMemberInfo({}).then(res =>{ 
                if (res && res.code ===200) { 
                    that.$store.commit('setUserInfo', res.data)
                    that.$isResolve()
                }else{
                    that.$store.commit('setToken','')
                    that.$store.commit('setUserInfo',{})
                    that.$isResolve()
                }
            })
            
        },
        onHide: function() {
            console.log('App Hide')
        }
    }
</script>
 
<style lang="scss">
    @import "uview-ui/index.scss"; 
</style>