component.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineComponent } from "vue";
  2. import { string } from "vue-types";
  3. import { useCompData } from ".";
  4. import { View } from "../View";
  5. import { useEditor } from "@/modules/editor";
  6. import { IconPicture } from "@queenjs/icons";
  7. import { css } from "@linaria/core";
  8. export const Component = defineComponent({
  9. props: {
  10. compId: string().isRequired,
  11. },
  12. setup(props) {
  13. const { store, controls } = useEditor();
  14. const { value } = useCompData(props.compId);
  15. async function changeVal() {
  16. const url = await controls.pickCtrl.pickOneImage();
  17. if (!url) return;
  18. value.url = url;
  19. }
  20. return () => {
  21. const options: any = {};
  22. if (value.autoplay) options.autoplay = true;
  23. if (value.loop) options.loop = true;
  24. if (value.controls) options.controls = true;
  25. return (
  26. <View class={rootCls} compId={props.compId}>
  27. <video
  28. class="w-full object-cover"
  29. src={value.url}
  30. style={{ aspectRatio: value.ratio }}
  31. {...options}
  32. />
  33. {store.isEditMode && (
  34. <IconPicture class={btnCls} onClick={changeVal} />
  35. )}
  36. </View>
  37. );
  38. };
  39. },
  40. });
  41. const btnCls = css`
  42. display: none;
  43. position: absolute;
  44. top: 50%;
  45. left: 50%;
  46. padding: 0.4rem;
  47. font-size: 0.75rem;
  48. color: #666;
  49. border-radius: 50%;
  50. background-color: rgba(255, 255, 255, 0.7);
  51. transform: translate(-50%, -50%);
  52. @apply shadow;
  53. `;
  54. const rootCls = css`
  55. &:hover {
  56. .${btnCls} {
  57. display: block;
  58. }
  59. }
  60. `;