edit.js 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370
  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
  694. var $dom = fnc(file, $din, $seft)// 封面图thumbSuccess的话在此处理
  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. }).then(function(videoUrls) {
  1022. args.video = videoUrls
  1023. //获取视频封面路径
  1024. return new Promise(function(resolve, reject) {
  1025. upload($thums, 'images', resolve)
  1026. })
  1027. }).then(function(thums) {
  1028. args.video = args.video.map(function(video, index) {//整合视频+封面
  1029. return {
  1030. url: video,
  1031. img: thums[index]
  1032. }
  1033. })
  1034. }).then(function() {
  1035. //获取音乐路径
  1036. //console.log($miusc)
  1037. if ($miusc[0].files.length > 0) {
  1038. return new Promise(function(resolve) {
  1039. upload($miusc, 'miusc', function(res) {
  1040. resolve(res[0])
  1041. })
  1042. })
  1043. } else {
  1044. return $miusc.attr('data-hotBgm')
  1045. }
  1046. }).then(function(src) {
  1047. if(that.musicBox.hasMusic && !src){
  1048. args.backgroundMusic = hot.infoAttribute.backgroundMusic
  1049. args.bgName = hot.infoAttribute.bgName
  1050. }else{
  1051. args.backgroundMusic = src
  1052. args.bgName = $bgName[0].innerHTML;
  1053. }
  1054. }).then(function() {
  1055. //上传style图片
  1056. var a = $.Deferred();
  1057. var doneNum = 0;
  1058. if (currStyle == "user" && currentHotStyleImg.length) {
  1059. currentHotStyleImg.forEach((img)=>{
  1060. if (img.needSave)
  1061. uploadFile(img.file, 'hot/image', function(rs) {
  1062. if (rs.code === 0) {
  1063. img.needSave = false;
  1064. img.saveURL = rs.data;
  1065. if (++doneNum >= currentHotStyleImg.length) {
  1066. a.resolve();
  1067. }
  1068. } else {
  1069. alert("样式图上传失败");
  1070. a.reject();
  1071. }
  1072. })
  1073. else if (++doneNum >= currentHotStyleImg.length) {
  1074. a.resolve();
  1075. }
  1076. }
  1077. )
  1078. return a.promise()
  1079. } else
  1080. return a.resolve()
  1081. }).then(()=>{
  1082. //获取style图的信息
  1083. args.styleImg = [];
  1084. if (currStyle == "user") {
  1085. currentHotStyleImg.forEach((img)=>{
  1086. args.styleImg.push(img.saveURL || img.src)
  1087. })
  1088. hot.styleTex = currentHotStyleImg.slice(0)
  1089. } else {
  1090. hot.styleTex = [];
  1091. }
  1092. hot.changeTex();//更新材质
  1093. }
  1094. ).then(function() {
  1095. //获取热点标题、内容、内嵌网页、模型网页。
  1096. args.title = $title.val()
  1097. args.content = $content.val()
  1098. var iframes = []
  1099. for (var i = 0; i < $iframes.length; i++) {
  1100. var iframe = $iframes.eq(i).val()
  1101. iframe && iframes.push(iframe)
  1102. }
  1103. args.iframe = iframes
  1104. var modules = []
  1105. for (var i = 0; i < $modules.length; i++) {
  1106. var module = $modules.eq(i).val()
  1107. module && modules.push(module)
  1108. }
  1109. args.model = modules
  1110. args.position = hot.mesh.position.clone()
  1111. args.quaternion = hot.mesh.quaternion.clone()
  1112. return args
  1113. }).then(function(args) {
  1114. console.log(args);
  1115. //把获取的所有信息都保存在对应热点的dom元素里面
  1116. //hotpointDetail[0].targetDOM.infoAttribute = args;
  1117. hot.infoAttribute = args;
  1118. $layout.addClass('hide');
  1119. hotpointDetail.addClass("atRight");
  1120. spot.find(".title").html(args.title);
  1121. transformControls.detach()
  1122. })
  1123. })
  1124. var _this = this;
  1125. $("#isSprite").on("change", function(e) {
  1126. _this.editSpot.isSprite = this.checked;
  1127. if (this.checked) {
  1128. _this.editSpot.update(player.camera)
  1129. } else {
  1130. _this.editSpot.mesh.quaternion.copy(_this.editSpot.quaternion)
  1131. }
  1132. })
  1133. $(".webPage .MenuOptions li").on("click", (e)=>{ //链接打开方式切换
  1134. _this.editSpot.linkType = $(e.target).attr("index")
  1135. $(".webPage .MenuOptions li").removeClass("chosen");
  1136. $(e.target).addClass("chosen")
  1137. })
  1138. $("#noAction").on("change", function(e) {
  1139. _this.editSpot.noAction = this.checked;
  1140. })
  1141. }
  1142. //背景音乐
  1143. var EditMiuse = function() {
  1144. this.mediaUpload = $(".music .audio.mediaUpload");
  1145. this.musicBox = musicPlayBoxBind(this.mediaUpload, (file)=>{
  1146. uploadMiuse(file, (rs, file)=>{
  1147. if (rs.code === 0) {
  1148. this.musicBox.show(this.mediaUpload, file.name, rs.data)
  1149. }else{
  1150. this.musicBox.hide()
  1151. }
  1152. })
  1153. }, null)
  1154. /* this.success = function(text, url) {
  1155. this.mediaUpload.find(".innerBtn").text("替换");
  1156. this.mediaUpload.find(".playBox").removeClass("hide");
  1157. this.mediaUpload.find(".title").text(text);
  1158. this.mediaUpload.find('#query-bgm').attr('href', url)
  1159. }
  1160. ;
  1161. this.delete = function() {
  1162. this.mediaUpload.find('#query-bgm').attr('href', "");
  1163. this.mediaUpload.find(".playBox").addClass("hide");
  1164. this.mediaUpload.find(".innerBtn").text("上传");
  1165. this.mediaUpload.find("input").val("");
  1166. }
  1167. ;
  1168. var that = this;
  1169. $('#upload-bgm').on('change', function(e) {
  1170. var file = this.files[0];
  1171. uploadMiuse(file, function(rs, file) {
  1172. if (rs.code === 0) {
  1173. that.success(file.name, rs.data)
  1174. }
  1175. })
  1176. e.target.value = null
  1177. });
  1178. //删除音乐
  1179. this.mediaUpload.on("click", ".delete", function() {
  1180. that.delete();
  1181. }) */
  1182. }
  1183. EditMiuse.prototype.init = function(data) {
  1184. if (!data.backgroundMusic)
  1185. return;
  1186. this.musicBox.show(this.mediaUpload, data.bgName || "backgound", data.backgroundMusic);
  1187. }
  1188. //导览编辑
  1189. var EditGuide = function() {
  1190. this.$list = $('#guide-list')
  1191. //$('#tourItemEdit') = $('#tourItemEdit');
  1192. this.targetTourPoint = null;
  1193. // fyz 记录当前编辑的导览点
  1194. // fyz 导览音乐队列
  1195. //this.tourAudio = {};
  1196. }
  1197. /**
  1198. * @author fyz 2019.07.31
  1199. * @description 新增参数data2, 表示data2.js中的数据
  1200. */
  1201. /* function snapATourView(that, renew) {
  1202. var ev = document.createEvent("MouseEvent");
  1203. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1204. g_snapShotWidth = 200;
  1205. g_snapShotHeight = 140;
  1206. window.screenSta = 'tour';
  1207. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1208. ev.__callback = function(imgData, info) {
  1209. that.uploadGuide(imgData, info, renew, that.targetTourPoint)
  1210. }.bind(that);
  1211. window.dispatchEvent(ev);
  1212. } */
  1213. EditGuide.prototype.snapATourView = function(renew, insideFolder){
  1214. var ev = document.createEvent("MouseEvent");
  1215. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  1216. g_snapShotWidth = 200;
  1217. g_snapShotHeight = 140;
  1218. window.screenSta = 'tour';
  1219. // 记录当前哪个功能截屏, 因为导览截屏需要做额外的校对调整, 初始画面截屏不需要
  1220. ev.__callback = (imgData, info)=> {
  1221. this.uploadGuide(imgData, info, renew, insideFolder)
  1222. };
  1223. window.dispatchEvent(ev);
  1224. }
  1225. EditGuide.prototype.init = function(data, data2) {
  1226. this.createDom(data, data2);
  1227. //this.tourAudio = data2.tourAudio || {};
  1228. var that = this;
  1229. //点击添加导览
  1230. $('.addTour .innerBtn').eq(0).on("click", function () {
  1231. this.addFolderDom({name:"区域"+($("#tourList .listItem").length+1) } );//点击增加一段导览
  1232. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight //scroll to bottom
  1233. }.bind(this));
  1234. $('.addTour .innerBtn').eq(1).on("click", function () {
  1235. this.snapATourView()//点击截取视图
  1236. $("#tourList ul")[0].scrollTop = $("#tourList ul")[0].scrollHeight
  1237. }.bind(this));
  1238. $('.snapATourView .innerBtn').on("click", function() {
  1239. this.snapATourView(null,true);//folder内点击截取视图
  1240. $("#tourItemList ul")[0].scrollTop = $("#tourItemList ul")[0].scrollHeight
  1241. }.bind(this));
  1242. $('#renewTourBtn').on("click", function() { // 重新截取视图
  1243. this.snapATourView(this, !!this.editingFolderLi);
  1244. }.bind(this));
  1245. // 确认并保存导览信息
  1246. $('#tourFolderEdit .tourSubmit').on("click", function() {
  1247. this.completeFolder();
  1248. }.bind(this));
  1249. $('#tourItemEdit .tourSubmit').on("click", function() {
  1250. this.completeItem();
  1251. }.bind(this));
  1252. //点击导览编辑窗口右上角的关闭按钮
  1253. /* $("#tourItemEdit a.close, button.cancel").on("click", function() {
  1254. that.targetTourPoint[0].musicSta = true; ///??????????
  1255. // 取消操作, 重置状态
  1256. that.tourDetail.addClass("atRight");
  1257. }); */
  1258. //导览目录
  1259. $("#tourList").on("click", function(e) {
  1260. var target = $(e.target);
  1261. let folder = searchParent(e.target, { className: 'listItem' }, 7);
  1262. if(!folder)return;//可能点到了item
  1263. if (target.hasClass("del")) {
  1264. e.stopPropagation();
  1265. target.siblings(".DelConfirm").addClass("active");
  1266. } else {
  1267. if (target.hasClass("DelConfirm")) {
  1268. e.stopPropagation();
  1269. $(folder).remove()
  1270. //that.removeFolder(folder);//删除
  1271. } else {
  1272. if (target.hasClass("title") || target.hasClass("icon")) {
  1273. that.editFolder(folder)//编辑
  1274. }
  1275. }
  1276. }
  1277. });
  1278. //编辑item
  1279. $('.tourList ul').on('click', function(e) {
  1280. var target = $(e.target);
  1281. let itemDom = searchParent(e.target, { className: 'guideItem' }, 7);
  1282. if(!itemDom)return;//可能点到了folder
  1283. if(searchParent(e.target, { className: 'preview' })){
  1284. var choice = confirm("你确定删除吗?");
  1285. if (choice) {
  1286. var ul = searchParent(e.target, { className: 'tourList' })
  1287. target.closest('li').remove();
  1288. reIndexTourList(ul)
  1289. } else {
  1290. return false
  1291. }
  1292. }else{
  1293. that.editItem(itemDom);
  1294. }
  1295. })
  1296. //fyz 拖拽以改变顺序
  1297. let tourListNode = $("#tourList>ul")[0];
  1298. let tourItemListNode = $("#tourItemList>ul")[0];
  1299. let draging = null;
  1300. let dragStart = (event)=> {
  1301. event.dataTransfer.setData("te", event.target.innerText); //不能使用text,firefox会打开新tab
  1302. draging = event.target;
  1303. }
  1304. let dragOver = (event)=>{
  1305. event.preventDefault();
  1306. let target = searchParent(event.target, { tagName: 'LI' }, 7); //event.target.parentNode.parentNode;
  1307. // 判断dragover是否发生在LI元素上
  1308. if ((target.classList.contains('guideItem') || target.classList.contains('listItem')) && target !== draging ) {
  1309. let dragingIndex = $(draging).index()//draging.querySelector('#index');
  1310. let targetIndex = $(target).index()//target.querySelector('#index');
  1311. var targetRect = target.getBoundingClientRect();
  1312. var dragingRect = draging.getBoundingClientRect();
  1313. if (target && target.animated) {
  1314. return;
  1315. }
  1316. let ulElem = target.parentNode;
  1317. // 寻找到 ul节点
  1318. if (getIndex(draging) < getIndex(target)) {
  1319. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1320. // 交换两个节点的序号
  1321. if(event.clientY<targetRect.top+targetRect.height*0.3)return
  1322. ulElem.insertBefore(draging, target.nextSibling);
  1323. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];// 交换两个节点的序号
  1324. } else {
  1325. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1326. if(event.clientY>targetRect.bottom-targetRect.height*0.3)return
  1327. ulElem.insertBefore(draging, target);
  1328. //dragingIndex.innerText = [targetIndex.innerText, targetIndex.innerText = dragingIndex.innerText][0];
  1329. }
  1330. _animate(dragingRect, draging);
  1331. _animate(targetRect, target);
  1332. var ul = searchParent(event.target, { className: 'tourList' })
  1333. reIndexTourList(ul)
  1334. }
  1335. }
  1336. tourListNode.ondragstart = dragStart
  1337. tourItemListNode.ondragstart = dragStart
  1338. tourListNode.ondragover = dragOver
  1339. tourItemListNode.ondragover = dragOver
  1340. //音乐
  1341. this.musicBox = musicPlayBoxBind($(".snapTour .audio.mediaUpload"), null, ()=>{
  1342. (that.editingFolderLi || that.editingItemLi).tourData.musicInfo = {}//直接删除 不可逆
  1343. })
  1344. /*
  1345. var mediaUpload = $(".snapTour .audio.mediaUpload");
  1346. var that = this;
  1347. mediaUpload.find("input").on("change", function(e) {
  1348. if(!e.target.files.length) return;
  1349. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1350. var file = e.target.files[0];
  1351. mediaDom.find(".innerBtn").text("替换");
  1352. mediaDom.find(".playBox").removeClass("hide");
  1353. mediaDom.find(".title").text(file.name);
  1354. mediaDom.find('#query-bgm').attr('href', URL.createObjectURL(file));
  1355. //that.editingFolderLi.musicSta = true;
  1356. });
  1357. mediaUpload.find("input").on("click", function() {
  1358. mediaUpload
  1359. });
  1360. //删除音乐
  1361. mediaUpload.on("click", ".delete", function(e) {
  1362. var mediaDom = $(searchParent(e.target, { className: '.mediaUpload' }));
  1363. mediaDom.find('#query-bgm').attr('href', "");
  1364. mediaDom.find(".playBox").addClass("hide");
  1365. mediaDom.find(".innerBtn").text("上传");
  1366. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1367. //that.editingFolderLi.musicSta = false;
  1368. (that.editingFolderLi || that.editingItemLi).data.musicInfo = {}//直接删除 不可逆
  1369. }) */
  1370. }
  1371. function musicPlayBoxBind($dom, addCallback, delCallback){
  1372. var musicBox = {
  1373. hasMusic:false,
  1374. show: function(mediaDom, name, url){
  1375. mediaDom = mediaDom || $dom
  1376. mediaDom.find(".innerBtn").text("替换");
  1377. mediaDom.find(".playBox").removeClass("hide");
  1378. mediaDom.find(".title").text(name);
  1379. mediaDom.find('#query-bgm').attr('href', url);
  1380. musicBox.hasMusic = true
  1381. },
  1382. addMusic : function(e) {
  1383. if(!e.target.files.length) return;
  1384. var file = e.target.files[0];
  1385. if (!/audio\/\w+/.test(file.type)) {
  1386. alert("文件必须为音乐!");
  1387. return false;
  1388. }
  1389. //限制大小不大于8m
  1390. if (!restrictedSize(file, _musicMaxWeight)) {
  1391. return false
  1392. }
  1393. var mediaDom = $(searchParent(e.target, { className: 'mediaUpload' }));
  1394. musicBox.show(mediaDom, file.name, URL.createObjectURL(file))
  1395. addCallback && addCallback(file)
  1396. },
  1397. hide : function(e) {
  1398. var mediaDom = e ? $(searchParent(e.target, { className: 'mediaUpload' })) : $dom
  1399. mediaDom.find('#query-bgm').attr('href', "");
  1400. mediaDom.find(".playBox").addClass("hide");
  1401. mediaDom.find(".innerBtn").text("上传");
  1402. mediaDom.find("input").val("")//.removeAttr("data-hotbgm");
  1403. musicBox.hasMusic = false
  1404. delCallback && delCallback()
  1405. }
  1406. }
  1407. $dom.find("input").on("change", musicBox.addMusic)
  1408. /* $dom.find("input").on("click", function() {
  1409. mediaUpload
  1410. }); */
  1411. //删除音乐
  1412. $dom.on("click", ".delete", musicBox.hide)
  1413. return musicBox;
  1414. }
  1415. function reIndexTourList(ul) {
  1416. Array.from($(ul).find('li.guideItem')).forEach((li,index)=>{
  1417. $(li).find("div:first-child span").text(index + 1);
  1418. })
  1419. }
  1420. EditGuide.prototype.addFolderDom = function( tourData){
  1421. 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>");
  1422. $folder[0].tourItemDoms = [] //记录所有item的li dom
  1423. $folder[0].tourData = tourData //注: data中的locations不会更新,保存时直接读取li
  1424. $("#tourList ul").append($folder);
  1425. return $folder
  1426. }
  1427. EditGuide.prototype.getItemDom = function(title, img) {
  1428. 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 >';
  1429. }
  1430. EditGuide.prototype.createDom = function(data, data2) {
  1431. var that = this;
  1432. var tourAudio = data2.tourAudio || {};
  1433. data.model.images.forEach((Info,index)=>{
  1434. if(Info.locations){//是folder
  1435. var $folder = this.addFolderDom(Info)
  1436. // 音频链接
  1437. Info.locations = Info.locations.filter(e=>e)
  1438. Info.locations.forEach(function(info, index) {
  1439. if (info.thumbnail_signed_src) {
  1440. var $li = $(that.getItemDom( info.name, info.thumbnail_signed_src));
  1441. $li[0].tourData = info
  1442. $folder[0].tourItemDoms.push($li[0])
  1443. }
  1444. })
  1445. }else{//是散落在外的item
  1446. if (Info.thumbnail_signed_src) {
  1447. var $li = $(that.getItemDom(Info.name, Info.thumbnail_signed_src));
  1448. $li[0].tourData = Info
  1449. // 音频链接
  1450. $li[0].tourData.musicInfo = $li[0].tourData.musicInfo || tourAudio[Info.sid] || {}//新的music数据统一写在每个info下
  1451. $("#tourList ul").append($li)
  1452. /* if (Info.sid in tourAudio && tourAudio[info.sid].music && tourAudio[info.sid].music !== '') {
  1453. //$li[0].musicUrl = tourAudio[info.sid].music;
  1454. $li[0].musicInfo = tourAudio[info.sid]
  1455. } */
  1456. }
  1457. }
  1458. })
  1459. reIndexTourList($("#tourList")[0])
  1460. }
  1461. //暂时不实时更新左侧场景,所以信息全写在UI上,不保存data
  1462. EditGuide.prototype.editFolder = function(folderDom){
  1463. this.editingFolderLi = folderDom;
  1464. $("#tourFolderEdit").removeClass('atRight');
  1465. $("#tourFolderEdit .tourName input").val( $(folderDom).find('.title').text()||'');
  1466. $("#folderTourSwitch input").prop('checked', folderDom.tourData.momentTour === 'black');
  1467. folderDom.tourItemDoms.forEach(li=>{
  1468. $("#tourItemList>ul").append(li)
  1469. })
  1470. reIndexTourList($("#tourItemList>ul")[0])
  1471. //判断当前点是否有导览音频
  1472. //target[0].musicSta = true;
  1473. //var audio = this.tourAudio[target.closest('li')[0].data.sid];
  1474. var musicInfo = this.editingFolderLi.tourData.musicInfo //audio ? audio.music : null;
  1475. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1476. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1477. /* $('#tourFolderEdit').find(".audio .playBox").removeClass("hide");
  1478. $('#tourFolderEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1479. $('#tourFolderEdit').find(".audio .submit").text("替换");
  1480. $('#tourFolderEdit').find(".title").text(musicName); */
  1481. this.musicBox.show($('#tourFolderEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1482. } else {
  1483. /* $('#tourFolderEdit').find(".audio .playBox").addClass("hide");
  1484. $('#tourFolderEdit').find(".audio .submit").text("上传"); */
  1485. this.musicBox.hide()
  1486. }
  1487. }
  1488. /**
  1489. * @author fyz 编辑单个导览item
  1490. * @param {any} target 所点击的导览点
  1491. */
  1492. EditGuide.prototype.editItem = function(li) {
  1493. //this.targetTourPoint = target;
  1494. this.editingItemLi = li
  1495. // 记录当前编辑的导览点
  1496. var that = this;
  1497. $('#tourItemEdit').removeClass('atRight');
  1498. $('#tourItemEdit .tourName input').val( $(li).find('.guide-name').text() );
  1499. var metadata = JSON.parse(li.tourData.metadata);
  1500. if(metadata.scan_id != 'outside'){
  1501. var pano = player.model.panos.index[metadata.scan_id]
  1502. if(pano){
  1503. var q = new THREE.Quaternion().copy(metadata.camera_quaternion);
  1504. var lookAtPoint = new THREE.Vector3(0,0,-1).applyQuaternion(q).add(pano.position);
  1505. player.flyToPano({
  1506. pano: pano,
  1507. lookAtPoint: lookAtPoint
  1508. })
  1509. }
  1510. }
  1511. if(!this.editingFolderLi){//在外的item, 可以上传音乐
  1512. $('#tourItemEdit .mediaUpload').removeClass('hide')
  1513. var musicInfo = li.tourData.musicInfo //audio ? audio.music : null;
  1514. if (musicInfo && musicInfo.music) { // 判断改导览点是否已经已有音乐
  1515. var musicName = musicInfo.name || '导览音频.mp3' // 获取音频的文件名
  1516. /* $('#tourItemEdit').find(".audio .playBox").removeClass("hide");
  1517. $('#tourItemEdit').find(".audio .playBox a").attr("href", "//" + musicInfo.music);
  1518. $('#tourItemEdit').find(".audio .submit").text("替换");
  1519. $('#tourItemEdit').find(".title").text(musicName); */
  1520. this.musicBox.show($('#tourItemEdit .mediaUpload'), musicName, "//" + musicInfo.music)
  1521. } else {
  1522. this.musicBox.hide()
  1523. /* $('#tourItemEdit').find(".audio .playBox").addClass("hide");
  1524. $('#tourItemEdit').find(".audio .submit").text("上传"); */
  1525. }
  1526. }else{
  1527. $('#tourItemEdit .mediaUpload').addClass('hide')
  1528. }
  1529. }
  1530. EditGuide.prototype.completeFolder = function(){//点击完成
  1531. var tourName = $('#tourFolderEdit .tourName input').val() //|| this.targetTourPoint.context.innerText;
  1532. $(this.editingFolderLi).find(".title").text(tourName)
  1533. this.editingFolderLi.tourData.momentTour = $("#folderTourSwitch input").is(':checked') ? "black" : 'walk'
  1534. this.editingFolderLi.tourItemDoms = Array.from($('#tourItemList ul li'));
  1535. var done = ()=>{
  1536. $("#tourFolderEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1537. this.editingFolderLi = null
  1538. $("#tourFolderEdit").addClass('atRight');
  1539. $(".edit-loading").addClass('hide');
  1540. $("#tourItemList>ul").html('')
  1541. }
  1542. //save导览音乐
  1543. var tourAudio = $('#tourFolderEdit .mediaUpload input');
  1544. // 记录音频名称
  1545. //判断当前编辑的导览点位是否已上传音乐
  1546. if (tourAudio[0].files.length > 0/* && this.targetTourPoint[0].musicSta */) { //有input文件
  1547. $(".edit-loading").removeClass('hide');
  1548. var musicName = $('#tourFolderEdit .mediaUpload .title').text();
  1549. new Promise( (resolve, reject)=> {
  1550. uploadMiuse(tourAudio[0].files[0], function(res) {
  1551. resolve(res.data);
  1552. })
  1553. } ).then( (src)=>{
  1554. var audio = new Audio();
  1555. audio.src = src;
  1556. audio.onloadedmetadata = ()=>{
  1557. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1558. srcArr[0] = '';
  1559. src = srcArr.join('/');
  1560. //var sid = this.editingFolderLi.data.sid
  1561. //that.tourAudio[sid] = {
  1562. this.editingFolderLi.tourData.musicInfo = {
  1563. "name": musicName,
  1564. "music": '/' + src,
  1565. "time": Math.round(audio.duration * 1000 + 1000)
  1566. }
  1567. done()
  1568. }
  1569. })
  1570. }else done()
  1571. }
  1572. EditGuide.prototype.completeItem = function() {//点击完成
  1573. var done = ()=>{
  1574. $("#tourItemEdit .audio.mediaUpload").find("input").val(''); // 清空 文件
  1575. this.editingItemLi = null
  1576. $("#tourItemEdit").addClass('atRight');
  1577. $(".edit-loading").addClass('hide');
  1578. }
  1579. var tourName = $('#tourItemEdit .tourName input').val()
  1580. $(this.editingItemLi).find('.guide-name').text(tourName)
  1581. //save导览音乐
  1582. var tourAudio = $('#tourItemEdit .mediaUpload input');
  1583. //判断当前编辑的导览点位是否已上传音乐
  1584. if (!this.editingFolderLi && tourAudio[0].files.length > 0) { //有input文件
  1585. $(".edit-loading").removeClass('hide');
  1586. var musicName = $('#tourItemEdit .mediaUpload .title').text();
  1587. new Promise( (resolve, reject)=>{
  1588. uploadMiuse(tourAudio[0].files[0], function(res) {
  1589. resolve(res.data);
  1590. })
  1591. } ).then( (src)=>{
  1592. var audio = new Audio();
  1593. audio.src = src;
  1594. audio.onloadedmetadata = ()=>{
  1595. var srcArr = src.split('/'); // 对返回的src进行处理, 去掉前面域名, 尽量避免修改main.js
  1596. srcArr[0] = '';
  1597. src = srcArr.join('/');
  1598. //that.tourAudio[sid] = {
  1599. this.editingItemLi.tourData.musicInfo = {
  1600. "name": musicName,
  1601. "music": '/' + src,
  1602. "time": Math.round(audio.duration * 1000 + 1000)
  1603. }
  1604. done()
  1605. }
  1606. })
  1607. }else done()
  1608. }
  1609. /**
  1610. * @author fyz 2019.07.31
  1611. * @description uploadGuide方法新增参数renew状态码, 表示是否重新录制当前导览, 新增targetTourPoint, 记录当前的导览点元素
  1612. */
  1613. EditGuide.prototype.uploadGuide = function(urlData, guide, renew, insideFolder) {
  1614. var that = this;
  1615. uploadImg(urlData, function(rs) {
  1616. if (rs.code === 0) {
  1617. //var editGuide = new EditGuide();
  1618. var sid = rs.data.substring(rs.data.lastIndexOf('/') + 1, rs.data.lastIndexOf('.'));
  1619. var thumbnail_signed_src = rs.data;
  1620. var args = JSON.parse("{" + guide + "}");
  1621. args.sid = sid;
  1622. args.name = sid;
  1623. args.thumbnail_signed_src = thumbnail_signed_src;
  1624. args.metadata = JSON.stringify({
  1625. camera_mode: args.metadata.camera_mode,
  1626. camera_position: {
  1627. x: args.metadata.camera_position[0],
  1628. y: args.metadata.camera_position[1],
  1629. z: args.metadata.camera_position[2]
  1630. },
  1631. camera_quaternion: {
  1632. x: args.metadata.camera_quaternion[0],
  1633. y: args.metadata.camera_quaternion[1],
  1634. z: args.metadata.camera_quaternion[2],
  1635. w: args.metadata.camera_quaternion[3]
  1636. },
  1637. ortho_zoom: args.metadata.ortho_zoom,
  1638. scan_id: args.metadata.scan_id || "outside",
  1639. //这个"outside"不能随便改成别的
  1640. /* final_angle: 110,
  1641. is_ortho: false, */
  1642. zoom: args.metadata.zoom // fyz zoom是内部计算的zoomLevel, 乘以系数1.06才是实际缩放倍数
  1643. })
  1644. if (renew/* && target */) { // 重新录制导览
  1645. // 更新数据
  1646. var musicInfo = insideFolder || that.editingItemLi.tourData.musicInfo;
  1647. musicInfo && (args.musicInfo = musicInfo);
  1648. $(that.editingItemLi).find('#tourBg')[0].style.backgroundImage = 'url(' + args.thumbnail_signed_src + ')';
  1649. //args.name = insideFolder $('#tourItemEdit').find('#tourNameInput').val()
  1650. /* var oldId = target.closest('li')[0].data.sid;
  1651. that.tourAudio[args.sid] = that.tourAudio[oldId];
  1652. // 新生成的id指向以前的导览音频
  1653. delete that.tourAudio[oldId];
  1654. // 删除导览音频中的旧导览id */
  1655. that.editingItemLi.tourData = args;
  1656. //target.text(args.name); // 更新导览列表中的导览名称 //不改名字
  1657. //$('#tourItemEdit').find('#tourNameInput').val(args.name); // 修改输入框内容
  1658. } else {
  1659. var $li = $(that.getItemDom(args.name, args.thumbnail_signed_src));
  1660. $li[0].tourData = args;
  1661. var $ul = insideFolder ? $("#tourItemList>ul") : $("#tourList>ul")
  1662. $ul.append($li);
  1663. reIndexTourList($ul[0])
  1664. }
  1665. }
  1666. })
  1667. }
  1668. EditGuide.prototype.getSavingInfo = function(){
  1669. var data = []
  1670. Array.from($("#tourList ul li")).forEach(dom=>{
  1671. if(dom.classList.contains("guideItem")){//item
  1672. dom.tourData.name = $(dom).find('.guide-name').text()
  1673. data.push(dom.tourData)
  1674. }else{//folder
  1675. var dataFolder = dom.tourData;
  1676. dataFolder.name = $(dom).find('.title').text()
  1677. dataFolder.locations = dom.tourItemDoms.map(li => li.tourData )
  1678. data.push(dataFolder)
  1679. }
  1680. })
  1681. return data
  1682. }
  1683. /* -- 以下是一些公用的方法 -- */
  1684. //限制大小
  1685. var restrictedSize = function(file, _size) {
  1686. //限制大小不大于8m
  1687. var fileSize = 0;
  1688. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  1689. if (isIE && !file) {
  1690. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  1691. var _file = fileSystem.GetFile(filepath);
  1692. fileSize = _file.Size;
  1693. } else {
  1694. fileSize = file.size;
  1695. }
  1696. var size = fileSize / 1024;
  1697. var RSize = _size * 1024;
  1698. if (size > RSize) {
  1699. alert("文件不能大于" + _size + "M");
  1700. return false;
  1701. }
  1702. if (size <= 0) {
  1703. alert("文件大小不能为0M!");
  1704. return false;
  1705. }
  1706. return true
  1707. }
  1708. //上传音乐
  1709. var uploadMiuse = function(file, callback) {
  1710. uploadFile(file, 'audio', callback);
  1711. }
  1712. $(".toolRight .music .itemTitle span").text(`背景音乐 (<${_musicMaxWeight}M)`)
  1713. //上传图片
  1714. function uploadImg(urlData, callback, fileName) {
  1715. //console.log('urlData',urlData);
  1716. var bytes = window.atob(urlData.split(',')[1]);
  1717. //去掉url的头,并转换为byte
  1718. //处理异常,将ascii码小于0的转换为大于0
  1719. var ab = new ArrayBuffer(bytes.length);
  1720. var ia = new Uint8Array(ab);
  1721. for (var i = 0; i < bytes.length; i++) {
  1722. ia[i] = bytes.charCodeAt(i);
  1723. }
  1724. var blob = new Blob([ab],{
  1725. type: 'image/jpeg',
  1726. });
  1727. uploadFile(blob, 'hot/images', callback, fileName);
  1728. }
  1729. //上传文件
  1730. function uploadFile(file, type, callback, fileName) {
  1731. $(".edit-loading").removeClass("hide");
  1732. var formData = new FormData()
  1733. formData.append('name', number)
  1734. formData.append('dir', type)
  1735. formData.append('random', true)
  1736. //formData.append('file', file)
  1737. formData.append("file", file, fileName);
  1738. let url = cmp ? ('/api/scene/upload/' + number) : ('/manage/scene/upload/' + number)
  1739. $.ajax({
  1740. url: ceshi + url,
  1741. data: formData,
  1742. headers: {
  1743. token: token
  1744. },
  1745. dataType: 'json',
  1746. type: 'POST',
  1747. cache: false,
  1748. //上传文件无需缓存
  1749. processData: false,
  1750. //用于对data参数进行序列化处理 这里必须false
  1751. contentType: false,
  1752. //必须
  1753. success: function(rs) {
  1754. if (rs.code === 5001) {
  1755. alert('请重新登录')
  1756. localStorage.dcj_token = ''
  1757. location.reload()
  1758. }
  1759. callback(rs, file);
  1760. $(".edit-loading").addClass("hide");
  1761. }
  1762. })
  1763. }
  1764. function _animate(prevRect, target) {
  1765. var ms = 300;
  1766. if (ms) {
  1767. var currentRect = target.getBoundingClientRect();
  1768. if (prevRect.nodeType === 1) {
  1769. prevRect = prevRect.getBoundingClientRect();
  1770. }
  1771. _css(target, 'transition', 'none');
  1772. _css(target, 'transform', 'translate3d(' + (prevRect.left - currentRect.left) + 'px,' + (prevRect.top - currentRect.top) + 'px,0)');
  1773. target.offsetWidth;
  1774. // 触发重绘
  1775. //放在timeout里面也可以
  1776. // setTimeout(function() {
  1777. // _css(target, 'transition', 'all ' + ms + 'ms');
  1778. // _css(target, 'transform', 'translate3d(0,0,0)');
  1779. // }, 0);
  1780. _css(target, 'transition', 'all ' + ms + 'ms');
  1781. _css(target, 'transform', 'translate3d(0,0,0)');
  1782. clearTimeout(target.animated);
  1783. target.animated = setTimeout(function() {
  1784. _css(target, 'transition', '');
  1785. _css(target, 'transform', '');
  1786. target.animated = false;
  1787. }, ms);
  1788. }
  1789. }
  1790. //给元素添加style
  1791. function _css(el, prop, val) {
  1792. var style = el && el.style;
  1793. if (style) {
  1794. if (val === void 0) {
  1795. if (document.defaultView && document.defaultView.getComputedStyle) {
  1796. val = document.defaultView.getComputedStyle(el, '');
  1797. } else if (el.currentStyle) {
  1798. val = el.currentStyle;
  1799. }
  1800. return prop === void 0 ? val : val[prop];
  1801. } else {
  1802. if (!(prop in style)) {
  1803. prop = '-webkit-' + prop;
  1804. }
  1805. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  1806. }
  1807. }
  1808. }
  1809. function upload($files, type, cb) {//保存系列文件
  1810. var length = $files.length
  1811. var rcount = 0
  1812. var result = []
  1813. Array.from($files).forEach(function(dFile, index) {
  1814. var $file = $(dFile)
  1815. var $image = type == 'videos' ? $file.find('img.play-video') : $file.find('img')
  1816. if ($file.hasClass('success')) {//已经上传过,有链接
  1817. if ($file.attr('attr-thum')) {//视频的封面
  1818. result[index] = $file.attr('attr-thum')
  1819. } else if ($image.attr('videoURL')) {//视频
  1820. result[index] = $image.attr('videoURL')
  1821. } else {
  1822. result[index] = $image.attr('src')
  1823. }
  1824. return success(++rcount);
  1825. } else {
  1826. switch ($file[0].localName) {
  1827. case "input":
  1828. dFile = $file[0]
  1829. break;
  1830. case "span"://封面
  1831. dFile = $file.find('input')[0];
  1832. break;
  1833. case "a"://重传的图or视频
  1834. dFile = {files:[$file[0].file]}
  1835. //dFile = $file.find('input')[0];
  1836. break;
  1837. default:
  1838. dFile = $file.closest("li").find('.upload input')[0];
  1839. break;
  1840. }
  1841. // dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
  1842. }
  1843. var file = (dFile.files && dFile.files[0]) || '';
  1844. if (!file)
  1845. return success(++rcount);
  1846. uploadFile(file, 'hot/' + type, function(rs) {
  1847. //似乎所有图保存路径都是这个hot/前缀。图地址 :"场景id/edit/重新生成的文件名.原后缀", 展示页面也是。
  1848. if (rs.code === 0) {
  1849. result[index] = rs.data
  1850. }
  1851. ;success(++rcount);
  1852. })
  1853. })
  1854. //判断当前队列元素是否处理成功
  1855. function success() {
  1856. if (rcount === length) {
  1857. cb(result)
  1858. }
  1859. }
  1860. success()
  1861. }
  1862. function getIndex(el) {
  1863. let index = 0;
  1864. if (!el || !el.parentNode) {
  1865. return -1;
  1866. }
  1867. while (el && (el = el.previousElementSibling)) {
  1868. index++;
  1869. }
  1870. return index;
  1871. }
  1872. dataURLtoBlob = function(dataurl) {
  1873. //将base64转换blob
  1874. var arr = dataurl.split(',')
  1875. , mime = arr[0].match(/:(.*?);/)[1]
  1876. , bstr = atob(arr[1])
  1877. , n = bstr.length
  1878. , u8arr = new Uint8Array(n);
  1879. while (n--) {
  1880. u8arr[n] = bstr.charCodeAt(n);
  1881. }
  1882. return new Blob([u8arr],{
  1883. type: mime
  1884. });
  1885. }
  1886. ;
  1887. //=========================
  1888. var eachMaxWeights = {
  1889. //大小限制
  1890. "photo": 10,
  1891. "video": 1000,//50, expand size for overlayVideo
  1892. //20,
  1893. "audio": 10 //5
  1894. }
  1895. var supportTypes = {
  1896. //支持后缀
  1897. "photo": ["jpg", "png", "jpeg", "bmp", "gif"],
  1898. "audio": ["mp3", "aac", "ogg", "wav"/* , "m4a" */
  1899. ],
  1900. "video": ["mp4", "mov"/* ,"webm", "rmvb", "wmv" */
  1901. ]//ios:mov
  1902. }
  1903. function getExt(name) {
  1904. //后缀
  1905. if (name.indexOf('.') > -1) {
  1906. var a = name.split(".");
  1907. return a.pop();
  1908. } else {
  1909. return '';
  1910. }
  1911. }
  1912. function detectType(fileName) {
  1913. //检测文件后缀类型
  1914. console.log("名:" + fileName)
  1915. var ext = getExt(fileName);
  1916. console.log("后缀:" + ext)
  1917. //不一定所有浏览器都可以
  1918. var type;
  1919. //仅能根据后缀判断类型,尽管后缀可能被修改。 其他方法如file.type和base64开头的字符串均是根据后缀。
  1920. for (var i in supportTypes) {
  1921. if (supportTypes[i].indexOf(ext.toLowerCase()) > -1) {
  1922. type = i;
  1923. break;
  1924. }
  1925. }
  1926. if (type) {
  1927. return type;
  1928. } else {
  1929. return false;
  1930. }
  1931. }
  1932. //手机上的相片会不会太大?
  1933. var detectWeights = function(file, type) {
  1934. //检测大小
  1935. var size = file.size / 1024 / 1024;
  1936. console.log("weight" + size)
  1937. var over;
  1938. if (size > eachMaxWeights[type]) {
  1939. over = Math.ceil(size * 100) / 100;
  1940. }
  1941. return over;
  1942. }
  1943. var exitUpload = function(input) {
  1944. $('.waiting').removeClass('showloading');
  1945. input.value = "";
  1946. }
  1947. var inputMedia = function(options, type, e) {
  1948. var input = e.target;
  1949. if (!window.FileReader) {
  1950. alert('您的浏览器不支持上传文件');
  1951. exitUpload(input);
  1952. return;
  1953. } else if (e.target.files.length === 0) {
  1954. /* exitUpload(input); */
  1955. return;
  1956. }
  1957. $('.waiting').addClass('showloading');
  1958. var file = e.target.files[0];
  1959. var elemType = type;
  1960. var inputType = detectType(file.name);
  1961. var chType = {
  1962. "photo": '图片',
  1963. "video": '视频',
  1964. "audio": '音乐'
  1965. }
  1966. var overWeight = detectWeights(file, inputType);
  1967. if (elemType) {
  1968. //有指定其中一种类型
  1969. if (inputType != elemType) {
  1970. alert("您选择的不是浏览器支持的" + chType[elemType] + '文件,请重新选择');
  1971. exitUpload(e.target);
  1972. return;
  1973. }
  1974. } else {
  1975. if (!options.enableTypes.includes(inputType)) {
  1976. var text = "";
  1977. options.enableTypes.forEach((type,index)=>{
  1978. text += ((index != 0 ? " / " : "") + chType[elemType])
  1979. }
  1980. )
  1981. alert("您选择的不是浏览器支持的" + text + '文件,请重新选择');
  1982. exitUpload(e.target);
  1983. return;
  1984. }
  1985. }
  1986. if (overWeight) {
  1987. alert(`文件过大(${overWeight}兆),不能大于${eachMaxWeights[inputType]} 兆`)
  1988. exitUpload(e.target);
  1989. return;
  1990. }
  1991. var loadError = function() {
  1992. exitUpload(e.target);
  1993. alert(`文件出错, 无法加载此${chType[inputType]}文件。 文件可能损坏,或者浏览器不支持,或者后缀与文件不匹配。建议在IE以外的浏览器上传`)
  1994. }
  1995. deal();
  1996. function deal(fi) {
  1997. console.log('开始deal文件')
  1998. var reader = new FileReader();
  1999. //reader.name = file.name;
  2000. file = fi || file;
  2001. reader.readAsDataURL(file);
  2002. reader.onload = function(evt) {
  2003. var blob = dataURLtoBlob(evt.target.result);
  2004. var blobSrc = window.URL.createObjectURL(blob);
  2005. if (inputType == "photo") {
  2006. /* EXIF.getData(file, function () {
  2007. //获取相片旋转
  2008. EXIF.getAllTags(this);
  2009. var orient = EXIF.getTag(this, 'Orientation');
  2010. var img = new Image();
  2011. img.src = evt.target.result;
  2012. img.onload = function (e) { //这时img才有宽高,才能赋予texture宽高
  2013. var smallerImg = CompressImg(e.target, {
  2014. weight: blob.size,
  2015. maxWeight: 0.5 * 1024 * 1024,
  2016. maxSize: 1480
  2017. });
  2018. //最大500k
  2019. smallerImg.onload = function () {
  2020. var f = function (resultImg) {//处理结束回调
  2021. options.photoDone(resultImg)
  2022. $('.waiting').removeClass('showloading');
  2023. }
  2024. Rotate(smallerImg, orient, f)
  2025. window.URL.revokeObjectURL(blobSrc);
  2026. }
  2027. }
  2028. .bind(this)
  2029. img.onerror = loadError;
  2030. }); */
  2031. var img = new Image();
  2032. img.src = blobSrc;
  2033. img.base64Src = evt.target.result;
  2034. img.file = file;
  2035. img.onload = function(e) {
  2036. options.photoDone(img)
  2037. $('.waiting').removeClass('showloading');
  2038. }
  2039. } else if (inputType == "video") {
  2040. var video = $('<video controls="controls" x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>')[0]
  2041. video.setAttribute("crossOrigin", 'Anonymous')
  2042. //要在src设置好前解决跨域
  2043. $(video).on('contextmenu', function() {
  2044. return false;
  2045. });
  2046. //禁止右键点击出现选项(尤其是下载选项)
  2047. $(video).attr('src', blobSrc);
  2048. //华为无法使用blobSrc,否则加载不出来
  2049. //$(video).attr('src', evt.target.result);
  2050. video.base64Src = evt.target.result;
  2051. var hasload = false;
  2052. var error = false;
  2053. var up = function() {
  2054. if (hasload)
  2055. return;
  2056. hasload = true;
  2057. options.videoDone(file, video)
  2058. $('.waiting').removeClass('showloading');
  2059. }
  2060. video.addEventListener('loadeddata', function(e) {
  2061. up()
  2062. })
  2063. //video.onerror = loadError;
  2064. video.onerror = function(e) {
  2065. console.log('error')
  2066. error = true;
  2067. loadError();
  2068. //将mp4改成mov后缀会error
  2069. }
  2070. } else if (inputType == "audio") {
  2071. //林俊波 new Howl For IE&Safari:
  2072. var sound = new Howl({
  2073. src: [blobSrc],
  2074. format: ["mp3"]
  2075. });
  2076. // Clear listener after first call.
  2077. sound.once('load', function() {
  2078. console.log('loaded sound')
  2079. sound.unload()
  2080. console.log("audio.onloadeddata");
  2081. var audio = new Audio;
  2082. audio.controls = "controls";
  2083. audio.src = blobSrc;
  2084. audio.base64Src = evt.target.result;
  2085. options.audioDone(file, audio)
  2086. $('.waiting').removeClass('showloading');
  2087. //}
  2088. });
  2089. sound.once('loaderror', function() {
  2090. loadError.apply(this, arguments)
  2091. console.log('loaderror sound')
  2092. });
  2093. // Fires when the sound finishes playing.
  2094. sound.on('end', function() {
  2095. console.log('Finished sound');
  2096. });
  2097. }
  2098. }
  2099. }
  2100. e.target.value = "";
  2101. //更改value会触发change
  2102. }
  2103. .bind(player)
  2104. //滑动条控件
  2105. var SlideBar = function(o) {
  2106. var scope = this;
  2107. this.name = o.name;
  2108. this.value = o.value;
  2109. //初始值
  2110. this.min = o.min != void 0 ? o.min : 0;
  2111. this.max = this.oriMax = o.max != void 0 ? o.max : 100;
  2112. this.noValue = o.noValue;
  2113. //是否数值输入
  2114. this.precision = o.precision;
  2115. //精度 保留几位小数
  2116. 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>'))
  2117. div.addClass('slider')
  2118. if (o.unitStr) {
  2119. div.find(".BarTxt").append($('<span>' + o.unitStr + '</span>'));
  2120. }
  2121. o.root.append(div);
  2122. this.line = $(".scrollBar", div);
  2123. this.knot = $(".scroll_Thumb", div);
  2124. o.noValue || (this.textArea = $(".scrollBarTxt", div));
  2125. this.track = $(".scroll_Track", div);
  2126. this.unitStr = o.unitStr;
  2127. //unitStr是单位字符串,比如角度的°。不能是数字
  2128. this.onchange = o.onchange;
  2129. this.percent = null;
  2130. this.dragStart = false;
  2131. this.offsetToBody = null;
  2132. this.getOffset();
  2133. this.checkError();
  2134. this.percent = this.getPercent();
  2135. o.noValue || this.displayValue();
  2136. this.moveKnot();
  2137. this.knotWidth = 0;
  2138. this.lineWidth = 0;
  2139. //this.waitValue;//等待要触发事件的值,防止崩溃
  2140. this.avoidCrash = o.avoidCrash;
  2141. this.realMax = !this.noValue ? o.realMax : null;
  2142. //如果传入realMax,代表可以通过输入数字修改最大值范围,最大值不可以超过realMax。
  2143. this.scrollUnit = (scope.max - scope.min) * 0.001;
  2144. if (this.precision != void 0) {
  2145. var prec = Math.pow(10, -this.precision);
  2146. this.scrollUnit < prec && (this.scrollUnit = prec);
  2147. } else {
  2148. //默认化为整数
  2149. this.scrollUnit < 1 && (this.scrollUnit = 1);
  2150. }
  2151. this.dragStartEvent = o.dragStartEvent;
  2152. this.line.on("mousedown touchstart", function(event) {
  2153. scope.dragStart = true;
  2154. scope.dragChange(event);
  2155. if (scope.dragStartEvent)
  2156. scope.dragStartEvent()
  2157. //if(o.avoidCrash && isMobile)scope.dealInterval();
  2158. });
  2159. !window.isMobile && this.line.on("mousewheel DOMMouseScroll wheel", function(event) {
  2160. event.preventDefault();
  2161. var v = event.originalEvent.deltaY > 0 ? -scope.scrollUnit : scope.scrollUnit;
  2162. scope.setValue(scope.value + v);
  2163. });
  2164. this.dragEndEvent = o.dragEndEvent;
  2165. var stop = function() {
  2166. if (scope.dragStart) {
  2167. scope.dragStart = false;
  2168. if (scope.dragEndEvent)
  2169. scope.dragEndEvent()
  2170. }
  2171. }
  2172. $(document).on("mouseup touchend", stop)
  2173. /* isMobile || */
  2174. $("#player").on("mouseup", stop)
  2175. var lastChangeTime = 0;
  2176. $(document).on("mousemove touchmove", function() {
  2177. if (scope.dragStart) {
  2178. /* if(isMobile && o.avoidCrash){
  2179. scope.lastDragEvent = event;
  2180. }else */
  2181. scope.dragChange(event);
  2182. }
  2183. })
  2184. o.noValue || this.textArea.on("change", function() {
  2185. var v = parseFloat(scope.textArea.val());
  2186. if (v != v)
  2187. //NaN
  2188. return;
  2189. scope.setValueFromOutside(v);
  2190. });
  2191. window.addEventListener("resize",()=>{
  2192. if(this.line[0].clientWidth){
  2193. this.getOffset()
  2194. this.moveKnot();
  2195. }
  2196. })
  2197. }
  2198. SlideBar.prototype.dealInterval = function() {
  2199. this.interval = setInterval(function() {
  2200. this.lastDragEvent && this.dragChange(this.lastDragEvent);
  2201. this.lastDragEvent = null
  2202. if (!this.dragStart)
  2203. clearInterval(this.interval)
  2204. }
  2205. .bind(this), 90)
  2206. }
  2207. SlideBar.prototype.changeLimit = function(o) {
  2208. if (o.min)
  2209. this.min = o.min;
  2210. if (o.max)
  2211. this.max = o.max;
  2212. }
  2213. SlideBar.prototype.getOffset = function() {
  2214. //为了检测鼠标位置需要获得相对body的offset
  2215. var left = this.line[0].offsetLeft;
  2216. var element = this.line[0];
  2217. while (element = element.offsetParent) {
  2218. left += element.offsetLeft;
  2219. }
  2220. this.offsetToBody = (left == 0) ? (this.offsetToBody || 0) : left;
  2221. //如果left为0,很可能是它不可见,那么最好使用旧的offsetToBody
  2222. }
  2223. SlideBar.prototype.InitOffset = function() {
  2224. //如果一开始scroller没有显示,要在显示时获取一下offset
  2225. this.getOffset();
  2226. this.getWidth();
  2227. this.moveKnot();
  2228. }
  2229. SlideBar.prototype.checkError = function() {
  2230. if (this.min >= this.max) {
  2231. console.log("scrollbar值有误 " + name);
  2232. return;
  2233. }
  2234. }
  2235. SlideBar.prototype.getPercent = function() {
  2236. return (this.value - this.min) / (this.max - this.min);
  2237. }
  2238. SlideBar.prototype.displayValue = function(value) {
  2239. //this.textArea.val(this.value + (this.unitStr ? " " + this.unitStr : ""));
  2240. if (value != void 0)
  2241. this.value = value;
  2242. this.textArea.val(this.value)
  2243. }
  2244. SlideBar.prototype.getWidth = function() {
  2245. this.knotWidth = this.knot.width();
  2246. this.lineWidth = this.line.width() - this.knotWidth
  2247. }
  2248. SlideBar.prototype.moveKnot = function() {
  2249. //this.getWidth();
  2250. var width = this.percent * this.lineWidth;
  2251. this.knot.css('left', width + "px")
  2252. if (this.track)
  2253. this.track.css('width', (width + this.knotWidth / 2) + "px")
  2254. }
  2255. SlideBar.prototype.bind = function(f) {
  2256. this.onchange = f;
  2257. }
  2258. SlideBar.prototype.setValue = function(v, noEvent, changeMax) {
  2259. //设置数值并改变knot位置 noEvent为true的话就可以不触发回调函数,仅仅改变显示
  2260. //if(this.value==v)return; //因为换选材质需要执行后面onchange才会带动preview的改变,所以这里一样还是执行,而拉动滑动条的部分值不变就不执行
  2261. if (this.precision != void 0) {
  2262. this.value = parseFloat(v.toFixed(this.precision))
  2263. } else {
  2264. //默认化为整数
  2265. this.value = Math.round(v);
  2266. }
  2267. if (changeMax && this.realMax != void 0) {
  2268. if (this.value > this.oriMax) {
  2269. this.value = Math.min(this.value, this.realMax);
  2270. this.changeLimit({
  2271. max: this.value
  2272. })
  2273. } else {
  2274. this.changeLimit({
  2275. max: this.oriMax
  2276. })
  2277. }
  2278. }
  2279. this.percent = this.getPercent();
  2280. var makeit = true;
  2281. if (this.onchange && !noEvent) {
  2282. var result = this.onchange(this.value);
  2283. //如果执行的函数不允许这个值,就不能变
  2284. if (result === false) {
  2285. makeit = false;
  2286. }
  2287. }
  2288. if (makeit) {
  2289. this.moveKnot();
  2290. //console.log("SlideBarV-"+this.name + " : "+this.value)
  2291. this.noValue || this.displayValue();
  2292. }
  2293. }
  2294. SlideBar.prototype.dragChange = function(event) {
  2295. //拖动时触发 计算数值
  2296. //this.getWidth();
  2297. //if(!this.offsetToBody || isNaN(this.offsetToBody)this.getOffset();
  2298. if (event.clientX != void 0) {
  2299. this.percent = (event.clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2300. } else {
  2301. if (event.touches != void 0) {
  2302. this.percent = (event.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2303. } else
  2304. this.percent = (event.originalEvent.touches[0].clientX - this.knotWidth / 2 - this.offsetToBody) / this.lineWidth;
  2305. }
  2306. if (this.percent < 0)
  2307. this.percent = 0;
  2308. else if (this.percent > 1)
  2309. this.percent = 1;
  2310. //var v = this.percent * this.max;
  2311. var v = this.percent * (this.max - this.min) + this.min;
  2312. //var v = Math.round(this.percent * this.max * 10)/10; //精度为0.1
  2313. if (this.value == v)
  2314. return;
  2315. this.setValue(v);
  2316. }
  2317. SlideBar.prototype.setValueFromOutside = function(v) {
  2318. //外面的事件触发的
  2319. if (this.line.width() == 0)
  2320. return;
  2321. //不可见就不执行。
  2322. //v = Math.round(v*10)/10;
  2323. if (this.realMax != void 0) {
  2324. v = THREE.Math.clamp(v, this.min, this.realMax);
  2325. if (v > this.max)
  2326. this.changeLimit({
  2327. max: v
  2328. });
  2329. } else
  2330. v = THREE.Math.clamp(v, this.min, this.max);
  2331. this.setValue(v);
  2332. }
  2333. //-----------------------------------------------------
  2334. var LineDraw = {
  2335. createLine: function(posArr, o) {
  2336. var e = new THREE.BufferGeometry
  2337. , p = new Float32Array(6);
  2338. e.addAttribute("position", new THREE.BufferAttribute(p,3));
  2339. //这句新旧版写法不同 旧版这样:e.addAttribute("position",Float32Array,2,3);
  2340. var p = e.attributes.position.array;
  2341. for (var i = 0; i < 2; i++) {
  2342. p[i * 3] = posArr[i].x;
  2343. p[i * 3 + 1] = posArr[i].y;
  2344. p[i * 3 + 2] = posArr[i].z;
  2345. }
  2346. var mat = new THREE[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"]({
  2347. linewidth: o.width || 1,
  2348. //windows无效。 似乎mac/ios上粗细有效 ?
  2349. color: o.color || defaultColor,
  2350. transparent: o.dontAlwaysSeen ? false : true,
  2351. depthTest: o.dontAlwaysSeen ? true : false
  2352. })
  2353. var line = new THREE.Line(e,mat);
  2354. line.renderOrder = o.renderOrder || 4
  2355. //同tagStem; //如果不加高,可能会部分被model遮住
  2356. return line;
  2357. }
  2358. }
  2359. var toPrecision = function(e, t) {
  2360. function i(e, t) {
  2361. var i = Math.pow(10, t);
  2362. return Math.round(e * i) / i
  2363. }
  2364. if (e instanceof Array) {
  2365. for (var n = 0; n < e.length; n++)
  2366. e[n] = i(e[n], t);
  2367. return e
  2368. }
  2369. return i(e, t)
  2370. }
  2371. var transformControls;
  2372. var initTransformCtl = function(THREE) {
  2373. TransformControls.init(THREE)
  2374. TransformControls.prototype.transCtlChangeMode = function(mode) {
  2375. //if(!this.editing)return;
  2376. if (mode && this.mode != mode) {
  2377. this.mode = mode;
  2378. $(".MenuOptions[name='transform'] li").removeClass("chosen");
  2379. $(".MenuOptions[name='transform'] li[index='" + mode + "']").addClass("chosen");
  2380. }
  2381. }
  2382. ,
  2383. transformControls = new TransformControls(player.camera,player.domElement,{
  2384. player: player,
  2385. dontHideWhenFaceCamera: true,
  2386. scaleAxis: ["x", "y"],
  2387. //隐藏了z轴。虽然参数没用上
  2388. NoScaleZ: true //整体缩放时只缩放xy轴。
  2389. });
  2390. transformControls.space = 'local'//为了在当前方向上平移
  2391. transformControls.setSize(1.5)
  2392. player.model.add(transformControls)
  2393. $(".MenuOptions[name='transform'] li").on("click", (e)=>{
  2394. transformControls.transCtlChangeMode($(e.target).attr("index"))
  2395. }
  2396. )
  2397. }
  2398. var EditOverlay = {
  2399. editing: false,
  2400. overlayMaxCount: 10,
  2401. scroller: {
  2402. videoDepth: new SlideBar({
  2403. root: $('#videoDepth').eq(0),
  2404. value: settings.overlay.depth * 100,
  2405. min: 0 * 100,
  2406. max: 1 * 100,
  2407. name: "videoDepth",
  2408. unitStr: "cm",
  2409. avoidCrash: true,
  2410. onchange: function(s) {
  2411. if (s == 0) {
  2412. EditOverlay.editPlane.addBox(false)
  2413. } else {
  2414. EditOverlay.editPlane.addBox(true)
  2415. EditOverlay.editPlane.scale.z = s / 100 / settings.overlay.depth;
  2416. }
  2417. },
  2418. dragEndEvent: function() {
  2419. }
  2420. })
  2421. },
  2422. panoPosSwitch : $('#setOverlayPosForPano input') // 当前漫游点独立调整位置开关
  2423. ,
  2424. init: function(THREE) {
  2425. var mat = new THREE.MeshBasicMaterial({
  2426. wireframe: true,
  2427. opacity: 0.5,
  2428. color: "#57e4f3",
  2429. transparent: true
  2430. })
  2431. var wireframeModel = this.wireframeModel = new THREE.Object3D;
  2432. wireframeModel.name = 'wireframeModel'
  2433. player.model.chunks.forEach((mesh)=>{
  2434. var chunk = mesh.clone();
  2435. chunk.material = mat;
  2436. wireframeModel.add(chunk)
  2437. }
  2438. )
  2439. wireframeModel.visible = false
  2440. player.model.add(wireframeModel)
  2441. //------------------------------
  2442. this.panoPosSwitch.on("change", this.panoPosSwitchOnChange.bind(this))
  2443. $('.overlay .addBtn button').on("click", this.beginToAddPlane.bind(this))
  2444. $("#overlayProp a.close").on("click", ()=>{
  2445. this.closeOverlayPanel("cancel")
  2446. }
  2447. )
  2448. $("#overlayProp button.submit").on("click", (e)=>{
  2449. this.SaveOverlay()
  2450. }
  2451. )
  2452. $("#overlayProp button.delete").on("click", (e)=>{
  2453. this.DeleteOverlay();
  2454. }
  2455. )
  2456. $('#overlayUpload [name="useImgRatio"] button').on("click", this.useImgRatio.bind(this));
  2457. var uploadInputs = {
  2458. video : $('<input type="file" style="display:none" accept="video/*"></input>'),
  2459. photo : $('<input type="file" style="display:none" accept="image/*"></input>')
  2460. }
  2461. $('#overlayUpload [name="upload"] button').on('click', ()=>{
  2462. uploadInputs[this.editType].click()
  2463. })
  2464. uploadInputs.video.on("change", (e)=>{
  2465. inputMedia({
  2466. enableTypes: [this.editType ],
  2467. videoDone: (file,video)=>{
  2468. var plane = this.editPlane.plane
  2469. $(video).css('width', '100%')
  2470. $(video).css('height', '100%')
  2471. plane.material.map = new THREE.VideoTexture(video);
  2472. plane.material.map.image.play();
  2473. plane.material.map.minFilter = THREE.LinearFilter;
  2474. this.editPlane.overlayType = "video";
  2475. $('#overlayUpload .preview video').remove();
  2476. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2477. video.autoplay = true;
  2478. video.loop = true;
  2479. video.volume = 0
  2480. video.muted = true
  2481. this.useImgRatio()
  2482. //自适应比例
  2483. this.editPlane.file = file;
  2484. plane.material.opacity = 1;
  2485. plane.material.color = new THREE.Color(1,1,1)
  2486. plane.material.needsUpdate = true;
  2487. }
  2488. }, "video", e);
  2489. }
  2490. )
  2491. uploadInputs.photo.on("change", (e)=>{
  2492. inputMedia({
  2493. enableTypes: [this.editType ],
  2494. photoDone: (photo)=>{
  2495. var plane = this.editPlane.plane
  2496. /* $(video).css('width', '100%')
  2497. $(video).css('height', '100%') */
  2498. plane.material.map = new THREE.Texture();
  2499. plane.material.map.image = photo
  2500. plane.material.map.needsUpdate = !0
  2501. plane.material.map.minFilter = THREE.LinearFilter;
  2502. this.editPlane.overlayType = "photo";
  2503. $('#overlayUpload .preview video').remove();
  2504. //$('#overlayUpload .preview').css('background-image',"").append($(video));
  2505. this.useImgRatio()
  2506. //自适应比例
  2507. this.editPlane.file = photo.file;
  2508. plane.material.opacity = 1;
  2509. plane.material.color = new THREE.Color(1,1,1)
  2510. plane.material.needsUpdate = true;
  2511. }
  2512. }, "photo", e);
  2513. }
  2514. )
  2515. player.overlayGroup.children.forEach((overlay)=>{
  2516. if(!overlay.plane.material.map || !overlay.plane.material.map.image){
  2517. overlay._loadDones = [()=>{this.getOverlayInfo(overlay)}]
  2518. }
  2519. else {
  2520. this.getOverlayInfo(overlay)
  2521. }
  2522. this.addToList(overlay)
  2523. }
  2524. )
  2525. },
  2526. enter: function() {
  2527. this.editing = true;
  2528. this.wireframeModel.visible = true;
  2529. },
  2530. leave: function() {
  2531. if (!this.editing)
  2532. return;
  2533. this.editing = false
  2534. $("#overlayProp a.close").click();
  2535. this.endAddPlane();
  2536. this.wireframeModel.visible = false;
  2537. },
  2538. switchEditType : function(type){
  2539. this.editType = type;
  2540. $('#overlayUpload [name="upload"] button').text(type == 'video' ? "上传视频" : "上传图片")
  2541. $('#overlayUpload .preview span').text(type == 'video' ? "支持MP4、MOV等,<20M" : "支持jpg、png等,<20M");
  2542. },
  2543. beginToAddPlane: function(event) {
  2544. this.switchEditType($(event.target).attr("data-type"))
  2545. player.reticule.visible = false;
  2546. this.objCursorType = 'overlay';
  2547. player.currentCursor = 'url(images/edit/box_video.png), auto'
  2548. $('#player').css('cursor', player.currentCursor)
  2549. $('.overlay .addBtn button').addClass("unable")
  2550. //可以加多个视频时的按钮
  2551. },
  2552. endAddPlane: function() {
  2553. this.objCursorType = null;
  2554. player.currentCursor = '';
  2555. $('#player').css('cursor', '')
  2556. $('.overlay .addBtn button').removeClass("unable")
  2557. player.reticule.visible = true
  2558. },
  2559. addPlane: function(o) {
  2560. if(!o.intersect)return;
  2561. var pos = o.intersect.point;
  2562. var overlay = new Overlay({
  2563. sid: new Date().getTime() + ""
  2564. })
  2565. overlay.hasRequestLoad = true
  2566. overlay.position.copy(pos);
  2567. if (player.getMouseDirection().angleTo(o.intersect.face.normal) < Math.PI / 2) {
  2568. overlay.lookAt(o.intersect.face.normal.clone().negate().add(pos));
  2569. overlay.position.add(o.intersect.face.normal.clone().negate().multiplyScalar(0.01))
  2570. //avoid mesh crash with chunks 模型的精度可能和floorplan的不一样,所以chunk即使材质经过处理还是会闪烁但是wallmesh不会
  2571. } else {
  2572. overlay.lookAt(o.intersect.face.normal.clone().add(pos));
  2573. overlay.position.add(o.intersect.face.normal.clone().multiplyScalar(0.01))
  2574. }
  2575. overlay.posCustom = overlay.position.clone();
  2576. overlay.quaCustom = overlay.quaternion.clone();
  2577. overlay.widthCustom = overlay.width;
  2578. overlay.heightCustom = overlay.height;
  2579. overlay.isNew = true
  2580. player.clickOverlay(overlay)
  2581. transformControls.transCtlChangeMode("translate")
  2582. this.addToList(overlay)
  2583. },
  2584. updateOverlayScaleDisplay: function() {
  2585. var overlay = this.editPlane;
  2586. var maxWidth = 193
  2587. , maxHeight = maxWidth
  2588. //maxWidth/2;
  2589. var ratioW = Math.abs(overlay.width) / maxWidth;
  2590. var ratioH = Math.abs(overlay.height) / maxHeight;
  2591. var ratio = 1 / Math.max(ratioW, ratioH);
  2592. //缩放比例
  2593. var w = Math.round(Math.abs(overlay.width) * ratio)
  2594. var h = Math.round(Math.abs(overlay.height) * ratio)
  2595. $('#overlayUpload .preview').css({
  2596. "width": w + 'px',
  2597. "height": h + 'px',
  2598. });
  2599. $('#overlayUpload .preview [attr-type="width"]').text(toPrecision(overlay.width, 2))
  2600. $('#overlayUpload .preview [attr-type="height"]').text(toPrecision(overlay.height, 2))
  2601. },
  2602. updateOverlayPanel: function(overlay) {
  2603. this.editPlane = overlay;
  2604. overlay.requestDownload()
  2605. if(overlay._loadDones){
  2606. $('.waiting').addClass('showloading');
  2607. overlay._loadDones.push(()=>{
  2608. $('.waiting').removeClass('showloading');
  2609. })
  2610. }
  2611. var plane = overlay.plane
  2612. var src = plane.material.map && (plane.material.map.image ? plane.material.map.image.src : overlay.fileSrc );
  2613. $('#overlayUpload .preview video').remove();
  2614. overlay.overlayType && this.switchEditType(overlay.overlayType)
  2615. if (overlay.overlayType == "video") {
  2616. var video = plane.material.map.image
  2617. $('#overlayUpload .preview').css({'background-image':"", 'background-size':""}).append(video);
  2618. } else if(overlay.overlayType == "photo" || overlay.overlayType == "text"){
  2619. $('#overlayUpload .preview').css({
  2620. 'background-image': src ? ("url(" + src + ")") : "",
  2621. 'background-size': "contain"
  2622. })
  2623. }else{
  2624. $('#overlayUpload .preview').css({
  2625. 'background-image': "",
  2626. 'background-size': ""
  2627. })
  2628. }
  2629. if (overlay.overlayType) {
  2630. $('#overlayUpload [name="useImgRatio"]').removeClass("hide")
  2631. $('#overlayUpload .preview').addClass('uploaded')
  2632. } else {
  2633. $('#overlayUpload [name="useImgRatio"]').addClass("hide")
  2634. $('#overlayUpload .preview').removeClass('uploaded')
  2635. }
  2636. this.updateOverlayScaleDisplay()
  2637. if (overlay.hasBox) {
  2638. this.scroller.videoDepth.setValue(overlay.scale.z * settings.overlay.depth * 100, true)
  2639. } else {
  2640. this.scroller.videoDepth.setValue(0, true)
  2641. }
  2642. setTimeout(()=>{
  2643. this.scroller.videoDepth.InitOffset()
  2644. }
  2645. , 201)
  2646. player.currentPano && this.updatePano(player.currentPano)
  2647. },
  2648. //----------------------------
  2649. panoPosSwitchOnChange : function(){
  2650. var on = this.panoPosSwitch.is(':checked')
  2651. if(!on) delete this.editPlane.transformAtPanos[player.currentPano.id]
  2652. }
  2653. ,
  2654. getTransformAtPano : function(){
  2655. this.editPlane.transformAtPanos[player.currentPano.id] = {
  2656. pos : this.editPlane.position.clone(),
  2657. qua : this.editPlane.quaternion.clone(),
  2658. width : this.editPlane.width,
  2659. height : this.editPlane.height,
  2660. }
  2661. },
  2662. updatePosition:function(){
  2663. var on = this.panoPosSwitch.is(':checked')
  2664. if(on && player.mode == 'panorama'){
  2665. this.getTransformAtPano()
  2666. }else{
  2667. this.editPlane.posCustom.copy(this.editPlane.position)
  2668. }
  2669. },
  2670. updateScale : function(){
  2671. var on = this.panoPosSwitch.is(':checked')
  2672. var size = this.editPlane.getSizeByScale( )
  2673. this.editPlane.width = size.width
  2674. this.editPlane.height = size.height
  2675. if(on && player.mode == 'panorama'){
  2676. this.getTransformAtPano()
  2677. }else{
  2678. this.editPlane.widthCustom = this.editPlane.width
  2679. this.editPlane.heightCustom = this.editPlane.height
  2680. }
  2681. this.updateOverlayScaleDisplay()
  2682. }
  2683. ,
  2684. updateQua : function(){
  2685. var on = this.panoPosSwitch.is(':checked')
  2686. if(on && player.mode == 'panorama'){
  2687. this.getTransformAtPano()
  2688. }else{
  2689. this.editPlane.quaCustom.copy(this.editPlane.quaternion)
  2690. }
  2691. }
  2692. ,
  2693. updatePano:function(pano){
  2694. if(!EditOverlay.editPlane ) return;
  2695. this.panoPosSwitch.prop('checked', !!EditOverlay.editPlane.transformAtPanos[pano.id]);
  2696. },
  2697. //------------------------------
  2698. closeOverlayPanel: function(type) {
  2699. if (!this.editPlane)
  2700. return;
  2701. if (type == 'cancel') {
  2702. if (!this.editPlane.isNew && !this.editPlane.needDelete)
  2703. this.editPlane.setFromInfo(this.editPlane.info)
  2704. //this.setOverlayFromInfo(this.editPlane, this.editPlane.info);//恢复
  2705. else
  2706. this.disposeOverlay(this.editPlane);
  2707. //删除
  2708. }
  2709. this.editPlane = null;
  2710. transformControls.detach()
  2711. $("#overlayProp").addClass("atRight");
  2712. //if(player.model.overlayPlanes.length < this.overlayMaxCount) this.beginToAddPlane()
  2713. },
  2714. useImgRatio: function(o) {
  2715. var plane = this.editPlane.plane;
  2716. if (!plane.material.map)
  2717. return;
  2718. var img = plane.material.map.image;
  2719. var mintranRatio = 200;
  2720. //default is 200 , 防止图片太小时在墙上依旧很大
  2721. var width = this.editPlane.overlayType == "video" ? img.videoWidth : img.width;
  2722. var height = this.editPlane.overlayType == "video" ? img.videoHeight : img.height;
  2723. if (o == "suitSize") {
  2724. var boundWidth = Math.min(Math.max(width, height) / mintranRatio, 1)
  2725. if (width > height) {
  2726. var w = boundWidth;
  2727. var h = boundWidth * height / width
  2728. } else {
  2729. var h = boundWidth;
  2730. var w = boundWidth * width / height;
  2731. }
  2732. } else {
  2733. //假设不变总面积
  2734. var k = Math.sqrt(Math.abs(this.editPlane.width * this.editPlane.height) / (width * height))
  2735. var w = k * width * (this.editPlane.width < 0 ? -1 : 1);
  2736. var h = k * height * (this.editPlane.height < 0 ? -1 : 1);
  2737. }
  2738. this.editPlane.scale.setX(w / settings.overlay.width)
  2739. this.editPlane.scale.setY(h / settings.overlay.height)
  2740. this.editPlane.width = w;
  2741. this.editPlane.height = h;
  2742. this.updateScale()
  2743. this.updateOverlayPanel(this.editPlane)
  2744. },
  2745. getOverlayInfo: function(overlay) {
  2746. //2 编辑前, 从当前状态获取info
  2747. var plane = overlay.plane;
  2748. var transformAtPanos = {}
  2749. for(var i in overlay.transformAtPanos){
  2750. transformAtPanos[i] = {
  2751. width : overlay.transformAtPanos[i].width,
  2752. height : overlay.transformAtPanos[i].height,
  2753. pos : overlay.transformAtPanos[i].pos.clone(),
  2754. qua : overlay.transformAtPanos[i].qua.clone(),
  2755. }
  2756. }
  2757. overlay.info = {
  2758. width: overlay.widthCustom,
  2759. height: overlay.heightCustom,
  2760. depth: settings.overlay.depth * overlay.scale.z,
  2761. pos: overlay.posCustom.clone(),
  2762. qua: overlay.quaCustom.clone(),
  2763. media: plane.material.map.image,
  2764. file: overlay.file,
  2765. type: overlay.overlayType,
  2766. hasBox: overlay.hasBox,
  2767. transformAtPanos: transformAtPanos
  2768. }
  2769. },
  2770. getSavingInfo: function(overlay) {
  2771. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  2772. return;
  2773. }
  2774. var transformAtPanos = {}
  2775. for(var i in overlay.transformAtPanos){
  2776. transformAtPanos[i] = {
  2777. width : toPrecision(overlay.transformAtPanos[i].width, 4),
  2778. height : toPrecision(overlay.transformAtPanos[i].height, 4),
  2779. pos : toPrecision(overlay.transformAtPanos[i].pos.toArray(), 3),
  2780. qua : toPrecision(overlay.transformAtPanos[i].qua.toArray(), 5)
  2781. }
  2782. }
  2783. var info = {
  2784. width: toPrecision(overlay.widthCustom, 4),
  2785. height: toPrecision(overlay.heightCustom, 4),
  2786. depth: toPrecision(settings.overlay.depth * overlay.scale.z, 4),
  2787. pos: toPrecision(overlay.posCustom.toArray(), 3),
  2788. qua: toPrecision(overlay.quaCustom.toArray(), 5),
  2789. sid: overlay.sid,
  2790. hasBox: overlay.hasBox ? 1 : 0,
  2791. media: [overlay.overlayType],
  2792. file: overlay.fileSrc || overlay.plane.material.map.image.src,
  2793. transformAtPanos : transformAtPanos
  2794. }
  2795. return info
  2796. },
  2797. SaveOverlay: function() {
  2798. var overlay = this.editPlane;
  2799. if (!overlay.file && (!overlay.plane.material.map || !overlay.plane.material.map.image)) {
  2800. this.editType == "video" ? alert("请上传视频") : alert("请上传图片");
  2801. return;
  2802. }
  2803. var saveInfo = ()=>{
  2804. //overlay.savingInfo = JSON.stringify(info)//准备写入的info
  2805. //saveDone:
  2806. overlay.isNew = false;
  2807. this.getOverlayInfo(overlay);
  2808. this.closeOverlayPanel()
  2809. $('.waiting').removeClass('showloading');
  2810. }
  2811. if (!overlay.info || overlay.file != overlay.info.file) {
  2812. $('.waiting').addClass('showloading');
  2813. uploadFile(overlay.file, 'overlay', function(rs) {
  2814. if (rs.code === 0) {
  2815. overlay.fileSrc = rs.data;
  2816. saveInfo()
  2817. }
  2818. ;
  2819. })
  2820. } else
  2821. saveInfo();
  2822. },
  2823. disposeOverlay: function(overlay) {
  2824. var plane = overlay.plane
  2825. if (overlay == player.hoveringPlane) {
  2826. player.hoverOverlay(null, "soon");
  2827. }
  2828. if (plane.material.map) {//删除视频src
  2829. //overlay.info && common.destroyBlob(overlay.info.media.src)
  2830. //common.destroyBlob(plane.material.map.image.src)
  2831. }
  2832. plane.material.dispose();
  2833. overlay.parent.remove(overlay);
  2834. this.removeFromList(overlay)
  2835. //this.beginToAddPlane()
  2836. },
  2837. DeleteOverlay: function() {
  2838. var overlay = this.editPlane;
  2839. if (!overlay.isNew) {
  2840. if (confirm(overlay.overlayType== "photo" ? "确定删除该图片?" : "确定删除该视频?")) {
  2841. overlay.needDelete = true;
  2842. $("#overlayProp a.close").click()
  2843. //this.closeOverlayPanel()
  2844. }
  2845. } else {
  2846. //刚创建时的删除按钮等同于取消按钮
  2847. $("#overlayProp a.close").click()
  2848. //this.closeOverlayPanel()
  2849. }
  2850. },
  2851. addToList: function(overlay) {
  2852. var li = $(`<li class='listItem'><div class="icon"></div><div class="title">${(overlay.overlayType == "video" ? "视频 ":"图片 ")+ overlay.sid}</div></li>`)
  2853. $(".overlayList ul").append(li);
  2854. li.on("click", ()=>{
  2855. player.clickOverlay(overlay)
  2856. }
  2857. )
  2858. overlay.domLi = li;
  2859. },
  2860. removeFromList: function(overlay) {
  2861. overlay.domLi.remove();
  2862. }
  2863. }
  2864. //----------------漫游可见性---------------------------------
  2865. var VisiSet = {
  2866. setPanoVisible: false,
  2867. setTagVisible: false,
  2868. panoVLines: {},
  2869. //线条
  2870. panoVTemp: {},
  2871. //修改后还没保存的临时数据
  2872. tagVsetting: null,
  2873. //正在设置的热点中心点
  2874. tagsVLines: {},
  2875. //线条
  2876. //tagVTemp //修改后还没保存的临时数据
  2877. //热点可见性
  2878. $confirmSnap: $("#camera-start"),
  2879. colors: {
  2880. green: "#00c8ae"
  2881. },
  2882. init: function() {
  2883. this.meshGroup = new THREE.Object3D;
  2884. this.meshGroup.name = "setVisible-group"
  2885. player.model.add(this.meshGroup)
  2886. $("#hotVisible").on("click", ()=>{
  2887. VisiSet.enterSet(VisiSet.beginSetTagVisible.bind(VisiSet))
  2888. }
  2889. )
  2890. },
  2891. enterSet: function(fun) {
  2892. var enter = function() {
  2893. if (player.modeTran.split('-')[1] != "floorplan") {
  2894. setTimeout(fun, 300)
  2895. //提前一点出现
  2896. }
  2897. player.flyToMode("floorplan", fun);
  2898. }
  2899. permitTranMode(false)
  2900. if (!player.modeTran) {
  2901. player.afterCModeFuc = ()=>{
  2902. enter()
  2903. }
  2904. } else
  2905. enter()
  2906. },
  2907. beginSetPanoVisible: function() {
  2908. $(".toolLeft").removeClass("unable")
  2909. if (this.setPanoVisible)
  2910. return;
  2911. this.setPanoVisible = true;
  2912. this.panoVTemp = {};
  2913. this.SetOnePanoVisible(player.currentPano)
  2914. //先设置currentPano
  2915. this.$confirmSnap.text('保存当前设置').removeClass("hide")
  2916. //objects.tagManager.hideAllTags();
  2917. this.setDisplay(true)
  2918. this.updateFootIconSize()
  2919. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  2920. for(let i in player.model.hots){
  2921. player.model.hots[i].visi_ = player.model.hots[i].mesh.visible;
  2922. player.model.hots[i].mesh.visible = false
  2923. }
  2924. },
  2925. SetOnePanoVisible: function(pano) {
  2926. //点击某个pano后就对该pano点进行设置
  2927. if (this.panoVsetting == pano)
  2928. return;
  2929. //if (this.panoVsetting) saveLastPanoVi(this.panoVsetting);
  2930. this.panoVsetting = pano;
  2931. //记录正在修改的
  2932. this.delVisibleLines();
  2933. //删除线
  2934. this.showFootIcons(pano, true);
  2935. this.createPanoVisiLines(pano);
  2936. //创线
  2937. },
  2938. saveLastPanoVi: function() {
  2939. //保存刚设置过的pano
  2940. var change = [];
  2941. for (var r in this.panoVLines) {
  2942. var line = this.panoVLines[r];
  2943. if (line.name.indexOf("new") > -1 && line.visible) {
  2944. //新设置为visible且没有取消
  2945. change.push({
  2946. type: "add",
  2947. id: r
  2948. })
  2949. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  2950. //旧的且已经取消
  2951. change.push({
  2952. type: "sub",
  2953. id: r
  2954. })
  2955. }
  2956. }
  2957. if (change.length) {
  2958. //添加双向的neighbour:
  2959. var self = this.searchNeib(this.panoVsetting.id)
  2960. //var seeMarkers_self = self.seeMarkers;
  2961. var neighbourUUIDs_self = self.neighbourUUIDs
  2962. var neighbourPanos_self = self.neighbourPanos;
  2963. for (var i = 0; i < change.length; i++) {
  2964. var other = this.searchNeib(change[i].id)
  2965. //var seeMarkers = other.seeMarkers;
  2966. var neighbourUUIDs = other.neighbourUUIDs;
  2967. var neighbourPanos = other.neighbourPanos;
  2968. if (change[i].type == "add") {
  2969. //seeMarkers.push(this.panoVsetting.id);
  2970. neighbourUUIDs.push(this.panoVsetting.id);
  2971. neighbourPanos[this.panoVsetting.id] = true;
  2972. //seeMarkers_self.push(change[i].id);
  2973. neighbourUUIDs_self.push(change[i].id);
  2974. neighbourPanos_self[change[i].id] = true;
  2975. } else {
  2976. //var index = seeMarkers.indexOf(this.panoVsetting.id);
  2977. //index > -1 && seeMarkers.splice(index, 1);
  2978. var index = neighbourUUIDs.indexOf(this.panoVsetting.id);
  2979. index > -1 && neighbourUUIDs.splice(index, 1);
  2980. neighbourPanos[this.panoVsetting.id] = false;
  2981. //var index = seeMarkers_self.indexOf(change[i].id);
  2982. //index > -1 && seeMarkers_self.splice(index, 1);
  2983. var index = neighbourUUIDs_self.indexOf(change[i].id);
  2984. index > -1 && neighbourUUIDs_self.splice(index, 1);
  2985. neighbourPanos_self[change[i].id] = false;
  2986. }
  2987. this.panoVTemp[change[i].id] = {
  2988. //后面两个是作为保存到后台的数据存储,临时需要用到的是第一个
  2989. neighbourPanos: neighbourPanos,
  2990. //seeMarkers: seeMarkers,
  2991. neighbourUUIDs: neighbourUUIDs
  2992. }
  2993. }
  2994. this.panoVTemp[this.panoVsetting.id] = {
  2995. //加上自己
  2996. neighbourPanos: neighbourPanos_self,
  2997. //seeMarkers: seeMarkers_self,
  2998. neighbourUUIDs: neighbourUUIDs_self
  2999. }
  3000. }
  3001. },
  3002. pauseSetPanoVisible: function(type) {
  3003. //暂停 因为点击了保存设置 但没有退出设置
  3004. if (!this.setPanoVisible)
  3005. return;
  3006. if (type == "unsaved") {
  3007. //中途点击pano从而停止一个热点的设置
  3008. this.saveLastPanoVi();
  3009. } else {
  3010. this.panoVTemp = {};
  3011. //清空数据
  3012. }
  3013. this.delVisibleLines();
  3014. this.showFootIcons();
  3015. //清空选择
  3016. var lastPanoSetting = this.panoVsetting;
  3017. this.panoVsetting = null;
  3018. lastPanoSetting && this.changeFIconState2(lastPanoSetting.footIcon, this.checkHasNeighbor(lastPanoSetting))
  3019. //这句要放在this.panoVsetting = null后。 根据可见性更改透明度
  3020. },
  3021. //按理说改变了neighbourPano,tag的初始visible也要改。但是这样还要考虑已经改过的tag。。很麻烦
  3022. finishSetPanoVisible: function() {
  3023. //结束 退出这个设置
  3024. if (!this.setPanoVisible)
  3025. return;
  3026. //否则会加多个侦听
  3027. this.setPanoVisible = false;
  3028. this.hideFootIcons();
  3029. this.delVisibleLines();
  3030. //objects.tagManager.showAllTags();
  3031. this.recoverAllState2();
  3032. this.panoVsetting = null;
  3033. this.panoVTemp = {};
  3034. player.flyoutType = null
  3035. this.$confirmSnap.addClass("hide")
  3036. permitTranMode(true)
  3037. this.setDisplay(false)
  3038. for(let i in player.model.hots){
  3039. player.model.hots[i].mesh.visible = player.model.hots[i].visi_
  3040. }
  3041. },
  3042. recoverAllState2: function() {
  3043. //为了热点可视恢复成pano全部可见
  3044. if(!this.footIcons)return;
  3045. for (var i = 0; i < this.footIcons.length; i++) {
  3046. this.footIcons[i].material.uniforms.opacity.value = 1;
  3047. this.footIcons[i].material.uniforms.map.value = footTex1;
  3048. }
  3049. },
  3050. afterSavePanoVisibles: function() {
  3051. //实施:
  3052. var panos = player.model.panos;
  3053. for (var i in this.panoVTemp) {
  3054. var pano = panos.index[i];
  3055. //pano.seeMarkers = this.panoVTemp[i].seeMarkers;
  3056. pano.neighbourUUIDs = this.panoVTemp[i].neighbourUUIDs;
  3057. pano.neighbourPanos = this.panoVTemp[i].neighbourPanos;
  3058. }
  3059. if (!this.checkHasNeighbor(player.currentPano)) {
  3060. //currentPano变为孤立点 就要换一个防止飞入
  3061. var list = panos.sortByScore([pano=>{
  3062. return this.checkHasNeighbor(pano)
  3063. }
  3064. ], [function(pano) {
  3065. return -pano.position.distanceTo(player.currentPano.position)
  3066. }
  3067. ])
  3068. if (list && list.length) {
  3069. player.currentPano = list[0].pano;
  3070. //找最近的一非孤立点
  3071. //this.noPanoHasNeighbor = false; //更新状态
  3072. } else {//this.noPanoHasNeighbor = true; //更新状态
  3073. }
  3074. } else {//this.noPanoHasNeighbor = false; //更新状态
  3075. }
  3076. //dataDeal.done();
  3077. //暂时:
  3078. this.pauseSetPanoVisible()
  3079. this.updateFootIconSize()
  3080. //更新一下center大小 写在最后
  3081. },
  3082. //最佳推荐操作顺序: 先设置pano可见性 再创建热点 这样热点的visible正确些,否则之后再设置热点可见性会改更多
  3083. savePanoVisibles: function() {
  3084. //保存
  3085. if (this.panoVsetting)
  3086. this.saveLastPanoVi(this.panoVsetting);
  3087. //获取最后设置的那个热点的改动
  3088. var PanoData = [];
  3089. for (var i in this.panoVTemp) {
  3090. PanoData.push({
  3091. //希望算法部不会更改index排序,或者更改后能将visible信息一并更改
  3092. panoID: i,
  3093. //visibles: this.turnToPanoIndex(this.panoVTemp[i].seeMarkers),
  3094. visibles3: this.turnToPanoIndex(this.panoVTemp[i].neighbourUUIDs)
  3095. })
  3096. }
  3097. if (PanoData.length == 0) {
  3098. //没改变
  3099. alert("保存成功")
  3100. return;
  3101. }
  3102. /* this.afterSavePanoVisibles()
  3103. alert("保存成功")
  3104. console.log(JSON.stringify(PanoData)) */
  3105. let url = cmp ? ('/api/scene/roamViable/' + cmp) : '/manage/scene/roamViable'
  3106. $.ajax({
  3107. method: 'POST',
  3108. url: ceshi + url,
  3109. headers: {
  3110. 'Content-Type': 'application/json',
  3111. token: token
  3112. },
  3113. contentType: 'application/json',
  3114. data: JSON.stringify({
  3115. data: JSON.stringify(PanoData),
  3116. sceneCode: window.number
  3117. }),
  3118. success: (data)=>{
  3119. if (data.code === 0) {
  3120. this.afterSavePanoVisibles()
  3121. alert("保存漫游可行成功")
  3122. } else
  3123. alert("保存漫游可行失败")
  3124. if (data.code === 5001) {
  3125. alert('请重新登录')
  3126. localStorage.dcj_token = ''
  3127. location.reload()
  3128. }
  3129. }
  3130. ,
  3131. fail: function() {
  3132. alert("保存漫游可行失败")
  3133. }
  3134. })
  3135. /* var o = {
  3136. name_t: "panoVisible",
  3137. f: this.pauseSetPanoVisible,
  3138. url: Config.prefixEditProPCApi+"/saveLinkPano",
  3139. dialog: i18n.get('设置'),
  3140. data: { data: JSON.stringify(PanoData) }
  3141. }
  3142. var dataDeal = uploadsSaving.saveFucforPC(o);
  3143. dataDeal.group[0] = function () {
  3144. //实施:
  3145. for (var i in player.panoVTemp) {
  3146. var pano = player.model.panos.index[i];
  3147. pano.seeMarkers = player.panoVTemp[i].seeMarkers;
  3148. pano.neighbourUUIDs = player.panoVTemp[i].neighbourUUIDs;
  3149. pano.neighbourPanos = player.panoVTemp[i].neighbourPanos;
  3150. }
  3151. if(!player.model.checkHasNeighbor(player.currentPano)){//currentPano变为孤立点 就要换一个防止飞入
  3152. var list = player.model.panos.sortByScore([function(pano){return player.model.checkHasNeighbor(pano)}],
  3153. [function(pano){return -pano.position.distanceTo(player.currentPano.position)}])
  3154. if(list && list.length){
  3155. player.currentPano = list[0].pano;//找最近的一非孤立点
  3156. player.model.noPanoHasNeighbor = false; //更新状态
  3157. }else{
  3158. player.model.noPanoHasNeighbor = true; //更新状态
  3159. }
  3160. }else{
  3161. player.model.noPanoHasNeighbor = false; //更新状态
  3162. }
  3163. dataDeal.done();
  3164. player.model.updateFootIconSize(player.cameraControls.activeControl)//更新一下center大小 写在最后
  3165. } */
  3166. },
  3167. searchNeib: function(panoId) {
  3168. //寻找某pano的相关neighbour 可能是修改过的
  3169. var panos = player.model.panos;
  3170. var o = {};
  3171. if (this.panoVTemp[panoId]) {
  3172. //o.seeMarkers = this.panoVTemp[panoId].seeMarkers;
  3173. o.neighbourUUIDs = this.panoVTemp[panoId].neighbourUUIDs;
  3174. o.neighbourPanos = this.panoVTemp[panoId].neighbourPanos;
  3175. } else {
  3176. //o.seeMarkers = panos.index[panoId].seeMarkers.slice(0);
  3177. o.neighbourUUIDs = panos.index[panoId].neighbourUUIDs.slice(0);
  3178. o.neighbourPanos = CloneObject(panos.index[panoId].neighbourPanos);
  3179. }
  3180. return o;
  3181. },
  3182. turnToPanoIndex: function(panoArr) {
  3183. var panos = player.model.panos;
  3184. var array = [];
  3185. for (var i = 0; i < panoArr.length; i++) {
  3186. var pano = panos.index[panoArr[i]];
  3187. var index = panos.list.indexOf(pano)
  3188. array.push(index);
  3189. }
  3190. return array;
  3191. },
  3192. setDisplay: function(state) {
  3193. var panos = player.model.panos;
  3194. if (state) {
  3195. } else {
  3196. }
  3197. player.path.currentPanoMarker.mesh.visible = !state;
  3198. player.overlayGroup.visible = !state;
  3199. player.reticule.visible = !state;
  3200. },
  3201. delVisibleLines: function() {
  3202. //xzw add 所有线都删除
  3203. for (var i in this.tagsVLines) {
  3204. this.tagsVLines[i].geometry.dispose();
  3205. this.tagsVLines[i].material.dispose();
  3206. this.meshGroup.remove(this.tagsVLines[i]);
  3207. delete this.tagsVLines[i];
  3208. }
  3209. for (var i in this.panoVLines) {
  3210. this.panoVLines[i].geometry.dispose();
  3211. this.panoVLines[i].material.dispose();
  3212. this.meshGroup.remove(this.panoVLines[i]);
  3213. delete this.panoVLines[i];
  3214. }
  3215. },
  3216. //--------panoVisible
  3217. createPanoVisiLines: function(pano) {
  3218. // pano可见性线条
  3219. var neighbours = this.panoVTemp[pano.id] && this.panoVTemp[pano.id].neighbourPanos || pano.neighbourPanos;
  3220. for (var r in neighbours) {
  3221. if (neighbours[r] && r != pano.id) {
  3222. this.createPanoSingleLine(pano, "old", r)
  3223. }
  3224. }
  3225. },
  3226. createPanoSingleLine: function(pano, type, id) {
  3227. //pano是中心
  3228. var panos = player.model.panos;
  3229. var p2 = panos.index[id].floorPosition.clone()
  3230. /* .sub(player.model.position) */
  3231. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3232. , p2], {
  3233. color: this.colors.green
  3234. });
  3235. this.meshGroup.add(line);
  3236. line.name = "PanoVL-" + type + "-" + id;
  3237. this.panoVLines[id] = line;
  3238. this.changeFIconState(panos.index[id].footIcon, "linked")
  3239. },
  3240. dealPanoVisible: function(id) {
  3241. //外部调用
  3242. var panos = player.model.panos;
  3243. if (this.panoVsetting) {
  3244. if (id == this.panoVsetting.id) {
  3245. //关闭当前pano设置
  3246. this.pauseSetPanoVisible('unsaved')
  3247. } else {
  3248. var link;
  3249. //结果是否连接
  3250. if (this.panoVLines[id]) {
  3251. this.panoVLines[id].visible = !this.panoVLines[id].visible;
  3252. link = this.panoVLines[id].visible;
  3253. this.changeFIconState(panos.index[id].footIcon, this.panoVLines[id].visible ? "linked" : false)
  3254. } else {
  3255. this.createPanoSingleLine(this.panoVsetting, "new", id)
  3256. link = true;
  3257. }
  3258. if (link) {
  3259. //如果连接上了,直接判断该点是可见的(有附近点),(不能通过checkHasNeighbor来判断,因为新增的线条可能不在它的neighbour中
  3260. this.changeFIconState2(panos.index[id].footIcon, true)
  3261. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, true)
  3262. } else {
  3263. //否则需要checkHasNeighbor
  3264. this.changeFIconState2(panos.index[id].footIcon, this.checkHasNeighbor(panos.index[id]))
  3265. this.changeFIconState2(panos.index[this.panoVsetting.id].footIcon, this.checkHasNeighbor(this.panoVsetting))
  3266. }
  3267. }
  3268. } else {
  3269. //点击开始设置要设置的pano
  3270. this.SetOnePanoVisible(panos.index[id])
  3271. }
  3272. this.updateFootIconSize()
  3273. },
  3274. showFootIcons: function(pano, isPanovisible) {
  3275. if (!this.footIcons) {
  3276. footTex1 = Texture.load("images/edit/End_128.png");
  3277. //Store.FootIcon);
  3278. footTex2 = Texture.load("images/edit/End_unable_128.png");
  3279. //Store.FootIcon_unable);
  3280. this.footIcons = [];
  3281. var scale = 0.4;
  3282. scale *= 40 / Math.sqrt(Math.min($("#player").width(), $("#player").height()));
  3283. //屏幕越小,放得越大
  3284. scale = THREE.Math.clamp(scale, 0.3, 0.7)
  3285. //console.log("scale"+scale)
  3286. var geo = new THREE.PlaneGeometry(scale,scale,1,1)
  3287. var panos = player.model.panos;
  3288. for (var r in panos.index) {
  3289. if (!panos.index[r].isAligned())
  3290. continue;
  3291. var t = THREE.UniformsUtils.clone(shaders.waypoint.uniforms);
  3292. t.map.value = footTex1
  3293. t.color.value.set("#ffffff");
  3294. var mat = new THREE.RawShaderMaterial({
  3295. vertexShader: shaders.waypoint.vertexShader,
  3296. fragmentShader: shaders.waypoint.fragmentShader,
  3297. uniforms: t,
  3298. side: THREE.DoubleSide,
  3299. transparent: !0,
  3300. depthWrite: !1,
  3301. depthTest: false,
  3302. name: "footIcon"
  3303. })
  3304. var foot = new THREE.Mesh(geo,mat)
  3305. foot.position.copy(panos.index[r].floorPosition.clone()/* .sub(player.model.position) */
  3306. )
  3307. foot.lookAt(foot.position.clone().add(new THREE.Vector3(0,1,0)));
  3308. foot.name = panos.index[r].id;
  3309. foot.visible = false;
  3310. foot.renderOrder = 6,
  3311. panos.index[r].footIcon = foot;
  3312. this.meshGroup.add(foot);
  3313. this.footIcons.push(foot)
  3314. }
  3315. }
  3316. for (var i = 0; i < this.footIcons.length; i++) {
  3317. this.footIcons[i].visible = true;
  3318. this.changeFIconState(this.footIcons[i], false)
  3319. var panos = player.model.panos;
  3320. if (isPanovisible) {
  3321. this.changeFIconState2(this.footIcons[i], this.checkHasNeighbor(panos.index[this.footIcons[i].name], "showFoot"))
  3322. }
  3323. if (pano && (this.footIcons[i].name == pano.id)) {
  3324. //pano为中心 或者 currentPano 所以放大一点
  3325. this.footIcons[i].oriScale = new THREE.Vector3(1.5,1.5,1.5)
  3326. if (isPanovisible) {
  3327. //currentPano特殊些:
  3328. this.changeFIconState(this.footIcons[i], "center")
  3329. //this.footIcons[i].Unclick = true;//不让点击和hover
  3330. }
  3331. } else {
  3332. this.footIcons[i].oriScale = new THREE.Vector3(1,1,1)
  3333. }
  3334. }
  3335. },
  3336. checkHasNeighbor: function(pano, state) {
  3337. //检查当前状态pano点是否有可通行点
  3338. var neighbours = /* this.panoVTemp && */
  3339. this.panoVTemp[pano.id] ? this.panoVTemp[pano.id].neighbourPanos : pano.neighbourPanos;
  3340. if (state != "showFoot" && pano == this.panoVsetting) {
  3341. //是中心点的话。state == "showFoot"代表是showFootIcon时, 这时候线还没创建,无法用线判断中心点有几个相邻点,直接用neighbourPanos
  3342. for (var i in this.panoVLines) {
  3343. if (this.panoVLines[i].visible) {
  3344. return true;
  3345. //有一条线即可
  3346. }
  3347. }
  3348. return;
  3349. }
  3350. for (var i in neighbours) {
  3351. if (i == pano.id)
  3352. continue;
  3353. if (neighbours[i]) {
  3354. if (this.panoVsetting && this.panoVsetting.id == i && this.panoVLines[pano.id] && !this.panoVLines[pano.id].visible)
  3355. continue;
  3356. return true;
  3357. }
  3358. }
  3359. return false;
  3360. },
  3361. /* ifAllPanoNoNeighbor : function(){//检查是否全是孤立点
  3362. var panos = player.model.panos;
  3363. for(var i in panos.index){
  3364. if(this.checkHasNeighbor(panos.index[i])){
  3365. return false;
  3366. }
  3367. }
  3368. this.noPanoHasNeighbor = true;
  3369. return true;//是全部没有neighbour
  3370. }, */
  3371. changeFIconState: function(footIcon, state) {
  3372. var color = state == "linked" ? this.colors.green : (state == "center" ? /* "#d7f244" */
  3373. "#d5f12e" : "#ffffff");
  3374. footIcon.material.uniforms.color.value.set(color)
  3375. },
  3376. changeFIconState2: function(footIcon, state) {
  3377. //是可见点还是不可见点
  3378. if (state) {
  3379. footIcon.material.uniforms.map.value = footTex1;
  3380. if (this.panoVsetting) {
  3381. if (this.panoVsetting.id != footIcon.name) {
  3382. footIcon.material.uniforms.opacity.value = 1;
  3383. } else {//this.changeVisiBtnState(true)
  3384. }
  3385. }
  3386. } else {
  3387. //不可见
  3388. footIcon.material.uniforms.map.value = footTex2;
  3389. if (!this.panoVsetting || this.panoVsetting.id != footIcon.name) {
  3390. //非中心点时
  3391. footIcon.material.uniforms.opacity.value = 0.5;
  3392. } else {
  3393. //变为中心点时
  3394. footIcon.material.uniforms.opacity.value = 1;
  3395. //this.changeVisiBtnState(false)
  3396. }
  3397. }
  3398. },
  3399. hideFootIcons: function() {
  3400. if (!this.footIcons)
  3401. return;
  3402. for (var i = 0; i < this.footIcons.length; i++) {
  3403. this.footIcons[i].visible = false;
  3404. }
  3405. },
  3406. updateFootIconSize: function() {
  3407. //根据相机位置 改变footIcon大小,使在范围内看到的热点大小一致,防止太小点击不到
  3408. if (!this.footIcons)
  3409. return;
  3410. var s = player.cameraControls.controls.floorplan.absoluteScale * 2.8;
  3411. s = THREE.Math.clamp(s, 0.5, 1.4);
  3412. this.footIcons.forEach(function(f) {
  3413. try {
  3414. f.scale.copy(f.oriScale).multiplyScalar(s);
  3415. } catch (e) {
  3416. console.log(e)
  3417. }
  3418. })
  3419. }
  3420. //========热点可见性==============
  3421. ,
  3422. beginSetTagVisible: function() {
  3423. if (this.setTagVisible)
  3424. return;
  3425. $(".toolTop").addClass("unable")
  3426. $("#hotVisible").addClass("unable")
  3427. this.setTagVisible = true;
  3428. this.tagVTemp = {};
  3429. this.$confirmSnap.text('完成设置').removeClass("hide")
  3430. //objects.tagManager.hideAllTags();
  3431. for (let i in player.model.hots) {
  3432. player.model.hots[i]._isSprite = player.model.hots[i].isSprite;
  3433. player.model.hots[i].isSprite = true;
  3434. player.model.hots[i].mesh.material.depthTest = false;
  3435. }
  3436. this.setDisplay(true)
  3437. this.updateFootIconSize()
  3438. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3439. },
  3440. SetOneTagVisible: function(tag) {
  3441. //点击某个热点后就对该热点进行设置,或者在热点修改时对其进行设置
  3442. if (this.tagVsetting == tag)
  3443. return;
  3444. if (this.tagVsetting) {
  3445. this.saveLastTagVi(this.tagVsetting);
  3446. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL);
  3447. }
  3448. this.tagVsetting = tag;
  3449. //记录正在修改的
  3450. this.delVisibleLines();
  3451. //删除线
  3452. this.showFootIcons(player.currentPano);
  3453. this.createTagVisiLines(tag);
  3454. //创线
  3455. this.updateFootIconSize()
  3456. //更新一下大小,尤其是上次换了中心点然后退出又进入但是镜头没有变化的话
  3457. },
  3458. saveLastTagVi: function() {
  3459. //保存刚设置过的tag
  3460. var change = false;
  3461. var newVPs = this.tagVTemp[this.tagVsetting.sid] || this.tagVsetting.visiblePanos.slice(0);
  3462. for (var r in this.tagsVLines) {
  3463. var line = this.tagsVLines[r];
  3464. if (line.name.indexOf("new") > -1 && line.visible) {
  3465. //新设置为visible且没有取消
  3466. newVPs.push(r)
  3467. change = true;
  3468. //console.log("add: "+r)
  3469. } else if (line.name.indexOf("new") == -1 && !line.visible) {
  3470. //旧的且已经取消
  3471. var i = newVPs.indexOf(r);
  3472. if (i == -1) {
  3473. console.log("visiblePanos删除error");
  3474. continue;
  3475. }
  3476. newVPs.splice(i, 1);
  3477. change = true;
  3478. //console.log("sub: "+r)
  3479. }
  3480. }
  3481. if (change) {
  3482. this.tagVTemp[this.tagVsetting.sid] = newVPs;
  3483. }
  3484. },
  3485. pauseSetTagVisible: function() {
  3486. //pc保存后删除连线 但还在继续设置 点选热点即开始
  3487. if (!this.setTagVisible || !this.tagVsetting)
  3488. return;
  3489. //this.tagVsetting.setElemType(this.tagVsetting.style, this.tagVsetting.styleImageURL );
  3490. this.delVisibleLines();
  3491. this.hideFootIcons();
  3492. this.tagVTemp = {};
  3493. this.tagVsetting = null;
  3494. },
  3495. finishSetTagVisible: function() {
  3496. if (!this.setTagVisible)
  3497. return;
  3498. $(".toolTop").removeClass("unable")
  3499. $("#hotVisible").removeClass("unable")
  3500. this.pauseSetTagVisible();
  3501. this.setTagVisible = false;
  3502. this.setDisplay(false)
  3503. this.$confirmSnap.addClass("hide")
  3504. permitTranMode(true)
  3505. /* for (var r in objects.tagManager.tags) {
  3506. if(objects.tagManager.tags[r].state == "videoPanoFlag")continue;
  3507. objects.tagManager.tags[r].disc.visible = false;
  3508. objects.tagManager.tags[r].disc.material.depthTest = true;
  3509. } */
  3510. for (let i in player.model.hots) {
  3511. player.model.hots[i].isSprite = player.model.hots[i]._isSprite;
  3512. player.model.hots[i].isSprite || player.model.hots[i].mesh.quaternion.copy(player.model.hots[i].quaternion)
  3513. player.model.hots[i].mesh.material.depthTest = true;
  3514. }
  3515. },
  3516. /* saveTagVisibles : function () { //保存到服务器
  3517. if (this.tagVsetting) this.saveLastTagVi(this.tagVsetting); //获取最后设置的那个热点的改动
  3518. //可能出现数据没变但保存的情况。比如先改变了然后切换别的热点但切换回来时又改回来。
  3519. var tags = [];
  3520. for (var i in this.tagVTemp) {
  3521. tags.push({
  3522. sid: i,
  3523. value: this.tagVTemp[i]//turnToPanoIndex(this.tagVTemp[i])
  3524. })
  3525. }
  3526. if (tags.length == 0) {//没有需要保存的改动
  3527. this.finishSetTagVisible()
  3528. return;
  3529. }
  3530. return tags;
  3531. } */
  3532. //afterSaveTagVisibles : function(){
  3533. saveTagVisibles: function() {
  3534. if (this.tagVsetting)
  3535. this.saveLastTagVi(this.tagVsetting);
  3536. for (var i in this.tagVTemp) {
  3537. //保持成功于是生效
  3538. player.model.hots[i].visiblePanos = this.tagVTemp[i];
  3539. }
  3540. this.finishSetTagVisible()
  3541. //还是保存完直接结束吧,因为现在热点可视不放在单独的设置页面了
  3542. },
  3543. createTagVisiLines: function(tag) {
  3544. // 热点可见性线条
  3545. var panos = player.model.panos;
  3546. tag.visiblePanos || tag.setVisiblePanos("get")
  3547. var visibleList = this.tagVTemp[tag.sid] || tag.visiblePanos;
  3548. //如果是刚在设置的要读取设置过的数据
  3549. for (var r = 0; r < visibleList.length; r++) {
  3550. var pano = panos.index[visibleList[r]];
  3551. this.createTagSingleLine(pano, "old", tag)
  3552. }
  3553. },
  3554. createTagSingleLine: function(pano, type, tag) {
  3555. var panos = player.model.panos;
  3556. var line = LineDraw.createLine([pano.floorPosition.clone()/* .sub(this.position) */
  3557. , tag.mesh.position.clone()], {
  3558. color: this.colors.green
  3559. });
  3560. this.meshGroup.add(line);
  3561. line.name = "tagVL-" + type + "-" + pano.id;
  3562. this.tagsVLines[pano.id] = line;
  3563. this.changeFIconState(panos.index[pano.id].footIcon, "linked")
  3564. },
  3565. dealTagVisible: function(tag, panoName) {
  3566. //外部调用
  3567. var panos = player.model.panos;
  3568. if (this.tagsVLines[panoName]) {
  3569. this.tagsVLines[panoName].visible = !this.tagsVLines[panoName].visible;
  3570. this.changeFIconState(panos.index[panoName].footIcon, this.tagsVLines[panoName].visible ? "linked" : false)
  3571. } else {
  3572. this.createTagSingleLine(panos.index[panoName], "new", tag)
  3573. }
  3574. },
  3575. delVisibleLines: function() {
  3576. //xzw add 所有线都删除
  3577. for (var i in this.tagsVLines) {
  3578. this.tagsVLines[i].geometry.dispose();
  3579. this.tagsVLines[i].material.dispose();
  3580. this.meshGroup.remove(this.tagsVLines[i]);
  3581. delete this.tagsVLines[i];
  3582. }
  3583. for (var i in this.panoVLines) {
  3584. this.panoVLines[i].geometry.dispose();
  3585. this.panoVLines[i].material.dispose();
  3586. this.meshGroup.remove(this.panoVLines[i]);
  3587. delete this.panoVLines[i];
  3588. }
  3589. }
  3590. }
  3591. function permitTranMode(state) {
  3592. state ? $(".pinBottom.left").removeClass('hide') : $(".pinBottom.left").addClass('hide');
  3593. }
  3594. CloneObject = function(copyObj, result, isSimpleCopy) {
  3595. //isSimpleCopy只复制最外层
  3596. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  3597. result = result || {};
  3598. if (copyObj instanceof Array) {
  3599. if (copyObj[0]instanceof Object) {
  3600. //不支持含有 [[Object]] 这样二级数组里面还是复杂数据的,普通和复杂的数据混合可能也不支持
  3601. console.error("不支持含有 [[Object]] 这样二级数组里面还是复杂数据的...")
  3602. }
  3603. return copyObj.slice(0);
  3604. //如果是数组,直接复制返回(排除数组内是object
  3605. }
  3606. for (var key in copyObj) {
  3607. if (copyObj[key]instanceof Object && !isSimpleCopy)
  3608. result[key] = CloneObject(copyObj[key]);
  3609. else
  3610. result[key] = copyObj[key];
  3611. //如果是函数类同基本数据,即复制引用
  3612. }
  3613. return result;
  3614. }
  3615. ;
  3616. function randomWord(randomFlag, min, max) {
  3617. //随机字符串
  3618. var str = ""
  3619. , range = min
  3620. , 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'];
  3621. if (randomFlag) {
  3622. // 随机长度
  3623. range = Math.round(Math.random() * (max - min)) + min;
  3624. }
  3625. for (var i = 0; i < range; i++) {
  3626. var pos = Math.round(Math.random() * (arr.length - 1));
  3627. str += arr[pos];
  3628. }
  3629. return str;
  3630. }
  3631. function getRandomSid() {
  3632. //5-7位随机字符串 + 6位时间 为热点准备
  3633. var pre = randomWord(true, 5, 7);
  3634. var post = new Date().getTime() + "";
  3635. var len = post.length;
  3636. post = post.substring(len - 8, len - 5) + post.substring(len - 3, len)
  3637. //其实还是有可能重复的....
  3638. return pre + post;
  3639. }
  3640. function searchParent(searchArea, o, maxTimes) {
  3641. //是否是某种元素的下级,并找出该元素
  3642. maxTimes = maxTimes || 20;
  3643. var count = 0
  3644. var f = function(dom) {
  3645. if (o.id && o.id == dom.id)
  3646. return dom
  3647. else if (o.className && dom.classList && dom.classList.contains(o.className))
  3648. return dom
  3649. else if (o.tagName && dom.tagName && o.tagName.toUpperCase() == dom.tagName.toUpperCase())
  3650. return dom
  3651. }
  3652. var find;
  3653. while (searchArea && count < maxTimes) {
  3654. if (find = f(searchArea))
  3655. return find
  3656. searchArea = searchArea.parentNode;
  3657. count++;
  3658. }
  3659. }
  3660. //})();