index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <view v-if="template">
  3. <s-layout title="首页" navbar="custom" tabbar="/pages/index/index" :bgStyle="template.style?.background"
  4. :navbarStyle="template.style?.navbar" onShareAppMessage>
  5. <s-block v-for="(item, index) in template.data" :key="index" :styles="item.style">
  6. <s-block-item :type="item.type" :data="item.data" :styles="item.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. let {
  31. data
  32. } = await index2Api.decorate();
  33. template.value.data[0].data.list = JSON.parse(data[0].value).map(item => {
  34. return {
  35. src: item.picUrl,
  36. url: item.url,
  37. title: item.name,
  38. type: "image"
  39. }
  40. })
  41. }())
  42. onLoad((options) => {
  43. // #ifdef MP
  44. // 小程序识别二维码
  45. if (options.scene) {
  46. const sceneParams = decodeURIComponent(options.scene).split('=');
  47. options[sceneParams[0]] = sceneParams[1];
  48. }
  49. // #endif
  50. // 预览模板
  51. if (options.templateId) {
  52. sheep.$store('app').init(options.templateId);
  53. }
  54. // 解析分享信息
  55. if (options.spm) {
  56. $share.decryptSpm(options.spm);
  57. }
  58. // 进入指定页面(完整页面路径)
  59. if (options.page) {
  60. sheep.$router.go(decodeURIComponent(options.page));
  61. }
  62. // TODO 芋艿:测试接口的调用
  63. sheep.$api.app.test();
  64. });
  65. // 下拉刷新
  66. onPullDownRefresh(() => {
  67. sheep.$store('app').init();
  68. setTimeout(function() {
  69. uni.stopPullDownRefresh();
  70. }, 800);
  71. });
  72. onPageScroll(() => {});
  73. </script>
  74. <style></style>