login.vue 10 KB

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