login.vue 6.3 KB

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