login.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="container">
  3. <view class="top">
  4. <view class="login">登录</view>
  5. </view>
  6. <view class="center">
  7. <view class="login_input">
  8. <image class="img" src="../../static/icon/img03.png"></image>
  9. <input class="input" v-model="username" focus placeholder="请输入手机号" />
  10. </view>
  11. <view class="login_input">
  12. <image class="img" src="../../static/icon/img04.png"></image>
  13. <input class="input" type="password" v-model="passward" placeholder="请输入密码" />
  14. </view>
  15. <!-- 登录按钮 -->
  16. <view class="login_buttom" @click="toLogin">
  17. 登录
  18. </view>
  19. <!-- 注册按钮 -->
  20. <view class="register_buttom" @click="register">
  21. 注册账号
  22. </view>
  23. <!--
  24. <view class="login_else">
  25. <view class="login_else_border">
  26. </view>
  27. 其他方式登录
  28. <view class="login_else_border">
  29. </view>
  30. </view> -->
  31. <!-- 微信登录 -->
  32. <!-- <view class="login_wx" @click="appLogin">
  33. <image src="https://zhxc2030.com/img/wxlogin.png"></image>
  34. </view>
  35. <view class="login_wx_text">
  36. 微信登录
  37. </view> -->
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. mapMutations
  44. } from 'vuex';
  45. import {
  46. login,
  47. getUserInfo
  48. } from '@/api/login.js';
  49. export default {
  50. data() {
  51. return {
  52. username: '',
  53. passward: '',
  54. // #ifdef APP-PLUS
  55. // 保存当前是否为微信浏览器
  56. weixinB: false,
  57. // #endif
  58. };
  59. },
  60. onLoad() {
  61. this.weixinB = uni.getStorageSync('weichatBrowser')
  62. },
  63. methods: {
  64. //微信登录
  65. appLogin: function() {
  66. uni.getProvider({
  67. service: 'oauth',
  68. success: function(res) {
  69. console.log(res.provider);
  70. //支持微信、qq和微博等
  71. if (~res.provider.indexOf('weixin')) {
  72. uni.login({
  73. provider: 'weixin',
  74. success: function(loginRes) {
  75. console.log('-------获取openid(unionid)-----');
  76. console.log(JSON.stringify(loginRes));
  77. // 获取用户信息
  78. uni.getUserInfo({
  79. provider: 'weixin',
  80. success: function(infoRes) {
  81. console.log('-------获取微信用户所有-----');
  82. console.log(JSON.stringify(infoRes
  83. .userInfo));
  84. }
  85. });
  86. }
  87. });
  88. }
  89. }
  90. });
  91. },
  92. ...mapMutations('user', ['setUserInfo', 'login']),
  93. //登录
  94. async toLogin() {
  95. let obj = this;
  96. obj.logining = true;
  97. let reg = /^1[3456789]\d{9}$/;
  98. if (obj.username == '') {
  99. obj.$api.msg('请输入手机号');
  100. return;
  101. }
  102. if (!reg.test(obj.username)) {
  103. obj.$api.msg('请输入正确的手机号');
  104. return;
  105. }
  106. if (obj.passward == '') {
  107. obj.$api.msg('请输入密码');
  108. return;
  109. }
  110. login({
  111. account: obj.username,
  112. password: obj.passward
  113. })
  114. .then(function(e) {
  115. uni.setStorageSync('token', e.data.userinfo.token);
  116. console.log(e.data.userinfo.token, 'u++++++++++++++++++++')
  117. //调用注册接口,成功跳转首页
  118. getUserInfo({}).then((e) => {
  119. console.log(e, 'userInfo000000000000000000000')
  120. obj.login();
  121. // 保存返回用户数据
  122. obj.setUserInfo(e.data);
  123. uni.switchTab({
  124. url: '/pages/index/index'
  125. })
  126. })
  127. })
  128. .catch(function(e) {
  129. console.log(e);
  130. });
  131. },
  132. //跳转注册页
  133. register() {
  134. uni.navigateTo({
  135. url: `/pages/login/register`
  136. });
  137. },
  138. //跳转忘记密码
  139. // forget() {
  140. // uni.navigateTo({
  141. // url: `/pages/public/forget`
  142. // });
  143. // },
  144. // 后退
  145. navBack() {
  146. uni.navigateBack();
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss">
  152. .container {
  153. line-height: 1;
  154. .top {
  155. width: 750rpx;
  156. height: 500rpx;
  157. position: relative;
  158. background-color: #fa7e67;
  159. image {
  160. width: 750rpx;
  161. height: 500rpx;
  162. }
  163. .login {
  164. font-size: 36rpx;
  165. font-weight: bold;
  166. position: absolute;
  167. top: 270rpx;
  168. left: 340rpx;
  169. color: #FFFFFF;
  170. }
  171. }
  172. .center {
  173. z-index: 9;
  174. width: 700rpx;
  175. // height: 840rpx;
  176. background-color: #FFFFFF;
  177. border-radius: 20rpx;
  178. margin-top: -150rpx;
  179. margin-left: 24rpx;
  180. padding-bottom: 60rpx;
  181. position: absolute;
  182. .login_input {
  183. width: 560rpx;
  184. display: flex;
  185. justify-content: center;
  186. margin: 70rpx auto;
  187. border-bottom: 2rpx solid #F0F0F0;
  188. padding-bottom: 9rpx;
  189. color: #999999;
  190. .img {
  191. width: 30rpx;
  192. height: auto;
  193. margin-right: 18rpx;
  194. }
  195. .input {
  196. width: 470rpx;
  197. font-size: $font-base;
  198. letter-spacing: 3rpx;
  199. }
  200. }
  201. .login_buttom {
  202. width: 560rpx;
  203. background: linear-gradient(0deg, #fa7e67, #F24D33);
  204. border-radius: 40rpx;
  205. margin: 0 auto;
  206. margin-bottom: 20rpx;
  207. text-align: center;
  208. line-height: 80rpx;
  209. color: #FFFFFF;
  210. font-size: 30rpx;
  211. }
  212. .register_buttom {
  213. width: 560rpx;
  214. line-height: 80rpx;
  215. border: 1rpx solid #fa7e67;
  216. border-radius: 40rpx;
  217. text-align: center;
  218. margin: 0 auto;
  219. font-size: 30rpx;
  220. font-weight: 500;
  221. color: #fa7e67;
  222. }
  223. .login_else {
  224. width: 560rpx;
  225. margin: 0 auto;
  226. margin-top: 100rpx;
  227. margin-bottom: 45rpx;
  228. font-size: 24rpx;
  229. font-weight: 500;
  230. color: rgba(153, 153, 153, 1);
  231. display: flex;
  232. justify-content: center;
  233. align-items: center;
  234. .login_else_border {
  235. flex: 1;
  236. height: 1rpx;
  237. background: rgba(238, 238, 238, 1);
  238. }
  239. }
  240. .login_wx {
  241. width: 63rpx;
  242. height: 63rpx;
  243. margin: 0 auto;
  244. border: none;
  245. position: static;
  246. padding: 0;
  247. image {
  248. width: 63rpx;
  249. height: 63rpx;
  250. }
  251. }
  252. .login_wx_text {
  253. text-align: center;
  254. font-size: 24rpx;
  255. font-weight: 400;
  256. color: rgba(153, 153, 153, 1);
  257. margin-top: 15rpx;
  258. }
  259. }
  260. }
  261. </style>