Graphics.vue 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. <template>
  2. <div class="graphics">
  3. <div class="input-search">
  4. <div class="btn">
  5. <t-icon name="search" />
  6. </div>
  7. <t-input placeholder="搜索" />
  8. </div>
  9. <div class="groups-panel">
  10. <div class="groups">
  11. <div
  12. v-for="group in groups"
  13. :class="group.name === activedGroup ? 'active' : ''"
  14. @click="groupChange(group.name)"
  15. >
  16. <t-icon :name="group.icon" />
  17. {{ group.name }}
  18. </div>
  19. </div>
  20. <div class="list" :class="groupType ? 'two-columns' : ''">
  21. <div v-if="activedGroup === '我的'" class="px-16 mt-12 mb-8 ml-4">
  22. <a @click="onCreateFolder">+ 新建文件夹</a>
  23. </div>
  24. <t-collapse
  25. v-if="groupType < 2"
  26. v-model:value="activedPanel"
  27. @change="onChangeGroupPanel"
  28. >
  29. <t-collapse-panel
  30. :value="item.name"
  31. v-for="item in subGroups"
  32. :key="item.name"
  33. >
  34. <template #header>
  35. <div class="flex middle mr-8">
  36. <div v-if="item.edited" @click.stop>
  37. <t-input
  38. v-model="item.label"
  39. style="width: 140px"
  40. @blur="createFoder"
  41. @enter="createFoder"
  42. @keyup="onKeyHeader"
  43. />
  44. </div>
  45. <div v-else class="ellipsis" style="width: 140px">
  46. {{ item.name }}
  47. </div>
  48. </div>
  49. </template>
  50. <template #headerRightContent v-if="item.canEdited">
  51. <t-space size="small" @click.stop>
  52. <t-icon
  53. name="edit"
  54. class="hover mr-4"
  55. @click="onEditHeader(item)"
  56. />
  57. <t-popconfirm
  58. content="确认删除该文件夹吗"
  59. placement="left"
  60. @confirm=""
  61. >
  62. <t-icon name="delete" class="hover" />
  63. </t-popconfirm>
  64. </t-space>
  65. </template>
  66. <div v-if="item.loading">
  67. <t-loading
  68. text="加载中..."
  69. size="small"
  70. style="margin-left: 32px; margin-bottom: 4px"
  71. />
  72. </div>
  73. <template v-else>
  74. <div
  75. class="graphic"
  76. v-for="elem in item.list"
  77. :draggable="true"
  78. @dragstart="dragStart($event, elem)"
  79. @click.prevent="dragStart($event, elem)"
  80. @dblclick.stop="open(elem)"
  81. @contextmenu="onContextMenu($event, item, elem)"
  82. >
  83. <t-image
  84. v-if="elem.image"
  85. :src="elem.image"
  86. :lazy="true"
  87. fit="contain"
  88. />
  89. <div class="svg-box" v-else-if="elem.svg" v-html="elem.svg" />
  90. <svg v-else class="l-icon" aria-hidden="true">
  91. <use :xlink:href="'#' + elem.icon"></use>
  92. </svg>
  93. <p :title="elem.name">{{ elem.name }}</p>
  94. <div class="price" v-if="elem.price > 0">
  95. ¥{{ elem.price }}
  96. </div>
  97. </div>
  98. <div
  99. v-if="!item.list || !item.list.length"
  100. class="gray center"
  101. style="white-space: nowrap; margin-left: 32px"
  102. >
  103. 暂无数据,待更新
  104. </div>
  105. </template>
  106. </t-collapse-panel>
  107. </t-collapse>
  108. <div v-else class="t-collapse-panel__content" style="padding: 8px">
  109. <div
  110. class="graphic"
  111. v-for="elem in subGroups"
  112. :draggable="true"
  113. @dragstart="dragStart($event, elem)"
  114. @click.stop="dragStart($event, elem)"
  115. @dblclick.stop="open(elem)"
  116. >
  117. <t-image
  118. v-if="elem.image"
  119. :src="elem.image"
  120. :lazy="true"
  121. fit="contain"
  122. />
  123. <div class="svg-box" v-else-if="elem.svg" v-html="elem.svg" />
  124. <svg v-else class="l-icon" aria-hidden="true">
  125. <use :xlink:href="'#' + elem.icon"></use>
  126. </svg>
  127. <p :title="elem.name">{{ elem.name }}</p>
  128. <div class="price" v-if="elem.price > 0">¥{{ elem.price }}</div>
  129. </div>
  130. <div
  131. v-if="!subGroups.length"
  132. class="gray center"
  133. style="white-space: nowrap; margin-left: 32px"
  134. >
  135. 暂无数据,待更新
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. <div
  141. class="context-menu-box"
  142. ref="contextmenuDom"
  143. v-if="contextmenu.visible"
  144. tabindex="0"
  145. :style="contextmenu.style"
  146. @blur="contextmenu.visible = false"
  147. >
  148. <t-menu class="context-menu" @change="onMenu" expandType="popup">
  149. <t-submenu
  150. value="move"
  151. title="移动到"
  152. v-if="contextmenu.subMenus.length"
  153. :disabled="!contextmenu.component.component"
  154. >
  155. <t-menu-item
  156. v-for="subMenu in contextmenu.subMenus"
  157. :value="'move:' + subMenu.name"
  158. >
  159. {{ subMenu.name }}
  160. </t-menu-item>
  161. </t-submenu>
  162. <t-menu-item value="edit"> 编辑 </t-menu-item>
  163. <t-menu-item value="del" :disabled="!contextmenu.component.component">
  164. 删除
  165. </t-menu-item>
  166. </t-menu>
  167. </div>
  168. <t-dialog
  169. v-if="delDialog.show"
  170. theme="danger"
  171. header="删除"
  172. :visible="true"
  173. @close="delDialog.show = false"
  174. @confirm="delComponet"
  175. >
  176. 确定删除该数据吗?删除后不可恢复!
  177. </t-dialog>
  178. </div>
  179. </template>
  180. <script lang="ts" setup>
  181. import { onMounted, onUnmounted, reactive, ref } from 'vue';
  182. import { useRouter } from 'vue-router';
  183. import axios from 'axios';
  184. import { cases, shapes, formComponents } from '@/services/defaults';
  185. import { charts } from '@/services/echarts';
  186. import { getFolders, getFiles, getIcons } from '@/services/png';
  187. import {
  188. getComponents,
  189. getComponentsList,
  190. getLe5leV,
  191. updateCollection,
  192. } from '@/services/api';
  193. import { convertPen } from '@/services/upgrade';
  194. import { deepClone } from '@meta2d/core';
  195. import { isGif } from '@/services/utils';
  196. import { autoSave, delAttrs } from '@/services/common';
  197. import { MessagePlugin } from 'tdesign-vue-next';
  198. const router = useRouter();
  199. const activedGroup = ref('');
  200. const groups = reactive([
  201. {
  202. icon: 'desktop',
  203. name: '场景',
  204. key: '',
  205. class: 'tow',
  206. },
  207. {
  208. icon: 'root-list',
  209. name: '模板',
  210. key: '',
  211. },
  212. {
  213. icon: 'chart',
  214. name: '图表',
  215. key: 'chart',
  216. },
  217. {
  218. icon: 'image',
  219. name: '素材',
  220. key: '',
  221. },
  222. {
  223. icon: 'control-platform',
  224. name: '图元',
  225. key: '',
  226. },
  227. {
  228. icon: 'relativity',
  229. name: '控件',
  230. key: '',
  231. },
  232. {
  233. icon: 'chart-bubble',
  234. name: '图形',
  235. key: 'shape',
  236. },
  237. {
  238. icon: 'app',
  239. name: '我的',
  240. key: '',
  241. },
  242. ]);
  243. const subGroups = ref<any[]>([]);
  244. const groupType = ref(0);
  245. const activedPanel = ref([]);
  246. const caseCaches = reactive<any>({});
  247. const templates = ref([]);
  248. const materials = ref([]);
  249. const pngs = ref([]);
  250. const icons = ref([]);
  251. let dropped = false;
  252. const groupChange = async (name: string) => {
  253. activedPanel.value = [];
  254. activedGroup.value = name;
  255. groupType.value = 0;
  256. switch (name) {
  257. case '场景':
  258. groupType.value = 1;
  259. subGroups.value = cases;
  260. subGroups.value[0].loading = true;
  261. if (!caseCaches[name + cases[0].name]) {
  262. caseCaches[name + cases[0].name] = await getCaseProjects(
  263. name,
  264. cases[0].name
  265. );
  266. }
  267. subGroups.value[0].list = caseCaches[name + cases[0].name];
  268. subGroups.value[0].loading = false;
  269. break;
  270. case '模板':
  271. groupType.value = 2;
  272. if (!templates.value.length) {
  273. templates.value = await getCaseProjects(name);
  274. }
  275. subGroups.value = templates.value;
  276. break;
  277. case '图表':
  278. subGroups.value = charts;
  279. break;
  280. case '控件':
  281. subGroups.value = formComponents;
  282. break;
  283. case '素材':
  284. groupType.value = 2;
  285. if (!materials.value.length) {
  286. materials.value = await getFiles('material/');
  287. }
  288. subGroups.value = materials.value;
  289. break;
  290. case '图元':
  291. subGroups.value = [];
  292. if (!pngs.value.length) {
  293. pngs.value = await getFolders('png');
  294. }
  295. subGroups.value.push(...pngs.value);
  296. if (!icons.value.length) {
  297. icons.value = await getFolders('svg');
  298. }
  299. subGroups.value.push(...icons.value);
  300. onChangeGroupPanel([subGroups.value[0].name]);
  301. break;
  302. case '图形':
  303. subGroups.value = shapes;
  304. break;
  305. case '我的':
  306. subGroups.value = await getPrivateGroups();
  307. groupType.value = 1;
  308. onChangeGroupPanel([subGroups.value[0].name]);
  309. break;
  310. }
  311. activedPanel.value = [subGroups.value[0].name];
  312. };
  313. const getCaseProjects = async (name: string, group?: string) => {
  314. const query: any = { tags: name };
  315. if (group) {
  316. query.case = group;
  317. }
  318. const ret: any = await axios.post(
  319. '/api/data/le5leV/list?current=1&pageSize=100',
  320. {
  321. query,
  322. shared: 'true',
  323. projection: { _id: 1, name: 1, image: 1, price: 1 },
  324. }
  325. );
  326. if (!ret) {
  327. return [];
  328. }
  329. for (const item of ret.list) {
  330. item.draggable = false;
  331. }
  332. return ret.list;
  333. };
  334. const getPrivateGroups = async () => {
  335. const list = [
  336. {
  337. name: '我的组件',
  338. list: [],
  339. },
  340. ];
  341. const config = {
  342. params: {
  343. current: 1,
  344. pageSize: 1000,
  345. },
  346. };
  347. let ret: any = await axios.post(
  348. '/api/data/folders/list',
  349. {
  350. projection: {
  351. image: 1,
  352. _id: 1,
  353. name: 1,
  354. list: 1,
  355. },
  356. query: {
  357. type: `le5leV-components`,
  358. },
  359. sort: { createdAt: 1 },
  360. },
  361. config
  362. );
  363. if (!ret) {
  364. ret = { list: [] };
  365. }
  366. for (const item of ret.list) {
  367. item.canEdited = true;
  368. }
  369. list.push(...ret.list);
  370. list.push({
  371. name: '3D',
  372. list: [],
  373. });
  374. return list;
  375. };
  376. const dragStart = async (event: DragEvent | MouseEvent, item: any) => {
  377. event.stopPropagation();
  378. if (!item) {
  379. return;
  380. }
  381. meta2d.canvas.addCaches = [];
  382. dropped = false;
  383. let data = null;
  384. const id = item._id || item.id;
  385. let isAsync: boolean;
  386. if (item.draggable === false) {
  387. // 场景
  388. data = item.data || item;
  389. } else if (item['3d']) {
  390. // 3D
  391. data = {
  392. name: 'iframe',
  393. width: 400,
  394. height: 300,
  395. externElement: true,
  396. iframe: 'https://view3d.le5le.com/?id=' + id,
  397. };
  398. } else if (item.component) {
  399. // 我的组件
  400. if (!item.componentDatas && !item.componentData) {
  401. isAsync = true;
  402. const ret: any = await axios.post(`/api/data/le5leV-components/get`, {
  403. id,
  404. });
  405. item.componentDatas = ret.componentDatas;
  406. item.componentData = ret.componentData;
  407. }
  408. if (item.componentData) {
  409. const pens = convertPen([item.componentData]);
  410. data = deepClone(pens);
  411. } else if (item.componentDatas) {
  412. data = deepClone(item.componentDatas);
  413. }
  414. } else if (item.data) {
  415. // 普通图元
  416. data = item.data;
  417. } else if (item.image) {
  418. // 拖拽图片
  419. let target: any = event.target;
  420. target.children[0] && (target = target.children[0].children[0]);
  421. // firefox naturalWidth svg 图片 可能是 0
  422. const normalWidth = target.naturalWidth || target.width;
  423. const normalHeight = target.naturalHeight || target.height;
  424. const [name, lockedOnCombine] = isGif(item.image)
  425. ? ['gif', 0]
  426. : ['image', undefined];
  427. data = {
  428. name,
  429. width: 100,
  430. height: 100 * (normalHeight / normalWidth),
  431. image: item.image,
  432. imageRatio: true,
  433. lockedOnCombine,
  434. };
  435. } else {
  436. return;
  437. }
  438. if (!Array.isArray(data)) {
  439. data = deepClone([data]);
  440. }
  441. !dropped && (meta2d.canvas.addCaches = data);
  442. if (event instanceof DragEvent) {
  443. event.dataTransfer.setData(
  444. 'Meta2d',
  445. isAsync ? undefined : JSON.stringify(data)
  446. );
  447. }
  448. };
  449. const dragstart = (event: any) => {
  450. event.target.style.opacity = 0.5;
  451. };
  452. const dragend = (event: any) => {
  453. event.target.style.opacity = 1;
  454. };
  455. const open = async (item: any) => {
  456. if (!item || item.draggable !== false) {
  457. return;
  458. }
  459. router.push({
  460. path: '/',
  461. query: {
  462. r: Date.now() + '',
  463. },
  464. });
  465. const ret: any = await getLe5leV(item._id || item.id);
  466. for (const k of delAttrs) {
  467. delete (ret as any)[k];
  468. }
  469. meta2d.open(ret);
  470. autoSave(true);
  471. };
  472. const onChangeGroupPanel = async (val: string[]) => {
  473. if (val?.length) {
  474. for (const name of val) {
  475. switch (activedGroup.value) {
  476. case '场景':
  477. if (
  478. !caseCaches[activedGroup.value + name] ||
  479. !caseCaches[activedGroup.value + name].length
  480. ) {
  481. for (const item of subGroups.value) {
  482. if (item.name === name) {
  483. item.loading = true;
  484. }
  485. }
  486. caseCaches[activedGroup.value + name] = await getCaseProjects(
  487. activedGroup.value,
  488. name
  489. );
  490. for (const item of subGroups.value) {
  491. if (item.name === name) {
  492. item.list = caseCaches[activedGroup.value + name];
  493. item.loading = false;
  494. }
  495. }
  496. }
  497. break;
  498. case '图元':
  499. for (const item of subGroups.value) {
  500. if (item.name === name && !item.list.length) {
  501. item.loading = true;
  502. if (item.svg) {
  503. item.list = await getIcons(item.folder);
  504. } else {
  505. item.list = await getFiles(item.folder + item.name);
  506. }
  507. item.loading = false;
  508. }
  509. }
  510. break;
  511. case '我的':
  512. for (const item of subGroups.value) {
  513. if (!item.list.length) {
  514. item.loading = true;
  515. if (item.name === '我的组件') {
  516. const data = {
  517. query: { folder: '' },
  518. projection: {
  519. image: 1,
  520. _id: 1,
  521. name: 1,
  522. component: 1,
  523. },
  524. };
  525. const config = {
  526. params: {
  527. current: 1,
  528. pageSize: 1000,
  529. },
  530. };
  531. const res: any = await getComponentsList(data, config);
  532. if (res?.list) {
  533. item.list = res.list;
  534. }
  535. } else if (item.name === '3D') {
  536. const data = {
  537. projection: {
  538. image: 1,
  539. _id: 1,
  540. name: 1,
  541. },
  542. };
  543. const config = {
  544. params: {
  545. current: 1,
  546. pageSize: 1000,
  547. },
  548. };
  549. const res: any = await axios.post(
  550. '/api/data/le5le3d/list',
  551. data,
  552. config
  553. );
  554. if (res?.list) {
  555. for (const item of res.list) {
  556. item['3d'] = true;
  557. }
  558. item.list = res.list;
  559. }
  560. }
  561. item.loading = false;
  562. }
  563. }
  564. break;
  565. }
  566. }
  567. }
  568. };
  569. const editedFolder = ref<any>(undefined);
  570. const onCreateFolder = () => {
  571. editedFolder.value = {
  572. _id: '',
  573. name: '',
  574. label: '新建文件夹',
  575. list: [],
  576. edited: true,
  577. canEdited: true,
  578. };
  579. subGroups.value.splice(subGroups.value.length - 1, 0, editedFolder.value);
  580. };
  581. const createFoder = async () => {
  582. if (!editedFolder.value.label) {
  583. return;
  584. }
  585. if (editedFolder.value.label === editedFolder.value.name) {
  586. editedFolder.value.edited = false;
  587. return;
  588. }
  589. const found = subGroups.value.findIndex(
  590. (group: any) => group.name === editedFolder.value.label
  591. );
  592. if (found >= 0) {
  593. MessagePlugin.error('已经存在相同名称文件夹');
  594. return;
  595. }
  596. if (editedFolder.value._id) {
  597. const ret: any = await axios.post('/api/data/folders/update', {
  598. _id: editedFolder.value._id,
  599. name: editedFolder.value.label,
  600. });
  601. if (ret) {
  602. editedFolder.value.name = editedFolder.value.label;
  603. editedFolder.value.edited = false;
  604. }
  605. } else {
  606. const ret: any = await axios.post('/api/data/folders/add', {
  607. name: editedFolder.value.label,
  608. type: 'le5leV-components',
  609. list: [],
  610. });
  611. if (ret) {
  612. editedFolder.value.name = editedFolder.value.label;
  613. editedFolder.value._id = ret._id;
  614. editedFolder.value.edited = false;
  615. }
  616. }
  617. };
  618. const onEditHeader = (item: any) => {
  619. item.label = item.name;
  620. item.edited = true;
  621. editedFolder.value = item;
  622. };
  623. const onKeyHeader = (text: string, event: any) => {
  624. if (event.e.key === 'Escape') {
  625. editedFolder.value.edited = false;
  626. }
  627. };
  628. // 我的组件右键菜单
  629. const contextmenu = reactive<any>({
  630. visible: false,
  631. style: {},
  632. // 子分类
  633. group: undefined,
  634. // 组件图纸
  635. component: undefined,
  636. // 右键二级子菜单
  637. subMenus: [],
  638. });
  639. const contextmenuDom = ref<any>(null);
  640. const onContextMenu = async (e: MouseEvent, group: string, item: any) => {
  641. e.preventDefault();
  642. e.stopPropagation();
  643. if (activedGroup.value !== '我的') {
  644. return;
  645. }
  646. contextmenu.group = group;
  647. contextmenu.component = item;
  648. if (document.body.clientHeight - e.clientY < 128) {
  649. contextmenu.style = {
  650. left: e.clientX + 'px',
  651. bottom: '4px',
  652. };
  653. } else {
  654. contextmenu.style = {
  655. left: e.clientX + 'px',
  656. top: e.clientY + 'px',
  657. };
  658. }
  659. contextmenu.subMenus = [];
  660. for (const elem of subGroups.value) {
  661. if (elem === group || elem.name === '3D') {
  662. continue;
  663. }
  664. contextmenu.subMenus.push(elem);
  665. }
  666. contextmenu.visible = true;
  667. setTimeout(() => {
  668. if (contextmenuDom.value) {
  669. contextmenuDom.value.focus();
  670. }
  671. }, 500);
  672. };
  673. const delDialog = reactive<any>({});
  674. const onMenu = async (val: string) => {
  675. const id = contextmenu.component._id || contextmenu.component.id;
  676. switch (val) {
  677. case 'edit':
  678. if (contextmenu.component.component) {
  679. autoSave();
  680. router.push({
  681. path: '/',
  682. query: {
  683. id,
  684. c: 1,
  685. r: Date.now() + '',
  686. },
  687. });
  688. } else {
  689. let url = 'https://3d.le5le.com/?id=';
  690. if (import.meta.env.VITE_TRIAL == 0 && (window as any).url3D) {
  691. url = (window as any).url3D;
  692. }
  693. window.open(url + id, '_blank');
  694. }
  695. break;
  696. case 'del':
  697. delDialog.show = true;
  698. break;
  699. default:
  700. if (val.indexOf('move:')) {
  701. return;
  702. }
  703. val = val.replace('move:', '');
  704. const group = contextmenu.subMenus.find(
  705. (element: any) => element.name === val
  706. );
  707. if (!group) {
  708. return;
  709. }
  710. // 前端: 添加组件到目标文件夹
  711. group.list.push(contextmenu.component);
  712. // 前端:从源文件夹移出组件
  713. contextmenu.group.list.forEach((item: any, index: number, arr: any[]) => {
  714. if (id === item._id || id === item.id) {
  715. arr.splice(index, 1);
  716. }
  717. });
  718. // 更新后端组件信息
  719. let ret = await updateCollection('le5leV-components', {
  720. _id: id,
  721. folder: val === '我的组件' ? '' : val,
  722. });
  723. if (!ret) {
  724. return;
  725. }
  726. // 更新后端源文件夹列表
  727. if (contextmenu.group.name !== '我的组件') {
  728. await axios.post('/api/data/folders/update', {
  729. _id: contextmenu.group._id || contextmenu.group.id,
  730. list: contextmenu.group.list,
  731. });
  732. }
  733. // 更新后端目标文件夹列表
  734. if (group.name !== '我的组件') {
  735. await axios.post('/api/data/folders/update', {
  736. _id: group._id || group.id,
  737. list: group.list,
  738. });
  739. }
  740. break;
  741. }
  742. contextmenu.visible = false;
  743. };
  744. const delComponet = async () => {
  745. const id = contextmenu.component._id || contextmenu.component.id;
  746. await axios.post(`/api/data/le5leV-components/delete`, {
  747. id,
  748. });
  749. // 前端:从源文件夹移出组件
  750. contextmenu.group.list.forEach((item: any, index: number, arr: any[]) => {
  751. if (id === item._id || id === item.id) {
  752. arr.splice(index, 1);
  753. }
  754. });
  755. // 更新后端源文件夹列表
  756. if (contextmenu.group.name !== '我的组件') {
  757. await axios.post('/api/data/folders/update', {
  758. _id: contextmenu.group._id || contextmenu.group.id,
  759. list: contextmenu.group.list,
  760. });
  761. }
  762. delDialog.show = false;
  763. };
  764. const drop = (obj: any) => {
  765. dropped = true;
  766. if (obj) {
  767. Array.isArray(obj) && open(obj[0]);
  768. } else {
  769. MessagePlugin.warning('正在请求网络数据中,请稍后重试');
  770. }
  771. };
  772. onMounted(() => {
  773. groupChange('场景');
  774. document.addEventListener('dragstart', dragstart, false);
  775. document.addEventListener('dragend', dragend, false);
  776. setTimeout(() => {
  777. meta2d.on('drop', drop);
  778. }, 2000);
  779. });
  780. onUnmounted(() => {
  781. document.removeEventListener('dragstart', dragstart);
  782. document.removeEventListener('dragend', dragend);
  783. meta2d.off('drop', drop);
  784. });
  785. </script>
  786. <style lang="postcss" scoped>
  787. .graphics {
  788. display: flex;
  789. flex-direction: column;
  790. .input-search {
  791. flex-shrink: 0;
  792. height: 40px;
  793. }
  794. .groups-panel {
  795. display: grid;
  796. grid-template-columns: 50px 1fr;
  797. border-top: 1px solid var(--color-background-input);
  798. flex-grow: 1;
  799. overflow-y: auto;
  800. font-size: 12px;
  801. z-index: 7;
  802. .groups {
  803. & > div {
  804. display: flex;
  805. flex-direction: column;
  806. align-items: center;
  807. padding: 16px 4px;
  808. line-height: 1;
  809. cursor: pointer;
  810. .t-icon {
  811. font-size: 20px;
  812. margin-bottom: 8px;
  813. }
  814. &:hover {
  815. color: var(--color-primary);
  816. }
  817. }
  818. .active {
  819. background-color: var(--color-background-active);
  820. color: var(--color-primary);
  821. border-left: 2px solid var(--color-primary);
  822. }
  823. }
  824. .list {
  825. overflow-y: auto;
  826. max-height: calc(100vh - 100px);
  827. background-color: var(--color-background-active);
  828. padding-top: 8px;
  829. * {
  830. background-color: var(--color-background-active);
  831. }
  832. :deep(.t-collapse) {
  833. min-height: 100vh;
  834. border: none;
  835. }
  836. :deep(.t-collapse-panel__header) {
  837. border: none;
  838. font-size: 12px;
  839. font-weight: 400;
  840. padding: 8px 16px;
  841. &:hover {
  842. color: var(--color-primary);
  843. }
  844. }
  845. :deep(.t-collapse-panel__body) {
  846. border: none;
  847. }
  848. :deep(.t-collapse-panel__content) {
  849. background-color: var(--color-background-active);
  850. padding: 4px 4px 20px 4px;
  851. display: grid;
  852. grid-template-columns: 1fr 1fr 1fr;
  853. grid-row-gap: 12px;
  854. }
  855. :deep(.t-loading--center) {
  856. width: 100px;
  857. .t-loading__text {
  858. margin-left: 8px;
  859. height: 24px;
  860. }
  861. }
  862. :deep(.t-image__error) {
  863. .t-space-item:last-child {
  864. display: none;
  865. }
  866. }
  867. :deep(.t-image__loading) {
  868. .t-space-item:last-child {
  869. display: none;
  870. }
  871. }
  872. .graphic {
  873. position: relative;
  874. padding: 10px 0;
  875. border-radius: 2px;
  876. border: 1px solid transparent;
  877. &:hover {
  878. cursor: pointer;
  879. border-color: var(--color-primary);
  880. }
  881. p {
  882. margin-top: 10px;
  883. padding: 0 10px;
  884. text-align: center;
  885. font-size: 12px;
  886. height: 12px;
  887. line-height: 1;
  888. overflow: hidden;
  889. text-overflow: ellipsis;
  890. display: -webkit-box;
  891. -webkit-line-clamp: 1;
  892. word-break: break-all;
  893. -webkit-box-orient: vertical;
  894. }
  895. .t-image__wrapper {
  896. height: 32px;
  897. width: 32px;
  898. margin: auto;
  899. :deep(.t-image) {
  900. border-radius: 2px;
  901. }
  902. }
  903. svg {
  904. color: var(--color);
  905. height: 32px;
  906. width: 100%;
  907. margin: auto;
  908. }
  909. .svg-box {
  910. height: 32px;
  911. width: 32px;
  912. margin-left: calc(50% - 16px);
  913. margin-top: 10px;
  914. margin-bottom: 10px;
  915. &:deep(svg) {
  916. height: 100%;
  917. width: 100%;
  918. .cls-1 {
  919. stroke: var(--color) !important;
  920. }
  921. }
  922. }
  923. .price {
  924. position: absolute;
  925. top: 8px;
  926. right: 8px;
  927. display: inline-block;
  928. z-index: 1;
  929. border-radius: 2px;
  930. background-color: #ff400060;
  931. color: var(--color-bland);
  932. font-size: 10px;
  933. line-height: 1;
  934. padding: 3px;
  935. }
  936. }
  937. }
  938. .two-columns {
  939. :deep(.t-collapse-panel__content) {
  940. grid-template-columns: 1fr 1fr;
  941. }
  942. .graphic {
  943. .t-image__wrapper {
  944. width: 100px;
  945. height: 88px;
  946. background-color: var(--color-background);
  947. }
  948. }
  949. }
  950. }
  951. .context-menu-box {
  952. position: fixed;
  953. z-index: 200;
  954. & > div {
  955. width: 140px !important;
  956. }
  957. :deep(.t-menu) {
  958. .t-menu__item {
  959. &.t-is-opened {
  960. background-color: var(--color-background-popup-hover);
  961. transition: none !important;
  962. }
  963. }
  964. .t-fake-arrow {
  965. transform: rotate(-90deg) !important;
  966. }
  967. .t-fake-arrow--active {
  968. transform: rotate(90deg) !important;
  969. }
  970. }
  971. }
  972. }
  973. </style>