register.vue 6.6 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">
  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" focus 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" v-model="phone" focus 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" focus 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" focus 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="text" v-model="invitation" focus 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" focus 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: '888888', //验证码
  53. time: '', //保存倒计时对象
  54. countDown: 0 ,//倒计时
  55. };
  56. },
  57. onLoad(opt) {
  58. // 获取扫码邀请人id
  59. this.invitation = uni.getStorageSync('spread')||'';
  60. if(opt.spread) {
  61. this.invitation = opt.spread
  62. }
  63. },
  64. watch: {
  65. // 监听倒计时
  66. countDown(i) {
  67. if (i == 0) {
  68. clearInterval(this.time);
  69. }
  70. }
  71. },
  72. methods: {
  73. // 注册
  74. register() {
  75. let obj = this;
  76. if (obj.phone == '') {
  77. obj.$msg('请输入电话号码');
  78. return;
  79. }
  80. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.phone)) {
  81. obj.$msg('请输入正确的手机号');
  82. return;
  83. }
  84. if (obj.password == '') {
  85. obj.$msg('请输入密码');
  86. return;
  87. }
  88. if (obj.repassword == '') {
  89. obj.$msg('请再次输入密码');
  90. return;
  91. }
  92. if (obj.repassword != obj.password) {
  93. obj.$msg('两次密码不正确');
  94. return;
  95. }
  96. // if (obj.invitation == '') {
  97. // obj.$msg('请输入邀请码');
  98. // return;
  99. // }
  100. if (obj.code == '') {
  101. obj.$msg('请输入验证码');
  102. return;
  103. }
  104. register({
  105. phone: obj.phone, //账号
  106. nickname: obj.nickname,
  107. captcha: obj.code, //验证码
  108. password: obj.password ,//密码
  109. spread_uid:this.invitation//上级推广人
  110. }).then(function(e) {
  111. uni.showToast({
  112. title:'注册成功',
  113. duration:2000,
  114. position:'top'
  115. });
  116. setTimeout(function () {
  117. uni.navigateTo({
  118. url: '/pages/public/login'
  119. });
  120. },1000)
  121. });
  122. //调用注册接口,成功跳转登录页
  123. },
  124. //发送验证码
  125. verification() {
  126. let obj = this;
  127. if (this.phone == '') {
  128. this.$msg('请输入电话号码');
  129. return;
  130. }
  131. if (this.phone.length < 11) {
  132. this.$msg('请输入正确的手机号');
  133. return;
  134. }
  135. // 判断是否在倒计时
  136. if (obj.countDown > 0) {
  137. return false;
  138. } else {
  139. obj.countDown = 60;
  140. obj.time = setInterval(() => {
  141. obj.countDown--;
  142. }, 1000);
  143. //调用验证码接口
  144. verify({
  145. phone: obj.phone,
  146. type: 'register'
  147. })
  148. .then(({ data }) => {})
  149. .catch(err => {
  150. console.log(err);
  151. });
  152. }
  153. },
  154. login() {
  155. //返回登录
  156. uni.navigateTo({
  157. url: '/pages/public/login'
  158. });
  159. }
  160. }
  161. };
  162. </script>
  163. <style lang="scss">
  164. page {
  165. height: 100%;
  166. }
  167. .container {
  168. width: 100%;
  169. height: 100%;
  170. background-size: 100%;
  171. }
  172. .container_text {
  173. width: 100%;
  174. height: 500rpx;
  175. top: 0rpx;
  176. .banner-img {
  177. width: 100%;
  178. height: 100%;
  179. background-color: $base-color;
  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: $base-color;
  241. margin: 40rpx 10rpx;
  242. border-radius: 50rpx;
  243. }
  244. .uni-button-green-plain {
  245. border: 1px solid $base-color;
  246. margin: 40rpx 10rpx;
  247. border-radius: 50rpx;
  248. color: $base-color;
  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: $base-color;
  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>