CustomComps.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { Tag } from "ant-design-vue";
  2. import dayjs from "dayjs";
  3. import { Container, Draggable } from "vue-dndrop";
  4. import { any, bool } from "vue-types";
  5. import Empty from "@/components/Empty";
  6. import { useEditor } from "@/modules/editor";
  7. import { ICompKeys } from "@/modules/editor/typings";
  8. import { useResource } from "@/modules/resource";
  9. import { useAuth } from "@queenjs-modules/auth";
  10. import { Image, Loadmore } from "@queenjs/ui";
  11. import { useReactive } from "@queenjs/use";
  12. import { defineUI, queenApi } from "queenjs";
  13. import { CompList } from "./CompList";
  14. import Menu from "./Menu";
  15. const compList = [
  16. // "Card2",
  17. // "Card3",
  18. // "Card5",
  19. // "CardList",
  20. // "Cards11",
  21. // "Cards12",
  22. // "Cards13",
  23. // "Cards14",
  24. // "Cards15",
  25. "Cover",
  26. "Cover2",
  27. // "Text1",
  28. // "Title1",
  29. // "Title2",
  30. // "Title3",
  31. ];
  32. export default defineUI({
  33. setup() {
  34. const editor = useEditor();
  35. const resource = useResource();
  36. const { sysCompListCtrl } = resource.controls;
  37. const { compUICtrl } = editor.controls;
  38. sysCompListCtrl.loadPage(1);
  39. const state = useReactive(() => ({
  40. currComps() {
  41. return Array.from(compUICtrl.state.components.values()).filter(
  42. (item) => "senior" === item.compType
  43. );
  44. },
  45. cusComps() {
  46. return state.currComps.filter((d) => compList.includes(d.compKey));
  47. },
  48. }));
  49. return () => {
  50. const dataSource = sysCompListCtrl.state.list;
  51. return (
  52. <div>
  53. <CompList dataSource={dataSource} isSys={true} />
  54. <Comp components={state.cusComps} taggable={false} class="mt-10px" />
  55. {dataSource.length == 0 ? null : (
  56. <Loadmore
  57. class="mt-20px"
  58. loading={sysCompListCtrl.state.loading}
  59. canLoad={sysCompListCtrl.state.canLoadNext}
  60. onChange={sysCompListCtrl.loadNextPage}
  61. />
  62. )}
  63. </div>
  64. );
  65. };
  66. },
  67. });
  68. const Comp = defineUI({
  69. props: {
  70. components: any<
  71. {
  72. compKey: string;
  73. name: string;
  74. thumbnail: string;
  75. published?: boolean;
  76. createTime?: string;
  77. }[]
  78. >().isRequired,
  79. taggable: bool().def(false),
  80. },
  81. setup(props) {
  82. const editor = useEditor();
  83. const auth = useAuth();
  84. const resource = useResource();
  85. return () => {
  86. //@ts-ignore
  87. const isSys = (auth.store.userInfo.roles || []).indexOf("system") > -1;
  88. if (props.components.length == 0) return <Empty class="pt-150px" />;
  89. return (
  90. <Container
  91. class="space-y-10px scrollbar"
  92. behaviour="copy"
  93. group-name="canvas"
  94. animation-duration={0}
  95. get-child-payload={(index: number) => {
  96. return props.components[index].compKey;
  97. }}
  98. >
  99. {props.components.map((item) => {
  100. const items = ["删除"];
  101. if (isSys) {
  102. item.published ? items.push("取消发布") : items.push("发布平台");
  103. }
  104. return (
  105. <Draggable>
  106. <div
  107. class="text-center leading-50px bg-dark-50 rounded draggable-item relative"
  108. key={item.compKey}
  109. title={item.name}
  110. onClick={() =>
  111. editor.actions.clickCompToDesign(item.compKey as ICompKeys)
  112. }
  113. >
  114. <Image
  115. class="w-full rounded pointer-events-none"
  116. src={item.thumbnail}
  117. size={240}
  118. />
  119. {isSys && props.taggable && (
  120. <Tag
  121. color={item.published ? "green" : "#E88B00"}
  122. // color="rgba(0, 0, 0, 0.4)"
  123. class="absolute top-0 left-0 z-1 !rounded-none"
  124. >
  125. {item.published ? "已发布" : "未发布"}
  126. </Tag>
  127. )}
  128. {props.taggable && (
  129. <div class="item_footer rounded-b-4px flex items-center justify-between p-4px">
  130. <div class="flex-1 w-0">
  131. {/* <div class="text-white text-bold truncate">{record.title}</div> */}
  132. <div class="flex items-center text-opacity-60 text-white text-12px">
  133. {dayjs(item.createTime).format("YYYY.MM.DD")}
  134. </div>
  135. </div>
  136. <Menu
  137. items={items}
  138. onMenu={async (name) => {
  139. console.log("name", name);
  140. if (name == "删除") {
  141. await resource.actions.deleteCustomComp(item);
  142. // editor.controls.compUICtrl.
  143. queenApi.messageSuccess("删除成功!");
  144. return;
  145. }
  146. const pub = name == "发布平台";
  147. await resource.actions.publishFrame(item, pub);
  148. item.published = pub;
  149. }}
  150. />
  151. </div>
  152. )}
  153. </div>
  154. </Draggable>
  155. );
  156. })}
  157. </Container>
  158. );
  159. };
  160. },
  161. });