modifyPassword.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <!-- 修改密码组件 -->
  2. <script setup>
  3. import {
  4. ElMessage
  5. } from 'element-plus'
  6. </script>
  7. <template>
  8. <div class="main" v-show="isshow" v-drag>
  9. <div class="title header">
  10. 重置密码
  11. </div>
  12. <div style="height: 10rem;"></div>
  13. <el-form label-width="100rem" style="max-width: 460rem">
  14. <el-form-item label="账号:">
  15. <el-input v-model="user.account" disabled />
  16. </el-form-item>
  17. <el-form-item label="旧密码:">
  18. <el-input v-model="user.oldpassword" placeholder="请输入旧密码" />
  19. </el-form-item>
  20. <el-form-item label="新密码:">
  21. <el-input v-model="user.newpassword" placeholder="请输入8位以上大小写字母、数字、特殊字符" @change="newPwdChange" @input="newPwdChange" />
  22. <div class="PasswordStrength">
  23. <span id="weak">弱</span>
  24. <span id="medium">中</span>
  25. <span id="strong">强</span>
  26. </div>
  27. </el-form-item>
  28. <el-form-item label="确认密码:">
  29. <el-input v-model="user.enterpassword" @input="isenterpassword" placeholder="请再次输入新密码" />
  30. <el-icon :size="20" v-show="isicon" color="#ff2700" class="icon_warning">
  31. <WarningFilled />
  32. </el-icon>
  33. <span v-show="isicon">两次密码输入不一致!</span>
  34. </el-form-item>
  35. </el-form>
  36. <div class="footer">
  37. <el-button type="primary" @click="submit">确定</el-button>
  38. <el-button type="default" @click="cancel">关闭</el-button>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. user: {
  47. account: '', //用户账号
  48. oldpassword: '', //旧密码
  49. newpassword: '', //新密码
  50. enterpassword: '', //确定密码
  51. },
  52. isshow: false, //控制弹框是否显示
  53. isicon: false, //判断两次密码输入是否一致
  54. id: '', //用户主键
  55. info: '', //用户信息
  56. }
  57. },
  58. methods: {
  59. //表单提交事件
  60. submit() {
  61. if (!this.user.account || !this.user.newpassword || !this.user.oldpassword || !this.user.enterpassword) {
  62. ElMessage.error('请输入完整信息!')
  63. return
  64. } else if (this.user.newpassword !== this.user.enterpassword) {
  65. ElMessage.error('两次输入密码不一致!')
  66. return
  67. } else if (this.user.oldpassword !== this.info.password) {
  68. ElMessage.error('密码输入错误!')
  69. return
  70. }
  71. let data = {
  72. password: this.$md5(this.user.newpassword)
  73. }
  74. this.$http.post('/postSubmit', {
  75. tableName: 'base_sys_user',
  76. keyValue: this.id,
  77. formData: data
  78. }).then(res => {
  79. if (res.success == true) {
  80. ElMessage.success('密码修改成功!')
  81. this.isshow = false
  82. this.$router.push('/login')
  83. }
  84. })
  85. },
  86. //关闭修改密码弹出框
  87. cancel() {
  88. this.isshow = false
  89. },
  90. //判断两次密码是否一致
  91. isenterpassword() {
  92. if (this.user.newpassword != this.user.enterpassword) {
  93. this.isicon = true
  94. } else {
  95. this.isicon = false
  96. }
  97. },
  98. /**
  99. * 监听新密码变化,修改密码强弱提示
  100. */
  101. newPwdChange() {
  102. var password = this.user.newpassword;
  103. var level = this.ReturnPasswordStrength(password);
  104. if (level == "weak") {
  105. document.getElementById("weak").style.background = "#ffd800";
  106. } else {
  107. document.getElementById("weak").style.background = "#808080";
  108. }
  109. if (level == "medium") {
  110. document.getElementById("medium").style.background = "#ff6a00";
  111. } else {
  112. document.getElementById("medium").style.background = "#808080";
  113. }
  114. if (level == "strong") {
  115. document.getElementById("strong").style.background = "#f00";
  116. } else {
  117. document.getElementById("strong").style.background = "#808080";
  118. }
  119. },
  120. /**
  121. * 返回密码强弱
  122. * @param {Object} password
  123. */
  124. ReturnPasswordStrength(password) {
  125. //强 ==> 密码长度大于等于8位数 包含大写字母[A-Z] + 小写字母[a-z] + 数字[0-9] + 非单词字符的特殊字符[标点符号,空格啥的这些] 结尾
  126. var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
  127. //中 ==> 密码长度大于等于8位数 大写字母[A-Z] + 小写字母[a-z] 或者 大写字母[A-Z] + 数字[0-9] 或者 小写字母[a-z] + 数字[0-9] + 任意字符 结尾
  128. var mediumRegex = new RegExp("^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
  129. //弱 ==> 大于等于8位 任何字符或者数字 (如果达不到这个条件就是弱,所以这里需要用false判断)
  130. var weakRegex = new RegExp("(?=.{8,}).*", "g");
  131. if (weakRegex.test(password)) { //必须先要满足 弱 条件
  132. if (mediumRegex.test(password)) { //必须先要满足 弱 条件 才能 满足 中 条件
  133. if (strongRegex.test(password)) { //必须先要满足 中 条件才能 满足 强 条件
  134. return "strong";
  135. } else {
  136. return "medium";
  137. }
  138. } else {
  139. return "weak";
  140. }
  141. } else {
  142. return "weak";
  143. }
  144. },
  145. },
  146. mounted() {
  147. //在这里获取账户信息密码
  148. this.info = JSON.parse(localStorage.getItem('person'))
  149. this.user.account = this.info.account
  150. // this.user.oldpassword = info.password
  151. this.id = this.info.id
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .main {
  157. position: absolute;
  158. top: 200rem;
  159. left: calc(50% - 250rem);
  160. z-index: 1;
  161. background-color: white;
  162. width: 500rem;
  163. height: 300rem;
  164. box-shadow: 0 0 5rem 1rem #82d5fb;
  165. user-select: none;
  166. }
  167. .icon_warning {
  168. z-index: 100;
  169. }
  170. .title {
  171. height: 40rem;
  172. background-color: rgb(240, 244, 247);
  173. line-height: 40rem;
  174. text-align: center;
  175. color: black;
  176. border-bottom: 1rem solid lightgray;
  177. }
  178. .footer {
  179. height: 50rem;
  180. background-color: rgb(240, 244, 247);
  181. line-height: 50rem;
  182. border-top: 1rem solid lightgray;
  183. text-align: right;
  184. padding-right: 10rem;
  185. }
  186. .PasswordStrength span {
  187. display: inline-block;
  188. width: 80rem;
  189. height: 20rem;
  190. line-height: 20rem;
  191. background: #808080;
  192. font-size: 10rem;
  193. text-align: center;
  194. color: #fff;
  195. //弱
  196. #weak {
  197. border-top-left-radius: 5rem;
  198. border-bottom-left-radius: 5rem;
  199. border-right: 0rem solid;
  200. margin-left: 20rem;
  201. margin-right: 3rem;
  202. }
  203. //中
  204. #medium {
  205. border-left: 0rem solid;
  206. border-right: 0rem solid;
  207. margin-left: -5rem;
  208. margin-right: 3rem;
  209. }
  210. //强
  211. #strong {
  212. border-top-right-radius: 5rem;
  213. border-bottom-right-radius: 5rem;
  214. border-left: 0rem solid;
  215. margin-left: -5rem;
  216. }
  217. }
  218. .el-form-item{
  219. margin-bottom: 18rem !important;
  220. }
  221. </style>