register.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="container">
  3. <view class="left-bottom-sign"></view>
  4. <view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view>
  5. <view class="right-top-sign"></view>
  6. <!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
  7. <view class="wrapper">
  8. <view class="left-top-sign">REGISTER</view>
  9. <view class="welcome">
  10. 欢迎加入!
  11. </view>
  12. <view class="input-content">
  13. <view class="input-item">
  14. <text class="tit">手机号码</text>
  15. <input type="number" :value="phone" placeholder="请输入手机号码" maxlength="11" data-key="phone" @input="inputChange" />
  16. </view>
  17. <view class="input-item">
  18. <text class="tit">验证码</text>
  19. <view class="verify-code">
  20. <input type="mobile" value="" placeholder="6位验证码" maxlength="6"
  21. data-key="verifyCode" @input="inputChange" style="width: 60%;" />
  22. <button class="cu-btn bg-green shadow" :disabled="sendDisabled" @click="doGetVerify">{{sendText}}</button>
  23. </view>
  24. </view>
  25. <view class="input-item">
  26. <text class="tit">密码</text>
  27. <input type="mobile" value="" placeholder="8-18位数字、字母组合" placeholder-class="input-empty" maxlength="20"
  28. data-key="password" @input="inputChange" @confirm="doRegister" />
  29. </view>
  30. </view>
  31. <button class="confirm-btn" @click="doRegister" :disabled="registering">注册</button>
  32. </view>
  33. <view class="register-section">
  34. 已经有账号?
  35. <text @click="toLogin">马上登录</text>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. mapMutations
  42. } from 'vuex';
  43. export default {
  44. data() {
  45. return {
  46. phone: '',
  47. password: '',
  48. registering: false,
  49. sendText: '获取验证码',
  50. sendDisabled: false
  51. }
  52. },
  53. onLoad() {
  54. },
  55. methods: {
  56. ...mapMutations(['login']),
  57. inputChange(e) {
  58. const key = e.currentTarget.dataset.key;
  59. this[key] = e.detail.value;
  60. },
  61. navBack() {
  62. uni.navigateBack();
  63. },
  64. toLogin() {
  65. uni.redirectTo({
  66. url: "/pages/public/login"
  67. })
  68. },
  69. doGetVerify() {
  70. const that = this
  71. if (!that.phone || that.phone.length != 11) {
  72. uni.showToast({
  73. title:'请输入正确手机号!',
  74. icon:'none'
  75. })
  76. return
  77. }
  78. that.$api.request('user', 'sendVerifyCode', {
  79. phone: that.phone,
  80. }).then(res => {
  81. let sec = 60
  82. let interval = setInterval(() => {
  83. sec--;
  84. that.sendText = sec + 's后重发'
  85. if (sec <= 0) {
  86. that.sendDisabled = false
  87. that.sendText = "获取验证码"
  88. clearInterval(interval)
  89. }
  90. }, 1000)
  91. })
  92. },
  93. async doRegister() {
  94. const that = this
  95. that.registering = true;
  96. that.$api.request('user','register', {
  97. phone: that.phone,
  98. password: that.password,
  99. verifyCode: that.verifyCode
  100. }, (failres => {
  101. uni.showToast({
  102. title:failres.errmsg
  103. })
  104. that.registering = false
  105. })).then(res => {
  106. //注册成功
  107. that.registering = false
  108. uni.redirectTo({
  109. url: './login'
  110. })
  111. })
  112. }
  113. },
  114. }
  115. </script>
  116. <style lang='scss' scoped>
  117. page {
  118. background: #fff;
  119. }
  120. .container {
  121. padding-top: 115px;
  122. position: relative;
  123. width: 100vw;
  124. height: 100vh;
  125. overflow: hidden;
  126. background: #fff;
  127. }
  128. .wrapper {
  129. position: relative;
  130. z-index: 90;
  131. background: #fff;
  132. padding-bottom: 40upx;
  133. }
  134. .back-btn {
  135. position: absolute;
  136. left: 40upx;
  137. z-index: 9999;
  138. padding-top: var(--status-bar-height);
  139. top: 40upx;
  140. font-size: 40upx;
  141. color: $font-color-dark;
  142. }
  143. .left-top-sign {
  144. font-size: 120upx;
  145. color: $page-color-base;
  146. position: relative;
  147. left: -16upx;
  148. }
  149. .right-top-sign {
  150. position: absolute;
  151. top: 80upx;
  152. right: -30upx;
  153. z-index: 95;
  154. &:before,
  155. &:after {
  156. display: block;
  157. content: "";
  158. width: 400upx;
  159. height: 80upx;
  160. background: #b4f3e2;
  161. }
  162. &:before {
  163. transform: rotate(50deg);
  164. border-radius: 0 50px 0 0;
  165. }
  166. &:after {
  167. position: absolute;
  168. right: -198upx;
  169. top: 0;
  170. transform: rotate(-50deg);
  171. border-radius: 50px 0 0 0;
  172. /* background: pink; */
  173. }
  174. }
  175. .left-bottom-sign {
  176. position: absolute;
  177. left: -270upx;
  178. bottom: -320upx;
  179. border: 100upx solid #d0d1fd;
  180. border-radius: 50%;
  181. padding: 180upx;
  182. }
  183. .welcome {
  184. position: relative;
  185. left: 50upx;
  186. top: -90upx;
  187. font-size: 46upx;
  188. color: #555;
  189. text-shadow: 1px 0px 1px rgba(0, 0, 0, .3);
  190. }
  191. .input-content {
  192. padding: 0 60upx;
  193. }
  194. .input-item {
  195. display: flex;
  196. flex-direction: column;
  197. align-items: flex-start;
  198. justify-content: center;
  199. padding: 0 30upx;
  200. background: $page-color-light;
  201. height: 140upx;
  202. border-radius: 4px;
  203. margin-bottom: 50upx;
  204. &:last-child {
  205. margin-bottom: 0;
  206. }
  207. .tit {
  208. height: 50upx;
  209. line-height: 56upx;
  210. font-size: $font-sm+2upx;
  211. color: $font-color-base;
  212. }
  213. input {
  214. height: 60upx;
  215. font-size: $font-base + 2upx;
  216. color: $font-color-dark;
  217. width: 100%;
  218. }
  219. .verify-code {
  220. flex-direction: row;
  221. display: flex;
  222. justify-content:end;
  223. flex-wrap: wrap
  224. }
  225. }
  226. .confirm-btn {
  227. width: 630upx;
  228. height: 76upx;
  229. line-height: 76upx;
  230. border-radius: 50px;
  231. margin-top: 70upx;
  232. background: $uni-color-primary;
  233. color: #fff;
  234. font-size: $font-lg;
  235. &:after {
  236. border-radius: 100px;
  237. }
  238. }
  239. .forget-section {
  240. font-size: $font-sm+2upx;
  241. color: $font-color-spec;
  242. text-align: center;
  243. margin-top: 40upx;
  244. }
  245. .register-section {
  246. position: absolute;
  247. left: 0;
  248. bottom: 50upx;
  249. width: 100%;
  250. font-size: $font-sm+2upx;
  251. color: $font-color-base;
  252. text-align: center;
  253. text {
  254. color: $font-color-spec;
  255. margin-left: 10upx;
  256. }
  257. }
  258. </style>