component.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { useEditor } from "@/modules/editor";
  2. import { defineComponent, reactive } from "vue";
  3. import { string } from "vue-types";
  4. import { useCompData } from ".";
  5. import { View } from "../View";
  6. export const Component = defineComponent({
  7. props: {
  8. compId: string().isRequired,
  9. },
  10. setup(props) {
  11. const { store, controls } = useEditor();
  12. const { value } = useCompData(props.compId);
  13. const state = reactive({
  14. visible: false,
  15. });
  16. async function pickPack() {
  17. await controls.pickCtrl.onPickPack();
  18. value.url =
  19. "https://www.sku3d.com/share.html?id=6478676ca494a3ea15a6fa82";
  20. }
  21. function openWeb3D() {
  22. if (value.openWindow) {
  23. window.open(value.url);
  24. } else {
  25. state.visible = true;
  26. }
  27. }
  28. return () => {
  29. return (
  30. <View
  31. compId={props.compId}
  32. onDblclick={store.isEditMode ? pickPack : undefined}
  33. >
  34. {!state.visible ? (
  35. <img
  36. class={[
  37. "w-full h-full object-cover",
  38. store.isEditMode && "pointer-events-none",
  39. ]}
  40. style={{ aspectRatio: value.ratio }}
  41. src={value.poster}
  42. onClick={openWeb3D}
  43. />
  44. ) : (
  45. <iframe
  46. class="w-full h-full border-none"
  47. src={value.url}
  48. style={{ aspectRatio: value.ratio }}
  49. />
  50. )}
  51. </View>
  52. );
  53. };
  54. },
  55. });