BaseComp.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { useEditor } from "@/modules/editor";
  2. import { ICompKeys } from "@/modules/editor/typings";
  3. import { css } from "@linaria/core";
  4. import { useReactive } from "@queenjs/use";
  5. import { Tooltip } from "ant-design-vue";
  6. import { defineComponent } from "vue";
  7. import { Container, Draggable } from "vue-dndrop";
  8. export default defineComponent({
  9. setup() {
  10. const editor = useEditor();
  11. const { compUICtrl } = editor.controls;
  12. const state = useReactive(() => ({
  13. basicComps() {
  14. return ["Text", "Image", "Video", "Web3D", "Rectage", "Line", "Arc", "Ellipse", "Triangle", "QuadraticCurve"].map(
  15. (key) => compUICtrl.state.components.get(key) as any
  16. );
  17. },
  18. }));
  19. return () => {
  20. return (
  21. <Container
  22. class={basicStyle}
  23. orientation="horizontal"
  24. behaviour="copy"
  25. group-name="canvas"
  26. get-child-payload={(index: number) => {
  27. return state.basicComps[index].compKey;
  28. }}
  29. >
  30. {state.basicComps.map((item) => {
  31. return (
  32. <Draggable key={item.compKey} class="!leading-0">
  33. <div
  34. class="draggable-item"
  35. onClick={() =>
  36. editor.actions.clickCompToDesign(item.compKey as ICompKeys)
  37. }
  38. >
  39. <Tooltip title={item.name}>
  40. <span>
  41. <img
  42. class="h-24px m-4px pointer-events-none"
  43. src={item.thumbnail}
  44. />
  45. </span>
  46. </Tooltip>
  47. </div>
  48. </Draggable>
  49. );
  50. })}
  51. </Container>
  52. );
  53. };
  54. },
  55. });
  56. const basicStyle = css`
  57. display: flex;
  58. align-items: center;
  59. .draggable-item {
  60. border-radius: 4px;
  61. margin: 0 4px;
  62. cursor: pointer;
  63. &:hover {
  64. background-color: darken(@inf-component-bg, 3%);
  65. }
  66. }
  67. `;