register.vue 5.8 KB

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