819527061@qq.com
2024-07-09 e40cf023cdc19d3bdea6cfb5d74cca65cd7b9679
pages/register/register.vue
@@ -3,8 +3,9 @@
      <view class="registerForm">
         <u--form :rules="rules"
            :model="registerFormModel"
            ref="regesterFormRef">
            <u-form-item labelWidth="20%"
            ref="regesterFormRef"
            :labelStyle="labelStyle">
            <u-form-item labelWidth="160"
               label="选择身份"
               borderBottom
               ref="roleRef"
@@ -25,68 +26,110 @@
                     @change="radioChange"></u-radio>
               </u-radio-group>
            </u-form-item>
        <u-form-item
            v-if="radiovalue1 == '司机'"
            labelWidth="200"
                     label="是否有车辆"
                     borderBottom
                     required>
          <u-radio-group v-model="isHaveCar"
                         placement="row"
                         size="30"
                         shape="circle"
                         iconSize="20">
            <u-radio labelSize="14px"
                     size="20px"
                     :customStyle="{ marginBottom: '8px' }"
                     v-for="(item, index) in isHaveCarList"
                     :key="index"
                     :label="item.label"
                     :name="item.value"
                     @change="radioChange"></u-radio>
          </u-radio-group>
        </u-form-item>
            <u-form-item prop="name"
               label="姓名"
               labelWidth="20%"
               borderBottom
               required>
                label="姓名"
           labelWidth="160"
                borderBottom
                required>
               <u--input v-model="registerFormModel.name"
                  placeholder="请输入内容"
                  fontSize='40'
                  clearable></u--input>
            </u-form-item>
            <u-form-item prop="idCard"
               label="身份证"
               labelWidth="20%"
               labelWidth="160"
               borderBottom
               required>
               <u--input v-model="registerFormModel.idCard"
                  placeholder="请输入内容"
                  fontSize='40'
                  clearable></u--input>
            </u-form-item>
            <u-form-item prop="phone"
               label="手机号"
               labelWidth="20%"
               labelWidth="160"
               borderBottom
               required>
               <u--input v-model="registerFormModel.phone"
                  fontSize='40'
                  placeholder="请输入内容"
                  clearable></u--input>
            </u-form-item>
            <u-form-item prop="password"
               label="密码"
               labelWidth="20%"
               labelWidth="160"
               borderBottom
               required>
               <u--input v-model="registerFormModel.password"
                  placeholder="请输入内容"
                  fontSize='40'
                  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%"
               labelWidth="160"
               borderBottom
               required>
               <u--input v-model="registerFormModel.confirmPassword"
                  placeholder="请输入内容"
                  fontSize='40'
                  password
                  clearable
                  @blur="jiaoYanPassword"></u--input>
            </u-form-item>
            <u-form-item prop="carNo"
               label="车牌号"
               labelWidth="20%"
               labelWidth="160"
               borderBottom
               v-if="radiovalue1 == '司机'"
               v-if="radiovalue1 == '司机' && isHaveCar == '1'"
               required>
               <u--input v-model="registerFormModel.carNo"
                  placeholder="请输入内容"
                  fontSize='40'
                  clearable></u--input>
            </u-form-item>
            <u-form-item labelWidth="20%"
            <u-form-item labelWidth="160"
               label="车牌颜色"
               borderBottom
               v-if="radiovalue1 == '司机'"
               v-if="radiovalue1 == '司机'  && isHaveCar == '1'"
               required
               prop="vehicleColour">
               <u-radio-group v-model="registerFormModel.vehicleColour"
@@ -105,9 +148,9 @@
            </u-form-item>
            <u-form-item prop="carImg"
               label="车辆照片"
               labelWidth="20%"
               labelWidth="160"
               borderBottom
               v-if="radiovalue1 == '司机'"
               v-if="radiovalue1 == '司机'  && isHaveCar == '1'"
               required
               @click="beforeRead">
               <u-upload :fileList="fileList1"
@@ -122,30 +165,34 @@
                  :previewFullImage="true">
               </u-upload>
            </u-form-item>
            <u-form-item prop="bodyOfCarJpg"
               label="车辆细节照片"
               labelWidth="20%"
               borderBottom
               v-if="radiovalue1 == '司机'"
               required
               @click="beforeRead">
               <u-upload :fileList="fileList3"
                  deletable
                  @afterRead="afterRead"
                  @delete="deletePic"
                  name="3"
                  multiple
                  :maxCount="3"
                  width="250"
                  height="150"
                  :previewFullImage="true">
               </u-upload>
            </u-form-item>
        <div class="column-box">
          <u-form-item
              prop="bodyofcarJpg"
              label="车头、车尾、车身照片"
              labelWidth="auto"
              borderBottom
              v-if="radiovalue1 == '司机'  && isHaveCar == '1'"
              required
              @click="beforeRead">
            <u-upload :fileList="fileList3"
                      deletable
                      @afterRead="afterRead"
                      @delete="deletePic"
                      name="3"
                      multiple
                      :maxCount="3"
                      width="250"
                      height="150"
                      :previewFullImage="true">
            </u-upload>
          </u-form-item>
        </div>
            <u-form-item prop="drivingImg"
               label="行驶证"
               labelWidth="20%"
               labelWidth="160"
               borderBottom
               v-if="radiovalue1 == '司机'"
               v-if="radiovalue1 == '司机'  && isHaveCar == '1'"
               required
               @click="beforeRead">
               <u-upload :fileList="fileList2"
@@ -161,10 +208,11 @@
               </u-upload>
            </u-form-item>
            <u-form-item label="推荐人账号"
               labelWidth="25%"
               labelWidth="200"
               borderBottom>
               <u--input v-model="registerFormModel.tuiJianMa"
                  placeholder="请输入内容"
                  fontSize='40'
                  clearable></u--input>
            </u-form-item>
         </u--form>
@@ -179,7 +227,8 @@
      </view>
      <view class="registerBtn"><u-button text="注册"
            type="primary"
            @click="registerClick"></u-button></view>
            @click="registerClick"
        :loading="registerClickloading"></u-button></view>
      <!-- 图片预览弹出框 -->
      <!-- <view class="previewImage-container">
         <u-popup :show="previewImageShow" mode="center" @close="previewImageClose" @open="previewImageOpen">
@@ -218,7 +267,87 @@
         }
      },
      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 {
        isHaveCar:'1', //是否有车辆
        level:[],  //密码强度数组
            labelStyle: {
               fontSize: '36rpx'
            },
            // 车牌号键盘控制
            carNumShow: false,
            keyValue: '',
@@ -236,7 +365,7 @@
               tuiJianMa: '',
               confirmPassword: '',
               vehicleColour: '',
               bodyOfCarJpg: ''
               bodyofcarJpg: ''
            },
            fileList1: [],
            fileList2: [],
@@ -281,24 +410,18 @@
               ],
               password: [{
                     required: true,
                     message: '请设置初始密码',
                     message: '请设置密码',
                     trigger: ['blur', 'change']
                  },
                  {
                     min: 6,
                     max: 12,
                     message: '长度在6-12个字符之间'
                  }
            {
              validator: checkPassword,
              trigger: 'change'
            }
               ],
               confirmPassword: [{
                     required: true,
                     message: '请设置初始密码',
              validator: validatePass,
                     trigger: ['blur', 'change']
                  },
                  {
                     min: 6,
                     max: 12,
                     message: '长度在6-12个字符之间'
                  }
               ],
               carNo: [{
@@ -330,7 +453,7 @@
                  message: '请上传车辆图片',
                  trigger: ['blur', 'change']
               },
               bodyOfCarJpg: {
               bodyofcarJpg: {
                  type: 'string',
                  required: true,
                  message: '请上传车辆图片',
@@ -352,18 +475,25 @@
                  disabled: false
               }
            ],
        isHaveCarList: [{
          value: '1',
          label: '是',
        },{
          value: '2',
          label: '否'
        }],
            radiovalue1: '货代',
            radiolist2: [{
                  name: '黄色',
                  value: 'huangse'
                  value: '黄色'
               },
               {
                  name: '绿色',
                  value: 'lvse'
                  name: '黄绿色',
                  value: '黄绿色'
               },
               {
                  name: '蓝色',
                  value: 'lanse'
                  value: '蓝色'
               }
            ],
            beforeChangeValue: '',
@@ -372,7 +502,8 @@
            title: '提示',
            content: '当前填入信息,切换角色后,即清除,是否切换?',
            wxcode: '',
            openid: ''
            openid: '',
        registerClickloading: false,
         };
      },
      watch: {
@@ -401,38 +532,44 @@
      methods: {
         ...mapMutations(['changeisUploadimg']),
         registerClick() {
            if (this.registerFormModel.password == this.registerFormModel.confirmPassword) {
               this.$refs.regesterFormRef
                  .validate()
                  .then(res => {
                     console.log(this.registerFormModel);
                     this.registerFormModel.username = this.registerFormModel.phone;
                     apiRegister(this.registerFormModel)
                        .then(res => {
                           if (res.data.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.fileList3 && this.fileList3.length > 0) {  //车头车尾车身需要3张图片也可以一张也不传
          if(this.fileList3.length !== 3) {
            this.$u.toast('车头车尾车身需要3张图片');
            return
          }
        }
        this.$refs.regesterFormRef
            .validate()
            .then(res => {
              console.log(this.registerFormModel);
              this.registerClickloading = true;
              this.registerFormModel.username = this.registerFormModel.phone;
              apiRegister(this.registerFormModel)
                  .then(res => {
                    if (res.data.code == 0) {
                      this.registerClickloading = false;
                      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('请规范输入内容');
            }).finally(() => {
              this.registerClickloading = false;
        });
         },
         // 单选框事件
         groupChange(e) {},
@@ -508,7 +645,7 @@
                     } else if (num == 3) {
                        let imageUrl = JSON.parse(res.data).data.url
                        this.carBody.push(imageUrl)
                        this.registerFormModel.bodyOfCarJpg = this.carBody.join(',')
                        this.registerFormModel.bodyofcarJpg = this.carBody.join(',')
                        resolve(`${BaseUrl}${JSON.parse(res.data).data.url}`);
                     }
                  }
@@ -572,4 +709,53 @@
         }
      }
   }
</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;
    }
  }
  .column-box{
    ::v-deep{
      .u-form-item__body{
        flex-direction: column!important;
      }
      .u-form-item__body__right{
        margin-top: 20rpx;
      }
    }
  }
</style>