resetpassword.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div>
  3. <el-card class="box-card">
  4. <div slot="header" class="clearfix">
  5. <b>修改密码</b>
  6. </div>
  7. <el-form
  8. :model="addForm"
  9. :rules="rules"
  10. label-width="120px"
  11. ref="addForm"
  12. style="width: 500px"
  13. >
  14. <el-form-item label="原密码" prop="OldPwd">
  15. <el-input
  16. type="text"
  17. v-model="addForm.OldPwd"
  18. placeholder="请输入不超过20个字符"
  19. clearable
  20. autocomplete="new-password"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item label="新密码" prop="NewPwd" v-if="visible">
  24. <el-input
  25. type="password"
  26. v-model="addForm.NewPwd"
  27. placeholder="请输入长度不超过20个字符"
  28. maxlength="20"
  29. autocomplete="new-password"
  30. >
  31. <i
  32. slot="suffix"
  33. class="el-icon-view el-input__icon"
  34. title="显示密码"
  35. @click="changePass('show')"
  36. style="cursor: pointer"
  37. ></i>
  38. </el-input>
  39. </el-form-item>
  40. <el-form-item label="新密码" prop="NewPwd" v-else>
  41. <el-input
  42. type="text"
  43. v-model="addForm.NewPwd"
  44. placeholder="请输入长度不超过20个字符"
  45. maxlength="20"
  46. autocomplete="new-password"
  47. >
  48. <i
  49. slot="suffix"
  50. class="el-icon-more el-input__icon"
  51. title="隐藏密码"
  52. @click="changePass('hide')"
  53. style="cursor: pointer"
  54. ></i>
  55. </el-input>
  56. </el-form-item>
  57. <el-form-item label="确认新密码" prop="twoNewPwd" v-if="twovisible">
  58. <el-input
  59. type="password"
  60. v-model="addForm.twoNewPwd"
  61. placeholder="请输入长度不超过20个字符"
  62. maxlength="20"
  63. >
  64. <i
  65. slot="suffix"
  66. class="el-icon-view el-input__icon"
  67. title="显示密码"
  68. @click="changetwoPass('show')"
  69. style="cursor: pointer"
  70. ></i>
  71. </el-input>
  72. </el-form-item>
  73. <el-form-item label="确认新密码" prop="twoNewPwd" v-else>
  74. <el-input
  75. type="text"
  76. v-model="addForm.twoNewPwd"
  77. placeholder="请输入长度不超过20个字符"
  78. maxlength="20"
  79. >
  80. <i
  81. slot="suffix"
  82. class="el-icon-more el-input__icon"
  83. title="隐藏密码"
  84. @click="changetwoPass('hide')"
  85. style="cursor: pointer"
  86. ></i>
  87. </el-input>
  88. </el-form-item>
  89. <el-form-item style="text-align: center;">
  90. <el-button type="primary" size="medium" @click.native="addSubmit"
  91. >确定</el-button
  92. >
  93. <el-button
  94. type="primary"
  95. size="medium"
  96. plain
  97. @click.native="historyBack"
  98. >返回</el-button
  99. >
  100. </el-form-item>
  101. </el-form>
  102. </el-card>
  103. </div>
  104. </template>
  105. <script>
  106. import { modifyPwd } from "@/api/api.js";
  107. import http from "@/api/http.js";
  108. import md5 from "@/utils/md5.js";
  109. import{checkPassWord} from '@/utils/commonOptions';
  110. export default {
  111. data() {
  112. return {
  113. visible: true,
  114. twovisible: true,
  115. addForm: {
  116. OldPwd: "",
  117. NewPwd: "",
  118. twoNewPwd: "",
  119. },
  120. rules: {
  121. OldPwd: [
  122. {
  123. required: true,
  124. message: "请输入原密码",
  125. trigger: "blur",
  126. },
  127. ],
  128. NewPwd: [
  129. {
  130. validator:(rule,value,callback)=>{
  131. if(!checkPassWord(value)){
  132. callback(new Error('密码要求8位及以上,包含数字、大写字母、小写字母、特殊字符中的三个类型'))
  133. }else{
  134. callback()
  135. }
  136. }
  137. },
  138. {
  139. required: true,
  140. message: "请输入确认密码",
  141. trigger: "blur",
  142. },
  143. ],
  144. twoNewPwd: [
  145. {
  146. required: true,
  147. message: "请输入确认密码",
  148. trigger: "blur",
  149. },
  150. ],
  151. },
  152. };
  153. },
  154. mounted() {},
  155. methods: {
  156. changePass(value) {
  157. this.visible = !(value === "show");
  158. },
  159. changetwoPass(value) {
  160. this.twovisible = !(value === "show");
  161. },
  162. addSubmit() {
  163. this.$refs.addForm.validate((valid) => {
  164. if (valid) {
  165. let that = this;
  166. if (that.addForm.NewPwd != that.addForm.twoNewPwd) {
  167. that.$message.warning("新密码两次输入不一致,请核对!");
  168. return false;
  169. }
  170. modifyPwd({
  171. OldPwd: md5.hex_md5(that.addForm.OldPwd),
  172. NewPwd: md5.hex_md5(that.addForm.NewPwd),
  173. }).then((res) => {
  174. if (res.Ret == 200) {
  175. that.$message.success("修改密码成功,请重新登录!");
  176. setTimeout(function () {
  177. localStorage.setItem("auth", "");
  178. localStorage.setItem("userName", "");
  179. localStorage.setItem("Role", "");
  180. localStorage.setItem("RoleType", "");
  181. localStorage.setItem("AdminId", "");
  182. localStorage.setItem("AdminName", "");
  183. localStorage.setItem("RoleIdentity", "");
  184. localStorage.setItem("ManageType", "");
  185. localStorage.setItem("loginTime", "");
  186. that.$router.push({ path: "/login" });
  187. }, 1000);
  188. }
  189. });
  190. }
  191. });
  192. },
  193. historyBack() {
  194. //返回上一页
  195. history.back();
  196. },
  197. },
  198. };
  199. </script>
  200. <style scoped lang="scss">
  201. .box-card{
  202. .el-form-item{
  203. margin-bottom: 40px;
  204. }
  205. }
  206. </style>