register.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="container">
  3. <view class="container_text" >
  4. <!-- <image class="banner-img" src="/static/img/img01.png" mode="scaleToFill"></image> -->
  5. <view class="banner-img" style="background-color: #f63332;">
  6. </view>
  7. </view>
  8. <view class="loginTitle"><text>注册</text></view>
  9. <view class="login_text">
  10. <view class="login_input flex">
  11. <view class="login_img"><image src="/static/icon/img03.png"></image></view>
  12. <view class="login_name"><input class="uni-input" v-model="nickname" type="text" placeholder="请输入姓名"/></view>
  13. </view>
  14. <view class="login_input flex">
  15. <view class="login_img"><image src="/static/icon/img03.png"></image></view>
  16. <view class="login_name"><input class="uni-input" type="number" v-model="phone" placeholder="请输入手机号" /></view>
  17. </view>
  18. <view class="login_input flex">
  19. <view class="login_img"><image src="/static/icon/img04.png"></image></view>
  20. <view class="login_name"><input class="uni-input" type="password" v-model="password" placeholder="请输入密码" /></view>
  21. </view>
  22. <view class="login_input flex">
  23. <view class="login_img"><image src="/static/icon/img04.png"></image></view>
  24. <view class="login_name"><input class="uni-input" type="password" v-model="repassword" placeholder="请重复输入密码" /></view>
  25. </view>
  26. <view class="login_input flex">
  27. <view class="login_img"><image src="/static/icon/img07.png"></image></view>
  28. <view class="login_name"><input class="uni-input" type="number" v-model="invitation" placeholder="请输入邀请人手机号" /></view>
  29. </view>
  30. <view class="login_input flex" style="display: none;">
  31. <view class="login_img"><image src="/static/icon/img06.png"></image></view>
  32. <view class="login_name flex">
  33. <input class="uni-input width" v-model="code" placeholder="请输入验证码" />
  34. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  35. </view>
  36. </view>
  37. <view><button type="green" @click="register" class="uni-button uni-button-green">注册账号</button></view>
  38. <view><button class="uni-button uni-button-green uni-button-green-plain" type="green" plain="true" hover-class="none" @click="login">返回登录</button></view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { register, verify } from '@/api/login.js';
  44. export default {
  45. data() {
  46. return {
  47. nickname: '',//用户昵称
  48. phone: '', //用户
  49. password: '', //密码
  50. repassword: '',
  51. invitation: '', //邀请码
  52. code: '123456', //验证码
  53. time: '', //保存倒计时对象
  54. countDown: 0 ,//倒计时
  55. };
  56. },
  57. onLoad() {
  58. // 获取扫码邀请人id
  59. this.invitation = uni.getStorageSync('spread')||'';
  60. },
  61. watch: {
  62. // 监听倒计时
  63. countDown(i) {
  64. if (i == 0) {
  65. clearInterval(this.time);
  66. }
  67. }
  68. },
  69. methods: {
  70. // 注册
  71. register() {
  72. let obj = this;
  73. if(obj.nickname == '') {
  74. obj.$api.msg('请输入姓名');
  75. return;
  76. }
  77. if (obj.phone == '') {
  78. obj.$api.msg('请输入电话号码');
  79. return;
  80. }
  81. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.phone)) {
  82. obj.$api.msg('请输入正确的手机号');
  83. return;
  84. }
  85. if (obj.password == '') {
  86. obj.$api.msg('请输入密码');
  87. return;
  88. }
  89. if (obj.repassword == '') {
  90. obj.$api.msg('请再次输入密码');
  91. return;
  92. }
  93. if (obj.repassword != obj.password) {
  94. obj.$api.msg('两次密码不正确');
  95. return;
  96. }
  97. if ((obj.invitation == '')) {
  98. obj.$api.msg('请输入邀请码');
  99. return;
  100. }
  101. // if (obj.code == '') {
  102. // obj.$api.msg('请输入验证码');
  103. // return;
  104. // }
  105. register({
  106. nickname: obj.nickname,
  107. account: obj.phone, //账号
  108. captcha: obj.code, //验证码
  109. password: obj.password ,//密码
  110. spread:this.invitation//上级推广人
  111. }).then(function(e) {
  112. uni.showToast({
  113. title:'注册成功',
  114. duration:2000,
  115. position:'top'
  116. });
  117. setTimeout(function () {
  118. uni.navigateTo({
  119. url: '/pages/public/login'
  120. });
  121. },1000)
  122. });
  123. //调用注册接口,成功跳转登录页
  124. },
  125. //发送验证码
  126. verification() {
  127. let obj = this;
  128. if (this.phone == '') {
  129. this.$api.msg('请输入电话号码');
  130. return;
  131. }
  132. if (this.phone.length < 11) {
  133. this.$api.msg('请输入正确的手机号');
  134. return;
  135. }
  136. // 判断是否在倒计时
  137. if (obj.countDown > 0) {
  138. return false;
  139. } else {
  140. obj.countDown = 60;
  141. obj.time = setInterval(() => {
  142. obj.countDown--;
  143. }, 1000);
  144. //调用验证码接口
  145. verify({
  146. phone: obj.phone,
  147. type: 'register'
  148. })
  149. .then(({ data }) => {})
  150. .catch(err => {
  151. console.log(err);
  152. });
  153. }
  154. },
  155. login() {
  156. //返回登录
  157. uni.navigateTo({
  158. url: '/pages/public/login'
  159. });
  160. }
  161. }
  162. };
  163. </script>
  164. <style lang="scss">
  165. page {
  166. height: 100%;
  167. }
  168. .container {
  169. width: 100%;
  170. height: 100%;
  171. background-size: 100%;
  172. }
  173. .container_text {
  174. width: 100%;
  175. height: 500rpx;
  176. top: 0rpx;
  177. .banner-img {
  178. width: 100%;
  179. height: 100%;
  180. }
  181. }
  182. .login_text {
  183. margin: auto 30rpx;
  184. position: relative;
  185. padding: 100rpx 102rpx;
  186. background-color: #ffffff;
  187. margin-top: -180rpx;
  188. border-radius: 20rpx;
  189. .login_input {
  190. border-bottom: 1px solid #f0f0f0;
  191. margin-bottom: 65rpx;
  192. .login_img image {
  193. height: 35rpx;
  194. width: 29rpx;
  195. margin-right: 20rpx;
  196. }
  197. .uni-input {
  198. text-align: left;
  199. width: 470rpx;
  200. font-size: 28rpx !important;
  201. }
  202. .login_name {
  203. color: #333333;
  204. }
  205. }
  206. .other {
  207. margin-top: 60rpx;
  208. .fenge {
  209. width: 30%;
  210. height: 2rpx;
  211. background-color: #eeeeee;
  212. }
  213. .qita {
  214. font-size: 28rpx;
  215. color: #999999;
  216. }
  217. }
  218. .weixin {
  219. width: 75rpx;
  220. height: 75rpx;
  221. margin: 25rpx auto;
  222. }
  223. .weixin image {
  224. width: 100%;
  225. height: 100%;
  226. }
  227. .weixin_text {
  228. text-align: center;
  229. font-size: 28rpx;
  230. color: #999999;
  231. }
  232. .forget {
  233. font-size: 28rpx;
  234. width: 100%;
  235. text-align: right;
  236. color: #999999;
  237. }
  238. .uni-button-green {
  239. color: #ffffff;
  240. background-color: #ff4c4c;
  241. margin: 40rpx 10rpx;
  242. border-radius: 50rpx;
  243. }
  244. .uni-button-green-plain {
  245. border: 1px solid #ff4c4c;
  246. margin: 40rpx 10rpx;
  247. border-radius: 50rpx;
  248. color: #ff4c4c;
  249. background-color: #ffffff;
  250. }
  251. .uni-button {
  252. height: 85rpx;
  253. line-height: 85rpx;
  254. }
  255. }
  256. .loginTitle {
  257. position: absolute;
  258. top: 250rpx;
  259. width: 100%;
  260. text-align: center;
  261. color: white;
  262. font-size: 40rpx;
  263. }
  264. .forget {
  265. width: 100rpx;
  266. font-size: 24rpx;
  267. color: #ffffff;
  268. margin: 0px auto;
  269. border-bottom: 1px solid #ffffff;
  270. }
  271. .width {
  272. width: 325rpx !important;
  273. }
  274. .code {
  275. color: #ff4c4c;
  276. font-size: 23rpx;
  277. border-left: 1px solid #eeeeee;
  278. width: 150rpx;
  279. flex-shrink: 0;
  280. text-align: center;
  281. }
  282. uni-button {
  283. height: 80rpx !important;
  284. line-height: 80rpx !important;
  285. }
  286. </style>