|
@@ -1,59 +1,40 @@
|
|
import { useEditor } from "@/modules/editor";
|
|
import { useEditor } from "@/modules/editor";
|
|
import { defineComponent } from "vue";
|
|
import { defineComponent } from "vue";
|
|
-import { object, string } from "vue-types";
|
|
|
|
|
|
+import { string } from "vue-types";
|
|
import { useCompData } from ".";
|
|
import { useCompData } from ".";
|
|
import { View } from "../View";
|
|
import { View } from "../View";
|
|
|
|
+import { useImage } from "./useImage";
|
|
|
|
|
|
export const Component = defineComponent({
|
|
export const Component = defineComponent({
|
|
props: {
|
|
props: {
|
|
compId: string().isRequired,
|
|
compId: string().isRequired,
|
|
- value: object<{ url: string; x: number; y: number; s: number }>(),
|
|
|
|
},
|
|
},
|
|
- emits: ["update:value"],
|
|
|
|
- setup(props, { emit }) {
|
|
|
|
- const comp = props.compId ? useCompData(props.compId) : null;
|
|
|
|
|
|
+ setup(props) {
|
|
|
|
+ const comp = useCompData(props.compId);
|
|
const { store, controls } = useEditor();
|
|
const { store, controls } = useEditor();
|
|
|
|
+ const img = useImage(() => ({ ...comp.value, size: comp.layout.size }));
|
|
|
|
+
|
|
async function changeVal() {
|
|
async function changeVal() {
|
|
|
|
+ if (!store.isEditMode) return;
|
|
const url = await controls.pickCtrl.pickOneImage();
|
|
const url = await controls.pickCtrl.pickOneImage();
|
|
if (!url) return;
|
|
if (!url) return;
|
|
|
|
|
|
- if (comp) {
|
|
|
|
- comp.value.url = url;
|
|
|
|
- comp.value.x = 0;
|
|
|
|
- comp.value.y = 0;
|
|
|
|
- comp.value.s = 1;
|
|
|
|
- } else {
|
|
|
|
- emit("update:value", { url, x: 0, y: 0, s: 1 });
|
|
|
|
- }
|
|
|
|
|
|
+ comp.value.url = url;
|
|
|
|
+ comp.value.x = 0;
|
|
|
|
+ comp.value.y = 0;
|
|
|
|
+ comp.value.s = 1;
|
|
}
|
|
}
|
|
|
|
|
|
- return () => {
|
|
|
|
- const value = comp?.value || props.value;
|
|
|
|
- const scale = value?.s || 1;
|
|
|
|
- const ox = value?.x || 0;
|
|
|
|
- const oy = value?.y || 0;
|
|
|
|
- const objectFit =
|
|
|
|
- scale + "" == "1" && ox + "" == "0" && oy + "" == "0"
|
|
|
|
- ? "cover"
|
|
|
|
- : "contain";
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <View
|
|
|
|
- class="overflow-hidden"
|
|
|
|
- compId={props.compId}
|
|
|
|
- onDblclick={store.isEditMode ? changeVal : undefined}
|
|
|
|
- >
|
|
|
|
- <img
|
|
|
|
- crossorigin="anonymous"
|
|
|
|
- class="pointer-events-none"
|
|
|
|
- style={{
|
|
|
|
- transform: `scale(${scale}) translate(${ox}%,${oy}%)`,
|
|
|
|
- objectFit,
|
|
|
|
- }}
|
|
|
|
- src={value?.url}
|
|
|
|
- />
|
|
|
|
- </View>
|
|
|
|
- );
|
|
|
|
- };
|
|
|
|
|
|
+ return () => (
|
|
|
|
+ <View
|
|
|
|
+ class="overflow-hidden"
|
|
|
|
+ compId={props.compId}
|
|
|
|
+ onDblclick={changeVal}
|
|
|
|
+ >
|
|
|
|
+ <div style={img.style}>
|
|
|
|
+ <img class="w-full h-full pointer-events-none" src={img.url} />
|
|
|
|
+ </div>
|
|
|
|
+ </View>
|
|
|
|
+ );
|
|
},
|
|
},
|
|
});
|
|
});
|