login.vue 11 KB

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