MrShi
2025-08-21 a223d5e29e9384f720ae98c44cbe10f8fa4f73e7
small-program/App.vue
@@ -1,7 +1,69 @@
<script>
   import { mapState } from 'vuex'
   export default {
      onLaunch: function() {
         console.log('App Launch')
      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)
                     uni.getLocation({
                        type: 'wgs84',
                        success: (addr) => {
                           that.$store.commit('setPosition', { latitude: addr.latitude, longitude: addr.longitude })
                           that.$isResolve()
                        },
                        fail: (err) => {
                           console.error('获取位置失败', err);
                           that.$isResolve()
                        }
                     });
                  }
               }
            });
         } else {
            var that = this
            let res = this.$u.api.getMemberInfo({}).then(res =>{
               if (res && res.code === 200) {
                  that.$store.commit('setUserInfo', res.data)
                  uni.getLocation({
                     type: 'wgs84',
                     success: (addr) => {
                        that.$store.commit('setPosition', { latitude: addr.latitude, longitude: addr.longitude })
                        that.$isResolve()
                     },
                     fail: (err) => {
                        console.error('获取位置失败', err);
                        that.$isResolve()
                     }
                  });
               } else {
                  that.$store.commit('setToken','')
                  that.$store.commit('setUserInfo',{})
                  uni.getLocation({
                     type: 'wgs84',
                     success: (addr) => {
                        that.$store.commit('setPosition', { latitude: addr.latitude, longitude: addr.longitude })
                        that.$isResolve()
                     },
                     fail: (err) => {
                        console.error('获取位置失败', err);
                        that.$isResolve()
                     }
                  });
               }
            })
         }
      },
      onShow: function() {
         console.log('App Show')
@@ -13,6 +75,10 @@
</script>
<style lang="scss">
   /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
   @import "uview-ui/index.scss";
   @import "uview-ui/index.scss";
   .toast-custom {
       width: 500px !important;
       font-size: 14px !important;
   }
</style>