register.vue 6.2 KB

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