register.vue 6.5 KB

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