login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <image src="../../static/icon/logo.png" mode="" class="logo"></image>
  5. <view class="logo-tit"><text>博·赢</text></view>
  6. <!-- <image class="banner-img" src="/static/img/img01.png" mode="scaleToFill"></image> -->
  7. </view>
  8. <view class="login_text">
  9. <view class="login_input flex">
  10. <view class="login_img"><image src="/static/icon/icon-phone.png"></image></view>
  11. <view class="login_name"><input class="uni-input" v-model="username" focus placeholder="请输入手机号" /></view>
  12. </view>
  13. <view class="login_input flex">
  14. <view class="login_img"><image src="../../static/icon/icon-code.png"></image></view>
  15. <view class="login_name"><input class="uni-input" type="password" v-model="passward" focus placeholder="请输入密码" /></view>
  16. </view>
  17. <view><button type="green" class="uni-button uni-button-green" @click="toLogin">登录</button></view>
  18. <!-- <view><button type="green" class="uni-button uni-button-green uni-button-green-plain" plain="true"
  19. hover-class="none" @click="register">注册</button></view> -->
  20. <view class=" flex bombtn">
  21. <<<<<<< HEAD
  22. <navigator url="./forget">
  23. <view class="bbtn">忘记密码</view>
  24. </navigator>
  25. <!-- <view class="jg">
  26. </view>
  27. <view class="bbtn" @click="register">注册账号</view> -->
  28. =======
  29. <navigator url="./forget"><view class="bbtn">忘记密码</view></navigator>
  30. <!-- <view class="jg"></view> -->
  31. <!-- <view class="bbtn" @click="register">注册账号</view> -->
  32. >>>>>>> 7f70b33326ed3cfa9055d82f74b68a2005de68a3
  33. </view>
  34. <!-- <view class="flex other">
  35. <view class="fenge"></view>
  36. <view class="qita">其他方式登录</view>
  37. <view class="fenge"></view>
  38. </view> -->
  39. <!-- #ifndef APP-PLUS -->
  40. <!-- <view class="weixin" @click="wecahtLogin">
  41. <image src="/static/img/img05.png"></image>
  42. </view>
  43. <view class="weixin_text" @click="wecahtLogin">微信登录</view> -->
  44. <!-- #endif -->
  45. <!-- #ifdef APP-PLUS -->
  46. <!-- <block v-if="!is_ios">
  47. <view class="weixin" @click="wecahtLogin">
  48. <image src="/static/img/img05.png" mode="scaleToFill"></image>
  49. </view>
  50. <view class="weixin_text" @click="wecahtLogin">微信登录</view>
  51. </block>
  52. <block v-else>
  53. <view class="ios_login flex" @click="wecahtLogin('weixin')">
  54. <text class="iconfont iconweixin"></text>
  55. <text class="weixin_text">微信登录</text>
  56. </view>
  57. <view v-if='is_apple_login' class="ios_login flex" @click="wecahtLogin('apple')">
  58. <image class="loginIcon" src="/static/icon/appleIcon.png" mode=" scaleToFill"></image>
  59. <text class="weixin_text">通过Apple登录</text>
  60. </view>
  61. </block> -->
  62. <!-- #endif -->
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import { mapMutations } from 'vuex';
  68. import { login } from '@/api/login.js';
  69. import { getUserInfo } from '@/api/user.js';
  70. // #ifdef APP-PLUS
  71. // applelogin接口需要开发编写,基础项目中可能没有
  72. import { applelogin } from '@/api/set.js';
  73. // loginWx接口需要开发编写,基础项目中可能没有
  74. import { loginWx } from '@/api/login.js';
  75. // #endif
  76. // #ifdef H5
  77. import { loginWinxin } from '@/utils/wxAuthorized';
  78. // #endif
  79. export default {
  80. data() {
  81. return {
  82. username: '',
  83. passward: '',
  84. // #ifdef APP-PLUS
  85. is_ios: false, //判断是否为ios手机
  86. is_apple_login: false //是否有ios授权登录功能
  87. // #endif
  88. };
  89. },
  90. onLoad() {
  91. let obj = this;
  92. // #ifdef APP-PLUS
  93. let system = uni.getStorageSync('platform');
  94. // 判断是否为ios
  95. if (system == 'ios') {
  96. obj.is_ios = true;
  97. }
  98. uni.getSystemInfo({
  99. success(e) {
  100. if (+e.system.split('.')[0] >= 13) {
  101. obj.is_apple_login = true;
  102. }
  103. }
  104. });
  105. // #endif
  106. },
  107. methods: {
  108. ...mapMutations('user', ['setUserInfo', 'login']),
  109. // 微信登录
  110. wecahtLogin(type) {
  111. let obj = this;
  112. // #ifdef H5
  113. let weichatBrowser = uni.getStorageSync('weichatBrowser');
  114. if (weichatBrowser) {
  115. loginWinxin();
  116. }
  117. // #endif
  118. // #ifdef APP-PLUS
  119. uni.login({
  120. provider: type,
  121. success(e) {
  122. uni.getUserInfo({
  123. provider: type,
  124. success(es) {
  125. if (type === 'weixin') {
  126. loginWx(es.userInfo)
  127. .then(e => {
  128. uni.setStorageSync('token', e.data.token);
  129. getUserInfo({}).then(e => {
  130. obj.login();
  131. // 保存返回用户数据
  132. obj.setUserInfo(e.data);
  133. //成功跳转首页
  134. uni.switchTab({
  135. url: '/pages/index/index'
  136. });
  137. });
  138. })
  139. .catch(e => {
  140. console.log(e);
  141. uni.showModal({
  142. content: JSON.stringify(e),
  143. success() {},
  144. fail() {}
  145. });
  146. });
  147. }
  148. if (type === 'apple') {
  149. console.log(es.userInfo);
  150. applelogin({
  151. account: es.userInfo.openId
  152. })
  153. .then(function(e) {
  154. console.log(e, 'token');
  155. uni.setStorageSync('token', e.data.token);
  156. getUserInfo({}).then(e => {
  157. obj.login();
  158. // 保存返回用户数据
  159. obj.setUserInfo(e.data);
  160. //成功跳转首页
  161. uni.switchTab({
  162. url: '/pages/index/index'
  163. });
  164. });
  165. })
  166. .catch(function(e) {
  167. console.log(e);
  168. });
  169. }
  170. },
  171. fail(es) {
  172. uni.showModal({
  173. content: JSON.stringify(es),
  174. success() {
  175. // obj.login();
  176. // // 保存返回用户数据
  177. // obj.setUserInfo(e.data);
  178. // //成功跳转首页
  179. // uni.switchTab({
  180. // url: '/pages/index/index'
  181. // });
  182. }
  183. });
  184. }
  185. });
  186. },
  187. fail(e) {
  188. uni.showModal({
  189. title: '提示',
  190. content: JSON.stringify(e),
  191. showCancel: false
  192. });
  193. }
  194. });
  195. // #endif
  196. },
  197. //登录
  198. async toLogin() {
  199. let obj = this;
  200. obj.logining = true;
  201. if (obj.username == '') {
  202. obj.$api.msg('请输入手机号');
  203. return;
  204. }
  205. if (obj.passward == '') {
  206. obj.$api.msg('请输入密码');
  207. return;
  208. }
  209. login({
  210. account: obj.username,
  211. password: obj.passward
  212. })
  213. .then(function(e) {
  214. uni.setStorageSync('token', e.data.userinfo.token);
  215. // 保存返回用户数据
  216. obj.setUserInfo(e.data.userinfo);
  217. obj.$store.commit('hasLogin', true);
  218. getUserInfo({}).then(e => {
  219. obj.login();
  220. // 保存返回用户数据
  221. // obj.setUserInfo(e.data.userinfo);
  222. let ur = uni.getStorageSync('present') || '/pages/index/index';
  223. //成功跳转首页
  224. uni.switchTab({
  225. url: ur,
  226. fail(e) {
  227. uni.navigateTo({
  228. url: ur,
  229. fail(e) {
  230. uni.navigateTo({
  231. url: '/pages/index/index'
  232. });
  233. }
  234. });
  235. }
  236. });
  237. });
  238. })
  239. .catch(function(e) {
  240. console.log(e);
  241. });
  242. },
  243. //跳转注册页
  244. register() {
  245. uni.navigateTo({
  246. url: `/pages/public/register`
  247. });
  248. },
  249. // 后退
  250. navBack() {
  251. uni.navigateBack();
  252. }
  253. }
  254. };
  255. </script>
  256. <style lang="scss">
  257. /* #ifdef APP-PLUS */
  258. .ios_login {
  259. width: 260rpx;
  260. border-radius: 12rpx;
  261. justify-content: center;
  262. border: 1px solid #212121;
  263. margin: 24rpx auto;
  264. padding: 10rpx;
  265. background-color: #212121;
  266. color: #ffffff;
  267. .loginIcon {
  268. width: 50rpx;
  269. height: 50rpx;
  270. }
  271. .weixin_text {
  272. line-height: 1;
  273. margin-left: 20rpx;
  274. color: #ffffff !important;
  275. }
  276. }
  277. /* #endif */
  278. .ios_login {
  279. width: 350rpx;
  280. border-radius: 12rpx;
  281. justify-content: center;
  282. border: 1px solid #212121;
  283. margin: 24rpx auto;
  284. padding: 15rpx;
  285. background-color: #212121;
  286. color: #ffffff;
  287. font-size: 32rpx;
  288. .loginIcon {
  289. font-size: 35rpx;
  290. width: 35rpx;
  291. height: 35rpx;
  292. }
  293. .weixin_text {
  294. line-height: 1;
  295. margin-left: 20rpx;
  296. color: #ffffff !important;
  297. }
  298. }
  299. page {
  300. height: 100%;
  301. }
  302. .container {
  303. width: 100%;
  304. height: 100%;
  305. background-size: 100%;
  306. }
  307. .container_text {
  308. width: 100%;
  309. height: 500rpx;
  310. top: 0rpx;
  311. display: flex;
  312. flex-direction: column;
  313. justify-content: center;
  314. align-items: center;
  315. .banner-img {
  316. width: 100%;
  317. height: 100%;
  318. }
  319. .logo {
  320. width: 186rpx;
  321. height: 196rpx;
  322. }
  323. .logo-tit {
  324. text-align: center;
  325. font-size: 36rpx;
  326. font-family: PingFang SC;
  327. font-weight: 400;
  328. color: #fad6b0;
  329. }
  330. }
  331. .login_text {
  332. margin: auto 30rpx;
  333. position: relative;
  334. padding: 100rpx 102rpx;
  335. background-color: #000;
  336. // margin-top: -180rpx;
  337. border-radius: 20rpx;
  338. .login_input {
  339. padding-bottom: 20rpx;
  340. border-bottom: 1px solid #f0f0f0;
  341. margin-bottom: 65rpx;
  342. background-color: #000;
  343. .login_img image {
  344. height: 35rpx;
  345. width: 29rpx;
  346. margin-right: 20rpx;
  347. }
  348. .uni-input {
  349. background-color: #000;
  350. text-align: left;
  351. width: 470rpx;
  352. font-size: 28rpx !important;
  353. }
  354. .login_name {
  355. color: #fff;
  356. background-color: #000;
  357. }
  358. }
  359. .other {
  360. margin-top: 60rpx;
  361. .fenge {
  362. width: 30%;
  363. height: 2rpx;
  364. background-color: #eeeeee;
  365. }
  366. .qita {
  367. font-size: 28rpx;
  368. color: #999999;
  369. }
  370. }
  371. .weixin {
  372. width: 75rpx;
  373. height: 75rpx;
  374. margin: 25rpx auto;
  375. }
  376. .weixin image {
  377. width: 100%;
  378. height: 100%;
  379. }
  380. .weixin_text {
  381. text-align: center;
  382. font-size: 28rpx;
  383. color: #999999;
  384. }
  385. .forget {
  386. font-size: 28rpx;
  387. width: 100%;
  388. text-align: right;
  389. color: #999999;
  390. }
  391. .uni-button-green {
  392. background: linear-gradient(-74deg, #ce9c6d, #ffecd6);
  393. // border: 1px solid;
  394. border-image: linear-gradient(115deg, #feebd5, #ffffff, #e1ad7d) 1 1;
  395. box-shadow: 3rpx 4rpx 5rpx 0rpx rgba(151, 118, 74, 0.5);
  396. border-radius: 45rpx;
  397. font-size: 34rpx;
  398. font-family: PingFang SC;
  399. font-weight: 500;
  400. color: #97764a;
  401. }
  402. .uni-button-green-plain {
  403. border: 1px solid #5dbc7c;
  404. margin: 40rpx 10rpx;
  405. border-radius: 50rpx;
  406. color: #5dbc7c;
  407. background-color: #ffffff;
  408. }
  409. .uni-button {
  410. height: 85rpx;
  411. line-height: 85rpx;
  412. }
  413. }
  414. .loginTitle {
  415. position: absolute;
  416. top: 250rpx;
  417. width: 100%;
  418. text-align: center;
  419. color: white;
  420. font-size: 40rpx;
  421. }
  422. .bombtn {
  423. margin-top: 36rpx;
  424. justify-content: center;
  425. font-size: 28rpx;
  426. font-family: PingFang SC;
  427. font-weight: 500;
  428. color: #ffffff;
  429. .jg {
  430. height: 28rpx;
  431. width: 2rpx;
  432. background-color: #fff;
  433. margin: 0 10rpx;
  434. }
  435. }
  436. </style>