edit.js 146 KB

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