Header.vue 88 KB

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