index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <template>
  2. <view id="home" :data-theme="theme" :style="[pageStyle]">
  3. <tui-skeleton v-if="showSkeleton"></tui-skeleton>
  4. <!-- 有网内容-->
  5. <view v-if="!errorNetwork">
  6. <!-- 开屏广告 -->
  7. <advertisement v-if="isShowGuide" :advData="advData" @getShowIndexDiy="getShowIndexDiy">
  8. </advertisement>
  9. <!-- diy -->
  10. <view v-if="showIndexDiy" class="page-index tui-skeleton page_count 70ba6a" :class="{'bgf':navIndex >0}"
  11. :style="{visibility: showSkeleton ? 'hidden' : 'visible'}">
  12. <diy-component ref="diyComponentRef" :regionIds="regionIds" :isScrolled="isScrolled"
  13. :componentData="componentData" v-if="componentData && componentData.value" @getDiyData="getDiyData"></diy-component>
  14. </view>
  15. </view>
  16. <!-- 断网内容 -->
  17. <view v-else>
  18. <view class="error-network af90db">
  19. <image class="img" src="./error-network.png"></image>
  20. <view class="title">网络连接断开</view>
  21. <view class="con">
  22. <view class="label">请检查情况:</view>
  23. <view class="item">· 在设置中是否已开启网络权限</view>
  24. <view class="item">· 当前是否处于弱网环境</view>
  25. <view class="item">· 版本是否过低,升级试试吧</view>
  26. </view>
  27. <view class="btn" @click="reconnect">重新连接</view>
  28. </view>
  29. </view>
  30. <!-- 备案号、授权信息 -->
  31. <!-- #ifdef H5 -->
  32. <!-- <view v-show="(globalData.authorizeFilingNum || globalData.authorizeInfo) && !isShowGuide"
  33. class="mt-40 mb-40rpx">
  34. <view @click="toInternet" class="text-center text-24rpx text--w111-666 mb-24 3cfea756">
  35. {{globalData.authorizeFilingNum}}
  36. </view>
  37. <view class="text-center text-24rpx text--w111-666 48bfb4a">{{globalData.authorizeInfo}}</view>
  38. </view> -->
  39. <!-- #endif -->
  40. <!-- 底部导航距离,做兼容处理的-->
  41. <view v-if="bottomNavigationIsCustom && !isShowGuide" class="footerBottom"></view>
  42. <pageFooter v-show="!isShowGuide" :guidePages="guidePages"></pageFooter>
  43. <!-- 优惠券弹窗 -->
  44. <coupon-dialog :urlDomain="urlDomain" v-if="couponModal" :couponModal="couponModal"
  45. @on-close="closeDialog"></coupon-dialog>
  46. </view>
  47. </template>
  48. <script>
  49. // +----------------------------------------------------------------------
  50. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  51. // +----------------------------------------------------------------------
  52. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  53. // +----------------------------------------------------------------------
  54. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  55. // +----------------------------------------------------------------------
  56. // | Author: CRMEB Team <admin@crmeb.com>
  57. // +----------------------------------------------------------------------
  58. import Cache from '../../utils/cache';
  59. import advertisement from '../guide/guide.vue'
  60. import tuiSkeleton from '@/components/base/tui-skeleton.vue';
  61. import pageFooter from '@/components/pageFooter/index.vue';
  62. import {
  63. getIndexData,
  64. getAppVersion,
  65. getCategoryThird,
  66. getDiy,
  67. getOpenAdvApi
  68. } from '@/api/api.js';
  69. // #ifdef MP-WEIXIN || APP-PLUS
  70. import {
  71. getTemlIds
  72. } from '@/api/api.js';
  73. // #endif
  74. import {
  75. mapGetters
  76. } from "vuex";
  77. import {
  78. silenceBindingSpread,
  79. } from '@/utils/index.js';
  80. import animationType from '@/utils/animationType.js'
  81. import onShare from "@/mixins/onShare";
  82. import diyComponent from "@//components/homeIndex/diyComponent";
  83. const arrTemp = ["beforePay", "afterPay", "createBargain", "pink"];
  84. let app = getApp();
  85. export default {
  86. mixins: [onShare],
  87. computed: {
  88. ...mapGetters(['isLogin', 'uid', 'globalData', 'bottomNavigationIsCustom', 'isAdvertisement']),
  89. isShowGuide() {
  90. return this.guidePages && this.isAdvertisement
  91. }
  92. },
  93. components: {
  94. tuiSkeleton,
  95. diyComponent,
  96. pageFooter,
  97. advertisement
  98. },
  99. data() {
  100. return {
  101. urlDomain: this.$Cache.get("imgHost"),
  102. isScrolled: false, //是否开始滚动
  103. showSkeleton: true, //骨架屏显示隐藏
  104. isNodes: 0, //控制什么时候开始抓取元素节点,只要数值改变就重新抓取
  105. navIndex: 0, //判断首页显示内容,1显示分类页和商品,0首页
  106. theme: app.globalData.theme,
  107. imgHost: '', //图片域名地址
  108. appUpdate: {},
  109. domOffsetTop: 50,
  110. couponModal: false,
  111. styleConfig: [], //DIY数据
  112. pageStyle: {},
  113. errorNetwork: false, //是否有网络
  114. guidePages: false, //是否展示开屏广告
  115. advData: [],
  116. showIndexDiy: false, //首页diy内容
  117. regionIds: '', // 圈层ID集合,逗号分隔,传递给goodList组件
  118. componentData: {}
  119. }
  120. },
  121. //下拉刷新
  122. onPullDownRefresh() {
  123. // #ifdef APP-PLUS
  124. setTimeout(() => {
  125. this.$util.navigateTo('/pages/index/index');
  126. uni.stopPullDownRefresh();
  127. }, 1000)
  128. // #endif
  129. },
  130. onLoad(options) {
  131. if (!this.isAdvertisement) this.showIndexDiy = true
  132. this.loadExecution()
  133. // #ifdef APP-PLUS
  134. //app刚进入检测有无网络
  135. this.snycNetWork();
  136. //APP版本检测
  137. this.appVersionConfig();
  138. // #endif
  139. //获取浏览器id
  140. this.getOptionData(options)
  141. //初始化圈层ID
  142. this.initRegionIds();
  143. //首页数据加载
  144. this.getIndexConfig();
  145. // #ifdef MP || APP-PLUS
  146. this.getTemlIds()
  147. // #endif
  148. },
  149. onShow() {
  150. // 更新圈层ID(从圈层选择页面返回时)
  151. this.initRegionIds();
  152. // 通知组件位置可能已变化
  153. this.$nextTick(() => {
  154. uni.$emit('locationChanged');
  155. });
  156. let self = this;
  157. // #ifdef APP-PLUS
  158. setTimeout(() => {
  159. if (self.appUpdate.openUpgrade == 'true') {
  160. self.appVersionConfig();
  161. }
  162. }, 1000)
  163. // #endif
  164. //新人礼的展示判断
  165. let newGift = self.$Cache.get('newGift') ? JSON.parse(self.$Cache.get('newGift')) : [];
  166. self.couponModal = newGift.length ? true : false;
  167. // 恢复滚动条位置(使用缓存方案)
  168. let scrollTop = uni.getStorageSync('index_scroll_top');
  169. if (scrollTop > 0) {
  170. this.$nextTick(() => {
  171. setTimeout(() => {
  172. uni.pageScrollTo({
  173. scrollTop: parseInt(scrollTop),
  174. duration: 0
  175. });
  176. }, 200); // 给一定的延迟等待列表渲染
  177. });
  178. }
  179. },
  180. // 滚动监听
  181. onPageScroll(e) {
  182. uni.setStorageSync('index_scroll_top', e.scrollTop);
  183. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  184. uni.$emit('scroll');
  185. if (e.scrollTop > this.domOffsetTop) {
  186. this.isScrolled = true;
  187. }
  188. if (e.scrollTop < this.domOffsetTop) {
  189. this.$nextTick(() => {
  190. this.isScrolled = false;
  191. });
  192. }
  193. },
  194. methods: {
  195. // 初始化圈层ID参数
  196. initRegionIds() {
  197. try {
  198. const areasInfo = uni.getStorageSync('areas_info') || [];
  199. if (Array.isArray(areasInfo) && areasInfo.length > 0) {
  200. // 提取所有圈层ID,用逗号分隔
  201. this.regionIds = areasInfo
  202. .filter(area => area.id) // 过滤掉没有id的项
  203. .map(area => area.id)
  204. .join(',');
  205. } else {
  206. this.regionIds = '';
  207. }
  208. } catch (error) {
  209. console.error('页面获取圈层ID失败:', error);
  210. this.regionIds = '';
  211. }
  212. },
  213. //开屏广告结束回调展示首页diy
  214. getShowIndexDiy() {
  215. this.showIndexDiy = true
  216. this.guidePages = false
  217. // uni.showTabBar();
  218. },
  219. // 获取开屏广告信息
  220. loadExecution() {
  221. const tagDate = uni.getStorageSync('guideDate') || 0,
  222. nowDate = new Date().getTime();
  223. getOpenAdvApi().then(res => {
  224. if (res.data.splashAdSwitch == 0 || res.data.adList.length == 0) {
  225. this.showIndexDiy = true
  226. // uni.switchTab({
  227. // url: '/pages/index/index'
  228. // });
  229. } else if (res.data.splashAdSwitch == 1 && res.data.adList.length) {
  230. this.advData = res.data
  231. uni.hideTabBar()
  232. // splashAdShowInterval 开屏广告展示间隔,单位:小时, splashAdShowTime:开屏广告展示时间,单位:秒, splashAdSwitch:开屏广告开关
  233. let intervalTime = parseFloat(res.data.splashAdShowInterval) * 60 * 60 * 1000 || 0;
  234. uni.setStorageSync('intervalTime', intervalTime);
  235. uni.setStorageSync('guideDate', new Date().getTime());
  236. if ((nowDate - tagDate) <= uni.getStorageSync('intervalTime')) {
  237. this.showIndexDiy = true
  238. this.guidePages = false
  239. return
  240. }
  241. this.guidePages = true
  242. } else {
  243. this.showIndexDiy = true
  244. this.guidePages = false
  245. // uni.showTabBar();
  246. }
  247. }).catch(err => {
  248. this.showIndexDiy = true
  249. })
  250. },
  251. //获取扫码或者浏览器传来的值
  252. getOptionData(options) {
  253. let diyid = 0;
  254. if (options.hasOwnProperty('id') || options.scene) {
  255. if (options.scene) { // 仅仅小程序扫码进入
  256. let value = this.$util.getUrlParams(decodeURIComponent(options.scene));
  257. if (value.sd) this.$store.commit('Change_Spread', value.sd);
  258. //分销绑定
  259. silenceBindingSpread(this.isLogin, value.sd);
  260. diyid = value.id ? value.id : 0;
  261. } else {
  262. diyid = options.id ? options.id : 0;
  263. if (options.sd) this.$store.commit('Change_Spread', options.sd);
  264. //分销绑定
  265. silenceBindingSpread(this.isLogin, options.sd);
  266. }
  267. }
  268. //diy数据加载
  269. this.getDiyData(diyid, false);
  270. },
  271. //备案授权跳转
  272. toInternet() {
  273. window.open('https://beian.miit.gov.cn/#/Integrated/index')
  274. },
  275. //app刚进入检测有无网络
  276. snycNetWork() {
  277. uni.getNetworkType({
  278. success: res => {
  279. //res.networkType === 'none'无网络
  280. this.errorNetwork = res.networkType === 'none';
  281. //如果没有网络,清除骨架屏
  282. if (this.errorNetwork) this.reloadData();
  283. }
  284. });
  285. },
  286. // 断网后重新链接
  287. reconnect() {
  288. uni.getNetworkType({
  289. success: res => {
  290. this.errorNetwork = res.networkType === 'none';
  291. if (!this.errorNetwork) {
  292. setTimeout(() => {
  293. this.$util.navigateTo('/pages/index/index');
  294. }, 1000)
  295. }
  296. }
  297. });
  298. },
  299. /**
  300. * 获取DIY
  301. * @param {number} id
  302. * @param {boolean} type 区分是否是微页面
  303. */
  304. getDiyData(id, type) {
  305. this.componentData = null
  306. this.styleConfig = []
  307. uni.showLoading({
  308. title: '加载中...'
  309. });
  310. getDiy(id).then(res => {
  311. this.errorNetwork = false;
  312. uni.setNavigationBarTitle({
  313. title: res.data.title
  314. });
  315. uni.setNavigationBarColor({
  316. //必须要16进制小写
  317. frontColor: res.data.titleColor,
  318. backgroundColor: res.data.titleBgColor.toString().toLowerCase(),
  319. })
  320. let data = res.data;
  321. this.componentData = data
  322. this.pageStyle = {
  323. 'background-color': data.isBgColor === 1 ? res.data.colorPicker : '',
  324. 'background-image': data.isBgPic === 1 ? `url(${res.data.bgPic})` : '',
  325. 'background-repeat': res.data.bgTabVal === 1 ? 'repeat-y' : 'no-repeat',
  326. 'background-size': res.data.bgTabVal === 2 ? 'cover' : 'contain'
  327. };
  328. uni.hideLoading();
  329. setTimeout(() => {
  330. this.isNodes++;
  331. }, 100);
  332. }).catch(err => {
  333. uni.hideLoading();
  334. return this.$util.Tips({
  335. title: err
  336. });
  337. });
  338. },
  339. //清除骨架屏
  340. reloadData() {
  341. this.showSkeleton = false;
  342. },
  343. xieyiApp() {
  344. uni.navigateTo({
  345. url: '/pages/users/web_page/index?webUel=https://admin.java.crmeb.net/useragreement/xieyi.html&title=协议内容'
  346. })
  347. },
  348. // #ifdef APP-PLUS
  349. xieyiApp() {
  350. uni.navigateTo({
  351. animationType: animationType.type,
  352. animationDuration: animationType.duration,
  353. url: '/pages/users/web_page/index?webUel=https://admin.java.crmeb.net/useragreement/xieyi.html&title=协议内容'
  354. })
  355. },
  356. // #endif
  357. // #ifdef MP || APP-PLUS
  358. getTemlIds() {
  359. for (var i in arrTemp) {
  360. this.getTem(arrTemp[i]);
  361. }
  362. },
  363. getTem(data) {
  364. getTemlIds({
  365. type: data
  366. }).then(res => {
  367. if (res.data) {
  368. let arr = res.data.map((item) => {
  369. return item.tempId
  370. })
  371. wx.setStorageSync('tempID' + data, arr);
  372. }
  373. });
  374. },
  375. // #endif
  376. // 首页数据
  377. getIndexConfig: function() {
  378. let that = this;
  379. getIndexData().then(res => {
  380. let imgHost = res.data.logoUrl.split('crmebimage')[0];
  381. that.imgHost = imgHost;
  382. that.$Cache.set('imgHost', imgHost + '/');
  383. // #ifdef H5 || APP-PLUS
  384. that.$store.commit("SET_CHATURL", res.data.yzfUrl);
  385. Cache.set('chatUrl', res.data.yzfUrl);
  386. // #endif
  387. Cache.setItem({
  388. name: 'platChatConfig',
  389. value: {
  390. servicePhone: res.data.consumerHotline, //客服电话
  391. serviceLink: res.data.consumerH5Url, //云智服
  392. serviceType: res.data.consumerType //客服类型四选一
  393. }
  394. });
  395. this.reloadData();
  396. }).catch(err => {
  397. return this.$util.Tips({
  398. title: err
  399. });
  400. });
  401. },
  402. appVersionConfig() {
  403. var that = this;
  404. //app升级
  405. // 获取本地应用资源版本号
  406. getAppVersion().then(res => {
  407. that.$set(that.appUpdate, 'androidAddress', res.data.androidAddress);
  408. that.$set(that.appUpdate, 'appVersion', res.data.appVersion);
  409. that.$set(that.appUpdate, 'iosAddress', res.data.iosAddress);
  410. that.$set(that.appUpdate, 'openUpgrade', res.data.openUpgrade);
  411. plus.runtime.getProperty(plus.runtime.appid, function(inf) {
  412. let nowVersion = (inf.version).split('.').join('');
  413. let appVersion = (res.data.appVersion).split('.').join('');
  414. uni.getSystemInfo({
  415. success: (res) => {
  416. if (appVersion > nowVersion) {
  417. uni.showModal({
  418. title: '更新提示',
  419. content: '发现新版本,是否前去下载?',
  420. showCancel: that.appUpdate.openUpgrade == '1' ?
  421. true : false,
  422. cancelColor: '#eeeeee',
  423. confirmColor: '#f55850',
  424. success(response) {
  425. if (response.confirm) {
  426. switch (res.platform) {
  427. case "android":
  428. plus.runtime.openURL(that
  429. .appUpdate
  430. .androidAddress);
  431. break;
  432. case "ios":
  433. plus.runtime.openURL(encodeURI(
  434. that.appUpdate
  435. .iosAddress));
  436. break;
  437. }
  438. }
  439. }
  440. });
  441. }
  442. }
  443. })
  444. });
  445. })
  446. },
  447. // 微信分享;
  448. setOpenShare: function(data) {
  449. let that = this;
  450. if (that.$wechat.isWeixin()) {
  451. let configAppMessage = {
  452. desc: this.globalData.companyName,
  453. title: this.globalData.companyName,
  454. link: location.href
  455. };
  456. that.$wechat.wechatEvevt(["updateAppMessageShareData", "updateTimelineShareData"],
  457. configAppMessage);
  458. }
  459. },
  460. stopTouchMove() {
  461. return true //禁止新闻swiper手动滑动
  462. },
  463. closeDialog() {
  464. this.couponModal = false;
  465. this.$Cache.clear('newGift');
  466. },
  467. },
  468. onHide() {
  469. this.guidePages = false
  470. // uni.showTabBar();
  471. },
  472. onReachBottom() {
  473. this.$refs.diyComponentRef.getRecommend();
  474. }
  475. }
  476. </script>
  477. <style>
  478. page {
  479. height: auto;
  480. display: flex;
  481. flex-direction: column;
  482. height: 100%;
  483. }
  484. </style>
  485. <style lang="scss" scoped>
  486. .error-network {
  487. position: fixed;
  488. left: 0;
  489. top: 0;
  490. display: flex;
  491. flex-direction: column;
  492. align-items: center;
  493. width: 100%;
  494. height: 100%;
  495. padding-top: 40rpx;
  496. background: #fff;
  497. padding-top: 30%;
  498. .img {
  499. width: 414rpx;
  500. height: 336rpx;
  501. }
  502. .title {
  503. position: relative;
  504. top: -40rpx;
  505. font-size: 32rpx;
  506. color: #666;
  507. }
  508. .con {
  509. font-size: 24rpx;
  510. color: #999;
  511. .label {
  512. margin-bottom: 20rpx;
  513. }
  514. .item {
  515. margin-bottom: 20rpx;
  516. }
  517. }
  518. .btn {
  519. display: flex;
  520. align-items: center;
  521. justify-content: center;
  522. width: 508rpx;
  523. height: 86rpx;
  524. margin-top: 100rpx;
  525. border: 1px solid #d74432;
  526. color: #e93323;
  527. font-size: 30rpx;
  528. border-radius: 120rpx;
  529. }
  530. }
  531. .ysize {
  532. background-size: 100%;
  533. }
  534. .fullsize {
  535. background-size: 100% 100%;
  536. }
  537. .repeat {
  538. background-repeat: repeat;
  539. }
  540. .noRepeat {
  541. background-repeat: no-repeat;
  542. }
  543. .noCommodity {
  544. margin-top: 30%;
  545. }
  546. .icon-gengduo1 {
  547. color: #F8F8F8;
  548. }
  549. .pageIndex {
  550. padding: 0 24rpx;
  551. }
  552. .page-index {
  553. display: flex;
  554. flex-direction: column;
  555. min-height: 100%;
  556. }
  557. .fixed {
  558. z-index: 100;
  559. position: fixed;
  560. left: 0;
  561. top: 0;
  562. background: linear-gradient(90deg, red 50%, #ff5400 100%);
  563. }
  564. .menu-txt {
  565. font-size: 24rpx;
  566. color: #454545;
  567. }
  568. </style>