register.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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':(accountData.nickname==='' && isShake)}" >
  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':(accountData.name==='' && isShake)}" >
  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':(accountData.phone==='' && isShake)}" >
  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':(accountData.code==='' && isShake)}">
  15. <en-input type="number" class="login-input" placeholder="请输入验证码" v-model="loginData.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':(accountData.password==='' && isShake)}" >
  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':(accountData.passwordTwo==='' && isShake)}">
  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. export default {
  45. components: {Agreement, EnInput},
  46. data() {
  47. return {
  48. accountData:{
  49. 'openid':'',
  50. 'phone':'',
  51. 'password':'',
  52. 'passwordTwo':'',
  53. 'code':'',
  54. 'wxCode':'',
  55. 'name':'',
  56. 'nickname':'',
  57. 'head_img':'',
  58. },
  59. timeNum:0,
  60. timer:null,
  61. isAJAX:false,
  62. isConsent: true,
  63. isRegister: false,
  64. isShake: false,
  65. };
  66. },
  67. watch:{
  68. 'accountData': {
  69. handler() {
  70. this.verifyData(false)
  71. },
  72. deep: true
  73. },
  74. },
  75. methods:{
  76. goToUrl(type){
  77. uni.navigateTo({
  78. 'url':'/pages/login/index'
  79. })
  80. },
  81. verifyData(type){
  82. let isRegister=true;
  83. if(!this.accountData.nickname){
  84. isRegister=false
  85. if(type)tools.error('请输入昵称');
  86. }
  87. if(!this.accountData.name){
  88. isRegister=false
  89. if(type)tools.error('请输入姓名');
  90. }
  91. if(!this.accountData.password){
  92. isRegister=false
  93. if(type)tools.error('请输入密码');
  94. }
  95. if(!this.accountData.passwordTwo){
  96. isRegister=false
  97. if(type)tools.error('请确认密码');
  98. }
  99. if(this.accountData.password!==this.accountData.passwordTwo){
  100. isRegister=false
  101. if(type)tools.error('密码输入不一致');
  102. }
  103. if(!this.accountData.code){
  104. isRegister=false
  105. if(type)tools.error('请输入验证码');
  106. }
  107. this.isRegister=isRegister
  108. },
  109. register(){
  110. this.verifyData(true)
  111. if(!this.isRegister){
  112. return ;
  113. }
  114. if(this.isAJAX){
  115. return
  116. }
  117. this.isAJAX = true
  118. uni.login({
  119. provider: "weixin",
  120. success: (loginRes) => {
  121. this.accountData.wxCode=loginRes.code;
  122. register(this.accountData).then((res)=>{
  123. if(res.code===1){
  124. tools.setLoginData(res.data,false)
  125. tools.success('注册成功')
  126. setTimeout(()=>{
  127. this.isAJAX = false;
  128. uni.reLaunch({
  129. url: '/pages/login/module/fill-in-data'
  130. });
  131. },1500)
  132. }else {
  133. this.isAJAX = false;
  134. tools.error(res.msg)
  135. }
  136. })
  137. },
  138. fail: (loginRes) => {
  139. this.isAJAX = false;
  140. tools.error("获取授权信息失败");
  141. },
  142. });
  143. },
  144. getVerifiedCode() {
  145. if (this.timeNum > 0) {
  146. return;
  147. }
  148. if (this.accountData.phone === '') {
  149. tools.error("请输入手机号码")
  150. return;
  151. }
  152. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  153. if (!regPhone.test(this.accountData.phone)) {
  154. tools.error("手机号码格式错误")
  155. return;
  156. }
  157. commonSend({
  158. 'phone': this.accountData.phone,
  159. 'send_type': 'register'
  160. }).then((res) => {
  161. if (res.code === 1) {
  162. tools.success(res.msg);
  163. this.timeNum = 60;
  164. this.timer = setInterval(() => {
  165. this.timeNum--;
  166. if (this.timeNum <= 0) {
  167. clearInterval(this.timer);
  168. }
  169. }, 1000);
  170. } else {
  171. tools.error(res.msg);
  172. }
  173. })
  174. },
  175. }
  176. }
  177. </script>
  178. <style lang="scss">
  179. @import "/static/css/login.css";
  180. .page-box{
  181. padding-top: 370rpx;
  182. .login-form{
  183. margin: 0 30rpx;
  184. border-radius: 50rpx;
  185. padding: 40rpx 45rpx;
  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>