index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  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. // 滚动监听
  169. onPageScroll(e) {
  170. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  171. uni.$emit('scroll');
  172. if (e.scrollTop > this.domOffsetTop) {
  173. this.isScrolled = true;
  174. }
  175. if (e.scrollTop < this.domOffsetTop) {
  176. this.$nextTick(() => {
  177. this.isScrolled = false;
  178. });
  179. }
  180. },
  181. methods: {
  182. // 初始化圈层ID参数
  183. initRegionIds() {
  184. try {
  185. const areasInfo = uni.getStorageSync('areas_info') || [];
  186. if (Array.isArray(areasInfo) && areasInfo.length > 0) {
  187. // 提取所有圈层ID,用逗号分隔
  188. this.regionIds = areasInfo
  189. .filter(area => area.id) // 过滤掉没有id的项
  190. .map(area => area.id)
  191. .join(',');
  192. } else {
  193. this.regionIds = '';
  194. }
  195. } catch (error) {
  196. console.error('页面获取圈层ID失败:', error);
  197. this.regionIds = '';
  198. }
  199. },
  200. //开屏广告结束回调展示首页diy
  201. getShowIndexDiy() {
  202. this.showIndexDiy = true
  203. this.guidePages = false
  204. // uni.showTabBar();
  205. },
  206. // 获取开屏广告信息
  207. loadExecution() {
  208. const tagDate = uni.getStorageSync('guideDate') || 0,
  209. nowDate = new Date().getTime();
  210. getOpenAdvApi().then(res => {
  211. if (res.data.splashAdSwitch == 0 || res.data.adList.length == 0) {
  212. this.showIndexDiy = true
  213. // uni.switchTab({
  214. // url: '/pages/index/index'
  215. // });
  216. } else if (res.data.splashAdSwitch == 1 && res.data.adList.length) {
  217. this.advData = res.data
  218. uni.hideTabBar()
  219. // splashAdShowInterval 开屏广告展示间隔,单位:小时, splashAdShowTime:开屏广告展示时间,单位:秒, splashAdSwitch:开屏广告开关
  220. let intervalTime = parseFloat(res.data.splashAdShowInterval) * 60 * 60 * 1000 || 0;
  221. uni.setStorageSync('intervalTime', intervalTime);
  222. uni.setStorageSync('guideDate', new Date().getTime());
  223. if ((nowDate - tagDate) <= uni.getStorageSync('intervalTime')) {
  224. this.showIndexDiy = true
  225. this.guidePages = false
  226. return
  227. }
  228. this.guidePages = true
  229. } else {
  230. this.showIndexDiy = true
  231. this.guidePages = false
  232. // uni.showTabBar();
  233. }
  234. }).catch(err => {
  235. this.showIndexDiy = true
  236. })
  237. },
  238. //获取扫码或者浏览器传来的值
  239. getOptionData(options) {
  240. let diyid = 0;
  241. if (options.hasOwnProperty('id') || options.scene) {
  242. if (options.scene) { // 仅仅小程序扫码进入
  243. let value = this.$util.getUrlParams(decodeURIComponent(options.scene));
  244. if (value.sd) this.$store.commit('Change_Spread', value.sd);
  245. //分销绑定
  246. silenceBindingSpread(this.isLogin, value.sd);
  247. diyid = value.id ? value.id : 0;
  248. } else {
  249. diyid = options.id ? options.id : 0;
  250. if (options.sd) this.$store.commit('Change_Spread', options.sd);
  251. //分销绑定
  252. silenceBindingSpread(this.isLogin, options.sd);
  253. }
  254. }
  255. //diy数据加载
  256. this.getDiyData(diyid, false);
  257. },
  258. //备案授权跳转
  259. toInternet() {
  260. window.open('https://beian.miit.gov.cn/#/Integrated/index')
  261. },
  262. //app刚进入检测有无网络
  263. snycNetWork() {
  264. uni.getNetworkType({
  265. success: res => {
  266. //res.networkType === 'none'无网络
  267. this.errorNetwork = res.networkType === 'none';
  268. //如果没有网络,清除骨架屏
  269. if (this.errorNetwork) this.reloadData();
  270. }
  271. });
  272. },
  273. // 断网后重新链接
  274. reconnect() {
  275. uni.getNetworkType({
  276. success: res => {
  277. this.errorNetwork = res.networkType === 'none';
  278. if (!this.errorNetwork) {
  279. setTimeout(() => {
  280. this.$util.navigateTo('/pages/index/index');
  281. }, 1000)
  282. }
  283. }
  284. });
  285. },
  286. /**
  287. * 获取DIY
  288. * @param {number} id
  289. * @param {boolean} type 区分是否是微页面
  290. */
  291. getDiyData(id, type) {
  292. this.componentData = null
  293. this.styleConfig = []
  294. uni.showLoading({
  295. title: '加载中...'
  296. });
  297. getDiy(id).then(res => {
  298. this.errorNetwork = false;
  299. uni.setNavigationBarTitle({
  300. title: res.data.title
  301. });
  302. uni.setNavigationBarColor({
  303. //必须要16进制小写
  304. frontColor: res.data.titleColor,
  305. backgroundColor: res.data.titleBgColor.toString().toLowerCase(),
  306. })
  307. let data = res.data;
  308. this.componentData = data
  309. this.pageStyle = {
  310. 'background-color': data.isBgColor === 1 ? res.data.colorPicker : '',
  311. 'background-image': data.isBgPic === 1 ? `url(${res.data.bgPic})` : '',
  312. 'background-repeat': res.data.bgTabVal === 1 ? 'repeat-y' : 'no-repeat',
  313. 'background-size': res.data.bgTabVal === 2 ? 'cover' : 'contain'
  314. };
  315. uni.hideLoading();
  316. setTimeout(() => {
  317. this.isNodes++;
  318. }, 100);
  319. }).catch(err => {
  320. uni.hideLoading();
  321. return this.$util.Tips({
  322. title: err
  323. });
  324. });
  325. },
  326. //清除骨架屏
  327. reloadData() {
  328. this.showSkeleton = false;
  329. },
  330. xieyiApp() {
  331. uni.navigateTo({
  332. url: '/pages/users/web_page/index?webUel=https://admin.java.crmeb.net/useragreement/xieyi.html&title=协议内容'
  333. })
  334. },
  335. // #ifdef APP-PLUS
  336. xieyiApp() {
  337. uni.navigateTo({
  338. animationType: animationType.type,
  339. animationDuration: animationType.duration,
  340. url: '/pages/users/web_page/index?webUel=https://admin.java.crmeb.net/useragreement/xieyi.html&title=协议内容'
  341. })
  342. },
  343. // #endif
  344. // #ifdef MP || APP-PLUS
  345. getTemlIds() {
  346. for (var i in arrTemp) {
  347. this.getTem(arrTemp[i]);
  348. }
  349. },
  350. getTem(data) {
  351. getTemlIds({
  352. type: data
  353. }).then(res => {
  354. if (res.data) {
  355. let arr = res.data.map((item) => {
  356. return item.tempId
  357. })
  358. wx.setStorageSync('tempID' + data, arr);
  359. }
  360. });
  361. },
  362. // #endif
  363. // 首页数据
  364. getIndexConfig: function() {
  365. let that = this;
  366. getIndexData().then(res => {
  367. let imgHost = res.data.logoUrl.split('crmebimage')[0];
  368. that.imgHost = imgHost;
  369. that.$Cache.set('imgHost', imgHost + '/');
  370. // #ifdef H5 || APP-PLUS
  371. that.$store.commit("SET_CHATURL", res.data.yzfUrl);
  372. Cache.set('chatUrl', res.data.yzfUrl);
  373. // #endif
  374. Cache.setItem({
  375. name: 'platChatConfig',
  376. value: {
  377. servicePhone: res.data.consumerHotline, //客服电话
  378. serviceLink: res.data.consumerH5Url, //云智服
  379. serviceType: res.data.consumerType //客服类型四选一
  380. }
  381. });
  382. this.reloadData();
  383. }).catch(err => {
  384. return this.$util.Tips({
  385. title: err
  386. });
  387. });
  388. },
  389. appVersionConfig() {
  390. var that = this;
  391. //app升级
  392. // 获取本地应用资源版本号
  393. getAppVersion().then(res => {
  394. that.$set(that.appUpdate, 'androidAddress', res.data.androidAddress);
  395. that.$set(that.appUpdate, 'appVersion', res.data.appVersion);
  396. that.$set(that.appUpdate, 'iosAddress', res.data.iosAddress);
  397. that.$set(that.appUpdate, 'openUpgrade', res.data.openUpgrade);
  398. plus.runtime.getProperty(plus.runtime.appid, function(inf) {
  399. let nowVersion = (inf.version).split('.').join('');
  400. let appVersion = (res.data.appVersion).split('.').join('');
  401. uni.getSystemInfo({
  402. success: (res) => {
  403. if (appVersion > nowVersion) {
  404. uni.showModal({
  405. title: '更新提示',
  406. content: '发现新版本,是否前去下载?',
  407. showCancel: that.appUpdate.openUpgrade == '1' ?
  408. true : false,
  409. cancelColor: '#eeeeee',
  410. confirmColor: '#f55850',
  411. success(response) {
  412. if (response.confirm) {
  413. switch (res.platform) {
  414. case "android":
  415. plus.runtime.openURL(that
  416. .appUpdate
  417. .androidAddress);
  418. break;
  419. case "ios":
  420. plus.runtime.openURL(encodeURI(
  421. that.appUpdate
  422. .iosAddress));
  423. break;
  424. }
  425. }
  426. }
  427. });
  428. }
  429. }
  430. })
  431. });
  432. })
  433. },
  434. // 微信分享;
  435. setOpenShare: function(data) {
  436. let that = this;
  437. if (that.$wechat.isWeixin()) {
  438. let configAppMessage = {
  439. desc: this.globalData.companyName,
  440. title: this.globalData.companyName,
  441. link: location.href
  442. };
  443. that.$wechat.wechatEvevt(["updateAppMessageShareData", "updateTimelineShareData"],
  444. configAppMessage);
  445. }
  446. },
  447. stopTouchMove() {
  448. return true //禁止新闻swiper手动滑动
  449. },
  450. closeDialog() {
  451. this.couponModal = false;
  452. this.$Cache.clear('newGift');
  453. },
  454. },
  455. onHide() {
  456. this.guidePages = false
  457. // uni.showTabBar();
  458. },
  459. onReachBottom() {
  460. this.$refs.diyComponentRef.getRecommend();
  461. }
  462. }
  463. </script>
  464. <style>
  465. page {
  466. height: auto;
  467. display: flex;
  468. flex-direction: column;
  469. height: 100%;
  470. }
  471. </style>
  472. <style lang="scss" scoped>
  473. .error-network {
  474. position: fixed;
  475. left: 0;
  476. top: 0;
  477. display: flex;
  478. flex-direction: column;
  479. align-items: center;
  480. width: 100%;
  481. height: 100%;
  482. padding-top: 40rpx;
  483. background: #fff;
  484. padding-top: 30%;
  485. .img {
  486. width: 414rpx;
  487. height: 336rpx;
  488. }
  489. .title {
  490. position: relative;
  491. top: -40rpx;
  492. font-size: 32rpx;
  493. color: #666;
  494. }
  495. .con {
  496. font-size: 24rpx;
  497. color: #999;
  498. .label {
  499. margin-bottom: 20rpx;
  500. }
  501. .item {
  502. margin-bottom: 20rpx;
  503. }
  504. }
  505. .btn {
  506. display: flex;
  507. align-items: center;
  508. justify-content: center;
  509. width: 508rpx;
  510. height: 86rpx;
  511. margin-top: 100rpx;
  512. border: 1px solid #d74432;
  513. color: #e93323;
  514. font-size: 30rpx;
  515. border-radius: 120rpx;
  516. }
  517. }
  518. .ysize {
  519. background-size: 100%;
  520. }
  521. .fullsize {
  522. background-size: 100% 100%;
  523. }
  524. .repeat {
  525. background-repeat: repeat;
  526. }
  527. .noRepeat {
  528. background-repeat: no-repeat;
  529. }
  530. .noCommodity {
  531. margin-top: 30%;
  532. }
  533. .icon-gengduo1 {
  534. color: #F8F8F8;
  535. }
  536. .pageIndex {
  537. padding: 0 24rpx;
  538. }
  539. .page-index {
  540. display: flex;
  541. flex-direction: column;
  542. min-height: 100%;
  543. }
  544. .fixed {
  545. z-index: 100;
  546. position: fixed;
  547. left: 0;
  548. top: 0;
  549. background: linear-gradient(90deg, red 50%, #ff5400 100%);
  550. }
  551. .menu-txt {
  552. font-size: 24rpx;
  553. color: #454545;
  554. }
  555. </style>