Commit 4d81bacbb3e027b001e6ed492c1b71e53a35d9eb
1 parent
167079c6
添加修改密码
Showing
3 changed files
with
142 additions
and
7 deletions
src/api/apis/apis.js
src/api/urls/apis.js
src/views/layout/header/header.vue
| ... | ... | @@ -9,7 +9,10 @@ |
| 9 | 9 | <!-- <li> |
| 10 | 10 | <langSelect></langSelect> |
| 11 | 11 | </li> --> |
| 12 | - <li class="dropdown-box" v-if="role != 'ROLE_PERSONAL'&&role != 'ROLE_PINGTAI'"> | |
| 12 | + <li | |
| 13 | + class="dropdown-box" | |
| 14 | + v-if="role != 'ROLE_PERSONAL' && role != 'ROLE_PINGTAI'" | |
| 15 | + > | |
| 13 | 16 | <div class="userInfo"> |
| 14 | 17 | <img :src="avatar" /> |
| 15 | 18 | <div class="txt"> |
| ... | ... | @@ -35,14 +38,18 @@ |
| 35 | 38 | </el-dropdown> |
| 36 | 39 | </li> |
| 37 | 40 | <li class="dropdown-box" v-if="role == 'ROLE_PINGTAI'"> |
| 38 | - <div class="userInfo"> | |
| 41 | + <div class="userInfo"> | |
| 39 | 42 | <img :src="avatar" /> |
| 40 | 43 | <div class="txt"> |
| 41 | 44 | <p>{{ `${this.$store.getters.info.name}` }}</p> |
| 42 | 45 | </div> |
| 43 | 46 | </div> |
| 44 | 47 | </li> |
| 45 | - <li class="dropdown-box" v-if="role == 'ROLE_PERSONAL'" @click="linkToUserInfo"> | |
| 48 | + <li | |
| 49 | + class="dropdown-box" | |
| 50 | + v-if="role == 'ROLE_PERSONAL'" | |
| 51 | + @click="linkToUserInfo" | |
| 52 | + > | |
| 46 | 53 | <div class="userInfo"> |
| 47 | 54 | <img :src="avatar" /> |
| 48 | 55 | <div class="txt"> |
| ... | ... | @@ -51,6 +58,16 @@ |
| 51 | 58 | </div> |
| 52 | 59 | </div> |
| 53 | 60 | </li> |
| 61 | + | |
| 62 | + <li class="fullScreen" v-if="role != 'ROLE_PERSONAL'" @click="openPwd"> | |
| 63 | + <el-tooltip | |
| 64 | + class="item" | |
| 65 | + effect="dark" | |
| 66 | + content="修改密码" | |
| 67 | + placement="bottom" | |
| 68 | + ><i class="el-icon el-icon-key"></i | |
| 69 | + ></el-tooltip> | |
| 70 | + </li> | |
| 54 | 71 | <li class="fullScreen" @click="fullScreen"> |
| 55 | 72 | <el-tooltip |
| 56 | 73 | class="item" |
| ... | ... | @@ -83,10 +100,53 @@ |
| 83 | 100 | </ul> |
| 84 | 101 | </el-header> |
| 85 | 102 | <!-- <tabNav></tabNav> --> |
| 103 | + <el-dialog title="修改密码" :visible.sync="diaPass" width="400"> | |
| 104 | + <el-form | |
| 105 | + v-loading="loading" | |
| 106 | + ref="formPass" | |
| 107 | + class="form-box" | |
| 108 | + :model="password" | |
| 109 | + :rules="rulesPassword" | |
| 110 | + label-width="160px" | |
| 111 | + > | |
| 112 | + <el-form-item label="旧密码:" prop="oldPassword" | |
| 113 | + ><el-col :span="10" | |
| 114 | + ><el-input | |
| 115 | + maxlength="30" | |
| 116 | + v-model="password.oldPassword" | |
| 117 | + placeholder="请输入密码" | |
| 118 | + show-password | |
| 119 | + ></el-input></el-col | |
| 120 | + ></el-form-item> | |
| 121 | + <el-form-item label="新密码:" prop="password" | |
| 122 | + ><el-col :span="10" | |
| 123 | + ><el-input | |
| 124 | + maxlength="30" | |
| 125 | + v-model="password.password" | |
| 126 | + placeholder="请输入新密码" | |
| 127 | + show-password | |
| 128 | + ></el-input></el-col | |
| 129 | + ></el-form-item> | |
| 130 | + <el-form-item label="确认密码:" prop="resetPassword" | |
| 131 | + ><el-col :span="10" | |
| 132 | + ><el-input | |
| 133 | + maxlength="30" | |
| 134 | + v-model="password.resetPassword" | |
| 135 | + placeholder="请输入新密码" | |
| 136 | + show-password | |
| 137 | + ></el-input></el-col | |
| 138 | + ></el-form-item> | |
| 139 | + </el-form> | |
| 140 | + <div class="dialog-footer" slot="footer"> | |
| 141 | + <el-button @click="editPass">确 定</el-button> | |
| 142 | + <el-button @click="diaPass = false">取 消</el-button> | |
| 143 | + </div> | |
| 144 | + </el-dialog> | |
| 86 | 145 | </div> |
| 87 | 146 | </template> |
| 88 | 147 | |
| 89 | 148 | <script> |
| 149 | +import { encryptLoginPassword } from "@/utils"; | |
| 90 | 150 | import langSelect from "../../../components/lang/langSelect"; |
| 91 | 151 | import tabNav from "./tabNav"; |
| 92 | 152 | import _ from "lodash"; |
| ... | ... | @@ -100,6 +160,7 @@ export default { |
| 100 | 160 | }, |
| 101 | 161 | data() { |
| 102 | 162 | return { |
| 163 | + loading: false, | |
| 103 | 164 | code: "", |
| 104 | 165 | role: "", |
| 105 | 166 | isfullScreen: true, |
| ... | ... | @@ -109,11 +170,30 @@ export default { |
| 109 | 170 | title: "", |
| 110 | 171 | userId: "", |
| 111 | 172 | isCollapse: false, |
| 173 | + diaPass: false, | |
| 174 | + password: { | |
| 175 | + oldPassword: "", | |
| 176 | + password: "", | |
| 177 | + resetPassword: "", | |
| 178 | + }, | |
| 179 | + rulesPassword: { | |
| 180 | + oldPassword: [ | |
| 181 | + { required: true, message: "请输入旧密码", trigger: "blur" }, | |
| 182 | + ], | |
| 183 | + password: [ | |
| 184 | + { required: true, message: "请输入新密码", trigger: "blur" }, | |
| 185 | + ], | |
| 186 | + resetPassword: [ | |
| 187 | + { required: true, message: "请输入新密码", trigger: "blur" }, | |
| 188 | + ], | |
| 189 | + }, | |
| 112 | 190 | }; |
| 113 | 191 | }, |
| 114 | 192 | created() { |
| 115 | 193 | this.code = localStorage.getItem("csCode") || ""; |
| 116 | - this.role = this.$store.getters.info.showRole || this.$store.getters.info.permissions[0].role; | |
| 194 | + this.role = | |
| 195 | + this.$store.getters.info.showRole || | |
| 196 | + this.$store.getters.info.permissions[0].role; | |
| 117 | 197 | this.isCollapse = this.$store.getters.isCollapse; |
| 118 | 198 | }, |
| 119 | 199 | methods: { |
| ... | ... | @@ -129,10 +209,51 @@ export default { |
| 129 | 209 | 2000, |
| 130 | 210 | { leading: true, trailing: false } |
| 131 | 211 | ), |
| 212 | + openPwd() { | |
| 213 | + this.password.password = ""; | |
| 214 | + this.password.oldPassword = ""; | |
| 215 | + this.password.resetPassword = ""; | |
| 216 | + this.diaPass = true; | |
| 217 | + }, | |
| 218 | + editPass() { | |
| 219 | + if (this.loading) { | |
| 220 | + return; | |
| 221 | + } | |
| 222 | + this.$refs.formPass.validate(async (valid) => { | |
| 223 | + if (valid) { | |
| 224 | + if (this.password.password != this.password.resetPassword) { | |
| 225 | + this.$message.warning("两次输入密码不一致请检查!"); | |
| 226 | + return; | |
| 227 | + } | |
| 228 | + this.loading = true; | |
| 229 | + const { data, status, info } = await this.$request.changePwd({ | |
| 230 | + oldPassword: encryptLoginPassword(this.password.oldPassword), | |
| 231 | + password: encryptLoginPassword(this.password.password), | |
| 232 | + }); | |
| 233 | + this.loading = false; | |
| 234 | + if (status === 0) { | |
| 235 | + this.$message.success("密码修改成功~"); | |
| 236 | + this.diaPass = false; | |
| 237 | + const res = await this.$request.logout(); | |
| 238 | + this.$store.commit("setToken", ""); | |
| 239 | + this.$store.commit("setInfo", {}); | |
| 240 | + this.$store.commit("setRouters", []); | |
| 241 | + this.$store.commit("resetTabnavBox"); | |
| 242 | + this.$router.push({ | |
| 243 | + path: "/login", | |
| 244 | + }); | |
| 245 | + } else { | |
| 246 | + this.$message.error(info); | |
| 247 | + } | |
| 248 | + } else { | |
| 249 | + this.$message.error("数据有误,请检查!"); | |
| 250 | + } | |
| 251 | + }); | |
| 252 | + }, | |
| 132 | 253 | linkToUserInfo() { |
| 133 | 254 | this.$router.push({ |
| 134 | - path:'/userInfo' | |
| 135 | - }) | |
| 255 | + path: "/userInfo", | |
| 256 | + }); | |
| 136 | 257 | }, |
| 137 | 258 | collapse() { |
| 138 | 259 | this.isCollapse = !this.isCollapse; |
| ... | ... | @@ -180,7 +301,7 @@ export default { |
| 180 | 301 | if (data) { |
| 181 | 302 | window.location.href = data; |
| 182 | 303 | } else { |
| 183 | - localStorage.setItem("token","") | |
| 304 | + localStorage.setItem("token", ""); | |
| 184 | 305 | this.$store.commit("setToken", ""); |
| 185 | 306 | this.$store.commit("setInfo", {}); |
| 186 | 307 | this.$store.commit("setRouters", []); | ... | ... |