index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="player-page" :style="bodyStyle">
  3. <div class="page-wrapper" :style="pageWapperStyle">
  4. <RenderComponent v-for="element in currentPage?.elements" :key="element.key" :element="element"/>
  5. <Result
  6. v-if="!currentPage"
  7. status="warning"
  8. title="很抱歉!当前项目未知错误."
  9. subTitle="请联系管理员"
  10. >
  11. <template #extra>
  12. <Button key="console" type="primary" @click="$router.replace('/')">返回首页</Button>
  13. </template>
  14. </Result>
  15. </div>
  16. </div>
  17. </template>
  18. <script setup lang="ts">
  19. import type { ProjectInfo } from '#/project';
  20. import { ref, onMounted, onBeforeUnmount, StyleValue } from "vue";
  21. import { Result, Button } from "ant-design-vue";
  22. import RenderComponent from "./component/RenderComponent.vue";
  23. import { ScreenFillEnum } from "@/enum/screenFillEnum";
  24. const projectInfo = JSON.parse(localStorage.getItem("currentProject") || "{}") as ProjectInfo;
  25. document.title = `${projectInfo?.name || '沙鲁大屏项目'}--沙鲁低码平台`;
  26. const currentPage = ref(projectInfo.pages?.[0]);
  27. const pageWapperStyle = ref<StyleValue>();
  28. const bodyStyle = ref<StyleValue>();
  29. // 页面样式
  30. const getWapperStyle = () => {
  31. if (!currentPage.value) return;
  32. const { background } = currentPage.value;
  33. const pageBackground =
  34. background.type === "color"
  35. ? { background: background.color }
  36. : {
  37. background: `url(${background.image}) no-repeat center center`,
  38. backgroundSize: background.fillType,
  39. };
  40. const { width = 1280, height = 720 } = projectInfo;
  41. const { clientWidth, clientHeight } = document.documentElement;
  42. let scale: string | number = 1;
  43. switch (projectInfo.fillType) {
  44. case ScreenFillEnum.FILL_HEIGHT:
  45. scale = clientHeight / height;
  46. break;
  47. case ScreenFillEnum.FILL_WIDTH:
  48. scale = clientWidth / width;
  49. break;
  50. case ScreenFillEnum.FILL_BOTH:
  51. const scaleX = clientWidth / width;
  52. const scaleY = clientHeight / height;
  53. scale = `${scaleX},${scaleY}`;
  54. break;
  55. default:
  56. scale = Math.min(clientWidth / width, clientHeight / height);
  57. }
  58. bodyStyle.value = {
  59. background: '#000',
  60. } as unknown as StyleValue;
  61. pageWapperStyle.value = {
  62. position: 'absolute',
  63. left: '50%',
  64. top: '50%',
  65. width: `${width}px`,
  66. height: `${height}px`,
  67. overflow: "hidden",
  68. // border: "1px solid #f0f0f0",
  69. boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
  70. transform: `scale(${scale}) translate(-50%, -50%)`,
  71. transformOrigin: "0 0",
  72. ...pageBackground,
  73. } as unknown as StyleValue;
  74. };
  75. onMounted(() => {
  76. getWapperStyle();
  77. window.addEventListener("resize", getWapperStyle);
  78. });
  79. onBeforeUnmount(() => {
  80. window.removeEventListener("resize", getWapperStyle);
  81. });
  82. </script>
  83. <style lang="less" scoped>
  84. .player-page {
  85. height: 100%;
  86. width: 100%;
  87. position: fixed;
  88. overflow: hidden;
  89. }
  90. </style>