rk
2025-09-28 2304d7b140c5c5b4bf3a83f9ced8bff37d20c42e
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
<script>
    import { mapState } from 'vuex'
    var QQMapWX = require('@/utils/qqmap-wx-jssdk.js')
    export default {
        computed: {
            ...mapState(['userInfo','openid'])
        },
        onLaunch: function() {  
            var that = this;
            that.getLocaltionBiz() 
            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)
                            
                        }
                    }
                });
            } else {
                var that = this
                let res = this.$u.api.getMemberInfo({}).then(res =>{ 
                    if (res && res.code === 200) { 
                        that.$store.commit('setUserInfo', res.data) 
                    } else {
                        that.$store.commit('setToken','')
                        that.$store.commit('setUserInfo',{}) 
                    }
                })
            }
        },
        onShow: function() {
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        },
        methods:{
            getLocaltionBiz(){
                var that =this
                uni.getLocation({
                    type: 'wgs84',
                    success: (addr) => {
                        const locParam = { latitude: addr.latitude, longitude: addr.longitude };
                        uni.setStorageSync('address', locParam);
                        var address =null
                        const qqmapsdk = new QQMapWX({
                             key: '4PXBZ-JLBC7-LCLXG-P2SZX-C4HYE-LDBLQ' //腾讯地图申请的key(后续需要公司提供,个人开发者额度有限)
                         });  
                          // 腾讯地图逆地理编码
                        qqmapsdk.reverseGeocoder({
                            locParam,
                            success: function(res) {
                                console.log(res, '==================获取地址');
                                let info = res.result;
                                locParam.province = info.address_component.province;
                                locParam.city = info.address_component.city;
                                locParam.area = info.address_component.district;
                                locParam.street = info.address_component.street;
                                var ta = info.address  || '地址获取失败' ;
                                if(info.formatted_addresses  && info.formatted_addresses.recommend){
                                    ta =info.formatted_addresses.recommend
                                }
                                locParam.address =ta                                            
                                that.$store.commit('setPosition',locParam)
                                that.$isResolve()
                            },
                            fail: (err) => {
                                console.error('获取位置失败===========', err);
                                that.$store.commit('setPosition',locParam)
                                that.$isResolve()
                            }
                        });
                        // that.$store.commit('setPosition',locParam)
                        that.$isResolve()
                    },
                    fail: (err) => {
                        console.error('获取位置失败', err);
                        that.$isResolve()
                    }
                });
            }
        }
    }
</script>
 
<style lang="scss">
    @import "uview-ui/index.scss"; 
    
    .toast-custom {
        width: 500px !important;
        font-size: 14px !important;
    }
</style>