register.vue 8.0 KB

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