wxLogin.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. <template>
  2. <view class="box" :class="['qn-page-' + theme]">
  3. <view class="top-bg"></view>
  4. <view class="welcome-title">
  5. <view>嗨~朋友</view>
  6. <view>欢迎使用六牛云商</view>
  7. </view>
  8. <view class="logo-img">
  9. <image src="http://image.qianniao.vip/16239218995338/35e97bca34dab476692d2ad8cc47954b/logo1024-fff.png"
  10. mode="aspectFill"></image>
  11. </view>
  12. <view class="login-bg" v-if="login_type === 1">
  13. <image src="https://onlineimg.qianniao.vip/login-img.jpg" mode="aspectFill"></image>
  14. <view class="login-btn-view">
  15. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  16. <view class="wx-Btn" @click="loginFinish">微信授权快速登录</view>
  17. <!-- #endif -->
  18. <!-- #ifdef H5 -->
  19. <view class="wx-Btn" @click="H5WXLogin">微信授权快速登录</view>
  20. <!-- #endif -->
  21. <!-- <view class="yzm-Btn" @click="login_type = 2">
  22. <text class="ibonfont ibonshouji1"></text>
  23. 短信验证登录
  24. </view> -->
  25. </view>
  26. </view>
  27. <view class="login-bg" v-if="login_type === 2">
  28. <view class="tab-ul">
  29. <view class="tab-li" @click="login_type = 1">微信快捷登录</view>
  30. <view class="tab-on">手机验证登录</view>
  31. </view>
  32. <view class="input-ul">
  33. <view class="input-li">
  34. <text class="ibonfont ibonshouji1"></text>
  35. <input type="number" placeholder-class="input-pl" v-model="mobile" placeholder="请输入手机号" />
  36. </view>
  37. <view class="input-li">
  38. <text class="ibonfont ibonyanzhengma"></text>
  39. <input type="number" placeholder-class="input-pl" v-model="smsCode" placeholder="请输入验证码" />
  40. <view class="yzm-view">获取验证码</view>
  41. </view>
  42. </view>
  43. <view class="login-btn">登录</view>
  44. <u-divider half-width="280" border-color="#eeeeee" color="#CAD0D7"><text class="divider-text">or</text>
  45. </u-divider>
  46. <view class="wx-change-btn" @click="login_type = 1">
  47. <u-icon class='wxicon' name="weixin-fill" color="#28c422" size="40"></u-icon>
  48. 微信登录
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. userInfo: {},
  58. base_set_info: {},
  59. login_type: 1,
  60. mobile: '',
  61. smsCode: '',
  62. source: 2,
  63. is_dis_yzm: false,
  64. num: 60,
  65. unionId: '',
  66. openId: '',
  67. isIosLogin: true
  68. };
  69. },
  70. onShow() {
  71. // #ifdef MP
  72. uni.hideHomeButton();
  73. // #endif
  74. },
  75. onLoad(options) {
  76. // #ifdef H5
  77. const codeindex = location.href.indexOf('code=') + 5;
  78. const stateindex = location.href.indexOf('&state');
  79. const code = location.href.substring(codeindex, stateindex);
  80. if (stateindex > -1) {
  81. this.getAccessToken(code);
  82. }
  83. // #endif
  84. if (options.loginType) {
  85. this.login_type = parseInt(options.loginType);
  86. }
  87. this.base_set_info = this.$store.state.baseSet;
  88. // #ifdef APP-PLUS
  89. const res = uni.getSystemInfoSync();
  90. if (res.platform === 'ios') {
  91. const iosAuditStatus = this.$store.state.iosAuditStatus;
  92. if (iosAuditStatus === 4) {
  93. this.goPage('/pagesT/public/login');
  94. this.isIosLogin = false;
  95. } else {
  96. this.isIosLogin = true;
  97. }
  98. }
  99. // #endif
  100. },
  101. methods: {
  102. //H5 获取accessToken
  103. getAccessToken(code) {
  104. this.$u.api
  105. .getAccessToken({
  106. code: code,
  107. type: 1
  108. })
  109. .then(res => {
  110. uni.setStorageSync('openid', res.data.openid);
  111. uni.setStorageSync('unionid', res.data.unionid);
  112. this.unionIDUserinfo(res.data.access_token, res.data.openid);
  113. });
  114. },
  115. mobileInput(e) {
  116. let val = e.detail.value;
  117. if (val.length === 3 || val.length === 8) {
  118. val += ' ';
  119. }
  120. this.$nextTick(() => {
  121. this.mobile = val;
  122. });
  123. },
  124. closePage() {
  125. if (!this.isIosLogin) {
  126. uni.navigateBack();
  127. } else {
  128. this.goPage('/pages/index/index', 'switchTab');
  129. }
  130. },
  131. // 验证码
  132. getYzm() {
  133. const mobile = this.$_utils.mobileRe(this.mobile);
  134. const re = /^1[3456789]\d{9}$/;
  135. if (!re.test(mobile)) {
  136. this.$api.msg('手机号格式不正确');
  137. return;
  138. }
  139. this.$u.api
  140. .sendMobileCode({
  141. mobile: mobile,
  142. source: 6
  143. })
  144. .then(res => {
  145. // 发送验证码
  146. this.is_dis_yzm = !this.is_dis_yzm;
  147. const secondNumIn = setInterval(() => {
  148. this.num--;
  149. if (this.num === 0) {
  150. // 清除定时器
  151. clearInterval(secondNumIn);
  152. this.is_dis_yzm = false;
  153. this.num = 60;
  154. }
  155. }, 1000);
  156. this.$api.msg('发送成功');
  157. });
  158. },
  159. yzmLogin() {
  160. const mobile = this.$_utils.mobileRe(this.mobile);
  161. this.$u.api
  162. .smsLogin({
  163. mobile: mobile,
  164. smsCode: this.smsCode,
  165. source: this.$common.source()
  166. })
  167. .then(data => {
  168. uni.setStorageSync('token', data.data.token);
  169. uni.setStorageSync('expireTime', data.data.expireTime);
  170. // this.goPage(`/pages/index/index`, 'switchTab');
  171. // 更新登录状态
  172. this.$store.commit('commit_hasLogin', true);
  173. // 验证审核
  174. this.getCustomerInfo(data.data.token);
  175. });
  176. },
  177. H5WXLogin() {
  178. // #ifdef H5
  179. window.open(
  180. `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf6aee42d157492f3&response_type=code&scope=snsapi_userinfo&redirect_uri=${encodeURIComponent(
  181. 'https://dev.qianniao.vip/H5/#/pagesT/public/wxLogin'
  182. )}&state=123#wechat_redirect`
  183. );
  184. // #endif
  185. },
  186. loginFinish() {
  187. uni.switchTab({
  188. url: '/pages/user/user'
  189. });
  190. },
  191. // WXLogin() {
  192. // uni.getProvider({
  193. // service: 'oauth',
  194. // success: res => {
  195. // //支持微信、qq和微博等
  196. // if (~res.provider.indexOf('weixin')) {
  197. // uni.showLoading();
  198. // uni.login({
  199. // provider: 'weixin',
  200. // success: loginRes => {
  201. // console.log(loginRes)
  202. // // 获取用户信息
  203. // uni.getUserInfo({
  204. // provider: 'weixin',
  205. // success: infoRes => {
  206. // this.openId = infoRes.userInfo.openId;
  207. // // 用户图像
  208. // const avator = infoRes.userInfo.avatarUrl;
  209. // uni.setStorageSync('avator', avator);
  210. // // 用户昵称
  211. // const NickName = infoRes.userInfo.nickName;
  212. // uni.setStorageSync('NickName', NickName);
  213. // uni.setStorageSync('openid', infoRes
  214. // .userInfo.openId);
  215. // if (!infoRes.userInfo.unionId) {
  216. // console.log(infoRes);
  217. // this.unionIDUserinfo(loginRes
  218. // .authResult.access_token,
  219. // infoRes.userInfo.openId);
  220. // } else {
  221. // this.unionId = infoRes.userInfo
  222. // .unionId;
  223. // uni.setStorageSync('unionid', infoRes
  224. // .userInfo.unionId);
  225. // this.checkBindMiniProgram(infoRes
  226. // .userInfo.openId, infoRes
  227. // .userInfo.unionId);
  228. // }
  229. // uni.hideLoading();
  230. // }
  231. // });
  232. // }
  233. // });
  234. // }
  235. // },
  236. // complete: () => {
  237. // // console.log('complete::getProvider');
  238. // }
  239. // });
  240. // },
  241. // App微信授权登录获取unionID
  242. unionIDUserinfo(accessToken, openid) {
  243. // console.log('微信授权登录获取::', accessToken, openid);
  244. this.$u.api
  245. .unionIDUserinfo({
  246. access_token: accessToken,
  247. openid: openid,
  248. source: this.$common.source()
  249. })
  250. .then(({
  251. data
  252. }) => {
  253. // 用户图像
  254. const avator = data.headimgurl;
  255. uni.setStorageSync('avator', avator);
  256. // 用户昵称
  257. const NickName = data.nickname;
  258. uni.setStorageSync('NickName', NickName);
  259. // #ifdef APP-PLUS || MP
  260. this.unionId = data.unionId;
  261. uni.setStorageSync('unionid', data.unionId);
  262. // #endif
  263. // #ifdef H5
  264. this.unionId = data.unionid;
  265. // #endif
  266. this.checkBindMiniProgram(openid, this.unionId);
  267. });
  268. },
  269. // 判断是否已绑定 checkBindMiniProgram
  270. checkBindMiniProgram(openid, unionid) {
  271. this.$u.api
  272. .checkBindMiniProgram({
  273. openId: openid,
  274. unionId: unionid,
  275. source: this.$common.source()
  276. })
  277. .then(data => {
  278. uni.showToast({
  279. title: '是否已绑定成功',
  280. icon: 'none',
  281. duration: 2000
  282. });
  283. // 如果返回空绑定手机
  284. if (!data.data.token) {
  285. setTimeout(() => {
  286. this.goPage(`/pagesT/binding/bindPhone`);
  287. }, 100);
  288. return;
  289. } else {
  290. const token = data.data.token;
  291. uni.setStorageSync('token', token);
  292. uni.setStorageSync('expireTime', data.data.expireTime);
  293. // 更新登录状态
  294. this.$store.commit('commit_hasLogin', true);
  295. // 否则验证审核
  296. this.getCustomerInfo(data.data.token);
  297. }
  298. });
  299. },
  300. //先获取个人资料
  301. async getCustomerInfo(token) {
  302. this.$u.api.getCustomerInfo().then(({
  303. data
  304. }) => {
  305. if (data.enableStatus === 4) {
  306. uni.clearStorageSync();
  307. uni.showModal({
  308. title: '账号已被禁用,您可以',
  309. content: '联系电话:' + (data.enterpriseMobile||''),
  310. confirmText: '联系客服',
  311. cancelText: '取消',
  312. success: res => {
  313. if (res.confirm) {
  314. uni.makePhoneCall({
  315. phoneNumber: data.enterpriseMobile
  316. });
  317. } else {
  318. }
  319. }
  320. });
  321. return;
  322. }
  323. if (data.status === 3) {
  324. // uni.clearStorageSync();
  325. // 说明资料不完善,跳转到完善资料的页面
  326. uni.showModal({
  327. title: '审核未通过,请重新修改资料',
  328. content: data.auditFailReason || '',
  329. cancelText: '联系客服',
  330. confirmText: '修改资料',
  331. success: res => {
  332. if (res.confirm) {
  333. this.goPage('/pagesT/user/editUserInfo?token=' + token);
  334. } else if (res.cancel) {
  335. uni.makePhoneCall({
  336. phoneNumber: data.enterpriseMobile
  337. });
  338. }
  339. }
  340. });
  341. } else if (data.status === 1) {
  342. // uni.clearStorageSync();
  343. uni.showModal({
  344. title: '账号正在审核中,您可以',
  345. content: '联系电话:' + (data.enterpriseMobile||''),
  346. confirmText: '先去逛逛',
  347. cancelText: '联系客服',
  348. success: res => {
  349. if (res.confirm) {
  350. this.goPage('/pages/index/index', 'switchTab');
  351. } else {
  352. uni.makePhoneCall({
  353. phoneNumber: data.enterpriseMobile
  354. });
  355. }
  356. }
  357. });
  358. } else {
  359. // this.$emit('loginSuccess');
  360. this.goPage(`/pages/index/index`, 'switchTab');
  361. }
  362. });
  363. }
  364. }
  365. };
  366. </script>
  367. <style>
  368. /* page不能写带scope的style标签中,否则无效 */
  369. page {
  370. background: #ffffff;
  371. }
  372. .input-pl {
  373. color: #b8c0c8 !important;
  374. }
  375. </style>
  376. <style lang="scss" scoped>
  377. .box {
  378. .top-bg {
  379. width: 385rpx;
  380. height: 385rpx;
  381. background: linear-gradient(315deg, #fa6400 6%, #b620e0 49%, #32c5ff 88%);
  382. opacity: 0.08;
  383. filter: blur(50px);
  384. position: fixed;
  385. top: 20rpx;
  386. left: 0;
  387. z-index: 0;
  388. }
  389. .welcome-title {
  390. position: fixed;
  391. top: 162rpx;
  392. left: 56rpx;
  393. font-weight: bold;
  394. z-index: 1;
  395. line-height: 80rpx;
  396. font-size: 46rpx;
  397. font-family: jiangxikaiti;
  398. }
  399. .logo-img {
  400. position: fixed;
  401. top: 150rpx;
  402. right: 56rpx;
  403. image {
  404. width: 120rpx;
  405. border-radius: 34rpx;
  406. height: 120rpx;
  407. display: block;
  408. box-shadow: 0px 0px 20rpx 8rpx rgba(250, 100, 0, 0.08);
  409. }
  410. }
  411. .login-bg {
  412. position: fixed;
  413. top: 370rpx;
  414. left: 0;
  415. width: 100%;
  416. image {
  417. width: 360rpx;
  418. height: 360rpx;
  419. display: block;
  420. margin: 0 auto;
  421. }
  422. .login-btn-view {
  423. width: 638rpx;
  424. margin: 0 auto;
  425. .wx-Btn {
  426. margin-top: 106rpx;
  427. width: 638rpx;
  428. height: 89rpx;
  429. background: #fa6400;
  430. border-radius: 11rpx;
  431. line-height: 89rpx;
  432. text-align: center;
  433. font-weight: 500;
  434. color: #ffffff;
  435. }
  436. .yzm-Btn {
  437. margin-top: 40rpx;
  438. text-align: center;
  439. width: 638rpx;
  440. height: 80rpx;
  441. line-height: 80rpx;
  442. border-radius: 11rpx;
  443. border: 1px solid #cad0d7;
  444. color: #2d405e;
  445. font-size: 26rpx;
  446. .ibonshouji1 {
  447. font-size: 26rpx;
  448. margin-right: 14rpx;
  449. }
  450. }
  451. }
  452. .tab-ul {
  453. display: flex;
  454. padding: 0 56rpx;
  455. .tab-li {
  456. width: 328rpx;
  457. height: 88rpx;
  458. line-height: 88rpx;
  459. border-radius: 16rpx;
  460. color: #fa6400;
  461. text-align: center;
  462. background: linear-gradient(-62deg, transparent 32rpx, rgba(250, 100, 0, 0.08) 0) top right;
  463. background-size: 100% 100%;
  464. background-repeat: no-repeat;
  465. margin-right: 40rpx;
  466. }
  467. .tab-on {
  468. width: 328rpx;
  469. height: 88rpx;
  470. line-height: 88rpx;
  471. border-radius: 16rpx;
  472. text-align: center;
  473. color: #ffffff;
  474. font-weight: 500;
  475. background: linear-gradient(117deg, transparent 32rpx, #fa6400 0) top left;
  476. background-size: 100% 100%;
  477. background-repeat: no-repeat;
  478. margin-left: -25px;
  479. }
  480. }
  481. .input-ul {
  482. padding: 16rpx 0;
  483. .input-li {
  484. color: #2d405e;
  485. width: 638rpx;
  486. margin: 40rpx auto;
  487. height: 80rpx;
  488. background: #f5f5f6;
  489. border-radius: 4rpx;
  490. position: relative;
  491. padding-left: 88rpx;
  492. .ibonfont {
  493. position: absolute;
  494. font-size: 40rpx;
  495. top: 50%;
  496. transform: translateY(-50%);
  497. left: 24rpx;
  498. }
  499. input {
  500. color: #2d405e;
  501. height: 80rpx;
  502. line-height: 80rpx;
  503. width: 400rpx;
  504. }
  505. .yzm-view {
  506. position: absolute;
  507. top: 50%;
  508. transform: translateY(-50%);
  509. right: 32rpx;
  510. color: #fa6400;
  511. }
  512. }
  513. }
  514. .login-btn {
  515. margin: 0 auto 170rpx;
  516. width: 638rpx;
  517. height: 89rpx;
  518. background: #fa6400;
  519. border-radius: 11rpx;
  520. line-height: 89rpx;
  521. text-align: center;
  522. font-weight: 500;
  523. color: #ffffff;
  524. }
  525. .divider-text {
  526. margin: 0 27rpx;
  527. }
  528. .wx-change-btn {
  529. color: #2d405e;
  530. margin: 50rpx auto 0;
  531. width: 638rpx;
  532. font-size: 26rpx;
  533. height: 80rpx;
  534. border-radius: 11rpx;
  535. line-height: 80rpx;
  536. text-align: center;
  537. border: 1px solid #cad0d7;
  538. .wxicon {
  539. vertical-align: middle;
  540. margin-right: 10rpx;
  541. }
  542. }
  543. }
  544. }
  545. </style>