forget.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="page-box login-box">
  3. <view class="login-form sys-radius-50 sys-background-fff">
  4. <view class="from-box animate__animated animate__fadeIn">
  5. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':shakeNum===3}" >
  6. <en-input type="number" class="login-input" placeholder="请输入手机号" v-model="accountData.phone" ></en-input>
  7. </view>
  8. <view class="input-item input-send sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':shakeNum===4}">
  9. <en-input type="number" class="login-input" placeholder="请输入验证码" v-model="accountData.code" maxlength="6"></en-input>
  10. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" @click="getVerifiedCode" v-if="timeNum<=0">发送验证码</view>
  11. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" v-else>{{ timeNum }} s</view>
  12. </view>
  13. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':(shakeNum===5 || shakeNum===7)}" >
  14. <en-input type="password" class="login-input" placeholder="请输入密码" v-model="accountData.password" ></en-input>
  15. </view>
  16. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':(shakeNum===6 || shakeNum===7)}">
  17. <en-input type="password" class="login-input" placeholder="请再次输入密码" v-model="accountData.passwordTwo" ></en-input>
  18. </view>
  19. </view>
  20. <agreement v-model="isConsent" ref="agreement"></agreement>
  21. <view
  22. class="input-but sys-background-dominant text-color-fff sys-size-30 sys-radius-100 sys-weight-600"
  23. :class="{'sys-selected-but':isRegister,'sys-unselected-but':!isRegister}"
  24. @click="retrievePassword"
  25. >确认</view>
  26. </view>
  27. <view class="register-box">
  28. <view class="register-text sys-weight-400 sys-size-24 text-color-666">已有账号?</view>
  29. <view class="register-text text-color-dominant sys-size-24 sys-weight-400" @click="goToUrl(1)">去登录</view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import EnInput from "../../components/en-from/en-input/index.vue";
  35. import tools from "../../service/tools";
  36. import {commonSend} from "../../api/common";
  37. import Agreement from "@/pages/login/model/agreement.vue";
  38. import {register, retrievePassword, wxLogin} from "@/api/login";
  39. export default {
  40. components: {Agreement, EnInput},
  41. data() {
  42. return {
  43. accountData: {
  44. 'phone': '',
  45. 'password': '',
  46. 'passwordTwo': '',
  47. 'code': '',
  48. },
  49. timeNum: 0,
  50. timer: null,
  51. isAJAX: false,
  52. isConsent: false,
  53. isRegister: false,
  54. shakeNum: 0,
  55. };
  56. },
  57. watch: {
  58. 'accountData': {
  59. handler() {
  60. this.verifyData(false)
  61. },
  62. deep: true
  63. },
  64. },
  65. methods: {
  66. goToUrl(type) {
  67. uni.reLaunch({
  68. 'url': '/pages/login/index'
  69. })
  70. },
  71. verifyData(type) {
  72. let isRegister = true;
  73. if (!this.accountData.phone) {
  74. isRegister = false
  75. if (type) {
  76. this.shakeNum = 3
  77. tools.error('请输入手机号码');
  78. }
  79. } else if (!this.accountData.password) {
  80. isRegister = false
  81. if (type) {
  82. this.shakeNum = 5
  83. tools.error('请输入密码');
  84. }
  85. } else if (!this.accountData.passwordTwo) {
  86. isRegister = false
  87. if (type) {
  88. this.shakeNum = 6
  89. tools.error('请确认密码');
  90. }
  91. } else if (this.accountData.password !== this.accountData.passwordTwo) {
  92. isRegister = false
  93. if (type) {
  94. this.shakeNum = 7
  95. tools.error('密码输入不一致');
  96. }
  97. } else if (!this.accountData.code) {
  98. isRegister = false
  99. if (type) {
  100. this.shakeNum = 4
  101. tools.error('请输入验证码');
  102. }
  103. } else if (!this.isConsent) {
  104. isRegister = false
  105. if (type) {
  106. this.shakeNum = 8
  107. tools.error('请阅读并同意协议');
  108. this.$refs.agreement.setConsentShake()
  109. }
  110. }
  111. if (!isRegister) {
  112. setTimeout(() => {
  113. if (this.shakeNum > 0) this.shakeNum = 0
  114. }, 500)
  115. }
  116. this.isRegister = isRegister
  117. },
  118. retrievePassword() {
  119. this.verifyData(true)
  120. if (!this.isRegister) {
  121. return;
  122. }
  123. if (this.isAJAX) {
  124. return
  125. }
  126. this.isAJAX = true
  127. retrievePassword(this.accountData).then((res) => {
  128. if (res.code === 1) {
  129. tools.setLoginData(res.data, false)
  130. tools.success('修改成功')
  131. setTimeout(() => {
  132. this.isAJAX = false;
  133. uni.reLaunch({
  134. url: '/pages/login/index'
  135. });
  136. }, 1500)
  137. } else {
  138. this.isAJAX = false;
  139. tools.error(res.msg)
  140. }
  141. })
  142. },
  143. getVerifiedCode() {
  144. if (this.timeNum > 0) {
  145. return;
  146. }
  147. if (this.accountData.phone === '') {
  148. tools.error("请输入手机号码")
  149. return;
  150. }
  151. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  152. if (!regPhone.test(this.accountData.phone)) {
  153. tools.error("手机号码格式错误")
  154. return;
  155. }
  156. commonSend({
  157. 'phone': this.accountData.phone,
  158. 'send_type': 'register'
  159. }).then((res) => {
  160. if (res.code === 1) {
  161. tools.success(res.msg);
  162. this.timeNum = 60;
  163. this.timer = setInterval(() => {
  164. this.timeNum--;
  165. if (this.timeNum <= 0) {
  166. clearInterval(this.timer);
  167. }
  168. }, 1000);
  169. } else {
  170. tools.error(res.msg);
  171. }
  172. })
  173. },
  174. }
  175. }
  176. </script>
  177. <style lang="scss">
  178. @import "/static/css/login.css";
  179. .page-box {
  180. padding-top: 370rpx;
  181. .login-form {
  182. margin: 0 30rpx;
  183. border-radius: 50rpx;
  184. padding: 40rpx 45rpx;
  185. animation-delay: 0.8s;
  186. .input-item {
  187. height: 96rpx;
  188. padding: 28rpx 40rpx;
  189. box-sizing: border-box;
  190. margin-top: 30rpx;
  191. .login-input {
  192. width: 100%;
  193. }
  194. }
  195. .input-item:first-child {
  196. margin-top: 0;
  197. }
  198. .input-send {
  199. display: flex;
  200. justify-content: flex-start;
  201. align-items: center;
  202. .login-input {
  203. width: calc(100% - 140rpx);
  204. }
  205. .login-send {
  206. width: 140rpx;
  207. text-align: center;
  208. }
  209. }
  210. .input-but {
  211. margin-top: 40rpx;
  212. width: 100%;
  213. height: 96rpx;
  214. line-height: 96rpx;
  215. text-align: center;
  216. }
  217. }
  218. .register-box {
  219. display: flex;
  220. justify-content: center;
  221. align-items: center;
  222. margin-top: 60rpx;
  223. .register-text {
  224. height: 34rpx;
  225. line-height: 34rpx;
  226. }
  227. .register-text:last-child {
  228. margin-right: 5rpx;
  229. }
  230. }
  231. }
  232. </style>