pwdDlg.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="container-reset">
  3. <el-dialog
  4. title="修改密码"
  5. :visible.sync="dialogVisiblePwd"
  6. :append-to-body="true"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. :show-close="false"
  10. custom-class="reset-pwd-dlg"
  11. v-dialogDrag
  12. >
  13. <div>
  14. <p class="p-text" v-if="isInitText">当前使用的是初始密码,请您修改密码</p>
  15. <div v-else>
  16. <el-form :model="addForm" :rules="rules" label-width="120px" ref="addForm">
  17. <el-form-item label="新密码" prop="NewPwd" v-if="visible">
  18. <el-input type="password" v-model="addForm.NewPwd" placeholder="请输入长度不超过20个字符" maxlength="20" autocomplete="new-password">
  19. <i slot="suffix" class="el-icon-view el-input__icon" title="显示密码" @click="changePass('show')" style="cursor: pointer"></i>
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item label="新密码" prop="NewPwd" v-else>
  23. <el-input type="text" v-model="addForm.NewPwd" placeholder="请输入长度不超过20个字符" maxlength="20" autocomplete="new-password">
  24. <i slot="suffix" class="el-icon-more el-input__icon" title="隐藏密码" @click="changePass('hide')" style="cursor: pointer"></i>
  25. </el-input>
  26. </el-form-item>
  27. <el-form-item label="确认新密码" prop="twoNewPwd" v-if="twovisible">
  28. <el-input type="password" v-model="addForm.twoNewPwd" placeholder="请输入长度不超过20个字符" maxlength="20">
  29. <i slot="suffix" class="el-icon-view el-input__icon" title="显示密码" @click="changetwoPass('show')" style="cursor: pointer"></i>
  30. </el-input>
  31. </el-form-item>
  32. <el-form-item label="确认新密码" prop="twoNewPwd" v-else>
  33. <el-input type="text" v-model="addForm.twoNewPwd" placeholder="请输入长度不超过20个字符" maxlength="20">
  34. <i slot="suffix" class="el-icon-more el-input__icon" title="隐藏密码" @click="changetwoPass('hide')" style="cursor: pointer"></i>
  35. </el-input>
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. </div>
  40. <div slot="footer" class="dialog-footer">
  41. <el-button type="primary" plain @click="$router.back()">退出</el-button>
  42. <el-button v-if="isInitText" type="primary" @click="isInitText = false">立即修改</el-button>
  43. <el-button v-else type="primary" @click="addSubmit">确定</el-button>
  44. </div>
  45. </el-dialog>
  46. </div>
  47. </template>
  48. <script>
  49. import { modifyPwd } from "@/api/api.js";
  50. import md5 from "@/utils/md5.js";
  51. export default {
  52. name: "",
  53. components: {},
  54. props: {
  55. dialogVisiblePwd: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. },
  60. data() {
  61. return {
  62. isInitText: true,
  63. visible: true,
  64. twovisible: true,
  65. addForm: {
  66. NewPwd: "",
  67. twoNewPwd: "",
  68. },
  69. rules: {
  70. NewPwd: [
  71. {
  72. required: true,
  73. message: "请输入确认密码",
  74. trigger: "blur",
  75. },
  76. ],
  77. twoNewPwd: [
  78. {
  79. required: true,
  80. message: "请输入确认密码",
  81. trigger: "blur",
  82. },
  83. ],
  84. },
  85. };
  86. },
  87. computed: {},
  88. watch: {},
  89. created() {},
  90. mounted() {},
  91. methods: {
  92. resetPwd() {},
  93. changePass(value) {
  94. this.visible = !(value === "show");
  95. },
  96. changetwoPass(value) {
  97. this.twovisible = !(value === "show");
  98. },
  99. addSubmit() {
  100. this.$refs.addForm.validate((valid) => {
  101. if (valid) {
  102. if (this.addForm.NewPwd != this.addForm.twoNewPwd) {
  103. this.$message.warning("新密码两次输入不一致,请核对!");
  104. return false;
  105. }
  106. const initPwd = "123456a";
  107. modifyPwd({ OldPwd: md5.hex_md5(initPwd), NewPwd: md5.hex_md5(this.addForm.NewPwd) }).then((res) => {
  108. if (res.Ret == 200) {
  109. this.$message.success("修改密码成功,请重新登录!");
  110. setTimeout(() => {
  111. localStorage.setItem("auth", "");
  112. localStorage.setItem("userName", "");
  113. localStorage.setItem("Role", "");
  114. localStorage.setItem("RoleType", "");
  115. localStorage.setItem("AdminId", "");
  116. localStorage.setItem('AdminName',"");
  117. localStorage.setItem("RoleIdentity", "");
  118. localStorage.setItem("ManageType", "");
  119. localStorage.setItem("loginTime", "");
  120. this.$router.push({ path: "/login" });
  121. }, 1000);
  122. }
  123. });
  124. }
  125. });
  126. },
  127. },
  128. };
  129. </script>
  130. <style lang="scss">
  131. .reset-pwd-dlg {
  132. width: 500px;
  133. display: flex;
  134. flex-direction: column;
  135. margin: 0 !important;
  136. position: absolute;
  137. top: 50%;
  138. left: 50%;
  139. transform: translate(-50%, -50%);
  140. max-height: calc(100% - 30px);
  141. max-width: calc(100% - 30px);
  142. .el-dialog__body {
  143. flex: 1;
  144. overflow: auto;
  145. }
  146. .el-input {
  147. width: 80%;
  148. }
  149. .dialog-footer {
  150. margin-top: 20px;
  151. text-align: center;
  152. }
  153. }
  154. .p-text {
  155. margin: 20px 0;
  156. text-indent: 2em;
  157. }
  158. </style>