index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. onShow,
  22. onPageScroll,
  23. onPullDownRefresh
  24. } from '@dcloudio/uni-app';
  25. import sheep from '@/sheep';
  26. import $share from '@/sheep/platform/share';
  27. import PageApi from '@/sheep/api/promotion/page';
  28. import {
  29. t
  30. } from '@/locale'
  31. // 隐藏原生tabBar
  32. uni.hideTabBar();
  33. const template = ref({})
  34. const shopName = ref('')
  35. const state = reactive({
  36. shopName : '',
  37. merchantId: 0,
  38. shopId:0
  39. })
  40. const tabbar = ref({
  41. "theme": "red",
  42. "style": {
  43. "bgType": "color",
  44. "bgColor": "#ffffff",
  45. "color": "#3c3c3c",
  46. "activeColor": "#1fa380"
  47. },
  48. "items": [{
  49. "text": t('common.shop_index'),
  50. "url": "/pages/shop/index",
  51. "iconUrl": sheep.$url.static('/static/shopIndex/shopIndex.svg'),
  52. "activeIconUrl": sheep.$url.static('/static/shopIndex/shopIndex-active.svg')
  53. },
  54. {
  55. "text": t('common.shop_category'),
  56. "url": "/pages/shop/category",
  57. "iconUrl": sheep.$url.static('/static/shopIndex/category.svg'),
  58. "activeIconUrl": sheep.$url.static('/static/shopIndex/category-active.svg')
  59. },
  60. {
  61. "text": t('common.all_product'),
  62. "url": "/pages/shop/allproduct",
  63. "iconUrl": sheep.$url.static('/static/shopIndex/allProduct.svg'),
  64. "activeIconUrl": sheep.$url.static('/static/shopIndex/allProduct-active.svg')
  65. },
  66. ]
  67. });
  68. onLoad(async(options) => {
  69. // #ifdef MP
  70. // 小程序识别二维码
  71. if (options.scene) {
  72. const sceneParams = decodeURIComponent(options.scene).split('=');
  73. options[sceneParams[0]] = sceneParams[1];
  74. }
  75. // #endif
  76. // 预览模板
  77. if (options.templateId) {
  78. sheep.$store('app').init(options.templateId);
  79. }
  80. // 解析分享信息
  81. if (options.spm) {
  82. $share.decryptSpm(options.spm);
  83. }
  84. // 进入指定页面(完整页面路径)
  85. if (options.page) {
  86. sheep.$router.go(decodeURIComponent(options.page));
  87. }
  88. state.merchantId = options.merchantId;
  89. state.shopId = options.shopId;
  90. state.shopName = options.shopName;
  91. tabbar.value.items = tabbar.value.items.map(item => {
  92. // 为每个 URL 添加参数
  93. item.url = `${item.url}?shopId=${state.shopId}&shopName=${encodeURIComponent(state.shopName)}&merchantId=${state.merchantId}`;
  94. return item;
  95. });
  96. console.log(options)
  97. const { code,data } = await PageApi.getPage({shopId:options.shopId,merchantId:options.merchantId});
  98. console.log(data)
  99. template.value = data.property
  100. });
  101. onPageScroll(() => {});
  102. </script>
  103. <style></style>