|
@@ -0,0 +1,123 @@
|
|
|
+import { useEditor } from "@/modules/editor";
|
|
|
+import { css } from "@linaria/core";
|
|
|
+import { Button, Divider, InputNumber, Select } from "ant-design-vue";
|
|
|
+import { defineComponent, reactive , effect, watch} from "vue";
|
|
|
+import { any, array } from "vue-types";
|
|
|
+
|
|
|
+import ToolbarsUI from "../../formItems/ToolbarsUI";
|
|
|
+import Slider from "../../formItems/Slider";
|
|
|
+import { ToolbarItem } from "@/modules/editor/objects/Toolbars/default";
|
|
|
+import _ from "lodash";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const PointsComp = defineComponent({
|
|
|
+ props: {
|
|
|
+ value: any<{points: number[][], index: number}>().isRequired
|
|
|
+ },
|
|
|
+ emits: ["change"],
|
|
|
+
|
|
|
+ setup(props, { emit }) {
|
|
|
+ const state = reactive({ index: 0 })
|
|
|
+
|
|
|
+ watch(()=>props.value.index, ()=>{
|
|
|
+ state.index = props.value.index;
|
|
|
+ })
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ const options = props.value.points.map((item, index) => { return { label: "顶点" + (index + 1), value: index } });
|
|
|
+ return (
|
|
|
+ <div class="flex items-center">
|
|
|
+ <Select class="w-82px" value={state.index} options={options} onChange={v => {
|
|
|
+ state.index = v as number;
|
|
|
+ }}>
|
|
|
+ </Select>
|
|
|
+ {
|
|
|
+ props.value.points.length > 0 && <>
|
|
|
+ <span class="ml-10px">X:</span> <Slider class="w-140px" value={props.value.points[state.index][0]} min={0} max={1} step={0.01} onChange={(v) => {
|
|
|
+ const ps = props.value.points.slice(0);
|
|
|
+ ps[state.index][0] = v;
|
|
|
+ emit("change", ps);
|
|
|
+ }} />
|
|
|
+
|
|
|
+ <span class="ml-10px">Y:</span> <Slider class="w-140px" value={props.value.points[state.index][1]} min={0} max={1} step={0.01} onChange={(v) => {
|
|
|
+ const ps = props.value.points.slice(0);
|
|
|
+ ps[state.index][1] = v;
|
|
|
+ emit("change", ps);
|
|
|
+ }} />
|
|
|
+ </>
|
|
|
+ }
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ },
|
|
|
+})
|
|
|
+
|
|
|
+const PolygonToolbar = defineComponent({
|
|
|
+ props: {
|
|
|
+ value: any<{ points: number[][] }>().isRequired,
|
|
|
+ },
|
|
|
+
|
|
|
+ setup(props) {
|
|
|
+ const { actions } = useEditor();
|
|
|
+
|
|
|
+ const toolbarColumns = [
|
|
|
+ {
|
|
|
+ component: () => (
|
|
|
+ <Divider
|
|
|
+ type="vertical"
|
|
|
+ style={{ fontSize: "26px", borderColor: "#1f1f1f" }}
|
|
|
+ />
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ dataIndex: "value.points",
|
|
|
+ component: PointsComp,
|
|
|
+ getValue(points:any, data:any) {
|
|
|
+ return {points, index: data.index};
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ];
|
|
|
+
|
|
|
+ return () => {
|
|
|
+ console.log("prop value------------", props.value);
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div class={[ToolbarStyle, "flex items-center"]}>
|
|
|
+ <ToolbarsUI
|
|
|
+ data={props.value}
|
|
|
+ columns={toolbarColumns}
|
|
|
+ onChange={(e: { dataIndex: string; value: any }) => {
|
|
|
+ _.set(props.value, e.dataIndex,e.value);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ };
|
|
|
+ },
|
|
|
+});
|
|
|
+const ToolbarStyle = css``;
|
|
|
+
|
|
|
+const editState = reactive({
|
|
|
+ value: {},
|
|
|
+ index: 0
|
|
|
+})
|
|
|
+
|
|
|
+const toolbar = new ToolbarItem({
|
|
|
+ component: PolygonToolbar,
|
|
|
+ getVisible: (comp) => !!comp && comp.compKey == "Polygon",
|
|
|
+
|
|
|
+ getValue: (comp)=>{
|
|
|
+ // editState.value = comp.value;
|
|
|
+ effect(()=>{
|
|
|
+ editState.value = comp.value;
|
|
|
+ })
|
|
|
+ return editState;
|
|
|
+ },
|
|
|
+ onClick(comp) {
|
|
|
+ // this.actions.setCompLayer(comp, -1);
|
|
|
+ console.log("click");
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+export {toolbar, editState};
|