Graphics.vue 74 KB

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