edit.js 148 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380
  1. /* var ceshi = '';
  2. // var ceshi = 'http://192.168.0.135:8105';
  3. // var ceshi = 'http://47.107.252.54:8105';
  4. // var token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInJvbGUiOm51bGwsIm1hbmFnZXIiOm51bGwsImlkIjoxLCJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNTk2NzAxNjAyLCJpYXQiOjE1OTY2MTUyMDIsImp0aSI6Ijk0YjA5YTg1LWViY2ItNDE1Yy04OGVmLWU0MDM1M2UzYmIxYyJ9.Uzi95n0kYXp7bdpY77MdLtTpPL_Fq-jn0tE7gjg6AzA"
  5. var token = window.localStorage.dcj_token
  6. */
  7. var _musicMaxWeight = 8
  8. //M
  9. var cmp = getQueryVariable('cmp') || ''
  10. var _hotNum = 0
  11. function reData(data, type) {
  12. return JSON.stringify(data) == type ? null : data
  13. }
  14. //新编辑界面
  15. var EditTools = function(n) {
  16. //main2018 里面的主要对象
  17. this.n = n;
  18. //当前状态
  19. this.atPanel = null;
  20. //场景信息
  21. this.sceneInformation = new SceneInformation();
  22. //热点
  23. this.hotpoint = new Hotpoint();
  24. //导览
  25. this.editGuide = new EditGuide();
  26. //音乐
  27. this.editMiuse = new EditMiuse();
  28. //初始化界面
  29. this.init();
  30. }
  31. EditTools.prototype.init = function() {
  32. this.hotpoint.init(this.n);
  33. var that = this;
  34. this.initSaveAll();
  35. this.active();
  36. if(player.mode != 'panorama'){
  37. $(".toolLeft li[data-name=panoVisible]").addClass('unable')
  38. player.once("pano.chosen",()=>{
  39. $(".toolLeft li[data-name=panoVisible]").removeClass('unable')
  40. })
  41. }
  42. //请求数据someData.js
  43. $.ajax(g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(), {
  44. dataType: "json"
  45. }).done(function(data) {
  46. //创建导览
  47. that.editMiuse.init(data);
  48. //请求完someData.js 之后再请求data2.js
  49. data2(data, that.sceneInformation.init);
  50. })
  51. //请求热点数据 data2.js
  52. function data2(data, callback) {
  53. $.ajax(g_Prefix + "data/" + window.number + "/data2.js" + "?" + Date.now(), {
  54. dataType: "json"
  55. }).done(function(data2) {
  56. callback(data, data2);
  57. // fyz 初始化导览需要两部分数据, 其中data2为data.js中的数据
  58. that.editGuide.init(data, data2);
  59. }).fail(callback(data, data2))
  60. }
  61. $("body").on("click", function() {
  62. $(".DelConfirm").removeClass("active");
  63. })
  64. }
  65. //点击的时候激活状态
  66. EditTools.prototype.active = function() {
  67. var that = this;
  68. var confirmSnap = $(".confirmSnap.innerBtn");
  69. var snapshotGui = $(".snapshotGui.overlayGui");
  70. $('.toolBottom .toolLeft li').click(function() {
  71. var name = $(this).data("name");
  72. $('.toolLeft li[data-name=' + name + ']').addClass("active").siblings().removeClass("active");
  73. $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
  74. if (name == that.atPanel)
  75. return;
  76. console.log(`atPanel ${that.atPanel} name ${name}`)
  77. switch (that.atPanel) {
  78. //退出
  79. case "panoVisible":
  80. VisiSet.finishSetPanoVisible()
  81. break;
  82. case "screen":
  83. confirmSnap.addClass("hide").removeClass("unable");
  84. snapshotGui.hide();
  85. break;
  86. case "overlay":
  87. EditOverlay.leave()
  88. break;
  89. case "hotpoint":
  90. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click();
  91. VisiSet.finishSetTagVisible()
  92. break;
  93. }
  94. switch (name) {
  95. case "panoVisible":
  96. $(".toolLeft").addClass("unable")
  97. VisiSet.enterSet(VisiSet.beginSetPanoVisible.bind(VisiSet))
  98. break;
  99. case "screen":
  100. confirmSnap.removeClass("hide");
  101. $('#camera-start').text("点此设置为初始画面")
  102. snapshotGui.show();
  103. if (player.modeTran.split("-")[1] != "panorama")
  104. $(".confirmSnap").addClass("unable")
  105. break;
  106. case "overlay":
  107. EditOverlay.enter()
  108. break;
  109. }
  110. that.atPanel = name;
  111. /* if(name != "hotpoint"){
  112. $("#hotpointDetail").hasClass("atRight") || $("#hotpointDetail a.close").click()
  113. } */
  114. })
  115. //滚动阻止事件
  116. $(".toolRight div.content").on("mousewheel", function(event) {
  117. event.stopPropagation()
  118. });
  119. // 输入框阻止事件
  120. $('.toolRight').on('keydown', function(ev) {
  121. ev.stopPropagation();
  122. })
  123. }
  124. //保存按钮
  125. EditTools.prototype.initSaveAll = function() {
  126. var that = this;
  127. $('#save').on('click', function() {
  128. $(".edit-loading").removeClass("hide");
  129. var $shareImages = $(".information .edit-fun-images a.result");
  130. new Promise(function(resolve, reject) {//分享图
  131. upload($shareImages, 'images', resolve)
  132. }).then(function(imgUrls) {
  133. //导览的数据
  134. var guides = that.editGuide.getSavingInfo()/* Array.from($('.tourFolderList ul li')).map(function(dom) {
  135. return dom.data
  136. }) */
  137. var hots = {}
  138. // 热点数据
  139. var hotLength = 0;
  140. for (let i in player.model.hots) {
  141. let hot = player.model.hots[i];
  142. hots[i] = {
  143. position: {
  144. x: hot.mesh.position.x,
  145. y: hot.mesh.position.y,
  146. z: hot.mesh.position.z
  147. },
  148. //有的定制场景代码是旧的,只能使用rotation,所以不输出quaternion :
  149. rotation: hot.isSprite ? new THREE.Euler().setFromQuaternion(hot.quaternion).toObject() : hot.mesh.rotation.toObject(),
  150. isSprite: hot.isSprite ? 1 : 0,
  151. noAction: hot.noAction ? 1 : 0,
  152. linkType: hot.linkType,
  153. infoAttribute: hot.infoAttribute,
  154. order: hotLength++//因为热点保存后在hots里的顺序会被修改,所以使用order来记录顺序
  155. }
  156. if (hot.visiblePanos)
  157. hots[i].visiblePanos = hot.visiblePanos
  158. if (hot.infoAttribute) {
  159. delete hot.infoAttribute.position;
  160. delete hot.infoAttribute.quaternion;
  161. delete hot.infoAttribute.rotation;
  162. }
  163. }
  164. var info = {
  165. name: $('#pjtName').val(),
  166. summary: $('#info-summary').val(),
  167. weixinDesc: $('#weixin-summary').val(),
  168. shareImgUrl: imgUrls[0] || '',
  169. backgroundMusic: $('#query-bgm').attr('href'),
  170. bgName: $(".music .audio.mediaUpload .title").text(),
  171. hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
  172. camera_start: $('#camera-start')[0].data,
  173. loadlogo: $("#loadlogo").is(':checked'),
  174. special: $("#g_specialScene").is(':checked'),
  175. vision_version: $("#twoData").is(':checked') ? "1.1.562.17209" : false,
  176. /************************************** 方奕卓 场景可配置项 ******************************************/
  177. hotImageScale: $("#hotImgScale").is(':checked'),
  178. // 热点图片可放大
  179. hideFloorMarker: $("#hideFloorMarker").is(':checked'),
  180. // 地面标记
  181. hideMouseMarker: $("#hideMouseMarker").is(':checked'),
  182. // 鼠标标记
  183. floorMarkerColor: $('#floorMarkerColor').val(),
  184. // 地面/导览标志颜色
  185. mouseMarkerColor: $('#mouseMarkerColor').val(),
  186. // 鼠标标志颜色
  187. momentTour: $('#tourSwitch input').is(':checked') ? 'black' : 'walk',
  188. // 导览瞬间过渡
  189. showHotListSta: $('#hotListSwitch input').is(':checked'),
  190. // 开启热点列表
  191. hotIconScale: $('#hotIconScale input').val(),
  192. // 热点缩放
  193. supportsVR: $('#VRSwitch input').is(':checked'),
  194. // 开启VR功能
  195. /**************** 陈志广 小地图可配置项 *********** */
  196. cadSignColor: $('#cadSignColor').val(),
  197. cadBorderColor: $('#cadBorderColor').val(),
  198. cadBorderWidth: $('#cad-size').val(),
  199. showCad: $('input[name="show-cad"]').is(':checked'),
  200. }
  201. var overlayInfo = []
  202. player.overlayGroup.children.forEach((overlay)=>{
  203. var info = EditOverlay.getSavingInfo(overlay)
  204. if (info)
  205. overlayInfo.push(info);
  206. }
  207. )
  208. /* console.log("保存数据");
  209. console.log({
  210. guides: reData(guides, '[]'),
  211. info: info,
  212. })
  213. console.log(JSON.stringify(guides) )
  214. debugger; */
  215. let url = cmp ? ('/api/scene/edit/' + cmp) : '/manage/scene/edit'
  216. $.ajax({
  217. method: 'POST',
  218. headers: {
  219. 'Content-Type': 'application/json',
  220. token: token
  221. },
  222. dataType: 'json',
  223. contentType: 'application/json',
  224. url: ceshi + url,
  225. data: JSON.stringify({
  226. sceneCode: number,
  227. hots: reData(hots, '{}'),
  228. name: number,
  229. guides: reData(guides, '[]'),
  230. info: info,
  231. //tourAudio: reData(that.editGuide.getTourAudio(), '{}'),
  232. overlays: reData(overlayInfo, '[]')
  233. }),
  234. success: function(data) {
  235. if (data.code === 0) {
  236. location.reload()
  237. }
  238. if (data.code === 5001) {
  239. alert('请重新登录')
  240. localStorage.dcj_token = ''
  241. location.reload()
  242. }
  243. }
  244. })
  245. });
  246. })
  247. }
  248. //场景信息编辑
  249. var SceneInformation = function() {}
  250. SceneInformation.prototype.init = function(data, data2) {
  251. var $options = $('.hotStyle-item li');
  252. var $loadlogo = $("#loadlogo");
  253. var $hotImageScale = $("#hotImgScale");
  254. var $hideFloorMarker = $("#hideFloorMarker");
  255. var $hideMouseMarker = $("#hideMouseMarker");
  256. var $g_specialScene = $("#g_specialScene");
  257. var $twoData = $("#twoData");
  258. /*******************方奕卓 其他项需要用到data来初始化, 故一并放到这里 ******************/
  259. let momentTour = $('#tourSwitch input');
  260. // 导览瞬间过渡开关
  261. let hotListSwitch = $('#hotListSwitch input');
  262. // 热点列表开关
  263. let hotIconScale = $('#hotIconScale input');
  264. // 热点图标缩放
  265. let VRSwitch = $('#VRSwitch input');
  266. // VR功能开启
  267. /***********************************************************************************/
  268. $(".model-title2").text(data.name);
  269. $('#pjtName').val(data.name);
  270. $('#info-summary').val(data.summary);
  271. //if (data2) $('#weixin-summary').val(data2.weixinDesc);
  272. $('#weixin-summary').val(data.weixinDesc);
  273. for (var i = 0; i < $options.length; i++) {
  274. if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
  275. $options.eq(i).addClass("active").siblings().removeClass("active");
  276. }
  277. }
  278. $('#camera-start')[0].data = data.camera_start;
  279. $(".shotImg.innerBtn").on("click", ()=>{
  280. var EntryInfo = $('#camera-start')[0].data
  281. if (EntryInfo) {
  282. var to = player.model.panos.get(EntryInfo.pano.uuid);
  283. var q = new THREE.Quaternion().fromArray(EntryInfo.camera.quaternion);
  284. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(to.position);
  285. player.flyToPano({
  286. pano: to,
  287. lookAtPoint: lookAtPoint
  288. })
  289. }
  290. }
  291. )
  292. if(data.shareImgUrl){
  293. var imagesHTML = '<div><a class=" result success"><span></span><img src="' + data.shareImgUrl + '"></a></div>'
  294. $(".information .edit-fun-images.list ").html(imagesHTML);
  295. $("#shareImgUpload").addClass("hide")
  296. }
  297. if(data.spotImgUrl){
  298. }
  299. /*************方奕卓 其他项的初始化操作 ************/
  300. initColorElem(data);
  301. addListener();
  302. // 给其他元素绑定事件
  303. if (data.momentTour === 'black') {
  304. momentTour.prop('checked', true);
  305. }
  306. if (data.showHotListSta) {
  307. hotListSwitch.prop('checked', true);
  308. }
  309. if (data.hotIconScale && parseFloat(data.hotIconScale) <= 1.5 && parseFloat(data.hotIconScale) >= 0.3) {
  310. hotIconScale.val(parseFloat(data.hotIconScale));
  311. }
  312. if (data.supportsVR) {
  313. VRSwitch.prop('checked', true);
  314. }
  315. /************************************************/
  316. //隐藏公司logo
  317. if (data.loadlogo) {
  318. $loadlogo[0].checked = true
  319. showLogo();
  320. }
  321. // 热点图片放大
  322. if (data.hotImageScale) {
  323. $hotImageScale[0].checked = true
  324. }
  325. // 隐藏地面标记
  326. if (data.hideFloorMarker) {
  327. $hideFloorMarker[0].checked = true
  328. }
  329. // 隐藏鼠标标记
  330. if (data.hideMouseMarker) {
  331. $hideMouseMarker[0].checked = true
  332. }
  333. //特殊大场景
  334. if (data.special) {
  335. $g_specialScene[0].checked = true
  336. }
  337. //启动二代的数据
  338. if (data.vision_version === "1.1.562.17209" || data.vision_version) {
  339. $twoData[0].checked = true
  340. }
  341. }
  342. /**
  343. * 初始化颜色选择的html元素
  344. * @param {*} data
  345. * @param {*} elem
  346. */
  347. function initColorElem(data, elem) {
  348. let $floorMarkerColor = $('#floorMarkerColor');
  349. let $mouseMarkerColor = $('#mouseMarkerColor');
  350. let $floorMarkerColorTex = $('#floorMarkerColorTex');
  351. let $mouseMarkerColorTex = $('#mouseMarkerColorTex');
  352. let $cadSignColor = $('#cadSignColor');
  353. let $cadSignColorTex = $('#cadSignColorTex');
  354. let $cadBorderColor = $('#cadBorderColor');
  355. let $cadBorderColorTex = $('#cadBorderColorTex');
  356. var colorRe = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
  357. // 事件监听
  358. $floorMarkerColor.on('change', function(e) {
  359. $('#floorMarkerColorTex').attr('placeholder', e.target.value)
  360. })
  361. $floorMarkerColorTex.on('blur keydown', function(e) {
  362. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $floorMarkerColor, this);
  363. })
  364. $mouseMarkerColor.on('change', function(e) {
  365. $('#mouseMarkerColorTex').attr('placeholder', e.target.value)
  366. })
  367. $mouseMarkerColorTex.on('blur keydown', function(e) {
  368. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $mouseMarkerColor, this);
  369. })
  370. // 事件监听
  371. $cadSignColor.on('change', function(e) {
  372. $('#cadSignColorTex').attr('placeholder', e.target.value)
  373. })
  374. $cadSignColorTex.on('blur keydown', function(e) {
  375. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadSignColor, this);
  376. })
  377. // 事件监听
  378. $cadBorderColor.on('change', function(e) {
  379. $('#cadBorderColorTex').attr('placeholder', e.target.value)
  380. })
  381. $cadBorderColorTex.on('blur keydown', function(e) {
  382. (e.type === 'blur' || e.type === 'keydown' && e.keyCode === 13) && setColor(e, $cadBorderColor, this);
  383. })
  384. // 设置颜色值
  385. function setColor(e, colorElem, inputElem) {
  386. var isColor = colorRe.test(e.target.value);
  387. isColor && colorElem.val(e.target.value);
  388. // isColor ? colorElem.val(e.target.value): (inputElem.placeholder = colorElem.val());
  389. }
  390. // 判断data中是否有存在的颜色值, 否则设置默认值
  391. data.floorMarkerColor ? $floorMarkerColor.val(data.floorMarkerColor) : $floorMarkerColor.val('#4bcdfc');
  392. data.mouseMarkerColor ? $mouseMarkerColor.val(data.mouseMarkerColor) : $mouseMarkerColor.val('#4bcdfc');
  393. // 判断data中是否有存在的颜色值, 否则设置默认值
  394. data.cadSignColor ? $cadSignColor.val(data.cadSignColor) : $cadSignColor.val('#00c8af');
  395. data.cadBorderColor ? $cadBorderColor.val(data.cadBorderColor) : $cadBorderColor.val('#ffffff');
  396. $('input[name="show-cad"]')[0].checked = !!data.showCad
  397. $('#cad-size > option[value="'+(data.cadBorderWidth ? data.cadBorderWidth : '0.01')+'"]').attr("selected",true);
  398. if (data.showCad) {
  399. $('input[name="show-cad"]').trigger('change')
  400. }
  401. }
  402. $('input[name="show-cad"]').on('change', function(ev) {
  403. if (!ev.target.checked) {
  404. return $('.cad').hide()
  405. }
  406. let taht = this
  407. if (!taht.floorJSON) {
  408. $.ajax({
  409. url: '//super.4dage.com/data/'+ window.number +'/floor.json',
  410. method: 'GET',
  411. success(res) {
  412. taht.floorJSON = res
  413. loadCAD(taht.floorJSON)
  414. $('#cadSignColor').on('change', function(ev) {
  415. loadCAD()
  416. })
  417. $('#cadBorderColor').on('change', function(ev) {
  418. loadCAD()
  419. })
  420. $('#cad-size').on('change', function(ev) {
  421. loadCAD()
  422. })
  423. },
  424. error() {
  425. alert('当前场景没有小地图floor.json文件,请联系三维部门添加')
  426. ev.target.checked = false
  427. }
  428. })
  429. } else {
  430. console.log('0000000000000000000')
  431. $('.cad').show()
  432. }
  433. })
  434. function loadCAD(data) {
  435. grendCAD(data, $('#player')[0], $('#cadSignColor').val(), $('#cadBorderColor').val(), $('#cad-size').val())
  436. }
  437. function addListener() {}
  438. //设置初始界面
  439. function getSeft(seft) {
  440. $('#camera-start').on('click', function() {
  441. if (VisiSet.setPanoVisible) {
  442. return VisiSet.savePanoVisibles()
  443. } else if (VisiSet.setTagVisible) {
  444. return VisiSet.saveTagVisibles()
  445. }
  446. // 这部分内容需要配合main_2018.js中来进行修改
  447. var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
  448. this.data = {
  449. camera: {
  450. position: snap.metadata.camera_position,
  451. quaternion: snap.metadata.camera_quaternion// 相机朝向
  452. },
  453. pano: {
  454. uuid: snap.metadata.scan_id // 起始点位的id
  455. }
  456. }
  457. var ev = document.createEvent("MouseEvent");
  458. //点击截取视图
  459. g_snapShotWidth = 240 * 4;
  460. g_snapShotHeight = 118 * 4;
  461. window.screenSta = 'startScreen';
  462. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  463. ev.__callback = (imgData,info)=>{
  464. uploadImg(imgData, (rs)=>{
  465. if (rs.code === 0) {
  466. $(".shotImg.innerBtn").css("background-image", "url(" + rs.data + ")")
  467. this.data.thumbImg = rs.data;
  468. }
  469. }
  470. , "thumbImg.jpg")
  471. }
  472. window.dispatchEvent(ev);
  473. });
  474. }
  475. //热点编辑
  476. var Hotpoint = function() {
  477. this.spotList = $(".spotList");
  478. this.hotpointDetail = $("#hotpointDetail");
  479. // fyz 导览编辑页面同样采取热点编辑的样式, 这里确保只查找到热点编辑
  480. }
  481. Hotpoint.prototype.init = function(n) {
  482. this.active();
  483. this.addmedia();
  484. // 添加多媒体
  485. this.addMusicInit();
  486. // 添加音乐
  487. this.addModel();
  488. // 添加模型
  489. this.addwebPack();
  490. // 添加外链
  491. this.initSaveHot();
  492. // 保存热点
  493. var that = this;
  494. let hotIconScale = $('#hotIconScale');
  495. //点击添加热点按钮
  496. $('#addHotSpots').on("click", function() {
  497. //点击添加热点
  498. g_HotStatus = g_HotStatus === "add" ? null : "add";
  499. $("#player").css("cursor", "cell");
  500. });
  501. //点击热点列表弹出按钮
  502. this.spotList.on("click", function(e) {
  503. var target = $(e.target);
  504. let li = searchParent(e.target, { className: 'listItem' }, 7);
  505. if(!li)return;
  506. var hotId = $(li).attr("data-spid");
  507. var hot = player.model.hots[hotId]
  508. if(VisiSet.setTagVisible){
  509. return VisiSet.SetOneTagVisible(hot)
  510. }
  511. if (target.hasClass("del")) {
  512. e.stopPropagation();
  513. target.siblings(".DelConfirm").addClass("active");
  514. that.spotList.find("i").text(that.spotList.find("ul li").length);
  515. } else {
  516. if (target.hasClass("DelConfirm")) {
  517. e.stopPropagation();
  518. that.removeHot(hot, $(li));
  519. } else {
  520. //点击热点列表弹出编辑热点窗口
  521. that.editHot(hot, $(li))
  522. }
  523. }
  524. });
  525. //点击热点编辑窗口右上角的关闭按钮
  526. this.hotpointDetail.find("a.close, button.cancel").on("click", function() {
  527. var spot_id = that.hotpointDetail.attr("data-id");
  528. var hot = player.model.hots[spot_id];
  529. var info = hot.infoAttribute;
  530. //that.hotpointDetail[0].targetDOM.infoAttribute;
  531. if (info) {
  532. info.position && hot.mesh.position.copy(info.position)
  533. info.quaternion && hot.mesh.quaternion.copy(info.quaternion)
  534. hot.isSprite = info.isSprite
  535. hot.noAction = info.noAction
  536. hot.linkOutside = info.linkOutside
  537. }
  538. that.hotpointDetail.addClass("atRight");
  539. transformControls.detach()
  540. });
  541. //创建列表
  542. for (let i in player.model.hots) {
  543. this.addHotList(player.model.hots[i]);
  544. }
  545. // 初始话的时候把热点信息添加到对应的热点中 直接使用data2.json的会怎样?
  546. /* $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
  547. .then(function (infos) {
  548. that.infos = infos ;
  549. Object.keys(infos).forEach(function (key) {
  550. //sxm增加热点列表可读性,方便查看删除操作等
  551. that.spotList.find("ul li[data-spid=" + key + "]")[0] && (that.spotList.find("ul li[data-spid=" + key + "]")[0].infoAttribute = infos[key])&& (that.spotList.find("ul li[data-spid=" + key + "] .title").html(infos[key].title));
  552. })
  553. }) */
  554. }
  555. /**
  556. * 显示编辑热点的窗口和初始化热点窗口的数据
  557. */
  558. Hotpoint.prototype.editHot = function(hot, $li) {
  559. this.hotpointDetail.removeClass("atRight");
  560. $("#hotpointDetail .audio.mediaUpload").find("input").val('');
  561. // 点击编辑导览清空上一次文件
  562. var playIcon = 'images/play.png';
  563. var $layout = $("#hotpointDetail")[0];
  564. //$layout.targetDOM = target.closest("li")[0];
  565. //closest匹配选择器的第一个祖先元素
  566. //编辑时将热点列表唯一标识带入,以便后期保存使用识别
  567. //var li_id = $li.attr("data-spid");
  568. this.editSpot = hot
  569. this.hotpointDetail.attr("data-id", hot.sid);
  570. var info = this.editSpot.infoAttribute || {}
  571. //$layout.targetDOM.infoAttribute || {}
  572. transformControls.transCtlChangeMode("translate")
  573. // 参数初始化
  574. info.title = info.title || '';
  575. info.content = info.content || '';
  576. info.iframe = info.iframe || [];
  577. info.model = info.model || [];
  578. info.images = info.images || [];
  579. info.video = info.video || [];
  580. info.isSprite = this.editSpot.isSprite
  581. info.noAction = this.editSpot.noAction
  582. try {
  583. transformControls.attach(hot.mesh)
  584. hot.examine(player, {
  585. dontOpen: true
  586. })
  587. //add
  588. info.position = hot.position.clone()
  589. info.quaternion = hot.quaternion.clone()
  590. } catch (e) {}
  591. initStyle(hot)
  592. $("#isSprite")[0].checked = this.editSpot.isSprite
  593. $("#noAction")[0].checked = this.editSpot.noAction
  594. $(".webPage .MenuOptions li").removeClass("chosen")
  595. $(".webPage .MenuOptions li[index = " + this.editSpot.linkType+"]").addClass("chosen")
  596. var iframesHTML = info.iframe.map(function(iframe) {
  597. return this.inputList("请填写网页链接", iframe)
  598. }
  599. .bind(this))
  600. var modulesHTML = info.model.map(function(module) {
  601. return this.inputList("请填写网页链接", module)
  602. }
  603. .bind(this))
  604. var imagesHTML = info.images.map(function(image) {
  605. return '<div><a class=" result success" data-type="photo"><span></span><img src="' + image + '" class="bg"></a></div>'
  606. })
  607. var videosHTML = info.video.map(function(ly) {
  608. //var imgDom = (!ly.img || ly.img === "undefined") ? '' : 'success';
  609. //var imgUrl = (!ly.img || ly.img === "undefined") ? playIcon : ly.img;
  610. //return '<div><a class=" result success" data-type="video"><span></span><img class="play-video" videoURL="' + ly.url + '" src="' + imgUrl + '"></a ><span class="upload-thum ' + imgDom + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file"></i></span></div>'
  611. var thumb = (!ly.img || ly.img === "undefined") ? '' : '<img src='+ ly.img +' class="bg"></img>'
  612. var thumbResult = (!ly.img || ly.img === "undefined") ? '' : 'success';
  613. var dom = '<div><a class=" result success" data-type="video"><span></span>' + thumb + ' <img class="play-video" videoURL="' + ly.url + '" src="' + playIcon + '"></a> <span class="upload-thum ' + thumbResult + ' result" attr-thum="' + ly.img + '">上传封面<i><input type="file" accept="image/*"></i></span></div>'
  614. return dom
  615. })
  616. this.hotpointDetail.find(".name > input").val(info.title);
  617. this.hotpointDetail.find(".editText").val(info.content);
  618. this.hotpointDetail.find(".photo .list").html(imagesHTML);
  619. this.hotpointDetail.find(".video .list").html(videosHTML);
  620. this.hotpointDetail.find(".model .list").html(modulesHTML);
  621. this.hotpointDetail.find(".webPage .list").html(iframesHTML);
  622. let bgName = info.bgName || '热点背景音乐';
  623. if (info.backgroundMusic) {
  624. /* this.hotpointDetail.find(".audio .playBox").removeClass("hide");
  625. this.hotpointDetail.find("#upload-hotBgm").attr('data-hotBgm', info.backgroundMusic)
  626. this.hotpointDetail.find(".audio .playBox a").attr("href", info.backgroundMusic);
  627. this.hotpointDetail.find('#hotBgName')[0].innerHTML = bgName;
  628. this.hotpointDetail.find(".audio .submit").text("替换"); */
  629. this.musicBox.show(this.hotpointDetail.find(".audio.mediaUpload"), bgName, info.backgroundMusic)
  630. } else {
  631. this.musicBox.hide()
  632. /* this.hotpointDetail.find(".audio .playBox").addClass("hide");
  633. this.hotpointDetail.find("#upload-hotBgm").removeAttr('data-hotBgm') */
  634. // 没有背景音乐,则移除该属性, 避免其他热点的干扰
  635. }
  636. // $layout.targetDOM.infoAttribute = info
  637. this.editSpot.infoAttribute = info
  638. }
  639. //添加图片和视频
  640. Hotpoint.prototype.addmedia = function() {
  641. // 视频预览控制
  642. var $videoLayout = $('.fun-view-video')
  643. $videoLayout.find('span').on('click', function() {
  644. $videoLayout.hide();
  645. $videoLayout.find('video').attr('src', '')[0].pause()
  646. });
  647. // 图片加载回调
  648. function imageSuccess(file) {
  649. if (!/image\/\w+/.test(file.type)) {
  650. alert("文件必须为图片!");
  651. return false;
  652. }
  653. if (!restrictedSize(file, 9)) {
  654. return false;
  655. }
  656. var img = new Image()
  657. img.src = URL.createObjectURL(file);
  658. img.className = 'bg'
  659. return img
  660. }
  661. // 视频加载回调
  662. function videoSuccess(file, $elayout) {
  663. if (!/video\/\w+/.test(file.type)) {
  664. alert("视频必须为map4格式!");
  665. return false;
  666. }
  667. $elayout.append('<span class="upload-thum">上传封面<i><input type="file" accept="image/*"></i></span>')
  668. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
  669. }
  670. // 视频封面回调
  671. function thumbSuccess(file, $elayout, $seft) {
  672. if (!/image\/\w+/.test(file.type)) {
  673. alert("文件必须为图片!");
  674. return false;
  675. }
  676. if (!restrictedSize(file, 2)) {
  677. return false;
  678. }
  679. var img = $seft.closest('div').find('img.bg');
  680. if(!img[0]){
  681. img = $("<img class='bg'></img>");
  682. $seft.closest('div').find('a').append(img)
  683. }
  684. img.attr('src', URL.createObjectURL(file));
  685. $seft.closest('span').removeClass("success")
  686. }
  687. // 图片与视频加载
  688. function fileHandle() {
  689. var $seft = $(this) //input
  690. var file = this.files[0];
  691. var type = this.activeElem ? this.activeElem.attr('data-type') : $seft.parent().attr('data-type');
  692. var $din = $(document.createElement('div'));
  693. var fnc = type === 'photo' ? imageSuccess : type === 'video' ? videoSuccess : thumbSuccess //再次传都会是thumSuccess
  694. var $dom = fnc(file, $din, $seft)
  695. if (type === 'photo' || type === 'video') {
  696. if (!$dom)
  697. return $seft.val('');
  698. if(!this.activeElem){//创建新的item
  699. var $layout = $seft.closest("li");
  700. var $addLayout = $(document.createElement('a'));
  701. $addLayout.attr("data-type", type)
  702. var $close = $(document.createElement('span'));
  703. $addLayout[0].file = file;
  704. $addLayout.append($close);
  705. $addLayout.append($dom);
  706. $addLayout.addClass("result");
  707. $din.prepend($addLayout);
  708. $layout.find('.edit-fun-images').append($din);
  709. }else{//重传
  710. if (type === 'photo'){
  711. this.activeElem.find("img.bg").remove();
  712. }else{
  713. this.activeElem.find(".play-video").remove();
  714. }
  715. this.activeElem.removeClass("success")
  716. this.activeElem.append($dom)
  717. this.activeElem[0].file = file;
  718. this.value = ''
  719. }
  720. }
  721. if (searchParent($seft[0], {
  722. id: 'shareImgUpload'
  723. })) {
  724. //信息页面的分享图片
  725. $("#shareImgUpload").addClass("hide")
  726. }else if(searchParent($seft[0], {
  727. id: 'SpotStyle'
  728. })){
  729. $("#SpotStyle").addClass("hide")
  730. }
  731. }
  732. //用于重传的input
  733. var imgInput = $("<input accept='image/*' type='file'></input>")
  734. var videoInput = $("<input accept='video/*' type='file'></input>")
  735. // 图片与视频加载
  736. $('.upload, .edit-fun-images').on('change', function(ev) {
  737. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  738. ev.target.files.length && fileHandle.call(ev.target)
  739. }
  740. })
  741. imgInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  742. videoInput.on('change', (ev)=>{fileHandle.call(ev.target)})
  743. $('.edit-fun-images').on('click', function(ev) {//点击item时
  744. var $tag = $(ev.target)
  745. var tagName = ev.target.tagName.toUpperCase()
  746. if (tagName === 'SPAN') {
  747. if (searchParent($tag[0], {
  748. className: 'forShareImg'
  749. })) {
  750. //信息页面的分享图片
  751. $("#shareImgUpload").removeClass('hide')
  752. }else if(searchParent($tag[0], {
  753. className: 'SpotStyle'
  754. })){
  755. $("#SpotStyle").removeClass('hide')
  756. }
  757. $tag.parent().parent().remove()
  758. }else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  759. $videoLayout.css('display', 'flex').find('video').attr('src', $tag.attr('videoURL'))[0].play()
  760. }else{// 替换
  761. var a = searchParent($tag[0], {
  762. tagName: 'a'
  763. })
  764. if(a) {
  765. var input
  766. if(searchParent($tag[0], {
  767. className: 'video'
  768. })){
  769. input = videoInput
  770. }else{
  771. input = imgInput
  772. }
  773. input[0].activeElem = $(a)
  774. input.click()
  775. }
  776. }
  777. })
  778. }
  779. //========================xzw=======================更改热点样式图
  780. var currStyle;
  781. //当前选择的模式 默认or用户自定义
  782. var currentHotStyleImg = [];
  783. //当前编辑状态下添加的图, 每次开始编辑热点时更新
  784. var editStyleImgIndex = 0;
  785. //当前正在编辑第几张图
  786. var uploadInput = $('<input type="file" style="display:none" accept="image/*"></input>');
  787. $("#hotpointDetail .style .MenuOptions li").on("click", (e)=>{
  788. //热点页面内样式切换
  789. currStyle = $(e.target).attr("index")
  790. if (currStyle == "default") {
  791. $("#userUploadStyle").addClass("hide")
  792. } else {
  793. $("#userUploadStyle").removeClass("hide")
  794. }
  795. $("#hotpointDetail .style .MenuOptions li").removeClass("chosen");
  796. $(e.target).addClass("chosen")
  797. }
  798. )
  799. $('#userUploadStyle li').on('click', (e)=>{
  800. var index = $(e.currentTarget).index();
  801. if (e.target.classList.contains("del")) {
  802. //删除图片
  803. if (currentHotStyleImg.length == 2 && index == 0) {
  804. //删除第一个 且有第二个的话
  805. setImgContent(0, currentHotStyleImg[1].src);
  806. setImgContent(1, null);
  807. currentHotStyleImg = [currentHotStyleImg[1]]
  808. } else {
  809. setImgContent(index, null);
  810. currentHotStyleImg.pop()
  811. if (currentHotStyleImg.length == 0) {
  812. $('#userUploadStyle li').eq(1).addClass("hide");
  813. }
  814. }
  815. } else {
  816. //添加图片
  817. uploadInput.click()
  818. editStyleImgIndex = index;
  819. }
  820. }
  821. )
  822. uploadInput.on("change", (e)=>{
  823. inputMedia({
  824. enableTypes: ["photo"],
  825. photoDone: (resultImg)=>{
  826. currentHotStyleImg[editStyleImgIndex] = resultImg;
  827. setImgContent(editStyleImgIndex, resultImg.src)
  828. if (editStyleImgIndex == 0)
  829. $('#userUploadStyle li').eq(1).removeClass("hide");
  830. resultImg.needSave = true
  831. }
  832. }, "photo", e);
  833. }
  834. )
  835. var setImgContent = function(index, src) {
  836. var li = $('#userUploadStyle li').eq(index)
  837. var div = li.find('>div');
  838. if (src) {
  839. li.addClass("uploaded")
  840. div.css("background-image", `url(${src})`)
  841. } else {
  842. li.removeClass("uploaded")
  843. div.css("background-image", '')
  844. }
  845. }
  846. var initStyle = function(hot) {
  847. //每次开始编辑热点时更新列表UI 和 currentHotStyleImg
  848. if (!hot.styleTex)
  849. hot.styleTex = [];
  850. $('#userUploadStyle li>div').css("background-image", "");
  851. $('#userUploadStyle li').removeClass("uploaded")
  852. currentHotStyleImg = hot.styleTex.slice(0);
  853. if (hot.styleTex.length) {
  854. $("#hotpointDetail .style .MenuOptions li").eq(1).click();
  855. hot.styleTex.forEach((img,index)=>{
  856. setImgContent(index, img.src)
  857. }
  858. )
  859. $('#userUploadStyle li').eq(1).removeClass("hide")
  860. } else {
  861. $("#hotpointDetail .style .MenuOptions li").eq(0).click()
  862. $('#userUploadStyle li').eq(1).addClass("hide")
  863. }
  864. }
  865. //=====================================================
  866. //选择热点的样式
  867. Hotpoint.prototype.active = function() {
  868. $(".hotStyle-item li").on('click', function() {
  869. $(this).addClass('active').siblings().removeClass('active');
  870. })
  871. }
  872. //当前处于的状态,比如是否是添加热点的状态
  873. Hotpoint.prototype.state = function(that, Hot) {
  874. if (g_HotStatus === "add") {
  875. //console.log(Hot)
  876. this.addHot(that, Hot, (hot)=>{
  877. this.addHotList(hot);
  878. }
  879. );
  880. }
  881. }
  882. Hotpoint.prototype.updateNumDisplay = function() {
  883. this.spotList.find("i").text(this.spotList.find("ul li").length);
  884. }
  885. //删除热点
  886. Hotpoint.prototype.removeHot = function(hot, $li ) {
  887. hot.dispose();
  888. delete player.model.hots[hot.sid]
  889. $li.remove();
  890. this.updateNumDisplay()
  891. }
  892. //添加热点模型
  893. Hotpoint.prototype.addHot = function(that, Hot, fn) {
  894. if (!window.hotIntersect)
  895. return;
  896. // 没有正确的热点位置, return
  897. var position = hotIntersect.point.toArray();
  898. //var sid = g_HotMeshes.length > 0 ? "sprite_" + (parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1) : "sprite_" + g_HotMeshes.length;//这么写出bug了。因为当前热点名字不是按照从小到大
  899. var sid = getRandomSid()
  900. var hot = new Hot(sid,{
  901. position: position,
  902. rotation: [0, 0, 0],
  903. size: 1.05
  904. },that.model);
  905. that.model.hots[sid] = hot;
  906. if (player.getMouseDirection().angleTo(window.hotIntersect.face.normal) < Math.PI / 2) {
  907. hot.mesh.lookAt(window.hotIntersect.face.normal.clone().negate().add(hotIntersect.point));
  908. hot.mesh.position.add(window.hotIntersect.face.normal.clone().negate().multiplyScalar(0.01))
  909. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  910. } else {
  911. hot.mesh.lookAt(window.hotIntersect.face.normal.clone().add(hotIntersect.point));
  912. hot.mesh.position.add(window.hotIntersect.face.normal.clone().multiplyScalar(0.01))
  913. }
  914. hot.quaternion.copy(hot.mesh.quaternion)
  915. hot.position.copy(hot.mesh.position)
  916. g_HotStatus = false;
  917. that.mouseCouldBeClickToMove = false;
  918. $("#player").css("cursor", "");
  919. //添加完热点之后的回调函数
  920. if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
  921. var thisScene = that;
  922. //fn && fn.call(this, thisScene);
  923. fn && fn(hot)
  924. }
  925. }
  926. //添加热点列表
  927. Hotpoint.prototype.addHotList = function(hot) {
  928. var li = $("<li class='listItem' data-spid=" + hot.sid + ">" + "<div class=icon></div>" + "<div class=number title=热点>" + (++_hotNum) + "</div>" + "<div class=title title=热点>" + (hot.infoAttribute && hot.infoAttribute.title || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
  929. li.hot = hot
  930. $(".spotList ul").append(li);
  931. this.updateNumDisplay()
  932. }
  933. //添加热点音乐
  934. Hotpoint.prototype.addMusicInit = function() {
  935. /* var mediaUpload = $("#hotpointDetail .audio.mediaUpload");
  936. mediaUpload.find("input").on("change", function() {
  937. var file = this.files[0];
  938. mediaUpload.find(".innerBtn").text("替换");
  939. mediaUpload.find(".playBox").removeClass("hide");
  940. mediaUpload.find(".title").text(file.name);
  941. mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
  942. });
  943. //删除音乐
  944. mediaUpload.on("click", ".delete", function() {
  945. mediaUpload.find('#query-bgm').attr('href', "");
  946. mediaUpload.find(".playBox").addClass("hide");
  947. mediaUpload.find(".innerBtn").text("上传");
  948. mediaUpload.find("input").val("").removeAttr("data-hotbgm");
  949. }) */
  950. this.musicBox = musicPlayBoxBind($("#hotpointDetail .audio.mediaUpload"), null )
  951. }
  952. //添加热点模型列表dom
  953. Hotpoint.prototype.inputList = function(text, val) {
  954. var _val = '';
  955. if (arguments[1]) {
  956. _val = 'value=' + val;
  957. }
  958. return '<div class="link"> <input class="text" type="text" placeholder=' + text + ' spellcheck="false" ' + _val + ' > </div>'
  959. }
  960. //添加热点模型
  961. Hotpoint.prototype.addModel = function() {
  962. var text = this.inputList("请填写模型链接");
  963. this.hotpointDetail.find(".model .add").on('click', function() {
  964. $(this).closest(".model").find(".list").append(text)
  965. });
  966. this.hotpointDetail.find(".model .delete").on('click', function() {
  967. $(this).closest(".model").find(".list > div:last").remove();
  968. });
  969. }
  970. //添加网页链接
  971. Hotpoint.prototype.addwebPack = function() {
  972. var text = this.inputList("请填写网页链接", "");
  973. this.hotpointDetail.find(".webPage .add").on('click', function() {
  974. $(this).closest(".webPage").find(".list").append(text)
  975. });
  976. this.hotpointDetail.find(".webPage .delete").on('click', function() {
  977. $(this).closest(".webPage").find(".list > div:last").remove();
  978. });
  979. }
  980. // 保存热点信息
  981. Hotpoint.prototype.initSaveHot = function() {
  982. var $layout = $(".edit-loading");
  983. var hotpointDetail = this.hotpointDetail;
  984. var spotList = this.spotList;
  985. var that = this
  986. hotpointDetail.find(".tail .submit").on('click', function() {
  987. //获取唯一标识
  988. var spot_id = hotpointDetail.attr("data-id");
  989. var spot = spotList.find("li[data-spid=" + spot_id + "]");
  990. var hot = player.model.hots[spot_id];
  991. //显示loading
  992. $layout.removeClass('hide');
  993. var args = {};
  994. //热点标题
  995. var $title = hotpointDetail.find(".info input");
  996. //热点内容
  997. var $content = hotpointDetail.find(".info textarea");
  998. //热点图片
  999. var $images = hotpointDetail.find(".photo .edit-fun-images a.result");
  1000. //热点视频
  1001. var $videos = hotpointDetail.find(".video .edit-fun-images a.result");
  1002. //热点视频的图片
  1003. var $thums = hotpointDetail.find(".video .edit-fun-images .upload-thum");
  1004. //热点模型
  1005. var $modules = hotpointDetail.find(".model input");
  1006. //热点内嵌网页
  1007. var $iframes = hotpointDetail.find(".webPage input.text");
  1008. //热点音乐
  1009. var $miusc = hotpointDetail.find("#upload-hotBgm");
  1010. let $bgName = hotpointDetail.find('.title');
  1011. new Promise(function(resolve, reject) {
  1012. //获取图片路径
  1013. upload($images, 'images', resolve)
  1014. }
  1015. ).then(function(imgUrls) {
  1016. args.images = imgUrls
  1017. //获取视频路径
  1018. return new Promise(function(resolve, reject) {
  1019. upload($videos, 'videos', resolve)
  1020. }
  1021. )
  1022. }).then(function(videoUrls) {
  1023. args.video = videoUrls
  1024. //获取视频封面路径
  1025. return new Promise(function(resolve, reject) {
  1026. upload($thums, 'images', resolve)
  1027. }
  1028. )
  1029. }).then(function(thums) {
  1030. args.video = args.video.map(function(video, index) {//整合视频+封面
  1031. return {
  1032. url: video,
  1033. img: thums[index]
  1034. }
  1035. })
  1036. }).then(function() {
  1037. //获取热点音乐所有的路径
  1038. //console.log($miusc)
  1039. if ($miusc[0].files.length > 0) {
  1040. return new Promise(function(resolve) {
  1041. upload($miusc, 'miusc', function(res) {
  1042. resolve(res[0])
  1043. })
  1044. }
  1045. )
  1046. } else {
  1047. return $miusc.attr('data-hotBgm')
  1048. }
  1049. }).then(function(src) {
  1050. if(that.musicBox.hasMusic && !src){
  1051. args.backgroundMusic = hot.infoAttribute.backgroundMusic
  1052. args.bgName = hot.infoAttribute.bgName
  1053. }else{
  1054. args.backgroundMusic = src
  1055. args.bgName = $bgName[0].innerHTML;
  1056. }
  1057. }).then(function() {
  1058. //上传style图片
  1059. var a = $.Deferred();
  1060. var doneNum = 0;
  1061. if (currStyle == "user" && currentHotStyleImg.length) {
  1062. currentHotStyleImg.forEach((img)=>{
  1063. if (img.needSave)
  1064. uploadFile(img.file, 'hot/image', function(rs) {
  1065. if (rs.code === 0) {
  1066. img.needSave = false;
  1067. img.saveURL = rs.data;
  1068. if (++doneNum >= currentHotStyleImg.length) {
  1069. a.resolve();
  1070. }
  1071. } else {
  1072. alert("样式图上传失败");
  1073. a.reject();
  1074. }
  1075. })
  1076. else if (++doneNum >= currentHotStyleImg.length) {
  1077. a.resolve();
  1078. }
  1079. }
  1080. )
  1081. return a.promise()
  1082. } else
  1083. return a.resolve()
  1084. }).then(()=>{
  1085. //获取style图的信息
  1086. args.styleImg = [];
  1087. if (currStyle == "user") {
  1088. currentHotStyleImg.forEach((img)=>{
  1089. args.styleImg.push(img.saveURL || img.src)
  1090. }
  1091. )
  1092. hot.styleTex = currentHotStyleImg.slice(0)
  1093. } else {
  1094. hot.styleTex = [];
  1095. }
  1096. hot.changeTex();//更新材质
  1097. }
  1098. ).then(function() {
  1099. //获取热点标题、内容、内嵌网页、模型网页。
  1100. args.title = $title.val()
  1101. args.content = $content.val()
  1102. var iframes = []
  1103. for (var i = 0; i < $iframes.length; i++) {
  1104. var iframe = $iframes.eq(i).val()
  1105. iframe && iframes.push(iframe)
  1106. }
  1107. args.iframe = iframes
  1108. var modules = []
  1109. for (var i = 0; i < $modules.length; i++) {
  1110. var module = $modules.eq(i).val()
  1111. module && modules.push(module)
  1112. }
  1113. args.model = modules
  1114. args.position = hot.mesh.position.clone()
  1115. args.quaternion = hot.mesh.quaternion.clone()
  1116. return args
  1117. }).then(function(args) {
  1118. console.log(args);
  1119. //把获取的所有信息都保存在对应热点的dom元素里面
  1120. //hotpointDetail[0].targetDOM.infoAttribute = args;
  1121. hot.infoAttribute = args;
  1122. $layout.addClass('hide');
  1123. hotpointDetail.addClass("atRight");
  1124. spot.find(".title").html(args.title);
  1125. transformControls.detach()
  1126. })
  1127. })
  1128. var _this = this;
  1129. $("#isSprite").on("change", function(e) {
  1130. _this.editSpot.isSprite = this.checked;
  1131. if (this.checked) {
  1132. _this.editSpot.update(player.camera)
  1133. } else {
  1134. _this.editSpot.mesh.quaternion.copy(_this.editSpot.quaternion)
  1135. }
  1136. })
  1137. $(".webPage .MenuOptions li").on("click", (e)=>{ //链接打开方式切换
  1138. _this.editSpot.linkType = $(e.target).attr("index")
  1139. $(".webPage .MenuOptions li").removeClass("chosen");
  1140. $(e.target).addClass("chosen")
  1141. })
  1142. $("#noAction").on("change", function(e) {
  1143. _this.editSpot.noAction = this.checked;
  1144. })
  1145. }
  1146. //背景音乐
  1147. var EditMiuse = function() {
  1148. this.mediaUpload = $(".music .audio.mediaUpload");
  1149. this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
  1150. uploadMiuse(file, (rs, file)=>{
  1151. if (rs.code === 0) {
  1152. this.musicBox.show(this.mediaUpload, file.name, rs.data)
  1153. }else{
  1154. this.musicBox.hide()
  1155. }
  1156. })
  1157. }, null)
  1158. /* this.success = function(text, url) {
  1159. this.mediaUpload.find(".innerBtn").text("替换");
  1160. this.mediaUpload.find(".playBox").removeClass("hide");
  1161. this.mediaUpload.find(".title").text(text);
  1162. this.mediaUpload.find('#query-bgm').attr('href', url)
  1163. }
  1164. ;
  1165. this.delete = function() {
  1166. this.mediaUpload.find('#query-bgm').attr('href', "");
  1167. this.mediaUpload.find(".playBox").addClass("hide");
  1168. this.mediaUpload.find(".innerBtn").text("上传");
  1169. this.mediaUpload.find("input").val("");
  1170. }
  1171. ;
  1172. var that = this;
  1173. $('#upload-bgm').on('change', function(e) {
  1174. var file = this.files[0];
  1175. uploadMiuse(file, function(rs, file) {
  1176. if (rs.code === 0) {
  1177. that.success(file.name, rs.data)
  1178. }
  1179. })
  1180. e.target.value = null
  1181. });
  1182. //删除音乐
  1183. this.mediaUpload.on("click", ".delete", function() {
  1184. that.delete();
  1185. }) */
  1186. }
  1187. EditMiuse.prototype.init = function(data) {
  1188. if (!data.backgroundMusic)
  1189. return;
  1190. this.musicBox.show(this.mediaUpload, data.bgName || "backgound", data.backgroundMusic);
  1191. }
  1192. //导览编辑
  1193. var EditGuide = function() {
  1194. this.$list = $('#guide-list')
  1195. //$('#tourItemEdit') = $('#tourItemEdit');
  1196. this.targetTourPoint = null;
  1197. // fyz 记录当前编辑的导览点
  1198. // fyz 导览音乐队列
  1199. //this.tourAudio = {};
  1200. }
  1201. /**
  1202. * @author fyz 2019.07.31
  1203. * @description 新增参数data2, 表示data2.js中的数据
  1204. */
  1205. /* function snapATourView(that, renew) {
  1206. var ev = document.createEvent("MouseEvent");
  1207. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1208. g_snapShotWidth = 200;
  1209. g_snapShotHeight = 140;
  1210. window.screenSta = 'tour';
  1211. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1212. ev.__callback = function(imgData, info) {
  1213. that.uploadGuide(imgData, info, renew, that.targetTourPoint)
  1214. }.bind(that);
  1215. window.dispatchEvent(ev);
  1216. } */
  1217. EditGuide.prototype.snapATourView = function(renew, insideFolder){
  1218. var ev = document.createEvent("MouseEvent");
  1219. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1220. g_snapShotWidth = 200;
  1221. g_snapShotHeight = 140;
  1222. window.screenSta = 'tour';
  1223. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1224. ev.__callback = (imgData, info)=> {
  1225. this.uploadGuide(imgData, info, renew, insideFolder)
  1226. };
  1227. window.dispatchEvent(ev);
  1228. }
  1229. EditGuide.prototype.init = function(data, data2) {
  1230. this.createDom(data, data2);
  1231. //this.tourAudio = data2.tourAudio || {};
  1232. var that = this;
  1233. //点击添加导览
  1234. $('.addTour .innerBtn').eq(0).on("click", function () {
  1235. this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
  1236. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
  1237. }.bind(this));
  1238. $('.addTour .innerBtn').eq(1).on("click", function () {
  1239. this.snapATourView()//点击截取视图
  1240. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
  1241. }.bind(this));
  1242. $('.snapATourView .innerBtn').on("click", function() {
  1243. this.snapATourView(null,true);//folder内点击截取视图
  1244. $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
  1245. }.bind(this));
  1246. $('#renewTourBtn').on("click", function() { // 重新截取视图
  1247. this.snapATourView(this, !!this.editingFolderLi);
  1248. }.bind(this));
  1249. // 确认并保存导览信息
  1250. $('#tourFolderEdit .tourSubmit').on("click", function() {
  1251. this.completeFolder();
  1252. }.bind(this));
  1253. $('#tourItemEdit .tourSubmit').on("click", function() {
  1254. this.completeItem();
  1255. }.bind(this));
  1256. //点击导览编辑窗口右上角的关闭按钮
  1257. /* $("#tourItemEdit a.close, button.cancel").on("click", function() {
  1258. that.targetTourPoint[0].musicSta = true; ///??????????
  1259. // 取消操作, 重置状态
  1260. that.tourDetail.addClass("atRight");
  1261. }); */
  1262. //导览目录
  1263. $("#tourList").on("click", function(e) {
  1264. var target = $(e.target);
  1265. let folder = searchParent(e.target, { className: 'listItem' }, 7);
  1266. if(!folder)return;//可能点到了item
  1267. if (target.hasClass("del")) {
  1268. e.stopPropagation();
  1269. target.siblings(".DelConfirm").addClass("active");
  1270. } else {
  1271. if (target.hasClass("DelConfirm")) {
  1272. e.stopPropagation();
  1273. $(folder).remove()
  1274. //that.removeFolder(folder);//删除
  1275. } else {
  1276. if (target.hasClass("title") || target.hasClass("icon")) {
  1277. that.editFolder(folder)//编辑
  1278. }
  1279. }
  1280. }
  1281. });
  1282. //编辑item
  1283. $('.tourList ul').on('click', function(e) {
  1284. var target = $(e.target);
  1285. let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
  1286. if(!itemDom)return;//可能点到了folder
  1287. if(searchParent(e.target, { className: 'preview' })){
  1288. var choice = confirm("你确定删除吗?");
  1289. if (choice) {
  1290. var ul = searchParent(e.target, { className: 'tourList' })
  1291. target.closest('li').remove();
  1292. reIndexTourList(ul)
  1293. } else {
  1294. return false
  1295. }
  1296. }else{
  1297. that.editItem(itemDom);
  1298. }
  1299. })
  1300. //fyz 拖拽以改变顺序
  1301. let tourListNode = $("#tourList>ul")[0];
  1302. let tourItemListNode = $("#tourItemList>ul")[0];
  1303. let draging = null;
  1304. let dragStart = (event)=> {
  1305. event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
  1306. draging = event.target;
  1307. }
  1308. let dragOver = (event)=>{
  1309. event.preventDefault();
  1310. let target = searchParent(event.target, { tagName: 'LI' }, 7); //event.target.parentNode.parentNode;
  1311. // 判断dragover是否发生在LI元素上
  1312. if ((target.classList.contains('guideItem') || target.classList.contains('listItem')) && target !== draging ) {
  1313. let dragingIndex = $(draging).index()//draging.querySelector('#index');
  1314. let targetIndex = $(target).index()//target.querySelector('#index');
  1315. var targetRect = target.getBoundingClientRect();
  1316. var dragingRect = draging.getBoundingClientRect();
  1317. if (target && target.animated) {
  1318. return;
  1319. }
  1320. let ulElem = target.parentNode;
  1321. // 寻找到 ul节点
  1322. if (getIndex(draging) < getIndex(target)) {
  1323. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1324. // 交换两个节点的序号
  1325. if(event.clientY<targetRect.top+targetRect.height*0.3)return
  1326. ulElem.insertBefore(draging, target.nextSibling);
  1327. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];// 交换两个节点的序号
  1328. } else {
  1329. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1330. if(event.clientY>targetRect.bottom-targetRect.height*0.3)return
  1331. ulElem.insertBefore(draging, target);
  1332. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1333. }
  1334. _animate(dragingRect, draging);
  1335. _animate(targetRect, target);
  1336. var ul = searchParent(event.target, { className: 'tourList' })
  1337. reIndexTourList(ul)
  1338. }
  1339. }
  1340. tourListNode.ondragstart = dragStart
  1341. tourItemListNode.ondragstart = dragStart
  1342. tourListNode.ondragover = dragOver
  1343. tourItemListNode.ondragover = dragOver
  1344. //音乐
  1345. this.musicBox = musicPlayBoxBind($(".snapTour .audio.mediaUpload"), null, ()=>{
  1346. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  1347. })
  1348. /*
  1349. var mediaUpload = $(".snapTour .audio.mediaUpload");
  1350. var that = this;
  1351. mediaUpload.find("input").on("change", function(e) {
  1352. if(!e.target.files.length) return;
  1353. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1354. var file = e.target.files[0];
  1355. mediaDom.find(".innerBtn").text("替换");
  1356. mediaDom.find(".playBox").removeClass("hide");
  1357. mediaDom.find(".title").text(file.name);
  1358. mediaDom.find('#query-bgm').attr('href', URL.createObjectURL(file));
  1359. //that.editingFolderLi.musicSta = true;
  1360. });
  1361. mediaUpload.find("input").on("click", function() {
  1362. mediaUpload
  1363. });
  1364. //删除音乐
  1365. mediaUpload.on("click", ".delete", function(e) {
  1366. var mediaDom = $(searchParent(e.target, { className: '.mediaUpload' }));
  1367. mediaDom.find('#query-bgm').attr('href', "");
  1368. mediaDom.find(".playBox").addClass("hide");
  1369. mediaDom.find(".innerBtn").text("上传");
  1370. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1371. //that.editingFolderLi.musicSta = false;
  1372. (that.editingFolderLi || that.editingItemLi).data.musicInfo = {}//直接删除 不可逆
  1373. }) */
  1374. }
  1375. function musicPlayBoxBind($dom, addCallback, delCallback){
  1376. var musicBox = {
  1377. hasMusic:false,
  1378. show: function(mediaDom, name, url){
  1379. mediaDom = mediaDom || $dom
  1380. mediaDom.find(".innerBtn").text("替换");
  1381. mediaDom.find(".playBox").removeClass("hide");
  1382. mediaDom.find(".title").text(name);
  1383. mediaDom.find('#query-bgm').attr('href', url);
  1384. musicBox.hasMusic = true
  1385. },
  1386. addMusic : function(e) {
  1387. if(!e.target.files.length) return;
  1388. var file = e.target.files[0];
  1389. if (!/audio\/\w+/.test(file.type)) {
  1390. alert("文件必须为音乐!");
  1391. return false;
  1392. }
  1393. //限制大小不大于8m
  1394. if (!restrictedSize(file, _musicMaxWeight)) {
  1395. return false
  1396. }
  1397. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1398. musicBox.show(mediaDom, file.name, URL.createObjectURL(file))
  1399. addCallback && addCallback(file)
  1400. },
  1401. hide : function(e) {
  1402. var mediaDom = e ? $(searchParent(e.target, { className: 'mediaUpload' })) : $dom
  1403. mediaDom.find('#query-bgm').attr('href', "");
  1404. mediaDom.find(".playBox").addClass("hide");
  1405. mediaDom.find(".innerBtn").text("上传");
  1406. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1407. musicBox.hasMusic = false
  1408. delCallback && delCallback()
  1409. }
  1410. }
  1411. $dom.find("input").on("change", musicBox.addMusic)
  1412. /* $dom.find("input").on("click", function() {
  1413. mediaUpload
  1414. }); */
  1415. //删除音乐
  1416. $dom.on("click", ".delete", musicBox.hide)
  1417. return musicBox;
  1418. }
  1419. function reIndexTourList(ul) {
  1420. Array.from($(ul).find('li.guideItem')).forEach((li,index)=>{
  1421. $(li).find("div:first-child span").text(index + 1);
  1422. })
  1423. }
  1424. EditGuide.prototype.addFolderDom = function( tourData){
  1425. var $folder = $("<li class='listItem' draggable='true'>" + "<div class=icon></div>" + "<div class=title >" + (tourData.name || "") + "</div>" + "<div class=DelConfirm>确定删除</div>" + "<div class=del></div>" + "</li>");
  1426. $folder[0].tourItemDoms = [] //记录所有item的li dom
  1427. $folder[0].tourData = tourData //注: data中的locations不会更新,保存时直接读取li
  1428. $("#tourList ul").append($folder);
  1429. return $folder
  1430. }
  1431. EditGuide.prototype.getItemDom = function(title, img) {
  1432. return '<li draggable="true" class="guideItem">' + '<div>' + '<span id="index"></span>' + '<div class="line"></div>' + '</div>' + '<div>' + '<span class="guide-name" >' + title + '</span>' + '<input maxlength="14" class="hide" data-oper=tour-input>' + '</div>' + '<div class="preview" >' + '<div id="tourBg" style="background-image: url(' + img + ');" >' + '</div>' + '</div>' + '</li >';
  1433. }
  1434. EditGuide.prototype.createDom = function(data, data2) {
  1435. var that = this;
  1436. var tourAudio = data2.tourAudio || {};
  1437. data.model.images.forEach((Info,index)=>{
  1438. if(Info.locations){//是folder
  1439. var $folder = this.addFolderDom(Info)
  1440. // 音频链接
  1441. Info.locations = Info.locations.filter(e=>e)
  1442. Info.locations.forEach(function(info, index) {
  1443. if (info.thumbnail_signed_src) {
  1444. var $li = $(that.getItemDom( info.name, info.thumbnail_signed_src));
  1445. $li[0].tourData = info
  1446. $folder[0].tourItemDoms.push($li[0])
  1447. }
  1448. })
  1449. }else{//是散落在外的item
  1450. if (Info.thumbnail_signed_src) {
  1451. var $li = $(that.getItemDom(Info.name, Info.thumbnail_signed_src));
  1452. $li[0].tourData = Info
  1453. // 音频链接
  1454. $li[0].tourData.musicInfo = $li[0].tourData.musicInfo || tourAudio[Info.sid] || {}//新的music数据统一写在每个info下
  1455. $("#tourList ul").append($li)
  1456. /* if (Info.sid in tourAudio && tourAudio[info.sid].music && tourAudio[info.sid].music !== '') {
  1457. //$li[0].musicUrl = tourAudio[info.sid].music;
  1458. $li[0].musicInfo = tourAudio[info.sid]
  1459. } */
  1460. }
  1461. }
  1462. })
  1463. reIndexTourList($("#tourList")[0])
  1464. }
  1465. //暂时不实时更新左侧场景,所以信息全写在UI上,不保存data
  1466. EditGuide.prototype.editFolder = function(folderDom){
  1467. this.editingFolderLi = folderDom;
  1468. $("#tourFolderEdit").removeClass('atRight');
  1469. $("#tourFolderEdit .tourName input").val( $(folderDom).find('.title').text()||'');
  1470. $("#folderTourSwitch input").prop('checked', folderDom.tourData.momentTour === 'black');
  1471. folderDom.tourItemDoms.forEach(li=>{
  1472. $("#tourItemList>ul").append(li)
  1473. })
  1474. reIndexTourList($("#tourItemList>ul")[0])
  1475. //判断当前点是否有导览音频
  1476. //target[0].musicSta = true;
  1477. //var audio = this.tourAudio[target.closest('li')[0].data.sid];
  1478. var musicInfo = this.editingFolderLi.tourData.musicInfo //audio ? audio.music : null;
  1479. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1480. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1481. /* $('#tourFolderEdit').find(".audio .playBox").removeClass("hide");
  1482. $('#tourFolderEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1483. $('#tourFolderEdit').find(".audio .submit").text("替换");
  1484. $('#tourFolderEdit').find(".title").text(musicName); */
  1485. this.musicBox.show($('#tourFolderEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1486. } else {
  1487. /* $('#tourFolderEdit').find(".audio .playBox").addClass("hide");
  1488. $('#tourFolderEdit').find(".audio .submit").text("上传"); */
  1489. this.musicBox.hide()
  1490. }
  1491. }
  1492. /**
  1493. * @author fyz 编辑单个导览item
  1494. * @param {any} target 所点击的导览点
  1495. */
  1496. EditGuide.prototype.editItem = function(li) {
  1497. //this.targetTourPoint = target;
  1498. this.editingItemLi = li
  1499. // 记录当前编辑的导览点
  1500. var that = this;
  1501. $('#tourItemEdit').removeClass('atRight');
  1502. $('#tourItemEdit .tourName input').val( $(li).find('.guide-name').text() );
  1503. var metadata = JSON.parse(li.tourData.metadata);
  1504. if(metadata.scan_id != 'outside'){
  1505. var pano = player.model.panos.index[metadata.scan_id]
  1506. if(pano){
  1507. var q = new THREE.Quaternion().copy(metadata.camera_quaternion);
  1508. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(pano.position);
  1509. player.flyToPano({
  1510. pano: pano,
  1511. lookAtPoint: lookAtPoint
  1512. })
  1513. }
  1514. }
  1515. if(!this.editingFolderLi){//在外的item, 可以上传音乐
  1516. $('#tourItemEdit .mediaUpload').removeClass('hide')
  1517. var musicInfo = li.tourData.musicInfo //audio ? audio.music : null;
  1518. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1519. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1520. /* $('#tourItemEdit').find(".audio .playBox").removeClass("hide");
  1521. $('#tourItemEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1522. $('#tourItemEdit').find(".audio .submit").text("替换");
  1523. $('#tourItemEdit').find(".title").text(musicName); */
  1524. this.musicBox.show($('#tourItemEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1525. } else {
  1526. this.musicBox.hide()
  1527. /* $('#tourItemEdit').find(".audio .playBox").addClass("hide");
  1528. $('#tourItemEdit').find(".audio .submit").text("上传"); */
  1529. }
  1530. }else{
  1531. $('#tourItemEdit .mediaUpload').addClass('hide')
  1532. }
  1533. }
  1534. EditGuide.prototype.completeFolder = function(){//点击完成
  1535. var tourName = $('#tourFolderEdit .tourName input').val() //|| this.targetTourPoint.context.innerText;
  1536. $(this.editingFolderLi).find(".title").text(tourName)
  1537. this.editingFolderLi.tourData.momentTour = $("#folderTourSwitch input").is(':checked') ? "black" : 'walk'
  1538. this.editingFolderLi.tourItemDoms = Array.from($('#tourItemList ul li'));
  1539. var done = ()=>{
  1540. $("#tourFolderEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1541. this.editingFolderLi = null
  1542. $("#tourFolderEdit").addClass('atRight');
  1543. $(".edit-loading").addClass('hide');
  1544. $("#tourItemList>ul").html('')
  1545. }
  1546. //save导览音乐
  1547. var tourAudio = $('#tourFolderEdit .mediaUpload input');
  1548. // 记录音频名称
  1549. //判断当前编辑的导览点位是否已上传音乐
  1550. if (tourAudio[0].files.length > 0/* && this.targetTourPoint[0].musicSta */) { //有input文件
  1551. $(".edit-loading").removeClass('hide');
  1552. var musicName = $('#tourFolderEdit .mediaUpload .title').text();
  1553. new Promise( (resolve, reject)=> {
  1554. uploadMiuse(tourAudio[0].files[0], function(res) {
  1555. resolve(res.data);
  1556. })
  1557. } ).then( (src)=>{
  1558. var audio = new Audio();
  1559. audio.src = src;
  1560. audio.onloadedmetadata = ()=>{
  1561. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1562. srcArr[0] = '';
  1563. src = srcArr.join('/');
  1564. //var sid = this.editingFolderLi.data.sid
  1565. //that.tourAudio[sid] = {
  1566. this.editingFolderLi.tourData.musicInfo = {
  1567. "name": musicName,
  1568. "music": '/' + src,
  1569. "time": Math.round(audio.duration * 1000 + 1000)
  1570. }
  1571. done()
  1572. }
  1573. })
  1574. }else done()
  1575. }
  1576. EditGuide.prototype.completeItem = function() {//点击完成
  1577. var done = ()=>{
  1578. $("#tourItemEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1579. this.editingItemLi = null
  1580. $("#tourItemEdit").addClass('atRight');
  1581. $(".edit-loading").addClass('hide');
  1582. }
  1583. var tourName = $('#tourItemEdit .tourName input').val()
  1584. $(this.editingItemLi).find('.guide-name').text(tourName)
  1585. //save导览音乐
  1586. var tourAudio = $('#tourItemEdit .mediaUpload input');
  1587. //判断当前编辑的导览点位是否已上传音乐
  1588. if (!this.editingFolderLi && tourAudio[0].files.length > 0) { //有input文件
  1589. $(".edit-loading").removeClass('hide');
  1590. var musicName = $('#tourItemEdit .mediaUpload .title').text();
  1591. new Promise( (resolve, reject)=>{
  1592. uploadMiuse(tourAudio[0].files[0], function(res) {
  1593. resolve(res.data);
  1594. })
  1595. } ).then( (src)=>{
  1596. var audio = new Audio();
  1597. audio.src = src;
  1598. audio.onloadedmetadata = ()=>{
  1599. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1600. srcArr[0] = '';
  1601. src = srcArr.join('/');
  1602. //that.tourAudio[sid] = {
  1603. this.editingItemLi.tourData.musicInfo = {
  1604. "name": musicName,
  1605. "music": '/' + src,
  1606. "time": Math.round(audio.duration * 1000 + 1000)
  1607. }
  1608. done()
  1609. }
  1610. })
  1611. }else done()
  1612. }
  1613. /**
  1614. * @author fyz 2019.07.31
  1615. * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
  1616. */
  1617. EditGuide.prototype.uploadGuide = function(urlData, guide, renew, insideFolder) {
  1618. var that = this;
  1619. uploadImg(urlData, function(rs) {
  1620. if (rs.code === 0) {
  1621. //var editGuide = new EditGuide();
  1622. var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
  1623. var thumbnail_signed_src = rs.data;
  1624. var args = JSON.parse("{" + guide + "}");
  1625. args.sid = sid;
  1626. args.name = sid;
  1627. args.thumbnail_signed_src = thumbnail_signed_src;
  1628. args.metadata = JSON.stringify({
  1629. camera_mode: args.metadata.camera_mode,
  1630. camera_position: {
  1631. x: args.metadata.camera_position[0],
  1632. y: args.metadata.camera_position[1],
  1633. z: args.metadata.camera_position[2]
  1634. },
  1635. camera_quaternion: {
  1636. x: args.metadata.camera_quaternion[0],
  1637. y: args.metadata.camera_quaternion[1],
  1638. z: args.metadata.camera_quaternion[2],
  1639. w: args.metadata.camera_quaternion[3]
  1640. },
  1641. ortho_zoom: args.metadata.ortho_zoom,
  1642. scan_id: args.metadata.scan_id || "outside",
  1643. //这个"outside"不能随便改成别的
  1644. /* final_angle: 110,
  1645. is_ortho: false, */
  1646. zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
  1647. })
  1648. if (renew/* && target */) { // 重新录制导览
  1649. // 更新数据
  1650. var musicInfo = insideFolder || that.editingItemLi.tourData.musicInfo;
  1651. musicInfo && (args.musicInfo = musicInfo);
  1652. $(that.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
  1653. //args.name = insideFolder $('#tourItemEdit').find('#tourNameInput').val()
  1654. /* var oldId = target.closest('li')[0].data.sid;
  1655. that.tourAudio[args.sid] = that.tourAudio[oldId];
  1656. // 新生成的id指向以前的导览音频
  1657. delete that.tourAudio[oldId];
  1658. // 删除导览音频中的旧导览id */
  1659. that.editingItemLi.tourData = args;
  1660. //target.text(args.name); // 更新导览列表中的导览名称 //不改名字
  1661. //$('#tourItemEdit').find('#tourNameInput').val(args.name); // 修改输入框内容
  1662. } else {
  1663. var $li = $(that.getItemDom(args.name, args.thumbnail_signed_src));
  1664. $li[0].tourData = args;
  1665. var $ul = insideFolder ? $("#tourItemList>ul") : $("#tourList>ul")
  1666. $ul.append($li);
  1667. reIndexTourList($ul[0])
  1668. }
  1669. }
  1670. })
  1671. }
  1672. EditGuide.prototype.getSavingInfo = function(){
  1673. var data = []
  1674. Array.from($("#tourList ul li")).forEach(dom=>{
  1675. if(dom.classList.contains("guideItem")){//item
  1676. dom.tourData.name = $(dom).find('.guide-name').text()
  1677. data.push(dom.tourData)
  1678. }else{//folder
  1679. var dataFolder = dom.tourData;
  1680. dataFolder.name = $(dom).find('.title').text()
  1681. dataFolder.locations = dom.tourItemDoms.map(li => li.tourData )
  1682. data.push(dataFolder)
  1683. }
  1684. })
  1685. return data
  1686. }
  1687. /* -- 以下是一些公用的方法 -- */
  1688. //限制大小
  1689. var restrictedSize = function(file, _size) {
  1690. //限制大小不大于8m
  1691. var fileSize = 0;
  1692. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  1693. if (isIE && !file) {
  1694. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  1695. var _file = fileSystem.GetFile(filepath);
  1696. fileSize = _file.Size;
  1697. } else {
  1698. fileSize = file.size;
  1699. }
  1700. var size = fileSize / 1024;
  1701. var RSize = _size * 1024;
  1702. if (size > RSize) {
  1703. alert("文件不能大于" + _size + "M");
  1704. return false;
  1705. }
  1706. if (size <= 0) {
  1707. alert("文件大小不能为0M!");
  1708. return false;
  1709. }
  1710. return true
  1711. }
  1712. //上传音乐
  1713. var uploadMiuse = function(file, callback) {
  1714. uploadFile(file, 'audio', callback);
  1715. }
  1716. $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
  1717. //上传图片
  1718. function uploadImg(urlData, callback, fileName) {
  1719. //console.log('urlData',urlData);
  1720. var bytes = window.atob(urlData.split(',')[1]);
  1721. //去掉url的头,并转换为byte
  1722. //处理异常,将ascii码小于0的转换为大于0
  1723. var ab = new ArrayBuffer(bytes.length);
  1724. var ia = new Uint8Array(ab);
  1725. for (var i = 0; i < bytes.length; i++) {
  1726. ia[i] = bytes.charCodeAt(i);
  1727. }
  1728. var blob = new Blob([ab],{
  1729. type: 'image/jpeg',
  1730. });
  1731. uploadFile(blob, 'hot/images', callback, fileName);
  1732. }
  1733. //上传文件
  1734. function uploadFile(file, type, callback, fileName) {
  1735. $(".edit-loading").removeClass("hide");
  1736. var formData = new FormData()
  1737. formData.append('name', number)
  1738. formData.append('dir', type)
  1739. formData.append('random', true)
  1740. //formData.append('file', file)
  1741. formData.append("file", file, fileName);
  1742. let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
  1743. $.ajax({
  1744. url: ceshi + url,
  1745. data: formData,
  1746. headers: {
  1747. token: token
  1748. },
  1749. dataType: 'json',
  1750. type: 'POST',
  1751. cache: false,
  1752. //上传文件无需缓存
  1753. processData: false,
  1754. //用于对data参数进行序列化处理 这里必须false
  1755. contentType: false,
  1756. //必须
  1757. success: function(rs) {
  1758. if (rs.code === 5001) {
  1759. alert('请重新登录')
  1760. localStorage.dcj_token = ''
  1761. location.reload()
  1762. }
  1763. callback(rs, file);
  1764. $(".edit-loading").addClass("hide");
  1765. }
  1766. })
  1767. }
  1768. function _animate(prevRect, target) {
  1769. var ms = 300;
  1770. if (ms) {
  1771. var currentRect = target.getBoundingClientRect();
  1772. if (prevRect.nodeType === 1) {
  1773. prevRect = prevRect.getBoundingClientRect();
  1774. }
  1775. _css(target, 'transition', 'none');
  1776. _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' + (prevRect.top - currentRect.top) + 'px,0)');
  1777. target.offsetWidth;
  1778. // 触发重绘
  1779. //放在timeout里面也可以
  1780. // setTimeout(function() {
  1781. // _css(target, 'transition', 'all ' + ms + 'ms');
  1782. // _css(target, 'transform', 'translate3d(0,0,0)');
  1783. // }, 0);
  1784. _css(target, 'transition', 'all ' + ms + 'ms');
  1785. _css(target, 'transform', 'translate3d(0,0,0)');
  1786. clearTimeout(target.animated);
  1787. target.animated = setTimeout(function() {
  1788. _css(target, 'transition', '');
  1789. _css(target, 'transform', '');
  1790. target.animated = false;
  1791. }, ms);
  1792. }
  1793. }
  1794. //给元素添加style
  1795. function _css(el, prop, val) {
  1796. var style = el && el.style;
  1797. if (style) {
  1798. if (val === void 0) {
  1799. if (document.defaultView && document.defaultView.getComputedStyle) {
  1800. val = document.defaultView.getComputedStyle(el, '');
  1801. } else if (el.currentStyle) {
  1802. val = el.currentStyle;
  1803. }
  1804. return prop === void 0 ? val : val[prop];
  1805. } else {
  1806. if (!(prop in style)) {
  1807. prop = '-webkit-' + prop;
  1808. }
  1809. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  1810. }
  1811. }
  1812. }
  1813. function upload($files, type, cb) {
  1814. var length = $files.length
  1815. var rcount = 0
  1816. var result = []
  1817. Array.from($files).forEach(function(dFile, index) {
  1818. //a 标签的success 是用来判断是否是已经上传过的文件
  1819. //attr-thum 属性是视频的图片
  1820. //videoURL 是判断是否有视频
  1821. var $file = $(dFile)
  1822. var $image = type == 'videos' ? $file.find('img.play-video') : $file.find('img')
  1823. if ($file.hasClass('success')) {//已经上传过,有链接
  1824. if ($file.attr('attr-thum')) {//视频的封面
  1825. result[index] = $file.attr('attr-thum')
  1826. } else if ($image.attr('videoURL')) {//视频
  1827. result[index] = $image.attr('videoURL')
  1828. } else {
  1829. result[index] = $image.attr('src')
  1830. }
  1831. return success(++rcount);
  1832. } else {
  1833. switch ($file[0].localName) {
  1834. case "input":
  1835. dFile = $file[0]
  1836. break;
  1837. case "span"://封面
  1838. dFile = $file.find('input')[0];
  1839. break;
  1840. case "a"://重传的图or视频
  1841. dFile = {files:[$file[0].file]}
  1842. //dFile = $file.find('input')[0];
  1843. break;
  1844. default:
  1845. dFile = $file.closest("li").find('.upload input')[0];
  1846. break;
  1847. }
  1848. // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
  1849. }
  1850. var file = (dFile.files && dFile.files[0]) || '';
  1851. if (!file)
  1852. return success(++rcount);
  1853. uploadFile(file, 'hot/' + type, function(rs) {
  1854. //似乎所有图保存路径都是这个hot/前缀。图地址 :"场景id/edit/重新生成的文件名.原后缀", 展示页面也是。
  1855. if (rs.code === 0) {
  1856. result[index] = rs.data
  1857. }
  1858. ;success(++rcount);
  1859. })
  1860. })
  1861. //判断当前队列元素是否处理成功
  1862. function success() {
  1863. if (rcount === length) {
  1864. cb(result)
  1865. }
  1866. }
  1867. success()
  1868. }
  1869. function getIndex(el) {
  1870. let index = 0;
  1871. if (!el || !el.parentNode) {
  1872. return -1;
  1873. }
  1874. while (el && (el = el.previousElementSibling)) {
  1875. index++;
  1876. }
  1877. return index;
  1878. }
  1879. dataURLtoBlob = function(dataurl) {
  1880. //将base64转换blob
  1881. var arr = dataurl.split(',')
  1882. , mime = arr[0].match(/:(.*?);/)[1]
  1883. , bstr = atob(arr[1])
  1884. , n = bstr.length
  1885. , u8arr = new Uint8Array(n);
  1886. while (n--) {
  1887. u8arr[n] = bstr.charCodeAt(n);
  1888. }
  1889. return new Blob([u8arr],{
  1890. type: mime
  1891. });
  1892. }
  1893. ;
  1894. //=========================
  1895. var eachMaxWeights = {
  1896. //大小限制
  1897. "photo": 10,
  1898. "video": 1000,//50, expand size for overlayVideo
  1899. //20,
  1900. "audio": 10 //5
  1901. }
  1902. var supportTypes = {
  1903. //支持后缀
  1904. "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
  1905. "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */
  1906. ],
  1907. "video": ["mp4", "mov"/* ,"webm", "rmvb", "wmv" */
  1908. ]//ios:mov
  1909. }
  1910. function getExt(name) {
  1911. //后缀
  1912. if (name.indexOf('.') > -1) {
  1913. var a = name.split(".");
  1914. return a.pop();
  1915. } else {
  1916. return '';
  1917. }
  1918. }
  1919. function detectType(fileName) {
  1920. //检测文件后缀类型
  1921. console.log("名:" + fileName)
  1922. var ext = getExt(fileName);
  1923. console.log("后缀:" + ext)
  1924. //不一定所有浏览器都可以
  1925. var type;
  1926. //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
  1927. for (var i in supportTypes) {
  1928. if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
  1929. type = i;
  1930. break;
  1931. }
  1932. }
  1933. if (type) {
  1934. return type;
  1935. } else {
  1936. return false;
  1937. }
  1938. }
  1939. //手机上的相片会不会太大?
  1940. var detectWeights = function(file, type) {
  1941. //检测大小
  1942. var size = file.size / 1024 / 1024;
  1943. console.log("weight" + size)
  1944. var over;
  1945. if (size > eachMaxWeights[type]) {
  1946. over = Math.ceil(size * 100) / 100;
  1947. }
  1948. return over;
  1949. }
  1950. var exitUpload = function(input) {
  1951. $('.waiting').removeClass('showloading');
  1952. input.value = "";
  1953. }
  1954. var inputMedia = function(options, type, e) {
  1955. var input = e.target;
  1956. if (!window.FileReader) {
  1957. alert('您的浏览器不支持上传文件');
  1958. exitUpload(input);
  1959. return;
  1960. } else if (e.target.files.length === 0) {
  1961. /* exitUpload(input); */
  1962. return;
  1963. }
  1964. $('.waiting').addClass('showloading');
  1965. var file = e.target.files[0];
  1966. var elemType = type;
  1967. var inputType = detectType(file.name);
  1968. var chType = {
  1969. "photo": '图片',
  1970. "video": '视频',
  1971. "audio": '音乐'
  1972. }
  1973. var overWeight = detectWeights(file, inputType);
  1974. if (elemType) {
  1975. //有指定其中一种类型
  1976. if (inputType != elemType) {
  1977. alert("您选择的不是浏览器支持的" + chType[elemType] + '文件,请重新选择');
  1978. exitUpload(e.target);
  1979. return;
  1980. }
  1981. } else {
  1982. if (!options.enableTypes.includes(inputType)) {
  1983. var text = "";
  1984. options.enableTypes.forEach((type,index)=>{
  1985. text += ((index != 0 ? " / " : "") + chType[elemType])
  1986. }
  1987. )
  1988. alert("您选择的不是浏览器支持的" + text + '文件,请重新选择');
  1989. exitUpload(e.target);
  1990. return;
  1991. }
  1992. }
  1993. if (overWeight) {
  1994. alert(`文件过大(${overWeight}兆),不能大于${eachMaxWeights[inputType]} 兆`)
  1995. exitUpload(e.target);
  1996. return;
  1997. }
  1998. var loadError = function() {
  1999. exitUpload(e.target);
  2000. alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
  2001. }
  2002. deal();
  2003. function deal(fi) {
  2004. console.log('开始deal文件')
  2005. var reader = new FileReader();
  2006. //reader.name = file.name;
  2007. file = fi || file;
  2008. reader.readAsDataURL(file);
  2009. reader.onload = function(evt) {
  2010. var blob = dataURLtoBlob(evt.target.result);
  2011. var blobSrc = window.URL.createObjectURL(blob);
  2012. if (inputType == "photo") {
  2013. /* EXIF.getData(file, function () {
  2014. //获取相片旋转
  2015. EXIF.getAllTags(this);
  2016. var orient = EXIF.getTag(this, 'Orientation');
  2017. var img = new Image();
  2018. img.src = evt.target.result;
  2019. img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
  2020. var smallerImg = CompressImg(e.target, {
  2021. weight: blob.size,
  2022. maxWeight: 0.5 * 1024 * 1024,
  2023. maxSize: 1480
  2024. });
  2025. //最大500k
  2026. smallerImg.onload = function () {
  2027. var f = function (resultImg) {//处理结束回调
  2028. options.photoDone(resultImg)
  2029. $('.waiting').removeClass('showloading');
  2030. }
  2031. Rotate(smallerImg, orient, f)
  2032. window.URL.revokeObjectURL(blobSrc);
  2033. }
  2034. }
  2035. .bind(this)
  2036. img.onerror = loadError;
  2037. }); */
  2038. var img = new Image();
  2039. img.src = blobSrc;
  2040. img.base64Src = evt.target.result;
  2041. img.file = file;
  2042. img.onload = function(e) {
  2043. options.photoDone(img)
  2044. $('.waiting').removeClass('showloading');
  2045. }
  2046. } else if (inputType == "video") {
  2047. var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
  2048. video.setAttribute("crossOrigin", 'Anonymous')
  2049. //要在src设置好前解决跨域
  2050. $(video).on('contextmenu', function() {
  2051. return false;
  2052. });
  2053. //禁止右键点击出现选项(尤其是下载选项)
  2054. $(video).attr('src', blobSrc);
  2055. //华为无法使用blobSrc,否则加载不出来
  2056. //$(video).attr('src', evt.target.result);
  2057. video.base64Src = evt.target.result;
  2058. var hasload = false;
  2059. var error = false;
  2060. var up = function() {
  2061. if (hasload)
  2062. return;
  2063. hasload = true;
  2064. options.videoDone(file, video)
  2065. $('.waiting').removeClass('showloading');
  2066. }
  2067. video.addEventListener('loadeddata', function(e) {
  2068. up()
  2069. })
  2070. //video.onerror = loadError;
  2071. video.onerror = function(e) {
  2072. console.log('error')
  2073. error = true;
  2074. loadError();
  2075. //将mp4改成mov后缀会error
  2076. }
  2077. } else if (inputType == "audio") {
  2078. //林俊波 new Howl For IE&Safari:
  2079. var sound = new Howl({
  2080. src: [blobSrc],
  2081. format: ["mp3"]
  2082. });
  2083. // Clear listener after first call.
  2084. sound.once('load', function() {
  2085. console.log('loaded sound')
  2086. sound.unload()
  2087. console.log("audio.onloadeddata");
  2088. var audio = new Audio;
  2089. audio.controls = "controls";
  2090. audio.src = blobSrc;
  2091. audio.base64Src = evt.target.result;
  2092. options.audioDone(file, audio)
  2093. $('.waiting').removeClass('showloading');
  2094. //}
  2095. });
  2096. sound.once('loaderror', function() {
  2097. loadError.apply(this, arguments)
  2098. console.log('loaderror sound')
  2099. });
  2100. // Fires when the sound finishes playing.
  2101. sound.on('end', function() {
  2102. console.log('Finished sound');
  2103. });
  2104. }
  2105. }
  2106. }
  2107. e.target.value = "";
  2108. //更改value会触发change
  2109. }
  2110. .bind(player)
  2111. //滑动条控件
  2112. var SlideBar = function(o) {
  2113. var scope = this;
  2114. this.name = o.name;
  2115. this.value = o.value;
  2116. //初始值
  2117. this.min = o.min != void 0 ? o.min : 0;
  2118. this.max = this.oriMax = o.max != void 0 ? o.max : 100;
  2119. this.noValue = o.noValue;
  2120. //是否数值输入
  2121. this.precision = o.precision;
  2122. //精度 保留几位小数
  2123. var div = $('<div><div class="Main"><div class="scrollBar"><div class="scroll_Track"></div><div class="scroll_Thumb"></div></div>' + (o.noValue ? '' : '<div class="BarTxt"><input class="scrollBarTxt"></div></div>'))
  2124. div.addClass('slider')
  2125. if (o.unitStr) {
  2126. div.find(".BarTxt").append($('<span>' + o.unitStr + '</span>'));
  2127. }
  2128. o.root.append(div);
  2129. this.line = $(".scrollBar", div);
  2130. this.knot = $(".scroll_Thumb", div);
  2131. o.noValue || (this.textArea = $(".scrollBarTxt", div));
  2132. this.track = $(".scroll_Track", div);
  2133. this.unitStr = o.unitStr;
  2134. //unitStr是单位字符串,比如角度的°。不能是数字
  2135. this.onchange = o.onchange;
  2136. this.percent = null;
  2137. this.dragStart = false;
  2138. this.offsetToBody = null;
  2139. this.getOffset();
  2140. this.checkError();
  2141. this.percent = this.getPercent();
  2142. o.noValue || this.displayValue();
  2143. this.moveKnot();
  2144. this.knotWidth = 0;
  2145. this.lineWidth = 0;
  2146. //this.waitValue;//等待要触发事件的值,防止崩溃
  2147. this.avoidCrash = o.avoidCrash;
  2148. this.realMax = !this.noValue ? o.realMax : null;
  2149. //如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
  2150. this.scrollUnit = (scope.max - scope.min) * 0.001;
  2151. if (this.precision != void 0) {
  2152. var prec = Math.pow(10, -this.precision);
  2153. this.scrollUnit < prec && (this.scrollUnit = prec);
  2154. } else {
  2155. //默认化为整数
  2156. this.scrollUnit < 1 && (this.scrollUnit = 1);
  2157. }
  2158. this.dragStartEvent = o.dragStartEvent;
  2159. this.line.on("mousedown touchstart", function(event) {
  2160. scope.dragStart = true;
  2161. scope.dragChange(event);
  2162. if (scope.dragStartEvent)
  2163. scope.dragStartEvent()
  2164. //if(o.avoidCrash && isMobile)scope.dealInterval();
  2165. });
  2166. !window.isMobile && this.line.on("mousewheel DOMMouseScroll wheel", function(event) {
  2167. event.preventDefault();
  2168. var v = event.originalEvent.deltaY > 0 ? -scope.scrollUnit : scope.scrollUnit;
  2169. scope.setValue(scope.value + v);
  2170. });
  2171. this.dragEndEvent = o.dragEndEvent;
  2172. var stop = function() {
  2173. if (scope.dragStart) {
  2174. scope.dragStart = false;
  2175. if (scope.dragEndEvent)
  2176. scope.dragEndEvent()
  2177. }
  2178. }
  2179. $(document).on("mouseup touchend", stop)
  2180. /* isMobile || */
  2181. $("#player").on("mouseup", stop)
  2182. var lastChangeTime = 0;
  2183. $(document).on("mousemove touchmove", function() {
  2184. if (scope.dragStart) {
  2185. /* if(isMobile && o.avoidCrash){
  2186. scope.lastDragEvent = event;
  2187. }else */
  2188. scope.dragChange(event);
  2189. }
  2190. })
  2191. o.noValue || this.textArea.on("change", function() {
  2192. var v = parseFloat(scope.textArea.val());
  2193. if (v != v)
  2194. //NaN
  2195. return;
  2196. scope.setValueFromOutside(v);
  2197. });
  2198. window.addEventListener("resize",()=>{
  2199. if(this.line[0].clientWidth){
  2200. this.getOffset()
  2201. this.moveKnot();
  2202. }
  2203. })
  2204. }
  2205. SlideBar.prototype.dealInterval = function() {
  2206. this.interval = setInterval(function() {
  2207. this.lastDragEvent && this.dragChange(this.lastDragEvent);
  2208. this.lastDragEvent = null
  2209. if (!this.dragStart)
  2210. clearInterval(this.interval)
  2211. }
  2212. .bind(this), 90)
  2213. }
  2214. SlideBar.prototype.changeLimit = function(o) {
  2215. if (o.min)
  2216. this.min = o.min;
  2217. if (o.max)
  2218. this.max = o.max;
  2219. }
  2220. SlideBar.prototype.getOffset = function() {
  2221. //为了检测鼠标位置需要获得相对body的offset
  2222. var left = this.line[0].offsetLeft;
  2223. var element = this.line[0];
  2224. while (element = element.offsetParent) {
  2225. left += element.offsetLeft;
  2226. }
  2227. this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
  2228. //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
  2229. }
  2230. SlideBar.prototype.InitOffset = function() {
  2231. //如果一开始scroller没有显示,要在显示时获取一下offset
  2232. this.getOffset();
  2233. this.getWidth();
  2234. this.moveKnot();
  2235. }
  2236. SlideBar.prototype.checkError = function() {
  2237. if (this.min >= this.max) {
  2238. console.log("scrollbar值有误 " + name);
  2239. return;
  2240. }
  2241. }
  2242. SlideBar.prototype.getPercent = function() {
  2243. return (this.value - this.min) / (this.max - this.min);
  2244. }
  2245. SlideBar.prototype.displayValue = function(value) {
  2246. //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
  2247. if (value != void 0)
  2248. this.value = value;
  2249. this.textArea.val(this.value)
  2250. }
  2251. SlideBar.prototype.getWidth = function() {
  2252. this.knotWidth = this.knot.width();
  2253. this.lineWidth = this.line.width() - this.knotWidth
  2254. }
  2255. SlideBar.prototype.moveKnot = function() {
  2256. //this.getWidth();
  2257. var width = this.percent * this.lineWidth;
  2258. this.knot.css('left', width + "px")
  2259. if (this.track)
  2260. this.track.css('width', (width + this.knotWidth / 2) + "px")
  2261. }
  2262. SlideBar.prototype.bind = function(f) {
  2263. this.onchange = f;
  2264. }
  2265. SlideBar.prototype.setValue = function(v, noEvent, changeMax) {
  2266. //设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
  2267. //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
  2268. if (this.precision != void 0) {
  2269. this.value = parseFloat(v.toFixed(this.precision))
  2270. } else {
  2271. //默认化为整数
  2272. this.value = Math.round(v);
  2273. }
  2274. if (changeMax && this.realMax != void 0) {
  2275. if (this.value > this.oriMax) {
  2276. this.value = Math.min(this.value, this.realMax);
  2277. this.changeLimit({
  2278. max: this.value
  2279. })
  2280. } else {
  2281. this.changeLimit({
  2282. max: this.oriMax
  2283. })
  2284. }
  2285. }
  2286. this.percent = this.getPercent();
  2287. var makeit = true;
  2288. if (this.onchange && !noEvent) {
  2289. var result = this.onchange(this.value);
  2290. //如果执行的函数不允许这个值,就不能变
  2291. if (result === false) {
  2292. makeit = false;
  2293. }
  2294. }
  2295. if (makeit) {
  2296. this.moveKnot();
  2297. //console.log("SlideBarV-"+this.name + " : "+this.value)
  2298. this.noValue || this.displayValue();
  2299. }
  2300. }
  2301. SlideBar.prototype.dragChange = function(event) {
  2302. //拖动时触发 计算数值
  2303. //this.getWidth();
  2304. //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
  2305. if (event.clientX != void 0) {
  2306. this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2307. } else {
  2308. if (event.touches != void 0) {
  2309. this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2310. } else
  2311. this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2312. }
  2313. if (this.percent < 0)
  2314. this.percent = 0;
  2315. else if (this.percent > 1)
  2316. this.percent = 1;
  2317. //var v = this.percent * this.max;
  2318. var v = this.percent * (this.max - this.min) + this.min;
  2319. //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
  2320. if (this.value == v)
  2321. return;
  2322. this.setValue(v);
  2323. }
  2324. SlideBar.prototype.setValueFromOutside = function(v) {
  2325. //外面的事件触发的
  2326. if (this.line.width() == 0)
  2327. return;
  2328. //不可见就不执行。
  2329. //v = Math.round(v*10)/10;
  2330. if (this.realMax != void 0) {
  2331. v = THREE.Math.clamp(v, this.min, this.realMax);
  2332. if (v > this.max)
  2333. this.changeLimit({
  2334. max: v
  2335. });
  2336. } else
  2337. v = THREE.Math.clamp(v, this.min, this.max);
  2338. this.setValue(v);
  2339. }
  2340. //-----------------------------------------------------
  2341. var LineDraw = {
  2342. createLine: function(posArr, o) {
  2343. var e = new THREE.BufferGeometry
  2344. , p = new Float32Array(6);
  2345. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  2346. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  2347. var p = e.attributes.position.array;
  2348. for (var i = 0; i < 2; i++) {
  2349. p[i * 3] = posArr[i].x;
  2350. p[i * 3 + 1] = posArr[i].y;
  2351. p[i * 3 + 2] = posArr[i].z;
  2352. }
  2353. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  2354. linewidth: o.width || 1,
  2355. //windows无效。 似乎mac/ios上粗细有效 ?
  2356. color: o.color || defaultColor,
  2357. transparent: o.dontAlwaysSeen ? false : true,
  2358. depthTest: o.dontAlwaysSeen ? true : false
  2359. })
  2360. var line = new THREE.Line(e,mat);
  2361. line.renderOrder = o.renderOrder || 4
  2362. //同tagStem; //如果不加高,可能会部分被model遮住
  2363. return line;
  2364. }
  2365. }
  2366. var toPrecision = function(e, t) {
  2367. function i(e, t) {
  2368. var i = Math.pow(10, t);
  2369. return Math.round(e * i) / i
  2370. }
  2371. if (e instanceof Array) {
  2372. for (var n = 0; n < e.length; n++)
  2373. e[n] = i(e[n], t);
  2374. return e
  2375. }
  2376. return i(e, t)
  2377. }
  2378. var transformControls;
  2379. var initTransformCtl = function(THREE) {
  2380. TransformControls.init(THREE)
  2381. TransformControls.prototype.transCtlChangeMode = function(mode) {
  2382. //if(!this.editing)return;
  2383. if (mode && this.mode != mode) {
  2384. this.mode = mode;
  2385. $(".MenuOptions[name='transform'] li").removeClass("chosen");
  2386. $(".MenuOptions[name='transform'] li[index='" + mode + "']").addClass("chosen");
  2387. }
  2388. }
  2389. ,
  2390. transformControls = new TransformControls(player.camera,player.domElement,{
  2391. player: player,
  2392. dontHideWhenFaceCamera: true,
  2393. scaleAxis: ["x", "y"],
  2394. //隐藏了z轴。虽然参数没用上
  2395. NoScaleZ: true //整体缩放时只缩放xy轴。
  2396. });
  2397. transformControls.space = 'local'//为了在当前方向上平移
  2398. transformControls.setSize(1.5)
  2399. player.model.add(transformControls)
  2400. $(".MenuOptions[name='transform'] li").on("click", (e)=>{
  2401. transformControls.transCtlChangeMode($(e.target).attr("index"))
  2402. }
  2403. )
  2404. }
  2405. var EditOverlay = {
  2406. editing: false,
  2407. overlayMaxCount: 10,
  2408. scroller: {
  2409. videoDepth: new SlideBar({
  2410. root: $('#videoDepth').eq(0),
  2411. value: settings.overlay.depth * 100,
  2412. min: 0 * 100,
  2413. max: 1 * 100,
  2414. name: "videoDepth",
  2415. unitStr: "cm",
  2416. avoidCrash: true,
  2417. onchange: function(s) {
  2418. if (s == 0) {
  2419. EditOverlay.editPlane.addBox(false)
  2420. } else {
  2421. EditOverlay.editPlane.addBox(true)
  2422. EditOverlay.editPlane.scale.z = s / 100 / settings.overlay.depth;
  2423. }
  2424. },
  2425. dragEndEvent: function() {
  2426. }
  2427. })
  2428. },
  2429. panoPosSwitch : $('#setOverlayPosForPano input') // 当前漫游点独立调整位置开关
  2430. ,
  2431. init: function(THREE) {
  2432. var mat = new THREE.MeshBasicMaterial({
  2433. wireframe: true,
  2434. opacity: 0.5,
  2435. color: "#57e4f3",
  2436. transparent: true
  2437. })
  2438. var wireframeModel = this.wireframeModel = new THREE.Object3D;
  2439. wireframeModel.name = 'wireframeModel'
  2440. player.model.chunks.forEach((mesh)=>{
  2441. var chunk = mesh.clone();
  2442. chunk.material = mat;
  2443. wireframeModel.add(chunk)
  2444. }
  2445. )
  2446. wireframeModel.visible = false
  2447. player.model.add(wireframeModel)
  2448. //------------------------------
  2449. this.panoPosSwitch.on("change", this.panoPosSwitchOnChange.bind(this))
  2450. $('.overlay .addBtn button').on("click", this.beginToAddPlane.bind(this))
  2451. $("#overlayProp a.close").on("click", ()=>{
  2452. this.closeOverlayPanel("cancel")
  2453. }
  2454. )
  2455. $("#overlayProp button.submit").on("click", (e)=>{
  2456. this.SaveOverlay()
  2457. }
  2458. )
  2459. $("#overlayProp button.delete").on("click", (e)=>{
  2460. this.DeleteOverlay();
  2461. }
  2462. )
  2463. $('#overlayUpload [name="useImgRatio"] button').on("click", this.useImgRatio.bind(this));
  2464. var uploadInputs = {
  2465. video : $('<input type="file" style="display:none" accept="video/*"></input>'),
  2466. photo : $('<input type="file" style="display:none" accept="image/*"></input>')
  2467. }
  2468. $('#overlayUpload [name="upload"] button').on('click', ()=>{
  2469. uploadInputs[this.editType].click()
  2470. })
  2471. uploadInputs.video.on("change", (e)=>{
  2472. inputMedia({
  2473. enableTypes: [this.editType ],
  2474. videoDone: (file,video)=>{
  2475. var plane = this.editPlane.plane
  2476. $(video).css('width', '100%')
  2477. $(video).css('height', '100%')
  2478. plane.material.map = new THREE.VideoTexture(video);
  2479. plane.material.map.image.play();
  2480. plane.material.map.minFilter = THREE.LinearFilter;
  2481. this.editPlane.overlayType = "video";
  2482. $('#overlayUpload .preview video').remove();
  2483. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2484. video.autoplay = true;
  2485. video.loop = true;
  2486. video.volume = 0
  2487. video.muted = true
  2488. this.useImgRatio()
  2489. //自适应比例
  2490. this.editPlane.file = file;
  2491. plane.material.opacity = 1;
  2492. plane.material.color = new THREE.Color(1,1,1)
  2493. plane.material.needsUpdate = true;
  2494. }
  2495. }, "video", e);
  2496. }
  2497. )
  2498. uploadInputs.photo.on("change", (e)=>{
  2499. inputMedia({
  2500. enableTypes: [this.editType ],
  2501. photoDone: (photo)=>{
  2502. var plane = this.editPlane.plane
  2503. /* $(video).css('width', '100%')
  2504. $(video).css('height', '100%') */
  2505. plane.material.map = new THREE.Texture();
  2506. plane.material.map.image = photo
  2507. plane.material.map.needsUpdate = !0
  2508. plane.material.map.minFilter = THREE.LinearFilter;
  2509. this.editPlane.overlayType = "photo";
  2510. $('#overlayUpload .preview video').remove();
  2511. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2512. this.useImgRatio()
  2513. //自适应比例
  2514. this.editPlane.file = photo.file;
  2515. plane.material.opacity = 1;
  2516. plane.material.color = new THREE.Color(1,1,1)
  2517. plane.material.needsUpdate = true;
  2518. }
  2519. }, "photo", e);
  2520. }
  2521. )
  2522. player.overlayGroup.children.forEach((overlay)=>{
  2523. if(!overlay.plane.material.map || !overlay.plane.material.map.image){
  2524. overlay._loadDones = [()=>{this.getOverlayInfo(overlay)}]
  2525. }
  2526. else {
  2527. this.getOverlayInfo(overlay)
  2528. }
  2529. this.addToList(overlay)
  2530. }
  2531. )
  2532. },
  2533. enter: function() {
  2534. this.editing = true;
  2535. this.wireframeModel.visible = true;
  2536. },
  2537. leave: function() {
  2538. if (!this.editing)
  2539. return;
  2540. this.editing = false
  2541. $("#overlayProp a.close").click();
  2542. this.endAddPlane();
  2543. this.wireframeModel.visible = false;
  2544. },
  2545. switchEditType : function(type){
  2546. this.editType = type;
  2547. $('#overlayUpload [name="upload"] button').text(type == 'video' ? "上传视频" : "上传图片")
  2548. $('#overlayUpload .preview span').text(type == 'video' ? "支持MP4、MOV等,<20M" : "支持jpg、png等,<20M");
  2549. },
  2550. beginToAddPlane: function(event) {
  2551. this.switchEditType($(event.target).attr("data-type"))
  2552. player.reticule.visible = false;
  2553. this.objCursorType = 'overlay';
  2554. player.currentCursor = 'url(images/edit/box_video.png), auto'
  2555. $('#player').css('cursor', player.currentCursor)
  2556. $('.overlay .addBtn button').addClass("unable")
  2557. //可以加多个视频时的按钮
  2558. },
  2559. endAddPlane: function() {
  2560. this.objCursorType = null;
  2561. player.currentCursor = '';
  2562. $('#player').css('cursor', '')
  2563. $('.overlay .addBtn button').removeClass("unable")
  2564. player.reticule.visible = true
  2565. },
  2566. addPlane: function(o) {
  2567. if(!o.intersect)return;
  2568. var pos = o.intersect.point;
  2569. var overlay = new Overlay({
  2570. sid: new Date().getTime() + ""
  2571. })
  2572. overlay.hasRequestLoad = true
  2573. overlay.position.copy(pos);
  2574. if (player.getMouseDirection().angleTo(o.intersect.face.normal) < Math.PI / 2) {
  2575. overlay.lookAt(o.intersect.face.normal.clone().negate().add(pos));
  2576. overlay.position.add(o.intersect.face.normal.clone().negate().multiplyScalar(0.01))
  2577. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  2578. } else {
  2579. overlay.lookAt(o.intersect.face.normal.clone().add(pos));
  2580. overlay.position.add(o.intersect.face.normal.clone().multiplyScalar(0.01))
  2581. }
  2582. overlay.posCustom = overlay.position.clone();
  2583. overlay.quaCustom = overlay.quaternion.clone();
  2584. overlay.widthCustom = overlay.width;
  2585. overlay.heightCustom = overlay.height;
  2586. overlay.isNew = true
  2587. player.clickOverlay(overlay)
  2588. transformControls.transCtlChangeMode("translate")
  2589. this.addToList(overlay)
  2590. },
  2591. updateOverlayScaleDisplay: function() {
  2592. var overlay = this.editPlane;
  2593. var maxWidth = 193
  2594. , maxHeight = maxWidth
  2595. //maxWidth/2;
  2596. var ratioW = Math.abs(overlay.width) / maxWidth;
  2597. var ratioH = Math.abs(overlay.height) / maxHeight;
  2598. var ratio = 1 / Math.max(ratioW, ratioH);
  2599. //缩放比例
  2600. var w = Math.round(Math.abs(overlay.width) * ratio)
  2601. var h = Math.round(Math.abs(overlay.height) * ratio)
  2602. $('#overlayUpload .preview').css({
  2603. "width": w + 'px',
  2604. "height": h + 'px',
  2605. });
  2606. $('#overlayUpload .preview [attr-type="width"]').text(toPrecision(overlay.width, 2))
  2607. $('#overlayUpload .preview [attr-type="height"]').text(toPrecision(overlay.height, 2))
  2608. },
  2609. updateOverlayPanel: function(overlay) {
  2610. this.editPlane = overlay;
  2611. overlay.requestDownload()
  2612. if(overlay._loadDones){
  2613. $('.waiting').addClass('showloading');
  2614. overlay._loadDones.push(()=>{
  2615. $('.waiting').removeClass('showloading');
  2616. })
  2617. }
  2618. var plane = overlay.plane
  2619. var src = plane.material.map && (plane.material.map.image ? plane.material.map.image.src : overlay.fileSrc );
  2620. $('#overlayUpload .preview video').remove();
  2621. overlay.overlayType && this.switchEditType(overlay.overlayType)
  2622. if (overlay.overlayType == "video") {
  2623. var video = plane.material.map.image
  2624. $('#overlayUpload .preview').css({'background-image':"", 'background-size':""}).append(video);
  2625. } else if(overlay.overlayType == "photo" || overlay.overlayType == "text"){
  2626. $('#overlayUpload .preview').css({
  2627. 'background-image': src ? ("url(" + src + ")") : "",
  2628. 'background-size': "contain"
  2629. })
  2630. }else{
  2631. $('#overlayUpload .preview').css({
  2632. 'background-image': "",
  2633. 'background-size': ""
  2634. })
  2635. }
  2636. if (overlay.overlayType) {
  2637. $('#overlayUpload [name="useImgRatio"]').removeClass("hide")
  2638. $('#overlayUpload .preview').addClass('uploaded')
  2639. } else {
  2640. $('#overlayUpload [name="useImgRatio"]').addClass("hide")
  2641. $('#overlayUpload .preview').removeClass('uploaded')
  2642. }
  2643. this.updateOverlayScaleDisplay()
  2644. if (overlay.hasBox) {
  2645. this.scroller.videoDepth.setValue(overlay.scale.z * settings.overlay.depth * 100, true)
  2646. } else {
  2647. this.scroller.videoDepth.setValue(0, true)
  2648. }
  2649. setTimeout(()=>{
  2650. this.scroller.videoDepth.InitOffset()
  2651. }
  2652. , 201)
  2653. player.currentPano && this.updatePano(player.currentPano)
  2654. },
  2655. //----------------------------
  2656. panoPosSwitchOnChange : function(){
  2657. var on = this.panoPosSwitch.is(':checked')
  2658. if(!on) delete this.editPlane.transformAtPanos[player.currentPano.id]
  2659. }
  2660. ,
  2661. getTransformAtPano : function(){
  2662. this.editPlane.transformAtPanos[player.currentPano.id] = {
  2663. pos : this.editPlane.position.clone(),
  2664. qua : this.editPlane.quaternion.clone(),
  2665. width : this.editPlane.width,
  2666. height : this.editPlane.height,
  2667. }
  2668. },
  2669. updatePosition:function(){
  2670. var on = this.panoPosSwitch.is(':checked')
  2671. if(on && player.mode == 'panorama'){
  2672. this.getTransformAtPano()
  2673. }else{
  2674. this.editPlane.posCustom.copy(this.editPlane.position)
  2675. }
  2676. },
  2677. updateScale : function(){
  2678. var on = this.panoPosSwitch.is(':checked')
  2679. var size = this.editPlane.getSizeByScale( )
  2680. this.editPlane.width = size.width
  2681. this.editPlane.height = size.height
  2682. if(on && player.mode == 'panorama'){
  2683. this.getTransformAtPano()
  2684. }else{
  2685. this.editPlane.widthCustom = this.editPlane.width
  2686. this.editPlane.heightCustom = this.editPlane.height
  2687. }
  2688. this.updateOverlayScaleDisplay()
  2689. }
  2690. ,
  2691. updateQua : function(){
  2692. var on = this.panoPosSwitch.is(':checked')
  2693. if(on && player.mode == 'panorama'){
  2694. this.getTransformAtPano()
  2695. }else{
  2696. this.editPlane.quaCustom.copy(this.editPlane.quaternion)
  2697. }
  2698. }
  2699. ,
  2700. updatePano:function(pano){
  2701. if(!EditOverlay.editPlane ) return;
  2702. this.panoPosSwitch.prop('checked', !!EditOverlay.editPlane.transformAtPanos[pano.id]);
  2703. },
  2704. //------------------------------
  2705. closeOverlayPanel: function(type) {
  2706. if (!this.editPlane)
  2707. return;
  2708. if (type == 'cancel') {
  2709. if (!this.editPlane.isNew && !this.editPlane.needDelete)
  2710. this.editPlane.setFromInfo(this.editPlane.info)
  2711. //this.setOverlayFromInfo(this.editPlane, this.editPlane.info);//恢复
  2712. else
  2713. this.disposeOverlay(this.editPlane);
  2714. //删除
  2715. }
  2716. this.editPlane = null;
  2717. transformControls.detach()
  2718. $("#overlayProp").addClass("atRight");
  2719. //if(player.model.overlayPlanes.length < this.overlayMaxCount) this.beginToAddPlane()
  2720. },
  2721. useImgRatio: function(o) {
  2722. var plane = this.editPlane.plane;
  2723. if (!plane.material.map)
  2724. return;
  2725. var img = plane.material.map.image;
  2726. var mintranRatio = 200;
  2727. //default is 200 , 防止图片太小时在墙上依旧很大
  2728. var width = this.editPlane.overlayType == "video" ? img.videoWidth : img.width;
  2729. var height = this.editPlane.overlayType == "video" ? img.videoHeight : img.height;
  2730. if (o == "suitSize") {
  2731. var boundWidth = Math.min(Math.max(width, height) / mintranRatio, 1)
  2732. if (width > height) {
  2733. var w = boundWidth;
  2734. var h = boundWidth * height / width
  2735. } else {
  2736. var h = boundWidth;
  2737. var w = boundWidth * width / height;
  2738. }
  2739. } else {
  2740. //假设不变总面积
  2741. var k = Math.sqrt(Math.abs(this.editPlane.width * this.editPlane.height) / (width * height))
  2742. var w = k * width * (this.editPlane.width < 0 ? -1 : 1);
  2743. var h = k * height * (this.editPlane.height < 0 ? -1 : 1);
  2744. }
  2745. this.editPlane.scale.setX(w / settings.overlay.width)
  2746. this.editPlane.scale.setY(h / settings.overlay.height)
  2747. this.editPlane.width = w;
  2748. this.editPlane.height = h;
  2749. this.updateScale()
  2750. this.updateOverlayPanel(this.editPlane)
  2751. },
  2752. getOverlayInfo: function(overlay) {
  2753. //2 编辑前, 从当前状态获取info
  2754. var plane = overlay.plane;
  2755. var transformAtPanos = {}
  2756. for(var i in overlay.transformAtPanos){
  2757. transformAtPanos[i] = {
  2758. width : overlay.transformAtPanos[i].width,
  2759. height : overlay.transformAtPanos[i].height,
  2760. pos : overlay.transformAtPanos[i].pos.clone(),
  2761. qua : overlay.transformAtPanos[i].qua.clone(),
  2762. }
  2763. }
  2764. overlay.info = {
  2765. width: overlay.widthCustom,
  2766. height: overlay.heightCustom,
  2767. depth: settings.overlay.depth * overlay.scale.z,
  2768. pos: overlay.posCustom.clone(),
  2769. qua: overlay.quaCustom.clone(),
  2770. media: plane.material.map.image,
  2771. file: overlay.file,
  2772. type: overlay.overlayType,
  2773. hasBox: overlay.hasBox,
  2774. transformAtPanos: transformAtPanos
  2775. }
  2776. },
  2777. getSavingInfo: function(overlay) {
  2778. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  2779. return;
  2780. }
  2781. var transformAtPanos = {}
  2782. for(var i in overlay.transformAtPanos){
  2783. transformAtPanos[i] = {
  2784. width : toPrecision(overlay.transformAtPanos[i].width, 4),
  2785. height : toPrecision(overlay.transformAtPanos[i].height, 4),
  2786. pos : toPrecision(overlay.transformAtPanos[i].pos.toArray(), 3),
  2787. qua : toPrecision(overlay.transformAtPanos[i].qua.toArray(), 5)
  2788. }
  2789. }
  2790. var info = {
  2791. width: toPrecision(overlay.widthCustom, 4),
  2792. height: toPrecision(overlay.heightCustom, 4),
  2793. depth: toPrecision(settings.overlay.depth * overlay.scale.z, 4),
  2794. pos: toPrecision(overlay.posCustom.toArray(), 3),
  2795. qua: toPrecision(overlay.quaCustom.toArray(), 5),
  2796. sid: overlay.sid,
  2797. hasBox: overlay.hasBox ? 1 : 0,
  2798. media: [overlay.overlayType],
  2799. file: overlay.fileSrc || overlay.plane.material.map.image.src,
  2800. transformAtPanos : transformAtPanos
  2801. }
  2802. return info
  2803. },
  2804. SaveOverlay: function() {
  2805. var overlay = this.editPlane;
  2806. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  2807. this.editType == "video" ? alert("请上传视频") : alert("请上传图片");
  2808. return;
  2809. }
  2810. var saveInfo = ()=>{
  2811. //overlay.savingInfo = JSON.stringify(info)//准备写入的info
  2812. //saveDone:
  2813. overlay.isNew = false;
  2814. this.getOverlayInfo(overlay);
  2815. this.closeOverlayPanel()
  2816. $('.waiting').removeClass('showloading');
  2817. }
  2818. if (!overlay.info || overlay.file != overlay.info.file) {
  2819. $('.waiting').addClass('showloading');
  2820. uploadFile(overlay.file, 'overlay', function(rs) {
  2821. if (rs.code === 0) {
  2822. overlay.fileSrc = rs.data;
  2823. saveInfo()
  2824. }
  2825. ;
  2826. })
  2827. } else
  2828. saveInfo();
  2829. },
  2830. disposeOverlay: function(overlay) {
  2831. var plane = overlay.plane
  2832. if (overlay == player.hoveringPlane) {
  2833. player.hoverOverlay(null, "soon");
  2834. }
  2835. if (plane.material.map) {//删除视频src
  2836. //overlay.info && common.destroyBlob(overlay.info.media.src)
  2837. //common.destroyBlob(plane.material.map.image.src)
  2838. }
  2839. plane.material.dispose();
  2840. overlay.parent.remove(overlay);
  2841. this.removeFromList(overlay)
  2842. //this.beginToAddPlane()
  2843. },
  2844. DeleteOverlay: function() {
  2845. var overlay = this.editPlane;
  2846. if (!overlay.isNew) {
  2847. if (confirm(overlay.overlayType== "photo" ? "确定删除该图片?" : "确定删除该视频?")) {
  2848. overlay.needDelete = true;
  2849. $("#overlayProp a.close").click()
  2850. //this.closeOverlayPanel()
  2851. }
  2852. } else {
  2853. //刚创建时的删除按钮等同于取消按钮
  2854. $("#overlayProp a.close").click()
  2855. //this.closeOverlayPanel()
  2856. }
  2857. },
  2858. addToList: function(overlay) {
  2859. var li = $(`<li class='listItem'><div class="icon"></div><div class="title">${(overlay.overlayType == "video" ? "视频 ":"图片 ")+ overlay.sid}</div></li>`)
  2860. $(".overlayList ul").append(li);
  2861. li.on("click", ()=>{
  2862. player.clickOverlay(overlay)
  2863. }
  2864. )
  2865. overlay.domLi = li;
  2866. },
  2867. removeFromList: function(overlay) {
  2868. overlay.domLi.remove();
  2869. }
  2870. }
  2871. //----------------漫游可见性---------------------------------
  2872. var VisiSet = {
  2873. setPanoVisible: false,
  2874. setTagVisible: false,
  2875. panoVLines: {},
  2876. //线条
  2877. panoVTemp: {},
  2878. //修改后还没保存的临时数据
  2879. tagVsetting: null,
  2880. //正在设置的热点中心点
  2881. tagsVLines: {},
  2882. //线条
  2883. //tagVTemp //修改后还没保存的临时数据
  2884. //热点可见性
  2885. $confirmSnap: $("#camera-start"),
  2886. colors: {
  2887. green: "#00c8ae"
  2888. },
  2889. init: function() {
  2890. this.meshGroup = new THREE.Object3D;
  2891. this.meshGroup.name = "setVisible-group"
  2892. player.model.add(this.meshGroup)
  2893. $("#hotVisible").on("click", ()=>{
  2894. VisiSet.enterSet(VisiSet.beginSetTagVisible.bind(VisiSet))
  2895. }
  2896. )
  2897. },
  2898. enterSet: function(fun) {
  2899. var enter = function() {
  2900. if (player.modeTran.split('-')[1] != "floorplan") {
  2901. setTimeout(fun, 300)
  2902. //提前一点出现
  2903. }
  2904. player.flyToMode("floorplan", fun);
  2905. }
  2906. permitTranMode(false)
  2907. if (!player.modeTran) {
  2908. player.afterCModeFuc = ()=>{
  2909. enter()
  2910. }
  2911. } else
  2912. enter()
  2913. },
  2914. beginSetPanoVisible: function() {
  2915. $(".toolLeft").removeClass("unable")
  2916. if (this.setPanoVisible)
  2917. return;
  2918. this.setPanoVisible = true;
  2919. this.panoVTemp = {};
  2920. this.SetOnePanoVisible(player.currentPano)
  2921. //先设置currentPano
  2922. this.$confirmSnap.text('保存当前设置').removeClass("hide")
  2923. //objects.tagManager.hideAllTags();
  2924. this.setDisplay(true)
  2925. this.updateFootIconSize()
  2926. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  2927. for(let i in player.model.hots){
  2928. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  2929. player.model.hots[i].mesh.visible = false
  2930. }
  2931. },
  2932. SetOnePanoVisible: function(pano) {
  2933. //点击某个pano后就对该pano点进行设置
  2934. if (this.panoVsetting == pano)
  2935. return;
  2936. //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
  2937. this.panoVsetting = pano;
  2938. //记录正在修改的
  2939. this.delVisibleLines();
  2940. //删除线
  2941. this.showFootIcons(pano, true);
  2942. this.createPanoVisiLines(pano);
  2943. //创线
  2944. },
  2945. saveLastPanoVi: function() {
  2946. //保存刚设置过的pano
  2947. var change = [];
  2948. for (var r in this.panoVLines) {
  2949. var line = this.panoVLines[r];
  2950. if (line.name.indexOf("new") > -1 && line.visible) {
  2951. //新设置为visible且没有取消
  2952. change.push({
  2953. type: "add",
  2954. id: r
  2955. })
  2956. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  2957. //旧的且已经取消
  2958. change.push({
  2959. type: "sub",
  2960. id: r
  2961. })
  2962. }
  2963. }
  2964. if (change.length) {
  2965. //添加双向的neighbour:
  2966. var self = this.searchNeib(this.panoVsetting.id)
  2967. //var seeMarkers_self = self.seeMarkers;
  2968. var neighbourUUIDs_self = self.neighbourUUIDs
  2969. var neighbourPanos_self = self.neighbourPanos;
  2970. for (var i = 0; i < change.length; i++) {
  2971. var other = this.searchNeib(change[i].id)
  2972. //var seeMarkers = other.seeMarkers;
  2973. var neighbourUUIDs = other.neighbourUUIDs;
  2974. var neighbourPanos = other.neighbourPanos;
  2975. if (change[i].type == "add") {
  2976. //seeMarkers.push(this.panoVsetting.id);
  2977. neighbourUUIDs.push(this.panoVsetting.id);
  2978. neighbourPanos[this.panoVsetting.id] = true;
  2979. //seeMarkers_self.push(change[i].id);
  2980. neighbourUUIDs_self.push(change[i].id);
  2981. neighbourPanos_self[change[i].id] = true;
  2982. } else {
  2983. //var index = seeMarkers.indexOf(this.panoVsetting.id);
  2984. //index > -1 && seeMarkers.splice(index, 1);
  2985. var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
  2986. index > -1 && neighbourUUIDs.splice(index, 1);
  2987. neighbourPanos[this.panoVsetting.id] = false;
  2988. //var index = seeMarkers_self.indexOf(change[i].id);
  2989. //index > -1 && seeMarkers_self.splice(index, 1);
  2990. var index = neighbourUUIDs_self.indexOf(change[i].id);
  2991. index > -1 && neighbourUUIDs_self.splice(index, 1);
  2992. neighbourPanos_self[change[i].id] = false;
  2993. }
  2994. this.panoVTemp[change[i].id] = {
  2995. //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
  2996. neighbourPanos: neighbourPanos,
  2997. //seeMarkers: seeMarkers,
  2998. neighbourUUIDs: neighbourUUIDs
  2999. }
  3000. }
  3001. this.panoVTemp[this.panoVsetting.id] = {
  3002. //加上自己
  3003. neighbourPanos: neighbourPanos_self,
  3004. //seeMarkers: seeMarkers_self,
  3005. neighbourUUIDs: neighbourUUIDs_self
  3006. }
  3007. }
  3008. },
  3009. pauseSetPanoVisible: function(type) {
  3010. //暂停 因为点击了保存设置 但没有退出设置
  3011. if (!this.setPanoVisible)
  3012. return;
  3013. if (type == "unsaved") {
  3014. //中途点击pano从而停止一个热点的设置
  3015. this.saveLastPanoVi();
  3016. } else {
  3017. this.panoVTemp = {};
  3018. //清空数据
  3019. }
  3020. this.delVisibleLines();
  3021. this.showFootIcons();
  3022. //清空选择
  3023. var lastPanoSetting = this.panoVsetting;
  3024. this.panoVsetting = null;
  3025. lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))
  3026. //这句要放在this.panoVsetting = null后。 根据可见性更改透明度
  3027. },
  3028. //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
  3029. finishSetPanoVisible: function() {
  3030. //结束 退出这个设置
  3031. if (!this.setPanoVisible)
  3032. return;
  3033. //否则会加多个侦听
  3034. this.setPanoVisible = false;
  3035. this.hideFootIcons();
  3036. this.delVisibleLines();
  3037. //objects.tagManager.showAllTags();
  3038. this.recoverAllState2();
  3039. this.panoVsetting = null;
  3040. this.panoVTemp = {};
  3041. player.flyoutType = null
  3042. this.$confirmSnap.addClass("hide")
  3043. permitTranMode(true)
  3044. this.setDisplay(false)
  3045. for(let i in player.model.hots){
  3046. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3047. }
  3048. },
  3049. recoverAllState2: function() {
  3050. //为了热点可视恢复成pano全部可见
  3051. if(!this.footIcons)return;
  3052. for (var i = 0; i < this.footIcons.length; i++) {
  3053. this.footIcons[i].material.uniforms.opacity.value = 1;
  3054. this.footIcons[i].material.uniforms.map.value = footTex1;
  3055. }
  3056. },
  3057. afterSavePanoVisibles: function() {
  3058. //实施:
  3059. var panos = player.model.panos;
  3060. for (var i in this.panoVTemp) {
  3061. var pano = panos.index[i];
  3062. //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
  3063. pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
  3064. pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
  3065. }
  3066. if (!this.checkHasNeighbor(player.currentPano)) {
  3067. //currentPano变为孤立点 就要换一个防止飞入
  3068. var list = panos.sortByScore([pano=>{
  3069. return this.checkHasNeighbor(pano)
  3070. }
  3071. ], [function(pano) {
  3072. return -pano.position.distanceTo(player.currentPano.position)
  3073. }
  3074. ])
  3075. if (list && list.length) {
  3076. player.currentPano = list[0].pano;
  3077. //找最近的一非孤立点
  3078. //this.noPanoHasNeighbor = false; //更新状态
  3079. } else {//this.noPanoHasNeighbor = true; //更新状态
  3080. }
  3081. } else {//this.noPanoHasNeighbor = false; //更新状态
  3082. }
  3083. //dataDeal.done();
  3084. //暂时:
  3085. this.pauseSetPanoVisible()
  3086. this.updateFootIconSize()
  3087. //更新一下center大小 写在最后
  3088. },
  3089. //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
  3090. savePanoVisibles: function() {
  3091. //保存
  3092. if (this.panoVsetting)
  3093. this.saveLastPanoVi(this.panoVsetting);
  3094. //获取最后设置的那个热点的改动
  3095. var PanoData = [];
  3096. for (var i in this.panoVTemp) {
  3097. PanoData.push({
  3098. //希望算法部不会更改index排序,或者更改后能将visible信息一并更改
  3099. panoID: i,
  3100. //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
  3101. visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
  3102. })
  3103. }
  3104. if (PanoData.length == 0) {
  3105. //没改变
  3106. alert("保存成功")
  3107. return;
  3108. }
  3109. /* this.afterSavePanoVisibles()
  3110. alert("保存成功")
  3111. console.log(JSON.stringify(PanoData)) */
  3112. let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
  3113. $.ajax({
  3114. method: 'POST',
  3115. url: ceshi + url,
  3116. headers: {
  3117. 'Content-Type': 'application/json',
  3118. token: token
  3119. },
  3120. contentType: 'application/json',
  3121. data: JSON.stringify({
  3122. data: JSON.stringify(PanoData),
  3123. sceneCode: window.number
  3124. }),
  3125. success: (data)=>{
  3126. if (data.code === 0) {
  3127. this.afterSavePanoVisibles()
  3128. alert("保存漫游可行成功")
  3129. } else
  3130. alert("保存漫游可行失败")
  3131. if (data.code === 5001) {
  3132. alert('请重新登录')
  3133. localStorage.dcj_token = ''
  3134. location.reload()
  3135. }
  3136. }
  3137. ,
  3138. fail: function() {
  3139. alert("保存漫游可行失败")
  3140. }
  3141. })
  3142. /* var o = {
  3143. name_t: "panoVisible",
  3144. f: this.pauseSetPanoVisible,
  3145. url: Config.prefixEditProPCApi+"/saveLinkPano",
  3146. dialog: i18n.get('设置'),
  3147. data: { data: JSON.stringify(PanoData) }
  3148. }
  3149. var dataDeal = uploadsSaving.saveFucforPC(o);
  3150. dataDeal.group[0] = function () {
  3151. //实施:
  3152. for (var i in player.panoVTemp) {
  3153. var pano = player.model.panos.index[i];
  3154. pano.seeMarkers = player.panoVTemp[i].seeMarkers;
  3155. pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
  3156. pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
  3157. }
  3158. if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
  3159. var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
  3160. [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
  3161. if(list && list.length){
  3162. player.currentPano = list[0].pano;//找最近的一非孤立点
  3163. player.model.noPanoHasNeighbor = false; //更新状态
  3164. }else{
  3165. player.model.noPanoHasNeighbor = true; //更新状态
  3166. }
  3167. }else{
  3168. player.model.noPanoHasNeighbor = false; //更新状态
  3169. }
  3170. dataDeal.done();
  3171. player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
  3172. } */
  3173. },
  3174. searchNeib: function(panoId) {
  3175. //寻找某pano的相关neighbour 可能是修改过的
  3176. var panos = player.model.panos;
  3177. var o = {};
  3178. if (this.panoVTemp[panoId]) {
  3179. //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
  3180. o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
  3181. o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
  3182. } else {
  3183. //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
  3184. o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
  3185. o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
  3186. }
  3187. return o;
  3188. },
  3189. turnToPanoIndex: function(panoArr) {
  3190. var panos = player.model.panos;
  3191. var array = [];
  3192. for (var i = 0; i < panoArr.length; i++) {
  3193. var pano = panos.index[panoArr[i]];
  3194. var index = panos.list.indexOf(pano)
  3195. array.push(index);
  3196. }
  3197. return array;
  3198. },
  3199. setDisplay: function(state) {
  3200. var panos = player.model.panos;
  3201. if (state) {
  3202. } else {
  3203. }
  3204. player.path.currentPanoMarker.mesh.visible = !state;
  3205. player.overlayGroup.visible = !state;
  3206. player.reticule.visible = !state;
  3207. },
  3208. delVisibleLines: function() {
  3209. //xzw add 所有线都删除
  3210. for (var i in this.tagsVLines) {
  3211. this.tagsVLines[i].geometry.dispose();
  3212. this.tagsVLines[i].material.dispose();
  3213. this.meshGroup.remove(this.tagsVLines[i]);
  3214. delete this.tagsVLines[i];
  3215. }
  3216. for (var i in this.panoVLines) {
  3217. this.panoVLines[i].geometry.dispose();
  3218. this.panoVLines[i].material.dispose();
  3219. this.meshGroup.remove(this.panoVLines[i]);
  3220. delete this.panoVLines[i];
  3221. }
  3222. },
  3223. //--------panoVisible
  3224. createPanoVisiLines: function(pano) {
  3225. // pano可见性线条
  3226. var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
  3227. for (var r in neighbours) {
  3228. if (neighbours[r] && r != pano.id) {
  3229. this.createPanoSingleLine(pano, "old", r)
  3230. }
  3231. }
  3232. },
  3233. createPanoSingleLine: function(pano, type, id) {
  3234. //pano是中心
  3235. var panos = player.model.panos;
  3236. var p2 = panos.index[id].floorPosition.clone()
  3237. /* .sub(player.model.position) */
  3238. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3239. , p2], {
  3240. color: this.colors.green
  3241. });
  3242. this.meshGroup.add(line);
  3243. line.name = "PanoVL-" + type + "-" + id;
  3244. this.panoVLines[id] = line;
  3245. this.changeFIconState(panos.index[id].footIcon, "linked")
  3246. },
  3247. dealPanoVisible: function(id) {
  3248. //外部调用
  3249. var panos = player.model.panos;
  3250. if (this.panoVsetting) {
  3251. if (id == this.panoVsetting.id) {
  3252. //关闭当前pano设置
  3253. this.pauseSetPanoVisible('unsaved')
  3254. } else {
  3255. var link;
  3256. //结果是否连接
  3257. if (this.panoVLines[id]) {
  3258. this.panoVLines[id].visible = !this.panoVLines[id].visible;
  3259. link = this.panoVLines[id].visible;
  3260. this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible ? "linked" : false)
  3261. } else {
  3262. this.createPanoSingleLine(this.panoVsetting, "new", id)
  3263. link = true;
  3264. }
  3265. if (link) {
  3266. //如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
  3267. this.changeFIconState2(panos.index[id].footIcon, true)
  3268. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
  3269. } else {
  3270. //否则需要checkHasNeighbor
  3271. this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
  3272. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
  3273. }
  3274. }
  3275. } else {
  3276. //点击开始设置要设置的pano
  3277. this.SetOnePanoVisible(panos.index[id])
  3278. }
  3279. this.updateFootIconSize()
  3280. },
  3281. showFootIcons: function(pano, isPanovisible) {
  3282. if (!this.footIcons) {
  3283. footTex1 = Texture.load("images/edit/End_128.png");
  3284. //Store.FootIcon);
  3285. footTex2 = Texture.load("images/edit/End_unable_128.png");
  3286. //Store.FootIcon_unable);
  3287. this.footIcons = [];
  3288. var scale = 0.4;
  3289. scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));
  3290. //屏幕越小,放得越大
  3291. scale = THREE.Math.clamp(scale, 0.3, 0.7)
  3292. //console.log("scale"+scale)
  3293. var geo = new THREE.PlaneGeometry(scale,scale,1,1)
  3294. var panos = player.model.panos;
  3295. for (var r in panos.index) {
  3296. if (!panos.index[r].isAligned())
  3297. continue;
  3298. var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
  3299. t.map.value = footTex1
  3300. t.color.value.set("#ffffff");
  3301. var mat = new THREE.RawShaderMaterial({
  3302. vertexShader: shaders.waypoint.vertexShader,
  3303. fragmentShader: shaders.waypoint.fragmentShader,
  3304. uniforms: t,
  3305. side: THREE.DoubleSide,
  3306. transparent: !0,
  3307. depthWrite: !1,
  3308. depthTest: false,
  3309. name: "footIcon"
  3310. })
  3311. var foot = new THREE.Mesh(geo,mat)
  3312. foot.position.copy(panos.index[r].floorPosition.clone()/* .sub(player.model.position) */
  3313. )
  3314. foot.lookAt(foot.position.clone().add(new THREE.Vector3(0,1,0)));
  3315. foot.name = panos.index[r].id;
  3316. foot.visible = false;
  3317. foot.renderOrder = 6,
  3318. panos.index[r].footIcon = foot;
  3319. this.meshGroup.add(foot);
  3320. this.footIcons.push(foot)
  3321. }
  3322. }
  3323. for (var i = 0; i < this.footIcons.length; i++) {
  3324. this.footIcons[i].visible = true;
  3325. this.changeFIconState(this.footIcons[i], false)
  3326. var panos = player.model.panos;
  3327. if (isPanovisible) {
  3328. this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
  3329. }
  3330. if (pano && (this.footIcons[i].name == pano.id)) {
  3331. //pano为中心 或者 currentPano 所以放大一点
  3332. this.footIcons[i].oriScale = new THREE.Vector3(1.5,1.5,1.5)
  3333. if (isPanovisible) {
  3334. //currentPano特殊些:
  3335. this.changeFIconState(this.footIcons[i], "center")
  3336. //this.footIcons[i].Unclick = true;//不让点击和hover
  3337. }
  3338. } else {
  3339. this.footIcons[i].oriScale = new THREE.Vector3(1,1,1)
  3340. }
  3341. }
  3342. },
  3343. checkHasNeighbor: function(pano, state) {
  3344. //检查当前状态pano点是否有可通行点
  3345. var neighbours = /* this.panoVTemp && */
  3346. this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
  3347. if (state != "showFoot" && pano == this.panoVsetting) {
  3348. //是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
  3349. for (var i in this.panoVLines) {
  3350. if (this.panoVLines[i].visible) {
  3351. return true;
  3352. //有一条线即可
  3353. }
  3354. }
  3355. return;
  3356. }
  3357. for (var i in neighbours) {
  3358. if (i == pano.id)
  3359. continue;
  3360. if (neighbours[i]) {
  3361. if (this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible)
  3362. continue;
  3363. return true;
  3364. }
  3365. }
  3366. return false;
  3367. },
  3368. /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
  3369. var panos = player.model.panos;
  3370. for(var i in panos.index){
  3371. if(this.checkHasNeighbor(panos.index[i])){
  3372. return false;
  3373. }
  3374. }
  3375. this.noPanoHasNeighbor = true;
  3376. return true;//是全部没有neighbour
  3377. }, */
  3378. changeFIconState: function(footIcon, state) {
  3379. var color = state == "linked" ? this.colors.green : (state == "center" ? /* "#d7f244" */
  3380. "#d5f12e" : "#ffffff");
  3381. footIcon.material.uniforms.color.value.set(color)
  3382. },
  3383. changeFIconState2: function(footIcon, state) {
  3384. //是可见点还是不可见点
  3385. if (state) {
  3386. footIcon.material.uniforms.map.value = footTex1;
  3387. if (this.panoVsetting) {
  3388. if (this.panoVsetting.id != footIcon.name) {
  3389. footIcon.material.uniforms.opacity.value = 1;
  3390. } else {//this.changeVisiBtnState(true)
  3391. }
  3392. }
  3393. } else {
  3394. //不可见
  3395. footIcon.material.uniforms.map.value = footTex2;
  3396. if (!this.panoVsetting || this.panoVsetting.id != footIcon.name) {
  3397. //非中心点时
  3398. footIcon.material.uniforms.opacity.value = 0.5;
  3399. } else {
  3400. //变为中心点时
  3401. footIcon.material.uniforms.opacity.value = 1;
  3402. //this.changeVisiBtnState(false)
  3403. }
  3404. }
  3405. },
  3406. hideFootIcons: function() {
  3407. if (!this.footIcons)
  3408. return;
  3409. for (var i = 0; i < this.footIcons.length; i++) {
  3410. this.footIcons[i].visible = false;
  3411. }
  3412. },
  3413. updateFootIconSize: function() {
  3414. //根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
  3415. if (!this.footIcons)
  3416. return;
  3417. var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8;
  3418. s = THREE.Math.clamp(s, 0.5, 1.4);
  3419. this.footIcons.forEach(function(f) {
  3420. try {
  3421. f.scale.copy(f.oriScale).multiplyScalar(s);
  3422. } catch (e) {
  3423. console.log(e)
  3424. }
  3425. })
  3426. }
  3427. //========热点可见性==============
  3428. ,
  3429. beginSetTagVisible: function() {
  3430. if (this.setTagVisible)
  3431. return;
  3432. $(".toolTop").addClass("unable")
  3433. $("#hotVisible").addClass("unable")
  3434. this.setTagVisible = true;
  3435. this.tagVTemp = {};
  3436. this.$confirmSnap.text('完成设置').removeClass("hide")
  3437. //objects.tagManager.hideAllTags();
  3438. for (let i in player.model.hots) {
  3439. player.model.hots[i]._isSprite = player.model.hots[i].isSprite;
  3440. player.model.hots[i].isSprite = true;
  3441. player.model.hots[i].mesh.material.depthTest = false;
  3442. }
  3443. this.setDisplay(true)
  3444. this.updateFootIconSize()
  3445. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3446. },
  3447. SetOneTagVisible: function(tag) {
  3448. //点击某个热点后就对该热点进行设置,或者在热点修改时对其进行设置
  3449. if (this.tagVsetting == tag)
  3450. return;
  3451. if (this.tagVsetting) {
  3452. this.saveLastTagVi(this.tagVsetting);
  3453. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL);
  3454. }
  3455. this.tagVsetting = tag;
  3456. //记录正在修改的
  3457. this.delVisibleLines();
  3458. //删除线
  3459. this.showFootIcons(player.currentPano);
  3460. this.createTagVisiLines(tag);
  3461. //创线
  3462. this.updateFootIconSize()
  3463. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3464. },
  3465. saveLastTagVi: function() {
  3466. //保存刚设置过的tag
  3467. var change = false;
  3468. var newVPs = this.tagVTemp[this.tagVsetting.sid] || this.tagVsetting.visiblePanos.slice(0);
  3469. for (var r in this.tagsVLines) {
  3470. var line = this.tagsVLines[r];
  3471. if (line.name.indexOf("new") > -1 && line.visible) {
  3472. //新设置为visible且没有取消
  3473. newVPs.push(r)
  3474. change = true;
  3475. //console.log("add: "+r)
  3476. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  3477. //旧的且已经取消
  3478. var i = newVPs.indexOf(r);
  3479. if (i == -1) {
  3480. console.log("visiblePanos删除error");
  3481. continue;
  3482. }
  3483. newVPs.splice(i, 1);
  3484. change = true;
  3485. //console.log("sub: "+r)
  3486. }
  3487. }
  3488. if (change) {
  3489. this.tagVTemp[this.tagVsetting.sid] = newVPs;
  3490. }
  3491. },
  3492. pauseSetTagVisible: function() {
  3493. //pc保存后删除连线 但还在继续设置 点选热点即开始
  3494. if (!this.setTagVisible || !this.tagVsetting)
  3495. return;
  3496. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL );
  3497. this.delVisibleLines();
  3498. this.hideFootIcons();
  3499. this.tagVTemp = {};
  3500. this.tagVsetting = null;
  3501. },
  3502. finishSetTagVisible: function() {
  3503. if (!this.setTagVisible)
  3504. return;
  3505. $(".toolTop").removeClass("unable")
  3506. $("#hotVisible").removeClass("unable")
  3507. this.pauseSetTagVisible();
  3508. this.setTagVisible = false;
  3509. this.setDisplay(false)
  3510. this.$confirmSnap.addClass("hide")
  3511. permitTranMode(true)
  3512. /* for (var r in objects.tagManager.tags) {
  3513. if(objects.tagManager.tags[r].state == "videoPanoFlag")continue;
  3514. objects.tagManager.tags[r].disc.visible = false;
  3515. objects.tagManager.tags[r].disc.material.depthTest = true;
  3516. } */
  3517. for (let i in player.model.hots) {
  3518. player.model.hots[i].isSprite = player.model.hots[i]._isSprite;
  3519. player.model.hots[i].isSprite || player.model.hots[i].mesh.quaternion.copy(player.model.hots[i].quaternion)
  3520. player.model.hots[i].mesh.material.depthTest = true;
  3521. }
  3522. },
  3523. /* saveTagVisibles : function () { //保存到服务器
  3524. if (this.tagVsetting) this.saveLastTagVi(this.tagVsetting); //获取最后设置的那个热点的改动
  3525. //可能出现数据没变但保存的情况。比如先改变了然后切换别的热点但切换回来时又改回来。
  3526. var tags = [];
  3527. for (var i in this.tagVTemp) {
  3528. tags.push({
  3529. sid: i,
  3530. value: this.tagVTemp[i]//turnToPanoIndex(this.tagVTemp[i])
  3531. })
  3532. }
  3533. if (tags.length == 0) {//没有需要保存的改动
  3534. this.finishSetTagVisible()
  3535. return;
  3536. }
  3537. return tags;
  3538. } */
  3539. //afterSaveTagVisibles : function(){
  3540. saveTagVisibles: function() {
  3541. if (this.tagVsetting)
  3542. this.saveLastTagVi(this.tagVsetting);
  3543. for (var i in this.tagVTemp) {
  3544. //保持成功于是生效
  3545. player.model.hots[i].visiblePanos = this.tagVTemp[i];
  3546. }
  3547. this.finishSetTagVisible()
  3548. //还是保存完直接结束吧,因为现在热点可视不放在单独的设置页面了
  3549. },
  3550. createTagVisiLines: function(tag) {
  3551. // 热点可见性线条
  3552. var panos = player.model.panos;
  3553. tag.visiblePanos || tag.setVisiblePanos("get")
  3554. var visibleList = this.tagVTemp[tag.sid] || tag.visiblePanos;
  3555. //如果是刚在设置的要读取设置过的数据
  3556. for (var r = 0; r < visibleList.length; r++) {
  3557. var pano = panos.index[visibleList[r]];
  3558. this.createTagSingleLine(pano, "old", tag)
  3559. }
  3560. },
  3561. createTagSingleLine: function(pano, type, tag) {
  3562. var panos = player.model.panos;
  3563. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3564. , tag.mesh.position.clone()], {
  3565. color: this.colors.green
  3566. });
  3567. this.meshGroup.add(line);
  3568. line.name = "tagVL-" + type + "-" + pano.id;
  3569. this.tagsVLines[pano.id] = line;
  3570. this.changeFIconState(panos.index[pano.id].footIcon, "linked")
  3571. },
  3572. dealTagVisible: function(tag, panoName) {
  3573. //外部调用
  3574. var panos = player.model.panos;
  3575. if (this.tagsVLines[panoName]) {
  3576. this.tagsVLines[panoName].visible = !this.tagsVLines[panoName].visible;
  3577. this.changeFIconState(panos.index[panoName].footIcon, this.tagsVLines[panoName].visible ? "linked" : false)
  3578. } else {
  3579. this.createTagSingleLine(panos.index[panoName], "new", tag)
  3580. }
  3581. },
  3582. delVisibleLines: function() {
  3583. //xzw add 所有线都删除
  3584. for (var i in this.tagsVLines) {
  3585. this.tagsVLines[i].geometry.dispose();
  3586. this.tagsVLines[i].material.dispose();
  3587. this.meshGroup.remove(this.tagsVLines[i]);
  3588. delete this.tagsVLines[i];
  3589. }
  3590. for (var i in this.panoVLines) {
  3591. this.panoVLines[i].geometry.dispose();
  3592. this.panoVLines[i].material.dispose();
  3593. this.meshGroup.remove(this.panoVLines[i]);
  3594. delete this.panoVLines[i];
  3595. }
  3596. }
  3597. }
  3598. function permitTranMode(state) {
  3599. state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
  3600. }
  3601. CloneObject = function(copyObj, result, isSimpleCopy) {
  3602. //isSimpleCopy只复制最外层
  3603. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  3604. result = result || {};
  3605. if (copyObj instanceof Array) {
  3606. if (copyObj[0]instanceof Object) {
  3607. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  3608. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  3609. }
  3610. return copyObj.slice(0);
  3611. //如果是数组,直接复制返回(排除数组内是object
  3612. }
  3613. for (var key in copyObj) {
  3614. if (copyObj[key]instanceof Object && !isSimpleCopy)
  3615. result[key] = CloneObject(copyObj[key]);
  3616. else
  3617. result[key] = copyObj[key];
  3618. //如果是函数类同基本数据,即复制引用
  3619. }
  3620. return result;
  3621. }
  3622. ;
  3623. function randomWord(randomFlag, min, max) {
  3624. //随机字符串
  3625. var str = ""
  3626. , range = min
  3627. , arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
  3628. if (randomFlag) {
  3629. // 随机长度
  3630. range = Math.round(Math.random() * (max - min)) + min;
  3631. }
  3632. for (var i = 0; i < range; i++) {
  3633. var pos = Math.round(Math.random() * (arr.length - 1));
  3634. str += arr[pos];
  3635. }
  3636. return str;
  3637. }
  3638. function getRandomSid() {
  3639. //5-7位随机字符串 + 6位时间 为热点准备
  3640. var pre = randomWord(true, 5, 7);
  3641. var post = new Date().getTime() + "";
  3642. var len = post.length;
  3643. post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)
  3644. //其实还是有可能重复的....
  3645. return pre + post;
  3646. }
  3647. function searchParent(searchArea, o, maxTimes) {
  3648. //是否是某种元素的下级,并找出该元素
  3649. maxTimes = maxTimes || 20;
  3650. var count = 0
  3651. var f = function(dom) {
  3652. if (o.id && o.id == dom.id)
  3653. return dom
  3654. else if (o.className && dom.classList && dom.classList.contains(o.className))
  3655. return dom
  3656. else if (o.tagName && dom.tagName && o.tagName.toUpperCase() == dom.tagName.toUpperCase())
  3657. return dom
  3658. }
  3659. var find;
  3660. while (searchArea && count < maxTimes) {
  3661. if (find = f(searchArea))
  3662. return find
  3663. searchArea = searchArea.parentNode;
  3664. count++;
  3665. }
  3666. }
  3667. //})();