register.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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="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':(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. 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. isShake: false,
  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.isShake=true
  88. tools.error('请输入昵称');
  89. }
  90. }
  91. if(!this.accountData.name){
  92. isRegister=false
  93. if(type){
  94. this.isShake=true
  95. tools.error('请输入姓名');
  96. }
  97. }
  98. if(!this.accountData.password){
  99. isRegister=false
  100. if(type){
  101. this.isShake=true
  102. tools.error('请输入密码');
  103. }
  104. }
  105. if(!this.accountData.passwordTwo){
  106. isRegister=false
  107. if(type){
  108. this.isShake=true
  109. tools.error('请确认密码');
  110. }
  111. }
  112. if(this.accountData.password!==this.accountData.passwordTwo){
  113. isRegister=false
  114. if(type){
  115. this.isShake=true
  116. tools.error('密码输入不一致');
  117. }
  118. }
  119. if(!this.accountData.code){
  120. isRegister=false
  121. if(type){
  122. this.isShake=true
  123. tools.error('请输入验证码');
  124. }
  125. }
  126. console.log(this.isConsent)
  127. if(!this.isConsent){
  128. isRegister=false
  129. if(type){
  130. this.isShake=true
  131. tools.error('请阅读并同意协议');
  132. this.$refs.agreement.setConsentShake()
  133. }
  134. }
  135. if(this.isShake){
  136. setTimeout(()=>{
  137. this.isShake=false
  138. },500)
  139. }
  140. this.isRegister=isRegister
  141. },
  142. register(){
  143. this.verifyData(true)
  144. if(!this.isRegister){
  145. return ;
  146. }
  147. if(this.isAJAX){
  148. return
  149. }
  150. this.isAJAX = true
  151. uni.login({
  152. provider: "weixin",
  153. success: (loginRes) => {
  154. this.accountData.wxCode=loginRes.code;
  155. register(this.accountData).then((res)=>{
  156. if(res.code===1){
  157. tools.setLoginData(res.data,false)
  158. tools.success('注册成功')
  159. setTimeout(()=>{
  160. this.isAJAX = false;
  161. uni.reLaunch({
  162. url: '/pages/login/module/fill-in-data'
  163. });
  164. },1500)
  165. }else {
  166. this.isAJAX = false;
  167. tools.error(res.msg)
  168. }
  169. })
  170. },
  171. fail: (loginRes) => {
  172. this.isAJAX = false;
  173. tools.error("获取授权信息失败");
  174. },
  175. });
  176. },
  177. getVerifiedCode() {
  178. if (this.timeNum > 0) {
  179. return;
  180. }
  181. if (this.accountData.phone === '') {
  182. tools.error("请输入手机号码")
  183. return;
  184. }
  185. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  186. if (!regPhone.test(this.accountData.phone)) {
  187. tools.error("手机号码格式错误")
  188. return;
  189. }
  190. commonSend({
  191. 'phone': this.accountData.phone,
  192. 'send_type': 'register'
  193. }).then((res) => {
  194. if (res.code === 1) {
  195. tools.success(res.msg);
  196. this.timeNum = 60;
  197. this.timer = setInterval(() => {
  198. this.timeNum--;
  199. if (this.timeNum <= 0) {
  200. clearInterval(this.timer);
  201. }
  202. }, 1000);
  203. } else {
  204. tools.error(res.msg);
  205. }
  206. })
  207. },
  208. }
  209. }
  210. </script>
  211. <style lang="scss">
  212. @import "/static/css/login.css";
  213. .page-box{
  214. padding-top: 370rpx;
  215. .login-form{
  216. margin: 0 30rpx;
  217. border-radius: 50rpx;
  218. padding: 40rpx 45rpx;
  219. animation-delay: 0.8s;
  220. .input-item{
  221. height: 96rpx;
  222. padding: 28rpx 40rpx;
  223. box-sizing: border-box;
  224. margin-top: 30rpx;
  225. .login-input{
  226. width: 100%;
  227. }
  228. }
  229. .input-item:first-child{
  230. margin-top: 0;
  231. }
  232. .input-send{
  233. display: flex;
  234. justify-content: flex-start;
  235. align-items: center;
  236. .login-input{
  237. width:calc(100% - 140rpx) ;
  238. }
  239. .login-send{
  240. width: 140rpx;
  241. text-align: center;
  242. }
  243. }
  244. .input-but{
  245. margin-top: 40rpx;
  246. width: 100%;
  247. height: 96rpx;
  248. line-height: 96rpx;
  249. text-align: center;
  250. }
  251. }
  252. .register-box{
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. margin-top: 60rpx;
  257. .register-text{
  258. height: 34rpx;
  259. line-height: 34rpx;
  260. }
  261. .register-text:last-child{
  262. margin-right: 5rpx;
  263. }
  264. }
  265. }
  266. </style>