index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <view :style="viewColor" class="wrapper">
  3. <view class="bag">
  4. <img :src="`${domain}/static/images/logo_bgh.png`" alt="" srcset="">
  5. </view>
  6. <view class="system-height" :style="{ height: statusBarHeight }"></view>
  7. <!-- #ifdef MP -->
  8. <view class="title-bar" style="height: 43px;">
  9. <view class="icon" @click="back" v-if="!isHome">
  10. <text class="iconfont icon-fanhui"></text>
  11. </view>
  12. <view class="icon" @click="home" v-else>
  13. <text class="iconfont icon-shouye2"></text>
  14. </view>
  15. 商城登录
  16. </view>
  17. <!-- #endif -->
  18. <view class="merchant-msg">
  19. <img :src="login_logo" />
  20. <view class="name">
  21. {{site_name}}
  22. </view>
  23. </view>
  24. <view class="wechat_login">
  25. <view class="btn-wrapper">
  26. <!-- #ifdef H5 -->
  27. <button hover-class="none" @click="wechatLogin" class="bg-theme btn1">微信登录</button>
  28. <!-- #endif -->
  29. <!-- #ifdef MP -->
  30. <template>
  31. <!--受否配置微信公众号-->
  32. <button class="bg-theme btn1" v-if="wechat_phone_switch==1 && bindPhone" open-type="getPhoneNumber"
  33. @getphonenumber="getphonenumber">授权登录</button>
  34. <button v-else class="bg-theme btn1" @click="getAuthLogin">
  35. 授权登录
  36. </button>
  37. </template>
  38. <!-- #endif -->
  39. </view>
  40. </view>
  41. <view class="protocol" v-if="!canGetPrivacySetting">
  42. <checkbox-group @click.stop='ChangeIsDefault'>
  43. <checkbox :class="inAnimation?'trembling':''" @animationend='inAnimation=false'
  44. :checked="protocol ? true : false" /> <text @click.stop='ChangeIsDefault'>已阅读并同意</text>
  45. <text class="main-color" @click.stop="privacy(4)">《用户协议》</text>
  46. 与<text class="main-color" @click.stop="privacy(3)">《隐私协议》</text>
  47. </checkbox-group>
  48. </view>
  49. <block>
  50. <editUserModal :isShow="isShow" @closeEdit="closeEdit" @editSuccess="editSuccess">
  51. </editUserModal>
  52. </block>
  53. <!-- #ifdef MP -->
  54. <privacyAgreementPopup v-if="canGetPrivacySetting" @onReject="onReject" @onAgree="onAgree">
  55. </privacyAgreementPopup>
  56. <!-- #endif -->
  57. </view>
  58. </template>
  59. <script>
  60. // +----------------------------------------------------------------------
  61. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  62. // +----------------------------------------------------------------------
  63. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  64. // +----------------------------------------------------------------------
  65. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  66. // +----------------------------------------------------------------------
  67. // | Author: CRMEB Team <admin@crmeb.com>
  68. // +----------------------------------------------------------------------
  69. const app = getApp();
  70. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  71. import editUserModal from '@/components/eidtUserModal/index.vue'
  72. import privacyAgreementPopup from '@/components/privacyAgreementPopup/index.vue'
  73. import { commonAuth } from '@/api/public';
  74. import { EXPIRES_TIME, USER_INFO } from '@/config/cache';
  75. import { getUserInfo,loginMpPhone,getAuthType } from '@/api/user.js';
  76. import Routine from '@/libs/routine';
  77. import wechat from '@/libs/wechat';
  78. import auth from '@/libs/wechat.js';
  79. import { HTTP_REQUEST_URL } from '@/config/app';
  80. import { isWeixin,configMap } from "@/utils";
  81. import Cache from '@/utils/cache';
  82. import { toLogin } from '@/libs/login.js';
  83. import { mapGetters } from "vuex";
  84. export default {
  85. data() {
  86. return {
  87. domain: HTTP_REQUEST_URL,
  88. isUp: false,
  89. canClose: true,
  90. phone: '',
  91. statusBarHeight: statusBarHeight,
  92. isHome: false,
  93. isPhoneBox: false,
  94. protocol: false,
  95. isShow: false,
  96. logoUrl: '',
  97. code: '',
  98. codeVal: "",
  99. authKey: '',
  100. options: '',
  101. userInfo: {},
  102. codeNum: 0,
  103. canUseGetUserProfile: false,
  104. canGetPrivacySetting: false,
  105. inAnimation: false,
  106. colorStatus: uni.getStorageSync('color_status'),
  107. mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false,
  108. configData: Cache.get('BASIC_CONFIG'),
  109. bindPhone: false,
  110. wechat_phone_switch: 0,
  111. };
  112. },
  113. computed:{
  114. ...configMap({login_logo:'',site_name: '',first_avatar_switch: ''}, mapGetters(['isLogin','viewColor'])),
  115. },
  116. components: {
  117. editUserModal,
  118. privacyAgreementPopup
  119. },
  120. watch:{
  121. },
  122. onLoad(options) {
  123. if (uni.getUserProfile) {
  124. this.canUseGetUserProfile = true
  125. }
  126. // #ifdef MP
  127. if (wx.getPrivacySetting) {
  128. this.canGetPrivacySetting = true
  129. }
  130. // #endif
  131. let that = this;
  132. let pages = getCurrentPages();
  133. let prePage = pages[pages.length - 2];
  134. if (prePage && prePage.route == 'pages/order_addcart/order_addcart') {
  135. this.isHome = true;
  136. } else {
  137. this.isHome = false;
  138. }
  139. },
  140. onReady(){
  141. this.getCode()
  142. },
  143. created() {
  144. // #ifdef MP
  145. if (wx.getUserProfile) {
  146. this.canUseGetUserProfile = true
  147. }
  148. // #endif
  149. },
  150. methods: {
  151. // 小程序 22.11.8日删除getUserProfile 接口获取用户昵称头像
  152. getCode() {
  153. let that = this
  154. // #ifdef MP
  155. Routine.getCode().then(code => {
  156. uni.hideLoading();
  157. that.code = code;
  158. let data = {code: code, spread: app.globalData.spid}
  159. getAuthType(data).then(res => {
  160. that.bindPhone = res.data.bindPhone
  161. that.wechat_phone_switch = res.data.wechat_phone_switch
  162. uni.setStorageSync('auth_token',res.data.key);
  163. }).catch(err => {
  164. uni.showToast({
  165. title: err,
  166. duration: 2000
  167. });
  168. });
  169. }).catch(e => {
  170. uni.hideLoading();
  171. uni.showToast({
  172. title: '登录失败',
  173. duration: 2000
  174. });
  175. })
  176. // #endif
  177. // #ifndef MP
  178. that.code = 1;
  179. // #endif
  180. },
  181. getAuthLogin() {
  182. let self = this;
  183. if(!self.protocol && !self.canGetPrivacySetting){
  184. return self.$util.Tips({
  185. title: '请勾选用户协议与隐私政策'
  186. });
  187. }
  188. uni.showLoading({
  189. title: "正在登录中"
  190. });
  191. self.canUseGetUserProfile = false;
  192. Routine.getUserProfile()
  193. .then(res => {
  194. let userInfo = res.userInfo;
  195. userInfo.code = self.code;
  196. userInfo.spread = app.globalData.spid; //获取推广人ID
  197. userInfo.spread_code = app.globalData.code; //获取推广人分享二维码ID
  198. commonAuth({
  199. auth: {
  200. type:'routine',
  201. auth: userInfo
  202. }
  203. }).then(res=>{
  204. if(res.data.status == 200){
  205. let time = res.data.result.expires_time - Cache.time();
  206. self.$store.commit('UPDATE_USERINFO', res.data.result.user);
  207. self.$store.commit('LOGIN', {token:res.data.result.token, time:time});
  208. self.$store.commit('SETUID', res.data.result.user.uid);
  209. Cache.set(EXPIRES_TIME,res.data.result.expires_time,time);
  210. Cache.set(USER_INFO,res.data.result.user,time);
  211. if(res.data.result.user.isNew && self.mp_is_new && self.first_avatar_switch==1){
  212. uni.hideLoading();
  213. self.isShow = true;
  214. }else{
  215. this.$util.Tips({
  216. title: '授权成功',
  217. icon: 'success'
  218. }, {
  219. tab: 3
  220. });
  221. }
  222. }else{
  223. uni.setStorageSync('auth_token',res.data.result.key);
  224. return uni.navigateTo({
  225. url:'/pages/users/login/index'
  226. })
  227. }
  228. }).catch(res => {
  229. uni.hideLoading();
  230. console.log('auth'+res)
  231. uni.showToast({
  232. title: res,
  233. icon: 'none',
  234. duration: 2000,
  235. });
  236. });
  237. })
  238. .catch(res => {
  239. uni.hideLoading();
  240. console.log('Routine'+res)
  241. uni.showToast({
  242. title: res.errMsg,
  243. icon: 'none',
  244. duration: 2000,
  245. });
  246. });
  247. },
  248. onAgree() {
  249. this.protocol = true
  250. },
  251. ChangeIsDefault(e) {
  252. this.$set(this, 'protocol', !this.protocol);
  253. },
  254. editSuccess() {
  255. this.isShow = false
  256. },
  257. closeEdit() {
  258. this.isShow = false
  259. this.$util.Tips({
  260. title: '登录成功',
  261. icon: 'success'
  262. }, {
  263. tab: 3
  264. });
  265. },
  266. onReject() {
  267. uni.switchTab({
  268. url: '/pages/index/index'
  269. })
  270. },
  271. // #ifdef MP
  272. back() {
  273. if (this.isLogin) {
  274. this.$store.commit('LOGIN', {
  275. token: '',
  276. time: 0
  277. });
  278. }
  279. uni.navigateBack();
  280. },
  281. // #endif
  282. // #ifndef MP
  283. back() {
  284. uni.navigateBack({
  285. delta: 1
  286. })
  287. },
  288. // #endif
  289. home() {
  290. uni.switchTab({
  291. url: '/pages/index/index'
  292. })
  293. },
  294. // 弹窗关闭
  295. maskClose(new_user) {
  296. this.isUp = false;
  297. // #ifdef MP
  298. if (new_user) {
  299. this.isShow = true
  300. }
  301. // #endif
  302. },
  303. bindPhoneClose(data) {
  304. this.isPhoneBox = false;
  305. if (data.isStatus) {
  306. // #ifdef MP
  307. this.getUserInfo(data.new_user)
  308. // #endif
  309. // #ifndef MP
  310. this.$util.Tips({
  311. title: '登录成功',
  312. icon: 'success'
  313. }, {
  314. tab: 3
  315. });
  316. // #endif
  317. }
  318. },
  319. // #ifdef MP
  320. // 小程序获取手机号码
  321. getphonenumber(e) {
  322. let that = this;
  323. if(!that.protocol && !that.canGetPrivacySetting){
  324. return that.$util.Tips({
  325. title: '请勾选用户协议与隐私政策'
  326. });
  327. }else{
  328. if(e.detail.iv){
  329. Routine.getCode().then(code => {
  330. uni.hideLoading();
  331. that.code = code;
  332. loginMpPhone({
  333. iv:e.detail.iv,
  334. encryptedData:e.detail.encryptedData,
  335. code:code,
  336. auth_token: uni.getStorageSync('auth_token'),
  337. }).then(({
  338. data
  339. }) => {
  340. const backUrl = that.$Cache.get('login_back_url') || "/pages/index/index";
  341. that.$Cache.clear('login_back_url');
  342. that.$store.commit("LOGIN", {
  343. 'token': data.token,
  344. 'time': data.exp
  345. });
  346. that.$store.commit("SETUID", data.user.uid);
  347. that.$store.commit('UPDATE_USERINFO', data.user);
  348. let method
  349. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  350. '/pages/user/index','/pages/plant_grass/index'
  351. ]
  352. if (indexPat.includes(that.getPath(backUrl))) {
  353. method = 'switchTab'
  354. } else {
  355. method = 'navigateTo'
  356. }
  357. if (that.getPath(backUrl) === '/pages/users/login/index') {
  358. uni.switchTab({
  359. url: '/pages/index/index'
  360. });
  361. return
  362. }
  363. uni[method]({
  364. url: backUrl
  365. });
  366. })
  367. .catch(res => {
  368. that.$util.Tips({
  369. title: res
  370. });
  371. });
  372. }).catch(e => {
  373. uni.hideLoading();
  374. uni.showToast({
  375. title: '登录失败',
  376. duration: 2000
  377. });
  378. })
  379. }
  380. }
  381. },
  382. // #endif
  383. getPath(url) {
  384. if (url.indexOf("?") != -1) {
  385. url = url.split("?")[0];
  386. console.log(url);
  387. }
  388. return url
  389. },
  390. /**
  391. * 获取个人用户信息
  392. */
  393. getUserInfo(new_user, back_url) {
  394. let that = this;
  395. getUserInfo().then(res => {
  396. uni.hideLoading();
  397. that.userInfo = res.data;
  398. that.$store.commit('SETUID', res.data.uid);
  399. that.$store.commit('UPDATE_USERINFO', res.data);
  400. if (new_user) {
  401. this.isShow = true
  402. } else {
  403. // #ifdef MP
  404. that.$util.Tips({
  405. title: '登录成功',
  406. icon: 'success'
  407. }, {
  408. tab: 3
  409. });
  410. // #endif
  411. // #ifndef MP
  412. that.$util.Tips({
  413. title: '登录成功',
  414. icon: 'success'
  415. }, {
  416. tab: 4,
  417. url: back_url || '/pages/user/index'
  418. });
  419. // #endif
  420. }
  421. }).catch(err => {
  422. uni.hideLoading();
  423. uni.showToast({
  424. title: err.message,
  425. icon: 'none',
  426. duration: 2000
  427. });
  428. });
  429. },
  430. privacy(type) {
  431. uni.navigateTo({
  432. url: "/pages/users/privacy/index?type=" + type
  433. })
  434. },
  435. // #ifdef H5
  436. // 公众号登录
  437. wechatLogin() {
  438. let that = this;
  439. if(!this.protocol){
  440. return this.$util.Tips({
  441. title: '请勾选用户协议与隐私政策'
  442. });
  443. }else{
  444. auth.oAuth();
  445. }
  446. },
  447. // #endif
  448. }
  449. };
  450. </script>
  451. <style lang="scss">
  452. page {
  453. background: #fff;
  454. }
  455. /deep/uni-checkbox .uni-checkbox-input,
  456. /deep/checkbox .wx-checkbox-input{
  457. border-radius: 100%;
  458. width: 28rpx;
  459. height: 28rpx;
  460. }
  461. /deep/checkbox .uni-checkbox-input.uni-checkbox-input-checked,
  462. /deep/checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  463. border: 1px solid var(--view-theme)!important;
  464. background-color: var(--view-theme)!important;
  465. }
  466. .wrapper {
  467. position: relative;
  468. height: 100vh;
  469. .bag {
  470. position: absolute;
  471. top: 0;
  472. left: 0;
  473. width: 100%;
  474. opacity: .8;
  475. z-index: -1;
  476. /* #ifdef H5 */
  477. z-index: 0;
  478. /* #endif */
  479. img {
  480. width: 100%;
  481. height: 838rpx;
  482. }
  483. }
  484. .merchant-msg {
  485. padding-top: 252rpx;
  486. display: flex;
  487. justify-content: center;
  488. align-items: center;
  489. flex-direction: column;
  490. z-index: 2;
  491. /* #ifdef H5 */
  492. position: relative;
  493. /* #endif */
  494. img {
  495. width: 152rpx;
  496. height: 152rpx;
  497. border-radius: 50%;
  498. }
  499. .name {
  500. font-size: 40rpx;
  501. font-weight: 500;
  502. color: #333333;
  503. line-height: 56rpx;
  504. margin-top: 32rpx;
  505. }
  506. }
  507. }
  508. .wechat_login {
  509. margin-top: 96rpx;
  510. .img image {
  511. width: 100%;
  512. }
  513. .btn-wrapper {
  514. padding: 0 66rpx;
  515. button {
  516. width: 100%;
  517. height: 86rpx;
  518. line-height: 86rpx;
  519. margin-bottom: 40rpx;
  520. border-radius: 120rpx;
  521. font-size: 30rpx;
  522. &.btn1 {
  523. color: #fff;
  524. background: var(--view-theme);
  525. }
  526. &.btn2 {
  527. color: #666666;
  528. border: 1px solid #DDDDDD;
  529. }
  530. }
  531. }
  532. }
  533. .title-bar {
  534. position: relative;
  535. display: flex;
  536. align-items: center;
  537. justify-content: center;
  538. font-size: 34rpx;
  539. font-weight: 500;
  540. color: #333333;
  541. line-height: 48rpx;
  542. }
  543. .icon {
  544. position: absolute;
  545. left: 30rpx;
  546. top: 0;
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. width: 80rpx;
  551. height: 80rpx;
  552. image {
  553. width: 50rpx;
  554. height: 50rpx;
  555. }
  556. }
  557. .protocol {
  558. position: fixed;
  559. bottom: 52rpx;
  560. left: 0;
  561. width: 100%;
  562. margin: 0 auto;
  563. color: #999999;
  564. font-size: 24rpx;
  565. line-height: 22rpx;
  566. text-align: center;
  567. bottom: calc(52rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  568. bottom: calc(52rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  569. .main-color {
  570. color: var(--view-theme);
  571. }
  572. .trembling {
  573. animation: shake 0.6s;
  574. }
  575. }
  576. </style>