ll
liukangdong
2025-01-13 d38f3d8c0642d5d58a3baeff5d80abafaa702f9f
h5/pages/waybill/home.vue
@@ -4,7 +4,7 @@
      <view class="login_wrap">
         <view class="item">
            <view class="la">手机号</view>
           <input v-model="form.phone" maxlength="18" placeholder-class="placeholder9" placeholder="请输入手机号" />
           <input v-model="form.phone" type="tel" maxlength="18" placeholder-class="placeholder9" placeholder="请输入手机号" />
         </view>
         <view class="item">
            <view class="la">验证码</view>
@@ -13,7 +13,8 @@
                v-model="form.code"
                placeholder="请输入验证码"
                 placeholder-class="placeholder9"
                type="text"
                  :maxlength="6"
                type="number"
              />
              <text class="captcha" v-if="countDown == 0" @click="initCaptcha"
                >获取验证码</text
@@ -29,7 +30,7 @@
</template>
<script>
   import { sendSms, validPhoneCaptcha } from '@/api'
   import { sendSms, loginGkUserWithCode, wxAuthorizea, getUserInfo } from '@/api'
   export default {
      data() {
         return {
@@ -37,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)
                  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: '手机号不能为空',