Header.vue 98 KB

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