rk
2026-04-28 908b9876dde97acbb09c53dc6debe3eecbb9d1b4
small-program/shop/pages/login/login.vue
@@ -26,9 +26,9 @@
         <image class="agree-icon" :src="agreed ? '/static/icon/ic_accept_sel@2x.png' : '/static/icon/ic_accept@2x.png'" mode="aspectFit" @tap="agreed = !agreed"></image>
         <view class="agreement-text-wrap">
            <text class="agreement-text">我已阅读并同意</text>
            <text class="agreement-link" @click="goToService">《用户服务协议》</text>
            <text class="agreement-link" @click="goToService(2)">《门店服务协议》</text>
            <text class="agreement-text">及</text>
            <text class="agreement-link" @click="goToPrivacy">《用户隐私政策》</text>
            <text class="agreement-link" @click="goToService(3)">《门店隐私政策》</text>
         </view>
      </view>
   </view>
@@ -52,7 +52,6 @@
      },
      onLoad() {
         // 静默登录
         if (this.userInfo.bindShopId) {
            uni.showLoading({
               title:'登录中...'
@@ -61,7 +60,7 @@
               console.log(this.userType,"============================================")
               this.$u.api.shopSilentLogin({})
                  .then( res => {
                     if (res.code === 200) {
                     if (res.code === 200 && res.data) {
                        this.$store.commit('setUserType', 1)
                        this.$store.commit('setShopToken', res.data.token)
                        // 获取门店信息
@@ -71,12 +70,13 @@
                           }
                           uni.hideLoading();
                           // setTimeout(() => {
                              uni.reLaunch({
                              uni.navigateTo({
                                 url: '/shop/pages/store-home/store-home'
                              });
                           // }, 1000)
                        })
                     }
                     uni.hideLoading()
                  })
            }catch(e){
               uni.hideLoading()
@@ -88,13 +88,6 @@
      },
      methods: {
         async handleLogin() {
            if (!this.agreed) {
               uni.showToast({
                  title: '请先阅读并同意协议',
                  icon: 'none'
               })
               return
            }
            if (!this.form.telephone) {
               uni.showToast({
                  title: '请输入账号',
@@ -109,52 +102,41 @@
               })
               return
            }
            uni.showLoading({ title: '登录中...', mask: true })
            try {
               const res = await this.$u.api.shopLogin({
                  openid: this.openid,
                  password: this.form.password,
                  telephone: this.form.telephone
               })
               uni.hideLoading()
               if (res.code === 200) {
                  this.$store.commit('setUserType', 1)
                  this.$store.commit('setShopToken', res.data.token)
                  // 获取门店信息
                  const shopInfoRes = await this.$u.api.getShopInfo({})
                  if (shopInfoRes.code === 200) {
                     this.$store.commit('setShopInfo', shopInfoRes.data)
                  }
                  uni.showToast({ title: '登录成功', icon: 'success' })
                  setTimeout(() => {
                     uni.reLaunch({
                        url: '/shop/pages/store-home/store-home'
                     });
                  }, 1500)
               } else {
                  uni.showToast({
                     title: res.msg || '登录失败',
                     icon: 'none'
                  })
               }
            } catch (err) {
               uni.hideLoading()
            if (!this.agreed) {
               uni.showToast({
                  title: '登录失败',
                  title: '请先阅读并同意协议',
                  icon: 'none'
               })
               return
            }
            uni.showLoading({ title: '登录中...', mask: true })
            const res = await this.$u.api.shopLogin({
               openid: this.openid,
               password: this.form.password,
               telephone: this.form.telephone
            })
            uni.hideLoading()
            if (res.code === 200) {
               this.$store.commit('setUserType', 1)
               this.$store.commit('setShopToken', res.data.token)
               // 获取门店信息
               const shopInfoRes = await this.$u.api.getShopInfo({})
               if (shopInfoRes.code === 200) {
                  this.$store.commit('setShopInfo', shopInfoRes.data)
               }
               uni.showToast({ title: '登录成功', icon: 'success' })
               setTimeout(() => {
                  uni.reLaunch({
                     url: '/shop/pages/store-home/store-home'
                  });
               }, 1500)
            }
         },
         goToService() {
         goToService(type) {
            uni.navigateTo({
               url: '/pages/rich-text/rich-text?type=userAgreement'
               url: '/pages/rich-text/rich-text?type='+type
            })
         },
         goToPrivacy() {
            uni.navigateTo({
               url: '/pages/rich-text/rich-text?type=privacyPolicy'
            })
         }
         }
      }
   }
</script>