|
@@ -1,39 +1,124 @@
|
|
|
import { useEditor } from "@/modules/editor";
|
|
|
-import { DesignComp } from "@/modules/editor/defines/DesignTemp/DesignComp";
|
|
|
+import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
|
|
|
+import { css } from "@linaria/core";
|
|
|
import { useReactive } from "@queenjs/use";
|
|
|
import { Tree } from "ant-design-vue";
|
|
|
import { defineComponent } from "vue";
|
|
|
+import { string } from "vue-types";
|
|
|
import { CompUI } from "../../../CompUI";
|
|
|
|
|
|
+type TreeItem = {
|
|
|
+ key: string;
|
|
|
+ title: string;
|
|
|
+ value: string;
|
|
|
+ children: TreeItem[];
|
|
|
+};
|
|
|
+
|
|
|
export const CompTree = defineComponent({
|
|
|
setup() {
|
|
|
const { store, actions, helper } = useEditor();
|
|
|
const state = useReactive(() => ({
|
|
|
treeData() {
|
|
|
- const { pageCompIds } = store;
|
|
|
const rootComp = helper.findRootComp();
|
|
|
+
|
|
|
+ function getCompChildren(ids: string[]): TreeItem[] {
|
|
|
+ return ids.map((id) => {
|
|
|
+ const comp = helper.findComp(id) as DesignComp;
|
|
|
+ return {
|
|
|
+ key: comp.id,
|
|
|
+ title: CompUI[comp.compKey].options.name,
|
|
|
+ value: comp.id,
|
|
|
+ children: getCompChildren(helper.getCompChildIds(comp)),
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
return [
|
|
|
{
|
|
|
key: rootComp?.id || "",
|
|
|
title: "页面",
|
|
|
- children: pageCompIds.map((id) => {
|
|
|
- const comp = helper.findComp(id) as DesignComp;
|
|
|
- return {
|
|
|
- key: comp.id,
|
|
|
- title: CompUI[comp.compKey].options.name,
|
|
|
- value: comp.id,
|
|
|
- };
|
|
|
- }),
|
|
|
+ children: getCompChildren(store.pageCompIds),
|
|
|
},
|
|
|
];
|
|
|
},
|
|
|
}));
|
|
|
return () => (
|
|
|
<Tree
|
|
|
+ class={treeStyle}
|
|
|
treeData={state.treeData}
|
|
|
selectedKeys={[store.currCompId]}
|
|
|
+ blockNode={true}
|
|
|
onSelect={(ids) => actions.pickComp(ids[0] as string)}
|
|
|
- ></Tree>
|
|
|
+ >
|
|
|
+ {{
|
|
|
+ title: (data: any) => {
|
|
|
+ return <CompNode title={data.title} id={data.key} />;
|
|
|
+ },
|
|
|
+ }}
|
|
|
+ </Tree>
|
|
|
);
|
|
|
},
|
|
|
});
|
|
|
+
|
|
|
+const CompNode = defineComponent({
|
|
|
+ props: {
|
|
|
+ id: string().isRequired,
|
|
|
+ title: string().isRequired,
|
|
|
+ },
|
|
|
+ setup(props) {
|
|
|
+ const editor = useEditor();
|
|
|
+ const { config, helper } = editor;
|
|
|
+ const comp = helper.findComp(props.id);
|
|
|
+ return () => {
|
|
|
+ if (!comp) return;
|
|
|
+ const compOpts = CompUI[comp.compKey].options;
|
|
|
+ const actions =
|
|
|
+ config.treeNodeActions[comp.compKey] || config.treeNodeActions.default;
|
|
|
+ const thumbnail =
|
|
|
+ comp.compKey === "Image" ? comp.value.url : compOpts.thumbnail;
|
|
|
+ return (
|
|
|
+ <div class={nodeStyle}>
|
|
|
+ <img src={thumbnail} />
|
|
|
+ <span class="flex-1">{props.title}</span>
|
|
|
+ <span class="space-x-4px">
|
|
|
+ {actions.map((action) => {
|
|
|
+ if (action.disable?.call(editor, comp)) return;
|
|
|
+ return (
|
|
|
+ <action.component
|
|
|
+ class="p-4px"
|
|
|
+ key={comp.id}
|
|
|
+ value={action.getValue?.(comp)}
|
|
|
+ onClick={(e: MouseEvent) => {
|
|
|
+ e.stopPropagation();
|
|
|
+ action.onClick.call(editor, comp);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ };
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+const treeStyle = css`
|
|
|
+ .ant-tree-switcher {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+ align-items: center;
|
|
|
+ }
|
|
|
+`;
|
|
|
+
|
|
|
+const nodeStyle = css`
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ padding: 6px;
|
|
|
+ @apply rounded;
|
|
|
+ > img {
|
|
|
+ width: 24px;
|
|
|
+ height: 24px;
|
|
|
+ margin-right: 6px;
|
|
|
+ object-fit: contain;
|
|
|
+ }
|
|
|
+`;
|