login.vue 11 KB

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