Graphics.vue 78 KB

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