quanyawei
2024-07-04 1e71dd86f6d0c4fc7e5143600d4bc4b50992a2a7
App.vue
@@ -3,32 +3,32 @@
      getDic
   } from '@/utils/login.js' // 配置文件
   import store from '@/store/index.js'
   import routingIntercept from '@/utils/permission.js'
   import {
      httpPost,
      httpGet
   } from '@/utils/http.js'
   export default {
      onShow: function(options) {
      onShow(options) {
         this.checkUpdate()
         console.log('optionsonShow', options)
         if (options.scene === 1007 || options.scene === 1014 || options.scene === 1008) {
            // 通过单人聊天会话分享进入
            this.getWXCode()
            // this.getWXCode()
         }
      },
      onLaunch() {
         // 自动登录检测
         let token = uni.getStorageSync('token')
         console.log('apptoken', token)
         console.log('apptoken1', !token)
         if (!token) {
            uni.login({
               provider: 'weixin',
               success: loginRes => {
                  console.log('loginRes', loginRes)
                  console.log('loginRes1', loginRes)
                  httpGet('/AppUser/wx/login', {
                     'code': loginRes.code
                  }).then(result => {
                     routingIntercept()
                     console.log('AppUser1', result)
                     try {
                        if (result.data.code === 0) {
                           uni.clearStorageSync()
@@ -73,65 +73,107 @@
         }
      },
      methods: {
         checkUpdate() {
            // 判断当前微信版本是否支持检测更新接口,注:(基础库版本大于v1.9.90才可以使用getUpdateManager接口所以要做低版本兼容处理)
            if (uni.canIUse('getUpdateManager')) {
               const updateManager = uni.getUpdateManager()
               // 请求完新版本信息的回调
               updateManager.onCheckForUpdate(function(res) {
                  // 如有新版本则进行静默下载更新并提示
                  console.log('res.hasUpdate', res.hasUpdate)
                  console.log('版本信息', res)
                  if (res.hasUpdate) {
                     // 新版本下载成功
                     updateManager.onUpdateReady(function() {
                        uni.showModal({
                           title: '更新提示',
                           content: '发现新版本',
                           showCancel: false,
                           success(res) {
                              if (res.confirm) {
                                 // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                                 updateManager.applyUpdate()
                              }
                           }
                        })
                     })
                     // 新版本下载失败
                     updateManager.onUpdateFailed(function() {
                        uni.showModal({
                           title: '更新提示',
                           content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
                           showCancel: false
                        })
                     })
                  }
               })
            } else {
               // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
               uni.showModal({
                  title: '提示',
                  content: '当前微信版本过低,无法使用最新版的小程序,请升级到最新微信版本后重试。',
                  success(res) {
                     if (res.confirm) {
                        // 使用此接口可直接跳转至微信客户端更新下载页面
                        uni.updateWeChatApp()
                     }
                  }
               })
            }
         },
         /**
          * 自动登录
          * 判断本地是否有账号信息,如果有,就自动重新登录
          *
          */
         getWXCode() {
            let token = uni.getStorageSync('token')
            console.log('apptoken', token)
            if (!token) {
               uni.login({
                  provider: 'weixin',
                  success: loginRes => {
                     console.log('loginRes', loginRes)
                     httpGet('/AppUser/wx/login', {
                        'code': loginRes.code
                     }).then(result => {
                        routingIntercept()
                        try {
                           if (result.data.code === 0) {
                              uni.clearStorageSync()
                              uni.setStorageSync('userInfor', JSON.stringify(result.data))
                              uni.setStorageSync('tonken', result.data.token)
                              uni.setStorageSync('openId', result.data.openId)
                              getDic()
                              this.$isResolve()
                           } else {
                              uni.clearStorageSync()
                              uni.setStorageSync('openId', result.data.openId)
                              uni.showModal({
                                 title: '未登录',
                                 content: '您未登录,需要登录后才能继续',
                                 showCancel: false,
                                 confirmText: '确定',
                                 success: res => {
                                    if (res.confirm) {
                                       uni.reLaunch({
                                          url: '/pages/login/login',
                                       })
                                    }
                                 },
                              })
                              this.$isResolve()
                           }
                        } catch (e) {
                           console.error(e)
            uni.login({
               provider: 'weixin',
               success: loginRes => {
                  console.log('loginRes2', loginRes)
                  httpGet('/AppUser/wx/login', {
                     'code': loginRes.code
                  }).then(result => {
                     console.log('AppUser2', result)
                     try {
                        if (result.data.code === 0) {
                           uni.clearStorageSync()
                           uni.setStorageSync('userInfor', JSON.stringify(result.data))
                           uni.setStorageSync('tonken', result.data.token)
                           uni.setStorageSync('openId', result.data.openId)
                           getDic()
                           this.$isResolve()
                        } else {
                           uni.clearStorageSync()
                           uni.setStorageSync('openId', result.data.openId)
                           uni.showModal({
                              title: '未登录',
                              content: '您未登录,需要登录后才能继续',
                              showCancel: false,
                              confirmText: '确定',
                              success: res => {
                                 if (res.confirm) {
                                    uni.reLaunch({
                                       url: '/pages/login/login',
                                    })
                                 }
                              },
                           })
                           this.$isResolve()
                        }
                     }).catch(errors => {
                        console.log('appdddd', errors)
                        uni.showToast({
                           title: errors,
                           icon: 'none',
                        })
                        this.$isResolve()
                     } catch (e) {
                        console.error(e)
                     }
                  }).catch(errors => {
                     console.log('appdddd2', errors)
                     uni.showToast({
                        title: errors,
                        icon: 'none',
                     })
                  }
               })
            } else {
               this.$isResolve()
            }
                     this.$isResolve()
                  })
               }
            })
         },
         getLogin(data) {
            // 调用接口。将登录code传给后端进行判断
@@ -165,6 +207,8 @@
   html {
      height: 100%;
      overflow-x: hidden;
      width: 750rpx;
   }
   .formItemContent {