PersonalMsg.vue 17.0 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
<template>
  <!-- 个人信息 -->
  <div class="personal_msg clearfix">
    <!-- 选项卡 -->
    <div class="personal_tabs">
      <div
        class="tab_option"
        v-for="(item,index) in tabList"
        :key="index"
        :class="{border_bottom:isBot == index}"
        @click="handleClick(index)"
      >{{item}}</div>
    </div>
    <!-- 内容 -->
    <div class="tab_box clearfix">
      <!-- 个人信息 -->
      <div class="tab_content layout justify flex_diection align_left clearfix" v-show="isBot == 0">
        <div class="tab_det_msg layout flex_row align_center">
          <div class="msg_title">学校:</div>
          <div class="msg_content">{{personalMsg.school_name}}</div>
        </div>
        <div class="tab_det_msg layout flex_row align_center">
          <div class="msg_title">年级:</div>
          <div class="msg_content">{{personalMsg.nianji}}</div>
        </div>
        <div class="tab_det_msg layout flex_row align_center">
          <div class="msg_title">姓名:</div>
          <div
            class="msg_content"
          >{{personalMsg.nickname}}{{groupId == 3?"(班主任)":groupId == 2?"(家长)":""}}</div>
        </div>
        <div class="tab_det_msg layout flex_row align_center">
          <div class="msg_title">学号:</div>
          <div class="msg_content">{{personalMsg.username}}</div>
        </div>
        <!-- 邮箱 -->
        <div class="tab_det_msg layout flex_row">
          <div class="msg_title">邮箱:</div>
          <div v-show="isEmail" class="layout flex_row align_center clearfix">
            <div class="msg_content" v-if="personalMsg.email">{{personalMsg.email}}</div>
            <div class="msg_operation" @click="modifyEmail">{{personalMsg.email?"修改邮箱":"绑定邮箱"}}</div>
          </div>
          <div v-show="!isEmail" class="modify_box">
            <div class="layout flex_row align_left email_inp ie_inp clearfix">
              <input type="text" class="inp_code" v-model="email" />
              <div class="send_email" @click="sendEmail()" v-show="isShowEmail">发送认证邮件</div>
              <div class="send_email send_code" v-show="!isShowEmail">{{email_time}}秒后重新发送</div>
              <div class="cancle" @click="Cancle">取消</div>
            </div>
            <div class="email_tips">邮箱注册用户修改邮箱后,登录名也一并修改,且半年内不能再修改,请谨慎填写!</div>
          </div>
        </div>
        <!-- 手机号 -->
        <div class="tab_det_msg layout flex_row">
          <div class="msg_title">手机号:</div>
          <div v-show="isPhone" class="layout flex_row align_center">
            <div class="msg_content" v-if="personalMsg.mobile">{{personalMsg.mobile}}</div>
            <div class="msg_operation" @click="modifyPhone()">{{personalMsg.mobile?"修改手机":"绑定手机"}}</div>
          </div>
          <div v-show="!isPhone" class="modify_box">
            <div class="layout flex_row align_left email_inp clearfix">
              <input type="text" maxlength="11" class="inp_code" v-model="phone" />
              <div class="send_email send_code" @click="getCode()" v-show="isShowPhone">获取验证码</div>
              <div class="send_email send_code" v-show="!isShowPhone">{{phone_time}}秒后重新获取</div>
              <div class="phone_num" v-show="isPhoneErr">请输入11位手机号</div>
            </div>
            <div class="email_tips">手机注册用户修改手机后,登录名也一并修改,且一周内不能再修改,请谨慎填写!</div>
          </div>
        </div>
        <!-- 验证码 -->
        <div class="tab_det_msg layout flex_row align_center clearfix" v-show="!isPhone">
          <div class="msg_title">验证码:</div>
          <input type="text" maxlength="4" class="inp_code inp_cap" v-model="smsCode" />
          <div class="phone_num code_num" v-show="isSmsCode">验证码错误请重新输入验证码</div>
        </div>
        <el-button type="primary" v-show="!isPhone" @click="submit">确定</el-button>
      </div>
      <!-- 修改密码 -->
      <div class="tab_pwd layout justify flex_diection align_left" v-show="isBot == 1">
        <!-- 原密码 -->
        <div class="oldPwd layout flex_row align_center">
          <label for>
            <i class="pwd_star">*</i>原密码:
          </label>
          <input type="password" class="pwd_inp" placeholder="请输入密码" v-model="oldPass" />
          <div class="pwd_tips" v-show="isOld">密码错误请输入正确密码</div>
        </div>
        <!-- 新密码 -->
        <div class="newPwd layout flex_row align_center">
          <label for>
            <i class="pwd_star">*</i>新密码:
          </label>
          <input type="password" class="pwd_inp" placeholder="请输入新密码" v-model="newPass" />
          <div class="pwd_tips" v-show="isNew">含有非法字符,请重新输入</div>
        </div>
        <!-- 确认密码 -->
        <div class="rePwd layout flex_row align_center">
          <label for>
            <i class="pwd_star">*</i>确认密码:
          </label>
          <input type="password" class="pwd_inp" placeholder="请确认新密码" v-model="rePass" />
          <div class="pwd_tips" v-show="isReq">密码不一致,请重新输入</div>
        </div>
        <el-button type="primary" class="pwd_button" @click="submitPwd()">修改</el-button>
      </div>
      <!-- 头像设置 -->
      <div class="tab_head" v-show="isBot == 2">
        <div class="upload_tips">添加或更改您的头像</div>
        <div class="upload_tips">从电脑中选择一项您喜欢的照片上传,仅支持GIF,PNG,JPG文件,且大小不能超过5M</div>
        <div class="add_header_img layout align_center flex_diection justify_center">
          <div class="layout align_center flex_diection justify_center" v-if="!imageUrl">
            <div class="carmer">
              <img src="@/assets/img/carmer.png" alt />
            </div>
            <div class="el-upload__text" v-show="!imageUrl">选择图片</div>
          </div>
          <div class="upload_img" v-else>
            <img class="media_img" :src="imageUrl" alt />
          </div>
          <input @change="fileImage" type="file" class="add_file_input" />
        </div>
        <div class="err_tips" v-show="isErr">图片格式不符合要求</div>
        <div class="submit_pic" @click="submitPic()">上传图片</div>
      </div>
    </div>
  </div>
</template>
<script>
import { post, uploadFile } from "@/api/http";
import { Notification } from "element-ui";
import axios from "axios";
export default {
  data() {
    return {
      myHeaders: {
        token: localStorage.getItem("token")
      },
      tabList: ["个人信息", "修改密码", "头像设置"],
      isBot: 0,
      isEmail: true,
      isPhone: true,
      //   密码错误提示
      isNew: false,
      isOld: false,
      isReq: false,
      oldPass: "",
      newPass: "",
      rePass: "",
      personalMsg: "",
      //学校
      schoolName: "",
      // 年级
      group: "",
      classical: "",
      // 姓名
      name: "",
      // 学号
      studentId: "",
      // 邮箱
      email: "",
      // 手机号
      mobile: "",
      // 图片上传
      imageUrl: "",
      imgFile: "",
      isErr: false,
      file: "",
      // 邮箱认证
      email: "",
      // 验证码手机号
      phone: "",
      isPhoneErr: false,
      smsCode: "",
      isSmsCode: false,
      // 身份判断
      groupId: "",
      // 手机号倒计时
      phone_time: 0,
      isShowPhone: true,
      // 邮箱倒计时
      email_time: 0,
      isShowEmail: true,
      // 修改手机号连点
      phoneClick: true,
      picClick: true
    };
  },
  methods: {
    // 个人信息
    inform() {
      let url = "";
      if (this.groupId == 1) {
        url = "/api/student/inform";
      } else if (this.groupId == 2) {
        url = "/api/parents/inform";
      } else if (this.groupId == 3) {
        url = "/api/teacher/inform";
      }

      post(url).then(res => {
        this.personalMsg = res;
      });
    },
    // 获取手机验证码
    getCode() {
      let that = this;
      if (!/^1[3456789]\d{9}$/.test(this.phone)) {
        this.isPhoneErr = true;
      } else {
        //  发送验证码
        let url = "/api/sms/send";
        let params = {
          mobile: this.phone,
          event: "changemobile",
          type: this.groupId
        };
        var phoneTimer;
        that.phone_time = 60;
        post(url, params).then(res => {
          that.isShowPhone = false;
          phoneTimer = setInterval(function() {
            that.phone_time--;
            if (that.phone_time == 0) {
              clearInterval(phoneTimer);
              that.isShowPhone = true;
            }
          }, 1000);
          Notification.info({
            title: "提示",
            message: "发送成功",
            duration: 1500
          });
        });
      }
    },
    // 修改手机号
    submit() {
      // 防止连点
      if (this.phoneClick) {
        this.phoneClick = false;
        if (this.phone && this.smsCode) {
          let url = "/api/common/changemobile";
          let params = {
            mobile: this.phone,
            captcha: this.smsCode
          };
          post(url, params)
            .then(res => {
              Notification.info({
                title: "提示",
                message: "修改成功",
                duration: 1500
              });
              this.isPhone = true;
              this.inform();
            })
            .catch(err => {
              this.isSmsCode = true;
            });
        } else {
          let t = this;
          Notification.info({
            title: "提示",
            message: "请输入完整信息",
            duration: 1500,
            onClose() {
              t.phoneClick = true;
            }
          });
        }
      }
    },
    //选项卡切换
    handleClick(index) {
      this.isBot = index;
    },
    // 修改邮箱
    modifyEmail() {
      this.isEmail = false;
    },
    // 发送认证邮箱
    sendEmail() {
      let that = this;
      var testEmail = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
      if (testEmail.test(this.email)) {
        let url = "/api/ems/send";
        let params = {
          email: this.email,
          event: "changeemail"
        };
        var emailTimer;
        that.email_time = 60;
        post(url, params).then(res => {
          that.isShowEmail = false;
          emailTimer = setInterval(function() {
            that.email_time--;
            if (that.email_time == 0) {
              clearInterval(emailTimer);
              that.isShowEmail = true;
            }
          }, 1000);
          Notification.info({
            title: "提示",
            message: "邮件发送成功,请注意查收",
            duration: 1500
          });
        });
      } else {
        Notification.info({
          title: "提示",
          message: "请输入正确邮箱",
          duration: 1500
        });
      }
    },
    // 取消
    Cancle() {
      this.isEmail = true;
    },
    // 修改手机
    modifyPhone() {
      this.isPhone = false;
    },

    // 修改密码
    submitPwd() {
      this.isOld = false;
      this.isReq = false;
      if (this.oldPass && this.newPass && this.rePass) {
        let url = "/api/common/change_pwd";
        let params = {
          old_password: this.oldPass,
          new_password: this.newPass,
          confirm_password: this.rePass
        };
        post(url, params)
          .then(res => {
            this.outLogin();
          })
          .catch(err => {
            if (err.msg == "原密码错误") {
              this.isOld = true;
            }
            if (err.msg == "新密码与确认密码不一致") {
              this.isReq = true;
            }
          });
      } else {
        this.isOld = true;
      }
    },
    // 退出登录
    outLogin() {
      post("/api/common/logout").then(res => {
        let test = localStorage.getItem("schoolSymbol");
        localStorage.clear();
        this.$router.push({ path: "/login/" + test });
      });
    },
    // 上传图片
    fileImage(e) {
      const picType1 = e.target.files[0].type == "image/png";
      const picType2 = e.target.files[0].type == "image/jpeg";
      const picType3 = e.target.files[0].type == "image/gif";
      const picSize = e.target.files[0].size / 1024 / 1024 < 5;
      if (picType1 || picType2 || picType3) {
        this.file = e.target.files[0];
        this.imageUrl = URL.createObjectURL(this.file);
      } else {
        this.isErr = true;
        this.imageUrl = "";
        this.file = "";
      }
    },
    // 上传文件
    submitPic() {
      if (this.picClick) {
        this.picClick = false;
        if (this.file) {
          let url = "/api/common/upload";
          let formData = new FormData();
          formData.append("file", this.file, this.file.name);
          uploadFile(url, formData).then(res => {
            this.changePic(res.path);
          });
        } else {
          let t = this;
          Notification.info({
            title: "提示",
            message: "请选择图片",
            duration: 1500,
            onClose() {
              t.picClick = true;
            }
          });
        }
      }
    },
    // 修改头像
    changePic(path) {
      let url = "/api/common/update_avatar";
      let params = {
        avatar: path
      };
      post(url, params).then(res => {
        localStorage.setItem("headImg", res.avatar);
        Notification.info({
          title: "提示",
          message: "修改成功",
          duration: 1500
        });
        this.$router.push({ path: "/BlankPage" });
      });
    }
  },
  mounted() {
    this.groupId = localStorage.getItem("groupId");
    this.inform();
  }
};
</script>
<style scoped>
.personal_msg {
  background: #fff;
  height: 509px;
}

/* 选项卡 */
.personal_tabs {
  width: 100%;
  height: 49px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

.tab_option {
  float: left;
  width: 104px;
  height: 48px;

  line-height: 48px;
  text-align: center;
  font-size: 16px;
}

.border_bottom {
  border-bottom: 2px solid #409eff;
}

/* 个人信息内容 */
.tab_content {
  padding: 24px 22px;
  text-align: left;
  font-size: 16px;
}

.tab_det_msg {
  margin-bottom: 22px;
}

/* 标题 */
.msg_title {
  color: #bdc4ce;
  text-align: right;
  width: 64px;
  margin-right: 24px;
}

.msg_content {
  color: #8c9198;
  margin-right: 24px;
}

.modify_box {
  margin-top: -6px;
}

/* 操作 */
.msg_operation {
  color: #409eff;
}

.email_inp {
  margin: 0 0 12px 0;
  position: relative;
}

.ie_inp {
  width: 414px;
  line-height: 34px;
}

/* 输入框 */
.inp_code {
  width: 241px;
  margin-right: 24px;
}

/* 发送认证邮箱 */
.send_email {
  position: absolute;
  right: 57px;
  top: 0;
  padding: 0 15px;
  height: 33px;
  background-color: #409eff;
  color: #fff;
  font-size: 14px;
  text-align: center;
  line-height: 34px;
  border-radius: 0 3px 3px 0;
}

/* 取消 */
.cancle {
  color: #409eff;
  position: absolute;
  right: 0;
}

/* 提示 */
.email_tips {
  font-size: 12px;
  color: #f7c51b;
}

/* 手机号错误提示 */
.phone_num {
  color: #f44a5e;
  position: absolute;
  right: -60px;
  top: 5px;
}
.code_num {
  right: -200px;
}
.tab_det_msg {
  position: relative;
}

.send_code {
  right: 87px;
}

/* 验证码 */
.inp_cap {
  width: 241px;
}

.el-button {
  outline: none;
  width: 92px;
  height: 40px;
  margin-left: 88px;
  color: #fff;
}

/* 修改密码 */
.tab_pwd {
  margin: 24px 0 0 12px;
}

label {
  width: 77px;
  text-align: right;
  color: #bdc4ce;
  margin-right: 15px;
  font-size: 14px;
  display: block;
}

/* 星 */
.pwd_star {
  color: #f44a5e;
}

/* 新密码 */
.newPwd {
  margin: 10px 0;
}

.pwd_inp {
  width: 282px;
}

/* 修改按钮 */
.pwd_button {
  margin-left: 92px;
  margin-top: 25px;
}

/* 错误提示 */
.pwd_tips {
  color: #f44a5e;
  font-size: 12px;
  margin-left: 25px;
}

/* 头像设置 */
.tab_head {
  margin: 24px 0 0 20px;
  text-align: left;
}

.upload_tips {
  font-size: 14px;
  color: #bdc4ce;
  margin-bottom: 25px;
}

.el-icon-camera-solid {
  font-size: 30px;
  margin-top: 19px;
  color: #8c9198;
}

.el-upload__text {
  color: #bdc4ce;
  font-size: 12px;
}

/* 上传的图片 */
.avatar {
  width: 100%;
  height: 100%;
}

/* 上传图片按钮 */
.submit_pic {
  width: 116px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  border-radius: 3px;
  color: #fff;
  font-size: 14px;
  background-color: #409eff;
  margin-top: 24px;
}

.err_tips {
  color: #f44a5e;
  font-size: 12px;
}
.add_header_img {
  width: 84px;
  height: 84px;
  border: 1px dashed #bdc4ce;
  border-radius: 3px;
  position: relative;
}
.upload_img {
  width: 84px;
  height: 84px;
  position: absolute;
  top: 0;
  right: 0;
}
.upload_img img {
  width: 100%;
  height: 100%;
}
.carmer {
  width: 27px;
  height: 26px;
}
.carmer img {
  font-size: 0;
  width: 100%;
  height: 100%;
}
.add_file_input {
  position: absolute;
  width: 84px;
  height: 84px;
  padding-left: 0;
  opacity: 0;
  left: 0;
  top: 0;
  z-index: 999;
}
</style>