forgetPass.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="forget-pass">
  3. <navbar ref="navbar" :config="config" backColor="#666"></navbar>
  4. <form @submit="formSubmit">
  5. <view class="phone">
  6. <view class="phone-item">
  7. 手机号码
  8. </view>
  9. <input type="number" name="phone" value="" maxlength="11" @input="onPhone" placeholder="请输入您的手机号码"
  10. placeholder-style="color:#cccccc; font-size:28rpx; font-weight:500;" />
  11. </view>
  12. <view class="verification-code">
  13. <view class="verification-item">
  14. 验证码
  15. </view>
  16. <input type="text" name="code" value="" maxlength="6" @input="onCode" placeholder="请输入您的验证码"
  17. placeholder-style="color:#cccccc; font-size:28rpx; font-weight:500;" />
  18. <button class="verification-right" :disabled="disabled" @click="judgeRegister"
  19. :class="isPhone?'active':''">
  20. {{verificationCode}}
  21. </button>
  22. </view>
  23. <view class="background">
  24. </view>
  25. <view class="new-pass">
  26. <view class="new-pass-item">
  27. 新密码
  28. </view>
  29. <input type="text" password="true" name="newPass" value="" maxlength="11" @input="onNewPass"
  30. placeholder="请输入您的新密码" placeholder-style="color:#cccccc; font-size:28rpx; font-weight:500;" />
  31. </view>
  32. <view class="confirm-pass">
  33. <view class="confirm-pass-item">
  34. 确认密码
  35. </view>
  36. <input type="text" password="true" name="confirmPass" maxlength="11" @input="onConfirmPass" value=""
  37. placeholder="确认密码" placeholder-style="color:#cccccc; font-size:28rpx; font-weight:500;" />
  38. </view>
  39. <view class="button">
  40. <button form-type="submit">确认提交</button>
  41. </view>
  42. </form>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. getVerfityCode,
  48. forgetPass
  49. } from "@/api/login.js"
  50. export default {
  51. data() {
  52. return {
  53. config: {
  54. back: true, //false是tolbar页面 是则不写
  55. title: '忘记密码',
  56. color: '#1A1A1A',
  57. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  58. backgroundColor: [1, "#fff"],
  59. statusBarFontColor: '#1A1A1A',
  60. // backTabPage: "/pages/index/my"
  61. },
  62. phone: "", //手机号
  63. isPhone: false, //手机号正则
  64. code: "", //验证码
  65. newPass: "", //新密码
  66. confirmPass: "", //确认密码
  67. disabled: false,
  68. time: 60,
  69. verificationCode: "发送验证码"
  70. }
  71. },
  72. methods: {
  73. //获取验证码
  74. async obtainCode() {
  75. if (this.isPhone) {
  76. let res = await this.$http.post(getVerfityCode, this.phone)
  77. if (res && res.code == 200) {
  78. this.$mUtil.toast("发送成功")
  79. this.disabled = false;
  80. this.isPhone = false;
  81. this.verificationCode = this.time + "s";
  82. this.clear = setInterval(this.countDown, 1000);
  83. }
  84. }
  85. },
  86. judgeRegister() {
  87. this.$http.get('/account/verify-mobile/' + this.phone).then(res => {
  88. if (res && res.code == 200) {
  89. console.log(res.data)
  90. if (res.data == false) {
  91. this.$mUtil.toast("该手机号还未注册")
  92. } else if (res.data == true) {
  93. this.obtainCode()
  94. }
  95. }
  96. })
  97. },
  98. countDown() {
  99. if (this.time <= 0) {
  100. this.disabled = false;
  101. this.verificationCode = "重新获取";
  102. this.isPhone = true;
  103. this.time = 60;
  104. clearInterval(this.clear)
  105. } else {
  106. --this.time;
  107. this.verificationCode = this.time + 's'
  108. }
  109. },
  110. //清楚计时器
  111. beforeDestroy() {
  112. clearInterval(this.clear)
  113. },
  114. //手机号
  115. onPhone(e) {
  116. this.phone = e.detail.value
  117. if (this.phone.match(this.$mConfig.telRegex)) {
  118. if (this.verificationCode == '发送验证码' || this.verificationCode == '重新获取') {
  119. this.isPhone = true
  120. }
  121. } else {
  122. this.isPhone = false
  123. }
  124. },
  125. //验证码
  126. onCode(e) {
  127. this.code = e.detail.value
  128. },
  129. //新密码
  130. onNewPass(e) {
  131. this.newPass = e.detail.value
  132. },
  133. //确认密码
  134. onConfirmPass(e) {
  135. this.confirmPass = e.detail.value
  136. },
  137. //提交信息
  138. formSubmit(e) {
  139. let target = e.detail.value;
  140. if (!target.phone) {
  141. this.$mUtil.toast("请输入手机号")
  142. return false
  143. }
  144. if (!(target.phone.match(this.$mConfig.telRegex))) {
  145. this.$mUtil.toast("请输入正确的手机号")
  146. return false
  147. }
  148. if (!target.code) {
  149. this.$mUtil.toast("请输入验证码")
  150. return false
  151. }
  152. if (!target.newPass) {
  153. this.$mUtil.toast("请输入新密码")
  154. return false
  155. }
  156. if (!target.confirmPass) {
  157. this.$mUtil.toast("请输入确认密码")
  158. return false
  159. }
  160. if (!(target.newPass.match(target.confirmPass))) {
  161. this.$mUtil.toast("两次密码不一致")
  162. return false
  163. }
  164. let param = {
  165. mobile: target.phone,
  166. new_password: target.newPass,
  167. captcha: target.code
  168. }
  169. this.$http.post(forgetPass, param)
  170. .then(res => {
  171. if (res.code == 200) {
  172. this.$mUtil.toast("修改成功")
  173. setTimeout(() => {
  174. this.$http.post("/account/logout").then(res => {
  175. if (res && res.code == 200) {
  176. uni.clearStorageSync()
  177. uni.navigateBack({
  178. delta: 1
  179. })
  180. }
  181. })
  182. }, 2000)
  183. this.$mUtil.toast("修改成功")
  184. }
  185. })
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .button {
  192. margin: 700rpx 30rpx 0 30rpx;
  193. button {
  194. width: 100%;
  195. text-align: center;
  196. margin-top: 70rpx;
  197. color: #ffffff;
  198. font-size: 32rpx;
  199. font-weight: Regular;
  200. background-color: #FA6138;
  201. border-radius: 43rpx;
  202. }
  203. }
  204. .phone {
  205. margin: 0 30rpx;
  206. display: flex;
  207. padding: 27rpx 0 30rpx 0;
  208. align-items: center;
  209. border-bottom: 1rpx solid #E6E6E6;
  210. .phone-item {
  211. font-size: 28rpx;
  212. font-weight: 400;
  213. color: #1A1A1A;
  214. }
  215. input {
  216. flex: 1;
  217. margin-left: 60rpx;
  218. }
  219. }
  220. .verification-code {
  221. margin: 0 30rpx;
  222. display: flex;
  223. align-items: center;
  224. padding: 12rpx 0;
  225. .verification-item {
  226. font-size: 28rpx;
  227. font-weight: 400;
  228. color: #1A1A1A;
  229. }
  230. input {
  231. flex: 1;
  232. margin-left: 88rpx;
  233. }
  234. .verification-right {
  235. font-size: 28rpx;
  236. color: #999999;
  237. background-color: #FFFFFF;
  238. font-weight: 400;
  239. border: 1rpx solid #b3b3b3;
  240. border-radius: 36rpx;
  241. padding: 0 30rpx;
  242. }
  243. .active {
  244. background-color: #FA6138;
  245. color: #FFFFFF;
  246. border: none;
  247. }
  248. }
  249. .background {
  250. height: 10rpx;
  251. background-color: #F5F5F5;
  252. }
  253. .new-pass {
  254. margin: 0 30rpx;
  255. display: flex;
  256. align-items: center;
  257. padding: 23rpx 0 30rpx 0;
  258. border-bottom: 1rpx solid #E6E6E6;
  259. .new-pass-item {
  260. font-size: 28rpx;
  261. color: #1A1A1A;
  262. font-weight: 400;
  263. }
  264. input {
  265. flex: 1;
  266. margin-left: 88rpx;
  267. }
  268. }
  269. .confirm-pass {
  270. margin: 0 30rpx;
  271. display: flex;
  272. padding: 34rpx 0 30rpx 0;
  273. border-bottom: 1rpx solid #E6E6E6;
  274. .confirm-pass-item {
  275. font-size: 28rpx;
  276. font-weight: 400;
  277. color: #1A1A1A;
  278. }
  279. input {
  280. flex: 1;
  281. margin-left: 60rpx;
  282. }
  283. }
  284. </style>