component.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { css, cx } from "@linaria/core";
  2. import { defineComponent, inject } from "vue";
  3. import { bool, string } from "vue-types";
  4. import { CompCardObj } from ".";
  5. import { CompUI } from "../..";
  6. import { useEditor } from "../../../..";
  7. import { DesignComp } from "../../../../objects/DesignTemp/DesignComp";
  8. import { useCompData } from "../../defines/hook";
  9. import { View } from "../View";
  10. export const Component = defineComponent({
  11. props: {
  12. compId: string().isRequired,
  13. showMask: bool().def(false),
  14. },
  15. setup(props) {
  16. const { helper, controls, store } = useEditor();
  17. const comp = useCompData<CompCardObj>(props.compId);
  18. const isStreamCard = helper.isStreamCard(props.compId);
  19. const isPreview = inject("isPreview", false);
  20. const isShowSwiper = () => {
  21. const { value } = controls.pageCtrl.rootPage;
  22. return value.pageMode == "short" && isPreview;
  23. };
  24. const getContainerStyles = () => {
  25. const rootPage = controls.pageCtrl.rootPage;
  26. const isPcDesign = rootPage.value.useFor == "pc";
  27. const isShortDesign = rootPage.value.pageMode == "short";
  28. const style: any = {};
  29. // 翻页
  30. if (isStreamCard && isShortDesign && store.isDisplay) {
  31. if (!isPcDesign) {
  32. style.height = "100%";
  33. style.width = "100%";
  34. } else {
  35. style.height = "100vh";
  36. style.width = "100vw";
  37. }
  38. style.display = "flex";
  39. style.justifyContent = "center";
  40. style.alignItems = "center";
  41. }
  42. return style;
  43. };
  44. const createScale = () => {
  45. const showSwiper = isShowSwiper();
  46. if (!showSwiper) return;
  47. const scale = controls.previewCtrl.state.scale;
  48. const style = { transform: `scale(${scale})` };
  49. return style;
  50. };
  51. return () => {
  52. const showSwiper = isShowSwiper();
  53. const containerStyles = getContainerStyles();
  54. const containerScale = createScale();
  55. const rootPage = controls.pageCtrl.rootPage;
  56. return (
  57. <div
  58. class={cx(rootStyles, showSwiper && "swiper-slide")}
  59. style={containerStyles}
  60. key={rootPage.children.default.indexOf(props.compId) + props.compId}
  61. >
  62. <View
  63. class="JS_viewRoot"
  64. compId={props.compId}
  65. style={containerScale}
  66. showMask={props.showMask}
  67. >
  68. {comp.children.default?.map((compId, index) => {
  69. const compItem = helper.findComp(compId) as DesignComp;
  70. const Comp =
  71. controls.compUICtrl.state.components.get(compItem?.compKey)
  72. ?.Component || CompUI.Container.Component;
  73. if (!compItem) return;
  74. return <Comp key={compItem?.id + index} compId={compItem?.id} />;
  75. })}
  76. </View>
  77. </div>
  78. );
  79. };
  80. },
  81. });
  82. const rootStyles = css`
  83. &.swiper-slide-active {
  84. z-index: 10;
  85. }
  86. `;