forgotPassword.vue 7.4 KB

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