|
@@ -17,8 +17,12 @@
|
|
|
{{ group.name }}
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="list" :class="groupType ? 'two-list' : ''">
|
|
|
- <t-collapse v-model:value="activedPanel" @change="onChangeGroupPanel">
|
|
|
+ <div class="list" :class="groupType ? 'two-columns' : ''">
|
|
|
+ <t-collapse
|
|
|
+ v-if="groupType < 2"
|
|
|
+ v-model:value="activedPanel"
|
|
|
+ @change="onChangeGroupPanel"
|
|
|
+ >
|
|
|
<t-collapse-panel
|
|
|
:value="item.name"
|
|
|
:header="item.name"
|
|
@@ -36,14 +40,15 @@
|
|
|
<div
|
|
|
class="graphic"
|
|
|
v-for="elem in item.list"
|
|
|
- :draggable="!groupType || groupType >= 10"
|
|
|
+ :draggable="elem.draggable !== false"
|
|
|
@dragstart="dragStart($event, elem)"
|
|
|
@drag="drag($event, elem)"
|
|
|
@dragend="dragEnd()"
|
|
|
@click.stop="dragStart($event, elem)"
|
|
|
@dblclick.stop="open(elem)"
|
|
|
+ :title="elem.draggable === false ? '双击打开' : '拖拽到画布'"
|
|
|
>
|
|
|
- <t-image v-if="elem.image" :src="elem.image" />
|
|
|
+ <t-image v-if="elem.image" :src="elem.image" :lazy="true" />
|
|
|
<div class="svg-box" v-else-if="elem.svg" v-html="elem.svg" />
|
|
|
<svg v-else class="l-icon" aria-hidden="true">
|
|
|
<use :xlink:href="'#' + elem.icon"></use>
|
|
@@ -63,6 +68,7 @@
|
|
|
</template>
|
|
|
</t-collapse-panel>
|
|
|
</t-collapse>
|
|
|
+ <template v-else></template>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -74,8 +80,7 @@ import { useRouter } from 'vue-router';
|
|
|
import axios from 'axios';
|
|
|
|
|
|
import { cases, shapes, charts, formComponents } from '@/services/defaults';
|
|
|
-import { getPngFolders, getPngs } from '@/services/png';
|
|
|
-import { getIconFolders, getIcons } from '@/services/icons';
|
|
|
+import { getFolders, getFiles, getIcons } from '@/services/png';
|
|
|
import { getComponents, getComponentsList, getLe5leV } from '@/services/api';
|
|
|
import { convertPen } from '@/services/upgrade';
|
|
|
import { deepClone } from '@meta2d/core';
|
|
@@ -84,13 +89,14 @@ import { autoSave, delAttrs } from '@/services/common';
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
-const activedGroup = ref('图形');
|
|
|
+const activedGroup = ref('');
|
|
|
|
|
|
const groups = reactive([
|
|
|
{
|
|
|
icon: 'desktop',
|
|
|
name: '场景',
|
|
|
key: '',
|
|
|
+ class: 'tow',
|
|
|
},
|
|
|
{
|
|
|
icon: 'root-list',
|
|
@@ -103,7 +109,7 @@ const groups = reactive([
|
|
|
key: 'chart',
|
|
|
},
|
|
|
{
|
|
|
- icon: 'control-platform',
|
|
|
+ icon: 'relativity',
|
|
|
name: '控件',
|
|
|
key: '',
|
|
|
},
|
|
@@ -113,8 +119,8 @@ const groups = reactive([
|
|
|
key: '',
|
|
|
},
|
|
|
{
|
|
|
- icon: 'file-icon',
|
|
|
- name: '图标',
|
|
|
+ icon: 'control-platform',
|
|
|
+ name: '图元',
|
|
|
key: '',
|
|
|
},
|
|
|
{
|
|
@@ -132,9 +138,11 @@ const subGroups = ref<any[]>([]);
|
|
|
const groupType = ref(0);
|
|
|
const activedPanel = ref([]);
|
|
|
|
|
|
-const templates = reactive<any>({});
|
|
|
-const materials = reactive([]);
|
|
|
-const icons = reactive([]);
|
|
|
+const caseCaches = reactive<any>({});
|
|
|
+const templates = ref([]);
|
|
|
+const materials = ref([]);
|
|
|
+const pngs = ref([]);
|
|
|
+const icons = ref([]);
|
|
|
|
|
|
const groupChange = async (name: string) => {
|
|
|
activedPanel.value = [];
|
|
@@ -145,27 +153,20 @@ const groupChange = async (name: string) => {
|
|
|
groupType.value = 1;
|
|
|
subGroups.value = cases;
|
|
|
subGroups.value[0].loading = true;
|
|
|
- if (!templates[name + cases[0].name]) {
|
|
|
- templates[name + cases[0].name] = await getCaseProjects(
|
|
|
+ if (!caseCaches[name + cases[0].name]) {
|
|
|
+ caseCaches[name + cases[0].name] = await getCaseProjects(
|
|
|
name,
|
|
|
cases[0].name
|
|
|
);
|
|
|
}
|
|
|
- subGroups.value[0].list = templates[name + cases[0].name];
|
|
|
+ subGroups.value[0].list = caseCaches[name + cases[0].name];
|
|
|
subGroups.value[0].loading = false;
|
|
|
break;
|
|
|
case '模板':
|
|
|
groupType.value = 2;
|
|
|
- subGroups.value = cases;
|
|
|
- subGroups.value[0].loading = true;
|
|
|
- if (!templates[name + cases[0].name]) {
|
|
|
- templates[name + cases[0].name] = await getCaseProjects(
|
|
|
- name,
|
|
|
- cases[0].name
|
|
|
- );
|
|
|
+ if (!templates.value.length) {
|
|
|
}
|
|
|
- subGroups.value[0].list = templates[name + cases[0].name];
|
|
|
- subGroups.value[0].loading = false;
|
|
|
+ subGroups.value = templates.value;
|
|
|
break;
|
|
|
case '图表':
|
|
|
subGroups.value = charts;
|
|
@@ -174,23 +175,29 @@ const groupChange = async (name: string) => {
|
|
|
subGroups.value = formComponents;
|
|
|
break;
|
|
|
case '素材':
|
|
|
- if (!materials.length) {
|
|
|
- materials.push(...(await getPngFolders()));
|
|
|
+ groupType.value = 2;
|
|
|
+ if (!materials.value.length) {
|
|
|
}
|
|
|
- subGroups.value = materials;
|
|
|
+ subGroups.value = materials.value;
|
|
|
break;
|
|
|
- case '图标':
|
|
|
- if (!icons.length) {
|
|
|
- icons.push(...(await getIconFolders()));
|
|
|
+ case '图元':
|
|
|
+ subGroups.value = [];
|
|
|
+ if (!pngs.value.length) {
|
|
|
+ pngs.value = await getFolders('png');
|
|
|
}
|
|
|
- subGroups.value = icons;
|
|
|
+ subGroups.value.push(...pngs.value);
|
|
|
+ if (!icons.value.length) {
|
|
|
+ icons.value = await getFolders('svg');
|
|
|
+ }
|
|
|
+ subGroups.value.push(...icons.value);
|
|
|
+ onChangeGroupPanel([subGroups.value[0].name]);
|
|
|
break;
|
|
|
case '图形':
|
|
|
subGroups.value = shapes;
|
|
|
break;
|
|
|
case '我的':
|
|
|
subGroups.value = await getPrivateCommponents();
|
|
|
- groupType.value = 10;
|
|
|
+ groupType.value = 1;
|
|
|
break;
|
|
|
}
|
|
|
activedPanel.value = [subGroups.value[0].name];
|
|
@@ -209,6 +216,9 @@ const getCaseProjects = async (name: string, group: string) => {
|
|
|
if (!ret) {
|
|
|
return [];
|
|
|
}
|
|
|
+ for (const item of ret.list) {
|
|
|
+ item.draggable = false;
|
|
|
+ }
|
|
|
return ret.list;
|
|
|
};
|
|
|
|
|
@@ -249,40 +259,10 @@ const getPrivateCommponents = async () => {
|
|
|
return list;
|
|
|
};
|
|
|
|
|
|
-watch(
|
|
|
- () => activedPanel.value,
|
|
|
- async (newV: any[], oldV: any[]) => {
|
|
|
- const newOpen: any = [];
|
|
|
- for (let v of newV) {
|
|
|
- !oldV.includes(v) && newOpen.push(v);
|
|
|
- }
|
|
|
- if (newOpen.length === 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (activedGroup.value === '素材') {
|
|
|
- const data: any = materials.find((item) => item.name === newOpen[0]);
|
|
|
- if (!data.list || data.list.length === 0) {
|
|
|
- data.list = await getPngs(
|
|
|
- globalThis.folderJson ? data.pinyin : data.name
|
|
|
- );
|
|
|
- subGroups.value = deepClone(materials);
|
|
|
- }
|
|
|
- } else if (activedGroup.value === '图标') {
|
|
|
- const data: any = icons.find((item) => item.name === newOpen[0]);
|
|
|
- if (!data.list || data.list.length === 0) {
|
|
|
- data.list = await getIcons(
|
|
|
- globalThis.folderJson ? data.pinyin : data.name
|
|
|
- );
|
|
|
- subGroups.value = deepClone(icons);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-);
|
|
|
-
|
|
|
const dragStart = async (event: DragEvent | MouseEvent, item: any) => {
|
|
|
if (
|
|
|
- (groupType.value > 0 && groupType.value < 10) ||
|
|
|
!item ||
|
|
|
+ item.draggable === false ||
|
|
|
(event instanceof DragEvent && !event.dataTransfer)
|
|
|
) {
|
|
|
return;
|
|
@@ -363,27 +343,45 @@ const open = async (item: any) => {
|
|
|
};
|
|
|
|
|
|
const onChangeGroupPanel = async (val: string[]) => {
|
|
|
- if (groupType.value > 0 && groupType.value < 10 && val?.length) {
|
|
|
+ if (val?.length) {
|
|
|
for (const name of val) {
|
|
|
- if (
|
|
|
- !templates[activedGroup.value + name] ||
|
|
|
- !templates[activedGroup.value + name].length
|
|
|
- ) {
|
|
|
- for (const item of subGroups.value) {
|
|
|
- if (item.name === name) {
|
|
|
- item.loading = true;
|
|
|
+ switch (activedGroup.value) {
|
|
|
+ case '场景':
|
|
|
+ if (
|
|
|
+ !caseCaches[activedGroup.value + name] ||
|
|
|
+ !caseCaches[activedGroup.value + name].length
|
|
|
+ ) {
|
|
|
+ for (const item of subGroups.value) {
|
|
|
+ if (item.name === name) {
|
|
|
+ item.loading = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ caseCaches[activedGroup.value + name] = await getCaseProjects(
|
|
|
+ activedGroup.value,
|
|
|
+ name
|
|
|
+ );
|
|
|
+ for (const item of subGroups.value) {
|
|
|
+ if (item.name === name) {
|
|
|
+ item.list = caseCaches[activedGroup.value + name];
|
|
|
+ item.loading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- templates[activedGroup.value + name] = await getCaseProjects(
|
|
|
- activedGroup.value,
|
|
|
- name
|
|
|
- );
|
|
|
- for (const item of subGroups.value) {
|
|
|
- if (item.name === name) {
|
|
|
- item.list = templates[activedGroup.value + name];
|
|
|
- item.loading = false;
|
|
|
+ break;
|
|
|
+ case '图元':
|
|
|
+ for (const item of subGroups.value) {
|
|
|
+ if (item.name === name && !item.list.length) {
|
|
|
+ item.loading = true;
|
|
|
+ if (item.svg) {
|
|
|
+ item.list = await getIcons(item.folder);
|
|
|
+ } else {
|
|
|
+ console.log(item.folder + item.name);
|
|
|
+ item.list = await getFiles(item.folder + item.name);
|
|
|
+ }
|
|
|
+ item.loading = false;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -455,6 +453,7 @@ onUnmounted(() => {
|
|
|
}
|
|
|
|
|
|
:deep(.t-collapse) {
|
|
|
+ min-height: 100vh;
|
|
|
border: none;
|
|
|
}
|
|
|
:deep(.t-collapse-panel__header) {
|
|
@@ -477,6 +476,14 @@ onUnmounted(() => {
|
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
|
grid-row-gap: 20px;
|
|
|
}
|
|
|
+
|
|
|
+ :deep(.t-loading--center) {
|
|
|
+ width: 100px;
|
|
|
+ .t-loading__text {
|
|
|
+ margin-left: 8px;
|
|
|
+ height: 24px;
|
|
|
+ }
|
|
|
+ }
|
|
|
.graphic {
|
|
|
position: relative;
|
|
|
|
|
@@ -549,7 +556,7 @@ onUnmounted(() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- .two-list {
|
|
|
+ .two-columns {
|
|
|
:deep(.t-collapse-panel__content) {
|
|
|
padding: 0 8px;
|
|
|
grid-template-columns: 116px 116px;
|