qingyiay
2023-03-28 5c01be6370291febe52adfa74fad8101a197c388
pages/login/userPassword.vue
@@ -31,7 +31,7 @@
<script>
import { apiLoginPassword } from '@/api/publicInterface.js';
import { mapMutations } from 'vuex';
import { setToken, setRefreshToken, setUsernameKey, setCustomerId, redirectHome } from '@/utils/status.js';
import { setName, setToken, setRefreshToken, setUsernameKey, setCustomerId, redirectHome } from '@/utils/status.js';
export default {
   name: 'userPassword',
   props: {
@@ -43,7 +43,9 @@
   },
   data() {
      return {
         username: '18812345677',
         username: '12222222222', // 客户
         // username:'13333333331',//货代
         // username: '13333333332',// 司机
         password: '123456',
         remember: true,
         baseUrl: ''
@@ -54,7 +56,7 @@
      //登录
      async submit() {
         uni.showLoading({
            title: '登陆中...'
            title: '登录中...'
         });
         //表单校验
         if (this.username.length === 0) {
@@ -78,29 +80,42 @@
               setRefreshToken(res.refresh_token);
               if (this.btnText == 0) {
                  if (res.code != 1) {
                     this.$u.toast('恭喜您,登录成功!');
                     // 登陆成功,存储相关信息
                     setToken(res.access_token);
                     setRefreshToken(res.refresh_token);
                     setUsernameKey(res.username);
                     //查询用户详细信息并储存
                     this.$reqGet('getUserEntity').then(res => {
                        this.setUserTabbar(res.data.type);
                        uni.setStorageSync('roleType', res.data.type);
                        setCustomerId(res.data.customerid);
                        uni.hideLoading();
                        //跳转页面
                        this.$nextTick(() => {
                           redirectHome();
                     this.$reqGet('getUserEntity')
                        .then(res => {
                           this.$u.toast('登录成功');
                           this.setUserTabbar(res.data.type);
                           uni.setStorageSync('roleType', res.data.type);
                           setCustomerId(res.data.customerid);
                           setName(res.name);
                           uni.hideLoading();
                           //跳转页面
                           this.$nextTick(() => {
                              redirectHome();
                           });
                        })
                        .catch(err => {
                           this.$u.toast('登录异常!');
                           console.log(err);
                        });
                     });
                  } else {
                     uni.hideLoading();
                     this.$u.toast(res.msg);
                  }
               } else {
                  this.$nextTick(() => {
                     this.$reqPost('wxBind', { state: 'MINI', code: uni.getStorageSync('code') }, 'params').then(res => {
                  uni.login({
                     success: res => {
                        if (res.code) {
                           uni.setStorageSync('bindcode', res.code);
                        }
                     }
                  });
                  if (uni.getStorageSync('bindcode')) {
                     this.$reqPost('wxBind', { state: 'MINI', code: uni.getStorageSync('bindcode') }, 'params').then(res => {
                        uni.hideLoading();
                        if (res.code == 0) {
                           this.$u.toast('绑定成功!即将回到登录页!');
@@ -111,7 +126,7 @@
                           this.$u.toast(res.msg ? res.msg : '绑定失败');
                        }
                     });
                  });
                  }
               }
            })
            .catch(e => {