quanyawei
2023-11-06 1e61215b48e59e94c1ed98e4ef956227d689d6bc
pages/login/login.vue
@@ -21,32 +21,38 @@
            </u-form>
         </view>
         <view class="loginContent">
            <p>
            <!-- <p>
               <navigator style="display: inline-block;" url="/pages/login/register/register">
                  <text style="text-decoration: underline">立即注册</text>
               </navigator>
            </p>
            </p> -->
            <u-button @click="submit">登录</u-button>
         </view>
      </view>
      <ws-wx-privacy id="privacy-popup" enableAutoProtocol></ws-wx-privacy>
   </view>
</template>
<script>
   import {
      login,
      getUserInfor,
      getDic
   } from '@/utils/login.js' // 配置文件
   import {
      httpPost,
      httpGet
   } from '@/utils/http.js'
   import store from '@/store/index.js'
   import {
      subScribeMsg
   } from '@/utils/subscribe.js'
   export default {
      data() {
         return {
            titlePrivacy: '用户隐私保护提示',
            labelStyle: {
               color: '#fff'
            },
            title: '设置头像',
            passwordIcon: false,
            form: {
               account: '',
@@ -71,38 +77,71 @@
         //onReady 为uni-app支持的生命周期之一
         this.$refs.uForm.setRules(this.rules)
      },
      async onLoad(option) {
         //等待登录成功
         await this.$onLaunched
         // 后续业务逻辑
      },
      async onShow() {
         uni.hideHomeButton()
      },
      methods: {
         // 点击时触发订阅信息
         async aClick() {
            let data = await subScribeMsg()
            console.log('data', data)
            if (data['YNqUZ1MgMvwY3G-NENVbcmIBR5dUotSdnwcz96CWrho'] === 'accept') { // 用户点击确定后
            } else {
               console.log('拒绝')
            }
         },
         doRequire() {
            uni.requirePrivacyAuthorize({
               success: () => {
                  console.log('同意')
                  // 用户同意授权
                  // 继续小程序逻辑
                  this.getlogin()
               },
               fail: () => {
                  console.log('拒绝')
               }, // 用户拒绝授权
               complete: () => {}
            })
         },
         submit() {
            this.$refs.uForm.validate().then(res => {
               this.getlogin()
            }).catch(errors => {
               uni.$u.toast('校验失败')
            })
               this.doRequire()
            }).catch(errors => {})
         },
         //登录
         getlogin() {
            let openId = this.$storage.get('openId')
            const value = uni.getStorageSync('openId')
            console.log('openId', value)
            if (value) {
               this.aClick()
               this.logining(value)
            }
         },
         logining(openId) {
            login({
               ...this.form,
               openId
            }).then(response => {
               this.$storage.set('token', response.data.token)
               uni.setStorageSync('userInfor', JSON.stringify(response.data))
               uni.setStorageSync('tonken', response.data.token)
               getDic()
               getUserInfor(response.data.token)
               uni.hideLoading()
               uni.switchTab({
                  url: '/pages/actionChange/agencyPage/index',
               uni.navigateTo({
                  url: '/pages/index/index',
               })
               // this.$storage.setJson("accountInFor", this.form);
               // console.log('this.$store', this.$store)
               // this.$store.commit('token', token)
            }).catch(errors => {
               uni.showToast({
                  title: errors,
                  icon: 'none',
               })
            })
         },
         }
      },
   }
</script>