top.vue 7.49 KB
Newer Older
qzhxx's avatar
qzhxx committed
1 2
<template>
  <div class="header_container" style="overflow:hidden;">
qzhxx's avatar
qzhxx committed
3
    <!-- <div class="headerTitle l-float">中国国家博物馆建党百年展点播院线服务平台</div> -->
qzhxx's avatar
qzhxx committed
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
    <el-dropdown class="adminlogo r-float H100" @command="handleCommand" trigger="click">
      <div class="box">
        <span class="el-dropdown-link">
           {{loginInf.username}}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
      </div>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="editPwd">修改密码</el-dropdown-item>
        <el-dropdown-item command="singout">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <span class="header_icon r-float">
      <img class="bell" src="../../../static/images/icon/bell.png" alt="" />
      <img :src="loginInf.avatar" class="avator" />
    </span>
    <el-dialog title="修改密码" class="hotEvent" :visible.sync="editManege" width="30%" :before-close="close">
      <el-form :model="form" :rules="Rules" id="ruleo" ref="form" label-position="right" label-width="100px">
        <el-form-item label="旧密码:" prop="oldPass">
          <el-input  type="password" size="small"  v-model="form.oldPass" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="新密码:" prop="newPass">
          <el-input  type="password" size="small"  v-model="form.newPass" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码:" prop="checkPass">
          <el-input  type="password" size="small"  v-model="form.checkPass" auto-complete="off"></el-input>
        </el-form-item>
        <!--password-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="close">取消</el-button>
        <el-button type="primary" size="mini" @click="submitForm">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      var validatePass = (rule, value, callback) => {
        if (value == '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.form.newPass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        activeIndex: "",
        loginInf: {},
        editManege: false,
        form: {
          oldPass: '',
          newPass: '',
          checkPass: ''
        },
        Rules: {
          oldPass: [
            {required: true, message: '请输入旧密码', trigger: 'blur'}
          ],
          newPass: [
            {required: true, message: '请输入新密码', trigger: 'blur'},
            {min: 6, message: '密码至少为6个字符', trigger: 'blur'},
            {pattern: /^[a-zA-Z0-9_-]{0,20}$/, message: '请设置合格的密码(可用字母,数字,下划线,减号)'}
          ],
          checkPass: [
            {required: true, message: '请再次输入密码', trigger: 'blur'},
            {validator: validatePass, trigger: 'blur'}
          ]
        },
      }
    },
    mounted() {
      this.initData();
    },
    computed: {},
    methods: {
      initData () {
        let inf={
          avatar:'',
          username:'',
        }
        inf.avatar = localStorage.getItem('avatar');
        inf.username = localStorage.getItem('username');
        this.loginInf=inf;
      },
      handleCommand(command) {
        command == 'singout' ? this.singout() : this.editPwd();
      },
      singout() {
        let vm = this;
        vm.$https({
          url: `logout?token=${localStorage.getItem('backToken')}`,
          method: 'get',
        }).then(res=>{
          vm.removeSession()
          if (res.status == 200) {
            vm.$message({
              type: 'success',
              message: '退出登录!'
            });
            setTimeout(function () {
              vm.$router.push('/');
            },500);
          }
        })
      },
      removeSession () {
        if (localStorage.getItem('backToken')) {
           localStorage.clear();
        }
      },
      editPwd() {
        let _this = this;
        for (let key in _this.form) {
          _this.form[key] = null;
        }
        this.editManege = true;
      },
      submitForm() {
        let _this = this;
        let searchObj = {
          "oldPassWord": _this.form.oldPass,
          "password": _this.form.newPass
        };
        _this.$refs.form.validate((valid) => {
          if (valid) {
            _this.$https({
              url: 'employee/editPwd',
              method: 'put',
              authType: this.backToken
            }, _this.$qs.stringify(searchObj))
              .then((res) => {
                if (res.status == 200) {
                    _this.$message({
                      type: 'success',
                      message: res.data.message
                    });
                    _this.close();
                    _this.removeSession();
                    setTimeout(function () {
                      _this.$router.push('/');
                    },500);
                  } else {
                    _this.$message({
                      type: 'error',
                      message: res.data.message
                    });
                  }
                }, (error) => {
                  _this.$message({
                    type: 'error',
                    message: error
                  });
                }
              )
          } else {
            return false;
          }
        });
      },
      close() {
        this.editManege = false;
        this.$refs['form'].resetFields();
      },
    }
  }
</script>
<style lang="less">
  @import '../../style/common';
  .header_container {
    width: 100%;
    height: 63px;
    background-color: #dd44;
qzhxx's avatar
qzhxx committed
179 180 181 182 183 184 185 186 187 188 189
    .headerTitle {
        // width: 100%;
        /*height: 8%;*/
        height: 63px;
        line-height: 63px;
        // background: #002140;
        font-size: 24px;
        font-weight: 600;
        // color: rgba(255, 255, 255, 1);
        // text-align: center;
      }
qzhxx's avatar
qzhxx committed
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
    .header_icon{
      line-height:63px;
      margin-right:20px;
      img{
        vertical-align: middle;
        &.bell{margin-right:25px;}
        &.avator{background-color:#1D6CAD;border-radius:50%;width:24px; height: 24px;}
      }
    }
    .box {
      cursor: pointer;
      float: right;
      margin-right: 25px;
      margin-top: 20px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;

    }
    /*!*弹窗*!*/
    .el-dialog{
      width: 600px;
      background:rgba(255,255,255,1);
      box-shadow:0px 4px 12px 0px rgba(0,0,0,0.2);
      border-radius:4px;
      .el-dialog__header{
        padding: 15px;
        border-bottom: 1px solid rgba(0,0,0,0.09);
      }
      .el-dialog__body{
        padding: 0px 20px;
        border: 1px solid transparent;
        margin-top: 10px;
        .form_box{
          padding-bottom: 40px;
          .el-form {
            margin-bottom: 20px;
            .el-form-item{
              margin: 10px  50px 20px;
              .el-form-item__content{
                width: 280px;
              }
            }
            .el-input{
              width: 100%;
            }
          }
          .dialog-footer{
            border-top: 1px solid rgba(0,0,0,0.09);
            padding-top: 8px;
            .el-button{
              margin-right: 10px;
              padding: 8px 16px;
            }
          }
        }
      }
    }
  }

  .el-table::before {
    background-color: transparent;
  }
</style>