index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <!-- 店铺首页,支持店铺装修 -->
  2. <template>
  3. <view v-if="template">
  4. <su-navbar :title="state.shopName" statusBar :color="color" :tools="tools"
  5. :opacityBgUi="opacityBgUi" @search="(e) => emits('search', e)" :defaultSearch="defaultSearch" />
  6. <s-block v-for="(item, index) in template.components" :key="index" :styles="item.property.style">
  7. <s-block-item :type="item.id" :data="item.property" :styles="item.property.style" />
  8. </s-block>
  9. <s-tabbar path="/pages/shop/index" :tabbar="tabbar" />
  10. <s-menu-tools />
  11. </view>
  12. </template>
  13. <script setup>
  14. import {
  15. computed,
  16. reactive,
  17. ref
  18. } from 'vue';
  19. import {
  20. onLoad,
  21. onPageScroll,
  22. onPullDownRefresh
  23. } from '@dcloudio/uni-app';
  24. import sheep from '@/sheep';
  25. import $share from '@/sheep/platform/share';
  26. import PageApi from '@/sheep/api/promotion/page';
  27. import {
  28. t
  29. } from '@/locale'
  30. // 隐藏原生tabBar
  31. uni.hideTabBar();
  32. const template = ref({})
  33. const shopName = ref('')
  34. const state = reactive({
  35. shopName : '',
  36. merchantId: 0,
  37. shopId:0
  38. })
  39. const tabbar = ref({
  40. "theme": "red",
  41. "style": {
  42. "bgType": "color",
  43. "bgColor": "#ffffff",
  44. "color": "#3c3c3c",
  45. "activeColor": "#1fa380"
  46. },
  47. "items": [{
  48. "text": t('common.shop_index'),
  49. "url": "/pages/shop/index",
  50. "iconUrl": sheep.$url.static('/static/shopIndex/shopIndex.svg'),
  51. "activeIconUrl": sheep.$url.static('/static/shopIndex/shopIndex-active.svg')
  52. },
  53. {
  54. "text": t('common.shop_category'),
  55. "url": "/pages/shop/category",
  56. "iconUrl": sheep.$url.static('/static/shopIndex/category.svg'),
  57. "activeIconUrl": sheep.$url.static('/static/shopIndex/category-active.svg')
  58. },
  59. {
  60. "text": t('common.all_product'),
  61. "url": "/pages/shop/allproduct",
  62. "iconUrl": sheep.$url.static('/static/shopIndex/allProduct.svg'),
  63. "activeIconUrl": sheep.$url.static('/static/shopIndex/allProduct-active.svg')
  64. },
  65. ]
  66. });
  67. onLoad(async(options) => {
  68. // #ifdef MP
  69. // 小程序识别二维码
  70. if (options.scene) {
  71. const sceneParams = decodeURIComponent(options.scene).split('=');
  72. options[sceneParams[0]] = sceneParams[1];
  73. }
  74. // #endif
  75. // 预览模板
  76. if (options.templateId) {
  77. sheep.$store('app').init(options.templateId);
  78. }
  79. // 解析分享信息
  80. if (options.spm) {
  81. $share.decryptSpm(options.spm);
  82. }
  83. // 进入指定页面(完整页面路径)
  84. if (options.page) {
  85. sheep.$router.go(decodeURIComponent(options.page));
  86. }
  87. state.merchantId = options.merchantId;
  88. state.shopId = options.shopId;
  89. state.shopName = options.shopName;
  90. tabbar.value.items = tabbar.value.items.map(item => {
  91. // 为每个 URL 添加参数
  92. item.url = `${item.url}?shopId=${state.shopId}&shopName=${encodeURIComponent(state.shopName)}&merchantId=${state.merchantId}`;
  93. return item;
  94. });
  95. const { code,data } = await PageApi.getPage({shopId:options.shopId,merchantId:options.merchantId});
  96. // console.log(data)
  97. template.value = data.property
  98. });
  99. onPageScroll(() => {});
  100. </script>
  101. <style></style>