forget.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. uni.login({
  157. provider: "weixin",
  158. success: (loginRes) => {
  159. commonSend({
  160. 'phone': this.accountData.phone,
  161. 'send_type': 'register',
  162. 'wxCode':loginRes.code
  163. }).then((res) => {
  164. if (res.code === 1) {
  165. tools.success(res.msg);
  166. this.timeNum = 60;
  167. this.timer = setInterval(() => {
  168. this.timeNum--;
  169. if (this.timeNum <= 0) {
  170. clearInterval(this.timer);
  171. }
  172. }, 1000);
  173. } else {
  174. tools.error(res.msg);
  175. }
  176. })
  177. }
  178. })
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. @import "/static/css/login.css";
  185. .page-box {
  186. padding-top: 370rpx;
  187. .login-form {
  188. margin: 0 30rpx;
  189. border-radius: 50rpx;
  190. padding: 40rpx 45rpx;
  191. animation-delay: 0.8s;
  192. .input-item {
  193. height: 96rpx;
  194. padding: 28rpx 40rpx;
  195. box-sizing: border-box;
  196. margin-top: 30rpx;
  197. .login-input {
  198. width: 100%;
  199. }
  200. }
  201. .input-item:first-child {
  202. margin-top: 0;
  203. }
  204. .input-send {
  205. display: flex;
  206. justify-content: flex-start;
  207. align-items: center;
  208. .login-input {
  209. width: calc(100% - 140rpx);
  210. }
  211. .login-send {
  212. width: 140rpx;
  213. text-align: center;
  214. }
  215. }
  216. .input-but {
  217. margin-top: 40rpx;
  218. width: 100%;
  219. height: 96rpx;
  220. line-height: 96rpx;
  221. text-align: center;
  222. }
  223. }
  224. .register-box {
  225. display: flex;
  226. justify-content: center;
  227. align-items: center;
  228. margin-top: 60rpx;
  229. .register-text {
  230. height: 34rpx;
  231. line-height: 34rpx;
  232. }
  233. .register-text:last-child {
  234. margin-right: 5rpx;
  235. }
  236. }
  237. }
  238. </style>