login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="container">
  3. <view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view>
  4. <!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
  5. <view class="wrapper">
  6. <view class="left-top-sign">LOGIN</view>
  7. <view class="welcome">
  8. 欢迎回来!
  9. </view>
  10. <view class="input-content">
  11. <view class="input-item">
  12. <text class="tit">手机号码</text>
  13. <input
  14. type="text"
  15. :value="mobile"
  16. placeholder="请输入手机号码"
  17. data-key="mobile"
  18. @input="inputChange"
  19. />
  20. </view>
  21. <view class="input-item">
  22. <text class="tit">密码</text>
  23. <input
  24. type="mobile"
  25. value=""
  26. placeholder="6-18位不含特殊字符的数字、字母组合"
  27. placeholder-class="input-empty"
  28. maxlength="20"
  29. password
  30. data-key="password"
  31. @input="inputChange"
  32. @confirm="toLogin"
  33. />
  34. </view>
  35. </view>
  36. <button class="confirm-btn" @click="toLogin" :disabled="logining">登录</button>
  37. <!-- #ifdef MP-WEIXIN -->
  38. <button class="confirm-btn" open-type="getPhoneNumber" @getphonenumber="loginForWechatMini">授权微信绑定电话号码一键登录</button>
  39. <!-- #endif -->
  40. <view class="forget-section">
  41. <view><label @click="register('resetpwd')">忘记密码</label> - <label @click="register('register')">立马注册</label></view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. mapMutations
  49. } from 'vuex';
  50. export default{
  51. data(){
  52. return {
  53. mobile: '',
  54. password: '',
  55. logining: false
  56. }
  57. },
  58. onLoad(){
  59. },
  60. methods: {
  61. ...mapMutations(['login']),
  62. inputChange(e){
  63. const key = e.currentTarget.dataset.key;
  64. this[key] = e.detail.value;
  65. },
  66. navBack(){
  67. uni.navigateBack();
  68. },
  69. async toLogin(){
  70. this.logining = true;
  71. let data = await this.$api.request('/user/login', 'POST', {
  72. mobile: this.mobile,
  73. password: this.password
  74. })
  75. if (data) {
  76. this.$store.commit('login', data)
  77. this.logining = true;
  78. setTimeout(function(){
  79. uni.navigateBack();
  80. }, 2000)
  81. } else {
  82. this.logining = false;
  83. }
  84. },
  85. register(event){
  86. uni.navigateTo({
  87. url:'./register?event='+event
  88. })
  89. },
  90. // #ifdef MP-WEIXIN
  91. async loginForWechatMini(e) {
  92. if (e.hasOwnProperty('detail')) {
  93. let data = await this.$api.request('/user/loginForWechatMini', 'POST',{
  94. encryptedData: e.detail.encryptedData,
  95. iv: e.detail.iv
  96. });
  97. if (data) {
  98. this.$store.commit('login', data);
  99. this.$api.msg('登录成功');
  100. setTimeout(function() {
  101. uni.navigateBack();
  102. },2000);
  103. }
  104. }
  105. },
  106. // #endif
  107. },
  108. }
  109. </script>
  110. <style lang='scss'>
  111. page{
  112. background: #fff;
  113. }
  114. .container{
  115. padding-top: 160rpx;
  116. position:relative;
  117. width: 100vw;
  118. height: 100vh;
  119. overflow: hidden;
  120. background: #fff;
  121. }
  122. .wrapper{
  123. position:relative;
  124. z-index: 90;
  125. background: #fff;
  126. padding-bottom: 40upx;
  127. }
  128. .back-btn{
  129. position:absolute;
  130. left: 40upx;
  131. z-index: 9999;
  132. padding-top: var(--status-bar-height);
  133. top: 40upx;
  134. font-size: 40upx;
  135. color: $font-color-dark;
  136. }
  137. .left-top-sign{
  138. font-size: 120upx;
  139. color: $page-color-base;
  140. position:relative;
  141. left: -16upx;
  142. }
  143. .welcome{
  144. position:relative;
  145. left: 50upx;
  146. top: -90upx;
  147. font-size: 46upx;
  148. color: #555;
  149. text-shadow: 1px 0px 1px rgba(0,0,0,.3);
  150. }
  151. .input-content{
  152. padding: 0 60upx;
  153. }
  154. .input-item{
  155. display:flex;
  156. flex-direction: column;
  157. align-items:flex-start;
  158. justify-content: center;
  159. padding: 0 30upx;
  160. background:$page-color-light;
  161. height: 120upx;
  162. border-radius: 4px;
  163. margin-bottom: 50upx;
  164. &:last-child{
  165. margin-bottom: 0;
  166. }
  167. .tit{
  168. height: 50upx;
  169. line-height: 56upx;
  170. font-size: $font-sm+2upx;
  171. color: $font-color-base;
  172. }
  173. input{
  174. height: 60upx;
  175. font-size: $font-base + 2upx;
  176. color: $font-color-dark;
  177. width: 100%;
  178. }
  179. }
  180. .confirm-btn{
  181. width: 630upx;
  182. height: 76upx;
  183. line-height: 76upx;
  184. border-radius: 50px;
  185. margin-top: 70upx;
  186. background: $uni-color-primary;
  187. color: #fff;
  188. font-size: $font-lg;
  189. &:after{
  190. border-radius: 100px;
  191. }
  192. }
  193. .forget-section{
  194. font-size: $font-sm+10upx;
  195. color: $font-color-spec;
  196. text-align: center;
  197. margin-top: 100upx;
  198. label{
  199. margin: 10upx 60upx;
  200. }
  201. }
  202. .register-section{
  203. position:absolute;
  204. left: 0;
  205. bottom: 50upx;
  206. width: 100%;
  207. font-size: $font-sm+2upx;
  208. color: $font-color-base;
  209. text-align: center;
  210. text{
  211. color: $font-color-spec;
  212. margin-left: 10upx;
  213. }
  214. }
  215. </style>