component.tsx 2.9 KB

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