login.vue 5.9 KB

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