index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view v-if="template">
  3. <s-layout title="首页" navbar="custom" tabbar="/pages/index/index" :bgStyle="template.page"
  4. :navbarStyle="template.style?.navbar" onShareAppMessage>
  5. <s-block v-for="(item, index) in template.components" :key="index" :styles="item.property.style">
  6. <s-block-item :type="item.id" :data="item.property" :styles="item.property.style" />
  7. </s-block>
  8. <!-- 广告模块 -->
  9. <s-popup-image />
  10. </s-layout>
  11. </view>
  12. </template>
  13. <script setup>
  14. import {
  15. computed
  16. } from 'vue';
  17. import {
  18. onLoad,
  19. onPageScroll,
  20. onPullDownRefresh
  21. } from '@dcloudio/uni-app';
  22. import sheep from '@/sheep';
  23. import $share from '@/sheep/platform/share';
  24. import index2Api from '@/sheep/api/index2'
  25. // 隐藏原生tabBar
  26. uni.hideTabBar();
  27. const template = computed(() => sheep.$store('app').template?.home);
  28. // 在此处拦截改变一下首页轮播图 此处先写死后期复活 放到启动函数里
  29. (async function() {
  30. console.log('原代码首页定制化数据', template)
  31. let {
  32. data
  33. } = await index2Api.decorate();
  34. console.log('首页导航配置化过高无法兼容', JSON.parse(data[1].value))
  35. // 改变首页底部数据 但是没有通过数组id获取商品数据接口
  36. // let {
  37. // data: datas
  38. // } = await index2Api.spids();
  39. // template.value.data[9].data.goodsIds = datas.list.map(item => item.id);
  40. template.value.data[0].data.list = JSON.parse(data[0].value).map(item => {
  41. return {
  42. src: item.picUrl,
  43. url: item.url,
  44. title: item.name,
  45. type: "image"
  46. }
  47. })
  48. }())
  49. onLoad((options) => {
  50. // #ifdef MP
  51. // 小程序识别二维码
  52. if (options.scene) {
  53. const sceneParams = decodeURIComponent(options.scene).split('=');
  54. options[sceneParams[0]] = sceneParams[1];
  55. }
  56. // #endif
  57. // 预览模板
  58. if (options.templateId) {
  59. sheep.$store('app').init(options.templateId);
  60. }
  61. // 解析分享信息
  62. if (options.spm) {
  63. $share.decryptSpm(options.spm);
  64. }
  65. // 进入指定页面(完整页面路径)
  66. if (options.page) {
  67. sheep.$router.go(decodeURIComponent(options.page));
  68. }
  69. // TODO 芋艿:测试接口的调用
  70. sheep.$api.app.test();
  71. });
  72. // 下拉刷新
  73. onPullDownRefresh(() => {
  74. sheep.$store('app').init();
  75. setTimeout(function() {
  76. uni.stopPullDownRefresh();
  77. }, 800);
  78. });
  79. onPageScroll(() => {});
  80. </script>
  81. <style></style>