|
@@ -10,7 +10,7 @@
|
|
|
<div class="sub-groups">
|
|
|
<div
|
|
|
v-for="group in groups"
|
|
|
- :class="group.active ? 'active' : ''"
|
|
|
+ :class="group.name === activeGroup ? 'active' : ''"
|
|
|
@click="groupChange(group.name)"
|
|
|
>
|
|
|
<t-icon :name="group.icon" />
|
|
@@ -18,129 +18,121 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="list">
|
|
|
- <div
|
|
|
- class="show-item"
|
|
|
- v-for="item in showList"
|
|
|
- :draggable="true"
|
|
|
- @dragstart="dragStart($event, item)"
|
|
|
- @drag="drag($event, item)"
|
|
|
- @dragend="dragEnd()"
|
|
|
- >
|
|
|
- <t-image
|
|
|
- v-if="item.image"
|
|
|
- :src="item.image"
|
|
|
- fit="cover"
|
|
|
- :style="{ width: '88px', height: '88px' }"
|
|
|
- />
|
|
|
- <i v-else class="t-icon" :class="item.icon"></i>
|
|
|
- <p>{{ item.name }}</p>
|
|
|
- </div>
|
|
|
+ <t-collapse @change="handlePanelChange">
|
|
|
+ <t-collapse-panel
|
|
|
+ :value="item.name"
|
|
|
+ :header="item.name"
|
|
|
+ v-for="item in showList"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ class="show-item"
|
|
|
+ v-for="iItem in item.list"
|
|
|
+ :draggable="true"
|
|
|
+ @dragstart="dragStart($event, iItem)"
|
|
|
+ @drag="drag($event, iItem)"
|
|
|
+ @dragend="dragEnd()"
|
|
|
+ >
|
|
|
+ <t-image v-if="iItem.image" :src="iItem.image" fit="cover" />
|
|
|
+ <!-- <i v-else class="t-icon" :class="iItem.icon"></i> -->
|
|
|
+ <svg v-else class="l-icon" aria-hidden="true">
|
|
|
+ <use :xlink:href="'#' + iItem.icon"></use>
|
|
|
+ </svg>
|
|
|
+ <p>{{ iItem.name }}</p>
|
|
|
+ </div>
|
|
|
+ </t-collapse-panel>
|
|
|
+ </t-collapse>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { onMounted, onUnmounted, reactive } from 'vue';
|
|
|
+import { onMounted, onUnmounted, reactive, ref } from "vue";
|
|
|
+import { shapeLib, chartLib, formLib } from "@/services/defaults";
|
|
|
+import { getPngFolders } from "@/services/png";
|
|
|
|
|
|
+const activeGroup = ref("图形");
|
|
|
const groups = reactive([
|
|
|
{
|
|
|
- icon: 'desktop',
|
|
|
- name: '场景',
|
|
|
- key: '',
|
|
|
- active: false,
|
|
|
+ icon: "desktop",
|
|
|
+ name: "场景",
|
|
|
+ key: "",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ icon: "root-list",
|
|
|
+ name: "模板",
|
|
|
+ key: "",
|
|
|
},
|
|
|
{
|
|
|
- icon: 'root-list',
|
|
|
- name: '模板',
|
|
|
- key: '',
|
|
|
- active: false,
|
|
|
+ icon: "chart",
|
|
|
+ name: "图表",
|
|
|
+ key: "chart",
|
|
|
},
|
|
|
{
|
|
|
- icon: 'chart',
|
|
|
- name: '图表',
|
|
|
- key: '',
|
|
|
- active: false,
|
|
|
+ icon: "control-platform",
|
|
|
+ name: "控件",
|
|
|
+ key: "",
|
|
|
},
|
|
|
{
|
|
|
- icon: 'control-platform',
|
|
|
- name: '控件',
|
|
|
- key: '',
|
|
|
- active: false,
|
|
|
+ icon: "image",
|
|
|
+ name: "素材",
|
|
|
+ key: "",
|
|
|
},
|
|
|
{
|
|
|
- icon: 'file-icon',
|
|
|
- name: '图标',
|
|
|
- key: '',
|
|
|
- active: false,
|
|
|
+ icon: "file-icon",
|
|
|
+ name: "图标",
|
|
|
+ key: "",
|
|
|
},
|
|
|
{
|
|
|
- icon: 'chart-bubble',
|
|
|
- name: '图形',
|
|
|
- key: '',
|
|
|
- active: true,
|
|
|
+ icon: "chart-bubble",
|
|
|
+ name: "图形",
|
|
|
+ key: "shape",
|
|
|
},
|
|
|
{
|
|
|
- icon: 'app',
|
|
|
- name: '我的',
|
|
|
- key: '',
|
|
|
- active: false,
|
|
|
+ icon: "app",
|
|
|
+ name: "我的",
|
|
|
+ key: "",
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
-const groupChange = (name: string) => {
|
|
|
- if (name === '图形') {
|
|
|
+const getSceneLib = () => {};
|
|
|
+
|
|
|
+const getCommponentsLib = () => {};
|
|
|
+
|
|
|
+const getMaterialLib = async () => {
|
|
|
+ const [pngs] = await Promise.all([getPngFolders()]);
|
|
|
+ console.log("png", pngs);
|
|
|
+ return pngs;
|
|
|
+};
|
|
|
+let materialLib: any[] = [];
|
|
|
+
|
|
|
+const groupChange = async (name: string) => {
|
|
|
+ activeGroup.value = name;
|
|
|
+ switch (name) {
|
|
|
+ case "图形":
|
|
|
+ showList.value = shapeLib;
|
|
|
+ break;
|
|
|
+ case "图表":
|
|
|
+ showList.value = chartLib;
|
|
|
+ break;
|
|
|
+ case "控件":
|
|
|
+ showList.value = formLib;
|
|
|
+ break;
|
|
|
+ case "素材":
|
|
|
+ if (materialLib.length === 0) {
|
|
|
+ materialLib = await getMaterialLib();
|
|
|
+ }
|
|
|
+ console.log(materialLib);
|
|
|
+ showList.value = materialLib;
|
|
|
+ break;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-const showList = [
|
|
|
- {
|
|
|
- name: 'square',
|
|
|
- icon: 't-icon t-rect',
|
|
|
- id: '',
|
|
|
- data: {
|
|
|
- text: '正方形',
|
|
|
- width: 100,
|
|
|
- height: 100,
|
|
|
- name: 'square',
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'rectangle',
|
|
|
- icon: 't-icon t-rectangle',
|
|
|
- id: 2,
|
|
|
- data: {
|
|
|
- text: '圆角矩形',
|
|
|
- width: 200,
|
|
|
- height: 50,
|
|
|
- borderRadius: 0.1,
|
|
|
- name: 'rectangle',
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'circle',
|
|
|
- icon: 't-icon t-circle',
|
|
|
- image: '',
|
|
|
- id: 3,
|
|
|
- data: {
|
|
|
- text: '圆',
|
|
|
- width: 100,
|
|
|
- height: 100,
|
|
|
- name: 'circle',
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'triangle',
|
|
|
- icon: 't-icon t-triangle',
|
|
|
- id: 4,
|
|
|
- data: {
|
|
|
- text: '三角形',
|
|
|
- width: 100,
|
|
|
- height: 100,
|
|
|
- name: 'triangle',
|
|
|
- },
|
|
|
- },
|
|
|
-];
|
|
|
+const showList = ref<any[]>([]);
|
|
|
+
|
|
|
+const handlePanelChange = (e) => {
|
|
|
+ console.log("change", e);
|
|
|
+};
|
|
|
|
|
|
const dragStart = (event: DragEvent, item: any) => {
|
|
|
if (!item || !event.dataTransfer) {
|
|
@@ -148,7 +140,7 @@ const dragStart = (event: DragEvent, item: any) => {
|
|
|
}
|
|
|
|
|
|
event.dataTransfer.setData(
|
|
|
- 'Meta2d',
|
|
|
+ "Meta2d",
|
|
|
JSON.stringify(item.componentData || item.data)
|
|
|
);
|
|
|
event.stopPropagation();
|
|
@@ -167,13 +159,14 @@ const dragend = (event: any) => {
|
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
|
- document.removeEventListener('dragstart', dragstart);
|
|
|
- document.removeEventListener('dragend', dragend);
|
|
|
+ groupChange("图形");
|
|
|
+ document.removeEventListener("dragstart", dragstart);
|
|
|
+ document.removeEventListener("dragend", dragend);
|
|
|
});
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
- document.addEventListener('dragstart', dragstart, false);
|
|
|
- document.addEventListener('dragend', dragend, false);
|
|
|
+ document.addEventListener("dragstart", dragstart, false);
|
|
|
+ document.addEventListener("dragend", dragend, false);
|
|
|
});
|
|
|
</script>
|
|
|
<style lang="postcss" scoped>
|
|
@@ -221,32 +214,56 @@ onUnmounted(() => {
|
|
|
}
|
|
|
|
|
|
.list {
|
|
|
- background-color: var(--color-background-active);
|
|
|
- padding: 12px;
|
|
|
- display: grid;
|
|
|
- grid-template-columns: 112px 112px;
|
|
|
- grid-template-rows: 142px;
|
|
|
+ overflow-y: auto;
|
|
|
+ max-height: calc(100vh - 100px);
|
|
|
+ :deep(.t-collapse) {
|
|
|
+ border: 0px;
|
|
|
+ }
|
|
|
+ :deep(.t-collapse-panel__header) {
|
|
|
+ border: 0px;
|
|
|
+ }
|
|
|
|
|
|
+ :deep(.t-collapse-panel__body) {
|
|
|
+ border: 0px;
|
|
|
+ }
|
|
|
+ :deep(.t-collapse-panel__content) {
|
|
|
+ background-color: var(--color-background-active);
|
|
|
+ /* padding: 12px; */
|
|
|
+ padding: 0px;
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: 61px 61px 61px 61px;
|
|
|
+ grid-template-rows: 90px;
|
|
|
+ padding-bottom: 20px;
|
|
|
+ }
|
|
|
.show-item {
|
|
|
- padding: 12px;
|
|
|
+ /* padding: 10px; */
|
|
|
+
|
|
|
p {
|
|
|
- margin-top: 10px;
|
|
|
- height: 20px;
|
|
|
- line-height: 20px;
|
|
|
+ /* margin-top: 10px; */
|
|
|
+ height: 10px;
|
|
|
+ line-height: 10px;
|
|
|
text-align: center;
|
|
|
- font-size: 14px;
|
|
|
+ font-size: 12px;
|
|
|
}
|
|
|
|
|
|
- i {
|
|
|
+ /* i {
|
|
|
background-color: #fff;
|
|
|
border-radius: 4px;
|
|
|
- height: 88px;
|
|
|
- width: 88px;
|
|
|
- }
|
|
|
+ height: 40px;
|
|
|
+ width: 40px;
|
|
|
+ margin: 10px;
|
|
|
+ } */
|
|
|
.t-image {
|
|
|
background-color: #fff;
|
|
|
border-radius: 4px;
|
|
|
}
|
|
|
+
|
|
|
+ svg {
|
|
|
+ color: var(--color);
|
|
|
+ height: 32px;
|
|
|
+ width: 32px;
|
|
|
+ margin: 10px 14px;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|