Shapes.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import Empty from "@/components/Empty";
  2. import { useEditor } from "@/modules/editor";
  3. import { ICompKeys } from "@/modules/editor/typings";
  4. import { useResource } from "@/modules/resource";
  5. import { Loadmore } from "@queenjs/ui";
  6. import { useReactive } from "@queenjs/use";
  7. import { defineComponent } from "vue";
  8. import { Container, Draggable } from "vue-dndrop";
  9. import { CompList } from "./CompList";
  10. export default defineComponent({
  11. setup() {
  12. const editor = useEditor();
  13. const { compUICtrl } = editor.controls;
  14. const resource = useResource();
  15. const { sysShapeListCtrl } = resource.controls;
  16. sysShapeListCtrl.loadPage(1);
  17. const state = useReactive(() => ({
  18. basicComps() {
  19. return [
  20. "Line",
  21. "Arc",
  22. "Curve",
  23. "Ellipse",
  24. "Triangle",
  25. "Rectage",
  26. "PolygonNormal",
  27. "Polygon",
  28. ].map((key) => compUICtrl.state.components.get(key) as any);
  29. },
  30. }));
  31. return () => {
  32. const dataSource = sysShapeListCtrl.state.list;
  33. return (
  34. <div class="flex-1 overflow-x-hidden overflow-y-auto scrollbar">
  35. <div class="my-10px">默认</div>
  36. <Container
  37. class="grid grid-cols-3 gap-10px"
  38. behaviour="copy"
  39. group-name="canvas"
  40. get-child-payload={(index: number) => {
  41. return state.basicComps[index].compKey;
  42. }}
  43. >
  44. {state.basicComps.map((item) => {
  45. return (
  46. <Draggable key={item.compKey} class="!leading-0">
  47. <div
  48. title={item.name}
  49. class="draggable-item text-center leading-50px bg-[#303030] rounded cursor-pointer hover:bg-dark-100 transition"
  50. onClick={() =>
  51. editor.actions.clickCompToDesign(
  52. item.compKey as ICompKeys
  53. )
  54. }
  55. >
  56. <img class="h-34px m-4px" src={item.thumbnail} />
  57. </div>
  58. </Draggable>
  59. );
  60. })}
  61. </Container>
  62. <div class="my-20px">组合</div>
  63. <CompList dataSource={dataSource} columns={3} isSys={true} />
  64. {dataSource.length == 0 ? (
  65. <Empty />
  66. ) : (
  67. <Loadmore
  68. class="mt-20px"
  69. loading={sysShapeListCtrl.state.loading}
  70. canLoad={sysShapeListCtrl.state.canLoadNext}
  71. onChange={sysShapeListCtrl.loadNextPage}
  72. />
  73. )}
  74. </div>
  75. );
  76. };
  77. },
  78. });