login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <!-- 蓝色登录页面2 -->
  2. <template>
  3. <view>
  4. <u-toast ref="uToast"/>
  5. <view class="img-a">
  6. <view class="t-b" @click="goLogin3()">
  7. 您好,
  8. <br/>
  9. 欢迎使用 开源字节
  10. </view>
  11. </view>
  12. <view class="login-view">
  13. <view class="t-login">
  14. <form class="cl">
  15. <view class="t-a">
  16. <text class="txt">手机号</text>
  17. <input v-model="username" maxlength="11" name="phone" placeholder="请输入您的手机号" type="number"/>
  18. </view>
  19. <view class="t-a">
  20. <text class="txt">密码</text>
  21. <input v-model="password" maxlength="18" name="code" placeholder="请输入您的密码" type="password"/>
  22. </view>
  23. <button @tap="login()">登 录</button>
  24. <view class="reg" @tap="reg()">短信登录</view>
  25. </form>
  26. </view>
  27. </view>
  28. <!-- #ifdef MP-WEIXIN -->
  29. <!-- <view class="weixin">
  30. <button open-type="getPhoneNumber" @getphonenumber="weChatLogin" class="clearBtn">
  31. <view class="loginType">
  32. <view class="item">
  33. <view class="icon"><u-icon size="60" name="weixin-fill" color="rgb(83,194,64)"></u-icon></view>
  34. 微信
  35. </view>
  36. </view>
  37. </button>
  38. </view> -->
  39. <!-- #endif -->
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. username: '18720989281',
  47. password: '123456',
  48. }
  49. },
  50. methods: {
  51. login() {
  52. if (!this.$u.test.mobile(this.username)) {
  53. return this.$refs.uToast.show({
  54. title: '手机号不正确',
  55. type: 'warning',
  56. })
  57. }
  58. if (!this.password) {
  59. return this.$refs.uToast.show({
  60. title: '密码不能为空',
  61. type: 'warning',
  62. })
  63. }
  64. // 登录json参数,不同于表单参数
  65. let url = "/api/thirdLogin";
  66. this.$u.post(url, {
  67. username: this.username,
  68. password: this.password
  69. }).then(data => {
  70. // 登录成功初始化token与用户信息
  71. this.$u.vuex('vuex_token', data.token);
  72. this.$u.vuex('vuex_user', data.loginUser);
  73. uni.switchTab({
  74. url: '/pages/index/index'
  75. })
  76. });
  77. },
  78. reg() {
  79. this.$u.route({
  80. url: 'pages/login/account'
  81. })
  82. },
  83. weChatLogin(e) {
  84. let code = e.detail.code;
  85. if (code) {
  86. uni.showLoading({title: "登录中....", mask: true})
  87. let url = "/api/miniWxApi/getPhoneNum?code=" + code;
  88. this.$u.get(url).then(res => {
  89. let phoneNum = res.phoneNum
  90. let weChatUrl = "/api/weChatLogin";
  91. this.$u.post(weChatUrl, {
  92. username: phoneNum,
  93. code: code
  94. }).then(data => {
  95. uni.hideLoading();
  96. // 登录成功初始化token与用户信息
  97. this.$u.vuex('vuex_token', data.token);
  98. this.$u.vuex('vuex_user', data.loginUser);
  99. uni.switchTab({
  100. url: '/pages/index/index'
  101. })
  102. });
  103. });
  104. } else {
  105. this.$mytip.toast('登录失败')
  106. }
  107. },
  108. }
  109. };
  110. </script>
  111. <style>
  112. page {
  113. background-color: #ffffff;
  114. }
  115. </style>
  116. <style>
  117. .txt {
  118. font-size: 32 rpx;
  119. font-weight: bold;
  120. color: #333333;
  121. }
  122. .img-a {
  123. width: 100%;
  124. height: 450 rpx;
  125. background-image: url('../../static/bg/user.jpg');
  126. background-size: 100%;
  127. }
  128. .reg {
  129. font-size: 28 rpx;
  130. color: #fff;
  131. height: 90 rpx;
  132. line-height: 90 rpx;
  133. font-weight: bold;
  134. background: #f5f6fa;
  135. color: #000000;
  136. text-align: center;
  137. margin-top: 30 rpx;
  138. border-radius: 50px;
  139. }
  140. .login-view {
  141. width: 100%;
  142. position: relative;
  143. margin-top: -120 rpx;
  144. background-color: #ffffff;
  145. }
  146. .t-login {
  147. width: 600 rpx;
  148. margin: 0 auto;
  149. font-size: 28 rpx;
  150. padding-top: 80 rpx;
  151. }
  152. .t-login button {
  153. font-size: 28 rpx;
  154. background: #ff536f;
  155. color: #fff;
  156. height: 90 rpx;
  157. line-height: 90 rpx;
  158. border-radius: 50 rpx;
  159. font-weight: bold;
  160. }
  161. .t-login input {
  162. height: 90 rpx;
  163. line-height: 90 rpx;
  164. margin-bottom: 50 rpx;
  165. border-bottom: 1px solid #e9e9e9;
  166. font-size: 28 rpx;
  167. }
  168. .t-login .t-a {
  169. position: relative;
  170. }
  171. .t-b {
  172. text-align: left;
  173. font-size: 42 rpx;
  174. color: #ffffff;
  175. padding: 130 rpx 0 0 70 rpx;
  176. font-weight: bold;
  177. line-height: 70 rpx;
  178. }
  179. .t-login .t-c {
  180. position: absolute;
  181. right: 22 rpx;
  182. top: 22 rpx;
  183. background: #5677fc;
  184. color: #fff;
  185. font-size: 24 rpx;
  186. border-radius: 50 rpx;
  187. height: 50 rpx;
  188. line-height: 50 rpx;
  189. padding: 0 25 rpx;
  190. }
  191. .t-login .t-d {
  192. text-align: center;
  193. color: #999;
  194. margin: 80 rpx 0;
  195. }
  196. .t-login .t-e {
  197. text-align: center;
  198. width: 250 rpx;
  199. margin: 80 rpx auto 0;
  200. }
  201. .t-login .t-g {
  202. float: left;
  203. width: 50%;
  204. }
  205. .t-login .t-e image {
  206. width: 50 rpx;
  207. height: 50 rpx;
  208. }
  209. .t-login .t-f {
  210. text-align: center;
  211. margin: 150 rpx 0 0 0;
  212. color: #666;
  213. }
  214. .t-login .t-f text {
  215. margin-left: 20 rpx;
  216. color: #aaaaaa;
  217. font-size: 27 rpx;
  218. }
  219. .t-login .uni-input-placeholder {
  220. color: #aeaeae;
  221. }
  222. .cl {
  223. zoom: 1;
  224. }
  225. .cl:after {
  226. clear: both;
  227. display: block;
  228. visibility: hidden;
  229. height: 0;
  230. content: '\20';
  231. }
  232. .weixin {
  233. padding: 100 rpx 0;
  234. }
  235. .clearBtn {
  236. margin: 0;
  237. padding: 0;
  238. line-height: 1;
  239. background-color: #FFFFFF;
  240. }
  241. .clearBtn::after {
  242. position: unset !important;
  243. border: unset;
  244. }
  245. </style>