Header.vue 97 KB

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