resetPassword.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div class="login">
  3. <div class="position-box">
  4. <div class="inner-box">
  5. <img src="../../static/image/logo.png" class="inner-logo" />
  6. <div class="inner-line"></div>
  7. <span>重置密码</span>
  8. </div>
  9. </div>
  10. <div class="login-box">
  11. <div class="login-content">
  12. <div class="top-icon">
  13. 重置密码
  14. </div>
  15. <div v-loading="isLoading">
  16. <!-- 密码登录 -->
  17. <div class="login-password">
  18. <div class="pass-item">
  19. <img src="../../static/image/phone-icon.png" class="phone-icon" />
  20. <el-input placeholder="请输入手机号" v-model="mobile" class="input-phone" :maxlength="11" />
  21. </div>
  22. <div class="pass-item">
  23. <img src="../../static/image/code-icon.png" class="phone-icon" />
  24. <el-input placeholder="验证码" v-model="code" class="input-phone" :maxlength="4" />
  25. <div class="get-code" v-if="!showCode" @click.stop="getCode">获取短信验证码</div>
  26. <div class="get-code" v-else>{{ count }}秒</div>
  27. </div>
  28. <div class="pass-item">
  29. <img src="../../static/image/lock-icon.png" class="lock-icon" />
  30. <el-input placeholder="新密码" v-model="password" class="input-phone" type="password" />
  31. </div>
  32. <div class="pass-item">
  33. <img src="../../static/image/lock-icon.png" class="lock-icon" />
  34. <el-input placeholder="确认新密码" v-model="passwordAgian" class="input-phone" type="password" />
  35. </div>
  36. </div>
  37. </div>
  38. <div class="login-btn" @click.stop="commit">确认</div>
  39. </div>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import {
  45. getPhoneCode,
  46. forgotPassword
  47. } from '../api/user.js';
  48. export default {
  49. data() {
  50. return {
  51. isLoading: false, // 请求解决展示loading
  52. activeIndex: 1,
  53. mobile: '',
  54. code: '',
  55. password: '',
  56. passwordAgian: '',
  57. showCode: false,
  58. count: 60,
  59. timer: null
  60. }
  61. },
  62. destroyed() {
  63. clearInterval( this.timer );
  64. this.timer = null;
  65. },
  66. methods: {
  67. commit() {
  68. if (!this.mobile.trim()) {
  69. return this.$message({
  70. message: '手机号码不能为空',
  71. type: 'error'
  72. })
  73. }
  74. if (!this.checkPhone(this.mobile)) {
  75. return this.$message({
  76. message: '请输入正确的手机号',
  77. type: 'error'
  78. })
  79. }
  80. if (!this.code.trim()) {
  81. return this.$message({
  82. message: '验证码不能为空',
  83. type: 'error'
  84. })
  85. }
  86. if (!this.password.trim()) {
  87. return this.$message({
  88. message: '密码不能为空',
  89. type: 'error'
  90. })
  91. }
  92. if (!this.passwordAgian.trim()) {
  93. return this.$message({
  94. message: '确认密码不能为空',
  95. type: 'error'
  96. })
  97. }
  98. if (this.password.trim() !== this.passwordAgian.trim()) {
  99. return this.$message({
  100. message: '两次密码不一致',
  101. type: 'error'
  102. })
  103. }
  104. let params = {
  105. code: this.code,
  106. mobile: this.mobile,
  107. newPassword: this.password
  108. }
  109. forgotPassword( params ).then( res => {
  110. if ( res.code == 200 ) {
  111. this.$router.go(-1);
  112. }else {
  113. return this.$message({
  114. message: res.msg,
  115. type: 'error'
  116. })
  117. }
  118. } )
  119. },
  120. checkPhone(phone) {
  121. if (!(/^1\d{10}$/.test(phone))) {
  122. return false;
  123. } else {
  124. return true
  125. }
  126. },
  127. // 获取验证码
  128. getCode() {
  129. if (!this.mobile.trim()) {
  130. return this.$message({
  131. message: '手机号码不能为空',
  132. type: 'error'
  133. })
  134. }
  135. if (!this.checkPhone(this.mobile)) {
  136. return this.$message({
  137. message: '请输入正确的手机号',
  138. type: 'error'
  139. })
  140. }
  141. let params = {
  142. mobile: this.mobile,
  143. type: 1
  144. };
  145. this.isLoading = true;
  146. getPhoneCode(params).then(res => {
  147. if (res.code == 200) {
  148. this.isLoading = false;
  149. this.showCode = true;
  150. this.$message({
  151. message: '验证码发送成功',
  152. type: 'success'
  153. })
  154. this.timer = setInterval(() => {
  155. this.count--;
  156. if (this.count <= 1) {
  157. this.showCode = false;
  158. clearInterval(this.timer);
  159. }
  160. }, 1000)
  161. } else {
  162. this.isLoading = false;
  163. return this.$message({
  164. message: res.msg,
  165. type: 'error'
  166. })
  167. }
  168. })
  169. },
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. /deep/ .el-input__inner {
  175. border: none !important;
  176. }
  177. .login {
  178. position: relative;
  179. width: 100%;
  180. height: 100%;
  181. .position-box {
  182. position: absolute;
  183. top: 18px;
  184. left: 33px;
  185. .inner-box {
  186. display: flex;
  187. align-items: center;
  188. .inner-logo {
  189. width: 204px;
  190. height: 44px;
  191. }
  192. .inner-line {
  193. width: 1px;
  194. height: 24px;
  195. background-color: #eee;
  196. margin: 0 40px;
  197. }
  198. span {
  199. font-size: 18px;
  200. font-family: PingFang SC;
  201. font-weight: 400;
  202. color: #333333;
  203. }
  204. }
  205. }
  206. .login-box {
  207. position: relative;
  208. z-index: 200;
  209. height: 100vh;
  210. display: flex;
  211. display: -webkit-flex;
  212. align-items:center;
  213. justify-content:center;
  214. .login-content {
  215. background-color: #fff;
  216. border-radius: 14px;
  217. width: 360px;
  218. box-sizing: border-box;
  219. align-self: center;
  220. padding: 30px;
  221. .top-icon {
  222. font-size: 24px;
  223. font-family: PingFang SC;
  224. font-weight: bold;
  225. color: #333333;
  226. text-align: center;
  227. }
  228. .pass-code {
  229. display: flex;
  230. padding-top: 44px;
  231. .item {
  232. font-size: 16px;
  233. font-family: PingFang SC;
  234. font-weight: 400;
  235. color: #565656;
  236. cursor: pointer;
  237. &:nth-child(1) {
  238. margin-right: 30px;
  239. }
  240. &.active {
  241. font-weight: bold;
  242. color: #111111;
  243. padding-bottom: 10px;
  244. border-bottom: 3px solid #FC7200;
  245. }
  246. }
  247. }
  248. .login-password {
  249. padding-top: 30px;
  250. .pass-item {
  251. display: flex;
  252. align-items: center;
  253. padding-bottom: 2px;
  254. border-bottom: 1px solid #eee;
  255. .phone-icon {
  256. width: 14px;
  257. height: 17px;
  258. margin-right: 16px;
  259. }
  260. .lock-icon {
  261. width: 16px;
  262. height: 18px;
  263. margin-right: 14px;
  264. }
  265. .input-phone {
  266. flex: 1;
  267. }
  268. .get-code {
  269. min-width: 120px;
  270. box-sizing: border-box;
  271. text-align: center;
  272. padding: 0 6px;
  273. font-size: 14px;
  274. font-family: PingFang SC;
  275. font-weight: 400;
  276. color: #175199;
  277. cursor: pointer;
  278. }
  279. }
  280. }
  281. .forgot-pass {
  282. text-align: right;
  283. font-size: 14px;
  284. font-family: PingFang SC;
  285. font-weight: 400;
  286. color: #8590A6;
  287. padding-top: 10px;
  288. span {
  289. cursor: pointer;
  290. }
  291. }
  292. .login-btn {
  293. height: 36px;
  294. line-height: 36px;
  295. text-align: center;
  296. background: #FC7200;
  297. border-radius: 3px;
  298. font-size: 14px;
  299. font-family: PingFang SC;
  300. font-weight: 500;
  301. color: #FFFFFF;
  302. margin-top: 40px;
  303. cursor: pointer;
  304. }
  305. .xie-yi {
  306. font-size: 12px;
  307. font-family: PingFang SC;
  308. font-weight: 400;
  309. color: #808080;
  310. text-align: center;
  311. margin-top: 20px;
  312. a {
  313. text-decoration: none;
  314. color: #175199;
  315. }
  316. }
  317. }
  318. }
  319. }
  320. </style>