123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300 |
- <template>
- <div class="app-header">
- <a class="logo" :href="enterprise.home" target="_blank">
- <img src="/favicon.ico">
- <span> {{ $t(enterprise.name) }}</span>
- </a>
- <t-dropdown :minColumnWidth="200" :maxHeight="560" :delay2="[10, 150]" overlayClassName="header-dropdown" trigger1="click">
- <a> {{$t('文件')}} </a>
- <t-dropdown-menu>
- <t-dropdown-item @click="newFile">
- <a>{{$t('新建文件')}}</a>
- </t-dropdown-item>
- <t-dropdown-item @click="load(true)">
- <a>{{$t('打开文件')}}</a>
- </t-dropdown-item>
- <t-dropdown-item @click="load()">
- <a>{{$t('导入文件')}}</a>
- </t-dropdown-item>
- <t-dropdown-item >
- <a @click="importVisio">
- <div class="flex">
- {{$t('导入visio(vsdx)文件')}}<span class="flex-grow"></span>
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="importDxf">
- <div class="flex">
- {{$t('导入CAD(dxf)文件')}}<span class="flex-grow"></span>
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="save(SaveType.Save,'',true)">{{$t('保存')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="save(SaveType.SaveAs, '', true, 1)">{{$t('另存为')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="save(SaveType.Save, '', true, undefined, true)">{{$t('仅保存')}}JSON{{$t('数据')}}</a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="downloadJson">{{$t('下载')}}JSON{{$t('文件')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="downloadZip">
- <div class="flex">
- {{$t('导出为')}}ZIP{{$t('文件')}} <span class="flex-grow"></span>
- <!-- <span><label>VIP</label></span> -->
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="downloadHtml">
- <div class="flex">
- {{$t('下载离线部署包')}} <span class="flex-grow"></span>
- <!-- <span><label>企</label></span> -->
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="downloadVue3">
- <div class="flex">
- {{$t('下载')}}Vue3{{$t('组件包')}} <span class="flex-grow"></span>
- <!-- <span><label>企</label></span> -->
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="downloadVue2">
- <div class="flex">
- {{$t('下载')}}Vue2{{$t('组件包')}} <span class="flex-grow"></span>
- <!-- <span><label>企</label></span> -->
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="downloadReact">
- <div class="flex">
- {{$t('下载')}}React{{$t('组件包')}} <span class="flex-grow"></span>
- <!-- <span><label>企</label></span> -->
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="downloadPng">{{$t('下载为')}}PNG</a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="downloadSvg">{{$t('下载为')}}SVG</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="switchTheme('light')">{{$t('明亮主题')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="switchTheme('dark')">{{$t('暗黑主题')}}</a>
- </t-dropdown-item>
- </t-dropdown-menu>
- </t-dropdown>
- <t-dropdown :minColumnWidth="180" :maxHeight="500" :delay2="[10, 150]" overlayClassName="header-dropdown">
- <a> {{$t('编辑')}} </a>
- <t-dropdown-menu>
- <t-dropdown-item>
- <a @click="onUndo">
- <div class="flex">
- {{$t('撤销')}} <span class="flex-grow"></span> Ctrl + Z
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="onRedo">
- <div class="flex">
- {{$t('重做')}} <span class="flex-grow"></span> Ctrl + Y
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onCut">
- <div class="flex">
- {{$t('剪切')}} <span class="flex-grow"></span> Ctrl + X
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onCopy">
- <div class="flex">
- {{$t('复制')}} <span class="flex-grow"></span> Ctrl + C
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="onPaste">
- <div class="flex">
- {{$t('粘贴')}} <span class="flex-grow"></span> Ctrl + V
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onAll">
- <div class="flex">
- {{$t('全选')}} <span class="flex-grow"></span> Ctrl + A
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onDelete">
- <div class="flex">{{$t('删除')}} <span class="flex-grow"></span> DELETE</div>
- </a>
- </t-dropdown-item>
- </t-dropdown-menu>
- </t-dropdown>
- <t-dropdown :minColumnWidth="180" :maxHeight="500" :delay2="[10, 150]" overlayClassName="header-dropdown">
- <a> {{$t('工具')}} </a>
- <t-dropdown-menu>
- <t-dropdown-item>
- <a @click="onScaleWindow">{{$t('窗口大小')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onScaleUp">{{$t('放大')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onScaleDown">{{$t('缩小')}}</a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="onScaleFull">100%{{$t('视图')}}</a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="showMap">
- <div class="flex middle">
- {{$t('鹰眼地图')}} <span class="flex-grow"></span>
- <!-- <t-icon v-show="map" name="check" /> -->
- <check-icon v-show="map"></check-icon>
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="showMagnifier">
- <div class="flex middle">
- {{$t('放大镜')}} <span class="flex-grow"></span>
- <!-- <t-icon v-show="magnifier" name="check" /> -->
- <check-icon v-show="magnifier"></check-icon>
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onAutoAnchor">
- <div class="flex middle">
- {{$t('自动锚点')}} <span class="flex-grow"></span>
- <!-- <t-icon v-show="autoAnchor" name="check" /> -->
- <check-icon v-show="autoAnchor"></check-icon>
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a @click="onDisableAnchor">
- <div class="flex middle">
- {{$t('显示锚点')}} <span class="flex-grow"></span>
- <!-- <t-icon v-show="showAnchor" name="check" /> -->
- <check-icon v-show="showAnchor"></check-icon>
- </div>
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="onToggleAnchor">
- <div
- class="flex"
- :style="{
- color: showAnchor ? '' : '#4f5b75',
- }">
- {{$t('添加')}}/{{$t('删除锚点')}} <span class="flex-grow"></span> A
- </div>
- </a>
- </t-dropdown-item>
- </t-dropdown-menu>
- </t-dropdown>
- <t-dropdown
- :minColumnWidth="180"
- :maxHeight="500"
- :delay2="[10, 150]"
- overlayClassName="header-dropdown"
- >
- <a> {{$t( '帮助' )}} </a>
- <t-dropdown-menu>
- <t-dropdown-item
- v-for="item in enterprise.helps_v"
- :divider="item.divider"
- >
- <a :href="item.url" target="_blank">{{ item.name }}</a>
- </t-dropdown-item>
- </t-dropdown-menu>
- </t-dropdown>
- <t-dropdown
- :minColumnWidth="180"
- :maxHeight="500"
- :delay2="[10, 150]"
- overlayClassName="header-dropdown">
- <a> {{$t('语言')}} </a>
- <t-dropdown-menu>
- <t-dropdown-item v-for="item in languages">
- <div @click="changeLanguage(item.value)">{{ item.name }}</div>
- </t-dropdown-item>
- </t-dropdown-menu>
- </t-dropdown>
- <!-- <div style="width: 148px; flex-shrink: 0"></div> -->
- <input v-model="meta2dData.name" @change="onInputName($event)" />
- <!-- <a :href="enterprise.account" target="_blank">
- <home-icon></home-icon>
- {{$t('账户中心')}}
- </a> -->
- <a :href="enterprise['v']" target="_blank" class="active">
- <!-- <t-icon name="desktop" /> -->
- <desktop-icon></desktop-icon>
- {{$t('大屏可视化')}}
- </a>
- <a :href="enterprise['3d']" target="_blank">
- <!-- <t-icon name="control-platform" /> -->
- <control-platform-icon></control-platform-icon>
- 3D{{$t('可视化')}}
- </a>
- <a :href="enterprise['2d']" target="_blank">
- <!-- <t-icon name="app" /> -->
- <app-icon></app-icon>
- 2D{{$t('可视化')}}
- </a>
- <t-dropdown
- v-if="user.id"
- :minColumnWidth="200"
- :maxHeight="500"
- :delay2="[10, 150]"
- overlayClassName="custom-dropdown header"
- >
- <a style="margin-left: 32px; margin-right: 12px">
- <t-avatar
- size="small"
- :image="user.avatarUrl ? user.avatarUrl : baseUrl + 'img/avatar.png'"
- />
- </a>
- <t-dropdown-menu>
- <t-dropdown-item divider="true">
- <a :href="enterprise.account" target="_blank">
- {{ user.username }}
- <label
- class="ml-16 vip-label"
- :style="{
- color: user.limit > 1 ? '#ff4000' : '#D5C781',
- background: user.limit > 1 ? '#ff400030' : '#D5C78133',
- }"
- >VIP</label
- >
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a :href="`${enterprise.account}/v`" target="_blank"> {{$t('我的大屏')}} </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a :href="`${enterprise.account}/account/teams`" target="_blank">
- {{$t('我的团队')}}
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a :href="`${enterprise.account}/account/info`" target="_blank">
- {{$t('账号信息')}}
- </a>
- </t-dropdown-item>
- <t-dropdown-item divider="true">
- <a :href="`${enterprise.account}/account/security`" target="_blank">
- {{$t('安全设置')}}
- </a>
- </t-dropdown-item>
- <t-dropdown-item>
- <a @click="logout">{{$t('退出')}}</a>
- </t-dropdown-item>
- </t-dropdown-menu>
- </t-dropdown>
- <div class="flex middle" v-else>
- <a class="button primary solid" style="width: 80px" :href="login()">
- {{$t('登录')}}
- </a>
- </div>
- </div>
- <!-- <t-dialog
- v-if="payListDialog.show"
- v-model:visible="payListDialog.show"
- class="pay-dialog"
- :close-on-overlay-click="false"
- :top="95"
- :width="700"
- :cancel-btn="{
- content: '下载试用',
- variant: 'outline',
- style: {
- width: '100px',
- color:'#707B8F',
- marginRight:'8px'
- }
- }"
- confirm-btn="去支付"
- @cancel="downloadTrial"
- @close="payListDialog.show = false"
- @confirm="prePay"
- >
- <template #header>
- <div>
- <span style="vertical-align: middle">{{ payListDialog.title }}</span>
- <a
- :href="payListDialog.href"
- target="_blank"
- class="hover"
- >
- <HelpCircleIcon class="hover" style="margin-left:12px;" />
- </a>
- </div>
- </template>
- <div class="pay-box">
- <div class="pay-title">{{ payListDialog.title }}</div>
- <div class="pay-price">
- <p>¥</p>
- <p>{{ data.deploy.price }}</p>
- </div>
- </div>
- <div class="pay-box pay-diagram">
- <div class="pay-up">
- <div class="pay-title">
- <t-checkbox v-model="data.payDiagram.checked"> 企业图形库
-
- </t-checkbox>
- <ChevronDownIcon @click="data.payDiagram.expend=false" v-if="data.payDiagram.expend" />
- <ChevronRightIcon @click="data.payDiagram.expend=true" v-else />
- </div>
- <div class="pay-price">
- <p>¥</p>
- <p>{{ data.payDiagram.price }}</p>
- </div>
- </div>
- <div v-if="data.payDiagram.expend" class="pay-down">
- <div v-for="item in data.payDiagram.list">
- <img v-if="item.img" :src="item.img" />
- <div v-else-if="item.svg" v-html="item.svg" ></div>
- <svg v-else class="l-icon" aria-hidden="true">
- <use :xlink:href="'#' + iotPensMap[item.name]?.icon"></use>
- </svg>
- </div>
- <p v-if="data.payDiagram.payAll">
- 【说明】检查到当前项目为老版本格式,需要购买整套SVG线性图元。
- </p>
- </div>
- </div>
- <div class="pay-footer">
- 合计
- <div>
- <p>¥</p>
- <p>{{ data.deploy.price+(data.payDiagram.checked?data.payDiagram.price:0) }}</p>
- </div>
- </div>
- </t-dialog> -->
- <!-- <t-dialog
- v-if="downloadZipDialog.show"
- v-model:visible="downloadZipDialog.show"
- class="pay-dialog"
- :close-on-overlay-click="false"
- :top="95"
- :width="700"
- :cancel-btn="{
- content: '直接下载',
- variant: 'outline',
- style: {
- width: '100px',
- color:'#707B8F',
- marginRight:'8px'
- }
- }"
- :confirm-btn="downloadZipDialog.checked?'去支付':null"
- @close="downloadZipDialog.show = false"
- @confirm="prePayDownloadZip"
- @cancel="doDownloadZip"
- >
- <template #header>
- <div>
- <span style="vertical-align: middle">导出为Zip文件</span>
- <t-tooltip content="这是Tooltip内容">
- <a
- :href="`https://doc${rootDomain}/document/155692631#%E5%AF%BC%E5%87%BA%E4%B8%BAZip%E6%96%87%E4%BB%B6`"
- target="_blank"
- class="hover"
- >
- <HelpCircleIcon style="margin-left:12px;" />
- </a>
- </t-tooltip>
- </div>
- </template>
- <div class="pay-box pay-diagram" style="font-size: 14px;
- line-height: 30px;
- color: #6E7B91;">
- Zip包仅包含数据文件和图片文件,不包含js等依赖库。
- <div >- 注意</div>Zip包用于平台(已包含js等依赖库)的快捷导入导出项目,无法作为独立部署包使用。
- <p v-if="downloadZipDialog.hasJs">
- <p>- 当前图纸包含js企业图形依赖库。</p>
- 项目中打开如果没有js企业图形依赖库,对应的图元将无法显示。
- 推荐下载为离线部署包(包含js企业图形依赖库)。
- </p>
- </div>
- <div class="pay-box pay-diagram">
- <div class="pay-up">
- <div class="pay-title">
- <t-checkbox v-model="downloadZipDialog.checked"> 企业图形库
-
- </t-checkbox>
- <ChevronDownIcon @click="downloadZipDialog.expend=false" v-if="downloadZipDialog.expend" />
- <ChevronRightIcon @click="downloadZipDialog.expend=true" v-else />
- </div>
- <div class="pay-price">
- <p>¥</p>
- <p>{{ downloadZipDialog.price }}</p>
- </div>
- </div>
- <div v-if="downloadZipDialog.expend" class="pay-down">
- <div v-for="item in downloadZipDialog.list">
- <img :src="item" />
- </div>
- </div>
- </div>
- <div class="pay-footer">
- 合计
- <div>
- <p>¥</p>
- <p>{{downloadZipDialog.checked? downloadZipDialog.price:0 }}</p>
- </div>
- </div>
- </t-dialog> -->
- <!-- <t-dialog
- v-if="wechatPayDialog.show"
- v-model:visible="wechatPayDialog.show"
- class="pay-dialog"
- header="乐吾乐收银台"
- :close-on-overlay-click="false"
- :top="95"
- :width="700"
- confirm-btn="支付完成"
- :cancel-btn="null"
- @close="wechatPayDialog.show = false"
- :footer="false"
- >
- <Pay
- :order="data.order"
- :alipay-url="data.order.alipayUrl"
- :code-url="data.order.codeUrl"
- @success="onSuccess"
- />
- </t-dialog> -->
- <t-dialog v-model:visible="newFileDialog.show" @close="newFileDialog.show = false" @confirm="saveNewfile" @cancel="nosaveNewfile" :header="$t('提示')" :confirm-btn="$t('保存后新建')" :cancel-btn="$t('不保存直接新建')">
- {{$t('当前画布数据未保存')}},{{$t('是否保存后新建')}}?
- </t-dialog>
- </template>
- <script lang="ts" setup>
- import {
- reactive,
- ref,
- onBeforeMount,
- onUnmounted,
- nextTick,
- computed,
- getCurrentInstance
- } from 'vue';
- import { useRouter, useRoute } from 'vue-router';
- import { useUser } from '@/services/user';
- import { MessagePlugin } from 'tdesign-vue-next';
- import {
- Meta2dBackData,
- dealwithFormatbeforeOpen,
- gotoAccount,
- checkData,
- } from '@/services/utils';
- import { readFile } from '@/services/file';
- import { compareVersion, baseVer, upgrade } from '@/services/upgrade';
- import { parseSvg } from '@meta2d/svg';
- import { Pen, getGlobalColor, isShowChild, deepClone } from '@meta2d/core';
- import { cdn, upCdn, addCollection } from '@/services/api';
- import {V2M} from "visio2meta2d";
- import D2M from 'dxf';
- // import JSZip from 'jszip';
- import axios from 'axios';
- import { switchTheme } from '@/services/theme';
- import { noLoginTip } from '@/services/utils';
- import {
- save,
- blank,
- newFile,
- SaveType,
- onScaleFull,
- onScaleWindow,
- showMagnifier,
- showMap,
- drawPen,
- map,
- magnifier,
- useDot,
- delAttrs,
- // useAssets,
- autoSaveAS,
- queryURLParams,
- dealDataBeforeOpen,
- newFileDialog
- } from '@/services/common';
- import { useEnterprise } from '@/services/enterprise';
- import {
- CheckIcon,
- HomeIcon,
- DesktopIcon,
- ControlPlatformIcon,
- AppIcon,
- ChevronRightIcon,
- ChevronDownIcon,
- HelpCircleIcon
- } from 'tdesign-icons-vue-next';
- import {
- getDownloadList,
- getPayList,
- getComponentPurchased,
- get2dComponentJs,
- getTemPngs,
- getGoods,
- // preFrameDownload,
- zipBkImg,
- zipImages,
- Frame,
- img_cdn,
- img_upCdn,
- getDeployGoods,
- getFrameDownloadList,
- getDownloadZipList
- } from '@/services/download';
- import { formComponents, rootDomain } from '@/services/defaults';
- import Pay from './Pay.vue';
- import {getNetJsDiagram} from '@/services/material';
- import { useMeta2dData } from '@/services/common';
- import { upload } from '@/services/file';
- import { load3d } from '@/services/load3d';
- const { enterprise } = useEnterprise();
- const router = useRouter();
- const route = useRoute();
- const { meta2dData, setMeta2dData } = useMeta2dData();
- const baseUrl = import.meta.env.BASE_URL || '/';
- // const { assets, getAssets } = useAssets();
- import {useI18n} from "vue-i18n";
- const { user, signout } = useUser();
- const { setDot, dot } = useDot();
- const { proxy } = getCurrentInstance();
- const $t = proxy.$t
- const data = reactive<any>({
- name: $t('新建项目'),
- order: {
- codeUrl: '',
- id: '', //订单id
- },
- goods: [], //所有商品类型
- purchasedList: [], //已经购买的列表
- deploy:{
- price:400,
- },
- payDiagram: {
- price: 400,
- checked:true,
- expend:false,
- list:[],
- payAll:false
- },
- zips:{
- },
- payGoods:{},
- });
- const { locale } = useI18n()
- const languages = [{
- name:$t("简体中文"),value:"zh",
- },{
- name:$t("繁体中文"),value:"zh_CHT",
- },{
- name:"English",value:"en"
- }]
- function changeLanguage(v) {
- locale.value = v
- localStorage.setItem('i18n',v)
- }
- onBeforeMount(async () => {
- // getAssets();
- // getNetJsDiagram();
- });
- const logout = () => {
- signout();
- meta2d.emit('logout');
- };
- const onInputName = (e) => {
- // (meta2d.store.data as Meta2dBackData).name = data.name;
- setMeta2dData({ name: e.target.value });
- setDot(true);
- };
- const initMeta2dName = () => {
- data.name = (meta2d.store.data as Meta2dBackData).name || '';
- setMeta2dData({ name: (meta2d.store.data as Meta2dBackData).name || $t('新建项目') });
- };
- let downloadList = new Set<any>();
- let downloadZip3dList:any[] = [];
- let iframeNum = 0;
- let compareNum = 0;
- const prePayList = reactive({
- pngs: new Set<string>(),
- jsPens: new Set<string>(),
- iotPens: new Set<string>(),
- svgPens: new Set<string>(),
- });
- let payListNum = 0;
- let comparePayListNum = 0;
- // let purchasedList = []; //已购买列表
- const iotPensMap = {};
- let downloadType: Frame = null;
- // const payPrice = ref(0);
- const getIotPensMap = () => {
- formComponents.forEach((item) => {
- item.list.forEach((_item) => {
- iotPensMap[_item.data.name] = { name: _item.name, icon: _item.icon };
- });
- });
- };
- nextTick(() => {
- meta2d.on('opened', initMeta2dName);
- window.addEventListener('message', dealWithMessage);
- getIotPensMap();
- });
- const dealWithMessage = async (e) => {
- if (
- typeof e.data !== 'string' ||
- !e.data ||
- e.data.startsWith('setImmediate')
- ) {
- return;
- }
- try {
- let data = JSON.parse(e.data);
- if (typeof data === 'object') {
- if (data.type) {
- if (data.name === 'download') {
- let list = data.data;
- if(downloadType === Frame.zip){
- compareNum += 1;
- downloadZip3dList = [...downloadZip3dList, ...list];
- if (compareNum >= iframeNum) {
- doDownloadZip();
- }
-
- }else{
- let folderName =downloadType===Frame.vue3?'meta2d-vue3':downloadType===Frame.vue2?'meta2d-vue2': 'meta2d-react';
- list.forEach((item) => {
- // if(item.path.startsWith('/meta3d/')){
- // item.path = `/${folderName}/public/${item.path}`;
- // }
- if(item.path.startsWith('/vue3/')||item.path.startsWith('/vue2/')||item.path.startsWith('/react/')){
- item.path = item.path.replace('vue3',folderName).replace('vue2',folderName).replace('react',folderName);
- }
- });
- downloadList = new Set([...downloadList, ...list]);
- compareNum += 1;
- if (compareNum >= iframeNum) {
- saveDownload();
- }
- }
- } else if (data.name === 'payList') {
- prePayList.pngs = new Set([...prePayList.pngs, ...data.data.pngs]);
- prePayList.jsPens = new Set([
- ...prePayList.jsPens,
- ...data.data.jsPens,
- ]);
- prePayList.iotPens = new Set([
- ...prePayList.iotPens,
- ...data.data.iotPens,
- ]);
- prePayList.svgPens = new Set([
- ...prePayList.svgPens,
- ...data.data.svgPens,
- ]);
- comparePayListNum += 1;
- if (comparePayListNum >= payListNum) {
- // await showPayListDialog();
- }
- }
- // else if(data.name==='saveas'){
- // await autoSaveAS(data.id);
- // }
- } else {
- // meta2d.emit(data.name);
- }
- } else {
- // meta2d.emit(data);
- }
- } catch (e) {
- console.info(e);
- }
- };
- onUnmounted(() => {
- meta2d.off('opened', initMeta2dName);
- window.removeEventListener('message', dealWithMessage);
- });
- const login = () => {
- if(import.meta.env.BASE_URL.startsWith('/') ){
- return `${enterprise['account']}?cb=${encodeURIComponent(location.href)}`;
- }else{
- return `https://account${rootDomain}/login?cb=${encodeURIComponent(location.href)}`;
- }
- };
- function load(isNew = false) {
- const input = document.createElement('input');
- input.type = 'file';
- input.onchange = (event) => {
- const elem = event.target as HTMLInputElement;
- if (elem.files && elem.files[0]) {
- // 路由跳转 可能在 openFile 后执行
- if (elem.files[0].name.endsWith('.json')) {
- blank();
- openJson(elem.files[0]);
- if (isNew) {
- router.push({
- path: '/',
- query: {
- r: Date.now() + '',
- },
- });
- }
- } else if (elem.files[0].name.endsWith('.svg')) {
- MessagePlugin.info(
- $t('可二次编辑但转换存在损失,若作为图片使用,请使用右侧属性面板的上传图片功能')
- );
- openSvg(elem.files[0]);
- } else if (elem.files[0].name.endsWith('.zip')) {
- blank();
- if(isNew){
- router.push({
- path: '/',
- query: {
- r: Date.now() + '',
- },
- });
- }
- setTimeout(() => {
- openZip(elem.files[0]);
- }, 500);
- } else {
- MessagePlugin.info($t('打开文件只支持 json,svg,zip 格式'));
- }
- }
- };
- input.click();
- }
- async function importDxf(){
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- // if (!user.vip) {
- // MessagePlugin.info('需要开通会员~');
- // gotoAccount();
- // return;
- // }
- const input = document.createElement('input');
- input.type = 'file';
- input.onchange = async (event) => {
- const elem:any = event.target;
- if (elem.files && elem.files[0]) {
- // 路由跳转 可能在 openFile 后执行
- if (elem.files[0].name.endsWith('.DXF') ||elem.files[0].name.endsWith('.dxf') ) {
- const dataObj = elem.files[0]
- if (dataObj) {
- const reader = new FileReader();
- reader.readAsText(dataObj, "UTF-8")
- reader.addEventListener(
- "load",
- async () => {
- // 然后这将显示一个文本文件
- const parser = new D2M({
- scale: 10
- },(e)=>{
- console.error('error',e)
- })
- const res = await parser.load(dataObj)
- if(res.success.length > 0 ){
- const pens = await meta2d.addPens((res.success));
- meta2d.gotoView(pens[Math.floor(pens.length / 2)])
- }
- },
- false,
- );
- }
- }
- }
- };
- input.click();
- }
- function importVisio() {
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- // if (!user.isVip) {
- // gotoAccount();
- // return;
- // }
- // if (!user.vip) {
- // MessagePlugin.info('需要开通会员~');
- // gotoAccount();
- // return;
- // }
- const input = document.createElement('input');
- input.type = 'file';
- input.onchange = async (event) => {
- const elem:any = event.target;
- if (elem.files && elem.files[0]) {
- if (elem.files[0].name.endsWith('.vsdx')) {
- MessagePlugin.loading("文件正在加载中")
- const dataObj = elem.files[0]
- if (dataObj) {
- let factory = new V2M({
- ellipsis:false
- },(e)=>{
- MessagePlugin.closeAll();
- MessagePlugin.error("文件加载失败,请检查文件是否正确(vsdx)")
- });
- factory.addGraphMap('Separator',{name:'rectangle'})
- factory.addGraphMap('CFF Container',{name:'rectangle'})
- const res = await factory.load(dataObj)
- if(res.length > 0 ){
- for (const page of res) {
- const pens = await meta2d.addPens(deepClone(page.pens));
- meta2d.combine(pens)
- if(page.unmatch.length > 0){
- const unMatchList = page.unmatch.map(i=>i.origin.name).join(',');
- }
- pens.forEach((p)=>{
- if(p.children.length > 0){
- meta2d.pushChildren(p,p.children.map((c)=>meta2d.findOne(c)))
- }
- })
- }
- meta2d.centerView()
- }
- }
- MessagePlugin.closeAll();
- MessagePlugin.success("加载成功")
- }else {
- MessagePlugin.info("仅支持vsdx文件")
- }
- };
- }
- input.click();
- }
- const openJson = async (file: File) => {
- const text = await readFile(file);
- try {
- let data: Meta2dBackData = JSON.parse(text);
- if (!data.name) {
- data.name = file.name.replace('.json', '');
- }
- if (!data.version || compareVersion(data.version, baseVer) === -1) {
- // 如果版本号不存在或者版本号 version < 1.0.0
- data = upgrade(data, baseVer);
- }
- dealwithFormatbeforeOpen(data);
- for (const k of delAttrs) {
- delete (data as any)[k];
- }
- if(!data.background){
- data.background = '#1e2430';
- }
- if(!data.color){
- data.color = '#bdc7db';
- }
- dealDataBeforeOpen(data);
- if(!(data as any).oldV){
- if(!data.width){data.width= 1920};
- if(!data.height){data.height= 1080};
- }
- meta2d.open(data);
- } catch (e) {
- console.error(e);
- }
- };
- const openSvg = async (file: File) => {
- const text = await readFile(file);
- const pens: Pen[] = parseSvg(text);
- if(pens.length){
- if(pens[0].width>100||pens[0].height>100){
- if(pens[0].width>pens[0].height){
- pens[0].height = pens[0].height/pens[0].width*100;
- pens[0].width = 100;
- }else{
- pens[0].width = pens[0].width/pens[0].height*100;
- pens[0].height = 100;
- }
- }
- }
- meta2d.canvas.addCaches = pens;
- MessagePlugin.info($t('svg转换成功,请点击画布决定放置位置'));
- };
- const openZip = async (file: File) => {
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- // if (!user.isVip) {
- // gotoAccount();
- // return;
- // }
- // if (!user.vip) {
- // MessagePlugin.info($t('需要开通会员~'));
- // gotoAccount();
- // return;
- // }
- MessagePlugin.loading($t('正在读取...'),0);
- const { default: JSZip } = await import('jszip');
- const zip = new JSZip();
- await zip.loadAsync(file,{base64:true});
- let fileName = file.name.slice(0, -4)
- let dataStr = '';
- for (const key in zip.files) {
- if (zip.files[key].dir) {
- continue;
- }
- if (key.endsWith('.json')) {
- // 认为只有一个 json 文件
- dataStr = await zip.file(key).async('string');
- break;
- }
- }
- if (!dataStr) {
- return false;
- }
- const imgReplaceArr = [];
- const _2dDataMap ={};
- const _3dDataMap ={};
- MessagePlugin.loading($t('正在上传文件...'),0);
- for (const key in zip.files) {
- if (zip.files[key].dir) {
- continue;
- }
- let _keyLower = key.toLowerCase();
- if (
- _keyLower.endsWith('.png') ||
- _keyLower.endsWith('.svg') ||
- _keyLower.endsWith('.gif') ||
- _keyLower.endsWith('.jpg') ||
- _keyLower.endsWith('.jpeg')
- ) {
- let filename = key.substr(key.lastIndexOf('/') + 1);
- // 上传文件
- const form = new FormData();
- form.append('name', filename);
- form.append('directory', '/大屏/图片/默认');
- form.append('shared', true + '');
- form.append('file', await zip.file(key).async('blob'));
- form.append('conflict', 'new');
- const result: any = await axios.post('/api/image/upload', form);
- let arr = key.split('/');
- arr.shift();
- if(arr[0]===fileName){
- arr.shift();
- }
- let _key ='/'+ arr.join('/');
- if (result) {
- imgReplaceArr.push({ key: _key, url: result.url });
- }
- }else if(_keyLower.endsWith('.json')){
- let arr = key.split('/');
- arr.shift();
- if(arr[0]===fileName){
- arr.shift();
- }
- let data = await zip.file(key).async('string');
- if(!arr[0].endsWith('.json')){
- _2dDataMap[arr[0]] = data;
- }
- }else{
- // console.log("key",key);
- if(key.indexOf('3d')!==-1&&key.indexOf('files/')===-1){
- let id_3d = await load3d(zip,key);
- if(id_3d){
- // dataStr = dataStr.replaceAll(key, id_3d);
- let originId = key.split('3d-')[1];
- _3dDataMap[originId] = id_3d;
- }
- }
- }
- }
- //替换2d图片数据
- imgReplaceArr.forEach((item) => {
- dataStr = dataStr.replaceAll(item.key, item.url);
- for (let key in _2dDataMap) {
- _2dDataMap[key] = _2dDataMap[key].replaceAll(item.key, item.url);
- }
- });
- try {
- let domain = location.origin+ '/view';
- let data: Meta2dBackData = JSON.parse(dataStr);
- for(let i=0;i<data.pens.length;i++){
- const pen = data.pens[i];
- if(pen.name==='iframe'){
- let url = pen.iframe.split('?')[1]
- let params = queryURLParams(url);
- if(pen.iframe.indexOf('/2d/')!==-1 || pen.iframe.indexOf('/v/')!==-1 || pen.iframe.indexOf('/2d?')!==-1 ||pen.iframe.indexOf('/v?')!==-1){
- const idata = JSON.parse(_2dDataMap[params.id]);
- const ret:any = await addCollection('v',{
- data:idata,
- image:idata.image||'xxx',
- name:idata.name||$t('新建项目'),
- folder:idata.folder,
- // userFlag:2,
- system:false,
- case:idata.case,
- });
- if(!ret){
- continue;
- }
- pen.iframe = `${domain}/v/?id=${ret.id}`;
- }else if(pen.iframe.indexOf('/3d')!==-1){
- pen.iframe = `${domain}/3d/?id=${_3dDataMap[params.id]}`;
- }
- }
- }
- if (data) {
- if (!data.name) {
- data.name = file.name.replace('.zip', '');
- }
- if (!data.version || compareVersion(data.version, baseVer) === -1) {
- // 如果版本号不存在或者版本号 version < 1.0.0
- data = upgrade(data, baseVer);
- }
- dealwithFormatbeforeOpen(data);
- const delAttrs = [
- 'userId',
- 'shared',
- 'team',
- 'owner',
- 'username',
- 'editor',
- 'editorId',
- 'editorName',
- 'createdAt',
- 'folder',
- 'image',
- 'id',
- '_id',
- 'view',
- 'updatedAt',
- 'star',
- 'recommend',
- ];
- for (const k of delAttrs) {
- delete (data as any)[k];
- }
- if(!data.background){
- data.background = '#1e2430';
- }
- if(!data.color){
- data.color = '#bdc7db';
- }
- if(!data.width){data.width= 1920};
- if(!data.height){data.height= 1080};
- dealDataBeforeOpen(data)
- meta2d.open(data);
- MessagePlugin.closeAll();
- MessagePlugin.success($t('导入成功!'));
- }
- } catch (e) {
- return false;
- }
- };
- const _openZip = async (file: File) => {
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- // if (!user.isVip) {
- // gotoAccount();
- // return;
- // }
- // if (!user.vip) {
- // MessagePlugin.info($t('需要开通普通会员~'));
- // gotoAccount();
- // return;
- // }
- const { default: JSZip } = await import('jszip');
- const zip = new JSZip();
- await zip.loadAsync(file,{base64:true});
- let fileName = file.name.slice(0, -4)
- let dataStr = '';
- for (const key in zip.files) {
- if (zip.files[key].dir) {
- continue;
- }
- if (key.endsWith('.json')) {
- // 认为只有一个 json 文件
- dataStr = await zip.file(key).async('string');
- break;
- }
- }
- if (!dataStr) {
- return false;
- }
- for (const key in zip.files) {
- if (zip.files[key].dir) {
- continue;
- }
- // let _png = key.indexOf('/png');
- // let _img = key.indexOf('/img');
- // let _image = key.indexOf('/image');
- // let _file = key.indexOf('/file');
- let _keyLower = key.toLowerCase();
- // if (!key.endsWith('.json') && (_png !== -1 || _img !== -1 || _image !== -1 || _file !== -1)) {
- if (
- _keyLower.endsWith('.png') ||
- _keyLower.endsWith('.svg') ||
- _keyLower.endsWith('.gif') ||
- _keyLower.endsWith('.jpg') ||
- _keyLower.endsWith('.jpeg')
- ) {
- let filename = key.substr(key.lastIndexOf('/') + 1);
- const extPos = filename.lastIndexOf('.');
- let ext = '';
- if (extPos > 0) {
- ext = filename.substr(extPos);
- }
- filename = filename.substring(0, extPos > 8 ? 8 : extPos);
- // 上传文件
- const result: any = await upload(
- await zip.file(key).async('blob'),
- true,
- filename + ext
- );
- let arr = key.split('/');
- arr.shift();
- if(arr[0]===fileName){
- arr.shift();
- }
- let _key ='/'+ arr.join('/');
- // if (_png) {
- // _key = key.substring(_png);
- // } else if (_image) {
- // _key = key.substring(_png);
- // } else if (_img) {
- // _key = key.substring(_img);
- // } else if (_file) {
- // _key = key.substring(_file);
- // }
- if (result) {
- if (dataStr.replaceAll) {
- //'le5le.meta2d'
- dataStr = dataStr.replaceAll(_key, result.url);
- } else {
- while (dataStr.includes(_key)) {
- dataStr = dataStr.replace(_key, result.url);
- // 正则 gm 在特殊情况下报错,例如如下场景
- /**
- *
- const data = '{"image":"/image/materials/IoT-Chemical(化学)/Air stripper 2(汽提塔2).svg"}';
- const key = '/image/materials/IoT-Chemical(化学)/Air stripper 2(汽提塔2).svg';
- data.replace(key, '123');
- data.replaceAll(key, '123')
- data.replace(new RegExp(key, 'gm'), '123');
- data.replace(new RegExp(key, 'g'), '123');
- */
- }
- }
- }
- }
- }
- try {
- let data: Meta2dBackData = JSON.parse(dataStr);
- if (data) {
- if (!data.name) {
- data.name = file.name.replace('.zip', '');
- }
- if (!data.version || compareVersion(data.version, baseVer) === -1) {
- // 如果版本号不存在或者版本号 version < 1.0.0
- data = upgrade(data, baseVer);
- }
- dealwithFormatbeforeOpen(data);
- const delAttrs = [
- 'userId',
- 'shared',
- 'team',
- 'owner',
- 'username',
- 'editor',
- 'editorId',
- 'editorName',
- 'createdAt',
- 'folder',
- 'image',
- 'id',
- '_id',
- 'view',
- 'updatedAt',
- 'star',
- 'recommend',
- ];
- for (const k of delAttrs) {
- delete (data as any)[k];
- }
- if(!data.background){
- data.background = '#1e2430';
- }
- if(!data.color){
- data.color = '#bdc7db';
- }
- if(!data.width){data.width= 1920};
- if(!data.height){data.height= 1080};
- meta2d.open(data);
- }
- } catch (e) {
- return false;
- }
- };
- const downloadJson = () => {
- const data: Meta2dBackData = meta2d.data();
- if (data._id) delete data._id;
- if (data.id) delete data.id;
- checkData(data);
- import('file-saver').then(({ saveAs }) => {
- saveAs(
- new Blob(
- [JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')],
- {
- type: 'text/plain;charset=utf-8',
- }
- ),
- `${data.name || 'le5le.meta2d'}.json`
- );
- });
- };
- const downloadZip = async () => {
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- // if (!user.isVip) {
- // // gotoAccount();
- // return;
- // }
- if(!meta2d.store.data.pens.length){
- MessagePlugin.info($t('画布没有画笔!'));
- return;
- }
- // if (!user.vip) {
- // MessagePlugin.info('需要开通会员~');
- // gotoAccount();
- // return;
- // }
- //提前存储iframe嵌入2d数据
- downloadType = Frame.zip;
- downloadZip3dList = [];
- data.zips = {};
- const pen_pay = meta2d.store.data.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`/2d/`) !== -1 ||
- pen.iframe.indexOf('/2d?') !== -1 ||
- pen.iframe.indexOf(`/v/`) !== -1 ||
- pen.iframe.indexOf('/v?') !== -1)
- );
- if (pen_pay && pen_pay.length) {
- for(let i=0;i<pen_pay.length;i++){
- // pen_pay.forEach(async(pen) => {
- const pen = pen_pay[i];
- let arr = pen.iframe.split('?');
- let params = queryURLParams(arr[1]);
- if(params.id){
- if(arr[0].indexOf('2d') !== -1 ){
- const ret: any = await axios.post('/api/data/2d/get', {
- id:params.id
- });
- if(ret.data){
- let payList = getPayList(ret.data);
- // payList.pngs.forEach(item => pngs.add(item));
- ret.data.name = ret.name;
- data.zips[params.id] = {
- data:ret.data,
- pngs:payList.pngs
- }
- }
- }else if(arr[0].indexOf('v') !== -1){
- const ret: any = await axios.post('/api/data/v/get', {
- id:params.id
- });
- if(ret.data){
- let payList = getPayList(ret.data);
- // payList.pngs.forEach(item => pngs.add(item));
- ret.data.name = ret.name;
- data.zips[params.id] = {
- data:ret.data,
- pngs:payList.pngs
- }
- }
- }
- }
- // })
- }
- }
- preDoDownloadZip();
- return;
- // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
- // const [{ default: JSZip }, { saveAs }] = await Promise.all([
- // import('jszip'),
- // import('file-saver'),
- // ]);
- // const zip: any = new JSZip();
- // const data: Meta2dBackData = meta2d.data();
- // let _fileName =
- // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
- // 'le5le.meta2d';
- // const _zip = zip.folder(`${_fileName}`);
- // if (data._id) delete data._id;
- // if (data.id) delete data.id;
- // checkData(data);
- // _zip.file(
- // `${_fileName}.json`,
- // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
- // );
- // await zipBkImg(_zip);
- // await zipImages(_zip, meta2d.store.data.pens);
- // const blob = await zip.generateAsync({ type: 'blob' });
- // saveAs(blob, `${_fileName}.zip`);
- };
- const preDownloadZip =async () =>{
- const meta2dData = meta2d.data();
- let payList = getPayList(meta2dData);
- let purchased =await getComponentPurchased({
- pngs: payList.pngs,
- jsPens: [],
- iotPens: [],
- svgPens: [],
- });
- downloadZipDialog.checked = true;
- if(payList.jsPens.length||payList.iotPens.length||payList.svgPens.length){
- downloadZipDialog.hasJs = true;
- }else{
- downloadZipDialog.hasJs = false;
- }
- let names = purchased.map((item) => item.name);
- data.goods = await getGoods();
- let list = payList.pngs.filter((item) => !names.includes(item));
- if(!list.length){
- doDownloadZip();
- }else{
- let unitPrice = data.goods.find((item)=>item.type==='图片图元').unitPrice;
- downloadZipDialog.price = unitPrice*list.length;
- downloadZipDialog.show = true;
- downloadZipDialog.list = list;
- }
- }
- // const prePayDownloadZip = async ()=>{
- // if(downloadZipDialog.checked){
- // const res: any = await axios.post('/api/order/deployment/submit', {
- // goods:{},
- // '2ds':downloadZipDialog.list.map((item)=>{return { type: '图片图元', name: item}}),
- // });
- // wechatPayDialog.show = true;
- // wechatPayDialog.isZip = true;
- // data.order = res;
- // }else {
- // doDownloadZip();
- // }
- // }
- const preDoDownloadZip = async ()=>{
- const meta2dData:any = meta2d.data();
- const pen_3d = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1||
- pen.iframe.indexOf(`/view/3d`) !== -1 //安装包
- ));
- if (pen_3d && pen_3d.length) {
-
- pen_3d.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name: 'deployAsZip',
- // id: params.id,
- type: 1,
- path: `3d-${params.id}`,
- }),
- '*'
- );
- // pen.iframe = `/view?data=3d-${params.id}`;
- });
- }else{
- doDownloadZip();
- }
- }
- const doDownloadZip = async ()=>{
- // downloadZipDialog.show = false;
- MessagePlugin.info($t('正在下载打包中,可能需要几分钟,请耐心等待...'),0);
- const [{ default: JSZip }, { saveAs }] = await Promise.all([
- import('jszip'),
- import('file-saver'),
- ]);
- const zip: any = new JSZip();
- const _data: Meta2dBackData = meta2d.data();
- let _fileName =
- (_data.name && _data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
- 'le5le.meta2d';
- const _zip = zip.folder(`${_fileName}`);
- let list = getDownloadZipList(_data,data.zips);
- await Promise.all(
- [...list,...downloadZip3dList].map(async (item: any) => {
- if (item.url) {
- //接口请求
- try{
- let url = item.url.startsWith('/')?(cdn+item.url):item.url;
- if(url.includes('?')){
- url = url + `&r=${Date.now()}`;
- }else{
- url = url + `?r=${Date.now()}`;
- }
- const res: Blob = await axios.get(url, {
- responseType: 'blob',
- });
- let path = item.path.split('?')[0];
- if(path.startsWith('/')){
- path = path.slice(1);
- }
- _zip.file(path, res, { createFolders: true });
- }catch(e){
- console.log(e);
- }
- } else if (item.data) {
- //直接写数据
- let path = item.path;
- if(path.startsWith('/')){
- path = path.slice(1);
- }
- _zip.file(path, item.data, { createFolders: true });
- }
- })
- );
- const blob = await zip.generateAsync({ type: 'blob' });
- saveAs(blob, `${_fileName}.zip`);
- MessagePlugin.closeAll();
- MessagePlugin.success($t('下载成功,请在浏览器下载列表中查看'));
- // downloadZipDialog.show = false;
- // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
- // const [{ default: JSZip }, { saveAs }] = await Promise.all([
- // import('jszip'),
- // import('file-saver'),
- // ]);
- // const zip: any = new JSZip();
- // const data: Meta2dBackData = meta2d.data();
- // let _fileName =
- // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
- // 'le5le.meta2d';
- // const _zip = zip.folder(`${_fileName}`);
- // if (data._id) delete data._id;
- // if (data.id) delete data.id;
- // checkData(data);
- // _zip.file(
- // `${_fileName}.json`,
- // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
- // );
- // await zipBkImg(_zip);
- // await zipImages(_zip, meta2d.store.data.pens);
- // const blob = await zip.generateAsync({ type: 'blob' });
- // saveAs(blob, `${_fileName}.zip`);
- }
- // const zip3D = (name: string) => {
- // const pen_3d = meta2d.store.data.pens.filter(
- // (pen) =>
- // pen.name === 'iframe' &&
- // (pen.tags.includes('meta3d') || pen.iframe.indexOf('3d') !== -1)
- // );
- // if (pen_3d && pen_3d.length) {
- // //存在3d场景
- // pen_3d.forEach((pen) => {
- // //发送消息
- // let params = queryURLParams(pen.iframe.split('?')[1]);
- // (
- // pen.calculative.singleton.div.children[0] as HTMLIFrameElement
- // ).contentWindow.postMessage(
- // JSON.stringify({
- // type: 1,
- // name,
- // id: params.id,
- // }),
- // '*'
- // );
- // });
- // }
- // };
- // const zip2D = (name: string) => {
- // const pen_2d = meta2d.store.data.pens.filter(
- // (pen) =>
- // pen.name === 'iframe' &&
- // (pen.iframe.indexOf('2d.le5le.com') !== -1 ||
- // pen.iframe.indexOf('/2d/') !== -1 ||
- // pen.iframe.indexOf('v.le5le.com') !== -1 ||
- // pen.iframe.indexOf('/v/') !== -1)
- // );
- // if (pen_2d && pen_2d.length) {
- // //存在3d场景
- // pen_2d.forEach((pen) => {
- // //发送消息
- // // let params = queryURLParams(pen.iframe.split('?')[1]);
- // (
- // pen.calculative.singleton.div.children[0] as HTMLIFrameElement
- // ).contentWindow.postMessage(
- // JSON.stringify({
- // name,
- // type: 1,
- // }),
- // '*'
- // );
- // });
- // }
- // }
- // function queryURLParams(value?: string) {
- // let url = value || window.location.href.split('?')[1];
- // const urlSearchParams = new URLSearchParams(url);
- // const params = Object.fromEntries(urlSearchParams.entries());
- // return params;
- // }
- const downloadHtml = async () => {
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- downloadType = Frame.html;
- // await preGetPayList();
- preDownload();
- };
- // const preGetPayList = async () => {
- // //图形库需要购买
- // const meta2dData = meta2d.data();
- // if(!meta2dData.pens.length){
- // MessagePlugin.info('画布没有画笔!');
- // return;
- // }
- // let list = getPayList(meta2dData);
- // prePayList.pngs = new Set(list.pngs);
- // prePayList.jsPens = new Set(list.jsPens);
- // prePayList.iotPens = new Set(list.iotPens);
- // prePayList.svgPens = new Set(list.svgPens);
- // downloadList = new Set();
- // //向iframe发送消息
- // payListNum = 0;
- // comparePayListNum = 0;
- // const pen_pay = meta2dData.pens.filter(
- // (pen) =>
- // pen.name === 'iframe' &&
- // (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
- // pen.iframe.indexOf('/2d') !== -1 || pen.iframe.indexOf('data=2d') !== -1 ||
- // pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
- // pen.iframe.indexOf(`view${rootDomain}/v`) !== -1 ||pen.iframe.indexOf('data=v') !== -1 ||
- // pen.iframe.indexOf('/preview') !== -1)
- // );
- // if (pen_pay && pen_pay.length) {
- // pen_pay.forEach((pen) => {
- // //发送消息
- // (
- // meta2d.store.pens[pen.id].calculative.singleton.div
- // .children[0] as HTMLIFrameElement
- // ).contentWindow.postMessage(
- // JSON.stringify({
- // name: 'prePayList',
- // type: 1,
- // }),
- // '*'
- // );
- // payListNum += 1;
- // });
- // }
- // if (payListNum === 0) {
- // await showPayListDialog();
- // }
- // };
- // const showPayListDialog = async () => {
- // //下载离线部署包
- // const deploys =await getDeployGoods();
- // const pen_3d = meta2d.store.data.pens.filter(
- // (pen) =>
- // pen.name === 'iframe' &&
- // (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
- // pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1)
- // );
- // const pen_2d = meta2d.store.data.pens.filter(
- // (pen) =>
- // pen.name === 'iframe' &&
- // (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
- // pen.iframe.indexOf(`view${rootDomain}/2d`) !== -1)
- // );
- // const pen_v = meta2d.store.data.pens.filter(
- // (pen) =>
- // pen.name === 'iframe' &&
- // (pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
- // pen.iframe.indexOf(`view${rootDomain}/v`) !== -1||pen.iframe.indexOf('data=v') !== -1)
- // );
- // let price = 0;
- // data.payDiagram.checked = true;
- // data.payDiagram.expend = false;
- // data.payGoods ={}
- // deploys.forEach((item) => {
- // if(item.name==="3D离线部署下载"){
- // price+=item.price*pen_3d.length;
- // if(pen_3d.length){
- // data.payGoods[item.id]=pen_3d.length;
- // }
- // }else if(item.name==="2D离线部署下载"){
- // price+=item.price*pen_2d.length;
- // if(pen_2d.length){
- // data.payGoods[item.id]=pen_2d.length;
- // }
- // }else if(item.name==="大屏离线部署下载"){
- // price+=item.price*(pen_v.length+1);
- // data.payGoods[item.id]=pen_v.length+1;
- // }
- // });
- // data.deploy.price = price;
- // //图形库
- // data.goods = await getGoods();
- // data.purchasedList = await getComponentPurchased(prePayList);
- // data.payDiagram.list =[];
- // data.payDiagram.payAll = false;
- // data.goods.forEach((goods)=>{
- // let purchased = data.purchasedList?.filter(
- // (_item) => _item.type === goods.type
- // );
- // let names = purchased.map((item) => item.name);
- // let list = [];
- // if(goods.type==='图片图元'){
- // list = [...prePayList.pngs];
- // }else if(goods.type==='JS线性图元'){
- // list = [...prePayList.jsPens];
- // }else if(goods.type==='SVG线性图元'){
- // list = [...prePayList.svgPens];
- // }else if(goods.type==='控件'){
- // list = [...prePayList.iotPens];
- // }
- // let num =0;
- // if (goods.type==='SVG线性图元'&&[...prePayList.svgPens].includes('*')) {
- // //需要购买全部
- // num = goods.count-names.length;
- // data.payDiagram.payAll = true;
- // }else{
- // list.forEach((item)=>{
- // if(!names.includes(item)){
- // if(goods.type==='控件'){
- // data.payDiagram.list.push({
- // name:item
- // });
- // }else if(goods.type==='JS线性图元'){
- // data.payDiagram.list.push({
- // svg:globalThis.jsPensMap?globalThis.jsPensMap[item]:item
- // });
- // }else{
- // data.payDiagram.list.push({
- // img:item
- // });
- // }
- // num+=1;
- // }
- // })};
- // goods.num = num;
- // })
- // price = 0;
- // data.goods.forEach((item, index) => {
- // price += item.num * item.unitPrice;
- // });
- // data.payDiagram.price = price;
- // // data.goods.forEach((item, index) => {
- // // item.checked = true;
- // // let purchased = data.purchasedList?.filter(
- // // (_item) => _item.type === item.type
- // // );
- // // if (index === 0) {
- // // item.total = [...prePayList.pngs].length;
- // // item.unPurchased = item.total - purchased.length;
- // // } else if (index === 1) {
- // // item.total = [...prePayList.iotPens].length;
- // // item.unPurchased = item.total - purchased.length;
- // // } else if (index === 3) {
- // // item.total = [...prePayList.jsPens].length;
- // // item.unPurchased = item.total - purchased.length;
- // // } else if (index === 2) {
- // // if (purchased.length === 1 && !purchased[0].name) {
- // // //说明已经购买全部 //TODO
- // // item.total = item.count;
- // // item.unPurchased = 0;
- // // } else {
- // // //需要购买全部
- // // if ([...prePayList.svgPens].includes('*')) {
- // // item.total = item.count;
- // // item.unPurchased = item.total;
- // // } else {
- // // item.total = [...prePayList.svgPens].length;
- // // item.unPurchased = item.total - purchased.length;
- // // }
- // // }
- // // }
- // // });
- // payListDialog.show = true;
- // switch (downloadType) {
- // case Frame.html:
- // payListDialog.title = '下载离线部署包';
- // 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`;
- // payListDialog.downloadUrl =img_cdn+ '/deployment/大厦电力管理系统(html).zip';
- // break;
- // case Frame.vue2:
- // payListDialog.title = '下载vue2组件包';
- // payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BDVue2%E7%BB%84%E4%BB%B6%E5%8C%85`;
- // payListDialog.downloadUrl = img_cdn+ '/deployment/大厦电力管理系统(vue2).zip';
- // break;
- // case Frame.vue3:
- // payListDialog.title = '下载vue3组件包';
- // payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BDVue3%E7%BB%84%E4%BB%B6%E5%8C%85`;
- // payListDialog.downloadUrl = img_cdn+ '/deployment/大厦电力管理系统(vue3).zip';
- // break;
- // case Frame.react:
- // payListDialog.title = '下载react组件包';
- // payListDialog.href = `https://doc${rootDomain}/document/155692631#%E4%B8%8B%E8%BD%BDReact%E7%BB%84%E4%BB%B6%E5%8C%85`;
- // payListDialog.downloadUrl = img_cdn+ '/deployment/大厦电力管理系统(react).zip';
- // break;
- // }
- // // let price = 0;
- // // if (price === 0) {
- // // skipPay(); //如果计算价格为0,直接下载
- // // } else {
- // // payListDialog.show = true;
- // // }
- // };
- const preDownload =() => {
- iframeNum = 0;
- compareNum = 0;
- const meta2dData:any = meta2d.data();
- meta2dData.userId = user.id;
- const pen_3d = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1)
- );
- if (pen_3d && pen_3d.length) {
- //存在3d场景
- if (pen_3d.length === 1) {
- let params = queryURLParams(pen_3d[0].iframe.split('?')[1]);
- meta2d.store.pens[
- pen_3d[0].id
- ].calculative.singleton.div.children[0].contentWindow.postMessage(
- JSON.stringify({
- name: 'deploy',
- // id: params.id,
- type: 1, //用于区分是系统消息
- path: `3d`,
- }),
- '*'
- );
- pen_3d[0].iframe ='view/index.html?data=3d';// '/view?data=3d';
- } else {
- pen_3d.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name: 'deploy',
- // id: params.id,
- type: 1,
- path: `3d-${params.id}`,
- }),
- '*'
- );
- pen.iframe = `view/index.html?data=3d-${params.id}`;//`/view?data=3d-${params.id}`;
- });
- }
- iframeNum += pen_3d.length;
- }
- const pen_2d = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/2d`) !== -1)
- );
- if (pen_2d && pen_2d.length) {
- //存在3d场景
- if (pen_2d.length === 1) {
- let params = queryURLParams(pen_2d[0].iframe.split('?')[1]);
- meta2d.store.pens[
- pen_2d[0].id
- ].calculative.singleton.div.children[0].contentWindow.postMessage(
- JSON.stringify({
- name: 'downloadHtml',
- id: params.id,
- type: 1,
- path: `2d`,
- }),
- '*'
- );
- pen_2d[0].iframe = '/view?data=2d';
- } else {
- pen_2d.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name: 'downloadHtml',
- // id: params.id,
- type: 1,
- path: `2d-${params.id}`,
- }),
- '*'
- );
- pen.iframe = `/view?data=2d-${params.id}`;
- });
- }
- iframeNum += pen_2d.length;
- }
- const pen_v = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/v`) !== -1||pen.iframe.indexOf('data=v') !== -1)
- );
- if (pen_v && pen_v.length) {
- //存在3d场景
- pen_v.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name: 'downloadHtml',
- // id: params.id,
- type: 1,
- path: `v-${params.id}`,
- }),
- '*'
- );
- pen.iframe = `/view?data=v-${params.id}`;
- });
- iframeNum += pen_v.length;
- }
- downloadList = getDownloadList(meta2dData,undefined);
- if (iframeNum === 0) {
- //如果没有嵌入场景
- saveDownload();
- } else {
- setTimeout(() => {
- if (compareNum < iframeNum) {
- //message阻塞/报错的情况
- saveDownload();
- }
- }, 10000);
- }
- };
- const preFrameDownload = async () => {
- iframeNum = 0;
- compareNum = 0;
- const meta2dData:any = meta2d.data();
- meta2dData.userId = user.id;
- const pen_3d = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`3d${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/3d`) !== -1)
- );
- let name_3d = (downloadType===Frame.vue3?'toVue3':downloadType===Frame.vue2?'toVue2':'toReact');
- let flag_3d = false; //标记是否存在3d场景
- if (pen_3d && pen_3d.length) {
- //存在3d场景
- if (pen_3d.length === 1) {
- let params = queryURLParams(pen_3d[0].iframe.split('?')[1]);
- meta2d.store.pens[
- pen_3d[0].id
- ].calculative.singleton.div.children[0].contentWindow.postMessage(
- JSON.stringify({
- name: name_3d,
- type: 1, //用于区分是系统消息
- path: `3d`,
- }),
- '*'
- );
- pen_3d[0].iframe = 'view/index.html?data=3d'; //'/3d?id=3d';
- } else {
- pen_3d.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name:name_3d,
- // id: params.id,
- type: 1,
- path: `3d-${params.id}`,
- }),
- '*'
- );
- pen.iframe = `view/index.html?data=-${params.id}`; //`/3d?id=3d-${params.id}`;
- });
- }
- iframeNum += pen_3d.length;
- flag_3d = true;
- }
- const pen_2d = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`2d${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/2d`) !== -1)
- );
- let name_2d = (downloadType===Frame.vue3?'downloadVue3':downloadType===Frame.vue2?'downloadVue2':'downloadReact');
- if (pen_2d && pen_2d.length) {
- //存在3d场景
- if (pen_2d.length === 1) {
- let params = queryURLParams(pen_2d[0].iframe.split('?')[1]);
- meta2d.store.pens[
- pen_2d[0].id
- ].calculative.singleton.div.children[0].contentWindow.postMessage(
- JSON.stringify({
- name: name_2d,
- id: params.id,
- type: 1,
- path: `2d`,
- }),
- '*'
- );
- pen_2d[0].iframe = '/2d?id=2d';
- } else {
- pen_2d.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name:name_2d,
- // id: params.id,
- type: 1,
- path: `2d-${params.id}`,
- }),
- '*'
- );
- pen.iframe = `/2d?id=2d-${params.id}`;
- });
- }
- iframeNum += pen_2d.length;
- }
- const pen_v = meta2dData.pens.filter(
- (pen) =>
- pen.name === 'iframe' &&
- (pen.iframe.indexOf(`v${rootDomain}`) !== -1 ||
- pen.iframe.indexOf(`view${rootDomain}/v`) !== -1||pen.iframe.indexOf('data=v') !== -1||pen.iframe.indexOf('/preview') !== -1)
- );
- if (pen_v && pen_v.length) {
- //存在大屏场景
- pen_v.forEach((pen) => {
- //发送消息
- let params = queryURLParams(pen.iframe.split('?')[1]);
- (
- meta2d.store.pens[pen.id].calculative.singleton.div
- .children[0] as HTMLIFrameElement
- ).contentWindow.postMessage(
- JSON.stringify({
- name: name_2d,
- // id: params.id,
- type: 1,
- path: `v-${params.id}`,
- }),
- '*'
- );
- pen.iframe = `/2d?id=v-${params.id}`;
- });
- iframeNum += pen_v.length;
- }
- downloadList = getFrameDownloadList(meta2dData,undefined,downloadType,flag_3d);
- if (iframeNum === 0) {
- //如果没有嵌入场景
- saveDownload();
- } else {
- setTimeout(() => {
- if (compareNum < iframeNum) {
- //message阻塞/报错的情况
- saveDownload();
- }
- }, 10000);
- }
- }
- const saveDownload = async () => {
- const list = [...downloadList];
- //控件
- let jsPath= '';
- // let jsPensPath = '';
- switch (downloadType) {
- case Frame.html:
- jsPath = '/view/js/2d-components.js';
- // jsPensPath = `/view/js/1.js`;
- break;
- case Frame.vue2:
- jsPath = '/meta2d-vue2/public/js/2d-components.js';
- // jsPensPath = `/meta2d-vue2/public/js/1.js`;
- break;
- case Frame.vue3:
- jsPath = '/meta2d-vue3/public/js/2d-components.js';
- // jsPensPath = `/meta2d-vue3/public/js/1.js`;
- break;
- case Frame.react:
- jsPath = '/meta2d-react/public/js/2d-components.js';
- // jsPensPath = `/meta2d-react/public/js/1.js`;
- break;
- }
- // list.push({
- // url: '/view/js/2d-components.js', //需要购买
- // path: jsPath,
- // });
- // const js = await get2dComponentJs([...prePayList.iotPens]);
- // list.push({
- // data: js,
- // path:jsPath,
- // });
- ///png图形库
- // const pngs = await getTemPngs([...prePayList.pngs]);
- // list.forEach((item) => {
- // if(item.url){
- // let url =item.url.replace(img_cdn, '').replace(img_upCdn, '')
- // if (pngs[url]) {
- // item.url = pngs[url];
- // }
- // }
- // });
- //js线性图元
- // const res: any = await axios.post('/api/paid/2d/component?pageSize=1000', {
- // type: 'JS线性图元',
- // });
- // let purchased = res.list.map((item) => item.name);
- // let arr = [];
- // [...prePayList.jsPens].forEach((item) => {
- // if(purchased.includes(item)){
- // arr.push(item);
- // }
- // });
- // const res_list: Blob = await axios.post(
- // '/api/2d/tools',
- // {
- // list: arr.map((item) => {
- // return {
- // type: 'JS线性图元',
- // name: item,
- // };
- // }),
- // },
- // {
- // responseType: 'blob',
- // }
- // );
- // list.push({
- // data: res_list,
- // path: jsPensPath,
- // });
- //SVG线性图元
- // if ([...prePayList.svgPens].length) {
- // // let purchased = data.purchasedList?.filter(
- // // (_item) => _item.type === 'SVG线性图元'
- // // );
- // const res: any = await axios.post('/api/paid/2d/component?pageSize=1000', {
- // type: 'SVG线性图元',
- // });
- // let purchased = res.list;
- // let count = data.goods.find((item) => item.type === 'SVG线性图元').count;
- // if(purchased.length === count){
- // // if (purchased.length === 1 && !purchased[0].name) {
- // //已经购买全部
- // list.forEach((item) => {
- // if (item.data &&
- // (item.path.indexOf('/projects/2d') !== -1 || item.path.indexOf('/projects/v') !== -1 || item.path.indexOf('/public/json')!==-1) &&
- // item.path.indexOf('/projects/v/png/') === -1 && item.path.indexOf('/projects/2d/png/') === -1) {
- // //清空所有svgpath
- // let meta2dData = JSON.parse(item.data);
- // for (let key of Object.keys(meta2dData.paths)) {
- // let path = meta2dData.paths[key];
- // if (
- // path.indexOf('-1.18Zm4-1') !== -1 ||
- // path.indexOf('-1.19Zm4-1') !== -1 ||
- // path.indexOf('2.85ZM') !== -1 ||
- // path.indexOf('-1-2.39.3') !== -1
- // ) {
- // meta2dData.paths[key] = '';
- // }
- // }
- // item.data = JSON.stringify(meta2dData);
- // }
- // });
- // } else {
- // let svgnames = purchased.map(i=>i.name);
- // list.forEach((item) => {
- // if (
- // item.data &&
- // (item.path.indexOf('/projects/2d') !== -1 || item.path.indexOf('/projects/v') !== -1 || item.path.indexOf('/public/json')!==-1) &&
- // item.path.indexOf('/projects/v/png/') === -1 && item.path.indexOf('/projects/2d/png/') === -1
- // ) {
- // //2d 图纸数据
- // let meta2dData = JSON.parse(item.data);
- // meta2dData.pens.forEach((pen) => {
- // if (pen.name === 'svgPath' && pen.svgUrl) {
- // if (svgnames.includes(pen.svgUrl.replace(img_cdn, ''))) {
- // pen.pathId = null;
- // }
- // }
- // });
- // item.data = JSON.stringify(meta2dData);
- // }
- // });
- // }
- // }
- //开始下载list
- const [{ default: JSZip }, { saveAs }] = await Promise.all([
- import('jszip'),
- import('file-saver'),
- ]);
- const zip = new JSZip();
- await Promise.all(
- list.map(async (item: any) => {
- if (item.url) {
- //接口请求
- try{
- const res: Blob = await axios.get(item.url.startsWith('/')?(cdn+item.url):item.url, {
- responseType: 'blob',
- });
- let path = item.path.split('?')[0];
- if(path.startsWith('/')){
- path = path.slice(1);
- }
- zip.file(path, res, { createFolders: true });
- }catch(e){
- console.log(e);
- }
- } else if (item.data) {
- //直接写数据
- let path = item.path;
- if(path.startsWith('/')){
- path = path.slice(1);
- }
- zip.file(path, item.data, { createFolders: true });
- }
- })
- );
- let _fileName =
- (meta2d.store.data.name &&
- meta2d.store.data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
- 'le5le.meta2d';
- const blob = await zip.generateAsync({ type: 'blob' });
- saveAs(blob, `${_fileName}.zip`);
- MessagePlugin.closeAll();
- MessagePlugin.success($t('下载成功,请在浏览器下载列表中查看'));
- };
- // const _downloadHtml = async () => {
- // if (!(user && user.id)) {
- // MessagePlugin.warning(noLoginTip);
- // return;
- // }
- // // if (!user.isVip) {
- // // gotoAccount();
- // // return;
- // // }
- // if (user.vipDesc !== '超级会员' && user.vipDesc !== '旗舰会员') {
- // MessagePlugin.info('需要开通超级会员~');
- // gotoAccount();
- // return;
- // }
- // frameFlag = -1;
- // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
- // const data: Meta2dBackData = meta2d.data();
- // if (data._id) delete data._id;
- // if (data.id) delete data.id;
- // if (data.image) delete data.image;
- // checkData(data);
- // const [{ default: JSZip }, { saveAs }] = await Promise.all([
- // import('jszip'),
- // import('file-saver'),
- // ]);
- // const zip = new JSZip();
- // let _fileName =
- // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
- // 'le5le.meta2d';
- // //处理cdn图片地址
- // const _zip: any = zip.folder(`${_fileName}`);
- // _zip.file(
- // 'data.json',
- // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
- // );
- // await Promise.all([
- // zipBkImg(_zip),
- // zipImages(_zip, meta2d.store.data.pens),
- // zipFiles(_zip),
- // ]);
- // const blob = await zip.generateAsync({ type: 'blob' });
- // saveAs(blob, `${_fileName}.zip`);
- // };
- // async function zipBkImg(zip: JSZip) {
- // let img = meta2d.store.data.bkImage;
- // if (img) {
- // if (img.startsWith('/') || img.startsWith(cdn) || img.startsWith(upCdn)) {
- // const pngs = await getTemPngs([img.replace(cdn, '').replace(upCdn, '')]);
- // await zipImage(zip, img, pngs[img.replace(cdn, '').replace(upCdn, '')]);
- // }
- // }
- // }
- // enum Frame {
- // vue2,
- // vue3,
- // react,
- // html
- // }
- const downloadVue3 = async () => {
- downloadAsFrame(Frame.vue3);
- };
- const downloadVue2 = async () => {
- downloadAsFrame(Frame.vue2);
- };
- const downloadReact = async () => {
- downloadAsFrame(Frame.react);
- };
- async function downloadAsFrame(type: Frame) {
- if (!(user && user.id)) {
- MessagePlugin.warning(noLoginTip);
- return;
- }
- // if (user.vipDesc !== '旗舰会员') {
- // MessagePlugin.info('需要开通旗舰会员~');
- // gotoAccount();
- // return;
- // }
- downloadType = type;
- // await preGetPayList();
- preFrameDownload();
- }
- // const preFrameDownload = async (type: Frame) => {
- // frameFlag = type;
- // MessagePlugin.info('正在下载打包中,可能需要几分钟,请耐心等待...');
- // zip3D(
- // type === Frame.vue3 ? 'toVue3' : type === Frame.vue2 ? 'toVue2' : 'toReact'
- // );
- // zip2D(
- // type === Frame.vue3 ? 'downloadVue3' : type === Frame.vue2 ? 'downloadVue2' : 'downloadReact'
- // );
- // const data: any = meta2d.data();
- // if (data._id) delete data._id;
- // if (data.id) delete data.id;
- // if (data.image) delete data.image;
- // data.userId = user.id;
- // checkData(data);
- // const [{ default: JSZip }, { saveAs }] = await Promise.all([
- // import('jszip'),
- // import('file-saver'),
- // ]);
- // const zip = new JSZip();
- // let _fileName =
- // (data.name && data.name.replace(/\//g, '_').replace(/:/g, '_')) ||
- // 'le5le.meta2d';
- // //处理付费svg
- // if (Object.keys(data.paths).length >= 3) {
- // //简单判断有无svg图元
- // const res: any = await axios.post('/api/paid/2d/component', {
- // type: 'SVG线性图元',
- // });
- // if (res.list.length === 1 && !res.list[0].name) {
- // //已经购买全部
- // for (let key of Object.keys(data.paths)) {
- // let path = data.paths[key];
- // if (
- // path.indexOf('-1.18Zm4-1') !== -1 ||
- // path.indexOf('-1.19Zm4-1') !== -1 ||
- // path.indexOf('2.85ZM') !== -1 ||
- // path.indexOf('-1-2.39.3') !== -1
- // ) {
- // data.paths[key] = '';
- // }
- // }
- // } else {
- // //购买部分
- // let purchasedList = res.list.map((i) => i.name);
- // data.pens.forEach((pen) => {
- // if (pen.name === 'svgPath' && pen.svgUrl) {
- // if (purchasedList.includes(pen.svgUrl)) {
- // pen.pathId = null;
- // }
- // }
- // });
- // }
- // }
- // const _zip: any = zip.folder(`${_fileName}`);
- // _zip.file(
- // `${type === Frame.vue3
- // ? 'meta2d-vue3'
- // : type === Frame.vue2
- // ? 'meta2d-vue2'
- // : 'meta2d-react'
- // }/public/json/data.json`,
- // JSON.stringify(data).replaceAll(cdn, '').replaceAll(upCdn, '')
- // );
- // await Promise.all([
- // zipJs(_zip),
- // zipBkImg(_zip),
- // zipImages(_zip, meta2d.store.data.pens),
- // type === Frame.vue3
- // ? zipVue3Files(_zip)
- // : type === Frame.vue2
- // ? zipVue2Files(_zip)
- // : zipReactFiles(_zip),
- // zipIotPens(_zip),
- // ]);
- // const blob = await zip.generateAsync({ type: 'blob' });
- // saveAs(blob, `${_fileName}.zip`);
- // frameFlag = -1;
- // }
- // async function zipIotPens(zip: JSZip) {
- // //处理控件
- // const js = await get2dComponentJs();
- // zip.file(`${frameFlag === Frame.vue3
- // ? 'meta2d-vue3'
- // : frameFlag === Frame.vue2
- // ? 'meta2d-vue2'
- // : 'meta2d-react'
- // }/public/js/2d-components.js`, js, { createFolders: true });
- // const res: Blob = await axios.get('/view/js/r.js', {
- // responseType: 'blob',
- // });
- // zip.file(`${frameFlag === Frame.vue3
- // ? 'meta2d-vue3'
- // : frameFlag === Frame.vue2
- // ? 'meta2d-vue2'
- // : 'meta2d-react'
- // }/public/js/r.js`, res, { createFolders: true });
- // }
- // async function zipJs(zip: JSZip) {
- // const files = ['/view/js/marked.min.js', '/view/js/lcjs.iife.js'];
- // await Promise.all(
- // files.map(async (filePath) => {
- // const res: Blob = await axios.get(filePath, {
- // responseType: 'blob',
- // });
- // zip.file(
- // `${frameFlag === Frame.vue3
- // ? 'meta2d-vue3'
- // : frameFlag === Frame.vue2
- // ? 'meta2d-vue2'
- // : 'meta2d-react'
- // }/public` + filePath.replace('/view', ''),
- // res,
- // { createFolders: true }
- // );
- // })
- // );
- // }
- // async function _zipVue3Files(zip: JSZip) {
- // const files = [
- // '/view/js/marked.min.js',
- // '/view/js/lcjs.iife.js',
- // '/view/vue3/Meta2d.vue',
- // '/view/index.html',
- // '/view/js/meta2d.js',
- // '/view/使用说明.md',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- //新
- // async function zipVue3Files(zip: JSZip) {
- // const files = [
- // '/view/meta2d-vue3/src/components/Meta2d.vue',
- // '/view/meta2d-vue3/src/App.vue',
- // '/view/meta2d-vue3/src/main.js',
- // '/view/meta2d-vue3/src/style.css',
- // '/view/meta2d-vue3/index.html',
- // '/view/meta2d-vue3/package.json',
- // '/view/meta2d-vue3/README.md',
- // '/view/meta2d-vue3/vite.config.js',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- // async function _zipVue2Files(zip: JSZip) {
- // const files = [
- // '/view/js/marked.min.js',
- // '/view/js/lcjs.iife.js',
- // '/view/vue2/Meta2d.vue',
- // '/view/index.html',
- // '/view/js/meta2d.js',
- // '/view/使用说明.md',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- // async function zipVue2Files(zip: JSZip) {
- // const files = [
- // '/view/meta2d-vue2/src/components/Meta2d.vue',
- // '/view/meta2d-vue2/src/App.vue',
- // '/view/meta2d-vue2/src/main.js',
- // // '/view/meta2d-vue2/src/style.css',
- // '/view/meta2d-vue2/public/index.html',
- // '/view/meta2d-vue2/package.json',
- // '/view/meta2d-vue2/README.md',
- // // '/view/meta2d-vue3/vite.config.js',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- // async function _zipReactFiles(zip: JSZip) {
- // const files = [
- // '/view/js/marked.min.js',
- // '/view/js/lcjs.iife.js',
- // '/view/react/Meta2d.jsx',
- // '/view/react/Meta2d.css',
- // '/view/index.html',
- // '/view/js/meta2d.js',
- // '/view/使用说明.md',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- // async function zipReactFiles(zip: JSZip) {
- // const files = [
- // '/view/meta2d-react/src/index.css',
- // '/view/meta2d-react/src/index.js',
- // '/view/meta2d-react/src/Meta2d.css',
- // '/view/meta2d-react/src/Meta2d.jsx',
- // '/view/meta2d-react/package.json',
- // '/view/meta2d-react/README.md',
- // '/view/meta2d-react/public/index.html',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- // async function zipFiles(zip: JSZip) {
- // const files = [
- // '/view/js/marked.min.js',
- // '/view/js/lcjs.iife.js',
- // '/view/js/index.js',
- // '/view/js/meta2d.js',
- // '/view/index.html',
- // '/view/index.css',
- // '/view/favicon.ico',
- // '/view/使用说明.pdf',
- // ] as const;
- // // 文件同时加载
- // await Promise.all(files.map((filePath) => zipFile(zip, filePath)));
- // }
- // async function zipFile(zip: JSZip, filePath: string) {
- // const res: Blob = await axios.get(
- // (cdn ? cdn + '/v' : import.meta.env.BASE_URL.slice(0, -1)) + filePath,
- // {
- // responseType: 'blob',
- // }
- // );
- // zip.file(filePath.replace('/view', ''), res, { createFolders: true });
- // }
- // /**
- // * 图片放到 zip 里
- // * @param pens 可以是非具有 calculative 的 pen
- // */
- // async function zipImages(zip: JSZip, pens: Pen[]) {
- // if (!pens) {
- // return;
- // }
- // // 不止 image 上有图片, strokeImage ,backgroundImage 也有图片
- // const imageKeys = [
- // {
- // string: 'image',
- // },
- // { string: 'strokeImage' },
- // { string: 'backgroundImage' },
- // ] as const;
- // const images: string[] = [];
- // for (const pen of pens) {
- // for (const i of imageKeys) {
- // const image = pen[i.string];
- // if (image) {
- // // HTMLImageElement 无法精确控制图片格式
- // if (
- // image.startsWith('/') ||
- // image.startsWith(cdn) ||
- // image.startsWith(upCdn)
- // ) {
- // // 只考虑相对路径下的 image ,绝对路径图片无需下载
- // if (!images.includes(image)) {
- // images.push(image);
- // }
- // }
- // }
- // }
- // // 无需递归遍历子节点,现在所有的节点都在外层
- // }
- // //付费pngs
- // const pngs = await getTemPngs(images.map(i => i.replace(cdn, '').replace(upCdn, '')));
- // await Promise.all(images.map((image) => zipImage(zip, image, pngs[image.replace(cdn, '').replace(upCdn, '')])));
- // }
- // async function zipImage(zip: JSZip, image: string, temImage?: string) {
- // const res: Blob = await axios.get(temImage || image, {
- // responseType: 'blob',
- // // params: {
- // // isZip: true,
- // // },
- // });
- // zip.file(
- // (frameFlag === -1
- // ? ''
- // : `${frameFlag === Frame.vue3
- // ? 'meta2d-vue3'
- // : frameFlag === Frame.vue2
- // ? 'meta2d-vue2'
- // : 'meta2d-react'
- // }/public`) + (cdn ? image.replace(cdn, '').replace(upCdn, '') : image),
- // res,
- // {
- // createFolders: true,
- // }
- // );
- // }
- const downloadImageTips =
- $t('无法下载,宽度不合法,画布可能没有画笔/画布大小超出浏览器最大限制');
- const downloadPng = () => {
- if (!meta2d.store.data.pens.length) {
- MessagePlugin.warning(downloadImageTips);
- return;
- }
- try {
- meta2d.downloadPng();
- } catch (e) {
- MessagePlugin.warning(downloadImageTips);
- }
- };
- async function getIconDefs(url: string) {
- let res: any = await axios.get(url);
- let str = res.match(/@font-face([\s\S]*?)\}/)[1];
- str = `@font-face ${str} }`;
- return str;
- }
- const downloadSvg = async () => {
- // await import('@/assets/canvas2svg');
- for (const pen of meta2d.store.data.pens) {
- if (pen.calculative.img) {
- //重新生成绘制图片
- pen.onRenderPenRaw?.(pen);
- }
- }
- if (!C2S) {
- MessagePlugin.error($t('请先加载乐吾乐官网下的canvas2svg.js'));
- return;
- }
- const rect: any = meta2d.getRect();
- if (!isFinite(rect.width)) {
- MessagePlugin.error(downloadImageTips);
- return;
- }
- rect.x -= 10;
- rect.y -= 10;
- const ctx = new C2S(rect.width + 20, rect.height + 20);
- ctx.textBaseline = 'middle';
- ctx.strokeStyle = getGlobalColor(meta2d.store);
- for (const pen of meta2d.store.data.pens) {
- // 不使用 calculative.inView 的原因是,如果 pen 在 view 之外,那么它的 calculative.inView 为 false,但是它的绘制还是需要的
- if (!isShowChild(pen, meta2d.store) || pen.visible == false) {
- continue;
- }
- meta2d.renderPenRaw(ctx, pen, rect);
- }
- let mySerializedSVG = ctx.getSerializedSvg();
- let icon_pens = meta2d.store.data.pens.filter(
- (item) => item.iconFamily && item.icon
- );
- if (icon_pens && icon_pens.length > 0) {
- let iconList = [
- '/icon/国家电网/iconfont.css',
- '/icon/电气工程/iconfont.css',
- '/icon/通用图标/iconfont.css',
- ];
- let defsList: any = await Promise.all(
- iconList.map((item) => getIconDefs(item))
- );
- mySerializedSVG = mySerializedSVG.replace(
- '<defs/>',
- `<defs>
- <style type="text/css">
- ${defsList.join('\n')}
- </style>
- {{bk}}
- </defs>
- {{bkRect}}`
- );
- }
- /* mySerializedSVG = mySerializedSVG.replace(
- '<defs/>',
- `<defs>
- <style type="text/css">
- @font-face {
- font-family: 'ticon';
- src: url('icon/通用图标/iconfont.ttf') format('truetype');
- }
- </style>
- {{bk}}
- </defs>
- {{bkRect}}`
- );
- */
- if (meta2d.store.data.background) {
- mySerializedSVG = mySerializedSVG.replace('{{bk}}', '');
- mySerializedSVG = mySerializedSVG.replace(
- '{{bkRect}}',
- `<rect x="0" y="0" width="100%" height="100%" fill="${meta2d.store.data.background}"></rect>`
- );
- } else {
- mySerializedSVG = mySerializedSVG.replace('{{bk}}', '');
- mySerializedSVG = mySerializedSVG.replace('{{bkRect}}', '');
- }
- mySerializedSVG = mySerializedSVG.replace(/--le5le--/g, '&#x');
- const urlObject: any = (window as any).URL || window;
- const export_blob = new Blob([mySerializedSVG]);
- const url = urlObject.createObjectURL(export_blob);
- const a = document.createElement('a');
- a.setAttribute(
- 'download',
- `${(meta2d.store.data as Meta2dBackData).name || 'le5le.meta2d'}.svg`
- );
- a.setAttribute('href', url);
- const evt = document.createEvent('MouseEvents');
- evt.initEvent('click', true, true);
- a.dispatchEvent(evt);
- };
- const onUndo = () => {
- meta2d.undo();
- };
- const onRedo = () => {
- meta2d.redo();
- };
- const onCut = () => {
- meta2d.cut();
- };
- const onCopy = () => {
- meta2d.copy();
- };
- const onPaste = () => {
- meta2d.paste();
- };
- const onAll = () => {
- meta2d.activeAll();
- };
- const onDelete = () => {
- meta2d.delete();
- };
- const onToggleAnchor = () => {
- //取消连线状态
- // meta2d.store.options.disableAnchor = false;
- if (!meta2d.store.options.disableAnchor) {
- meta2d.canvas.drawingLineName && drawPen();
- meta2d.toggleAnchorMode();
- }
- };
- const onAddAnchorHand = () => {
- meta2d.addAnchorHand();
- };
- const onRemoveAnchorHand = () => {
- meta2d.removeAnchorHand();
- };
- const onToggleAnchorHand = () => {
- meta2d.toggleAnchorHand();
- };
- const onScaleUp = () => {
- const _scale = meta2d.store.data.scale + 0.1;
- meta2d.scale(_scale);
- };
- const onScaleDown = () => {
- const _scale = meta2d.store.data.scale - 0.1;
- meta2d.scale(_scale);
- };
- const autoAnchor = ref(true);
- const onAutoAnchor = () => {
- meta2d.store.options.autoAnchor = !meta2d.store.options.autoAnchor;
- autoAnchor.value = meta2d.store.options.autoAnchor;
- };
- const showAnchor = ref(false);
- const onDisableAnchor = () => {
- meta2d.store.options.disableAnchor = !meta2d.store.options.disableAnchor;
- changeDisableAnchor();
- };
- const changeDisableAnchor = () => {
- const { disableAnchor, autoAnchor } = meta2d.store.options;
- showAnchor.value = !disableAnchor || false;
- if (disableAnchor && autoAnchor) {
- // 禁用瞄点开了,需要关闭自动瞄点
- onAutoAnchor();
- }
- };
- const payListDialog = reactive({
- show: false,
- title:'',
- href:'',
- downloadUrl:''
- });
- const downloadZipDialog = reactive({
- show: false,
- checked:true,
- expend:false,
- price:0,
- list:[],
- hasJs:false,
- });
- const prePay = async () => {
- let list = [];
- let names = data.purchasedList.map((item) => item.name);
- if(data.payDiagram.checked){
- prePayList.pngs.forEach((item) => {
- if(!names.includes(item)){
- list.push({
- type: '图片图元',
- name: item,
- });
- }
- });
- prePayList.jsPens.forEach((item) => {
- if(!names.includes(item)){
- list.push({
- type: 'JS线性图元',
- name: item,
- });
- }
- });
- prePayList.iotPens.forEach((item) => {
- if(!names.includes(item)){
- list.push({
- type: '控件',
- name: item,
- });
- }
- });
- if ([...prePayList.svgPens].includes('*')) {
- list.push({
- type: 'SVG线性图元',
- });
- } else {
- prePayList.svgPens.forEach((item) => {
- if(!names.includes(item)){
- list.push({
- type: 'SVG线性图元',
- name: item,
- });
- }
- });
- }
- }
- const res: any = await axios.post('/api/order/deployment/submit', {
- goods:data.payGoods,
- '2ds':list,
- });
- wechatPayDialog.show = true;
- data.order = res;
- };
- const downloadTrial = () => {
- MessagePlugin.info($t('正在下载中,可能需要几分钟,请耐心等待...'));
- //下载试用版
- window.open(payListDialog.downloadUrl, '_blank');
- }
- const skipPay = () => {
- //跳过支付,直接下载
- MessagePlugin.info($t('正在下载打包中,可能需要几分钟,请耐心等待...'));
- if (downloadType === Frame.html) {
- preDownload();
- } else {
- preFrameDownload();
- }
- };
- const finishPay = async () => {
- // let id = data.order.id;
- // const result: { state: number } = await axios.post('/api/order/pay/state', {
- // id,
- // });
- // if (result && result.state) {
- MessagePlugin.success($t('支付成功'));
- wechatPayDialog.show = false;
- if(wechatPayDialog.isZip){
- // downloadZipDialog.show = false;
- wechatPayDialog.isZip = false;
- doDownloadZip();
- }else{
- payListDialog.show = false;
- MessagePlugin.loading($t('正在下载打包中,可能需要几分钟,请耐心等待...'),0);
- if (downloadType === Frame.html) {
- preDownload();
- } else {
- preFrameDownload();
- }
- }
- // } else {
- // MessagePlugin.error('支付失败');
- // // wechatPayDialog.show = false;
- // }
- };
- const finalPrice = computed(() => {
- let total = 0;
- let price = 0;
- data.goods.forEach((item, index) => {
- if (item.checked) {
- total += item.unPurchased;
- price += item.unPurchased * item.unitPrice;
- }
- });
- return {
- total,
- price,
- };
- });
- const wechatPayDialog = reactive({
- show: false,
- isZip:false
- });
- const emit = defineEmits(['success']);
- const onSuccess = (success: boolean) => {
- finishPay();
- emit('success', success);
- };
- const saveNewfile = async()=>{
- await save(SaveType.Save,'',true);
- // setTimeout(()=>{
- if(dot.value === false){
- newFile();
- newFileDialog.value.show = false;
- }
- // },2000);
- }
- const nosaveNewfile = ()=>{
- setDot(false);
- newFile();
- newFileDialog.value.show = false;
- }
- </script>
- <style lang="postcss" scoped>
- .app-header {
- display: flex;
- height: 40px;
- background-color: var(--color-background);
- position: relative;
- z-index: 2;
- .logo {
- display: flex;
- padding: 0 16px;
- align-items: center;
- font-size: 14px;
- font-weight: 500;
- img {
- height: 20px;
- margin-right: 6px;
- }
- }
- a {
- display: flex;
- padding: 0 8px;
- margin: 0 8px;
- align-items: center;
- color: var(--color);
- text-decoration: none;
- white-space: nowrap;
- &:hover {
- color: var(--color-primary);
- }
- svg {
- font-size: 15px;
- margin: 2px 4px 0 0;
- }
- &.active {
- background-color: var(--color-primary);
- color: #ffffff;
- }
- }
- input {
- font-size: var(--font-size);
- flex-grow: 1;
- min-width: 100px;
- background: none;
- outline: none;
- border: none;
- text-align: center;
- color: var(--color-title);
- }
- }
- .pay-box{
- background: rgba(175,202,255,0.04);
- border-radius: 4px;
- margin-bottom:24px;
- padding:20px 24px;
- position:relative;
- display:flex;
- .pay-up{
- display:flex;
- }
- :deep(.t-checkbox__label){
- font-size: 16px;
- color: #6e7b91;
- margin-left:16px;
- }
- .pay-title{
- font-size: 16px;
- color: #6e7b91;
- .t-icon{
- margin-top:-5px;
- margin-left:12px;
- }
- :deep(.t-checkbox__input){
- background:#fff0;
- }
- :deep(.t-is-checked){
- .t-checkbox__input{
- background:var(--color-primary);
- }
- }
- }
- .pay-price{
- position:absolute;
- right:24px;
- color:#4480F9;
- display:flex;
- p:nth-child(2){
- font-size: 20px;
- }
- }
- .pay-down{
- margin-top:16px;
- display:flex;
- flex-wrap:wrap;
- /* justify-content:space-between; */
- /* padding-top:24px; */
- max-height: 200px;
- overflow-y: scroll;
- &>div{
- width: 48px;
- height: 48px;
- background: #1c283b;
- border-radius: 4px;
- margin-right:2.5px;
- margin-bottom:2.5px;
- &:nth-child(12n){
- margin-right: 0px;
- }
- img{
- margin:4px;
- width:40px;
- height:40px;
- }
- .l-icon{
- /* width: 80px; */
- /* height: 80px; */
- /* margin:8px; */
- font-size:24px;
- margin:12px;
- }
- &>div{
- margin: 8px 12px;
- }
- }
- &>p{
- display: block;
- margin-top:8px;
- width:100%;
- }
- }
- }
- .pay-footer{
- display:flex;
- margin-bottom: -48px;
- margin-left:24px;
- font-size: 14px;
- &>div{
- color:#4480F9;
- display:flex;
- p:nth-child(2){
- font-size: 24px;
- font-weight: 800;
- margin-top:-3px;
- }
- p:nth-child(1){
- margin:0px 4px;
- }
- }
- }
- .pay-diagram{
- flex-direction:column;
- }
- /* .pay-dialog {
- background-color: red;
- } */
- /* .pay-body {
- height: 300px;
- overflow-y: scroll;
- margin-bottom: 30px;
- .t-collapse {
- border: 0px;
- :deep(.t-collapse-panel__wrapper .t-collapse-panel__header) {
- border-bottom: 0px;
- }
- :deep(.t-collapse-panel__wrapper .t-collapse-panel__body) {
- background: #fff0;
- border-bottom: 0px;
- .t-collapse-panel__content {
- padding: 0;
- color: #c1c8d7;
- }
- }
- }
- } */
- /* .pay-line {
- display: flex;
- height: 54px;
- background-color: #afcaff0a;
- margin-top: 1px;
- div {
- width: 30%;
- text-align: center;
- line-height: 54px;
- :deep(.t-image) {
- width: 40px;
- height: 40px;
- margin-top: 7px;
- }
- :deep(.pay-svg) {
- .t-image {
- background: #fff;
- }
- }
- .l-icon {
- width: 40px;
- height: 40px;
- margin-top: 7px;
- width: 30%;
- }
- }
- .pay-p{
- overflow:hidden;
- text-overflow:ellipsis;
- white-space:nowrap;
- }
- & > div:first-child {
- width: 40%;
- display: flex;
- }
- } */
- /* .pay-tip {
- height: 54px;
- width: 100%;
- position: relative;
- p {
- position: absolute;
- right: 16px;
- color: var(--color-desc);
- }
- }
- .pay-footer {
- margin-bottom: -42px;
- position: relative;
- .pay-price {
- position: absolute;
- right: 215px;
- margin-left: 50px;
- align-items: flex-end;
- line-height: 10px;
- p{
- vertical-align: bottom;
- line-height: normal;
- }
- p:nth-child(2) {
- font-size: 32px;
- font-weight: Semibold;
- color: #4480f9;
- line-height: 20px;
- }
- p:nth-child(1) {
- font-size: 14px;
- color: #4480f9;
- }
- }
- } */
- /* .pay-title {
- margin: 18px 0px 12px 18px;
- } */
- </style>
|