component.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useEditor } from "@/modules/editor";
  2. import { css } from "@linaria/core";
  3. import { string } from "vue-types";
  4. import { useCompData } from ".";
  5. import { Image, Text } from "../../../basicUI";
  6. import { createUIComp } from "../../../defines/createUIComp";
  7. import { watch } from "vue";
  8. export const Component = createUIComp({
  9. props: {
  10. compId: string().isRequired,
  11. },
  12. setup(props) {
  13. const editor = useEditor();
  14. const { children, layout } = useCompData(props.compId);
  15. function clickArrow() {
  16. if (editor.store.isEditMode) return;
  17. document.scrollingElement?.scrollTo({
  18. top: document.documentElement.clientHeight,
  19. });
  20. }
  21. if (!editor.store.isEditMode) {
  22. watch(
  23. () => editor.store.compPids[props.compId],
  24. () => {
  25. const height =
  26. document.body.clientHeight * (750 / document.body.clientWidth);
  27. layout.size[1] = height;
  28. const compTrees = editor.helper.getCompTrees(props.compId);
  29. editor.helper.extendStreamCard(compTrees[1].id);
  30. const image = editor.helper.findComp(children.bg);
  31. image?.setH(height);
  32. }
  33. );
  34. }
  35. return () => {
  36. return (
  37. <div class="h-full">
  38. <Image.Component compId={children.bg} />
  39. <Text.Component class={titleCls} compId={children.title} />
  40. <div class={arrowCls} onClick={clickArrow}>
  41. </div>
  42. </div>
  43. );
  44. };
  45. },
  46. });
  47. const titleCls = css`
  48. position: absolute;
  49. left: 50%;
  50. top: 20%;
  51. transform: translateX(-50%) !important;
  52. `;
  53. const arrowCls = css`
  54. position: absolute;
  55. left: 50%;
  56. bottom: 21px;
  57. width: 35px;
  58. height: 35px;
  59. line-height: 35px;
  60. font-size: 18px;
  61. text-align: center;
  62. color: #fff;
  63. border: 2px solid #fff;
  64. border-radius: 50%;
  65. transform: translateX(-50%);
  66. `;