OutputTemplateItem.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { css, cx } from "@linaria/core";
  2. import { Image, View } from "@queenjs/ui";
  3. import { Checkbox, Radio, RadioChangeEvent, Tag } from "ant-design-vue";
  4. import { defineUI, queenApi } from "queenjs";
  5. import { reactive } from "vue";
  6. import { any, bool, string } from "vue-types";
  7. import PreviewMaterialModal from "../../components/PreviewMaterialModal";
  8. const options = [
  9. { label: "1倍", value: 1 },
  10. { label: "2倍", value: 2 },
  11. ];
  12. export default defineUI({
  13. props: {
  14. type: string<"image" | "video">().def("image"),
  15. active: bool(),
  16. record: any(),
  17. },
  18. emits: ["select", "change"],
  19. setup(props, { emit }) {
  20. const state = reactive({
  21. qos: 1,
  22. });
  23. const change = (e: RadioChangeEvent) => {
  24. state.qos = e.target.value;
  25. emit("change", state.qos);
  26. };
  27. const showModal = () => {
  28. const { record, type } = props;
  29. const isVideo = type == "video";
  30. queenApi.dialog(
  31. <PreviewMaterialModal
  32. data={{
  33. url: isVideo ? record.videoUrl : record?.thumbnailUrl,
  34. fileType: type,
  35. }}
  36. />,
  37. {
  38. title: "预览渲染模板",
  39. width: "1000px",
  40. }
  41. );
  42. };
  43. return () => {
  44. const { active, record, type } = props;
  45. const isVideo = type == "video";
  46. return (
  47. <div class="cursor-pointer">
  48. <View
  49. ratio={1.4}
  50. onClick={() => emit("select")}
  51. class={cx(
  52. itemStyles,
  53. "relative overflow-hidden group",
  54. active && "active"
  55. )}
  56. >
  57. {isVideo && (
  58. <Tag color="#E88B00" class="absolute right-0 top-0 z-9 !mr-0">
  59. 视频
  60. </Tag>
  61. )}
  62. {active && (
  63. <Checkbox checked class="!-mt-0.2em absolute top-0 left-0 z-3" />
  64. )}
  65. {!isVideo ? (
  66. <Image class="h-1/1 w-1/1" src={record?.thumbnailUrl} />
  67. ) : (
  68. <video src={record.videoUrl} class="h-1/1 w-1/1 object-cover" />
  69. )}
  70. <span
  71. class="absolute left-1/2 top-1/2 z-3 transform -translate-x-1/2 -translate-y-1/2 rounded-1/2 w-56px leading-56px text-center bg-primary transition-all opacity-0 group-hover:opacity-100 hover:(bg-opacity-50)"
  72. onClick={(e) => {
  73. e.stopPropagation();
  74. showModal();
  75. }}
  76. >
  77. 预览
  78. </span>
  79. </View>
  80. <div>
  81. <div class="py-8px">
  82. 尺寸:{record.width} * {record.height}
  83. </div>
  84. <div>
  85. 渲染分辨率:
  86. <Radio.Group
  87. disabled={!props.active}
  88. value={state.qos}
  89. options={options}
  90. onChange={change}
  91. />
  92. </div>
  93. </div>
  94. </div>
  95. );
  96. };
  97. },
  98. });
  99. const itemStyles = css`
  100. border: 1px solid transparent;
  101. &.active {
  102. border-color: @inf-primary-color;
  103. }
  104. `;