edit.js 146 KB

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