login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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.token);
  227. obj.$store.commit('hasLogin', true);
  228. getUserInfo({}).then(e => {
  229. obj.login();
  230. // 保存返回用户数据
  231. obj.setUserInfo(e.data);
  232. let ur = uni.getStorageSync('present') || '/pages/index/index';
  233. //成功跳转首页
  234. uni.switchTab({
  235. url: ur,
  236. fail(e) {
  237. uni.navigateTo({
  238. url: ur,
  239. fail(e) {
  240. uni.navigateTo({
  241. url: '/pages/index/index',
  242. });
  243. }
  244. });
  245. }
  246. });
  247. });
  248. })
  249. .catch(function(e) {
  250. console.log(e);
  251. });
  252. },
  253. //跳转注册页
  254. register() {
  255. uni.navigateTo({
  256. url: `/pages/public/register`
  257. });
  258. },
  259. // 后退
  260. navBack() {
  261. uni.navigateBack();
  262. }
  263. }
  264. };
  265. </script>
  266. <style lang="scss">
  267. /* #ifdef APP-PLUS */
  268. .ios_login {
  269. width: 260rpx;
  270. border-radius: 12rpx;
  271. justify-content: center;
  272. border: 1px solid #212121;
  273. margin: 24rpx auto;
  274. padding: 10rpx;
  275. background-color: #212121;
  276. color: #ffffff;
  277. .loginIcon {
  278. width: 50rpx;
  279. height: 50rpx;
  280. }
  281. .weixin_text {
  282. line-height: 1;
  283. margin-left: 20rpx;
  284. color: #ffffff !important;
  285. }
  286. }
  287. /* #endif */
  288. .ios_login {
  289. width: 350rpx;
  290. border-radius: 12rpx;
  291. justify-content: center;
  292. border: 1px solid #212121;
  293. margin: 24rpx auto;
  294. padding: 15rpx;
  295. background-color: #212121;
  296. color: #ffffff;
  297. font-size: 32rpx;
  298. .loginIcon {
  299. font-size: 35rpx;
  300. width: 35rpx;
  301. height: 35rpx;
  302. }
  303. .weixin_text {
  304. line-height: 1;
  305. margin-left: 20rpx;
  306. color: #ffffff !important;
  307. }
  308. }
  309. page {
  310. height: 100%;
  311. }
  312. .container {
  313. width: 100%;
  314. height: 100%;
  315. background-size: 100%;
  316. }
  317. .container_text {
  318. width: 100%;
  319. height: 500rpx;
  320. top: 0rpx;
  321. display: flex;
  322. flex-direction: column;
  323. justify-content: center;
  324. align-items: center;
  325. .banner-img {
  326. width: 100%;
  327. height: 100%;
  328. }
  329. .logo {
  330. width: 186rpx;
  331. height: 196rpx;
  332. }
  333. .logo-tit {
  334. text-align: center;
  335. font-size: 36rpx;
  336. font-family: PingFang SC;
  337. font-weight: 400;
  338. color: #FAD6B0;
  339. }
  340. }
  341. .login_text {
  342. margin: auto 30rpx;
  343. position: relative;
  344. padding: 100rpx 102rpx;
  345. background-color: #000;
  346. // margin-top: -180rpx;
  347. border-radius: 20rpx;
  348. .login_input {
  349. padding-bottom: 20rpx;
  350. border-bottom: 1px solid #f0f0f0;
  351. margin-bottom: 65rpx;
  352. background-color: #000;
  353. .login_img image {
  354. height: 35rpx;
  355. width: 29rpx;
  356. margin-right: 20rpx;
  357. }
  358. .uni-input {
  359. background-color: #000;
  360. text-align: left;
  361. width: 470rpx;
  362. font-size: 28rpx !important;
  363. }
  364. .login_name {
  365. color: #fff;
  366. background-color: #000;
  367. }
  368. }
  369. .other {
  370. margin-top: 60rpx;
  371. .fenge {
  372. width: 30%;
  373. height: 2rpx;
  374. background-color: #eeeeee;
  375. }
  376. .qita {
  377. font-size: 28rpx;
  378. color: #999999;
  379. }
  380. }
  381. .weixin {
  382. width: 75rpx;
  383. height: 75rpx;
  384. margin: 25rpx auto;
  385. }
  386. .weixin image {
  387. width: 100%;
  388. height: 100%;
  389. }
  390. .weixin_text {
  391. text-align: center;
  392. font-size: 28rpx;
  393. color: #999999;
  394. }
  395. .forget {
  396. font-size: 28rpx;
  397. width: 100%;
  398. text-align: right;
  399. color: #999999;
  400. }
  401. .uni-button-green {
  402. background: linear-gradient(-74deg, #CE9C6D, #FFECD6);
  403. // border: 1px solid;
  404. border-image: linear-gradient(115deg, #FEEBD5, #FFFFFF, #E1AD7D) 1 1;
  405. box-shadow: 3rpx 4rpx 5rpx 0rpx rgba(151, 118, 74, 0.5);
  406. border-radius: 45rpx;
  407. font-size: 34rpx;
  408. font-family: PingFang SC;
  409. font-weight: 500;
  410. color: #97764A;
  411. }
  412. .uni-button-green-plain {
  413. border: 1px solid #5dbc7c;
  414. margin: 40rpx 10rpx;
  415. border-radius: 50rpx;
  416. color: #5dbc7c;
  417. background-color: #ffffff;
  418. }
  419. .uni-button {
  420. height: 85rpx;
  421. line-height: 85rpx;
  422. }
  423. }
  424. .loginTitle {
  425. position: absolute;
  426. top: 250rpx;
  427. width: 100%;
  428. text-align: center;
  429. color: white;
  430. font-size: 40rpx;
  431. }
  432. .bombtn {
  433. margin-top: 36rpx;
  434. justify-content: center;
  435. font-size: 28rpx;
  436. font-family: PingFang SC;
  437. font-weight: 500;
  438. color: #FFFFFF;
  439. .jg {
  440. height: 28rpx;
  441. width: 2rpx;
  442. background-color: #fff;
  443. margin: 0 10rpx;
  444. }
  445. }
  446. </style>