forget-pass.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="forget-wrap">
  3. <view class="login-body">
  4. <form class="login-form" @submit="formSubmit">
  5. <view class="login-title">{{state == 1 ? '修改密码':'找回密码'}}</view>
  6. <view v-show="state == 0">
  7. <view class="form-item">
  8. <u-input v-model="form.phone" :custom-style="{fontSize:'34upx'}" height="110" type="number" clearable maxlength="11" placeholder="请输入登录手机号" />
  9. </view>
  10. <view class="form-item flex-box justify_between">
  11. <view><u-input v-model="form.verifyCode" :custom-style="{fontSize:'34upx'}" height="110" type="number" clearable maxlength="6" placeholder="请输入短信验证码" /></view>
  12. <button class="getcode-btn" :style="{background:$config('primaryColor')}" :disabled="isDisable" @click="getCodeValidate">{{nowVal}}</button>
  13. </view>
  14. <view class="form-btn-con">
  15. <button class="form-btn" :disabled="isDisabled" :style="{'background':isDisabled?'#e5e5e5':$config('primaryColor')}" @click="goStep">下一步</button>
  16. </view>
  17. </view>
  18. <view v-show="state == 1">
  19. <view class="form-item">
  20. <u-input v-model="form.password" :custom-style="{fontSize:'34upx'}" height="110" type="password" :password-icon="true" maxlength="12" placeholder="请输入新密码"/>
  21. </view>
  22. <view class="form-item">
  23. <u-input v-model="form.passwords" :custom-style="{fontSize:'34upx'}" height="110" type="password" :password-icon="true" maxlength="12" placeholder="请再次输入新密码"/>
  24. </view>
  25. <view class="form-btn-con">
  26. <button class="form-btn" :disabled="isDisabledTwo" :style="{'background':isDisabledTwo?'#e5e5e5':$config('primaryColor')}" form-type="submit">提交</button>
  27. </view>
  28. </view>
  29. </form>
  30. <!-- 图文验证码 -->
  31. <uni-popup ref="imageTxtPopup" type="center">
  32. <popup-con type="forgetImageTxt" title="图文验证码" :popBtn="popBtn" :changeImg="changeImg" @captchaImg="captchaImg"></popup-con>
  33. </uni-popup>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import { isvalidPhone } from '@/libs/validate.js'
  39. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  40. import popupCon from '@/components/uni-popup/popup-con.vue'
  41. import { memberVerifyCode, memberChangePwd, memberValidateVerifyCode, memberGetByMobile } from '@/api/user.js'
  42. import { clzConfirm } from '@/libs/tools.js'
  43. export default{
  44. components: {
  45. uniPopup,
  46. popupCon
  47. },
  48. data(){
  49. return{
  50. state: 0, // 忘记密码当前状态
  51. form: {
  52. phone: '',
  53. verifyCode: '',
  54. password: '',
  55. passwords: ''
  56. },
  57. nowVal: '获取验证码', // 按钮显示内容
  58. count: '', // 当前秒数
  59. timer: null, // 倒计时
  60. isDisable: false, // 是否禁止获取验证码
  61. popBtn: [], // name为操作按钮名称,color为操作按钮颜色值
  62. changeImg: false, // 是否重新更换图形验证码
  63. randomCode: '', // 图片验证码随机码
  64. }
  65. },
  66. computed: {
  67. isDisabled() {
  68. return this.form.phone == '' || this.form.verifyCode == ''
  69. },
  70. isDisabledTwo(){
  71. return this.form.password == '' || this.form.passwords == ''
  72. }
  73. },
  74. onLoad(opts) {
  75. if(opts.username){
  76. this.form.phone = opts.username
  77. }
  78. },
  79. methods: {
  80. // 下一步
  81. goStep(){
  82. const _this = this
  83. // 表单校验
  84. if(this.form.phone == ''){
  85. uni.showToast({icon: 'none',title: '请输入登录手机号'})
  86. return
  87. }
  88. if(!isvalidPhone(this.form.phone)){
  89. uni.showToast({icon: 'none',title: '请输入正确的手机号码'})
  90. return
  91. }
  92. if(this.form.verifyCode == ''){
  93. uni.showToast({icon: 'none',title: '请输入验证码'})
  94. return
  95. }
  96. // 校验短信验证码是否正确
  97. const obj = {}
  98. obj.phone = _this.form.phone,
  99. obj.random = _this.randomCode, // 当前随机码
  100. obj.verifyCode = _this.form.verifyCode
  101. memberValidateVerifyCode(obj).then(res => {
  102. if(res.status == 200){
  103. _this.state = 1
  104. }else{
  105. uni.showToast({icon: 'none',title: res.message})
  106. }
  107. })
  108. },
  109. // 表单提交
  110. formSubmit(){
  111. const _this = this
  112. if(this.form.password == ''){
  113. uni.showToast({icon: 'none',title: '请输入新密码'})
  114. return
  115. }
  116. if(this.form.password.length < 6 || this.form.password.length > 12){
  117. uni.showToast({icon: 'none',title: '请输入6-12位新密码'})
  118. return
  119. }
  120. if(this.form.passwords == ''){
  121. uni.showToast({icon: 'none',title: '请再次输入新密码'})
  122. return
  123. }
  124. if(this.form.password != this.form.passwords){
  125. uni.showToast({icon: 'none',title: '两次密码输入不一致'})
  126. return
  127. }
  128. const obj = {}
  129. obj.phone = _this.form.phone,
  130. obj.random = _this.randomCode, // 当前随机码
  131. obj.verifyCode = _this.form.verifyCode,
  132. obj.password = _this.form.password
  133. memberChangePwd(obj).then(res => {
  134. if(res.status == 200){
  135. // 将修改后的账号密码 重新存储
  136. _this.$u.vuex('vuex_user.account', _this.form.phone)
  137. _this.$u.vuex('vuex_user.password', '')
  138. clzConfirm({
  139. title: '提示',
  140. content: '修改成功',
  141. confirmText: '去登录',
  142. showCancel: false,
  143. success: function (ret) {
  144. if (ret.confirm||ret.index==0) {
  145. uni.reLaunch({
  146. url: '/pages/login/login'
  147. })
  148. }
  149. }
  150. })
  151. }
  152. })
  153. },
  154. // 获取验证码
  155. getCodeValidate(){
  156. if(this.form.phone){
  157. if(!isvalidPhone(this.form.phone)){
  158. uni.showToast({icon: 'none',title: '请输入正确的手机号码'})
  159. return
  160. }else{
  161. // 校验手机号是否注册过
  162. memberGetByMobile({phone: this.form.phone}).then(res => {
  163. if(res.status == 200){
  164. // 图文验证码
  165. this.$refs.imageTxtPopup.open()
  166. }else{
  167. uni.showToast({icon: 'none',title: res.message})
  168. }
  169. })
  170. }
  171. }else{
  172. uni.showToast({icon: 'none',title: '请先输入手机号'})
  173. }
  174. },
  175. // 开始倒计时
  176. getCodeFun(){
  177. const TIME_COUNT = 60
  178. if (!this.timer) {
  179. this.count = TIME_COUNT
  180. this.timer = setInterval(() => {
  181. if (this.count > 0 && this.count <= TIME_COUNT) {
  182. this.count--
  183. this.nowVal = this.count + 's后重发'
  184. this.isDisable = true
  185. } else {
  186. this.nowVal = '重新获取验证码'
  187. clearInterval(this.timer)
  188. this.timer = null
  189. this.isDisable = false
  190. }
  191. }, 1000)
  192. }
  193. },
  194. // 图文验证码
  195. captchaImg(code, nowRandomCode){
  196. this.captchaVerify(code, nowRandomCode)
  197. },
  198. // 验证图片验证码
  199. captchaVerify(code, nowRandomCode){
  200. const _this = this
  201. let obj = {}
  202. obj.phone = this.form.phone
  203. obj.random = nowRandomCode
  204. obj.captcha = code
  205. // 短信验证码
  206. memberVerifyCode(obj).then(res => {
  207. console.log(JSON.stringify(res))
  208. if(res.status == 200){ // 验证码输入正确
  209. _this.randomCode = nowRandomCode // 图片验证码随机码
  210. // 关闭 图形验证码 弹框
  211. _this.$refs.imageTxtPopup.close()
  212. // 开启倒计时
  213. this.getCodeFun()
  214. uni.showToast({icon: 'none',title: '验证码发送成功'})
  215. }else { // 验证码输入错误
  216. _this.randomCode = ''
  217. // 切换验证码重新校验
  218. _this.changeImg = false
  219. _this.$nextTick(function(){
  220. _this.changeImg = true
  221. })
  222. uni.showToast({icon: 'none',title: res.message})
  223. }
  224. })
  225. },
  226. }
  227. }
  228. </script>
  229. <style scoped lang="scss">
  230. @import './login.scss';
  231. .forget-wrap .login-body{
  232. justify-content: space-between;
  233. }
  234. .forget-wrap .login-form{
  235. margin-top: 15%;
  236. }
  237. .getcode-btn {
  238. color: #0485F6 !important;
  239. border: none !important;
  240. background: none !important;
  241. &:after{
  242. border: none !important;
  243. }
  244. }
  245. </style>