wk
2024-08-05 76543a9506a9b43476e750c79c5ff595aa4bae36
pages/register/register.vue
@@ -82,7 +82,7 @@
               label="身份证过期时间"
               labelWidth="20%"
               borderBottom>
               <uni-datetime-picker v-model="registerFormModel.expirationTimeIdcard" type="datetime"  />
               <uni-datetime-picker v-model="registerFormModel.expirationTimeIdcard" type="date" :start="minDate" />
            </u-form-item>
            <u-form-item prop="phone"
               label="手机号"
@@ -103,6 +103,21 @@
                  password
                  clearable></u--input>
            </u-form-item>
        <view class="intensity">
          <view class="psdText">密码强度</view>
          <view
              class="line"
              :class="[level.includes('low') ? 'low' : '']"></view>
          <view
              class="line"
              :class="[level.includes('middle') ? 'middle' : '']"></view>
          <view
              class="line"
              :class="[level.includes('high') ? 'high' : '']"></view>
          <div class="warningtext">
            密码应由8-16位数字、字母、符号组成。请不要使用容易被猜到的密码
          </div>
        </view>
            <u-form-item prop="confirmPassword"
               label="确认密码"
               labelWidth="20%"
@@ -128,6 +143,7 @@
               label="车辆类型"
               borderBottom
               ref="roleRef"
               prop='carType'
               v-if="radiovalue1 == '司机'">
               <niceui-data-select-input v-model="registerFormModel.carType"
                  :localdata="radiolist2"
@@ -179,7 +195,7 @@
               labelWidth="20%"
               borderBottom
               v-if="radiovalue1 == '司机'">
               <uni-datetime-picker v-model="registerFormModel.expirationTimeDriving" type="datetime"  />
               <uni-datetime-picker v-model="registerFormModel.expirationTimeDriving" type="date"  :start="minDate" />
            </u-form-item>
            <u-form-item prop="driverImg"
               label="驾驶证"
@@ -205,14 +221,13 @@
               labelWidth="20%"
               borderBottom
               v-if="radiovalue1 == '司机'">
               <uni-datetime-picker v-model="registerFormModel.expirationTimeDriver" type="datetime"  />
               <uni-datetime-picker v-model="registerFormModel.expirationTimeDriver" type="date"  :start="minDate" />
            </u-form-item>
            <u-form-item prop="tradeQualificationImg"
               label="从业资格证"
               labelWidth="24%"
               borderBottom
               v-if="radiovalue1 == '司机'"
               required
               @click="beforeRead">
               <u-upload :fileList="fileList4"
                  deletable
@@ -234,25 +249,11 @@
               labelWidth="20%"
               borderBottom
               v-if="radiovalue1 == '司机'">
               <uni-datetime-picker v-model="registerFormModel.expirationTimeTradequalification" type="datetime"  />
            </u-form-item>
            <u-form-item label="是否非煤车辆"
               v-if="radiovalue1 == '司机'"
               labelWidth="30%"
               borderBottom
               prop="isNonCoal">
               <u-checkbox-group v-model="registerFormModel.isNonCoal"
                  placement="row"
                  size="40"
                  @change="isNonCoalChange">
                  <u-checkbox name="是"
                     label-size="30">
                  </u-checkbox>
               </u-checkbox-group>
               <uni-datetime-picker v-model="registerFormModel.expirationTimeTradequalification" type="date"  :start="minDate" />
            </u-form-item>
            <u-form-item labelWidth="20%"
               v-if="radiovalue1 == '司机'"
               label="车辆类型"
               label="环保类型"
               borderBottom
               prop="countryNumberCar">
               <u-radio-group v-model="registerFormModel.countryNumberCar"
@@ -301,7 +302,84 @@
         }
      },
      data() {
      const validatePass = (rule, value, callback) => {
        if (this.registerFormModel.confirmPassword !== "") {
          if (value !== this.registerFormModel.password) {
            callback(new Error("两次输入密码不一致!"));
          } else {
            callback();
          }
        } else {
          callback();
        }
      };
      const checkPassword = (rule, value, callback) => {
        // let roles = this.$store.getters.roles;//当前用户角色id
        // let passL = 8;
        // if (roles.concat(1)){
        //   passL = 10
        // }
        let passL = 8;
        this.level = []
        if(!value) {
          return callback('密码不能为空')
        }
        if(value.length < passL) {
          return callback(`密码不能少于${passL}位`)
        }
        if(value.length > 16) {
          return callback('密码不能大于16位')
        }
        //校验是数字
        const regex1 = /^\d+$/
        // 校验字母
        const regex2 = /^[A-Za-z]+$/
        // 校验符号
        const regex3 =
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]+$/;
        if(regex1.test(value)) {
          this.level.push('low')
          return callback('密码强度过低')
        }else if(regex2.test(value)) {
          this.level.push('low')
          return callback('密码强度过低')
        }else if(regex3.test(value)) {
          this.level.push('low')
          return callback('密码强度过低')
        }else if(/^[A-Za-z\d]+$/.test(value)) {
          this.level.push('low')
          this.level.push('middle')
          return callback('密码强度过低')
        }else if(
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、\d]+$/.test(
                value
            )
        ) {
          this.level.push('low')
          this.level.push('middle')
          return callback('密码强度过低')
        }else if(
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、A-Za-z]+$/.test(
                value
            )
        ) {
          this.level.push('low')
          this.level.push('middle')
          return callback('密码强度过低')
        } else if (
            /^[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、A-Za-z\d]+$/.test(
                value
            )
        ) {
          this.level.push('low')
          this.level.push('middle')
          this.level.push('high')
        }
        return callback()
      };
         return {
        level:[],  //密码强度数组
            minDate: this.getToday(),
            // 车牌号键盘控制
            carNumShow: false,
            keyValue: '',
@@ -320,10 +398,8 @@
               confirmPassword: '',
               tradeQualificationImg: '',
               driverImg: '',
               isNonCoal: [],
               isCoalCar: 1, //是否为煤炭车辆(司机使用字段) 1 是 2 不是
               countryNumberCar: 0, //车辆类型;国五 1,国六 2
               carType:0
               countryNumberCar: 2, //环保类型;国五 1,国六 2
               carType:null,
            },
            fileList1: [],
            fileList2: [],
@@ -347,12 +423,22 @@
               expirationTimeTradequalification: {
                  required: false,
               },
               name: {
               name: [{
                  type: 'string',
                  required: true,
                  message: '请填写姓名',
                  trigger: ['blur', 'change']
               },
               },{
                     pattern: /^[\u4e00-\u9fa5]{1,6}$/, //限制长度最多为 6 位
                     message: '姓名只能是中文',
                     trigger: ['blur', 'change']
                  }],
                  carType:[{
                     type: 'number',
                     required: true,
                     message: '请选择车辆类型',
                     trigger: ['blur', 'change']
                  }],
               idCard: [{
                     type: 'string',
                     required: true,
@@ -385,27 +471,19 @@
                  }
               ],
               password: [{
                     required: true,
                     message: '请设置初始密码',
                     trigger: ['blur', 'change']
                  },
                  {
                     min: 6,
                     max: 12,
                     message: '长度在6-12个字符之间'
                  }
               ],
            required: true,
            message: '请设置初始密码',
            trigger: ['blur', 'change']
          },
            {
              validator: checkPassword,
              trigger: 'change'
            }],
               confirmPassword: [{
                     required: true,
                     message: '请设置初始密码',
                     trigger: ['blur', 'change']
                  },
                  {
                     min: 6,
                     max: 12,
                     message: '长度在6-12个字符之间'
                  }
               ],
            required: true,
            validator: validatePass,
            trigger: "blur"
          }],
               carNo: [{
                     type: 'string',
                     required: true,
@@ -529,65 +607,71 @@
      },
      methods: {
         ...mapMutations(['changeisUploadimg']),
         getToday() {
           let now = new Date();
           let year = now.getFullYear();
           let month = this.padStart(now.getMonth() + 1); // 月份是从0开始的
           let day = this.padStart(now.getDate());
           return `${year}-${month}-${day}`;
         },
         padStart(value) {
           return value.toString().padStart(2, '0');
         },
         productcarTypeChange(e){
            console.log(this.registerFormModel.carType,this.radiolist2.find(v => v.value === e).value)
            this.registerFormModel.carType = this.radiolist2.find(v => v.value === e).value
         },
         registerClick() {
            if (this.registerFormModel.password == this.registerFormModel.confirmPassword) {
               if(this.registerFormModel.carType==3&&!this.registerFormModel.tradeQualificationImg||this.registerFormModel.carType==4&&!this.registerFormModel.tradeQualificationImg){
                  uni.showToast({
                     title: '请上传从业资格证!',
                     icon: 'error',
                     duration: 2000
                  });
               }else{
               this.$refs.regesterFormRef
                  .validate()
                  .then(res => {
                     this.registerClickloading = true;
                     this.registerFormModel.username = this.registerFormModel.phone;
                     this.registerFormModel.idCardImg = this.registerFormModel.cardImg1+","+this.registerFormModel.cardImg2;
                     if(this.registerFormModel.expirationTimeDriver){
                        this.registerFormModel.expirationTimeDriver=this.registerFormModel.expirationTimeDriver.slice(0,16)
                     }
                     if(this.registerFormModel.expirationTimeDriving){
                        this.registerFormModel.expirationTimeDriving=this.registerFormModel.expirationTimeDriving.slice(0,16)
                     }
                     if(this.registerFormModel.expirationTimeIdcard){
                        this.registerFormModel.expirationTimeIdcard=this.registerFormModel.expirationTimeIdcard.slice(0,16)
                     }
                     if(this.registerFormModel.expirationTimeTradequalification){
                        this.registerFormModel.expirationTimeTradequalification=this.registerFormModel.expirationTimeTradequalification.slice(0,16)
                     }
                        this.$reqPost('registerDriver', this.registerFormModel, 'json')
                        .then(res => {
                           this.registerClickloading = false;
                           if (res.code == 0) {
                              uni.showToast({
                                 title: '注册成功,即将返回登录页',
                                 icon: 'none',
                                 duration: 1000
                              });
                              setTimeout(() => {
                                 uni.redirectTo({ url: '/pages/login/login' });
                              }, 1000);
                           } else {
                              this.$u.toast(res.data.msg ? res.data.msg : '添加失败');
                           }
                        })
                        .catch(err => {
                           console.log('错误', err);
                        });
                  })
                  .catch(err => {
                     console.log('err', err);
                     this.$u.toast('请规范输入内容');
                  });
                  }
            } else {
               this.$u.toast('两次密码不一致');
            }
        if(this.registerFormModel.carType==3&&!this.registerFormModel.tradeQualificationImg||this.registerFormModel.carType==4&&!this.registerFormModel.tradeQualificationImg){
          uni.showToast({
            title: '请上传从业资格证!',
            icon: 'error',
            duration: 2000
          });
        }else{
          this.$refs.regesterFormRef
              .validate()
              .then(res => {
                this.registerClickloading = true;
                this.registerFormModel.username = this.registerFormModel.phone;
                this.registerFormModel.idCardImg = this.registerFormModel.cardImg1+","+this.registerFormModel.cardImg2;
                if(this.registerFormModel.expirationTimeDriver){
                  this.registerFormModel.expirationTimeDriver=this.registerFormModel.expirationTimeDriver.slice(0,16)
                }
                if(this.registerFormModel.expirationTimeDriving){
                  this.registerFormModel.expirationTimeDriving=this.registerFormModel.expirationTimeDriving.slice(0,16)
                }
                if(this.registerFormModel.expirationTimeIdcard){
                  this.registerFormModel.expirationTimeIdcard=this.registerFormModel.expirationTimeIdcard.slice(0,16)
                }
                if(this.registerFormModel.expirationTimeTradequalification){
                  this.registerFormModel.expirationTimeTradequalification=this.registerFormModel.expirationTimeTradequalification.slice(0,16)
                }
                this.$reqPost('registerDriver', this.registerFormModel, 'json')
                    .then(res => {
                      this.registerClickloading = false;
                      if (res.code == 0) {
                        uni.showToast({
                          title: '注册成功,即将返回登录页',
                          icon: 'none',
                          duration: 1000
                        });
                        setTimeout(() => {
                          uni.redirectTo({ url: '/pages/login/login' });
                        }, 1000);
                      } else {
                        this.$u.toast(res.msg ? res.msg : '添加失败');
                      }
                    })
                    .catch(err => {
                      console.log('错误', err);
                    });
              })
              .catch(err => {
                console.log('err', err);
                this.$u.toast('请规范输入内容');
              });
        }
         },
         // 单选框事件
         groupChange(e) {},
@@ -697,9 +781,6 @@
            this.$nextTick(() => {
               this.editRoleModelShow = false;
            });
         },
         isNonCoalChange() {
            this.registerFormModel.isCoalCar = this.registerFormModel.isNonCoal.length !== 0 ? 1 : 2
         }
      }
   };
@@ -738,4 +819,43 @@
         }
      }
   }
</style>
  .intensity {
    width: 100%;
    margin-top: 10rpx;
    .psdText {
      font-size: 14px;
      margin-right: 10px;
    }
    .line {
      display: inline-block;
      width: 70rpx;
      height: 8rpx;
      background: #d8d8d8;
      border-radius: 6rpx;
      margin-right: 16rpx;
      &.low {
        background: #f4664a;
      }
      &.middle {
        background: #ffb700;
      }
      &.high {
        background: #2cbb79;
      }
    }
    .level {
      margin: 0 32rpx 0 16rpx;
    }
    .warningtext {
      color: #5a5a5a;
      font-size: 24rpx;
      margin-top: 10rpx;
    }
  }
</style>