CompsUser.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { cx } from "@linaria/core";
  2. import { Tag } from "ant-design-vue";
  3. import dayjs from "dayjs";
  4. import { upperFirst } from "lodash";
  5. import { Container, Draggable } from "vue-dndrop";
  6. import { string } from "vue-types";
  7. import Empty from "@/components/Empty";
  8. import { useEditor } from "@/modules/editor";
  9. import { useResource } from "@/modules/resource";
  10. import { useAuth } from "@queenjs-modules/auth";
  11. import { Image } from "@queenjs/ui";
  12. import { defineUI, queenApi } from "queenjs";
  13. import Menu from "./Menu";
  14. export default defineUI({
  15. props: {
  16. sourceType: string<"comp" | "text" | "shape">().def("comp"),
  17. },
  18. setup(props) {
  19. const editor = useEditor();
  20. const auth = useAuth();
  21. const resource = useResource();
  22. const listCtrl = getCtrl();
  23. listCtrl.hasLimit = true;
  24. listCtrl.loadPage(1);
  25. //@ts-ignore
  26. let isSys = (auth.store.userInfo.roles || []).indexOf("system") > -1;
  27. function getCtrl() {
  28. const key = `cust${upperFirst(props.sourceType)}ListCtrl`;
  29. //@ts-ignore
  30. return resource.controls[key];
  31. }
  32. return () => {
  33. const { sourceType } = props;
  34. if (listCtrl.state.list.length == 0) return <Empty class="pt-150px" />;
  35. return (
  36. <div>
  37. <Container
  38. class={cx(
  39. "grid gap-10px",
  40. sourceType == "comp" ? "grid-cols-1" : "grid-cols-2"
  41. )}
  42. behaviour="copy"
  43. group-name="canvas"
  44. animation-duration={0}
  45. get-child-payload={(index: number) => {
  46. return {
  47. type: "CompCard",
  48. data: { id: listCtrl.state.list[index]._id, isSys: isSys },
  49. };
  50. }}
  51. >
  52. {listCtrl.state.list.map((item: any) => {
  53. const items = ["删除"];
  54. if (isSys) {
  55. item.published
  56. ? items.push("取消发布")
  57. : items.push("发布平台");
  58. }
  59. return (
  60. <Draggable>
  61. <div
  62. class="text-center leading-50px bg-dark-50 rounded draggable-item relative"
  63. key={item.compKey}
  64. title={item.name}
  65. >
  66. <Image
  67. class="w-full rounded"
  68. src={item.thumbnail}
  69. onClick={() => {
  70. editor.actions.clickCompUserToDesign(item._id, isSys);
  71. }}
  72. size={240}
  73. />
  74. {isSys && (
  75. <Tag
  76. color={item.published ? "green" : "#E88B00"}
  77. // color="rgba(0, 0, 0, 0.4)"
  78. class="absolute top-0 left-0 z-1 !rounded-none"
  79. >
  80. {item.published ? "已发布" : "未发布"}
  81. </Tag>
  82. )}
  83. <div class="item_footer rounded-b-4px flex items-center justify-between p-4px">
  84. <div class="flex-1 w-0">
  85. {/* <div class="text-white text-bold truncate">{record.title}</div> */}
  86. <div class="flex items-center text-opacity-60 text-white text-12px">
  87. {dayjs(item.createTime).format("YYYY.MM.DD")}
  88. </div>
  89. </div>
  90. <Menu
  91. items={items}
  92. onMenu={async (name) => {
  93. console.log("name", name);
  94. if (name == "删除") {
  95. await resource.actions.deleteCustomComp(item);
  96. listCtrl.fresh();
  97. queenApi.messageSuccess("删除成功!");
  98. return;
  99. }
  100. const pub = name == "发布平台";
  101. await resource.actions.publishFrame(item, pub);
  102. item.published = pub;
  103. }}
  104. />
  105. </div>
  106. </div>
  107. </Draggable>
  108. );
  109. })}
  110. </Container>
  111. </div>
  112. );
  113. };
  114. },
  115. });