register.vue 5.9 KB

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