MaterialItem.tsx 3.0 KB

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