Graphics.vue 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779
  1. <template>
  2. <div class="graphics">
  3. <div class="group-asset">
  4. <t-radio-group
  5. v-model="activeAssets"
  6. @change="assetsChange"
  7. variant="primary-filled"
  8. >
  9. <t-radio-button value="system">系统资源</t-radio-button>
  10. <t-radio-button value="user">我的资源</t-radio-button>
  11. <t-radio-button value="data">数据</t-radio-button>
  12. <t-radio-button value="structure">结构</t-radio-button>
  13. </t-radio-group>
  14. </div>
  15. <div class="groups-panel">
  16. <div class="groups">
  17. <div
  18. v-for="group in groups"
  19. :class="group.name === activedGroup ? 'active' : ''"
  20. @click="groupChange(group.name)"
  21. >
  22. <template v-if="group.type === 'iconfont'">
  23. <i class="l-icon" :class="group.icon"> </i>
  24. <span> {{ group.name }}</span>
  25. </template>
  26. <template v-else>
  27. <!-- <t-icon :name="group.icon" /> -->
  28. <DesktopIcon v-if="group.icon==='desktop'" />
  29. <RootListIcon v-else-if="group.icon==='root-list'"/>
  30. <ImageIcon v-else-if="group.icon==='image'"/>
  31. <ControlPlatformIcon v-else-if="group.icon==='control-platform'"/>
  32. <ChartIcon v-else-if="group.icon==='chart'"/>
  33. <RelativityIcon v-else-if="group.icon==='relativity'"/>
  34. <ChartBubbleIcon v-else-if="group.icon==='chart-bubble'"/>
  35. <LayersIcon v-else-if="group.icon==='layers'"/>
  36. <TagIcon v-else-if="group.icon==='tag'" />
  37. <DataIcon v-else-if="group.icon==='data'"/>
  38. <!-- <InstallIcon v-else-if="group.icon==='install'"/> -->
  39. <RssIcon v-else-if="group.icon==='install'"/>
  40. <ArrowUpDown3Icon v-else-if="group.icon==='code'"/>
  41. <SystemInterfaceIcon v-else-if="group.icon==='system-interface'"/>
  42. <span> {{ group.name }}</span>
  43. </template>
  44. </div>
  45. </div>
  46. <Data v-if="activeAssets === 'data'" :group="activedGroup" />
  47. <Structure v-else-if="activeAssets === 'structure'" :group="activedGroup"/>
  48. <template v-else>
  49. <div class="list" :class="groupType ? 'two-columns' : ''">
  50. <div class="input-search">
  51. <div class="btn">
  52. <!-- <t-icon name="search" /> -->
  53. <img src="/img/icon_search_gray.svg" />
  54. </div>
  55. <t-input
  56. v-model="search"
  57. @change="onSearch"
  58. @enter="onSearch"
  59. placeholder="搜索"
  60. />
  61. <div class="ml-16">
  62. <t-tooltip content="展开/折叠">
  63. <menu-fold-icon class="hover"
  64. style="font-size: 16px"
  65. @click="onFold"/>
  66. <!-- <t-icon
  67. name="menu-fold"
  68. class="hover"
  69. style="font-size: 16px"
  70. @click="onFold"
  71. /> -->
  72. </t-tooltip>
  73. </div>
  74. </div>
  75. <div v-if="loading" class="center mt-16">
  76. <t-loading text="加载中..." size="small" :indicator="false" />
  77. </div>
  78. <template v-else>
  79. <div
  80. v-if="
  81. activedGroup === '图片' ||
  82. (activeAssets === 'user' &&
  83. (activedGroup === '方案' || activedGroup === '模板' || activedGroup === '组件'))
  84. "
  85. class="px-16 mt-12 mb-8 ml-4"
  86. >
  87. <a @click="onCreateFolder">+ 新建文件夹</a>
  88. </div>
  89. <t-collapse v-model="activedPanels[activedGroup]">
  90. <t-collapse-panel
  91. :value="item.name"
  92. v-for="item in subGroups"
  93. :key="item.name"
  94. >
  95. <template #header>
  96. <div class="flex middle">
  97. <div v-if="item.edited" @click.stop>
  98. <t-input
  99. v-model="item.label"
  100. style="width: 140px"
  101. @blur="createFoder"
  102. @enter="createFoder"
  103. @keyup="onKeyHeader"
  104. :autofocus="true"
  105. />
  106. </div>
  107. <div v-else>
  108. {{ item.name }}
  109. </div>
  110. </div>
  111. </template>
  112. <template #headerRightContent>
  113. <t-space size="small" @click.stop tabindex="0">
  114. <t-upload
  115. v-if="item.canEdited && activedGroup === '图片'"
  116. action="/api/image/upload"
  117. accept="image/*"
  118. :headers="headers"
  119. :data="{
  120. directory: `/大屏/${activedGroup}/${item.name}`,
  121. conflict:'new'
  122. }"
  123. :auto-upload="true"
  124. :upload-all-files-in-one-request="false"
  125. :before-upload="beforeUpload"
  126. @selectChange="onSelectFiles(item)"
  127. allowUploadDuplicateFile
  128. @success="fileSuccessed"
  129. theme="custom"
  130. >
  131. <image-icon class="hover" />
  132. <!-- <t-icon name="image" class="hover" /> -->
  133. </t-upload>
  134. <template v-if="item.canEdited">
  135. <add-icon v-if="['组件', '方案', '模板'].includes(activedGroup)" class="hover"
  136. @click="onAdd(item)"/>
  137. <!-- <t-icon
  138. v-if="['组件', '方案', '模板'].includes(activedGroup)"
  139. name="add"
  140. class="hover"
  141. @click="onAdd(item)"
  142. /> -->
  143. <edit-icon class="hover"
  144. @click="onEditHeader(item)"/>
  145. <!-- <t-icon
  146. name="edit"
  147. class="hover"
  148. @click="onEditHeader(item)"
  149. /> -->
  150. <t-popconfirm
  151. content="确认删除该文件夹吗"
  152. placement="left"
  153. @confirm="delFolder(item)"
  154. >
  155. <delete-icon class="hover"/>
  156. <!-- <t-icon name="delete" class="hover" /> -->
  157. </t-popconfirm>
  158. </template>
  159. </t-space>
  160. </template>
  161. <template v-for="elem in item.list">
  162. <div
  163. v-show="elem.visible !== false"
  164. class="graphic"
  165. :draggable="true"
  166. @dragstart="dragStart($event, elem)"
  167. @click.stop="dragStart($event, elem)"
  168. @dblclick.stop="open(elem)"
  169. @contextmenu="onContextMenu($event, item, elem)"
  170. @touchstart.passive="dragStart($event, elem)"
  171. >
  172. <!-- img 路径这样拼凑避免更新后路径一致图片使用缓存不更新 -->
  173. <t-image
  174. v-if="!elem.svg && elem.image"
  175. :src="elem.image +(activeAssets === 'user'?'':('?' + Math.random()))"
  176. :lazy="true"
  177. fit="contain"
  178. @load="loadImage(elem)"
  179. />
  180. <div class="svg-box" v-else-if="elem.svg" v-html="elem.svg" />
  181. <svg v-else class="l-icon" aria-hidden="true">
  182. <use :xlink:href="'#' + elem.icon"></use>
  183. </svg>
  184. <p :title="elem.name">{{ elem.name }}</p>
  185. <div class="price" v-if="elem.price > 0">
  186. ¥{{ elem.price }}
  187. </div>
  188. </div>
  189. </template>
  190. <div
  191. v-if="!item.list || !item.list.length"
  192. class="gray"
  193. style="white-space: nowrap; margin-left: 34px"
  194. >
  195. 暂无数据
  196. </div>
  197. </t-collapse-panel>
  198. </t-collapse>
  199. </template>
  200. <!-- <div class="div-manage" v-if="['设备', '素材'].includes(activedGroup)">
  201. <t-button
  202. class="w-full"
  203. @click="onManageGraphic"
  204. style="height: 30px;color:var(--color) !important;"
  205. >
  206. {{ activedGroup }}管理
  207. </t-button>
  208. </div> -->
  209. </div>
  210. </template>
  211. </div>
  212. <div
  213. class="context-menu-box"
  214. ref="contextmenuDom"
  215. v-show="contextmenu.visible"
  216. tabindex="0"
  217. :style="contextmenu.style"
  218. @blur="hideContextmenu"
  219. >
  220. <t-menu
  221. class="context-menu"
  222. @change="onMenu"
  223. expandType="popup"
  224. v-model="contextmenu.activeValue"
  225. >
  226. <t-submenu
  227. value="move"
  228. title="移动到"
  229. v-if="contextmenu.subMenus.length"
  230. :disabled="contextmenu.component['3d']"
  231. >
  232. <t-menu-item
  233. v-for="subMenu in contextmenu.subMenus"
  234. :value="'move:' + subMenu.name"
  235. >
  236. {{ subMenu.name }}
  237. </t-menu-item>
  238. </t-submenu>
  239. <t-submenu
  240. value="moveTo"
  241. :title="`移动到${activedGroup==='方案'?'模板':'方案'}`"
  242. v-if="['方案', '模板'].includes(activedGroup)"
  243. :disabled="contextmenu.component['3d']"
  244. >
  245. <t-menu-item
  246. v-for="subMenu in moveGroups[activedGroup==='方案'?'模板':'方案']"
  247. :value="'moveTo:' + subMenu.name"
  248. >
  249. {{ subMenu.name }}
  250. </t-menu-item>
  251. </t-submenu>
  252. <t-menu-item value="edit" :disabled="activedGroup === '图片'">
  253. 编辑
  254. </t-menu-item>
  255. <t-menu-item value="del" :disabled="contextmenu.component['3d']">
  256. 删除
  257. </t-menu-item>
  258. </t-menu>
  259. </div>
  260. <t-dialog
  261. v-if="delDialog.show"
  262. theme="danger"
  263. header="删除"
  264. :visible="true"
  265. @close="delDialog.show = false"
  266. @confirm="delComponent"
  267. >
  268. {{current?'检测到该图纸正在被编辑,':''}}确定删除该数据吗?{{current?'画布将被清空,':''}}删除后不可恢复!
  269. </t-dialog>
  270. <!-- <t-dialog
  271. v-if="chargeDialog.show"
  272. :header="chargeDialog.data.name"
  273. :visible="true"
  274. @close="chargeDialog.show = false"
  275. width="70%"
  276. :top="8"
  277. >
  278. <t-image :src="chargeDialog.data.image" />
  279. <template #footer>
  280. <div class="flex between" style="margin-top: -7px">
  281. <p>付费项目,购买后查看并使用</p>
  282. <div>
  283. <label>金额:</label>
  284. <label class="bland">¥{{ chargeDialog.data.price }}</label>
  285. <t-button class="primary ml-12" @click="onSubmitOrder"
  286. >购买</t-button
  287. >
  288. </div>
  289. </div>
  290. </template>
  291. </t-dialog> -->
  292. <t-dialog
  293. class="dialog-charge"
  294. v-if="chargeDialogShow"
  295. :header="chargeDialog.name"
  296. :visible="true"
  297. @close="chargeDialogShow = false"
  298. width="80%"
  299. :top="8"
  300. :footer="false"
  301. :closeOnOverlayClick="false"
  302. >
  303. <iframe
  304. :src="`https://${rootDomain.slice(1)}/enterprise/preview?product=v&id=${chargeDialog.data.id}`"
  305. frameborder="no"
  306. scrolling="no"
  307. allowtransparency="true"
  308. />
  309. </t-dialog>
  310. <t-dialog
  311. v-if="wechatPayDialog.show"
  312. v-model:visible="wechatPayDialog.show"
  313. class="pay-dialog"
  314. header="乐吾乐收银台"
  315. :close-on-overlay-click="false"
  316. :top="95"
  317. :width="700"
  318. confirm-btn="支付完成"
  319. :cancel-btn="null"
  320. @close="getPayResult"
  321. :footer="false"
  322. >
  323. <Pay
  324. :order="wechatPayDialog.order"
  325. :alipay-url="wechatPayDialog.order.alipayUrl"
  326. :code-url="wechatPayDialog.order.codeUrl"
  327. @success="onChargeSuccess"
  328. />
  329. </t-dialog>
  330. <t-dialog
  331. class="dialog-manage"
  332. :header="activedGroup + '管理'"
  333. :visible="manageDialog.show"
  334. @close="manageDialog.show = false"
  335. @confirm="manageConfirm"
  336. width="90%"
  337. :top="8"
  338. >
  339. <div class="manage-body">
  340. <t-collapse v-model="activedPanels[activedGroup]">
  341. <t-collapse-panel
  342. :value="item.name"
  343. v-for="item in manageDialog.data"
  344. :key="item.name"
  345. >
  346. <template #header>
  347. <div class="flex middle">
  348. {{ item.name }}
  349. </div>
  350. </template>
  351. <template v-for="elem in item.list">
  352. <div
  353. :style="{
  354. background: elem.visible ? '#42516c' : '',
  355. }"
  356. class="graphic manage-list"
  357. >
  358. <t-checkbox v-model:checked="elem.visible"></t-checkbox>
  359. <t-image
  360. :src="elem.image"
  361. :lazy="true"
  362. fit="contain"
  363. @load="loadImage(elem)"
  364. />
  365. </div>
  366. </template>
  367. <div
  368. v-if="!item.list || !item.list.length"
  369. class="gray"
  370. style="white-space: nowrap; margin-left: 34px"
  371. >
  372. 暂无数据
  373. </div>
  374. </t-collapse-panel>
  375. </t-collapse>
  376. </div>
  377. </t-dialog>
  378. </div>
  379. </template>
  380. <script lang="ts" setup>
  381. import { onMounted, onUnmounted, reactive, ref } from 'vue';
  382. import { useRouter, useRoute } from 'vue-router';
  383. import { MessagePlugin } from 'tdesign-vue-next';
  384. import axios from 'axios';
  385. import { deepClone } from '@meta2d/core';
  386. import { cases, shapes, formComponents, templates } from '@/services/defaults';
  387. import { charts } from '@/services/echarts';
  388. import { getFolders, makeSvg } from '@/services/png';
  389. import {
  390. addCollection,
  391. delImage,
  392. getComponentsList,
  393. getLe5leV,
  394. updateCollection,
  395. getCollectionList,
  396. imageDrive,
  397. } from '@/services/api';
  398. import { convertPen } from '@/services/upgrade';
  399. import { isGif } from '@/services/utils';
  400. import { autoSave, delAttrs, blank, useFolder, chargeDialogShow } from '@/services/common';
  401. import { debounce, throttle } from '@/services/debouce';
  402. import { searchObjectPinyin } from '@/services/pinyin';
  403. import { getCookie } from '@/services/cookie';
  404. import { parseSvg } from '@meta2d/svg';
  405. import Pay from './Pay.vue';
  406. import { filename } from '@/services/file';
  407. import { useUser } from '@/services/user';
  408. import { iframeCustom, rootDomain } from '@/services/defaults';
  409. import { getLe5le3d } from '@/services/api';
  410. import { useSelection } from '@/services/selections';
  411. import localforage from 'localforage';
  412. import {
  413. MenuFoldIcon,
  414. ImageIcon,
  415. AddIcon,
  416. EditIcon,
  417. DeleteIcon,
  418. DesktopIcon,
  419. RootListIcon,
  420. ControlPlatformIcon,
  421. ChartIcon,
  422. RelativityIcon,
  423. ChartBubbleIcon,
  424. TagIcon,
  425. LayersIcon,
  426. SystemInterfaceIcon,
  427. TerminalRectangle1Icon,
  428. RssIcon,
  429. DataIcon,
  430. ArrowUpDown3Icon,
  431. WifiIcon
  432. } from 'tdesign-icons-vue-next';
  433. import { getNetJsDiagram } from '@/services/material';
  434. import Data from './Data.vue';
  435. import Structure from './Structure.vue';
  436. import { useDot } from '@/services/common';
  437. const { dot } = useDot();
  438. const { user } = useUser();
  439. const { setFolder, getFolder } = useFolder();
  440. const router = useRouter();
  441. const route = useRoute();
  442. const { select } = useSelection();
  443. const activedGroup = ref('');
  444. const activeAssets = ref('system');
  445. let groups = reactive([]);
  446. let moveGroups = reactive<any>({
  447. '方案':[],
  448. '模板':[]
  449. });
  450. const systemGroups = [
  451. {
  452. icon: 'desktop',
  453. name: '方案',
  454. key: '',
  455. class: 'tow',
  456. },
  457. {
  458. icon: 'root-list',
  459. name: '模板',
  460. key: '',
  461. },
  462. {
  463. icon: 'relativity',
  464. name: '控件',
  465. key: '',
  466. },
  467. {
  468. icon: 'control-platform',
  469. name: '设备',
  470. key: '',
  471. },
  472. {
  473. icon: 'chart',
  474. name: '图表',
  475. key: 'chart',
  476. },
  477. {
  478. icon: 'image',
  479. name: '素材',
  480. key: '',
  481. },
  482. {
  483. icon: 'chart-bubble',
  484. name: '图形',
  485. key: 'shape',
  486. },
  487. {
  488. icon: 'l-zujian',
  489. name: '组件',
  490. key: 'chart',
  491. type: 'iconfont',
  492. },
  493. // {
  494. // icon: 'app',
  495. // name: '我的',
  496. // key: '',
  497. // },
  498. ];
  499. const userGroups = [
  500. {
  501. icon: 'desktop',
  502. name: '方案',
  503. key: '',
  504. class: 'tow',
  505. },
  506. {
  507. icon: 'root-list',
  508. name: '模板',
  509. key: '',
  510. },
  511. {
  512. icon: 'l-zujian',
  513. name: '组件',
  514. key: 'chart',
  515. type: 'iconfont',
  516. },
  517. {
  518. icon: 'image',
  519. name: '图片',
  520. key: '',
  521. },
  522. {
  523. icon: 'control-platform',
  524. name: '3D',
  525. key: '',
  526. },
  527. ];
  528. const dataGroups = [
  529. {
  530. icon: 'data',
  531. name: '数据源',
  532. key: '',
  533. },
  534. {
  535. icon: 'install',
  536. name: '属性',
  537. key: '',
  538. },
  539. {
  540. icon: 'code',
  541. name: '解析',
  542. key: 'chart',
  543. },
  544. // {
  545. // icon: 'system-interface',
  546. // name: '数据模拟',
  547. // key: '',
  548. // }
  549. ];
  550. const structureGroups = [
  551. {
  552. icon: 'layers',
  553. name: '图层',
  554. key: '',
  555. },
  556. {
  557. icon: 'tag',
  558. name: '分组',
  559. key: '',
  560. }
  561. ];
  562. groups = systemGroups;
  563. const subGroups = ref<any[]>([]);
  564. const groupType = ref(0);
  565. const activedPanels = reactive<any>({});
  566. const caseCaches = [];
  567. const templateCaches = [];
  568. const componentCaches = [];
  569. const materials = [];
  570. const pngs = [];
  571. let jsDiagrams = [];
  572. const components = [
  573. {
  574. name:"默认",
  575. list:[]
  576. }
  577. ];
  578. let dropped = false;
  579. const chargeDialog = reactive<any>({});
  580. const wechatPayDialog = reactive<any>({
  581. show: false,
  582. });
  583. const manageDialog = reactive<any>({
  584. name: '',
  585. data: [],
  586. show: false,
  587. });
  588. const search = ref('');
  589. const loading = ref(false);
  590. const headers = {
  591. Authorization: 'Bearer ' + (getCookie('token') || ''),
  592. };
  593. const updataData = { directory: '/大屏/默认' };
  594. let lastName = '方案';
  595. let userLastName = '方案';
  596. const assetsChange = (value) => {
  597. if (value === 'system') {
  598. groups = systemGroups;
  599. activedGroup.value = lastName;
  600. } else if (value === 'user') {
  601. groups = userGroups;
  602. activedGroup.value = userLastName;
  603. }else if(value === 'data'){
  604. groups = dataGroups;
  605. activedGroup.value = '数据源';
  606. }else if(value === 'structure'){
  607. groups = structureGroups;
  608. activedGroup.value = '图层';
  609. }
  610. groupChange(activedGroup.value);
  611. };
  612. const groupChange = async (name: string) => {
  613. activedGroup.value = name;
  614. groupType.value = 0;
  615. switch (name) {
  616. case '方案':
  617. if (activeAssets.value === 'system') {
  618. if (!caseCaches.length) {
  619. loading.value = true;
  620. caseCaches.push(...(await getCaseProjects('系统方案',true,false)));
  621. for (const group of cases) {
  622. group.list = [];
  623. for (const item of caseCaches) {
  624. if (item.case === group.name) {
  625. group.list.push(item);
  626. }
  627. }
  628. }
  629. loading.value = false;
  630. }
  631. groupType.value = 1;
  632. subGroups.value = cases;
  633. lastName = name;
  634. } else {
  635. // subGroups.value = await getUserProjects('le5leV');
  636. // groupType.value = 1;
  637. // await getPrivateProjects('le5leV');
  638. // userLastName = name;
  639. //用户方案
  640. subGroups.value = await getCollectionImageList('方案', 'v',false,false);
  641. moveGroups['方案'] = [];
  642. subGroups.value.forEach((item)=>{if(item.name!=='默认'){ moveGroups['方案'].push({name:item.name})}});
  643. groupType.value = 1;
  644. userLastName = name;
  645. }
  646. break;
  647. case '模板':
  648. if (activeAssets.value === 'system') {
  649. if (!templateCaches.length) {
  650. loading.value = true;
  651. templateCaches.push(...(await getCaseProjects('系统模板',true,true)));
  652. for (const group of templates) {
  653. group.list = [];
  654. for (const item of templateCaches) {
  655. if (item.case === group.name) {
  656. group.list.push(item);
  657. }
  658. }
  659. }
  660. loading.value = false;
  661. }
  662. groupType.value = 1;
  663. subGroups.value = templates;
  664. lastName = name;
  665. } else {
  666. // subGroups.value = await getUserProjects('le5leV-template');
  667. // groupType.value = 1;
  668. // await getPrivateProjects('le5leV-template');
  669. // userLastName = name;
  670. subGroups.value = await getCollectionImageList('模板', 'v',false,true);
  671. moveGroups['模板'] = [];
  672. subGroups.value.forEach((item)=>{if(item.name!=='默认'){ moveGroups['模板'].push({name:item.name})}});
  673. groupType.value = 1;
  674. userLastName = name;
  675. }
  676. break;
  677. case '图表':
  678. subGroups.value = charts;
  679. lastName = name;
  680. break;
  681. case '控件':
  682. subGroups.value = formComponents;
  683. lastName = name;
  684. break;
  685. case '素材':
  686. groupType.value = 1;
  687. if (!materials.length) {
  688. loading.value = true;
  689. materials.push(...(await getFolders('v/material')));
  690. loading.value = false;
  691. const _materials: string = await localforage.getItem(
  692. 'le5leV-materials'
  693. );
  694. if (_materials) {
  695. Object.assign(materials, JSON.parse(_materials));
  696. }
  697. }
  698. subGroups.value = materials;
  699. lastName = name;
  700. break;
  701. case '设备':
  702. if (!pngs.length) {
  703. loading.value = true;
  704. pngs.push(...(await getFolders('png')));
  705. pngs.push(...(await getFolders('svg', true)));
  706. pngs.push(...jsDiagrams);
  707. loading.value = false;
  708. const _pngs: string = await localforage.getItem('le5leV-pngs');
  709. if (_pngs) {
  710. Object.assign(pngs, JSON.parse(_pngs));
  711. }
  712. }
  713. subGroups.value = pngs;
  714. lastName = name;
  715. break;
  716. case '图形':
  717. subGroups.value = shapes;
  718. lastName = name;
  719. break;
  720. case '组件':
  721. if (activeAssets.value === 'system') {
  722. if (!componentCaches.length) {
  723. loading.value = true;
  724. componentCaches.push(...(await getCaseProjects('系统组件',true,false)));
  725. loading.value = false;
  726. for (const component of componentCaches) {
  727. if(component.case){
  728. let group = components.filter((item)=>{item.name===component.case});
  729. if(group&&group.length){
  730. group[0].list.push(component);
  731. }else{
  732. components.push({
  733. name:component.case,
  734. list:[component]
  735. })
  736. }
  737. }else{
  738. components[0].list.push(component);
  739. }
  740. }
  741. }
  742. groupType.value = 1;
  743. subGroups.value = components;
  744. lastName = name;
  745. } else {
  746. // subGroups.value = await getUserComponents();
  747. // groupType.value = 1;
  748. // await getPrivateGraphics();
  749. // userLastName = name;
  750. subGroups.value = await getCollectionImageList(
  751. '组件',
  752. 'v.component',
  753. false,
  754. false
  755. );
  756. groupType.value = 1;
  757. userLastName = name;
  758. }
  759. break;
  760. case '图片':
  761. loading.value = true;
  762. subGroups.value = await getImageList();
  763. loading.value = false;
  764. userLastName = name;
  765. break;
  766. case '3D':
  767. subGroups.value = [
  768. {
  769. name: '3D',
  770. list: [],
  771. },
  772. ];
  773. groupType.value = 1;
  774. await getPrivateGraphics();
  775. userLastName = name;
  776. break;
  777. }
  778. // if (!activedPanels[name]) {
  779. activedPanels[name] = [];
  780. if(['素材','设备'].includes(name)){
  781. activedPanels[name].push(subGroups.value[0]?.name);
  782. }else{
  783. for (const item of subGroups.value) {
  784. activedPanels[name].push(item?.name);
  785. }
  786. }
  787. // }
  788. // searchGraphics();
  789. };
  790. // TODO 获取方案文件
  791. //获取方案文件夹
  792. const getCollectionImageList = async (name?: string, collection?: string, system?:boolean, template?:boolean) => {
  793. //1. 获取网盘文件夹
  794. const fullpath = `/大屏/${name}`;
  795. let ret: { list: any[] } = await axios.post('/api/directory/list', {
  796. fullpath,
  797. });
  798. if (!ret) {
  799. return [];
  800. }
  801. let list = [];
  802. for (let i of ret.list) {
  803. if (
  804. i.fullpath !== `${fullpath}/默认` &&
  805. i.fullpath.split('/').length === 4
  806. ) {
  807. //不取当前文件夹
  808. list.push(i);
  809. }
  810. }
  811. const data = {
  812. // directory: `/大屏/${name}`,
  813. // query: {
  814. // // folder: '',
  815. // tags: name !== '组件' ? name : undefined,
  816. // },
  817. // userFlag,
  818. system,
  819. template
  820. // projection: {
  821. // image: 1,
  822. // id: 1,
  823. // name: 1,
  824. // tags: 1,
  825. // folder: 1,
  826. // component: 1,
  827. // filename: 1,
  828. // },
  829. };
  830. if(!data.system){
  831. delete data.system;
  832. }
  833. const config = {
  834. params: {
  835. current: 1,
  836. pageSize: 1000,
  837. },
  838. };
  839. //2.请求所有图纸/组件数据
  840. const res: any = await getCollectionList(collection, data, config);
  841. //3.将数据对应到云盘文件夹
  842. const results = [];
  843. const resultsMap = {
  844. 默认: [],
  845. };
  846. for (const item of list) {
  847. let folder = item.fullpath.split('/')[3];
  848. if (!resultsMap[folder]) {
  849. resultsMap[folder] = [];
  850. }
  851. }
  852. for (const item of res.list) {
  853. if(collection === 'v.component') {
  854. item.component = true;
  855. }
  856. if (item.folder && resultsMap[item.folder]) {
  857. resultsMap[item.folder].push(item);
  858. } else {
  859. resultsMap['默认'].push(item);
  860. }
  861. }
  862. for (const item of list) {
  863. let folder = item.fullpath.split('/')[3];
  864. results.push({
  865. name: folder,
  866. canEdited: true,
  867. id: item.id,
  868. list: resultsMap[folder],
  869. });
  870. }
  871. results.push({
  872. name: '默认',
  873. list: resultsMap['默认'],
  874. });
  875. return results;
  876. };
  877. const getImageList = async () => {
  878. let ret: { list: any[] } = await axios.post('/api/directory/list', {
  879. fullpath: '/大屏/图片',
  880. });
  881. if (!ret) {
  882. return [];
  883. }
  884. let list = [];
  885. for (let i of ret.list) {
  886. if (i.fullpath.split('/').length === 4) {
  887. //不取当前文件夹
  888. list.push(i);
  889. }
  890. }
  891. return await Promise.all(
  892. list.map(async (item) => {
  893. let secondDir = item.fullpath.split('/');
  894. const _ret: { list: any[]; total: number } = await axios.post(
  895. '/api/file/list',
  896. {
  897. type: '图片',
  898. directory: item.fullpath,
  899. },
  900. {
  901. params: {
  902. current: 1,
  903. pageSize: 100,
  904. },
  905. }
  906. );
  907. let list = _ret.list.map((_item) => {
  908. return {
  909. ..._item,
  910. image: _item.url || `/file${_item.filename}`,
  911. visible: true,
  912. folder: item.fullpath,
  913. id: _item.id || _item._id,
  914. };
  915. });
  916. return {
  917. name: secondDir[3],
  918. id: item.id || item._id,
  919. canEdited: secondDir[3] !== '默认',
  920. list: list,
  921. };
  922. })
  923. );
  924. };
  925. const getCaseProjects = async (name: string, system:boolean, template:boolean, current = 1, pageSize = 1000) => {
  926. const query: any = { tags: name };
  927. let collection = name == '系统组件' ? 'v.component' : 'v';
  928. let data = { system, template };
  929. if(!data.system){
  930. delete data.system;
  931. }
  932. const ret: any = await axios.post(
  933. `/api/data/${collection}/list`,
  934. data ,
  935. // {
  936. // // query: {
  937. // // tags: "系统方案"
  938. // // },
  939. // //shared: true,
  940. // // projection: "id,_id,name,image,price,case",
  941. // // sort: { createdAt: 1 },
  942. // // systemFlag
  943. // system,
  944. // template
  945. // },
  946. {
  947. params: {
  948. current,
  949. pageSize,
  950. },
  951. }
  952. );
  953. if (!ret) {
  954. return [];
  955. }
  956. for (const item of ret.list) {
  957. if (!item.id) {
  958. item.id = item._id;
  959. }
  960. if(name !== '系统组件'){
  961. item.draggable = false;
  962. }else{
  963. item.component = true;
  964. }
  965. }
  966. return ret.list;
  967. };
  968. // const getUserProjects = async (name: string, current = 1, pageSize = 1000) => {
  969. // const query: any = { tags: name };
  970. // const ret: any = await axios.post(
  971. // '/api/data/le5leV/list',
  972. // {
  973. // query,
  974. // projection: {
  975. // id: 1,
  976. // _id: 1,
  977. // name: 1,
  978. // image: 1,
  979. // price: 1,
  980. // case: 1,
  981. // folder: 1,
  982. // },
  983. // sort: { createdAt: 1 },
  984. // },
  985. // {
  986. // params: {
  987. // current,
  988. // pageSize,
  989. // },
  990. // }
  991. // );
  992. // if (!ret) {
  993. // return [];
  994. // }
  995. // for (const item of ret.list) {
  996. // if (!item.id) {
  997. // item.id = item._id;
  998. // }
  999. // item.draggable = false;
  1000. // }
  1001. // return ret.list;
  1002. // };
  1003. const getPrivateGroups = async () => {
  1004. const list = [
  1005. {
  1006. name: '默认',
  1007. list: [],
  1008. },
  1009. ];
  1010. const config = {
  1011. params: {
  1012. current: 1,
  1013. pageSize: 1000,
  1014. },
  1015. };
  1016. let ret: any = await axios.post(
  1017. '/api/data/folders/list',
  1018. {
  1019. // projection: {
  1020. // image: 1,
  1021. // _id: 1,
  1022. // name: 1,
  1023. // list: 1,
  1024. // },
  1025. projection:'image,id,name,list',
  1026. // query: {
  1027. // type: `v-components`,
  1028. // },
  1029. sort: { createdAt: 1 },
  1030. },
  1031. config
  1032. );
  1033. if (!ret) {
  1034. ret = { list: [] };
  1035. }
  1036. for (const item of ret.list) {
  1037. item.canEdited = true;
  1038. }
  1039. list.push(...ret.list);
  1040. list.push({
  1041. name: '3D',
  1042. list: [],
  1043. });
  1044. return list;
  1045. };
  1046. const getUserComponents = async () => {
  1047. const list = [
  1048. {
  1049. name: '默认',
  1050. list: [],
  1051. },
  1052. ];
  1053. const config = {
  1054. params: {
  1055. current: 1,
  1056. pageSize: 1000,
  1057. },
  1058. };
  1059. let ret: any = await axios.post(
  1060. '/api/data/folders/list',
  1061. {
  1062. // projection: {
  1063. // image: 1,
  1064. // _id: 1,
  1065. // name: 1,
  1066. // list: 1,
  1067. // },
  1068. projection:'image,id,name,list',
  1069. // query: {
  1070. // type: `v.component`,
  1071. // },
  1072. sort: { createdAt: 1 },
  1073. },
  1074. config
  1075. );
  1076. if (!ret) {
  1077. ret = { list: [] };
  1078. }
  1079. for (const item of ret.list) {
  1080. item.canEdited = true;
  1081. }
  1082. list.push(...ret.list);
  1083. return list;
  1084. };
  1085. const getUserProjects = async (type: string) => {
  1086. const list = [
  1087. {
  1088. name: '默认',
  1089. list: [],
  1090. },
  1091. ];
  1092. const config = {
  1093. params: {
  1094. current: 1,
  1095. pageSize: 1000,
  1096. },
  1097. };
  1098. let ret: any = await axios.post(
  1099. '/api/data/folders/list',
  1100. {
  1101. // projection: {
  1102. // image: 1,
  1103. // _id: 1,
  1104. // name: 1,
  1105. // list: 1,
  1106. // },
  1107. projection:'image,id,name,list',
  1108. // query: {
  1109. // type,
  1110. // },
  1111. sort: { createdAt: 1 },
  1112. },
  1113. config
  1114. );
  1115. if (!ret) {
  1116. ret = { list: [] };
  1117. }
  1118. for (const item of ret.list) {
  1119. item.canEdited = true;
  1120. }
  1121. list.push(...ret.list);
  1122. return list;
  1123. };
  1124. const getPrivateProjects = async (type: string) => {
  1125. for (const item of subGroups.value) {
  1126. if (!item.list.length) {
  1127. item.loading = true;
  1128. //TODO 方案/模板分类
  1129. if (item.name === '默认') {
  1130. const data = {
  1131. // query: {
  1132. // folder: '',
  1133. // tags: type === 'v-template' ? '模板' : '方案',
  1134. // },
  1135. // projection: {
  1136. // image: 1,
  1137. // _id: 1,
  1138. // name: 1,
  1139. // tags: 1,
  1140. // },
  1141. projection:'image,id,name,tags'
  1142. };
  1143. const config = {
  1144. params: {
  1145. current: 1,
  1146. pageSize: 1000,
  1147. },
  1148. };
  1149. const res: any = await getCollectionList('v', data, config);
  1150. if (res?.list) {
  1151. // res.list.forEach((item) => {
  1152. // item.draggable = false;
  1153. // })
  1154. item.list = res.list;
  1155. // if (type === 'le5leV') {
  1156. // //过滤模板
  1157. // // item.list = res.list.filter((item) => !item.isTemplate);
  1158. // }
  1159. }
  1160. }
  1161. item.loading = false;
  1162. }
  1163. }
  1164. };
  1165. const dragStart = async (event: DragEvent | MouseEvent|TouchEvent, item: any) => {
  1166. // event.stopPropagation();
  1167. if (!item) {
  1168. return;
  1169. }
  1170. meta2d.canvas.addCaches = [];
  1171. dropped = false;
  1172. let data = null;
  1173. const id = item.id || item._id;
  1174. let isAsync: boolean;
  1175. if (
  1176. activeAssets.value === 'user' &&
  1177. ['方案', '模板'].includes(activedGroup.value)
  1178. ) {
  1179. if (!item._id) {
  1180. item._id = item.id;
  1181. }
  1182. item.draggable = false;
  1183. data = item.data || item;
  1184. dropped =true;
  1185. } else if (item.draggable === false) {
  1186. //方案
  1187. data = item.data || item;
  1188. dropped =true;
  1189. } else if (item['3d']) {
  1190. const res: any = await getLe5le3d(item.id || item._id, "id, name, image");
  1191. let iframe = (location.host.indexOf('.le5le')!==-1? 'https://view.le5le.com/3d?id=' :(location.origin+'/view/3d/?id=')) + (item.id || item._id)
  1192. data = {
  1193. name: 'iframe',
  1194. x: 0,
  1195. y: 0,
  1196. tags: ['meta3d'],
  1197. zIndex: 1,
  1198. operationalRect: {
  1199. x: 0.2,
  1200. y: 0.2,
  1201. height: 0.8,
  1202. width: 0.6,
  1203. },
  1204. props: {
  1205. custom: iframeCustom,
  1206. },
  1207. width: meta2d.store.data.width || meta2d.store.options.width,
  1208. height: meta2d.store.data.height || meta2d.store.options.height,
  1209. externElement: true,
  1210. thumbImg: res.image,
  1211. iframe,
  1212. };
  1213. } else if (item.component) {
  1214. // 默认
  1215. if (!item.componentDatas && !item.componentData) {
  1216. isAsync = true;
  1217. const ret: any = await axios.post(`/api/data/v.component/get`, {
  1218. id,
  1219. });
  1220. ret.data.componentDatas[0].componentId = id;
  1221. ret.data.componentDatas.forEach((item)=>{
  1222. item.originId = item.id;
  1223. });
  1224. item.componentDatas = ret.data.componentDatas;
  1225. item.componentData = ret.data.componentData;
  1226. }
  1227. if (item.componentData) {
  1228. const pens = convertPen([item.componentData]);
  1229. data = deepClone(pens);
  1230. } else if (item.componentDatas) {
  1231. data = deepClone(item.componentDatas);
  1232. }
  1233. } else if (item.data) {
  1234. // 普通图元
  1235. if(item.fullname || item.subClassName){
  1236. // data = item;
  1237. item.name = item.fullname;
  1238. item.width = item.data.rect.width*4;
  1239. item.height = item.data.rect.height*4;
  1240. delete item.rect;
  1241. data = item;
  1242. }else{
  1243. // 普通图元
  1244. data = item.data;
  1245. if(data.name==='tablePlus'){
  1246. if(data.tableType === 'longlist'){
  1247. const _data = new Array(100).fill(0)
  1248. .map((_, row) => new Array(10).fill(0)
  1249. .map((_, column) => `${row}, ${column}`));
  1250. _data.splice(0, 0, new Array(10).fill(0).map((_, i) =>String.fromCharCode(65+i)));
  1251. _data.forEach((item,index)=>{
  1252. if(index==0){
  1253. item.splice(0, 0, '');
  1254. }else{
  1255. item.splice(0, 0, index+'');
  1256. }
  1257. })
  1258. data.data = _data;
  1259. // console.log("data",data);
  1260. }
  1261. }
  1262. }
  1263. } else if (item.image) {
  1264. // 拖拽图片
  1265. let target: any = event.target;
  1266. target.children[0] && (target = target.children[0].children[0]);
  1267. // firefox naturalWidth svg 图片 可能是 0
  1268. const width = target.naturalWidth || target.width;
  1269. const height = target.naturalHeight || target.height;
  1270. const [name, lockedOnCombine] = await isGif(item.image)
  1271. ? ['gif', 0]
  1272. : ['image', undefined];
  1273. data = {
  1274. name,
  1275. width,
  1276. height,
  1277. isBottom:true,
  1278. image: item.image,
  1279. imageRatio: true,
  1280. ratio: true,
  1281. lockedOnCombine,
  1282. };
  1283. } else {
  1284. return;
  1285. }
  1286. if (!Array.isArray(data)) {
  1287. data = deepClone([data]);
  1288. }
  1289. !dropped && (meta2d.canvas.addCaches = data);
  1290. if (event instanceof DragEvent) {
  1291. event.dataTransfer.setData(
  1292. 'Meta2d',
  1293. isAsync ? undefined : JSON.stringify(data)
  1294. );
  1295. }
  1296. };
  1297. const dragstart = (event: any) => {
  1298. event.target.style.opacity = 0.5;
  1299. };
  1300. const dragend = (event: any) => {
  1301. event.target.style.opacity = 1;
  1302. };
  1303. const open = async (item: any) => {
  1304. if (!item || item.draggable !== false) {
  1305. return;
  1306. }
  1307. if(dot.value){
  1308. MessagePlugin.info('请先保存当前画布');
  1309. return;
  1310. }
  1311. if (activeAssets.value === 'user') {
  1312. router.push({
  1313. path: '/',
  1314. query: {
  1315. r: Date.now() + '',
  1316. id:item.id || item._id,
  1317. },
  1318. });
  1319. } else {
  1320. const ret: any = await getLe5leV(item._id || item.id);
  1321. // if (!ret) {
  1322. // if (item.price > 0) {
  1323. // chargeDialog.data = item;
  1324. // chargeDialog.show = true;
  1325. // }
  1326. // return;
  1327. // }
  1328. if(!ret.data&&ret.price>0){
  1329. chargeDialog.data = item;
  1330. chargeDialogShow.value = true;
  1331. return;
  1332. }
  1333. sessionStorage.setItem('opening', '1');
  1334. router.push({
  1335. path: '/',
  1336. query: {
  1337. r: Date.now() + '',
  1338. },
  1339. });
  1340. for (const k of delAttrs) {
  1341. delete ret[k];
  1342. delete ret.data[k];
  1343. }
  1344. ret.data.name = ret.name;
  1345. ret.data.case = ret.case;
  1346. autoSave();
  1347. if(!ret.data.background){
  1348. ret.data.background = '#1e2430';
  1349. }
  1350. if(!ret.data.color){
  1351. ret.data.color = '#bdc7db';
  1352. }
  1353. if(!ret.data.width){ret.data.width= 1920;}
  1354. if(!ret.data.height){ret.data.height= 1080;}
  1355. meta2d.open(ret.data);
  1356. meta2d.fitView();
  1357. }
  1358. select();
  1359. };
  1360. const getPrivateGraphics = async () => {
  1361. for (const item of subGroups.value) {
  1362. if (!item.list.length) {
  1363. item.loading = true;
  1364. if (item.name === '默认') {
  1365. const data = {
  1366. // query: { folder: '' },
  1367. // projection: {
  1368. // image: 1,
  1369. // _id: 1,
  1370. // name: 1,
  1371. // component: 1,
  1372. // },
  1373. projection:'image,id,name,component'
  1374. };
  1375. const config = {
  1376. params: {
  1377. current: 1,
  1378. pageSize: 1000,
  1379. },
  1380. };
  1381. const res: any = await getComponentsList(data, config);
  1382. if (res?.list) {
  1383. item.list = res.list;
  1384. }
  1385. } else if (item.name === '3D') {
  1386. const data = {
  1387. // projection: {
  1388. // image: 1,
  1389. // _id: 1,
  1390. // name: 1,
  1391. // },
  1392. projection:"id, name, image"
  1393. };
  1394. const config = {
  1395. params: {
  1396. current: 1,
  1397. pageSize: 1000,
  1398. },
  1399. };
  1400. const res: any = await axios.post(
  1401. '/api/data/3d/list',
  1402. data,
  1403. config
  1404. );
  1405. if (res?.list) {
  1406. for (const item of res.list) {
  1407. item['3d'] = true;
  1408. item['draggable'] = true;
  1409. }
  1410. item.list = res.list;
  1411. }
  1412. }
  1413. item.loading = false;
  1414. }
  1415. }
  1416. };
  1417. const editedFolder = ref<any>(undefined);
  1418. const onCreateFolder = () => {
  1419. activedPanels[activedGroup.value].splice(
  1420. 0,
  1421. activedPanels[activedGroup.value].length
  1422. );
  1423. editedFolder.value = {
  1424. _id: '',
  1425. name: '',
  1426. label: '新建文件夹',
  1427. list: [],
  1428. edited: true,
  1429. canEdited: true,
  1430. };
  1431. subGroups.value.splice(subGroups.value.length - 1, 0, editedFolder.value);
  1432. };
  1433. const createFoder = async () => {
  1434. if (!editedFolder.value.label) {
  1435. return;
  1436. }
  1437. if (editedFolder.value.label === editedFolder.value.name) {
  1438. editedFolder.value.edited = false;
  1439. return;
  1440. }
  1441. const found = subGroups.value.findIndex(
  1442. (group: any) => group.name === editedFolder.value.label
  1443. );
  1444. if (found >= 0) {
  1445. MessagePlugin.error('已经存在相同名称文件夹');
  1446. return;
  1447. }
  1448. if (activeAssets.value !== 'user') {
  1449. return;
  1450. }
  1451. if (editedFolder.value.id || editedFolder.value._id) {
  1452. const ret: any = await axios.post('/api/directory/update', {
  1453. oldFullpath: `/大屏/${activedGroup.value}/` + editedFolder.value.oldLabel,
  1454. newFullpath: `/大屏/${activedGroup.value}/` + editedFolder.value.label,
  1455. });
  1456. if (ret) {
  1457. editedFolder.value.name = editedFolder.value.label;
  1458. editedFolder.value.edited = false;
  1459. }
  1460. //更新图纸的folder
  1461. if (['组件', '方案', '模板'].includes(activedGroup.value)) {
  1462. const collection =
  1463. activedGroup.value === '组件' ? 'v.component' : 'v';
  1464. editedFolder.value.list?.forEach(async (item) => {
  1465. item.folder = editedFolder.value.label;
  1466. await updateCollection(collection, {
  1467. id: item.id || item._id,
  1468. folder: editedFolder.value.label,
  1469. });
  1470. });
  1471. }
  1472. } else {
  1473. const ret: any = await axios.post('/api/directory/add', {
  1474. fullpath: `/大屏/${activedGroup.value}/` + editedFolder.value.label,
  1475. });
  1476. if (ret) {
  1477. editedFolder.value.name = editedFolder.value.label;
  1478. editedFolder.value.id = ret.id;
  1479. editedFolder.value.edited = false;
  1480. }
  1481. }
  1482. };
  1483. const _createFoder = async () => {
  1484. if (!editedFolder.value.label) {
  1485. return;
  1486. }
  1487. if (editedFolder.value.label === editedFolder.value.name) {
  1488. editedFolder.value.edited = false;
  1489. return;
  1490. }
  1491. const found = subGroups.value.findIndex(
  1492. (group: any) => group.name === editedFolder.value.label
  1493. );
  1494. if (found >= 0) {
  1495. MessagePlugin.error('已经存在相同名称文件夹');
  1496. return;
  1497. }
  1498. if (activeAssets.value !== 'user') {
  1499. return;
  1500. }
  1501. if (['组件', '方案', '模板'].includes(activedGroup.value)) {
  1502. if (editedFolder.value._id) {
  1503. const ret: any = await axios.post('/api/data/folders/update', {
  1504. _id: editedFolder.value._id,
  1505. name: editedFolder.value.label,
  1506. });
  1507. if (ret) {
  1508. editedFolder.value.name = editedFolder.value.label;
  1509. editedFolder.value.edited = false;
  1510. }
  1511. } else {
  1512. let type =
  1513. activedGroup.value === '组件'
  1514. ? 'v.component'
  1515. : activedGroup.value === '模板'
  1516. ? 'v-template'
  1517. : 'v';
  1518. const ret: any = await axios.post('/api/data/folders/add', {
  1519. name: editedFolder.value.label,
  1520. type,
  1521. list: [],
  1522. });
  1523. if (ret) {
  1524. editedFolder.value.name = editedFolder.value.label;
  1525. editedFolder.value._id = ret._id;
  1526. editedFolder.value.edited = false;
  1527. }
  1528. }
  1529. } else if (activedGroup.value === '图片') {
  1530. if (editedFolder.value._id) {
  1531. const ret: any = await axios.post('/api/directory/update', {
  1532. oldFullpath: '/大屏/' + editedFolder.value.oldLabel,
  1533. newFullpath: '/大屏/' + editedFolder.value.label,
  1534. });
  1535. if (ret) {
  1536. editedFolder.value.name = editedFolder.value.label;
  1537. editedFolder.value.edited = false;
  1538. }
  1539. } else {
  1540. const ret: any = await axios.post('/api/directory/add', {
  1541. fullpath: '/大屏/' + editedFolder.value.label,
  1542. });
  1543. if (ret) {
  1544. editedFolder.value.name = editedFolder.value.label;
  1545. editedFolder.value._id = ret.id || ret._id;
  1546. editedFolder.value.edited = false;
  1547. }
  1548. }
  1549. }
  1550. };
  1551. const onEditHeader = (item: any) => {
  1552. item.label = item.name;
  1553. item.edited = true;
  1554. item.oldLabel = item.name;
  1555. editedFolder.value = item;
  1556. };
  1557. const onAdd = (item: any) => {
  1558. blank();
  1559. if (activedGroup.value === '方案') {
  1560. item.vType = 'v';
  1561. } else if (activedGroup.value === '模板') {
  1562. item.vType = 'v-template';
  1563. } else if (activedGroup.value === '组件') {
  1564. item.vType = 'v.component';
  1565. }
  1566. setFolder(item);
  1567. const query: any = {
  1568. r: Date.now() + '',
  1569. folder: item.name,
  1570. tags: activedGroup.value,
  1571. };
  1572. if (activedGroup.value === '组件') {
  1573. query.c = 1;
  1574. }
  1575. router.push({
  1576. path: '/',
  1577. query,
  1578. });
  1579. activeAssets.value = 'system';
  1580. assetsChange('system');
  1581. // meta2d.open({
  1582. // name: '新建项目',
  1583. // pens: [],
  1584. // enableMock: true,
  1585. // tags: activedGroup.value,
  1586. // folder: item.name,
  1587. // } as any);
  1588. };
  1589. const onKeyHeader = (text: string, event: any) => {
  1590. if (event.e.key === 'Escape') {
  1591. editedFolder.value.edited = false;
  1592. }
  1593. };
  1594. // 默认右键菜单
  1595. const contextmenu = reactive<any>({
  1596. visible: false,
  1597. style: {},
  1598. // 子分类
  1599. group: undefined,
  1600. // 组件图纸
  1601. component: {},
  1602. // 右键二级子菜单
  1603. subMenus: [],
  1604. });
  1605. const contextmenuDom = ref<any>(null);
  1606. const onContextMenu = async (e: MouseEvent, group: any, item: any) => {
  1607. e.preventDefault();
  1608. e.stopPropagation();
  1609. if (activeAssets.value === 'system') {
  1610. return;
  1611. }
  1612. contextmenu.group = group;
  1613. contextmenu.component = item;
  1614. if (document.body.clientHeight - e.clientY < 128) {
  1615. contextmenu.style = {
  1616. left: e.clientX + 'px',
  1617. bottom: '4px',
  1618. };
  1619. } else {
  1620. contextmenu.style = {
  1621. left: e.clientX + 'px',
  1622. top: e.clientY + 'px',
  1623. };
  1624. }
  1625. if(!(moveGroups['模板']&&moveGroups['模板'].length)){
  1626. let ret: { list: any[] } = await axios.post('/api/directory/list', {
  1627. fullpath:"/大屏/模板",
  1628. });
  1629. moveGroups['模板'] = [];
  1630. ret.list.forEach((item)=>{
  1631. if(item.fullpath!=='/大屏/模板/默认'){
  1632. moveGroups['模板'].push({name:item.fullpath.split('/')[3]})
  1633. }
  1634. });
  1635. }
  1636. if(!(moveGroups['方案']&&moveGroups['方案'].length)){
  1637. let ret: { list: any[] } = await axios.post('/api/directory/list', {
  1638. fullpath:"/大屏/方案",
  1639. });
  1640. moveGroups['方案'] = [];
  1641. ret.list.forEach((item)=>{
  1642. if(item.fullpath!=='/大屏/方案/默认'){
  1643. moveGroups['方案'].push({name:item.fullpath.split('/')[3]})
  1644. }
  1645. });
  1646. }
  1647. contextmenu.subMenus = [];
  1648. for (const elem of subGroups.value) {
  1649. if (elem === group || elem.name === '默认' || elem.name === '3D') {
  1650. continue;
  1651. }
  1652. contextmenu.subMenus.push(elem);
  1653. }
  1654. contextmenu.visible = true;
  1655. setTimeout(() => {
  1656. if (contextmenuDom.value) {
  1657. contextmenuDom.value.focus();
  1658. }
  1659. }, 500);
  1660. };
  1661. const delDialog = reactive<any>({
  1662. contextmenuObj: {},
  1663. });
  1664. // TODO 右键菜单移动图纸
  1665. const onMenu = async (val: string) => {
  1666. const id = contextmenu.component.id || contextmenu.component._id;
  1667. setTimeout(() => {
  1668. contextmenu.group = '';
  1669. contextmenu.component = {};
  1670. contextmenu.subMenus = [];
  1671. }, 500);
  1672. switch (val) {
  1673. case 'edit':
  1674. if (
  1675. contextmenu.component.tags &&
  1676. contextmenu.component.tags.includes('svg')
  1677. ) {
  1678. MessagePlugin.warning('解析的svg图元不允许编辑!');
  1679. hideContextmenu();
  1680. contextmenu.activeValue = 0;
  1681. return;
  1682. }
  1683. // if (contextmenu.component.component) {
  1684. if (activedGroup.value == '组件') {
  1685. autoSave();
  1686. router.push({
  1687. path: '/',
  1688. query: {
  1689. id,
  1690. c: 1,
  1691. r: Date.now() + '',
  1692. },
  1693. });
  1694. } else if (contextmenu.component['3d']) {
  1695. let url = `https://3d${rootDomain}/?id=`;
  1696. if (window.url3D) {
  1697. url = window.url3D;
  1698. }
  1699. window.open(url + id, '_blank');
  1700. } else {
  1701. if ((contextmenu.group.id||contextmenu.group._id) && contextmenu.group.name !== '默认') {
  1702. setFolder(contextmenu.group);
  1703. }
  1704. autoSave();
  1705. //文件夹
  1706. router.push({
  1707. path: '/',
  1708. query: {
  1709. id,
  1710. r: Date.now() + '',
  1711. },
  1712. });
  1713. }
  1714. hideContextmenu();
  1715. break;
  1716. case 'del':
  1717. if(route.query.id===id){
  1718. current.value = true;
  1719. }else{
  1720. current.value = false;
  1721. }
  1722. delDialog.show = true;
  1723. Object.assign(delDialog.contextmenuObj, contextmenu);
  1724. break;
  1725. default:
  1726. if(val.startsWith('moveTo:')){
  1727. val = val.replace('moveTo:', '');
  1728. //更新前端
  1729. contextmenu.group.list.forEach((item: any, index: number, arr: any[]) => {
  1730. if (id === item._id || id === item.id) {
  1731. arr.splice(index, 1);
  1732. }
  1733. });
  1734. //更新后端图纸
  1735. let ret = await updateCollection('v', {
  1736. id,
  1737. folder: val === '默认' ? '' : val,
  1738. system:false,
  1739. template:activedGroup.value === '方案' ? true : false
  1740. // userFlag:activedGroup.value === '方案' ? 2 : 1
  1741. });
  1742. if (!ret) {
  1743. return;
  1744. }
  1745. (meta2d.store.data as any).isTemplate = activedGroup.value === '方案' ? true : false;
  1746. (meta2d.store.data as any).template = activedGroup.value === '方案' ? true : false;
  1747. (meta2d.store.data as any).folder = val === '默认' ? '' : val;
  1748. //更新后端 图片
  1749. let path: string =
  1750. contextmenu.component.filename || contextmenu.component.image;
  1751. if (imageDrive && path?.startsWith(imageDrive)) {
  1752. path = path.slice(imageDrive.length);
  1753. }
  1754. if(path.startsWith('/file')) {
  1755. path = '/api' + path;
  1756. } else if(!path.startsWith('/api/file')) {
  1757. path = '/api/file' + path;
  1758. }
  1759. await axios.patch(`${path}`, {
  1760. // filenames: [filename],
  1761. directory: `/大屏/${activedGroup.value==='方案'?'模板':'方案' }/${val || '默认'}`,
  1762. });
  1763. break;
  1764. }
  1765. if (val.indexOf('move:')) {
  1766. return;
  1767. }
  1768. val = val.replace('move:', '');
  1769. const group = contextmenu.subMenus.find(
  1770. (element: any) => element.name === val
  1771. );
  1772. if (!group) {
  1773. return;
  1774. }
  1775. // 前端: 添加组件到目标文件夹
  1776. let data: any;
  1777. if (contextmenu.component.component) {
  1778. data = {
  1779. component: true,
  1780. image: contextmenu.component.image,
  1781. name: contextmenu.component.name,
  1782. visible: true,
  1783. _id: contextmenu.component._id || contextmenu.component.id,
  1784. filename: contextmenu.component.filename,
  1785. };
  1786. } else {
  1787. data = {
  1788. image: contextmenu.component.image,
  1789. name: contextmenu.component.name,
  1790. tags: contextmenu.component.tags,
  1791. visible: true,
  1792. _id: contextmenu.component._id || contextmenu.component.id,
  1793. filename: contextmenu.component.filename,
  1794. };
  1795. }
  1796. group.list.push(data);
  1797. // 前端:从源文件夹移出组件
  1798. contextmenu.group.list.forEach((item: any, index: number, arr: any[]) => {
  1799. if (id === item._id || id === item.id) {
  1800. arr.splice(index, 1);
  1801. }
  1802. });
  1803. if (activedGroup.value !== '图片') {
  1804. let collection = activedGroup.value === '组件'
  1805. ? 'v.component'
  1806. : 'v';
  1807. // 更新后端组件信息
  1808. let ret = await updateCollection(collection, {
  1809. id,
  1810. folder: val === '默认' ? '' : val,
  1811. });
  1812. if (!ret) {
  1813. return;
  1814. }
  1815. }
  1816. // // 更新后端源文件夹列表
  1817. // if (contextmenu.group.name !== '默认') {
  1818. // await axios.post('/api/data/folders/update', {
  1819. // _id: contextmenu.group._id || contextmenu.group.id,
  1820. // list: contextmenu.group.list,
  1821. // });
  1822. // }
  1823. // 更新后端目标文件夹列表
  1824. // if (group.name !== '默认') {
  1825. // await axios.post('/api/data/folders/update', {
  1826. // _id: group._id || group.id,
  1827. // list: group.list,
  1828. // });
  1829. // }
  1830. // let filename: string =
  1831. // contextmenu.component.filename || contextmenu.component.image;
  1832. // if (imageDrive && filename.startsWith(imageDrive)) {
  1833. // filename = filename.slice(imageDrive.length);
  1834. // }
  1835. let path: string =
  1836. contextmenu.component.filename || contextmenu.component.image;
  1837. //更新缩略图位置
  1838. // await axios.post('/api/files/update', {
  1839. // filenames: [filename],
  1840. // 'metadata.directory': `/大屏/${activedGroup.value}/${val || '默认'}`,
  1841. // });
  1842. // 原接口路径是 /api/file/{fullname}
  1843. // 因为img的路径中包含file,所以做如下拼接
  1844. if (imageDrive && path.startsWith(imageDrive)) {
  1845. path = path.slice(imageDrive.length);
  1846. }
  1847. if(path.startsWith('/file')) {
  1848. path = '/api' + path;
  1849. } else if(!path.startsWith('/api/file')) {
  1850. path = '/api/file' + path;
  1851. }
  1852. await axios.patch(`${path}`, {
  1853. // filenames: [filename],
  1854. directory: `/大屏/${activedGroup.value}/${val || '默认'}`,
  1855. });
  1856. break;
  1857. }
  1858. contextmenu.activeValue = 0;
  1859. };
  1860. const hideContextmenu = () => {
  1861. contextmenu.visible = false;
  1862. };
  1863. const _delComponent = async () => {
  1864. // const id = contextmenu.component._id || contextmenu.component.id;
  1865. if (['组件', '方案', '模板'].includes(activedGroup.value)) {
  1866. let collection = delDialog.contextmenuObj.component.component
  1867. ? 'v.component'
  1868. : 'v';
  1869. const id =
  1870. delDialog.contextmenuObj.component._id ||
  1871. delDialog.contextmenuObj.component.id;
  1872. try {
  1873. await axios.post(`/api/data/${collection}/delete`, {
  1874. id,
  1875. });
  1876. } catch (e) {
  1877. console.error(e);
  1878. return;
  1879. }
  1880. //删除缩略图
  1881. if (delDialog.contextmenuObj.component.image) {
  1882. await delImage(delDialog.contextmenuObj.component.image);
  1883. }
  1884. // 前端:从源文件夹移出组件
  1885. delDialog.contextmenuObj.group.list.forEach(
  1886. (item: any, index: number, arr: any[]) => {
  1887. if (id === item._id || id === item.id) {
  1888. arr.splice(index, 1);
  1889. }
  1890. }
  1891. );
  1892. // 更新后端源文件夹列表
  1893. if (delDialog.contextmenuObj.group.name !== '默认') {
  1894. await axios.post('/api/data/folders/update', {
  1895. _id:
  1896. delDialog.contextmenuObj.group._id ||
  1897. delDialog.contextmenuObj.group.id,
  1898. list: delDialog.contextmenuObj.group.list,
  1899. });
  1900. }
  1901. } else {
  1902. const id =
  1903. delDialog.contextmenuObj.component._id ||
  1904. delDialog.contextmenuObj.component.id;
  1905. delDialog.contextmenuObj.group.list.forEach(
  1906. (item: any, index: number, arr: any[]) => {
  1907. if (id && (id === item._id || id === item.id)) {
  1908. arr.splice(index, 1);
  1909. }
  1910. if (!id) {
  1911. if (item.url === delDialog.contextmenuObj.component.url) {
  1912. arr.splice(index, 1);
  1913. }
  1914. }
  1915. }
  1916. );
  1917. await axios.post(`/api/files/delete`, {
  1918. fullnames: [delDialog.contextmenuObj.component.filename],
  1919. physically: true,
  1920. });
  1921. }
  1922. delDialog.show = false;
  1923. delDialog.contextmenuObj = {};
  1924. MessagePlugin.success('删除成功');
  1925. };
  1926. const current = ref(false);
  1927. const delComponent = async () => {
  1928. // const id = contextmenu.component._id || contextmenu.component.id;
  1929. if (['组件', '方案', '模板'].includes(activedGroup.value)) {
  1930. // let collection = delDialog.contextmenuObj.component.component
  1931. // ? 'v.component'
  1932. // : 'v';
  1933. let collection = '';
  1934. if(activedGroup.value == '组件') {
  1935. collection = 'v.component'
  1936. } else {
  1937. collection = 'v'
  1938. }
  1939. const id =
  1940. delDialog.contextmenuObj.component._id ||
  1941. delDialog.contextmenuObj.component.id;
  1942. try {
  1943. await axios.post(`/api/data/${collection}/delete`, {
  1944. id,
  1945. });
  1946. } catch (e) {
  1947. console.error(e);
  1948. return;
  1949. }
  1950. // 前端:从源文件夹移出组件
  1951. delDialog.contextmenuObj.group.list.forEach(
  1952. (item: any, index: number, arr: any[]) => {
  1953. if (id === item._id || id === item.id) {
  1954. arr.splice(index, 1);
  1955. }
  1956. }
  1957. );
  1958. if(current.value){
  1959. router.push({
  1960. path: '/',
  1961. query: {
  1962. r: Date.now() + '',
  1963. },
  1964. });
  1965. };
  1966. } else {
  1967. const id =
  1968. delDialog.contextmenuObj.component._id ||
  1969. delDialog.contextmenuObj.component.id;
  1970. delDialog.contextmenuObj.group.list.forEach(
  1971. (item: any, index: number, arr: any[]) => {
  1972. if (id && (id === item.id || id === item._id)) {
  1973. arr.splice(index, 1);
  1974. }
  1975. if (!id) {
  1976. if (item.url === delDialog.contextmenuObj.component.url) {
  1977. arr.splice(index, 1);
  1978. }
  1979. }
  1980. }
  1981. );
  1982. // }
  1983. let fullname: string =
  1984. delDialog.contextmenuObj.component.fullname ||
  1985. delDialog.contextmenuObj.component.image;
  1986. //if (imageDrive && fullname.startsWith(imageDrive)) {
  1987. // fullname = fullname.slice(imageDrive.length);
  1988. //}
  1989. if(fullname.startsWith('/file')) {
  1990. fullname = fullname.slice('/file'.length);
  1991. }
  1992. if(fullname.startsWith('/api/file/')) {
  1993. fullname = fullname.slice('/api/file/'.length);
  1994. }
  1995. await axios.post(`/api/files/delete`, {
  1996. fullnames: [fullname],
  1997. physically: true,
  1998. });
  1999. }
  2000. delDialog.show = false;
  2001. delDialog.contextmenuObj = {};
  2002. MessagePlugin.success('删除成功');
  2003. };
  2004. const drop = (obj: any) => {
  2005. dropped = true;
  2006. if (obj) {
  2007. Array.isArray(obj) && open(obj[0]);
  2008. } else {
  2009. MessagePlugin.warning('正在请求网络数据中,请稍后重试');
  2010. }
  2011. };
  2012. const onSubmitOrder = async () => {
  2013. const result: any = await axios.post('/api/order/datas/submit', {
  2014. collection: 'v',
  2015. id: chargeDialog.data.id||chargeDialog.data._id,
  2016. });
  2017. if (result) {
  2018. wechatPayDialog.order = result;
  2019. wechatPayDialog.show = true;
  2020. }
  2021. };
  2022. const getPayResult = async () => {
  2023. const result: { state: number } = await axios.post('/api/order/pay/state', {
  2024. id: wechatPayDialog.order.id || wechatPayDialog.order._id,
  2025. });
  2026. if (result && result.state) {
  2027. return true;
  2028. }
  2029. };
  2030. const onChargeSuccess = () => {
  2031. MessagePlugin.success('支付成功!');
  2032. wechatPayDialog.show = false;
  2033. chargeDialog.show = false;
  2034. };
  2035. const onSearch = () => {
  2036. debounce(searchGraphics, 300);
  2037. };
  2038. const searchGraphics = async () => {
  2039. if (search.value) {
  2040. activedPanels[activedGroup.value].splice(
  2041. 0,
  2042. activedPanels[activedGroup.value].length
  2043. );
  2044. }
  2045. for (const group of subGroups.value) {
  2046. for (const item of group.list) {
  2047. if (search.value) {
  2048. item.visible = searchObjectPinyin(item, 'name', search.value);
  2049. } else {
  2050. item.visible = true;
  2051. }
  2052. }
  2053. if (search.value) {
  2054. activedPanels[activedGroup.value].push(group.name);
  2055. }
  2056. }
  2057. };
  2058. const onFold = () => {
  2059. if (!activedPanels[activedGroup.value]) {
  2060. return;
  2061. }
  2062. if (activedPanels[activedGroup.value].length) {
  2063. activedPanels[activedGroup.value] = [];
  2064. } else {
  2065. activedPanels[activedGroup.value] = [];
  2066. for (const item of subGroups.value) {
  2067. activedPanels[activedGroup.value].push(item.name);
  2068. }
  2069. }
  2070. };
  2071. const loadImage = (elem: any) => {
  2072. if (elem.isSvg) {
  2073. makeSvg(elem);
  2074. if (activedGroup.value === '设备') {
  2075. throttle(renderPngGroup, 100);
  2076. }
  2077. }
  2078. };
  2079. const renderPngGroup = () => {
  2080. subGroups.value = pngs;
  2081. };
  2082. let uploadGroup: any;
  2083. const onSelectFiles = (item: any) => {
  2084. uploadGroup = item;
  2085. };
  2086. const beforeUpload = (file: any) => {
  2087. if (!(user && user.id)) {
  2088. MessagePlugin.warning('请先登录!');
  2089. return false;
  2090. }
  2091. return true;
  2092. };
  2093. /*
  2094. * @description 根据上传的文件处理为meta2d能够识别的内容
  2095. * */
  2096. function processFileObj(fileObj, c) {
  2097. return new Promise((resolve) => {
  2098. if (fileObj.name.endsWith('.svg')) {
  2099. let fileReader = new FileReader();
  2100. fileReader.readAsText(fileObj.raw);
  2101. fileReader.onload = async () => {
  2102. let svgText = fileReader.result;
  2103. c.componentDatas = parseSvg(svgText as string);
  2104. c.component = true;
  2105. c.tags = ['svg'];
  2106. resolve(c);
  2107. };
  2108. } else {
  2109. // 除了svg 其他一律按照图片处理,这样是否会有问题?
  2110. resolve(c);
  2111. }
  2112. });
  2113. }
  2114. const fileSuccessed = async (content: any) => {
  2115. // 组件中去掉了上传图片入口
  2116. // if (activedGroup.value === '组件') {
  2117. // const c: any = {
  2118. // name: filename(content.file.name),
  2119. // image:
  2120. // content.response.url ||
  2121. // content.response.metadata.url ||
  2122. // `/file${content.response.filename}`,
  2123. // folder: uploadGroup.name === '默认' ? '' : uploadGroup.name,
  2124. // };
  2125. // let rst = await processFileObj(
  2126. // { raw: content.file.raw, name: content.file.name },
  2127. // c
  2128. // );
  2129. // const ret: any = await addCollection('v.component', rst);
  2130. // c._id = ret._id || ret.id;
  2131. // if (ret && uploadGroup.name !== '默认') {
  2132. // if (!uploadGroup.list) {
  2133. // uploadGroup.list = [];
  2134. // }
  2135. // uploadGroup.list.push(c);
  2136. // await axios.post('/api/data/folders/update', {
  2137. // _id: uploadGroup._id || uploadGroup.id,
  2138. // list: uploadGroup.list,
  2139. // });
  2140. // } else {
  2141. // if (!uploadGroup.list) {
  2142. // uploadGroup.list = [];
  2143. // }
  2144. // uploadGroup.list.push(c);
  2145. // }
  2146. // uploadGroup.list.push(c);
  2147. // } else if (activedGroup.value === '图片') {
  2148. uploadGroup.list.push({
  2149. ...content.response,
  2150. image:
  2151. content.response.url ||
  2152. content.response.metadata.url ||
  2153. `/file${content.response.filename}`,
  2154. visible: true,
  2155. folder: content.response.directory || content.response.metadata.directory,
  2156. });
  2157. // }
  2158. MessagePlugin.success('上传成功');
  2159. };
  2160. const delFolder = async (item: any) => {
  2161. if (item.list?.length) {
  2162. MessagePlugin.error('文件夹不为空!');
  2163. return;
  2164. }
  2165. const id = item.id || item._id;
  2166. let ret: any;
  2167. if (activeAssets.value !== 'user') {
  2168. return;
  2169. }
  2170. // if (['组件', '方案', '模板'].includes(activedGroup.value)) {
  2171. // ret = await axios.post('/api/data/folders/delete', {
  2172. // id,
  2173. // });
  2174. // } else if (activedGroup.value === '图片') {
  2175. // ret = await axios.post('/api/directory/delete', {
  2176. // fullpaths: [`/大屏/${item.name}`],
  2177. // });
  2178. // }
  2179. ret = await axios.post('/api/directory/delete', {
  2180. fullpaths: [`/大屏/${activedGroup.value}/${item.name}`],
  2181. physically: true
  2182. });
  2183. if (ret) {
  2184. const i = subGroups.value.findIndex(
  2185. (elem: any) => id === elem._id || id === elem.id
  2186. );
  2187. i >= 0 && subGroups.value.splice(i, 1);
  2188. }
  2189. };
  2190. const reloadCurrent = () => {
  2191. groupChange(activedGroup.value);
  2192. };
  2193. const updateAfterSave = (e) => {
  2194. if (activeAssets.value === 'user') {
  2195. if (e === 'v.component' && activedGroup.value === '组件') {
  2196. groupChange('组件');
  2197. } else if (e === 'v-template' && activedGroup.value === '模板') {
  2198. groupChange('模板');
  2199. } else if (e === '' && activedGroup.value === '方案') {
  2200. groupChange('方案');
  2201. }
  2202. }
  2203. };
  2204. const onManageGraphic = () => {
  2205. if (activedGroup.value === '素材') {
  2206. materials.forEach((item) => {
  2207. item.list.forEach((_item) => {
  2208. if(_item.visible === undefined){
  2209. _item.visible = true;
  2210. }
  2211. });
  2212. });
  2213. manageDialog.data = deepClone(materials);
  2214. } else if (activedGroup.value === '设备') {
  2215. pngs.forEach((item) => {
  2216. item.list.forEach((_item) => {
  2217. if(_item.visible === undefined){
  2218. _item.visible = true;
  2219. }
  2220. });
  2221. });
  2222. manageDialog.data = deepClone(pngs);
  2223. }
  2224. manageDialog.show = true;
  2225. };
  2226. const manageConfirm = () => {
  2227. //TODO 后续存放到后端 目前本地存储
  2228. if (activedGroup.value === '素材') {
  2229. localforage.setItem('le5leV-materials', JSON.stringify(manageDialog.data));
  2230. materials.length = 0;
  2231. materials.push(...manageDialog.data);
  2232. } else if (activedGroup.value === '设备') {
  2233. localforage.setItem('le5leV-pngs', JSON.stringify(manageDialog.data));
  2234. pngs.length = 0;
  2235. pngs.push(...manageDialog.data);
  2236. }
  2237. subGroups.value = manageDialog.data;
  2238. manageDialog.show = false;
  2239. };
  2240. onMounted(() => {
  2241. //js线性图元
  2242. setTimeout(()=>{
  2243. if (globalThis.meta2dTools?.length !== globalThis.jsDiagramNum) {
  2244. let jsLoadInterval = setInterval(() => {
  2245. if (globalThis.meta2dTools?.length == globalThis.jsDiagramNum) {
  2246. getJsDiagram();
  2247. clearInterval(jsLoadInterval);
  2248. }
  2249. }, 500);
  2250. } else {
  2251. getJsDiagram();
  2252. }
  2253. },100);
  2254. groupChange('方案');
  2255. document.addEventListener('dragstart', dragstart, false);
  2256. document.addEventListener('dragend', dragend, false);
  2257. setTimeout(() => {
  2258. meta2d.on('drop', drop);
  2259. meta2d.on('logout', reloadCurrent);
  2260. meta2d.on('business-save', updateAfterSave);
  2261. meta2d.on('business-assets', changeAssets);
  2262. }, 2000);
  2263. });
  2264. function getJsDiagram() {
  2265. if (globalThis.registerToolsNew) {
  2266. (window as any).registerToolsNew();
  2267. const temJSClass = [];
  2268. const temJSMaterial = [];
  2269. globalThis.meta2dTools.forEach((item: any) => {
  2270. if (temJSClass.indexOf(item.subClassName) === -1) {
  2271. temJSClass.push(item.subClassName);
  2272. temJSMaterial.push({
  2273. name: item.subClassName,
  2274. show: true,
  2275. list: [],
  2276. });
  2277. }
  2278. temJSMaterial.forEach((_class: any) => {
  2279. if (_class.name === item.subClassName) {
  2280. _class.list.push(item);
  2281. }
  2282. });
  2283. });
  2284. jsDiagrams.push(...temJSMaterial);
  2285. // 切换回页面仍需要注册,所以此处不清空
  2286. // window.meta2dTools = undefined;
  2287. }
  2288. }
  2289. const changeAssets = (e)=>{
  2290. if(e){
  2291. activeAssets.value = 'system';
  2292. assetsChange( activeAssets.value);
  2293. }
  2294. }
  2295. onUnmounted(() => {
  2296. document.removeEventListener('dragstart', dragstart);
  2297. document.removeEventListener('dragend', dragend);
  2298. meta2d.off('drop', drop);
  2299. meta2d.off('logout', reloadCurrent);
  2300. meta2d.off('business-save', updateAfterSave);
  2301. meta2d.off('business-assets', changeAssets);
  2302. });
  2303. </script>
  2304. <style lang="postcss" scoped>
  2305. .graphics {
  2306. display: flex;
  2307. flex-direction: column;
  2308. background-color: var(--color-background);
  2309. /* z-index: 2; */
  2310. .group-asset {
  2311. height: 40px;
  2312. justify-content: center;
  2313. align-items: center;
  2314. display: flex;
  2315. .t-radio-group.t-radio-group--filled {
  2316. padding: 0px;
  2317. height: 32px;
  2318. background-color: #fff0;
  2319. .t-radio-button::before{
  2320. content: none;
  2321. }
  2322. }
  2323. :deep(.t-radio-button__label) {
  2324. margin: auto;
  2325. }
  2326. .t-radio-button {
  2327. width: 72px;
  2328. height: 32px;
  2329. color: var(--color);
  2330. padding: 0px;
  2331. &:hover {
  2332. color: var(--color-primary);
  2333. }
  2334. &.t-is-checked {
  2335. background-color: var(--color-primary) !important;
  2336. color: #fff !important;
  2337. border-radius: 3px;
  2338. margin: 1px;
  2339. height: 28px;
  2340. }
  2341. }
  2342. }
  2343. .groups-panel {
  2344. display: grid;
  2345. grid-template-columns: 50px 250px;
  2346. border-top: 1px solid var(--color-background-input);
  2347. flex-grow: 1;
  2348. overflow-y: auto;
  2349. font-size: 12px;
  2350. z-index: 2;
  2351. .groups {
  2352. max-height: calc(100vh - 80px);
  2353. overflow-y: auto;
  2354. background: var(--color-background-groups);
  2355. & > div {
  2356. display: flex;
  2357. flex-direction: column;
  2358. align-items: center;
  2359. padding: 16px 4px;
  2360. line-height: 1;
  2361. cursor: pointer;
  2362. span{
  2363. width: 6ch;
  2364. line-height: 15px;
  2365. padding-left: 2px;
  2366. text-align: center;
  2367. }
  2368. .t-icon {
  2369. font-size: 20px;
  2370. margin-bottom: 8px;
  2371. }
  2372. .l-icon {
  2373. font-size: 24px;
  2374. margin-bottom: 8px;
  2375. }
  2376. &:hover {
  2377. color: var(--color-primary);
  2378. }
  2379. }
  2380. .active {
  2381. background-color: var(--color-background-active);
  2382. color: var(--color-primary);
  2383. border-left: 2px solid var(--color-primary);
  2384. }
  2385. }
  2386. .list {
  2387. overflow-y: auto;
  2388. max-height: calc(100vh - 80px);
  2389. background-color: var(--color-background-active);
  2390. /* padding-top: 8px; */
  2391. .input-search {
  2392. flex-shrink: 0;
  2393. /* height: 40px; */
  2394. position: sticky;
  2395. top: 0px;
  2396. z-index: 10;
  2397. padding: 16px;
  2398. color: #878f9c;
  2399. margin-top: -10px;
  2400. .btn {
  2401. background: #fff0;
  2402. img {
  2403. background-color: #fff0;
  2404. margin-top: 9px;
  2405. }
  2406. /* .t-icon {
  2407. background: #fff0;
  2408. } */
  2409. }
  2410. }
  2411. .div-manage {
  2412. position: sticky;
  2413. bottom: 2px;
  2414. z-index: 10;
  2415. margin-top: 800px;
  2416. }
  2417. * {
  2418. background-color: var(--color-background-active);
  2419. }
  2420. :deep(.t-collapse) {
  2421. /* min-height: 100vh; */
  2422. border: none;
  2423. }
  2424. :deep(.t-collapse-panel__header) {
  2425. border: none;
  2426. font-size: 12px;
  2427. font-weight: 400;
  2428. padding: 8px 8px 8px 16px;
  2429. & > .t-space {
  2430. display: none;
  2431. }
  2432. & > .t-space:focus {
  2433. display: inline-flex;
  2434. }
  2435. &:hover .t-collapse-panel__icon,
  2436. &:hover > .flex {
  2437. color: var(--color-primary);
  2438. }
  2439. .t-collapse-panel__icon,
  2440. .t-collapse-panel__icon * {
  2441. transition: none;
  2442. }
  2443. .t-icon {
  2444. font-size: 13px;
  2445. }
  2446. }
  2447. :deep(.t-collapse-panel__wrapper:hover) {
  2448. .t-collapse-panel__header > .t-space {
  2449. display: inline-flex;
  2450. }
  2451. }
  2452. :deep(.t-collapse-panel__body) {
  2453. border: none;
  2454. }
  2455. :deep(.t-collapse-panel__content) {
  2456. background-color: var(--color-background-active);
  2457. padding: 4px 4px 20px 4px;
  2458. display: grid;
  2459. grid-template-columns: 1fr 1fr 1fr;
  2460. grid-row-gap: 12px;
  2461. }
  2462. :deep(.t-loading--center) {
  2463. width: 100px;
  2464. .t-loading__text {
  2465. margin-left: 8px;
  2466. height: 24px;
  2467. }
  2468. }
  2469. :deep(.t-image__error) {
  2470. .t-space-item:last-child {
  2471. display: none;
  2472. }
  2473. }
  2474. :deep(.t-image__loading) {
  2475. .t-space-item:last-child {
  2476. display: none;
  2477. }
  2478. }
  2479. .graphic {
  2480. position: relative;
  2481. padding: 10px 0;
  2482. border-radius: 2px;
  2483. border: 1px solid transparent;
  2484. &:hover {
  2485. cursor: pointer;
  2486. border-color: var(--color-primary);
  2487. }
  2488. p {
  2489. margin-top: 10px;
  2490. padding: 0 8px;
  2491. text-align: center;
  2492. font-size: 12px;
  2493. height: 12px;
  2494. line-height: 1;
  2495. overflow: hidden;
  2496. text-overflow: ellipsis;
  2497. display: -webkit-box;
  2498. -webkit-line-clamp: 1;
  2499. word-break: break-all;
  2500. -webkit-box-orient: vertical;
  2501. }
  2502. .t-image__wrapper {
  2503. height: 32px;
  2504. width: 32px;
  2505. margin: auto;
  2506. :deep(.t-image) {
  2507. border-radius: 2px;
  2508. }
  2509. }
  2510. svg {
  2511. color: var(--color);
  2512. height: 32px;
  2513. width: 100%;
  2514. margin: auto;
  2515. }
  2516. .svg-box {
  2517. height: 32px;
  2518. width: 32px;
  2519. margin-left: calc(50% - 16px);
  2520. margin-top: 10px;
  2521. margin-bottom: 10px;
  2522. &:deep(svg) {
  2523. height: 100%;
  2524. width: 100%;
  2525. .cls-1 {
  2526. stroke: var(--color) !important;
  2527. stroke-width: 4px;
  2528. fill: none;
  2529. stroke-dasharray: none;
  2530. opacity: 1;
  2531. }
  2532. path{
  2533. stroke: var(--color) !important;
  2534. }
  2535. }
  2536. }
  2537. .price {
  2538. position: absolute;
  2539. top: 8px;
  2540. right: 8px;
  2541. display: inline-block;
  2542. z-index: 1;
  2543. border-radius: 2px;
  2544. background-color: #ff400060;
  2545. color: var(--color-bland);
  2546. font-size: 10px;
  2547. line-height: 1;
  2548. padding: 3px;
  2549. }
  2550. }
  2551. }
  2552. .two-columns {
  2553. :deep(.t-collapse-panel__content) {
  2554. grid-template-columns: 1fr 1fr;
  2555. }
  2556. .graphic {
  2557. .t-image__wrapper {
  2558. width: 100px;
  2559. height: 56.25px;
  2560. background-color: '#162030';
  2561. }
  2562. }
  2563. }
  2564. }
  2565. .context-menu-box {
  2566. position: fixed;
  2567. z-index: 200;
  2568. & > div {
  2569. width: 140px !important;
  2570. position: static;
  2571. }
  2572. :deep(.t-menu) {
  2573. .t-menu__item {
  2574. &.t-is-opened {
  2575. background-color: var(--color-background-popup-hover);
  2576. transition: none !important;
  2577. }
  2578. }
  2579. .t-fake-arrow {
  2580. transform: rotate(-90deg) !important;
  2581. }
  2582. .t-fake-arrow--active {
  2583. transform: rotate(90deg) !important;
  2584. }
  2585. }
  2586. }
  2587. :deep(.dialog-manage) {
  2588. .t-dialog__body {
  2589. height: 500px;
  2590. overflow: scroll;
  2591. }
  2592. .t-collapse {
  2593. border: 0px;
  2594. }
  2595. .t-collapse-panel__header {
  2596. border: 0px;
  2597. }
  2598. .t-collapse-panel__body {
  2599. border: 0px;
  2600. }
  2601. .t-collapse-panel__content {
  2602. display: grid;
  2603. grid-template-columns: 1fr 1fr 1fr 1fr;
  2604. /* grid-template-rows: repeat(100, 100px); */
  2605. grid-auto-rows: minmax(100px, auto);
  2606. grid-row-gap: 20px;
  2607. grid-column-gap: 20px;
  2608. }
  2609. .t-collapse-panel__body {
  2610. background: #fff0;
  2611. }
  2612. .manage-list {
  2613. max-height: 310px;
  2614. border: 1px solid #fff;
  2615. position: relative;
  2616. border: 1px solid #535f79;
  2617. position: relative;
  2618. border-radius: 2px;
  2619. .t-checkbox {
  2620. position: absolute;
  2621. right: 0px;
  2622. top: 10px;
  2623. z-index: 10;
  2624. }
  2625. }
  2626. }
  2627. :deep(.dialog-charge){
  2628. .t-dialog__body {
  2629. iframe{
  2630. width: 100%;
  2631. height: 80vh;
  2632. }
  2633. }
  2634. }
  2635. }
  2636. </style>