Header.vue 88 KB

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