jiangping
2025-01-07 41d11d9db46ccd44163860f6be6bfd2137aff369
h5/pages/waybill/home.vue
@@ -30,7 +30,7 @@
</template>
<script>
   import { sendSms, validPhoneCaptcha } from '@/api'
   import { sendSms, loginGkUserWithCode, wxAuthorizea, getUserInfo } from '@/api'
   export default {
      data() {
         return {
@@ -38,24 +38,76 @@
               code: '',
               phone: ''
            },
            countDown: 0
            countDown: 0,
            code: ''
         };
      },
      onShow() {
         var that = this
         let url = 'https://atwl.ahzyssl.com/zhyq_h5/#/pages/waybill/home'
         let code = ''
         if (window.location.href.indexOf('code=') !== -1 || this.code) {
            this.userAuth(3)
         } else {
            // let url = window.location.href
            const appID = 'wx173e6caf5abc718a'
            let uri = encodeURIComponent(url)
            let authURL =
               `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appID}&redirect_uri=${uri}&response_type=code&scope=snsapi_base#wechat_redirect`
            window.location.href = authURL
         }
      },
      methods: {
         onSubmit() {
            const { code, phone } = this.form
            if (!phone) return this.showToast('手机号不能为空')
            if (!code) return this.showToast('验证码不能为空')
            validPhoneCaptcha({
              phone, code
            loginGkUserWithCode({
              phone, code,openid: this.$store.state.openId, userType: 3
            }).then(res => {
              if (res && res.code == 200) {
                uni.navigateTo({
                  url: "/pages/waybill/list?phone=" + phone
                })
                  this.$store.commit('setToken', res.data.token)
                  getUserInfo().then(ress => {
                     this.$store.commit('setWaybillInfo', ress.data)
                     uni.navigateTo({
                        url: '/pages/waybill/list'
                     })
                  })
              }
            })
         },
         userAuth(source) {
            var that = this
            let url = window.location.href
            let code = ''
            if (url.indexOf('code=') !== -1 || this.code) {
               const query = url.split('?')
               for (const q of query) {
                  if (q.indexOf('code=') !== -1) {
                     let statusIndex = q.indexOf('&state')
                     code = q.substring(q.indexOf('code=') + 5, statusIndex)
                  }
               }
               wxAuthorizea({
                  code: code || this.code,
                  source: source
               }).then(res => {
                  if (res.code === 200) {
                     that.$store.commit('setOpenId', res.data.openid)
                     if (res.data.token) {
                        that.$store.commit('setToken', res.data.token)
                        getUserInfo().then(ress => {
                           that.$store.commit('setWaybillInfo', ress.data)
                           uni.navigateTo({
                              url: '/pages/waybill/list'
                           })
                        })
                     }
                  }
               })
            }
         },
         initCaptcha() {
           if (!this.form.phone) return uni.showToast({
             title: '手机号不能为空',