Graphics.vue 76 KB

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