forgotPassword.vue 7.2 KB

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