login.vue 10 KB

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