Header.vue 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115
  1. <template>
  2. <div class="app-header">
  3. <a class="logo" :href="enterprise.home" target="_blank">
  4. <img src="/favicon.ico" />
  5. <span> {{ enterprise.name }}</span>
  6. </a>
  7. <t-dropdown
  8. :minColumnWidth="200"
  9. :maxHeight="560"
  10. :delay2="[10, 150]"
  11. overlayClassName="header-dropdown"
  12. trigger1="click"
  13. >
  14. <a> 文件 </a>
  15. <t-dropdown-menu>
  16. <t-dropdown-item @click="newFile">
  17. <a>新建文件</a>
  18. </t-dropdown-item>
  19. <t-dropdown-item @click="load(true)">
  20. <a>打开文件</a>
  21. </t-dropdown-item>
  22. <t-dropdown-item divider="true" @click="load">
  23. <a>导入文件</a>
  24. </t-dropdown-item>
  25. <t-dropdown-item>
  26. <a @click="save()">保存</a>
  27. </t-dropdown-item>
  28. <t-dropdown-item>
  29. <a @click="save(SaveType.SaveAs, '', undefined, 1)">另存为</a>
  30. </t-dropdown-item>
  31. <t-dropdown-item divider="true">
  32. <a @click="downloadJson">下载JSON文件</a>
  33. </t-dropdown-item>
  34. <t-dropdown-item>
  35. <a @click="downloadZip">
  36. <div class="flex">
  37. 导出为ZIP文件 <span class="flex-grow"></span>
  38. <!-- <span><label>VIP</label></span> -->
  39. </div>
  40. </a>
  41. </t-dropdown-item>
  42. <t-dropdown-item>
  43. <a @click="downloadHtml">
  44. <div class="flex">
  45. 下载离线部署包 <span class="flex-grow"></span>
  46. <!-- <span><label>企</label></span> -->
  47. </div>
  48. </a>
  49. </t-dropdown-item>
  50. <t-dropdown-item>
  51. <a @click="downloadVue3">
  52. <div class="flex">
  53. 下载Vue3组件包 <span class="flex-grow"></span>
  54. <!-- <span><label>企</label></span> -->
  55. </div>
  56. </a>
  57. </t-dropdown-item>
  58. <t-dropdown-item>
  59. <a @click="downloadVue2">
  60. <div class="flex">
  61. 下载Vue2组件包 <span class="flex-grow"></span>
  62. <!-- <span><label>企</label></span> -->
  63. </div>
  64. </a>
  65. </t-dropdown-item>
  66. <t-dropdown-item divider="true">
  67. <a @click="downloadReact">
  68. <div class="flex">
  69. 下载React组件包 <span class="flex-grow"></span>
  70. <!-- <span><label>企</label></span> -->
  71. </div>
  72. </a>
  73. </t-dropdown-item>
  74. <t-dropdown-item>
  75. <a @click="downloadPng">下载为PNG</a>
  76. </t-dropdown-item>
  77. <t-dropdown-item divider="true">
  78. <a @click="downloadSvg">下载为SVG</a>
  79. </t-dropdown-item>
  80. <t-dropdown-item>
  81. <a @click="switchTheme('light')">明亮主题</a>
  82. </t-dropdown-item>
  83. <t-dropdown-item>
  84. <a @click="switchTheme('dark')">暗黑主题</a>
  85. </t-dropdown-item>
  86. </t-dropdown-menu>
  87. </t-dropdown>
  88. <t-dropdown
  89. :minColumnWidth="180"
  90. :maxHeight="500"
  91. :delay2="[10, 150]"
  92. overlayClassName="header-dropdown"
  93. >
  94. <a> 编辑 </a>
  95. <t-dropdown-menu>
  96. <t-dropdown-item>
  97. <a @click="onUndo">
  98. <div class="flex">
  99. 撤销 <span class="flex-grow"></span> Ctrl + Z
  100. </div>
  101. </a>
  102. </t-dropdown-item>
  103. <t-dropdown-item divider="true">
  104. <a @click="onRedo">
  105. <div class="flex">
  106. 重做 <span class="flex-grow"></span> Ctrl + Y
  107. </div>
  108. </a>
  109. </t-dropdown-item>
  110. <t-dropdown-item>
  111. <a @click="onCut">
  112. <div class="flex">
  113. 剪切 <span class="flex-grow"></span> Ctrl + X
  114. </div>
  115. </a>
  116. </t-dropdown-item>
  117. <t-dropdown-item>
  118. <a @click="onCopy">
  119. <div class="flex">
  120. 复制 <span class="flex-grow"></span> Ctrl + C
  121. </div>
  122. </a>
  123. </t-dropdown-item>
  124. <t-dropdown-item divider="true">
  125. <a @click="onPaste">
  126. <div class="flex">
  127. 粘贴 <span class="flex-grow"></span> Ctrl + V
  128. </div>
  129. </a>
  130. </t-dropdown-item>
  131. <t-dropdown-item>
  132. <a @click="onAll">
  133. <div class="flex">
  134. 全选 <span class="flex-grow"></span> Ctrl + A
  135. </div>
  136. </a>
  137. </t-dropdown-item>
  138. <t-dropdown-item>
  139. <a @click="onDelete">
  140. <div class="flex">删除 <span class="flex-grow"></span> DELETE</div>
  141. </a>
  142. </t-dropdown-item>
  143. </t-dropdown-menu>
  144. </t-dropdown>
  145. <t-dropdown
  146. :minColumnWidth="180"
  147. :maxHeight="500"
  148. :delay2="[10, 150]"
  149. overlayClassName="header-dropdown"
  150. >
  151. <a> 工具 </a>
  152. <t-dropdown-menu>
  153. <t-dropdown-item>
  154. <a @click="onScaleWindow">窗口大小</a>
  155. </t-dropdown-item>
  156. <t-dropdown-item>
  157. <a @click="onScaleUp">放大</a>
  158. </t-dropdown-item>
  159. <t-dropdown-item>
  160. <a @click="onScaleDown">缩小</a>
  161. </t-dropdown-item>
  162. <t-dropdown-item divider="true">
  163. <a @click="onScaleFull">100%视图</a>
  164. </t-dropdown-item>
  165. <t-dropdown-item>
  166. <a @click="showMap">
  167. <div class="flex middle">
  168. 鹰眼地图 <span class="flex-grow"></span>
  169. <!-- <t-icon v-show="map" name="check" /> -->
  170. <check-icon v-show="map" />
  171. </div>
  172. </a>
  173. </t-dropdown-item>
  174. <t-dropdown-item divider="true">
  175. <a @click="showMagnifier">
  176. <div class="flex middle">
  177. 放大镜 <span class="flex-grow"></span>
  178. <!-- <t-icon v-show="magnifier" name="check" /> -->
  179. <check-icon v-show="magnifier" />
  180. </div>
  181. </a>
  182. </t-dropdown-item>
  183. <t-dropdown-item>
  184. <a @click="onAutoAnchor">
  185. <div class="flex middle">
  186. 自动锚点 <span class="flex-grow"></span>
  187. <!-- <t-icon v-show="autoAnchor" name="check" /> -->
  188. <check-icon v-show="autoAnchor" />
  189. </div>
  190. </a>
  191. </t-dropdown-item>
  192. <t-dropdown-item divider="true">
  193. <a @click="onDisableAnchor">
  194. <div class="flex middle">
  195. 显示锚点 <span class="flex-grow"></span>
  196. <!-- <t-icon v-show="showAnchor" name="check" /> -->
  197. <check-icon v-show="showAnchor" />
  198. </div>
  199. </a>
  200. </t-dropdown-item>
  201. <t-dropdown-item>
  202. <a @click="onToggleAnchor">
  203. <div
  204. class="flex"
  205. :style="{
  206. color: showAnchor ? '' : '#4f5b75',
  207. }"
  208. >
  209. 添加/删除锚点 <span class="flex-grow"></span> A
  210. </div>
  211. </a>
  212. </t-dropdown-item>
  213. </t-dropdown-menu>
  214. </t-dropdown>
  215. <t-dropdown
  216. :minColumnWidth="180"
  217. :maxHeight="500"
  218. :delay2="[10, 150]"
  219. overlayClassName="header-dropdown"
  220. >
  221. <a> 帮助 </a>
  222. <t-dropdown-menu>
  223. <t-dropdown-item
  224. v-for="item in enterprise.helps_v"
  225. :divider="item.divider"
  226. >
  227. <a :href="item.url" target="_blank">{{ item.name }}</a>
  228. </t-dropdown-item>
  229. </t-dropdown-menu>
  230. </t-dropdown>
  231. <!-- <div style="width: 148px; flex-shrink: 0"></div> -->
  232. <input v-model="meta2dData.name" @change="onInputName($event)" />
  233. <a :href="enterprise.account" target="_blank">
  234. <!-- <t-icon name="home" /> -->
  235. <home-icon />
  236. 账户中心
  237. </a>
  238. <a :href="enterprise['v']" target="_blank" class="active">
  239. <!-- <t-icon name="desktop" /> -->
  240. <desktop-icon />
  241. 大屏可视化
  242. </a>
  243. <a :href="enterprise['3d']" target="_blank">
  244. <!-- <t-icon name="control-platform" /> -->
  245. <control-platform-icon />
  246. 3D可视化
  247. </a>
  248. <a :href="enterprise['2d']" target="_blank">
  249. <!-- <t-icon name="app" /> -->
  250. <app-icon />
  251. 2D可视化
  252. </a>
  253. <t-dropdown
  254. v-if="user.id"
  255. :minColumnWidth="200"
  256. :maxHeight="500"
  257. :delay2="[10, 150]"
  258. overlayClassName="custom-dropdown header"
  259. >
  260. <a style="margin-left: 32px; margin-right: 12px">
  261. <t-avatar
  262. size="small"
  263. :image="user.avatarUrl ? user.avatarUrl : baseUrl + 'img/avatar.png'"
  264. />
  265. </a>
  266. <t-dropdown-menu>
  267. <t-dropdown-item divider="true">
  268. <a :href="enterprise.account" target="_blank">
  269. {{ user.username }}
  270. <label
  271. class="ml-16 vip-label"
  272. :style="{
  273. color: user.limit > 1 ? '#ff4000' : '#D5C781',
  274. background: user.limit > 1 ? '#ff400030' : '#D5C78133',
  275. }"
  276. >VIP</label
  277. >
  278. </a>
  279. </t-dropdown-item>
  280. <t-dropdown-item divider="true">
  281. <a :href="`${enterprise.account}/v`" target="_blank"> 我的大屏 </a>
  282. </t-dropdown-item>
  283. <t-dropdown-item>
  284. <a :href="`${enterprise.account}/account/teams`" target="_blank">
  285. 我的团队
  286. </a>
  287. </t-dropdown-item>
  288. <t-dropdown-item>
  289. <a :href="`${enterprise.account}/account/info`" target="_blank">
  290. 账号信息
  291. </a>
  292. </t-dropdown-item>
  293. <t-dropdown-item divider="true">
  294. <a :href="`${enterprise.account}/account/security`" target="_blank">
  295. 安全设置
  296. </a>
  297. </t-dropdown-item>
  298. <t-dropdown-item>
  299. <a @click="logout">退出</a>
  300. </t-dropdown-item>
  301. </t-dropdown-menu>
  302. </t-dropdown>
  303. <div class="flex middle" v-else>
  304. <a class="button primary solid" style="width: 80px" :href="login()">
  305. 登录
  306. </a>
  307. </div>
  308. </div>
  309. <t-dialog
  310. v-if="payListDialog.show"
  311. v-model:visible="payListDialog.show"
  312. class="pay-dialog"
  313. :close-on-overlay-click="false"
  314. :top="95"
  315. :width="700"
  316. :cancel-btn="{
  317. content: '下载试用',
  318. variant: 'outline',
  319. style: {
  320. width: '100px',
  321. color:'#707B8F',
  322. marginRight:'8px'
  323. }
  324. }"
  325. confirm-btn="去支付"
  326. @cancel="downloadTrial"
  327. @close="payListDialog.show = false"
  328. @confirm="prePay"
  329. >
  330. <template #header>
  331. <div>
  332. <span style="vertical-align: middle">{{ payListDialog.title }}</span>
  333. <!-- <t-tooltip content="这是Tooltip内容"> -->
  334. <!-- @vue-ignore -->
  335. <a
  336. :href="payListDialog.href"
  337. target="_blank"
  338. class="hover"
  339. >
  340. <HelpCircleIcon class="hover" style="margin-left:12px;" />
  341. </a>
  342. <!-- </t-tooltip> -->
  343. </div>
  344. </template>
  345. <div class="pay-box">
  346. <div class="pay-title">{{ payListDialog.title }}</div>
  347. <div class="pay-price">
  348. <p>¥</p>
  349. <p>{{ data.deploy.price }}</p>
  350. </div>
  351. </div>
  352. <div class="pay-box pay-diagram">
  353. <div class="pay-up">
  354. <div class="pay-title">
  355. <t-checkbox v-model="data.payDiagram.checked"> 企业图形库
  356. </t-checkbox>
  357. <ChevronDownIcon @click="data.payDiagram.expend=false" v-if="data.payDiagram.expend" />
  358. <ChevronRightIcon @click="data.payDiagram.expend=true" v-else />
  359. </div>
  360. <div class="pay-price">
  361. <p>¥</p>
  362. <p>{{ data.payDiagram.price }}</p>
  363. </div>
  364. </div>
  365. <div v-if="data.payDiagram.expend" class="pay-down">
  366. <div v-for="item in data.payDiagram.list">
  367. <img v-if="item.img" :src="item.img" />
  368. <div v-else-if="item.svg" v-html="item.svg" ></div>
  369. <svg v-else class="l-icon" aria-hidden="true">
  370. <use :xlink:href="'#' + iotPensMap[item.name]?.icon"></use>
  371. </svg>
  372. </div>
  373. <p v-if="data.payDiagram.payAll">
  374. 【说明】检查到当前项目为老版本格式,需要购买整套SVG线性图元。
  375. </p>
  376. </div>
  377. </div>
  378. <div class="pay-footer">
  379. 合计
  380. <div>
  381. <p>¥</p>
  382. <p>{{ data.deploy.price+(data.payDiagram.checked?data.payDiagram.price:0) }}</p>
  383. </div>
  384. </div>
  385. </t-dialog>
  386. <t-dialog
  387. v-if="downloadZipDialog.show"
  388. v-model:visible="downloadZipDialog.show"
  389. class="pay-dialog"
  390. :close-on-overlay-click="false"
  391. :top="95"
  392. :width="700"
  393. :cancel-btn="{
  394. content: '直接下载',
  395. variant: 'outline',
  396. style: {
  397. width: '100px',
  398. color:'#707B8F',
  399. marginRight:'8px'
  400. }
  401. }"
  402. :confirm-btn="downloadZipDialog.checked?'去支付':null"
  403. @close="downloadZipDialog.show = false"
  404. @confirm="prePayDownloadZip"
  405. @cancel="doDownloadZip"
  406. >
  407. <template #header>
  408. <div>
  409. <span style="vertical-align: middle">导出为Zip文件</span>
  410. <t-tooltip content="这是Tooltip内容">
  411. <a
  412. :href="`https://doc${rootDomain}/document/155692631#%E5%AF%BC%E5%87%BA%E4%B8%BAZip%E6%96%87%E4%BB%B6`"
  413. target="_blank"
  414. class="hover"
  415. >
  416. <HelpCircleIcon style="margin-left:12px;" />
  417. </a>
  418. </t-tooltip>
  419. </div>
  420. </template>
  421. <div class="pay-box pay-diagram" style="font-size: 14px;
  422. line-height: 30px;
  423. color: #6E7B91;">
  424. Zip包仅包含数据文件和图片文件,不包含js等依赖库。
  425. <div >- 注意</div>Zip包用于平台(已包含js等依赖库)的快捷导入导出项目,无法作为独立部署包使用。
  426. <p v-if="downloadZipDialog.hasJs">
  427. <p>- 当前图纸包含js企业图形依赖库。</p>
  428. 项目中打开如果没有js企业图形依赖库,对应的图元将无法显示。
  429. 推荐下载为离线部署包(包含js企业图形依赖库)。
  430. </p>
  431. </div>
  432. <div class="pay-box pay-diagram">
  433. <div class="pay-up">
  434. <div class="pay-title">
  435. <t-checkbox v-model="downloadZipDialog.checked"> 企业图形库
  436. </t-checkbox>
  437. <ChevronDownIcon @click="downloadZipDialog.expend=false" v-if="downloadZipDialog.expend" />
  438. <ChevronRightIcon @click="downloadZipDialog.expend=true" v-else />
  439. </div>
  440. <div class="pay-price">
  441. <p>¥</p>
  442. <p>{{ downloadZipDialog.price }}</p>
  443. </div>
  444. </div>
  445. <div v-if="downloadZipDialog.expend" class="pay-down">
  446. <div v-for="item in downloadZipDialog.list">
  447. <img :src="item" />
  448. </div>
  449. </div>
  450. </div>
  451. <div class="pay-footer">
  452. 合计
  453. <div>
  454. <p>¥</p>
  455. <p>{{downloadZipDialog.checked? downloadZipDialog.price:0 }}</p>
  456. </div>
  457. </div>
  458. </t-dialog>
  459. <t-dialog
  460. v-if="wechatPayDialog.show"
  461. v-model:visible="wechatPayDialog.show"
  462. class="pay-dialog"
  463. header="乐吾乐收银台"
  464. :close-on-overlay-click="false"
  465. :top="95"
  466. :width="700"
  467. confirm-btn="支付完成"
  468. :cancel-btn="null"
  469. @close="wechatPayDialog.show = false"
  470. :footer="false"
  471. >
  472. <Pay
  473. :order="data.order"
  474. :alipay-url="data.order.alipayUrl"
  475. :code-url="data.order.codeUrl"
  476. @success="onSuccess"
  477. />
  478. </t-dialog>
  479. </template>
  480. <script lang="ts" setup>
  481. import {
  482. reactive,
  483. ref,
  484. onBeforeMount,
  485. onUnmounted,
  486. nextTick,
  487. computed,
  488. } from 'vue';
  489. import { useRouter, useRoute } from 'vue-router';
  490. import { useUser } from '@/services/user';
  491. import { MessagePlugin } from 'tdesign-vue-next';
  492. import {
  493. Meta2dBackData,
  494. dealwithFormatbeforeOpen,
  495. gotoAccount,
  496. checkData,
  497. } from '@/services/utils';
  498. import { readFile } from '@/services/file';
  499. import { compareVersion, baseVer, upgrade } from '@/services/upgrade';
  500. import { parseSvg } from '@meta2d/svg';
  501. import { Pen, getGlobalColor, isShowChild } from '@meta2d/core';
  502. import { cdn, upCdn, addCollection } from '@/services/api';
  503. // import JSZip from 'jszip';
  504. import axios from 'axios';
  505. import { switchTheme } from '@/services/theme';
  506. import { noLoginTip } from '@/services/utils';
  507. import {
  508. save,
  509. blank,
  510. newFile,
  511. SaveType,
  512. onScaleFull,
  513. onScaleWindow,
  514. showMagnifier,
  515. showMap,
  516. drawPen,
  517. map,
  518. magnifier,
  519. useDot,
  520. delAttrs,
  521. // useAssets,
  522. autoSaveAS,
  523. queryURLParams,
  524. dealDataBeforeOpen
  525. } from '@/services/common';
  526. import { useEnterprise } from '@/services/enterprise';
  527. import {
  528. CheckIcon,
  529. HomeIcon,
  530. DesktopIcon,
  531. ControlPlatformIcon,
  532. AppIcon,
  533. ChevronRightIcon,
  534. ChevronDownIcon,
  535. HelpCircleIcon
  536. } from 'tdesign-icons-vue-next';
  537. import {
  538. getDownloadList,
  539. getPayList,
  540. getComponentPurchased,
  541. get2dComponentJs,
  542. getTemPngs,
  543. getGoods,
  544. // preFrameDownload,
  545. zipBkImg,
  546. zipImages,
  547. Frame,
  548. img_cdn,
  549. img_upCdn,
  550. getDeployGoods,
  551. getFrameDownloadList,
  552. getDownloadZipList
  553. } from '@/services/download';
  554. import { formComponents, rootDomain } from '@/services/defaults';
  555. import Pay from './Pay.vue';
  556. import {getNetJsDiagram} from '@/services/material';
  557. import { useMeta2dData } from '@/services/common';
  558. import { upload } from '@/services/file';
  559. import { load3d } from '@/services/load3d';
  560. const { enterprise } = useEnterprise();
  561. const router = useRouter();
  562. const route = useRoute();
  563. const { meta2dData, setMeta2dData } = useMeta2dData();
  564. const baseUrl = import.meta.env.BASE_URL || '/';
  565. // const { assets, getAssets } = useAssets();
  566. const { user, signout } = useUser();
  567. const { setDot } = useDot();
  568. const data = reactive<any>({
  569. name: '新建项目',
  570. order: {
  571. codeUrl: '',
  572. id: '', //订单id
  573. },
  574. goods: [], //所有商品类型
  575. purchasedList: [], //已经购买的列表
  576. deploy:{
  577. price:400,
  578. },
  579. payDiagram: {
  580. price: 400,
  581. checked:true,
  582. expend:false,
  583. list:[],
  584. payAll:false
  585. },
  586. zips:{
  587. },
  588. payGoods:{},
  589. });
  590. onBeforeMount(async () => {
  591. // getAssets();
  592. // getNetJsDiagram();
  593. });
  594. const logout = () => {
  595. signout();
  596. meta2d.emit('logout');
  597. };
  598. const onInputName = (e) => {
  599. // (meta2d.store.data as Meta2dBackData).name = data.name;
  600. setMeta2dData({ name: e.target.value });
  601. setDot(true);
  602. };
  603. const initMeta2dName = () => {
  604. data.name = (meta2d.store.data as Meta2dBackData).name || '';
  605. setMeta2dData({ name: (meta2d.store.data as Meta2dBackData).name || '新建项目' });
  606. };
  607. let downloadList = new Set<any>();
  608. let downloadZip3dList:any[] = [];
  609. let iframeNum = 0;
  610. let compareNum = 0;
  611. const prePayList = reactive({
  612. pngs: new Set<string>(),
  613. jsPens: new Set<string>(),
  614. iotPens: new Set<string>(),
  615. svgPens: new Set<string>(),
  616. });
  617. let payListNum = 0;
  618. let comparePayListNum = 0;
  619. // let purchasedList = []; //已购买列表
  620. const iotPensMap = {};
  621. let downloadType: Frame = null;
  622. // const payPrice = ref(0);
  623. const getIotPensMap = () => {
  624. formComponents.forEach((item) => {
  625. item.list.forEach((_item) => {
  626. iotPensMap[_item.data.name] = { name: _item.name, icon: _item.icon };
  627. });
  628. });
  629. };
  630. nextTick(() => {
  631. meta2d.on('opened', initMeta2dName);
  632. window.addEventListener('message', dealWithMessage);
  633. getIotPensMap();
  634. });
  635. const dealWithMessage = async (e) => {
  636. if (
  637. typeof e.data !== 'string' ||
  638. !e.data ||
  639. e.data.startsWith('setImmediate')
  640. ) {
  641. return;
  642. }
  643. try {
  644. let data = JSON.parse(e.data);
  645. if (typeof data === 'object') {
  646. if (data.type) {
  647. if (data.name === 'download') {
  648. let list = data.data;
  649. if(downloadType === Frame.zip){
  650. compareNum += 1;
  651. downloadZip3dList = [...downloadZip3dList, ...list];
  652. if (compareNum >= iframeNum) {
  653. doDownloadZip();
  654. }
  655. }else{
  656. let folderName =downloadType===Frame.vue3?'meta2d-vue3':downloadType===Frame.vue2?'meta2d-vue2': 'meta2d-react';
  657. list.forEach((item) => {
  658. // if(item.path.startsWith('/meta3d/')){
  659. // item.path = `/${folderName}/public/${item.path}`;
  660. // }
  661. if(item.path.startsWith('/vue3/')||item.path.startsWith('/vue2/')||item.path.startsWith('/react/')){
  662. item.path = item.path.replace('vue3',folderName).replace('vue2',folderName).replace('react',folderName);
  663. }
  664. });
  665. downloadList = new Set([...downloadList, ...list]);
  666. compareNum += 1;
  667. if (compareNum >= iframeNum) {
  668. saveDownload();
  669. }
  670. }
  671. } else if (data.name === 'payList') {
  672. prePayList.pngs = new Set([...prePayList.pngs, ...data.data.pngs]);
  673. prePayList.jsPens = new Set([
  674. ...prePayList.jsPens,
  675. ...data.data.jsPens,
  676. ]);
  677. prePayList.iotPens = new Set([
  678. ...prePayList.iotPens,
  679. ...data.data.iotPens,
  680. ]);
  681. prePayList.svgPens = new Set([
  682. ...prePayList.svgPens,
  683. ...data.data.svgPens,
  684. ]);
  685. comparePayListNum += 1;
  686. if (comparePayListNum >= payListNum) {
  687. await showPayListDialog();
  688. }
  689. }
  690. // else if(data.name==='saveas'){
  691. // await autoSaveAS(data.id);
  692. // }
  693. } else {
  694. meta2d.emit(data.name);
  695. }
  696. } else {
  697. meta2d.emit(data);
  698. }
  699. } catch (e) {
  700. console.info(e);
  701. }
  702. };
  703. onUnmounted(() => {
  704. meta2d.off('opened', initMeta2dName);
  705. window.removeEventListener('message', dealWithMessage);
  706. });
  707. const login = () => {
  708. if(import.meta.env.BASE_URL.startsWith('/') ){
  709. return `${enterprise['account']}?cb=${encodeURIComponent(location.href)}`;
  710. }else{
  711. return `https://account${rootDomain}/login?cb=${encodeURIComponent(location.href)}`;
  712. }
  713. };
  714. function load(isNew = false) {
  715. const input = document.createElement('input');
  716. input.type = 'file';
  717. input.onchange = (event) => {
  718. const elem = event.target as HTMLInputElement;
  719. if (elem.files && elem.files[0]) {
  720. // 路由跳转 可能在 openFile 后执行
  721. if (elem.files[0].name.endsWith('.json')) {
  722. blank();
  723. openJson(elem.files[0]);
  724. if (isNew) {
  725. router.push({
  726. path: '/',
  727. query: {
  728. r: Date.now() + '',
  729. },
  730. });
  731. }
  732. } else if (elem.files[0].name.endsWith('.svg')) {
  733. MessagePlugin.info(
  734. '可二次编辑但转换存在损失,若作为图片使用,请使用右侧属性面板的上传图片功能'
  735. );
  736. openSvg(elem.files[0]);
  737. } else if (elem.files[0].name.endsWith('.zip')) {
  738. blank();
  739. router.push({
  740. path: '/',
  741. query: {
  742. r: Date.now() + '',
  743. },
  744. });
  745. setTimeout(() => {
  746. openZip(elem.files[0]);
  747. }, 500);
  748. } else {
  749. MessagePlugin.info('打开文件只支持 json,svg,zip 格式');
  750. }
  751. }
  752. };
  753. input.click();
  754. }
  755. const openJson = async (file: File) => {
  756. const text = await readFile(file);
  757. try {
  758. let data: Meta2dBackData = JSON.parse(text);
  759. if (!data.name) {
  760. data.name = file.name.replace('.json', '');
  761. }
  762. if (!data.version || compareVersion(data.version, baseVer) === -1) {
  763. // 如果版本号不存在或者版本号 version < 1.0.0
  764. data = upgrade(data, baseVer);
  765. }
  766. dealwithFormatbeforeOpen(data);
  767. for (const k of delAttrs) {
  768. delete (data as any)[k];
  769. }
  770. if(!data.background){
  771. data.background = '#1e2430';
  772. }
  773. if(!data.color){
  774. data.color = '#bdc7db';
  775. }
  776. dealDataBeforeOpen(data);
  777. if(!(data as any).oldV){
  778. if(!data.width){data.width= 1920};
  779. if(!data.height){data.height= 1080};
  780. }
  781. meta2d.open(data);
  782. } catch (e) {
  783. console.error(e);
  784. }
  785. };
  786. const openSvg = async (file: File) => {
  787. const text = await readFile(file);
  788. const pens: Pen[] = parseSvg(text);
  789. meta2d.canvas.addCaches = pens;
  790. MessagePlugin.info('svg转换成功,请点击画布决定放置位置');
  791. };
  792. const openZip = async (file: File) => {
  793. if (!(user && user.id)) {
  794. MessagePlugin.warning(noLoginTip);
  795. return;
  796. }
  797. // if (!user.isVip) {
  798. // gotoAccount();
  799. // return;
  800. // }
  801. if (!user.vip) {
  802. MessagePlugin.info('需要开通普通会员~');
  803. gotoAccount();
  804. return;
  805. }
  806. MessagePlugin.loading('正在读取...',0);
  807. const { default: JSZip } = await import('jszip');
  808. const zip = new JSZip();
  809. await zip.loadAsync(file,{base64:true});
  810. let fileName = file.name.slice(0, -4)
  811. let dataStr = '';
  812. for (const key in zip.files) {
  813. if (zip.files[key].dir) {
  814. continue;
  815. }
  816. if (key.endsWith('.json')) {
  817. // 认为只有一个 json 文件
  818. dataStr = await zip.file(key).async('string');
  819. break;
  820. }
  821. }
  822. if (!dataStr) {
  823. return false;
  824. }
  825. const imgReplaceArr = [];
  826. const _2dDataMap ={};
  827. const _3dDataMap ={};
  828. MessagePlugin.loading('正在上传文件...',0);
  829. for (const key in zip.files) {
  830. if (zip.files[key].dir) {
  831. continue;
  832. }
  833. let _keyLower = key.toLowerCase();
  834. if (
  835. _keyLower.endsWith('.png') ||
  836. _keyLower.endsWith('.svg') ||
  837. _keyLower.endsWith('.gif') ||
  838. _keyLower.endsWith('.jpg') ||
  839. _keyLower.endsWith('.jpeg')
  840. ) {
  841. let filename = key.substr(key.lastIndexOf('/') + 1);
  842. // 上传文件
  843. const form = new FormData();
  844. form.append('name', filename);
  845. form.append('directory', '/大屏/图片/默认');
  846. form.append('shared', true + '');
  847. form.append('file', await zip.file(key).async('blob'));
  848. form.append('conflict', 'new');
  849. const result: any = await axios.post('/api/image/upload', form);
  850. let arr = key.split('/');
  851. arr.shift();
  852. if(arr[0]===fileName){
  853. arr.shift();
  854. }
  855. let _key ='/'+ arr.join('/');
  856. if (result) {
  857. imgReplaceArr.push({ key: _key, url: result.url });
  858. }
  859. }else if(_keyLower.endsWith('.json')){
  860. let arr = key.split('/');
  861. arr.shift();
  862. if(arr[0]===fileName){
  863. arr.shift();
  864. }
  865. let data = await zip.file(key).async('string');
  866. if(!arr[0].endsWith('.json')){
  867. _2dDataMap[arr[0]] = data;
  868. }
  869. }else{
  870. // console.log("key",key);
  871. if(key.indexOf('3d')!==-1&&key.indexOf('files/')===-1){
  872. let id_3d = await load3d(zip,key);
  873. if(id_3d){
  874. // dataStr = dataStr.replaceAll(key, id_3d);
  875. let originId = key.split('3d-')[1];
  876. _3dDataMap[originId] = id_3d;
  877. }
  878. }
  879. }
  880. }
  881. //替换2d图片数据
  882. imgReplaceArr.forEach((item) => {
  883. dataStr = dataStr.replaceAll(item.key, item.url);
  884. for (let key in _2dDataMap) {
  885. _2dDataMap[key] = _2dDataMap[key].replaceAll(item.key, item.url);
  886. }
  887. });
  888. try {
  889. let domain = location.origin+ '/view';
  890. let data: Meta2dBackData = JSON.parse(dataStr);
  891. for(let i=0;i<data.pens.length;i++){
  892. const pen = data.pens[i];
  893. if(pen.name==='iframe'){
  894. let url = pen.iframe.split('?')[1]
  895. let params = queryURLParams(url);
  896. if(pen.iframe.indexOf('/2d/')!==-1 || pen.iframe.indexOf('/v/')!==-1 || pen.iframe.indexOf('/2d?')!==-1 ||pen.iframe.indexOf('/v?')!==-1){
  897. const idata = JSON.parse(_2dDataMap[params.id]);
  898. const ret:any = await addCollection('v',{
  899. data:idata,
  900. image:idata.image||'xxx',
  901. name:idata.name,
  902. folder:idata.folder,
  903. // userFlag:2,
  904. system:false,
  905. case:idata.case,
  906. });
  907. if(!ret){
  908. continue;
  909. }
  910. pen.iframe = `${domain}/v/?id=${ret.id}`;
  911. }else if(pen.iframe.indexOf('/3d')!==-1){
  912. pen.iframe = `${domain}/3d/?id=${_3dDataMap[params.id]}`;
  913. }
  914. }
  915. }
  916. if (data) {
  917. if (!data.name) {
  918. data.name = file.name.replace('.zip', '');
  919. }
  920. if (!data.version || compareVersion(data.version, baseVer) === -1) {
  921. // 如果版本号不存在或者版本号 version < 1.0.0
  922. data = upgrade(data, baseVer);
  923. }
  924. dealwithFormatbeforeOpen(data);
  925. const delAttrs = [
  926. 'userId',
  927. 'shared',
  928. 'team',
  929. 'owner',
  930. 'username',
  931. 'editor',
  932. 'editorId',
  933. 'editorName',
  934. 'createdAt',
  935. 'folder',
  936. 'image',
  937. 'id',
  938. '_id',
  939. 'view',
  940. 'updatedAt',
  941. 'star',
  942. 'recommend',
  943. ];
  944. for (const k of delAttrs) {
  945. delete (data as any)[k];
  946. }
  947. if(!data.background){
  948. data.background = '#1e2430';
  949. }
  950. if(!data.color){
  951. data.color = '#bdc7db';
  952. }
  953. if(!data.width){data.width= 1920};
  954. if(!data.height){data.height= 1080};
  955. dealDataBeforeOpen(data)
  956. meta2d.open(data);
  957. MessagePlugin.closeAll();
  958. MessagePlugin.success('导入成功!');
  959. }
  960. } catch (e) {
  961. return false;
  962. }
  963. };
  964. const _openZip = async (file: File) => {
  965. if (!(user && user.id)) {
  966. MessagePlugin.warning(noLoginTip);
  967. return;
  968. }
  969. // if (!user.isVip) {
  970. // gotoAccount();
  971. // return;
  972. // }
  973. if (!user.vip) {
  974. MessagePlugin.info('需要开通普通会员~');
  975. gotoAccount();
  976. return;
  977. }
  978. const { default: JSZip } = await import('jszip');
  979. const zip = new JSZip();
  980. await zip.loadAsync(file,{base64:true});
  981. let fileName = file.name.slice(0, -4)
  982. let dataStr = '';
  983. for (const key in zip.files) {
  984. if (zip.files[key].dir) {
  985. continue;
  986. }
  987. if (key.endsWith('.json')) {
  988. // 认为只有一个 json 文件
  989. dataStr = await zip.file(key).async('string');
  990. break;
  991. }
  992. }
  993. if (!dataStr) {
  994. return false;
  995. }
  996. for (const key in zip.files) {
  997. if (zip.files[key].dir) {
  998. continue;
  999. }
  1000. // let _png = key.indexOf('/png');
  1001. // let _img = key.indexOf('/img');
  1002. // let _image = key.indexOf('/image');
  1003. // let _file = key.indexOf('/file');
  1004. let _keyLower = key.toLowerCase();
  1005. // if (!key.endsWith('.json') && (_png !== -1 || _img !== -1 || _image !== -1 || _file !== -1)) {
  1006. if (
  1007. _keyLower.endsWith('.png') ||
  1008. _keyLower.endsWith('.svg') ||
  1009. _keyLower.endsWith('.gif') ||
  1010. _keyLower.endsWith('.jpg') ||
  1011. _keyLower.endsWith('.jpeg')
  1012. ) {
  1013. let filename = key.substr(key.lastIndexOf('/') + 1);
  1014. const extPos = filename.lastIndexOf('.');
  1015. let ext = '';
  1016. if (extPos > 0) {
  1017. ext = filename.substr(extPos);
  1018. }
  1019. filename = filename.substring(0, extPos > 8 ? 8 : extPos);
  1020. // 上传文件
  1021. const result: any = await upload(
  1022. await zip.file(key).async('blob'),
  1023. true,
  1024. filename + ext
  1025. );
  1026. let arr = key.split('/');
  1027. arr.shift();
  1028. if(arr[0]===fileName){
  1029. arr.shift();
  1030. }
  1031. let _key ='/'+ arr.join('/');
  1032. // if (_png) {
  1033. // _key = key.substring(_png);
  1034. // } else if (_image) {
  1035. // _key = key.substring(_png);
  1036. // } else if (_img) {
  1037. // _key = key.substring(_img);
  1038. // } else if (_file) {
  1039. // _key = key.substring(_file);
  1040. // }
  1041. if (result) {
  1042. if (dataStr.replaceAll) {
  1043. //'le5le.meta2d'
  1044. dataStr = dataStr.replaceAll(_key, result.url);
  1045. } else {
  1046. while (dataStr.includes(_key)) {
  1047. dataStr = dataStr.replace(_key, result.url);
  1048. // 正则 gm 在特殊情况下报错,例如如下场景
  1049. /**
  1050. *    
  1051. const data = '{"image":"/image/materials/IoT-Chemical(化学)/Air stripper 2(汽提塔2).svg"}';
  1052. const key = '/image/materials/IoT-Chemical(化学)/Air stripper 2(汽提塔2).svg';
  1053. data.replace(key, '123');
  1054. data.replaceAll(key, '123')
  1055. data.replace(new RegExp(key, 'gm'), '123');
  1056. data.replace(new RegExp(key, 'g'), '123');
  1057. */
  1058. }
  1059. }
  1060. }
  1061. }
  1062. }
  1063. try {
  1064. let data: Meta2dBackData = JSON.parse(dataStr);
  1065. if (data) {
  1066. if (!data.name) {
  1067. data.name = file.name.replace('.zip', '');
  1068. }
  1069. if (!data.version || compareVersion(data.version, baseVer) === -1) {
  1070. // 如果版本号不存在或者版本号 version < 1.0.0
  1071. data = upgrade(data, baseVer);
  1072. }
  1073. dealwithFormatbeforeOpen(data);
  1074. const delAttrs = [
  1075. 'userId',
  1076. 'shared',
  1077. 'team',
  1078. 'owner',
  1079. 'username',
  1080. 'editor',
  1081. 'editorId',
  1082. 'editorName',
  1083. 'createdAt',
  1084. 'folder',
  1085. 'image',
  1086. 'id',
  1087. '_id',
  1088. 'view',
  1089. 'updatedAt',
  1090. 'star',
  1091. 'recommend',
  1092. ];
  1093. for (const k of delAttrs) {
  1094. delete (data as any)[k];
  1095. }
  1096. if(!data.background){
  1097. data.background = '#1e2430';
  1098. }
  1099. if(!data.color){
  1100. data.color = '#bdc7db';
  1101. }
  1102. if(!data.width){data.width= 1920};
  1103. if(!data.height){data.height= 1080};
  1104. meta2d.open(data);
  1105. }
  1106. } catch (e) {
  1107. return false;
  1108. }
  1109. };
  1110. const downloadJson = () => {
  1111. const data: Meta2dBackData = meta2d.data();
  1112. if (data._id) delete data._id;
  1113. if (data.id) delete data.id;
  1114. checkData(data);
  1115. import('file-saver').then(({ saveAs }) => {
  1116. saveAs(
  1117. new Blob(
  1118. [JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')],
  1119. {
  1120. type: 'text/plain;charset=utf-8',
  1121. }
  1122. ),
  1123. `${data.name || 'le5le.meta2d'}.json`
  1124. );
  1125. });
  1126. };
  1127. const downloadZip = async () => {
  1128. if (!(user && user.id)) {
  1129. MessagePlugin.warning(noLoginTip);
  1130. return;
  1131. }
  1132. // if (!user.isVip) {
  1133. // // gotoAccount();
  1134. // return;
  1135. // }
  1136. if(!meta2d.store.data.pens.length){
  1137. MessagePlugin.info('画布没有画笔!');
  1138. return;
  1139. }
  1140. if (!user.vip) {
  1141. MessagePlugin.info('需要开通会员~');
  1142. gotoAccount();
  1143. return;
  1144. }
  1145. //提前存储iframe嵌入2d数据
  1146. downloadType = Frame.zip;
  1147. downloadZip3dList = [];
  1148. data.zips = {};
  1149. const pen_pay = meta2d.store.data.pens.filter(
  1150. (pen) =>
  1151. pen.name === 'iframe' &&
  1152. (pen.iframe.indexOf(`/2d/`) !== -1 ||
  1153. pen.iframe.indexOf('/2d?') !== -1 ||
  1154. pen.iframe.indexOf(`/v/`) !== -1 ||
  1155. pen.iframe.indexOf('/v?') !== -1)
  1156. );
  1157. if (pen_pay && pen_pay.length) {
  1158. for(let i=0;i<pen_pay.length;i++){
  1159. // pen_pay.forEach(async(pen) => {
  1160. const pen = pen_pay[i];
  1161. let arr = pen.iframe.split('?');
  1162. let params = queryURLParams(arr[1]);
  1163. if(params.id){
  1164. if(arr[0].indexOf('2d') !== -1 ){
  1165. const ret: any = await axios.post('/api/data/2d/get', {
  1166. id:params.id
  1167. });
  1168. if(ret.data){
  1169. let payList = getPayList(ret.data);
  1170. // payList.pngs.forEach(item => pngs.add(item));
  1171. data.zips[params.id] = {
  1172. data:ret.data,
  1173. pngs:payList.pngs
  1174. }
  1175. }
  1176. }else if(arr[0].indexOf('v') !== -1){
  1177. const ret: any = await axios.post('/api/data/v/get', {
  1178. id:params.id
  1179. });
  1180. if(ret.data){
  1181. let payList = getPayList(ret.data);
  1182. // payList.pngs.forEach(item => pngs.add(item));
  1183. data.zips[params.id] = {
  1184. data:ret.data,
  1185. pngs:payList.pngs
  1186. }
  1187. }
  1188. }
  1189. }
  1190. // })
  1191. }
  1192. }
  1193. preDoDownloadZip();
  1194. return;
  1195. // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  1196. // const [{ default: JSZip }, { saveAs }] = await Promise.all([
  1197. // import('jszip'),
  1198. // import('file-saver'),
  1199. // ]);
  1200. // const zip: any = new JSZip();
  1201. // const data: Meta2dBackData = meta2d.data();
  1202. // let _fileName =
  1203. // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  1204. // 'le5le.meta2d';
  1205. // const _zip = zip.folder(`${_fileName}`);
  1206. // if (data._id) delete data._id;
  1207. // if (data.id) delete data.id;
  1208. // checkData(data);
  1209. // _zip.file(
  1210. // `${_fileName}.json`,
  1211. // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
  1212. // );
  1213. // await zipBkImg(_zip);
  1214. // await zipImages(_zip, meta2d.store.data.pens);
  1215. // const blob = await zip.generateAsync({ type: 'blob' });
  1216. // saveAs(blob, `${_fileName}.zip`);
  1217. };
  1218. const preDownloadZip =async () =>{
  1219. const meta2dData = meta2d.data();
  1220. let payList = getPayList(meta2dData);
  1221. let purchased =await getComponentPurchased({
  1222. pngs: payList.pngs,
  1223. jsPens: [],
  1224. iotPens: [],
  1225. svgPens: [],
  1226. });
  1227. downloadZipDialog.checked = true;
  1228. if(payList.jsPens.length||payList.iotPens.length||payList.svgPens.length){
  1229. downloadZipDialog.hasJs = true;
  1230. }else{
  1231. downloadZipDialog.hasJs = false;
  1232. }
  1233. let names = purchased.map((item) => item.name);
  1234. data.goods = await getGoods();
  1235. let list = payList.pngs.filter((item) => !names.includes(item));
  1236. if(!list.length){
  1237. doDownloadZip();
  1238. }else{
  1239. let unitPrice = data.goods.find((item)=>item.type==='图片图元').unitPrice;
  1240. downloadZipDialog.price = unitPrice*list.length;
  1241. downloadZipDialog.show = true;
  1242. downloadZipDialog.list = list;
  1243. }
  1244. }
  1245. const prePayDownloadZip = async ()=>{
  1246. if(downloadZipDialog.checked){
  1247. const res: any = await axios.post('/api/order/deployment/submit', {
  1248. goods:{},
  1249. '2ds':downloadZipDialog.list.map((item)=>{return { type: '图片图元', name: item}}),
  1250. });
  1251. wechatPayDialog.show = true;
  1252. wechatPayDialog.isZip = true;
  1253. data.order = res;
  1254. }else {
  1255. doDownloadZip();
  1256. }
  1257. }
  1258. const preDoDownloadZip = async ()=>{
  1259. const meta2dData:any = meta2d.data();
  1260. const pen_3d = meta2dData.pens.filter(
  1261. (pen) =>
  1262. pen.name === 'iframe' &&
  1263. (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
  1264. pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1||
  1265. pen.iframe.indexOf(`/view/3d`) !== -1 //安装包
  1266. ));
  1267. if (pen_3d && pen_3d.length) {
  1268. pen_3d.forEach((pen) => {
  1269. //发送消息
  1270. let params = queryURLParams(pen.iframe.split('?')[1]);
  1271. (
  1272. meta2d.store.pens[pen.id].calculative.singleton.div
  1273. .children[0] as HTMLIFrameElement
  1274. ).contentWindow.postMessage(
  1275. JSON.stringify({
  1276. name: 'deployAsZip',
  1277. // id: params.id,
  1278. type: 1,
  1279. path: `3d-${params.id}`,
  1280. }),
  1281. '*'
  1282. );
  1283. // pen.iframe = `/view?data=3d-${params.id}`;
  1284. });
  1285. }else{
  1286. doDownloadZip();
  1287. }
  1288. }
  1289. const doDownloadZip = async ()=>{
  1290. // downloadZipDialog.show = false;
  1291. MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  1292. const [{ default: JSZip }, { saveAs }] = await Promise.all([
  1293. import('jszip'),
  1294. import('file-saver'),
  1295. ]);
  1296. const zip: any = new JSZip();
  1297. const _data: Meta2dBackData = meta2d.data();
  1298. let _fileName =
  1299. (_data.name && _data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  1300. 'le5le.meta2d';
  1301. const _zip = zip.folder(`${_fileName}`);
  1302. let list = getDownloadZipList(_data,data.zips);
  1303. await Promise.all(
  1304. [...list,...downloadZip3dList].map(async (item: any) => {
  1305. if (item.url) {
  1306. //接口请求
  1307. try{
  1308. let url = item.url.startsWith('/')?(cdn+item.url):item.url;
  1309. if(url.includes('?')){
  1310. url = url + `&r=${Date.now()}`;
  1311. }else{
  1312. url = url + `?r=${Date.now()}`;
  1313. }
  1314. const res: Blob = await axios.get(url, {
  1315. responseType: 'blob',
  1316. });
  1317. _zip.file(item.path.split('?')[0], res, { createFolders: true });
  1318. }catch(e){
  1319. console.log(e);
  1320. }
  1321. } else if (item.data) {
  1322. //直接写数据
  1323. _zip.file(item.path, item.data, { createFolders: true });
  1324. }
  1325. })
  1326. );
  1327. const blob = await zip.generateAsync({ type: 'blob' });
  1328. saveAs(blob, `${_fileName}.zip`);
  1329. // downloadZipDialog.show = false;
  1330. // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  1331. // const [{ default: JSZip }, { saveAs }] = await Promise.all([
  1332. // import('jszip'),
  1333. // import('file-saver'),
  1334. // ]);
  1335. // const zip: any = new JSZip();
  1336. // const data: Meta2dBackData = meta2d.data();
  1337. // let _fileName =
  1338. // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  1339. // 'le5le.meta2d';
  1340. // const _zip = zip.folder(`${_fileName}`);
  1341. // if (data._id) delete data._id;
  1342. // if (data.id) delete data.id;
  1343. // checkData(data);
  1344. // _zip.file(
  1345. // `${_fileName}.json`,
  1346. // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
  1347. // );
  1348. // await zipBkImg(_zip);
  1349. // await zipImages(_zip, meta2d.store.data.pens);
  1350. // const blob = await zip.generateAsync({ type: 'blob' });
  1351. // saveAs(blob, `${_fileName}.zip`);
  1352. }
  1353. // const zip3D = (name: string) => {
  1354. // const pen_3d = meta2d.store.data.pens.filter(
  1355. // (pen) =>
  1356. // pen.name === 'iframe' &&
  1357. // (pen.tags.includes('meta3d') || pen.iframe.indexOf('3d') !== -1)
  1358. // );
  1359. // if (pen_3d && pen_3d.length) {
  1360. // //存在3d场景
  1361. // pen_3d.forEach((pen) => {
  1362. // //发送消息
  1363. // let params = queryURLParams(pen.iframe.split('?')[1]);
  1364. // (
  1365. // pen.calculative.singleton.div.children[0] as HTMLIFrameElement
  1366. // ).contentWindow.postMessage(
  1367. // JSON.stringify({
  1368. // type: 1,
  1369. // name,
  1370. // id: params.id,
  1371. // }),
  1372. // '*'
  1373. // );
  1374. // });
  1375. // }
  1376. // };
  1377. // const zip2D = (name: string) => {
  1378. // const pen_2d = meta2d.store.data.pens.filter(
  1379. // (pen) =>
  1380. // pen.name === 'iframe' &&
  1381. // (pen.iframe.indexOf('2d.le5le.com') !== -1 ||
  1382. // pen.iframe.indexOf('/2d/') !== -1 ||
  1383. // pen.iframe.indexOf('v.le5le.com') !== -1 ||
  1384. // pen.iframe.indexOf('/v/') !== -1)
  1385. // );
  1386. // if (pen_2d && pen_2d.length) {
  1387. // //存在3d场景
  1388. // pen_2d.forEach((pen) => {
  1389. // //发送消息
  1390. // // let params = queryURLParams(pen.iframe.split('?')[1]);
  1391. // (
  1392. // pen.calculative.singleton.div.children[0] as HTMLIFrameElement
  1393. // ).contentWindow.postMessage(
  1394. // JSON.stringify({
  1395. // name,
  1396. // type: 1,
  1397. // }),
  1398. // '*'
  1399. // );
  1400. // });
  1401. // }
  1402. // }
  1403. // function queryURLParams(value?: string) {
  1404. // let url = value || window.location.href.split('?')[1];
  1405. // const urlSearchParams = new URLSearchParams(url);
  1406. // const params = Object.fromEntries(urlSearchParams.entries());
  1407. // return params;
  1408. // }
  1409. const downloadHtml = async () => {
  1410. if (!(user && user.id)) {
  1411. MessagePlugin.warning(noLoginTip);
  1412. return;
  1413. }
  1414. downloadType = Frame.html;
  1415. // await preGetPayList();
  1416. preDownload();
  1417. };
  1418. const preGetPayList = async () => {
  1419. //图形库需要购买
  1420. const meta2dData = meta2d.data();
  1421. if(!meta2dData.pens.length){
  1422. MessagePlugin.info('画布没有画笔!');
  1423. return;
  1424. }
  1425. let list = getPayList(meta2dData);
  1426. prePayList.pngs = new Set(list.pngs);
  1427. prePayList.jsPens = new Set(list.jsPens);
  1428. prePayList.iotPens = new Set(list.iotPens);
  1429. prePayList.svgPens = new Set(list.svgPens);
  1430. downloadList = new Set();
  1431. //向iframe发送消息
  1432. payListNum = 0;
  1433. comparePayListNum = 0;
  1434. const pen_pay = meta2dData.pens.filter(
  1435. (pen) =>
  1436. pen.name === 'iframe' &&
  1437. (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
  1438. pen.iframe.indexOf('/2d') !== -1 || pen.iframe.indexOf('data=2d') !== -1 ||
  1439. pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
  1440. pen.iframe.indexOf(`view${rootDomain}/v`) !== -1 ||pen.iframe.indexOf('data=v') !== -1 ||
  1441. pen.iframe.indexOf('/preview') !== -1)
  1442. );
  1443. if (pen_pay && pen_pay.length) {
  1444. pen_pay.forEach((pen) => {
  1445. //发送消息
  1446. (
  1447. meta2d.store.pens[pen.id].calculative.singleton.div
  1448. .children[0] as HTMLIFrameElement
  1449. ).contentWindow.postMessage(
  1450. JSON.stringify({
  1451. name: 'prePayList',
  1452. type: 1,
  1453. }),
  1454. '*'
  1455. );
  1456. payListNum += 1;
  1457. });
  1458. }
  1459. if (payListNum === 0) {
  1460. await showPayListDialog();
  1461. }
  1462. };
  1463. const showPayListDialog = async () => {
  1464. //下载离线部署包
  1465. const deploys =await getDeployGoods();
  1466. const pen_3d = meta2d.store.data.pens.filter(
  1467. (pen) =>
  1468. pen.name === 'iframe' &&
  1469. (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
  1470. pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1)
  1471. );
  1472. const pen_2d = meta2d.store.data.pens.filter(
  1473. (pen) =>
  1474. pen.name === 'iframe' &&
  1475. (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
  1476. pen.iframe.indexOf(`view${rootDomain}/2d`) !== -1)
  1477. );
  1478. const pen_v = meta2d.store.data.pens.filter(
  1479. (pen) =>
  1480. pen.name === 'iframe' &&
  1481. (pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
  1482. pen.iframe.indexOf(`view${rootDomain}/v`) !== -1||pen.iframe.indexOf('data=v') !== -1)
  1483. );
  1484. let price = 0;
  1485. data.payDiagram.checked = true;
  1486. data.payDiagram.expend = false;
  1487. data.payGoods ={}
  1488. deploys.forEach((item) => {
  1489. if(item.name==="3D离线部署下载"){
  1490. price+=item.price*pen_3d.length;
  1491. if(pen_3d.length){
  1492. data.payGoods[item.id]=pen_3d.length;
  1493. }
  1494. }else if(item.name==="2D离线部署下载"){
  1495. price+=item.price*pen_2d.length;
  1496. if(pen_2d.length){
  1497. data.payGoods[item.id]=pen_2d.length;
  1498. }
  1499. }else if(item.name==="大屏离线部署下载"){
  1500. price+=item.price*(pen_v.length+1);
  1501. data.payGoods[item.id]=pen_v.length+1;
  1502. }
  1503. });
  1504. data.deploy.price = price;
  1505. //图形库
  1506. data.goods = await getGoods();
  1507. data.purchasedList = await getComponentPurchased(prePayList);
  1508. data.payDiagram.list =[];
  1509. data.payDiagram.payAll = false;
  1510. data.goods.forEach((goods)=>{
  1511. let purchased = data.purchasedList?.filter(
  1512. (_item) => _item.type === goods.type
  1513. );
  1514. let names = purchased.map((item) => item.name);
  1515. let list = [];
  1516. if(goods.type==='图片图元'){
  1517. list = [...prePayList.pngs];
  1518. }else if(goods.type==='JS线性图元'){
  1519. list = [...prePayList.jsPens];
  1520. }else if(goods.type==='SVG线性图元'){
  1521. list = [...prePayList.svgPens];
  1522. }else if(goods.type==='控件'){
  1523. list = [...prePayList.iotPens];
  1524. }
  1525. let num =0;
  1526. if (goods.type==='SVG线性图元'&&[...prePayList.svgPens].includes('*')) {
  1527. //需要购买全部
  1528. num = goods.count-names.length;
  1529. data.payDiagram.payAll = true;
  1530. }else{
  1531. list.forEach((item)=>{
  1532. if(!names.includes(item)){
  1533. if(goods.type==='控件'){
  1534. data.payDiagram.list.push({
  1535. name:item
  1536. });
  1537. }else if(goods.type==='JS线性图元'){
  1538. data.payDiagram.list.push({
  1539. svg:globalThis.jsPensMap?globalThis.jsPensMap[item]:item
  1540. });
  1541. }else{
  1542. data.payDiagram.list.push({
  1543. img:item
  1544. });
  1545. }
  1546. num+=1;
  1547. }
  1548. })};
  1549. goods.num = num;
  1550. })
  1551. price = 0;
  1552. data.goods.forEach((item, index) => {
  1553. price += item.num * item.unitPrice;
  1554. });
  1555. data.payDiagram.price = price;
  1556. // data.goods.forEach((item, index) => {
  1557. // item.checked = true;
  1558. // let purchased = data.purchasedList?.filter(
  1559. // (_item) => _item.type === item.type
  1560. // );
  1561. // if (index === 0) {
  1562. // item.total = [...prePayList.pngs].length;
  1563. // item.unPurchased = item.total - purchased.length;
  1564. // } else if (index === 1) {
  1565. // item.total = [...prePayList.iotPens].length;
  1566. // item.unPurchased = item.total - purchased.length;
  1567. // } else if (index === 3) {
  1568. // item.total = [...prePayList.jsPens].length;
  1569. // item.unPurchased = item.total - purchased.length;
  1570. // } else if (index === 2) {
  1571. // if (purchased.length === 1 && !purchased[0].name) {
  1572. // //说明已经购买全部 //TODO
  1573. // item.total = item.count;
  1574. // item.unPurchased = 0;
  1575. // } else {
  1576. // //需要购买全部
  1577. // if ([...prePayList.svgPens].includes('*')) {
  1578. // item.total = item.count;
  1579. // item.unPurchased = item.total;
  1580. // } else {
  1581. // item.total = [...prePayList.svgPens].length;
  1582. // item.unPurchased = item.total - purchased.length;
  1583. // }
  1584. // }
  1585. // }
  1586. // });
  1587. payListDialog.show = true;
  1588. switch (downloadType) {
  1589. case Frame.html:
  1590. payListDialog.title = '下载离线部署包';
  1591. payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BD%E7%A6%BB%E7%BA%BF%E9%83%A8%E7%BD%B2%E5%8C%85`;
  1592. payListDialog.downloadUrl =img_cdn+ '/deployment/大厦电力管理系统(html).zip';
  1593. break;
  1594. case Frame.vue2:
  1595. payListDialog.title = '下载vue2组件包';
  1596. payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BDVue2%E7%BB%84%E4%BB%B6%E5%8C%85`;
  1597. payListDialog.downloadUrl = img_cdn+ '/deployment/大厦电力管理系统(vue2).zip';
  1598. break;
  1599. case Frame.vue3:
  1600. payListDialog.title = '下载vue3组件包';
  1601. payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BDVue3%E7%BB%84%E4%BB%B6%E5%8C%85`;
  1602. payListDialog.downloadUrl = img_cdn+ '/deployment/大厦电力管理系统(vue3).zip';
  1603. break;
  1604. case Frame.react:
  1605. payListDialog.title = '下载react组件包';
  1606. payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BDReact%E7%BB%84%E4%BB%B6%E5%8C%85`;
  1607. payListDialog.downloadUrl = img_cdn+ '/deployment/大厦电力管理系统(react).zip';
  1608. break;
  1609. }
  1610. // let price = 0;
  1611. // if (price === 0) {
  1612. // skipPay(); //如果计算价格为0,直接下载
  1613. // } else {
  1614. // payListDialog.show = true;
  1615. // }
  1616. };
  1617. const preDownload =() => {
  1618. iframeNum = 0;
  1619. compareNum = 0;
  1620. const meta2dData:any = meta2d.data();
  1621. meta2dData.userId = user.id;
  1622. const pen_3d = meta2dData.pens.filter(
  1623. (pen) =>
  1624. pen.name === 'iframe' &&
  1625. (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
  1626. pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1)
  1627. );
  1628. if (pen_3d && pen_3d.length) {
  1629. //存在3d场景
  1630. if (pen_3d.length === 1) {
  1631. let params = queryURLParams(pen_3d[0].iframe.split('?')[1]);
  1632. meta2d.store.pens[
  1633. pen_3d[0].id
  1634. ].calculative.singleton.div.children[0].contentWindow.postMessage(
  1635. JSON.stringify({
  1636. name: 'deploy',
  1637. // id: params.id,
  1638. type: 1, //用于区分是系统消息
  1639. path: `3d`,
  1640. }),
  1641. '*'
  1642. );
  1643. pen_3d[0].iframe ='view/index.html?data=3d';// '/view?data=3d';
  1644. } else {
  1645. pen_3d.forEach((pen) => {
  1646. //发送消息
  1647. let params = queryURLParams(pen.iframe.split('?')[1]);
  1648. (
  1649. meta2d.store.pens[pen.id].calculative.singleton.div
  1650. .children[0] as HTMLIFrameElement
  1651. ).contentWindow.postMessage(
  1652. JSON.stringify({
  1653. name: 'deploy',
  1654. // id: params.id,
  1655. type: 1,
  1656. path: `3d-${params.id}`,
  1657. }),
  1658. '*'
  1659. );
  1660. pen.iframe = `view/index.html?data=3d-${params.id}`;//`/view?data=3d-${params.id}`;
  1661. });
  1662. }
  1663. iframeNum += pen_3d.length;
  1664. }
  1665. const pen_2d = meta2dData.pens.filter(
  1666. (pen) =>
  1667. pen.name === 'iframe' &&
  1668. (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
  1669. pen.iframe.indexOf(`view${rootDomain}/2d`) !== -1)
  1670. );
  1671. if (pen_2d && pen_2d.length) {
  1672. //存在3d场景
  1673. if (pen_2d.length === 1) {
  1674. let params = queryURLParams(pen_2d[0].iframe.split('?')[1]);
  1675. meta2d.store.pens[
  1676. pen_2d[0].id
  1677. ].calculative.singleton.div.children[0].contentWindow.postMessage(
  1678. JSON.stringify({
  1679. name: 'downloadHtml',
  1680. id: params.id,
  1681. type: 1,
  1682. path: `2d`,
  1683. }),
  1684. '*'
  1685. );
  1686. pen_2d[0].iframe = '/view?data=2d';
  1687. } else {
  1688. pen_2d.forEach((pen) => {
  1689. //发送消息
  1690. let params = queryURLParams(pen.iframe.split('?')[1]);
  1691. (
  1692. meta2d.store.pens[pen.id].calculative.singleton.div
  1693. .children[0] as HTMLIFrameElement
  1694. ).contentWindow.postMessage(
  1695. JSON.stringify({
  1696. name: 'downloadHtml',
  1697. // id: params.id,
  1698. type: 1,
  1699. path: `2d-${params.id}`,
  1700. }),
  1701. '*'
  1702. );
  1703. pen.iframe = `/view?data=2d-${params.id}`;
  1704. });
  1705. }
  1706. iframeNum += pen_2d.length;
  1707. }
  1708. const pen_v = meta2dData.pens.filter(
  1709. (pen) =>
  1710. pen.name === 'iframe' &&
  1711. (pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
  1712. pen.iframe.indexOf(`view${rootDomain}/v`) !== -1||pen.iframe.indexOf('data=v') !== -1)
  1713. );
  1714. if (pen_v && pen_v.length) {
  1715. //存在3d场景
  1716. pen_v.forEach((pen) => {
  1717. //发送消息
  1718. let params = queryURLParams(pen.iframe.split('?')[1]);
  1719. (
  1720. meta2d.store.pens[pen.id].calculative.singleton.div
  1721. .children[0] as HTMLIFrameElement
  1722. ).contentWindow.postMessage(
  1723. JSON.stringify({
  1724. name: 'downloadHtml',
  1725. // id: params.id,
  1726. type: 1,
  1727. path: `v-${params.id}`,
  1728. }),
  1729. '*'
  1730. );
  1731. pen.iframe = `/view?data=v-${params.id}`;
  1732. });
  1733. iframeNum += pen_v.length;
  1734. }
  1735. downloadList = getDownloadList(meta2dData,undefined);
  1736. if (iframeNum === 0) {
  1737. //如果没有嵌入场景
  1738. saveDownload();
  1739. } else {
  1740. setTimeout(() => {
  1741. if (compareNum < iframeNum) {
  1742. //message阻塞/报错的情况
  1743. saveDownload();
  1744. }
  1745. }, 10000);
  1746. }
  1747. };
  1748. const preFrameDownload = async () => {
  1749. iframeNum = 0;
  1750. compareNum = 0;
  1751. const meta2dData:any = meta2d.data();
  1752. meta2dData.userId = user.id;
  1753. const pen_3d = meta2dData.pens.filter(
  1754. (pen) =>
  1755. pen.name === 'iframe' &&
  1756. (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
  1757. pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1)
  1758. );
  1759. let name_3d = (downloadType===Frame.vue3?'toVue3':downloadType===Frame.vue2?'toVue2':'toReact');
  1760. let flag_3d = false; //标记是否存在3d场景
  1761. if (pen_3d && pen_3d.length) {
  1762. //存在3d场景
  1763. if (pen_3d.length === 1) {
  1764. let params = queryURLParams(pen_3d[0].iframe.split('?')[1]);
  1765. meta2d.store.pens[
  1766. pen_3d[0].id
  1767. ].calculative.singleton.div.children[0].contentWindow.postMessage(
  1768. JSON.stringify({
  1769. name: name_3d,
  1770. type: 1, //用于区分是系统消息
  1771. path: `3d`,
  1772. }),
  1773. '*'
  1774. );
  1775. pen_3d[0].iframe = 'view/index.html?data=3d'; //'/3d?id=3d';
  1776. } else {
  1777. pen_3d.forEach((pen) => {
  1778. //发送消息
  1779. let params = queryURLParams(pen.iframe.split('?')[1]);
  1780. (
  1781. meta2d.store.pens[pen.id].calculative.singleton.div
  1782. .children[0] as HTMLIFrameElement
  1783. ).contentWindow.postMessage(
  1784. JSON.stringify({
  1785. name:name_3d,
  1786. // id: params.id,
  1787. type: 1,
  1788. path: `3d-${params.id}`,
  1789. }),
  1790. '*'
  1791. );
  1792. pen.iframe = `view/index.html?data=-${params.id}`; //`/3d?id=3d-${params.id}`;
  1793. });
  1794. }
  1795. iframeNum += pen_3d.length;
  1796. flag_3d = true;
  1797. }
  1798. const pen_2d = meta2dData.pens.filter(
  1799. (pen) =>
  1800. pen.name === 'iframe' &&
  1801. (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
  1802. pen.iframe.indexOf(`view${rootDomain}/2d`) !== -1)
  1803. );
  1804. let name_2d = (downloadType===Frame.vue3?'downloadVue3':downloadType===Frame.vue2?'downloadVue2':'downloadReact');
  1805. if (pen_2d && pen_2d.length) {
  1806. //存在3d场景
  1807. if (pen_2d.length === 1) {
  1808. let params = queryURLParams(pen_2d[0].iframe.split('?')[1]);
  1809. meta2d.store.pens[
  1810. pen_2d[0].id
  1811. ].calculative.singleton.div.children[0].contentWindow.postMessage(
  1812. JSON.stringify({
  1813. name: name_2d,
  1814. id: params.id,
  1815. type: 1,
  1816. path: `2d`,
  1817. }),
  1818. '*'
  1819. );
  1820. pen_2d[0].iframe = '/2d?id=2d';
  1821. } else {
  1822. pen_2d.forEach((pen) => {
  1823. //发送消息
  1824. let params = queryURLParams(pen.iframe.split('?')[1]);
  1825. (
  1826. meta2d.store.pens[pen.id].calculative.singleton.div
  1827. .children[0] as HTMLIFrameElement
  1828. ).contentWindow.postMessage(
  1829. JSON.stringify({
  1830. name:name_2d,
  1831. // id: params.id,
  1832. type: 1,
  1833. path: `2d-${params.id}`,
  1834. }),
  1835. '*'
  1836. );
  1837. pen.iframe = `/2d?id=2d-${params.id}`;
  1838. });
  1839. }
  1840. iframeNum += pen_2d.length;
  1841. }
  1842. const pen_v = meta2dData.pens.filter(
  1843. (pen) =>
  1844. pen.name === 'iframe' &&
  1845. (pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
  1846. pen.iframe.indexOf(`view${rootDomain}/v`) !== -1||pen.iframe.indexOf('data=v') !== -1||pen.iframe.indexOf('/preview') !== -1)
  1847. );
  1848. if (pen_v && pen_v.length) {
  1849. //存在大屏场景
  1850. pen_v.forEach((pen) => {
  1851. //发送消息
  1852. let params = queryURLParams(pen.iframe.split('?')[1]);
  1853. (
  1854. meta2d.store.pens[pen.id].calculative.singleton.div
  1855. .children[0] as HTMLIFrameElement
  1856. ).contentWindow.postMessage(
  1857. JSON.stringify({
  1858. name: name_2d,
  1859. // id: params.id,
  1860. type: 1,
  1861. path: `v-${params.id}`,
  1862. }),
  1863. '*'
  1864. );
  1865. pen.iframe = `/2d?id=v-${params.id}`;
  1866. });
  1867. iframeNum += pen_v.length;
  1868. }
  1869. downloadList = getFrameDownloadList(meta2dData,undefined,downloadType,flag_3d);
  1870. if (iframeNum === 0) {
  1871. //如果没有嵌入场景
  1872. saveDownload();
  1873. } else {
  1874. setTimeout(() => {
  1875. if (compareNum < iframeNum) {
  1876. //message阻塞/报错的情况
  1877. saveDownload();
  1878. }
  1879. }, 10000);
  1880. }
  1881. }
  1882. const saveDownload = async () => {
  1883. const list = [...downloadList];
  1884. //控件
  1885. let jsPath= '';
  1886. // let jsPensPath = '';
  1887. switch (downloadType) {
  1888. case Frame.html:
  1889. jsPath = '/view/js/2d-components.js';
  1890. // jsPensPath = `/view/js/1.js`;
  1891. break;
  1892. case Frame.vue2:
  1893. jsPath = '/meta2d-vue2/public/js/2d-components.js';
  1894. // jsPensPath = `/meta2d-vue2/public/js/1.js`;
  1895. break;
  1896. case Frame.vue3:
  1897. jsPath = '/meta2d-vue3/public/js/2d-components.js';
  1898. // jsPensPath = `/meta2d-vue3/public/js/1.js`;
  1899. break;
  1900. case Frame.react:
  1901. jsPath = '/meta2d-react/public/js/2d-components.js';
  1902. // jsPensPath = `/meta2d-react/public/js/1.js`;
  1903. break;
  1904. }
  1905. // list.push({
  1906. // url: '/view/js/2d-components.js', //需要购买
  1907. // path: jsPath,
  1908. // });
  1909. // const js = await get2dComponentJs([...prePayList.iotPens]);
  1910. // list.push({
  1911. // data: js,
  1912. // path:jsPath,
  1913. // });
  1914. ///png图形库
  1915. // const pngs = await getTemPngs([...prePayList.pngs]);
  1916. // list.forEach((item) => {
  1917. // if(item.url){
  1918. // let url =item.url.replace(img_cdn, '').replace(img_upCdn, '')
  1919. // if (pngs[url]) {
  1920. // item.url = pngs[url];
  1921. // }
  1922. // }
  1923. // });
  1924. //js线性图元
  1925. // const res: any = await axios.post('/api/paid/2d/component?pageSize=1000', {
  1926. // type: 'JS线性图元',
  1927. // });
  1928. // let purchased = res.list.map((item) => item.name);
  1929. // let arr = [];
  1930. // [...prePayList.jsPens].forEach((item) => {
  1931. // if(purchased.includes(item)){
  1932. // arr.push(item);
  1933. // }
  1934. // });
  1935. // const res_list: Blob = await axios.post(
  1936. // '/api/2d/tools',
  1937. // {
  1938. // list: arr.map((item) => {
  1939. // return {
  1940. // type: 'JS线性图元',
  1941. // name: item,
  1942. // };
  1943. // }),
  1944. // },
  1945. // {
  1946. // responseType: 'blob',
  1947. // }
  1948. // );
  1949. // list.push({
  1950. // data: res_list,
  1951. // path: jsPensPath,
  1952. // });
  1953. //SVG线性图元
  1954. // if ([...prePayList.svgPens].length) {
  1955. // // let purchased = data.purchasedList?.filter(
  1956. // // (_item) => _item.type === 'SVG线性图元'
  1957. // // );
  1958. // const res: any = await axios.post('/api/paid/2d/component?pageSize=1000', {
  1959. // type: 'SVG线性图元',
  1960. // });
  1961. // let purchased = res.list;
  1962. // let count = data.goods.find((item) => item.type === 'SVG线性图元').count;
  1963. // if(purchased.length === count){
  1964. // // if (purchased.length === 1 && !purchased[0].name) {
  1965. // //已经购买全部
  1966. // list.forEach((item) => {
  1967. // if (item.data &&
  1968. // (item.path.indexOf('/projects/2d') !== -1 || item.path.indexOf('/projects/v') !== -1 || item.path.indexOf('/public/json')!==-1) &&
  1969. // item.path.indexOf('/projects/v/png/') === -1 && item.path.indexOf('/projects/2d/png/') === -1) {
  1970. // //清空所有svgpath
  1971. // let meta2dData = JSON.parse(item.data);
  1972. // for (let key of Object.keys(meta2dData.paths)) {
  1973. // let path = meta2dData.paths[key];
  1974. // if (
  1975. // path.indexOf('-1.18Zm4-1') !== -1 ||
  1976. // path.indexOf('-1.19Zm4-1') !== -1 ||
  1977. // path.indexOf('2.85ZM') !== -1 ||
  1978. // path.indexOf('-1-2.39.3') !== -1
  1979. // ) {
  1980. // meta2dData.paths[key] = '';
  1981. // }
  1982. // }
  1983. // item.data = JSON.stringify(meta2dData);
  1984. // }
  1985. // });
  1986. // } else {
  1987. // let svgnames = purchased.map(i=>i.name);
  1988. // list.forEach((item) => {
  1989. // if (
  1990. // item.data &&
  1991. // (item.path.indexOf('/projects/2d') !== -1 || item.path.indexOf('/projects/v') !== -1 || item.path.indexOf('/public/json')!==-1) &&
  1992. // item.path.indexOf('/projects/v/png/') === -1 && item.path.indexOf('/projects/2d/png/') === -1
  1993. // ) {
  1994. // //2d 图纸数据
  1995. // let meta2dData = JSON.parse(item.data);
  1996. // meta2dData.pens.forEach((pen) => {
  1997. // if (pen.name === 'svgPath' && pen.svgUrl) {
  1998. // if (svgnames.includes(pen.svgUrl.replace(img_cdn, ''))) {
  1999. // pen.pathId = null;
  2000. // }
  2001. // }
  2002. // });
  2003. // item.data = JSON.stringify(meta2dData);
  2004. // }
  2005. // });
  2006. // }
  2007. // }
  2008. //开始下载list
  2009. const [{ default: JSZip }, { saveAs }] = await Promise.all([
  2010. import('jszip'),
  2011. import('file-saver'),
  2012. ]);
  2013. const zip = new JSZip();
  2014. await Promise.all(
  2015. list.map(async (item: any) => {
  2016. if (item.url) {
  2017. //接口请求
  2018. try{
  2019. const res: Blob = await axios.get(item.url.startsWith('/')?(cdn+item.url):item.url, {
  2020. responseType: 'blob',
  2021. });
  2022. zip.file(item.path.split('?')[0], res, { createFolders: true });
  2023. }catch(e){
  2024. console.log(e);
  2025. }
  2026. } else if (item.data) {
  2027. //直接写数据
  2028. zip.file(item.path, item.data, { createFolders: true });
  2029. }
  2030. })
  2031. );
  2032. let _fileName =
  2033. (meta2d.store.data.name &&
  2034. meta2d.store.data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  2035. 'le5le.meta2d';
  2036. const blob = await zip.generateAsync({ type: 'blob' });
  2037. saveAs(blob, `${_fileName}.zip`);
  2038. MessagePlugin.closeAll();
  2039. MessagePlugin.success('下载成功,请在浏览器下载列表中查看');
  2040. };
  2041. // const _downloadHtml = async () => {
  2042. // if (!(user && user.id)) {
  2043. // MessagePlugin.warning(noLoginTip);
  2044. // return;
  2045. // }
  2046. // // if (!user.isVip) {
  2047. // // gotoAccount();
  2048. // // return;
  2049. // // }
  2050. // if (user.vipDesc !== '超级会员' && user.vipDesc !== '旗舰会员') {
  2051. // MessagePlugin.info('需要开通超级会员~');
  2052. // gotoAccount();
  2053. // return;
  2054. // }
  2055. // frameFlag = -1;
  2056. // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  2057. // const data: Meta2dBackData = meta2d.data();
  2058. // if (data._id) delete data._id;
  2059. // if (data.id) delete data.id;
  2060. // if (data.image) delete data.image;
  2061. // checkData(data);
  2062. // const [{ default: JSZip }, { saveAs }] = await Promise.all([
  2063. // import('jszip'),
  2064. // import('file-saver'),
  2065. // ]);
  2066. // const zip = new JSZip();
  2067. // let _fileName =
  2068. // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  2069. // 'le5le.meta2d';
  2070. // //处理cdn图片地址
  2071. // const _zip: any = zip.folder(`${_fileName}`);
  2072. // _zip.file(
  2073. // 'data.json',
  2074. // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
  2075. // );
  2076. // await Promise.all([
  2077. // zipBkImg(_zip),
  2078. // zipImages(_zip, meta2d.store.data.pens),
  2079. // zipFiles(_zip),
  2080. // ]);
  2081. // const blob = await zip.generateAsync({ type: 'blob' });
  2082. // saveAs(blob, `${_fileName}.zip`);
  2083. // };
  2084. // async function zipBkImg(zip: JSZip) {
  2085. // let img = meta2d.store.data.bkImage;
  2086. // if (img) {
  2087. // if (img.startsWith('/') || img.startsWith(cdn) || img.startsWith(upCdn)) {
  2088. // const pngs = await getTemPngs([img.replace(cdn, '').replace(upCdn, '')]);
  2089. // await zipImage(zip, img, pngs[img.replace(cdn, '').replace(upCdn, '')]);
  2090. // }
  2091. // }
  2092. // }
  2093. // enum Frame {
  2094. // vue2,
  2095. // vue3,
  2096. // react,
  2097. // html
  2098. // }
  2099. const downloadVue3 = async () => {
  2100. downloadAsFrame(Frame.vue3);
  2101. };
  2102. const downloadVue2 = async () => {
  2103. downloadAsFrame(Frame.vue2);
  2104. };
  2105. const downloadReact = async () => {
  2106. downloadAsFrame(Frame.react);
  2107. };
  2108. async function downloadAsFrame(type: Frame) {
  2109. if (!(user && user.id)) {
  2110. MessagePlugin.warning(noLoginTip);
  2111. return;
  2112. }
  2113. // if (user.vipDesc !== '旗舰会员') {
  2114. // MessagePlugin.info('需要开通旗舰会员~');
  2115. // gotoAccount();
  2116. // return;
  2117. // }
  2118. downloadType = type;
  2119. // await preGetPayList();
  2120. preFrameDownload();
  2121. }
  2122. // const preFrameDownload = async (type: Frame) => {
  2123. // frameFlag = type;
  2124. // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  2125. // zip3D(
  2126. // type === Frame.vue3 ? 'toVue3' : type === Frame.vue2 ? 'toVue2' : 'toReact'
  2127. // );
  2128. // zip2D(
  2129. // type === Frame.vue3 ? 'downloadVue3' : type === Frame.vue2 ? 'downloadVue2' : 'downloadReact'
  2130. // );
  2131. // const data: any = meta2d.data();
  2132. // if (data._id) delete data._id;
  2133. // if (data.id) delete data.id;
  2134. // if (data.image) delete data.image;
  2135. // data.userId = user.id;
  2136. // checkData(data);
  2137. // const [{ default: JSZip }, { saveAs }] = await Promise.all([
  2138. // import('jszip'),
  2139. // import('file-saver'),
  2140. // ]);
  2141. // const zip = new JSZip();
  2142. // let _fileName =
  2143. // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
  2144. // 'le5le.meta2d';
  2145. // //处理付费svg
  2146. // if (Object.keys(data.paths).length >= 3) {
  2147. // //简单判断有无svg图元
  2148. // const res: any = await axios.post('/api/paid/2d/component', {
  2149. // type: 'SVG线性图元',
  2150. // });
  2151. // if (res.list.length === 1 && !res.list[0].name) {
  2152. // //已经购买全部
  2153. // for (let key of Object.keys(data.paths)) {
  2154. // let path = data.paths[key];
  2155. // if (
  2156. // path.indexOf('-1.18Zm4-1') !== -1 ||
  2157. // path.indexOf('-1.19Zm4-1') !== -1 ||
  2158. // path.indexOf('2.85ZM') !== -1 ||
  2159. // path.indexOf('-1-2.39.3') !== -1
  2160. // ) {
  2161. // data.paths[key] = '';
  2162. // }
  2163. // }
  2164. // } else {
  2165. // //购买部分
  2166. // let purchasedList = res.list.map((i) => i.name);
  2167. // data.pens.forEach((pen) => {
  2168. // if (pen.name === 'svgPath' && pen.svgUrl) {
  2169. // if (purchasedList.includes(pen.svgUrl)) {
  2170. // pen.pathId = null;
  2171. // }
  2172. // }
  2173. // });
  2174. // }
  2175. // }
  2176. // const _zip: any = zip.folder(`${_fileName}`);
  2177. // _zip.file(
  2178. // `${type === Frame.vue3
  2179. // ? 'meta2d-vue3'
  2180. // : type === Frame.vue2
  2181. // ? 'meta2d-vue2'
  2182. // : 'meta2d-react'
  2183. // }/public/json/data.json`,
  2184. // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
  2185. // );
  2186. // await Promise.all([
  2187. // zipJs(_zip),
  2188. // zipBkImg(_zip),
  2189. // zipImages(_zip, meta2d.store.data.pens),
  2190. // type === Frame.vue3
  2191. // ? zipVue3Files(_zip)
  2192. // : type === Frame.vue2
  2193. // ? zipVue2Files(_zip)
  2194. // : zipReactFiles(_zip),
  2195. // zipIotPens(_zip),
  2196. // ]);
  2197. // const blob = await zip.generateAsync({ type: 'blob' });
  2198. // saveAs(blob, `${_fileName}.zip`);
  2199. // frameFlag = -1;
  2200. // }
  2201. // async function zipIotPens(zip: JSZip) {
  2202. // //处理控件
  2203. // const js = await get2dComponentJs();
  2204. // zip.file(`${frameFlag === Frame.vue3
  2205. // ? 'meta2d-vue3'
  2206. // : frameFlag === Frame.vue2
  2207. // ? 'meta2d-vue2'
  2208. // : 'meta2d-react'
  2209. // }/public/js/2d-components.js`, js, { createFolders: true });
  2210. // const res: Blob = await axios.get('/view/js/r.js', {
  2211. // responseType: 'blob',
  2212. // });
  2213. // zip.file(`${frameFlag === Frame.vue3
  2214. // ? 'meta2d-vue3'
  2215. // : frameFlag === Frame.vue2
  2216. // ? 'meta2d-vue2'
  2217. // : 'meta2d-react'
  2218. // }/public/js/r.js`, res, { createFolders: true });
  2219. // }
  2220. // async function zipJs(zip: JSZip) {
  2221. // const files = ['/view/js/marked.min.js', '/view/js/lcjs.iife.js'];
  2222. // await Promise.all(
  2223. // files.map(async (filePath) => {
  2224. // const res: Blob = await axios.get(filePath, {
  2225. // responseType: 'blob',
  2226. // });
  2227. // zip.file(
  2228. // `${frameFlag === Frame.vue3
  2229. // ? 'meta2d-vue3'
  2230. // : frameFlag === Frame.vue2
  2231. // ? 'meta2d-vue2'
  2232. // : 'meta2d-react'
  2233. // }/public` + filePath.replace('/view', ''),
  2234. // res,
  2235. // { createFolders: true }
  2236. // );
  2237. // })
  2238. // );
  2239. // }
  2240. // async function _zipVue3Files(zip: JSZip) {
  2241. // const files = [
  2242. // '/view/js/marked.min.js',
  2243. // '/view/js/lcjs.iife.js',
  2244. // '/view/vue3/Meta2d.vue',
  2245. // '/view/index.html',
  2246. // '/view/js/meta2d.js',
  2247. // '/view/使用说明.md',
  2248. // ] as const;
  2249. // // 文件同时加载
  2250. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2251. // }
  2252. //新
  2253. // async function zipVue3Files(zip: JSZip) {
  2254. // const files = [
  2255. // '/view/meta2d-vue3/src/components/Meta2d.vue',
  2256. // '/view/meta2d-vue3/src/App.vue',
  2257. // '/view/meta2d-vue3/src/main.js',
  2258. // '/view/meta2d-vue3/src/style.css',
  2259. // '/view/meta2d-vue3/index.html',
  2260. // '/view/meta2d-vue3/package.json',
  2261. // '/view/meta2d-vue3/README.md',
  2262. // '/view/meta2d-vue3/vite.config.js',
  2263. // ] as const;
  2264. // // 文件同时加载
  2265. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2266. // }
  2267. // async function _zipVue2Files(zip: JSZip) {
  2268. // const files = [
  2269. // '/view/js/marked.min.js',
  2270. // '/view/js/lcjs.iife.js',
  2271. // '/view/vue2/Meta2d.vue',
  2272. // '/view/index.html',
  2273. // '/view/js/meta2d.js',
  2274. // '/view/使用说明.md',
  2275. // ] as const;
  2276. // // 文件同时加载
  2277. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2278. // }
  2279. // async function zipVue2Files(zip: JSZip) {
  2280. // const files = [
  2281. // '/view/meta2d-vue2/src/components/Meta2d.vue',
  2282. // '/view/meta2d-vue2/src/App.vue',
  2283. // '/view/meta2d-vue2/src/main.js',
  2284. // // '/view/meta2d-vue2/src/style.css',
  2285. // '/view/meta2d-vue2/public/index.html',
  2286. // '/view/meta2d-vue2/package.json',
  2287. // '/view/meta2d-vue2/README.md',
  2288. // // '/view/meta2d-vue3/vite.config.js',
  2289. // ] as const;
  2290. // // 文件同时加载
  2291. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2292. // }
  2293. // async function _zipReactFiles(zip: JSZip) {
  2294. // const files = [
  2295. // '/view/js/marked.min.js',
  2296. // '/view/js/lcjs.iife.js',
  2297. // '/view/react/Meta2d.jsx',
  2298. // '/view/react/Meta2d.css',
  2299. // '/view/index.html',
  2300. // '/view/js/meta2d.js',
  2301. // '/view/使用说明.md',
  2302. // ] as const;
  2303. // // 文件同时加载
  2304. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2305. // }
  2306. // async function zipReactFiles(zip: JSZip) {
  2307. // const files = [
  2308. // '/view/meta2d-react/src/index.css',
  2309. // '/view/meta2d-react/src/index.js',
  2310. // '/view/meta2d-react/src/Meta2d.css',
  2311. // '/view/meta2d-react/src/Meta2d.jsx',
  2312. // '/view/meta2d-react/package.json',
  2313. // '/view/meta2d-react/README.md',
  2314. // '/view/meta2d-react/public/index.html',
  2315. // ] as const;
  2316. // // 文件同时加载
  2317. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2318. // }
  2319. // async function zipFiles(zip: JSZip) {
  2320. // const files = [
  2321. // '/view/js/marked.min.js',
  2322. // '/view/js/lcjs.iife.js',
  2323. // '/view/js/index.js',
  2324. // '/view/js/meta2d.js',
  2325. // '/view/index.html',
  2326. // '/view/index.css',
  2327. // '/view/favicon.ico',
  2328. // '/view/使用说明.pdf',
  2329. // ] as const;
  2330. // // 文件同时加载
  2331. // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
  2332. // }
  2333. // async function zipFile(zip: JSZip, filePath: string) {
  2334. // const res: Blob = await axios.get(
  2335. // (cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1)) + filePath,
  2336. // {
  2337. // responseType: 'blob',
  2338. // }
  2339. // );
  2340. // zip.file(filePath.replace('/view', ''), res, { createFolders: true });
  2341. // }
  2342. // /**
  2343. // * 图片放到 zip 里
  2344. // * @param pens 可以是非具有 calculative 的 pen
  2345. // */
  2346. // async function zipImages(zip: JSZip, pens: Pen[]) {
  2347. // if (!pens) {
  2348. // return;
  2349. // }
  2350. // // 不止 image 上有图片, strokeImage ,backgroundImage 也有图片
  2351. // const imageKeys = [
  2352. // {
  2353. // string: 'image',
  2354. // },
  2355. // { string: 'strokeImage' },
  2356. // { string: 'backgroundImage' },
  2357. // ] as const;
  2358. // const images: string[] = [];
  2359. // for (const pen of pens) {
  2360. // for (const i of imageKeys) {
  2361. // const image = pen[i.string];
  2362. // if (image) {
  2363. // // HTMLImageElement 无法精确控制图片格式
  2364. // if (
  2365. // image.startsWith('/') ||
  2366. // image.startsWith(cdn) ||
  2367. // image.startsWith(upCdn)
  2368. // ) {
  2369. // // 只考虑相对路径下的 image ,绝对路径图片无需下载
  2370. // if (!images.includes(image)) {
  2371. // images.push(image);
  2372. // }
  2373. // }
  2374. // }
  2375. // }
  2376. // // 无需递归遍历子节点,现在所有的节点都在外层
  2377. // }
  2378. // //付费pngs
  2379. // const pngs = await getTemPngs(images.map(i => i.replace(cdn, '').replace(upCdn, '')));
  2380. // await Promise.all(images.map((image) => zipImage(zip, image, pngs[image.replace(cdn, '').replace(upCdn, '')])));
  2381. // }
  2382. // async function zipImage(zip: JSZip, image: string, temImage?: string) {
  2383. // const res: Blob = await axios.get(temImage || image, {
  2384. // responseType: 'blob',
  2385. // // params: {
  2386. // // isZip: true,
  2387. // // },
  2388. // });
  2389. // zip.file(
  2390. // (frameFlag === -1
  2391. // ? ''
  2392. // : `${frameFlag === Frame.vue3
  2393. // ? 'meta2d-vue3'
  2394. // : frameFlag === Frame.vue2
  2395. // ? 'meta2d-vue2'
  2396. // : 'meta2d-react'
  2397. // }/public`) + (cdn ? image.replace(cdn, '').replace(upCdn, '') : image),
  2398. // res,
  2399. // {
  2400. // createFolders: true,
  2401. // }
  2402. // );
  2403. // }
  2404. const downloadImageTips =
  2405. '无法下载,宽度不合法,画布可能没有画笔/画布大小超出浏览器最大限制';
  2406. const downloadPng = () => {
  2407. if (!meta2d.store.data.pens.length) {
  2408. MessagePlugin.warning(downloadImageTips);
  2409. return;
  2410. }
  2411. try {
  2412. meta2d.downloadPng();
  2413. } catch (e) {
  2414. MessagePlugin.warning(downloadImageTips);
  2415. }
  2416. };
  2417. async function getIconDefs(url: string) {
  2418. let res: any = await axios.get(url);
  2419. let str = res.match(/@font-face([\s\S]*?)\}/)[1];
  2420. str = `@font-face ${str} }`;
  2421. return str;
  2422. }
  2423. const downloadSvg = async () => {
  2424. // await import('@/assets/canvas2svg');
  2425. for (const pen of meta2d.store.data.pens) {
  2426. if (pen.calculative.img) {
  2427. //重新生成绘制图片
  2428. pen.onRenderPenRaw?.(pen);
  2429. }
  2430. }
  2431. if (!C2S) {
  2432. MessagePlugin.error('请先加载乐吾乐官网下的canvas2svg.js');
  2433. return;
  2434. }
  2435. const rect: any = meta2d.getRect();
  2436. if (!isFinite(rect.width)) {
  2437. MessagePlugin.error(downloadImageTips);
  2438. return;
  2439. }
  2440. rect.x -= 10;
  2441. rect.y -= 10;
  2442. const ctx = new C2S(rect.width + 20, rect.height + 20);
  2443. ctx.textBaseline = 'middle';
  2444. ctx.strokeStyle = getGlobalColor(meta2d.store);
  2445. for (const pen of meta2d.store.data.pens) {
  2446. // 不使用 calculative.inView 的原因是,如果 pen 在 view 之外,那么它的 calculative.inView 为 false,但是它的绘制还是需要的
  2447. if (!isShowChild(pen, meta2d.store) || pen.visible == false) {
  2448. continue;
  2449. }
  2450. meta2d.renderPenRaw(ctx, pen, rect);
  2451. }
  2452. let mySerializedSVG = ctx.getSerializedSvg();
  2453. let icon_pens = meta2d.store.data.pens.filter(
  2454. (item) => item.iconFamily && item.icon
  2455. );
  2456. if (icon_pens && icon_pens.length > 0) {
  2457. let iconList = [
  2458. '/icon/国家电网/iconfont.css',
  2459. '/icon/电气工程/iconfont.css',
  2460. '/icon/通用图标/iconfont.css',
  2461. ];
  2462. let defsList: any = await Promise.all(
  2463. iconList.map((item) => getIconDefs(item))
  2464. );
  2465. mySerializedSVG = mySerializedSVG.replace(
  2466. '<defs/>',
  2467. `<defs>
  2468. <style type="text/css">
  2469. ${defsList.join('\n')}
  2470. </style>
  2471. {{bk}}
  2472. </defs>
  2473. {{bkRect}}`
  2474. );
  2475. }
  2476. /* mySerializedSVG = mySerializedSVG.replace(
  2477. '<defs/>',
  2478. `<defs>
  2479. <style type="text/css">
  2480. @font-face {
  2481. font-family: 'ticon';
  2482. src: url('icon/通用图标/iconfont.ttf') format('truetype');
  2483. }
  2484. </style>
  2485. {{bk}}
  2486. </defs>
  2487. {{bkRect}}`
  2488. );
  2489. */
  2490. if (meta2d.store.data.background) {
  2491. mySerializedSVG = mySerializedSVG.replace('{{bk}}', '');
  2492. mySerializedSVG = mySerializedSVG.replace(
  2493. '{{bkRect}}',
  2494. `<rect x="0" y="0" width="100%" height="100%" fill="${meta2d.store.data.background}"></rect>`
  2495. );
  2496. } else {
  2497. mySerializedSVG = mySerializedSVG.replace('{{bk}}', '');
  2498. mySerializedSVG = mySerializedSVG.replace('{{bkRect}}', '');
  2499. }
  2500. mySerializedSVG = mySerializedSVG.replace(/--le5le--/g, '&#x');
  2501. const urlObject: any = (window as any).URL || window;
  2502. const export_blob = new Blob([mySerializedSVG]);
  2503. const url = urlObject.createObjectURL(export_blob);
  2504. const a = document.createElement('a');
  2505. a.setAttribute(
  2506. 'download',
  2507. `${(meta2d.store.data as Meta2dBackData).name || 'le5le.meta2d'}.svg`
  2508. );
  2509. a.setAttribute('href', url);
  2510. const evt = document.createEvent('MouseEvents');
  2511. evt.initEvent('click', true, true);
  2512. a.dispatchEvent(evt);
  2513. };
  2514. const onUndo = () => {
  2515. meta2d.undo();
  2516. };
  2517. const onRedo = () => {
  2518. meta2d.redo();
  2519. };
  2520. const onCut = () => {
  2521. meta2d.cut();
  2522. };
  2523. const onCopy = () => {
  2524. meta2d.copy();
  2525. };
  2526. const onPaste = () => {
  2527. meta2d.paste();
  2528. };
  2529. const onAll = () => {
  2530. meta2d.activeAll();
  2531. };
  2532. const onDelete = () => {
  2533. meta2d.delete();
  2534. };
  2535. const onToggleAnchor = () => {
  2536. //取消连线状态
  2537. // meta2d.store.options.disableAnchor = false;
  2538. if (!meta2d.store.options.disableAnchor) {
  2539. meta2d.canvas.drawingLineName && drawPen();
  2540. meta2d.toggleAnchorMode();
  2541. }
  2542. };
  2543. const onAddAnchorHand = () => {
  2544. meta2d.addAnchorHand();
  2545. };
  2546. const onRemoveAnchorHand = () => {
  2547. meta2d.removeAnchorHand();
  2548. };
  2549. const onToggleAnchorHand = () => {
  2550. meta2d.toggleAnchorHand();
  2551. };
  2552. const onScaleUp = () => {
  2553. const _scale = meta2d.store.data.scale + 0.1;
  2554. meta2d.scale(_scale);
  2555. };
  2556. const onScaleDown = () => {
  2557. const _scale = meta2d.store.data.scale - 0.1;
  2558. meta2d.scale(_scale);
  2559. };
  2560. const autoAnchor = ref(true);
  2561. const onAutoAnchor = () => {
  2562. meta2d.store.options.autoAnchor = !meta2d.store.options.autoAnchor;
  2563. autoAnchor.value = meta2d.store.options.autoAnchor;
  2564. };
  2565. const showAnchor = ref(false);
  2566. const onDisableAnchor = () => {
  2567. meta2d.store.options.disableAnchor = !meta2d.store.options.disableAnchor;
  2568. changeDisableAnchor();
  2569. };
  2570. const changeDisableAnchor = () => {
  2571. const { disableAnchor, autoAnchor } = meta2d.store.options;
  2572. showAnchor.value = !disableAnchor || false;
  2573. if (disableAnchor && autoAnchor) {
  2574. // 禁用瞄点开了,需要关闭自动瞄点
  2575. onAutoAnchor();
  2576. }
  2577. };
  2578. const payListDialog = reactive({
  2579. show: false,
  2580. title:'',
  2581. href:'',
  2582. downloadUrl:''
  2583. });
  2584. const downloadZipDialog = reactive({
  2585. show: false,
  2586. checked:true,
  2587. expend:false,
  2588. price:0,
  2589. list:[],
  2590. hasJs:false,
  2591. });
  2592. const prePay = async () => {
  2593. let list = [];
  2594. let names = data.purchasedList.map((item) => item.name);
  2595. if(data.payDiagram.checked){
  2596. prePayList.pngs.forEach((item) => {
  2597. if(!names.includes(item)){
  2598. list.push({
  2599. type: '图片图元',
  2600. name: item,
  2601. });
  2602. }
  2603. });
  2604. prePayList.jsPens.forEach((item) => {
  2605. if(!names.includes(item)){
  2606. list.push({
  2607. type: 'JS线性图元',
  2608. name: item,
  2609. });
  2610. }
  2611. });
  2612. prePayList.iotPens.forEach((item) => {
  2613. if(!names.includes(item)){
  2614. list.push({
  2615. type: '控件',
  2616. name: item,
  2617. });
  2618. }
  2619. });
  2620. if ([...prePayList.svgPens].includes('*')) {
  2621. list.push({
  2622. type: 'SVG线性图元',
  2623. });
  2624. } else {
  2625. prePayList.svgPens.forEach((item) => {
  2626. if(!names.includes(item)){
  2627. list.push({
  2628. type: 'SVG线性图元',
  2629. name: item,
  2630. });
  2631. }
  2632. });
  2633. }
  2634. }
  2635. const res: any = await axios.post('/api/order/deployment/submit', {
  2636. goods:data.payGoods,
  2637. '2ds':list,
  2638. });
  2639. wechatPayDialog.show = true;
  2640. data.order = res;
  2641. };
  2642. const downloadTrial = () => {
  2643. MessagePlugin.info('正在下载中,可能需要几分钟,请耐心等待...');
  2644. //下载试用版
  2645. window.open(payListDialog.downloadUrl, '_blank');
  2646. }
  2647. const skipPay = () => {
  2648. //跳过支付,直接下载
  2649. MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
  2650. if (downloadType === Frame.html) {
  2651. preDownload();
  2652. } else {
  2653. preFrameDownload();
  2654. }
  2655. };
  2656. const finishPay = async () => {
  2657. // let id = data.order.id;
  2658. // const result: { state: number } = await axios.post('/api/order/pay/state', {
  2659. // id,
  2660. // });
  2661. // if (result && result.state) {
  2662. MessagePlugin.success('支付成功');
  2663. wechatPayDialog.show = false;
  2664. if(wechatPayDialog.isZip){
  2665. // downloadZipDialog.show = false;
  2666. wechatPayDialog.isZip = false;
  2667. doDownloadZip();
  2668. }else{
  2669. payListDialog.show = false;
  2670. MessagePlugin.loading('正在下载打包中,可能需要几分钟,请耐心等待...',0);
  2671. if (downloadType === Frame.html) {
  2672. preDownload();
  2673. } else {
  2674. preFrameDownload();
  2675. }
  2676. }
  2677. // } else {
  2678. // MessagePlugin.error('支付失败');
  2679. // // wechatPayDialog.show = false;
  2680. // }
  2681. };
  2682. const finalPrice = computed(() => {
  2683. let total = 0;
  2684. let price = 0;
  2685. data.goods.forEach((item, index) => {
  2686. if (item.checked) {
  2687. total += item.unPurchased;
  2688. price += item.unPurchased * item.unitPrice;
  2689. }
  2690. });
  2691. return {
  2692. total,
  2693. price,
  2694. };
  2695. });
  2696. const wechatPayDialog = reactive({
  2697. show: false,
  2698. isZip:false
  2699. });
  2700. const emit = defineEmits(['success']);
  2701. const onSuccess = (success: boolean) => {
  2702. finishPay();
  2703. emit('success', success);
  2704. };
  2705. </script>
  2706. <style lang="postcss" scoped>
  2707. .app-header {
  2708. display: flex;
  2709. height: 40px;
  2710. background-color: var(--color-background);
  2711. position: relative;
  2712. z-index: 2;
  2713. .logo {
  2714. display: flex;
  2715. padding: 0 16px;
  2716. align-items: center;
  2717. font-size: 14px;
  2718. font-weight: 500;
  2719. img {
  2720. height: 20px;
  2721. margin-right: 6px;
  2722. }
  2723. }
  2724. a {
  2725. display: flex;
  2726. padding: 0 8px;
  2727. margin: 0 8px;
  2728. align-items: center;
  2729. color: var(--color);
  2730. text-decoration: none;
  2731. white-space: nowrap;
  2732. &:hover {
  2733. color: var(--color-primary);
  2734. }
  2735. svg {
  2736. font-size: 15px;
  2737. margin: 2px 4px 0 0;
  2738. }
  2739. &.active {
  2740. background-color: var(--color-primary);
  2741. color: #ffffff;
  2742. }
  2743. }
  2744. input {
  2745. font-size: var(--font-size);
  2746. flex-grow: 1;
  2747. min-width: 100px;
  2748. background: none;
  2749. outline: none;
  2750. border: none;
  2751. text-align: center;
  2752. color: var(--color-title);
  2753. }
  2754. }
  2755. .pay-box{
  2756. background: rgba(175,202,255,0.04);
  2757. border-radius: 4px;
  2758. margin-bottom:24px;
  2759. padding:20px 24px;
  2760. position:relative;
  2761. display:flex;
  2762. .pay-up{
  2763. display:flex;
  2764. }
  2765. :deep(.t-checkbox__label){
  2766. font-size: 16px;
  2767. color: #6e7b91;
  2768. margin-left:16px;
  2769. }
  2770. .pay-title{
  2771. font-size: 16px;
  2772. color: #6e7b91;
  2773. .t-icon{
  2774. margin-top:-5px;
  2775. margin-left:12px;
  2776. }
  2777. :deep(.t-checkbox__input){
  2778. background:#fff0;
  2779. }
  2780. :deep(.t-is-checked){
  2781. .t-checkbox__input{
  2782. background:var(--color-primary);
  2783. }
  2784. }
  2785. }
  2786. .pay-price{
  2787. position:absolute;
  2788. right:24px;
  2789. color:#4480F9;
  2790. display:flex;
  2791. p:nth-child(2){
  2792. font-size: 20px;
  2793. }
  2794. }
  2795. .pay-down{
  2796. margin-top:16px;
  2797. display:flex;
  2798. flex-wrap:wrap;
  2799. /* justify-content:space-between; */
  2800. /* padding-top:24px; */
  2801. max-height: 200px;
  2802. overflow-y: scroll;
  2803. &>div{
  2804. width: 48px;
  2805. height: 48px;
  2806. background: #1c283b;
  2807. border-radius: 4px;
  2808. margin-right:2.5px;
  2809. margin-bottom:2.5px;
  2810. &:nth-child(12n){
  2811. margin-right: 0px;
  2812. }
  2813. img{
  2814. margin:4px;
  2815. width:40px;
  2816. height:40px;
  2817. }
  2818. .l-icon{
  2819. /* width: 80px; */
  2820. /* height: 80px; */
  2821. /* margin:8px; */
  2822. font-size:24px;
  2823. margin:12px;
  2824. }
  2825. &>div{
  2826. margin: 8px 12px;
  2827. }
  2828. }
  2829. &>p{
  2830. display: block;
  2831. margin-top:8px;
  2832. width:100%;
  2833. }
  2834. }
  2835. }
  2836. .pay-footer{
  2837. display:flex;
  2838. margin-bottom: -48px;
  2839. margin-left:24px;
  2840. font-size: 14px;
  2841. &>div{
  2842. color:#4480F9;
  2843. display:flex;
  2844. p:nth-child(2){
  2845. font-size: 24px;
  2846. font-weight: 800;
  2847. margin-top:-3px;
  2848. }
  2849. p:nth-child(1){
  2850. margin:0px 4px;
  2851. }
  2852. }
  2853. }
  2854. .pay-diagram{
  2855. flex-direction:column;
  2856. }
  2857. /* .pay-dialog {
  2858. background-color: red;
  2859. } */
  2860. /* .pay-body {
  2861. height: 300px;
  2862. overflow-y: scroll;
  2863. margin-bottom: 30px;
  2864. .t-collapse {
  2865. border: 0px;
  2866. :deep(.t-collapse-panel__wrapper .t-collapse-panel__header) {
  2867. border-bottom: 0px;
  2868. }
  2869. :deep(.t-collapse-panel__wrapper .t-collapse-panel__body) {
  2870. background: #fff0;
  2871. border-bottom: 0px;
  2872. .t-collapse-panel__content {
  2873. padding: 0;
  2874. color: #c1c8d7;
  2875. }
  2876. }
  2877. }
  2878. } */
  2879. /* .pay-line {
  2880. display: flex;
  2881. height: 54px;
  2882. background-color: #afcaff0a;
  2883. margin-top: 1px;
  2884. div {
  2885. width: 30%;
  2886. text-align: center;
  2887. line-height: 54px;
  2888. :deep(.t-image) {
  2889. width: 40px;
  2890. height: 40px;
  2891. margin-top: 7px;
  2892. }
  2893. :deep(.pay-svg) {
  2894. .t-image {
  2895. background: #fff;
  2896. }
  2897. }
  2898. .l-icon {
  2899. width: 40px;
  2900. height: 40px;
  2901. margin-top: 7px;
  2902. width: 30%;
  2903. }
  2904. }
  2905. .pay-p{
  2906. overflow:hidden;
  2907. text-overflow:ellipsis;
  2908. white-space:nowrap;
  2909. }
  2910. & > div:first-child {
  2911. width: 40%;
  2912. display: flex;
  2913. }
  2914. } */
  2915. /* .pay-tip {
  2916. height: 54px;
  2917. width: 100%;
  2918. position: relative;
  2919. p {
  2920. position: absolute;
  2921. right: 16px;
  2922. color: var(--color-desc);
  2923. }
  2924. }
  2925. .pay-footer {
  2926. margin-bottom: -42px;
  2927. position: relative;
  2928. .pay-price {
  2929. position: absolute;
  2930. right: 215px;
  2931. margin-left: 50px;
  2932. align-items: flex-end;
  2933. line-height: 10px;
  2934. p{
  2935. vertical-align: bottom;
  2936. line-height: normal;
  2937. }
  2938. p:nth-child(2) {
  2939. font-size: 32px;
  2940. font-weight: Semibold;
  2941. color: #4480f9;
  2942. line-height: 20px;
  2943. }
  2944. p:nth-child(1) {
  2945. font-size: 14px;
  2946. color: #4480f9;
  2947. }
  2948. }
  2949. } */
  2950. /* .pay-title {
  2951. margin: 18px 0px 12px 18px;
  2952. } */
  2953. </style>