page.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!-- 自定义页面:支持装修 -->
  2. <template>
  3. <s-layout
  4. :title="state.name"
  5. navbar="custom"
  6. :bgStyle="state.page"
  7. :navbarStyle="state.navigationBar"
  8. onShareAppMessage
  9. showLeftButton
  10. >
  11. <s-block v-for="(item, index) in state.components" :key="index" :styles="item.property.style">
  12. <s-block-item :type="item.id" :data="item.property" :styles="item.property.style" />
  13. </s-block>
  14. </s-layout>
  15. </template>
  16. <script setup>
  17. import { reactive } from 'vue';
  18. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  19. import DiyApi from '@/sheep/api/promotion/diy';
  20. const state = reactive({
  21. name: '',
  22. components: [],
  23. navigationBar: {},
  24. page: {},
  25. });
  26. onLoad(async (options) => {
  27. let id = options.id
  28. // #ifdef MP
  29. // 小程序预览自定义页面
  30. if (options.scene) {
  31. const sceneParams = decodeURIComponent(options.scene).split('=');
  32. id = sceneParams[1];
  33. }
  34. // #endif
  35. const { code, data } = await DiyApi.getDiyPage(id);
  36. if (code === 0) {
  37. state.name = data.name;
  38. state.components = data.property?.components;
  39. state.navigationBar = data.property?.navigationBar;
  40. state.page = data.property?.page;
  41. }
  42. });
  43. onPageScroll(() => {});
  44. </script>
  45. <style></style>