forget.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. 'isConsent':function (){
  65. this.verifyData(false)
  66. }
  67. },
  68. methods: {
  69. goToUrl(type) {
  70. uni.reLaunch({
  71. 'url': '/pages/login/index'
  72. })
  73. },
  74. verifyData(type) {
  75. let isRegister = true;
  76. if (!this.accountData.phone) {
  77. isRegister = false
  78. if (type) {
  79. this.shakeNum = 3
  80. tools.error('请输入手机号码');
  81. }
  82. } else if (!this.accountData.password) {
  83. isRegister = false
  84. if (type) {
  85. this.shakeNum = 5
  86. tools.error('请输入密码');
  87. }
  88. } else if (!this.accountData.passwordTwo) {
  89. isRegister = false
  90. if (type) {
  91. this.shakeNum = 6
  92. tools.error('请确认密码');
  93. }
  94. } else if (this.accountData.password !== this.accountData.passwordTwo) {
  95. isRegister = false
  96. if (type) {
  97. this.shakeNum = 7
  98. tools.error('密码输入不一致');
  99. }
  100. } else if (!this.accountData.code) {
  101. isRegister = false
  102. if (type) {
  103. this.shakeNum = 4
  104. tools.error('请输入验证码');
  105. }
  106. } else if (!this.isConsent) {
  107. isRegister = false
  108. if (type) {
  109. this.shakeNum = 8
  110. tools.error('请阅读并同意协议');
  111. this.$refs.agreement.setConsentShake()
  112. }
  113. }
  114. console.log(isRegister,this.accountData,this.isConsent)
  115. if (!isRegister) {
  116. setTimeout(() => {
  117. if (this.shakeNum > 0) this.shakeNum = 0
  118. }, 500)
  119. }
  120. this.isRegister = isRegister
  121. },
  122. retrievePassword() {
  123. this.verifyData(true)
  124. if (!this.isRegister) {
  125. return;
  126. }
  127. if (this.isAJAX) {
  128. // return
  129. }
  130. this.isAJAX = true
  131. retrievePassword(this.accountData).then((res) => {
  132. if (res.code === 0) {
  133. tools.success('修改成功')
  134. setTimeout(() => {
  135. this.isAJAX = false;
  136. uni.reLaunch({
  137. url: '/pages/login/index'
  138. });
  139. }, 1500)
  140. } else {
  141. this.isAJAX = false;
  142. tools.error(res.msg)
  143. }
  144. })
  145. },
  146. getVerifiedCode() {
  147. if (this.timeNum > 0) {
  148. return;
  149. }
  150. if (this.accountData.phone === '') {
  151. tools.error("请输入手机号码")
  152. return;
  153. }
  154. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  155. if (!regPhone.test(this.accountData.phone)) {
  156. tools.error("手机号码格式错误")
  157. return;
  158. }
  159. uni.login({
  160. provider: "weixin",
  161. success: (loginRes) => {
  162. commonSend({
  163. 'phone': this.accountData.phone,
  164. 'send_type': 'register',
  165. 'wxCode':loginRes.code
  166. }).then((res) => {
  167. if (res.code === 0) {
  168. tools.success(res.msg);
  169. this.timeNum = 60;
  170. this.timer = setInterval(() => {
  171. this.timeNum--;
  172. if (this.timeNum <= 0) {
  173. clearInterval(this.timer);
  174. }
  175. }, 1000);
  176. } else {
  177. tools.error(res.msg);
  178. }
  179. })
  180. }
  181. })
  182. },
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. @import "/static/css/login.css";
  188. .page-box {
  189. padding-top: 370rpx;
  190. .login-form {
  191. margin: 0 30rpx;
  192. border-radius: 50rpx;
  193. padding: 40rpx 45rpx;
  194. animation-delay: 0.8s;
  195. .input-item {
  196. height: 96rpx;
  197. padding: 28rpx 40rpx;
  198. box-sizing: border-box;
  199. margin-top: 30rpx;
  200. .login-input {
  201. width: 100%;
  202. }
  203. }
  204. .input-item:first-child {
  205. margin-top: 0;
  206. }
  207. .input-send {
  208. display: flex;
  209. justify-content: flex-start;
  210. align-items: center;
  211. .login-input {
  212. width: calc(100% - 140rpx);
  213. }
  214. .login-send {
  215. width: 140rpx;
  216. text-align: center;
  217. }
  218. }
  219. .input-but {
  220. margin-top: 40rpx;
  221. width: 100%;
  222. height: 96rpx;
  223. line-height: 96rpx;
  224. text-align: center;
  225. }
  226. }
  227. .register-box {
  228. display: flex;
  229. justify-content: center;
  230. align-items: center;
  231. margin-top: 60rpx;
  232. .register-text {
  233. height: 34rpx;
  234. line-height: 34rpx;
  235. }
  236. .register-text:last-child {
  237. margin-right: 5rpx;
  238. }
  239. }
  240. }
  241. </style>