Graphics.vue 73 KB

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