Pwd.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div class="form_container">
  3. <el-form ref="form" :model="form" label-width="110px" :rules="rules">
  4. <el-form-item label="原密码" prop="old">
  5. <el-input v-model="form.old" type="password"></el-input>
  6. </el-form-item>
  7. <el-form-item label="新密码" prop="newpwd">
  8. <el-input v-model="form.newpwd" type="password"></el-input>
  9. </el-form-item>
  10. <el-form-item label="确认密码" prop="again">
  11. <el-input v-model="form.again" type="password"></el-input>
  12. </el-form-item>
  13. <s>
  14. <i class="el-icon-warning"></i><em>密码由6~32位字母、数字及下划线组成</em>
  15. </s>
  16. <el-form-item>
  17. <el-button size="small" type="primary" @click="onSubmit('form')">确认</el-button>
  18. <el-button size="small" @click="resetForm('form')">重置</el-button>
  19. </el-form-item>
  20. </el-form>
  21. </div>
  22. </template>
  23. <script>
  24. let qs = require('qs');
  25. import Global from '../Global.js'
  26. import {modPwd, logout} from '../api/getApiRes.js'
  27. export default {
  28. data() {
  29. let samepass = (rule, value, callback) => {
  30. if (value !== this.form.newpwd) {
  31. callback(new Error('两次输入密码不一致!'));
  32. } else {
  33. callback();
  34. }
  35. };
  36. let pwdPass = (rule, value, callback) => {
  37. let re = /^[0-9a-zA-Z_]{1,}$/;
  38. if (value.search(re) == -1) {
  39. callback(new Error('错了哦,密码只能由字母、数字及下划线组成'));
  40. } else {
  41. callback()
  42. }
  43. };
  44. return {
  45. form: {
  46. old: '',
  47. newpwd: '',
  48. again: '',
  49. },
  50. rules: {
  51. old: [
  52. {required: true, message: '请输入原密码', trigger: 'blur'},
  53. {min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur'}
  54. ],
  55. newpwd: [
  56. {required: true, message: '请输入新密码', trigger: 'blur'},
  57. {min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur'},
  58. {validator: pwdPass, trigger: 'blur'}
  59. ],
  60. again: [
  61. {required: true, message: '请输入确认密码', trigger: 'blur'},
  62. {min: 6, max: 32, message: '长度在 6 到 32 个字符', trigger: 'blur'},
  63. {validator: pwdPass, trigger: 'blur'},
  64. {validator: samepass, trigger: 'blur'},
  65. ],
  66. }
  67. }
  68. },
  69. methods: {
  70. onSubmit(formName) {
  71. let that = this;
  72. this.$refs[formName].validate((valid) => {
  73. if (valid) {
  74. that.submitPwd()
  75. } else {
  76. that.$message({
  77. showClose: true,
  78. message: '错了哦,提交新密码失败',
  79. type: 'error'
  80. });
  81. that.form.old = '';
  82. that.form.newpwd = '';
  83. that.form.again = '';
  84. return false;
  85. }
  86. });
  87. },
  88. resetForm(formName) {
  89. this.$refs[formName].resetFields();
  90. },
  91. submitPwd() {
  92. let that = this;
  93. let param = {
  94. oldPwd: that.form.old,
  95. newPwd: that.form.newpwd,
  96. };
  97. let postdata = qs.stringify(param);
  98. modPwd(postdata).then(res => {
  99. let json = res;
  100. if (json.Code == 0) {
  101. that.$message({
  102. showClose: true,
  103. message: '密码修改成功',
  104. type: 'success'
  105. });
  106. // clean info
  107. that.old = '';
  108. that.newpwd = '';
  109. that.again = '';
  110. that.logoutPage();
  111. } else {
  112. that.$message.error(json.Memo);
  113. }
  114. });
  115. },
  116. // 重登录
  117. logoutPage() {
  118. const that = this;
  119. let postdata = {};
  120. logout(postdata).then(res => {
  121. let json = res;
  122. if (json.Code == 0) {
  123. that.$router.push({
  124. path: '/login',
  125. query: {
  126. status: 1
  127. }
  128. })
  129. } else {
  130. that.$message.error(json.Memo);
  131. }
  132. })
  133. }
  134. },
  135. }
  136. </script>
  137. <style scoped>
  138. #pages {
  139. position: absolute;
  140. top: 0;
  141. bottom: 0;
  142. left: 0;
  143. right: 0;
  144. width: 100%;
  145. height: 100%;
  146. overflow: hidden;
  147. overflow-y: scroll;
  148. display: block;
  149. margin: 0 auto;
  150. padding-bottom: 80px;
  151. }
  152. .form_container {
  153. width: 50%;
  154. overflow: hidden;
  155. margin-top: 20px;
  156. margin-left: 40px;
  157. background: #fff;
  158. padding: 20px;
  159. }
  160. s {
  161. height: 50px;
  162. line-height: 40px;
  163. padding-left: 20px;
  164. text-decoration: none;
  165. font-style: normal;
  166. }
  167. i {
  168. color: red;
  169. }
  170. s em {
  171. font-style: normal;
  172. }
  173. </style>