yangan
2024-07-30 4e4842518007726677c1dd23dc57f3448e7b08b4
pages/login/userPassword.vue
@@ -2,13 +2,22 @@
   <view>
      <view class="list">
         <view class="list-call">
            <u--input v-model="username"
         <!--    <u--input v-model="username"
               clearable
               maxlength="32"
               type="text"
               placeholder="请输入手机号"
               prefixIcon="account"
               prefixIconStyle="font-size: 22px;color: #909399"></u--input>
               prefixIconStyle="font-size: 22px;color: #909399"></u--input> -->
            <customPagination
               style="width:100%; height: 60rpx;  font-size: 30rpx;"
               :options="userList"
               :value="username"
               v-model="username"
               @changeInput="changeInput2"
               @input="handleInput2"
               :placeholder="'请选择手机号'"
            ></customPagination>
         </view>
         <view class="list-call">
            <u--input v-model="password"
@@ -17,18 +26,24 @@
               type="password"
               placeholder="请输入密码"
               prefixIcon="lock"
               style="padding:0"
               prefixIconStyle="font-size: 22px;color: #909399"></u--input>
         </view>
      </view>
      <view class="loginBtn"><u-button type="primary"
      <view class="loginBtn">
      <u-button type="primary"
            :text="btnText == 1 ? '绑定' : '登录'"
            @click="submit()"></u-button></view>
            @click="submit()"
            :loading="submitLoading">
      </u-button>
    </view>
   </view>
</template>
<script>
   import { apiLoginPassword } from '@/api/publicInterface.js';
   import { mapMutations } from 'vuex';
   import customPagination from './user.vue'
   import { setName, setToken, setRefreshToken, setUsernameKey, setCustomerId, redirectHome } from '@/utils/status.js';
   export default {
      name: 'userPassword',
@@ -37,7 +52,16 @@
         btnText: {
            type: Number,
            default: 0
         },
         userList: {
            type: Array,
            default: () => {
               return [];
            }
         }
      },
      components: {
         customPagination
      },
      data() {
         return {
@@ -46,11 +70,18 @@
            // username: '13333333332',// 司机
            password: '',
            remember: true,
            baseUrl: ''
            baseUrl: '',
            submitLoading: false
         };
      },
      methods: {
         ...mapMutations(['setUserTabbar']),
         changeInput2(e){
            this.username=e.username
            // this.password=e.password
         },
         handleInput2(e){
         },
         //登录
         async submit() {
            uni.showLoading({
@@ -67,6 +98,7 @@
            }
            let grant_type = 'password';
            //登录接口
            this.submitLoading = true
            await apiLoginPassword({
                  username: this.username,
                  password: this.password,
@@ -77,6 +109,7 @@
                  setToken(res.access_token);
                  setRefreshToken(res.refresh_token);
                  if (this.btnText == 0) {
                     this.submitLoading = false
                     if (res.code != 1) {
                        // 登陆成功,存储相关信息
                        setToken(res.access_token);
@@ -85,19 +118,35 @@
                        //查询用户详细信息并储存
                        this.$reqGet('getUserEntity')
                           .then(res => {
                    console.log(res,'登录信息----------')
                              this.$u.toast('登录成功');
                              this.setUserTabbar(res.data.type);
                              uni.setStorageSync('roleType', res.data.type);
                              uni.setStorageSync("userId", res.data.userId)
                              uni.setStorageSync("carNo", res.data.carNo)
                              uni.setStorageSync("userInfo", res.data)
                              let data=uni.getStorageSync('userList')?JSON.parse(uni.getStorageSync('userList')):[];
                              let id = data.length + 1;
                               if (data.filter(item=> item.username == this.username).length == 0){
                               data.push({username: this.username,password: this.password,type:res.data.type})
                              }
                              uni.setStorageSync("userList", JSON.stringify(data))
                              setCustomerId(res.data.customerid);
                              setName(res.name);
                              setName(res.data.name);
                              uni.hideLoading();
                              //跳转页面
                              this.$nextTick(() => {
                                 redirectHome();
                              });
                    if(res.data.forcePassword == 1) {
                      uni.navigateTo({
                        url: '/pages/login/resetPassword/resetPassword'
                      })
                    }else {
                      //跳转页面
                      this.$nextTick(() => {
                        redirectHome();
                      });
                    }
                           })
                           .catch(err => {
                              this.submitLoading = false
                              this.$u.toast('登录异常!');
                              console.log(err);
                           });
@@ -128,10 +177,11 @@
                        });
                     }
                  }
               })
               .catch(e => {
               }).catch(e => {
                  this.submitLoading = false
                  this.$u.toast(e);
               });
         }
      }
   };
@@ -143,4 +193,10 @@
   .dengluBtn {
      margin-top: 80rpx;
   }
</style>
  /* #ifdef H5 */
  .loginBtn{
    width: 80%;
    margin: 0 auto;
  }
  /* #endif */
</style>