component.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { useEditor } from "@/modules/editor";
  2. import { defineComponent } 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()
  9. },
  10. emits: ["update:compId"],
  11. setup(props, { emit }) {
  12. const compConf = useCompData(props.compId || "") ;
  13. const { store, controls } = useEditor();
  14. async function changeVal() {
  15. const url = await controls.pickCtrl.pickOneImage();
  16. if (!url) return;
  17. compConf.value.url = url;
  18. compConf.value.x = 0;
  19. compConf.value.y = 0;
  20. compConf.value.s = 1;
  21. }
  22. //hello
  23. console.log("compConf", compConf)
  24. if (!props.compId) {
  25. emit("update:compId", compConf.id)
  26. }
  27. return () => {
  28. const value = compConf.value;
  29. const scale = value?.s || 1;
  30. const ox = value?.x || 0;
  31. const oy = value?.y || 0;
  32. const objectFit =
  33. scale + "" == "1" && ox + "" == "0" && oy + "" == "0"
  34. ? "cover"
  35. : "contain";
  36. console.log("Scalexxxxxxxxxxxxxxxxxx=>", compConf);
  37. return (
  38. <View
  39. compId={compConf.id}
  40. onDblclick={store.isEditMode ? changeVal : undefined}
  41. >
  42. <img
  43. class={"w-1/1 h-1/1 object-cover pointer-events-none"}
  44. style={{
  45. transform: `scale(${scale}) translate(${ox}%,${oy}%)`,
  46. objectFit,
  47. }}
  48. src={value?.url}
  49. />
  50. </View>
  51. );
  52. };
  53. },
  54. });