forgotPassword.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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.showModal({
  168. title: '',
  169. content: '密码长度最少10位 最多16位,必须同时包含一个大写字母、一个小写字母、一个数字和一个特殊字符!@#*?&',
  170. showCancel:false,
  171. confirmColor: '#0183FA',
  172. })
  173. return
  174. }
  175. uni.showModal({
  176. title: '确认提交?',
  177. cancelColor: '#999999',
  178. confirmColor: '#0183FA',
  179. content: '',
  180. success(res) {
  181. if (res.confirm) {
  182. // console.log('确定')
  183. self.authForgetPassword();
  184. } else if (res.cancel) {
  185. // console.log('取消')
  186. }
  187. }
  188. })
  189. },
  190. async authForgetPassword(){
  191. let self = this;
  192. let obj = {
  193. mobile:this.form.mobile,
  194. captcha:this.form.captcha,
  195. newPassword:md5.hex_md5(this.form.newPassword),
  196. confirmPassword:md5.hex_md5(this.form.confirmPassword),
  197. };
  198. const {
  199. data
  200. } = await authForgetPassword(obj);
  201. if (data.code == 200) {
  202. uni.showToast({
  203. title: '操作成功',
  204. icon: "none",
  205. mask: true,
  206. duration: 2000
  207. });
  208. setTimeout(function(){
  209. uni.navigateBack();
  210. },2000);
  211. }
  212. },
  213. },
  214. }
  215. </script>
  216. <style lang="stylus" scoped>
  217. #forgotPassword {
  218. height: 100%;
  219. display: flex;
  220. flex-direction: column;
  221. flex: 1;
  222. background-color: #FFFFFF;
  223. overflow-y: scroll;
  224. overflow-x: hidden;
  225. .page-title {
  226. line-height: 120rpx;
  227. font-weight: 700;
  228. font-size: 34rpx;
  229. margin-left: 30rpx;
  230. }
  231. .input-max-box {
  232. padding: 0 30rpx;
  233. view {
  234. line-height: 80rpx;
  235. font-size: 30rpx;
  236. font-weight: 700;
  237. }
  238. input {
  239. width: 630rpx;
  240. height: 100rpx;
  241. line-height: 100rpx;
  242. border-radius: 10rpx;
  243. border: 1px solid #D8D8D8;
  244. padding: 0 30rpx;
  245. }
  246. }
  247. .input-button-max-box {
  248. padding: 0 30rpx;
  249. view:nth-child(1) {
  250. line-height: 80rpx;
  251. font-size: 30rpx;
  252. font-weight: 700;
  253. }
  254. .input-button-box {
  255. display: flex;
  256. input {
  257. width: 412rpx;
  258. height: 100rpx;
  259. line-height: 100rpx;
  260. border-radius: 10rpx;
  261. border: 1px solid #D8D8D8;
  262. padding: 0 30rpx;
  263. margin-right: 18rpx;
  264. }
  265. view {
  266. width: 200rpx;
  267. line-height: 100rpx;
  268. text-align: center;
  269. font-size: 30rpx;
  270. border-radius: 10rpx;
  271. }
  272. .checkButton {
  273. color: #333;
  274. background-color: #E8E8E8;
  275. }
  276. .noCheckButton {
  277. color: #fff;
  278. background-color: #0183FA;
  279. }
  280. }
  281. }
  282. .bottom-button-box {
  283. display: flex;
  284. margin: 43rpx 0;
  285. view {
  286. font-size: 30rpx;
  287. line-height: 100rpx;
  288. text-align: center;
  289. }
  290. view:nth-child(1) {
  291. width: 220rpx;
  292. margin: 0 33rpx 0 30rpx;
  293. border-radius: 50rpx 50rpx 50rpx 50rpx;
  294. border: 1rpx solid #E0E0E0;
  295. }
  296. view:nth-child(2) {
  297. width: 437rpx;
  298. color: #fff;
  299. background: #0183FA;
  300. border-radius: 50rpx 50rpx 50rpx 50rpx;
  301. }
  302. }
  303. }
  304. </style>