edit.js 125 KB

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