forgotPassword.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!-- 忘记密码 -->
  2. <template>
  3. <view id="forgotPassword">
  4. <view class="page-title">忘记密码</view>
  5. <view class="input-max-box">
  6. <view>手机号</view>
  7. <input v-model="form.mobile" maxlength="11" focus placeholder="请输入手机号码" />
  8. </view>
  9. <view class="input-button-max-box">
  10. <view>手机验证码</view>
  11. <view class="input-button-box">
  12. <input maxlength="6" v-model="form.captcha" focus placeholder="请输入手机验证码" />
  13. <view @click="getCode()" :class="codeType?'checkButton':'noCheckButton'">
  14. {{codeType?seconds+'秒后重试':'获取验证码'}}
  15. </view>
  16. </view>
  17. </view>
  18. <view class="input-max-box">
  19. <view>新密码</view>
  20. <input type="password" maxlength="16" v-model="form.newPassword" focus placeholder="请输入新密码" />
  21. </view>
  22. <view class="input-max-box">
  23. <view>确认新密码</view>
  24. <input type="password" maxlength="16" v-model="form.confirmPassword" focus placeholder="请再次输入确认密码" />
  25. </view>
  26. <view class="bottom-button-box">
  27. <view @click="outButton()">稍后修改</view>
  28. <view @click="submitButton()">确定修改</view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import md5 from '@/utils/md5.js'
  34. import {
  35. authNumCaptcha,
  36. authForgetPassword,
  37. } from '@/pages_basics/api/index.js'
  38. export default {
  39. data() {
  40. return {
  41. form: {
  42. mobile:"",
  43. captcha:"",
  44. newPassword:"",
  45. confirmPassword:"",
  46. },
  47. codeType: false,
  48. seconds: 0,
  49. timer: null,
  50. }
  51. },
  52. onLoad(option) {
  53. },
  54. onShow() {
  55. },
  56. methods: {
  57. //返回上级页面
  58. outButton() {
  59. uni.navigateBack();
  60. },
  61. //获取验证码
  62. getCode() {
  63. let self = this;
  64. const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/
  65. if (this.codeType) {
  66. uni.showToast({
  67. title: '请稍后再试',
  68. icon: "none",
  69. duration: 3000
  70. });
  71. return
  72. } else if (!this.form.mobile) {
  73. uni.showToast({
  74. title: '请输入手机号码',
  75. icon: "none",
  76. duration: 3000
  77. });
  78. return
  79. } else if (!reg.test(this.form.mobile)) {
  80. uni.showToast({
  81. title: '请输入正确的手机号码',
  82. icon: "none",
  83. duration: 3000
  84. });
  85. return
  86. }
  87. this.authNumCaptcha();
  88. },
  89. //获取验证码
  90. async authNumCaptcha() {
  91. let self = this;
  92. const {
  93. data
  94. } = await authNumCaptcha({mobile:this.form.mobile});
  95. if (data.code == 200) {
  96. uni.showToast({
  97. title: '发送成功',
  98. icon: "none",
  99. mask: true,
  100. duration: 2000
  101. });
  102. const TIME_COUNT = 60;
  103. this.$set(this, 'codeType', true);
  104. if (!this.timer) {
  105. this.$set(this, 'seconds', TIME_COUNT);
  106. this.timer = setInterval(() => {
  107. if (this.seconds > 1 && this.seconds <= TIME_COUNT) {
  108. this.seconds -= 1;
  109. } else {
  110. this.$set(this, 'codeType', false);
  111. clearInterval(this.timer);
  112. this.$set(this, 'timer', null);
  113. }
  114. }, 1000);
  115. }
  116. }
  117. },
  118. //提交
  119. submitButton() {
  120. let self = this;
  121. const reg = /^1[3|4|5|7|8|9][0-9]\d{8}$/
  122. const password =
  123. /^(?=(?:.*[A-Z]){1})(?=(?:.*[a-z]){1})(?=(?:.*[0-9]){1})(?=(?:.*[!@#*?&]){1})(?!(.)\1)(.{10,16})$/
  124. if (!this.form.mobile) {
  125. uni.showToast({
  126. title: '请输入手机号码',
  127. icon: "none",
  128. duration: 3000
  129. });
  130. return
  131. } else if (!reg.test(this.form.mobile)) {
  132. uni.showToast({
  133. title: '请输入正确的手机号码',
  134. icon: "none",
  135. duration: 3000
  136. });
  137. return
  138. } else if (!this.form.captcha) {
  139. uni.showToast({
  140. title: '请输入手机验证码',
  141. icon: "none",
  142. duration: 3000
  143. });
  144. return
  145. } else if (!this.form.newPassword) {
  146. uni.showToast({
  147. title: '请输入新密码',
  148. icon: "none",
  149. duration: 3000
  150. });
  151. return
  152. } else if (!this.form.confirmPassword) {
  153. uni.showToast({
  154. title: '请再次输入确认密码',
  155. icon: "none",
  156. duration: 3000
  157. });
  158. return
  159. } else if (this.form.newPassword != this.form.confirmPassword) {
  160. uni.showToast({
  161. title: '新密码与确认新密码不一致',
  162. icon: "none",
  163. duration: 3000
  164. });
  165. return
  166. } else if (!password.test(this.form.newPassword) || !password.test(this.form.confirmPassword)) {
  167. uni.showToast({
  168. title: '密码长度最少10位 最多16位,必须同时包含一个大写字母、一个小写字母、一个数字和一个特殊字符!@#*?&',
  169. icon: "none",
  170. duration: 5000
  171. });
  172. return
  173. }
  174. uni.showModal({
  175. title: '确认提交?',
  176. cancelColor: '#999999',
  177. confirmColor: '#0183FA',
  178. content: '',
  179. success(res) {
  180. if (res.confirm) {
  181. // console.log('确定')
  182. self.authForgetPassword();
  183. } else if (res.cancel) {
  184. // console.log('取消')
  185. }
  186. }
  187. })
  188. },
  189. async authForgetPassword(){
  190. let self = this;
  191. let obj = {
  192. mobile:this.form.mobile,
  193. captcha:this.form.captcha,
  194. newPassword:md5.hex_md5(this.form.newPassword),
  195. confirmPassword:md5.hex_md5(this.form.confirmPassword),
  196. };
  197. const {
  198. data
  199. } = await authForgetPassword(obj);
  200. if (data.code == 200) {
  201. uni.showToast({
  202. title: '操作成功',
  203. icon: "none",
  204. mask: true,
  205. duration: 2000
  206. });
  207. setTimeout(function(){
  208. uni.navigateBack();
  209. },2000);
  210. }
  211. },
  212. },
  213. }
  214. </script>
  215. <style lang="stylus" scoped>
  216. #forgotPassword {
  217. height: 100%;
  218. display: flex;
  219. flex-direction: column;
  220. flex: 1;
  221. background-color: #FFFFFF;
  222. overflow-y: scroll;
  223. overflow-x: hidden;
  224. .page-title {
  225. line-height: 120rpx;
  226. font-weight: 700;
  227. font-size: 34rpx;
  228. margin-left: 30rpx;
  229. }
  230. .input-max-box {
  231. padding: 0 30rpx;
  232. view {
  233. line-height: 80rpx;
  234. font-size: 30rpx;
  235. font-weight: 700;
  236. }
  237. input {
  238. width: 630rpx;
  239. height: 100rpx;
  240. line-height: 100rpx;
  241. border-radius: 10rpx;
  242. border: 1px solid #D8D8D8;
  243. padding: 0 30rpx;
  244. }
  245. }
  246. .input-button-max-box {
  247. padding: 0 30rpx;
  248. view:nth-child(1) {
  249. line-height: 80rpx;
  250. font-size: 30rpx;
  251. font-weight: 700;
  252. }
  253. .input-button-box {
  254. display: flex;
  255. input {
  256. width: 412rpx;
  257. height: 100rpx;
  258. line-height: 100rpx;
  259. border-radius: 10rpx;
  260. border: 1px solid #D8D8D8;
  261. padding: 0 30rpx;
  262. margin-right: 18rpx;
  263. }
  264. view {
  265. width: 200rpx;
  266. line-height: 100rpx;
  267. text-align: center;
  268. font-size: 30rpx;
  269. border-radius: 10rpx;
  270. }
  271. .checkButton {
  272. color: #333;
  273. background-color: #E8E8E8;
  274. }
  275. .noCheckButton {
  276. color: #fff;
  277. background-color: #0183FA;
  278. }
  279. }
  280. }
  281. .bottom-button-box {
  282. display: flex;
  283. margin: 43rpx 0;
  284. view {
  285. font-size: 30rpx;
  286. line-height: 100rpx;
  287. text-align: center;
  288. }
  289. view:nth-child(1) {
  290. width: 220rpx;
  291. margin: 0 33rpx 0 30rpx;
  292. border-radius: 50rpx 50rpx 50rpx 50rpx;
  293. border: 1rpx solid #E0E0E0;
  294. }
  295. view:nth-child(2) {
  296. width: 437rpx;
  297. color: #fff;
  298. background: #0183FA;
  299. border-radius: 50rpx 50rpx 50rpx 50rpx;
  300. }
  301. }
  302. }
  303. </style>