MaterialItem.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { css, cx } from "@linaria/core";
  2. import { IconDelete } from "@queenjs/icons";
  3. import { Image, View } from "@queenjs/ui";
  4. import { Checkbox } from "ant-design-vue";
  5. import { defineUI } from "queenjs";
  6. import { any, bool, string } from "vue-types";
  7. export default defineUI({
  8. props: {
  9. active: bool().def(false),
  10. record: any(),
  11. use: string<"show" | "select" | "task">(),
  12. },
  13. emits: ["delete", "select", "download", "use"],
  14. setup(props, { emit }) {
  15. return () => {
  16. const { active, record, use } = props;
  17. // console.error("record: ", record);
  18. return (
  19. <div class={cx(itemStyles, "relative", active && "active")}>
  20. <View ratio={1.4} class="overflow-hidden">
  21. {record.fileType == "video" ? (
  22. <video src={record.file?.url} class="h-1/1 w-1/1" />
  23. ) : (
  24. <Image
  25. class="h-1/1 w-1/1"
  26. src={
  27. record?.thumbnail || record?.thumbnailUrl || record.file?.url
  28. }
  29. />
  30. )}
  31. {active && (
  32. <Checkbox
  33. checked
  34. class="!-mt-0.2em absolute top-0 left-0 text-20px text-red-200 z-3"
  35. />
  36. )}
  37. {use == "task" && (
  38. <div class="waiting absolute inset-0 z-2 flex items-center justify-center text-white">
  39. 渲染中…
  40. </div>
  41. )}
  42. {use !== "task" && (
  43. <div
  44. class="absolute inset-0 flex items-center justify-center z-2 opacity-0 hover:opacity-100 transition-all text-white"
  45. onClick={() => emit("select")}
  46. >
  47. {use == "show" && (
  48. <IconDelete
  49. class="icon_del absolute right-5px top-5px p-3px rounded-2px text-14px cursor-pointer"
  50. onClick={() => emit("delete")}
  51. />
  52. )}
  53. {use == "show" && (
  54. <div
  55. class="btn_circle rounded-1/2 text-center w-56px leading-56px cursor-pointer"
  56. onClick={() => emit("download")}
  57. >
  58. 下载
  59. </div>
  60. )}
  61. {use == "select" && (
  62. <div
  63. class="btn_circle rounded-1/2 text-center w-56px leading-56px cursor-pointer"
  64. onClick={(e) => {
  65. e.stopPropagation();
  66. emit("use");
  67. }}
  68. >
  69. 使用
  70. </div>
  71. )}
  72. </div>
  73. )}
  74. </View>
  75. {record.name && (
  76. <div class="py-8px px-10px" style={{ backgroundColor: "#262626" }}>
  77. {record.name}
  78. </div>
  79. )}
  80. </div>
  81. );
  82. };
  83. },
  84. });
  85. const itemStyles = css`
  86. border: 1px solid transparent;
  87. &.active {
  88. border-color: @inf-primary-color;
  89. }
  90. .btn_circle {
  91. background-color: rgba(0, 0, 0, 0.7);
  92. &:hover {
  93. background-color: rgba(0, 0, 0, 0.8);
  94. }
  95. &:not(:first-child) {
  96. margin-left: 10px;
  97. }
  98. }
  99. .icon_del {
  100. background-color: rgba(0, 0, 0, 0.5);
  101. &:hover {
  102. background-color: rgba(0, 0, 0, 0.6);
  103. }
  104. }
  105. .waiting {
  106. background-color: rgba(0, 0, 0, 0.3);
  107. }
  108. `;