edit.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. var ceshi = 'http://139.159.225.37:85';
  2. //新编辑界面
  3. var EditTools = function(n){
  4. //main2018 里面的主要对象
  5. this.n = n;
  6. //当前状态
  7. this.atPanel = null;
  8. //场景信息
  9. this.sceneInformation = new SceneInformation();
  10. //热点
  11. this.hotpoint = new Hotpoint();
  12. //导览
  13. this.editGuide = new EditGuide();
  14. //音乐
  15. this.editMiuse = new EditMiuse();
  16. //初始化界面
  17. this.init();
  18. }
  19. EditTools.prototype.init = function(){
  20. this.hotpoint.init(this.n);
  21. var that = this;
  22. this.saveAll();
  23. this.active();
  24. //请求数据someData.js
  25. $.ajax(g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(), { dataType: "json" })
  26. .done(function (data) {
  27. //创建导览
  28. that.editGuide.init(data);
  29. that.editMiuse.init(data);
  30. //请求完someData.js 之后再请求data2.js
  31. data2(data,that.sceneInformation.init)
  32. })
  33. //请求热点数据 data2.js
  34. function data2(data,callback){
  35. $.ajax(g_Prefix + "data/" + window.number + "/data2.js" + "?" + Date.now(), { dataType: "json" })
  36. .done(function (data2) {
  37. callback(data,data2)
  38. }).fail(
  39. callback(data,data2)
  40. )
  41. }
  42. $("body").on("click",function(){
  43. $(".DelConfirm").removeClass("active");
  44. })
  45. }
  46. //点击的时候激活状态
  47. EditTools.prototype.active = function(){
  48. var that = this;
  49. var confirmSnap = $(".confirmSnap.innerBtn");
  50. var snapshotGui = $(".snapshotGui.overlayGui");
  51. $('.toolBottom .toolLeft li').click(function() {
  52. var name = $(this).data("name");
  53. $('.toolLeft li[data-name='+name+']').addClass("active").siblings().removeClass("active");
  54. $('.toolRight .' + name).removeClass("hide").siblings().addClass("hide");
  55. that.atPanel = name;
  56. if(name === "screen"){
  57. confirmSnap.removeClass("hide");
  58. snapshotGui.show();
  59. }else{
  60. confirmSnap.addClass("hide");
  61. snapshotGui.hide();
  62. }
  63. })
  64. //滚动阻止事件
  65. $(".toolRight div.content").on("mousewheel", function (event) {
  66. event.stopPropagation()
  67. });
  68. // 输入框阻止事件
  69. $('.toolRight').on('keydown', function (ev) {
  70. ev.stopPropagation();
  71. })
  72. }
  73. //保存按钮
  74. EditTools.prototype.saveAll = function(){
  75. $('#save').on('click', function () {
  76. $(".edit-loading").removeClass("hide");
  77. //导览的数据
  78. var guides = Array.from($('.tourList ul li')).map(function (dom) {
  79. return dom.data
  80. })
  81. var hots = {}
  82. Array.from($('.spotList ul li')).forEach(function (dom) {
  83. hots[dom.hotAttribute.belongHot.sid] = {
  84. position: {
  85. x: dom.hotAttribute.position.x,
  86. y: dom.hotAttribute.position.y,
  87. z: dom.hotAttribute.position.z
  88. },
  89. rotation: {
  90. x: dom.hotAttribute.rotation.x,
  91. y: dom.hotAttribute.rotation.y,
  92. z: dom.hotAttribute.rotation.z
  93. },
  94. infoAttribute: dom.infoAttribute
  95. }
  96. })
  97. var info = {
  98. name: $('#pjtName').val(),
  99. summary: $('#info-summary').val(),
  100. backgroundMusic: $('#query-bgm').attr('href'),
  101. hoticon: JSON.parse($(".hotStyle-item li.active").attr("data-val")),
  102. camera_start: $('#camera-start')[0].data,
  103. loadlogo: $("#loadlogo").is(':checked'),
  104. special: $("#g_specialScene").is(':checked'),
  105. vision_version : $("#twoData").is(':checked') ? "1.1.562.17209" : false
  106. }
  107. info.weixinDesc = $('#weixin-summary').val();
  108. $.ajax({
  109. method: 'POST',
  110. url: '/savesetting',
  111. data: {
  112. hots: hots,
  113. name: number,
  114. guides: guides,
  115. info: info
  116. },
  117. success: function (data) {
  118. if (data.code === 200) {
  119. location.reload()
  120. }
  121. }
  122. })
  123. });
  124. }
  125. //场景信息编辑
  126. var SceneInformation = function(){
  127. }
  128. SceneInformation.prototype.init = function(data,data2){
  129. var $options = $('.hotStyle-item li');
  130. var $loadlogo = $("#loadlogo");
  131. var $g_specialScene = $("#g_specialScene");
  132. var $twoData = $("#twoData");
  133. $(".model-title2").text(data.model.name);
  134. $('#pjtName').val(data.model.name);
  135. $('#info-summary').val(data.model.summary);
  136. if(data2) $('#weixin-summary').val(data2.weixinDesc);
  137. for (var i = 0; i < $options.length; i++) {
  138. if ($options.eq(i).attr('data-val') === JSON.stringify(data.hoticon)) {
  139. $options.eq(i).addClass("active").siblings().removeClass("active");
  140. }
  141. }
  142. $('#camera-start')[0].data = data.model.camera_start;
  143. //隐藏公司logo
  144. if (data.loadlogo) {
  145. $loadlogo[0].checked = true
  146. showLogo();
  147. }
  148. //特殊大场景
  149. if (data.special === "true" || data.model.special) {
  150. $g_specialScene[0].checked = true
  151. }
  152. //启动二代的数据
  153. if (data.vision_version === "1.1.562.17209" || data.model.vision_version) {
  154. $twoData[0].checked = true
  155. }
  156. }
  157. //设置初始界面
  158. function getSeft(seft) {
  159. $('#camera-start').on('click', function () {
  160. var snap = JSON.parse("{" + seft.getSnapAngleInfo() + "}")
  161. this.data.camera.quaternion = snap.metadata.camera_quaternion;
  162. this.data.pano.uuid = snap.metadata.scan_id;
  163. var ev = document.createEvent("MouseEvent");//点击截取视图
  164. g_snapShotWidth = 240;
  165. g_snapShotHeight = 118;
  166. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  167. ev.__callback = function(imgData,info) {
  168. initialPicture(imgData,info)
  169. }.bind(this);
  170. window.dispatchEvent(ev);
  171. });
  172. //上传图片
  173. function initialPicture(imgData){
  174. uploadImg(imgData,function(rs){
  175. if (rs.code === 200) {
  176. $(".shotImg.innerBtn").css("background-image","url('//"+ rs.content+"')")
  177. }
  178. })
  179. }
  180. }
  181. //热点编辑
  182. var Hotpoint = function(){
  183. this.spotList = $(".spotList");
  184. this.hotpointDetail = $(".hotpointDetail");
  185. }
  186. Hotpoint.prototype.init = function(n){
  187. this.active();
  188. this.addmedia();
  189. this.addMusic();
  190. this.addModel();
  191. this.addwebPack();
  192. this.saveHot();
  193. var that = this;
  194. //点击添加热点按钮
  195. $('#addHotSpots').on("click", function () {//点击添加热点
  196. g_HotStatus = g_HotStatus === "add" ? null : "add";
  197. $("#player").css("cursor", "cell");
  198. });
  199. //点解热点列表删除按钮
  200. this.spotList.on("click",function(e){
  201. var target = $(e.target);
  202. if(target.hasClass("del")){
  203. e.stopPropagation();
  204. target.siblings(".DelConfirm").addClass("active");
  205. that.spotList.find("i").text(that.spotList.find("ul li").length);
  206. }else{
  207. if(target.hasClass("DelConfirm")){
  208. e.stopPropagation();
  209. that.remHot(target,n);
  210. }else{
  211. //点击热点列表弹出编辑热点窗口
  212. if(target.hasClass("title") || target.hasClass("icon")){
  213. that.editHot(target)
  214. }
  215. }
  216. }
  217. });
  218. //点击热点编辑窗口右上角的关闭按钮
  219. this.hotpointDetail.find("a.close, button.cancel").on("click",function(){
  220. that.hotpointDetail.addClass("atRight");
  221. });
  222. //遍历热点 初始话加载热点数据
  223. for (var i = 0; i < g_HotMeshes.length; i++) {
  224. this.spotList.children("ul").append(this.addHotList(g_HotMeshes[i], i));
  225. }
  226. this.spotList.find("i").text(g_HotMeshes.length);
  227. // 初始话的时候把热点信息添加到对应的热点中
  228. $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
  229. .then(function (infos) {
  230. Object.keys(infos).forEach(function (key) {
  231. that.spotList.find("ul li[data-spid=" + key + "]")[0] && (that.spotList.find("ul li[data-spid=" + key + "]")[0].infoAttribute = infos[key])
  232. })
  233. })
  234. }
  235. //显示编辑热点的窗口和初始化热点窗口的数据
  236. Hotpoint.prototype.editHot = function(target){
  237. this.hotpointDetail.removeClass("atRight");
  238. var playIcon = '139.159.225.37:85/images/play.png';
  239. var $layout = $(".hotpointDetail")[0];
  240. $layout.targetDOM = target.closest("li")[0];
  241. var info = $layout.targetDOM.infoAttribute || {}
  242. info.title = info.title || '';
  243. info.content = info.content || '';
  244. info.iframe = info.iframe || [];
  245. info.model = info.model || [];
  246. info.images = info.images || [];
  247. info.video = info.video || [];
  248. var iframesHTML = info.iframe.map(function (iframe) {
  249. return this.inputList("请填写网页链接",iframe)
  250. }.bind(this))
  251. var modulesHTML = info.model.map(function (module) {
  252. return this.inputList("请填写网页链接",module)
  253. }.bind(this))
  254. var imagesHTML = info.images.map(function (image) {
  255. return '<div><a class=" result success"><span></span><img src="//' + image + '"></a></div>'
  256. })
  257. var videosHTML = info.video.map(function (ly) {
  258. var imgDom = (!ly.img || ly.img === "undefined") ? '' : 'success';
  259. var imgUrl = (!ly.img || ly.img === "undefined")? playIcon: ly.img;
  260. 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>'
  261. })
  262. this.hotpointDetail.find(".name > input").val(info.title);
  263. this.hotpointDetail.find(".editText").val(info.content);
  264. this.hotpointDetail.find(".photo .list").html(imagesHTML);
  265. this.hotpointDetail.find(".video .list").html(videosHTML);
  266. this.hotpointDetail.find(".model .list").html(modulesHTML);
  267. this.hotpointDetail.find(".webPage .list").html(iframesHTML);
  268. if(info.backgroundMusic){
  269. this.hotpointDetail.find(".audio .playBox").removeClass("hide");
  270. this.hotpointDetail.find("#upload-hotBgm").attr('data-hotBgm', info.backgroundMusic)
  271. this.hotpointDetail.find(".audio .playBox a").attr("href","//" + info.backgroundMusic);
  272. this.hotpointDetail.find(".audio .submit").text("替换");
  273. }else{
  274. this.hotpointDetail.find(".audio .playBox").addClass("hide");
  275. }
  276. }
  277. //添加图片和视频
  278. Hotpoint.prototype.addmedia = function(){
  279. // 视频预览控制
  280. var $videoLayout = $('.fun-view-video')
  281. $videoLayout.find('span').on('click', function () {
  282. $videoLayout.hide();
  283. $videoLayout.find('video').attr('src', '')[0].pause()
  284. });
  285. // 图片加载回调
  286. function imageSuccess(file) {
  287. if (!/image\/\w+/.test(file.type)) {
  288. alert("文件必须为图片!");
  289. return false;
  290. }
  291. if(!restrictedSize(file,2)){
  292. return false;
  293. }
  294. var img = new Image()
  295. img.src = URL.createObjectURL(file);
  296. return img
  297. }
  298. // 视频加载回调
  299. function videoSuccess(file, $elayout) {
  300. if (!/video\/\w+/.test(file.type)) {
  301. alert("视频必须为map4格式!");
  302. return false;
  303. }
  304. $elayout.append('<span class="upload-thum">上传封面<i><input type="file"></i></span>')
  305. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) + '">'
  306. }
  307. // 视频封面回调
  308. function thumSuccess(file, $elayout,$seft) {
  309. if (!/image\/\w+/.test(file.type)) {
  310. alert("文件必须为图片!");
  311. return false;
  312. }
  313. if(!restrictedSize(file,2)){
  314. return false;
  315. }
  316. $seft.closest('div').find('img').attr('src', URL.createObjectURL(file));
  317. }
  318. // 图片与视频加载
  319. function fileHandle() {
  320. var $seft = $(this)
  321. var $layout = $seft.closest("li");
  322. var type = $seft.parent().attr('data-type');
  323. var file = this.files[0];
  324. var $din = $(document.createElement('div'));
  325. var fnc = type === 'photo' ? imageSuccess :
  326. type === 'video' ? videoSuccess : thumSuccess
  327. var $dom = fnc(file,$din,$seft)
  328. if (type === 'photo' || type === 'video') {
  329. if (!$dom) return $seft.val('');
  330. var $addLayout = $(document.createElement('a'));
  331. var $close = $(document.createElement('span'));
  332. $addLayout.append($close);
  333. $addLayout.append($dom);
  334. $addLayout.addClass("result");
  335. $din.prepend($addLayout);
  336. $layout.find('.edit-fun-images').append($din);
  337. }
  338. };
  339. // 图片与视频加载
  340. $('.upload, .edit-fun-images').on('change', function (ev) {
  341. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  342. fileHandle.call(ev.target)
  343. }
  344. })
  345. $('.edit-fun-images').on('click', function (ev) {
  346. var $tag = $(ev.target)
  347. var tagName = ev.target.tagName.toUpperCase()
  348. if (tagName === 'SPAN') {
  349. var $resf = $(ev.target)
  350. $resf.parent().parent().remove()
  351. } else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  352. $videoLayout
  353. .css('display', 'flex')
  354. .find('video')
  355. .attr('src', $tag.attr('videoURL'))[0]
  356. .play()
  357. }
  358. })
  359. }
  360. //选择热点的样式
  361. Hotpoint.prototype.active = function(){
  362. $(".hotStyle-item li").on('click',function(){
  363. $(this).addClass('active').siblings().removeClass('active');
  364. })
  365. }
  366. //当前处于的状态,比如是否是添加热点的状态
  367. Hotpoint.prototype.state = function (that, Hot) {
  368. if(g_HotStatus === "add"){
  369. this.addHot(that, Hot, function () {
  370. this.addHotList(g_HotMeshes, g_HotMeshes.length - 1 );
  371. this.spotList.find("i").text(this.spotList.find("ul li").length);
  372. });
  373. }
  374. }
  375. //删除热点
  376. Hotpoint.prototype.remHot = function (that,thisScene) {
  377. var hotId = that.closest("li").attr("data-spid");
  378. for (var i = 0; i < g_HotMeshes.length; i++) {
  379. if (g_HotMeshes[i].belongHot.sid === hotId) {
  380. //在场景中删除这个热点模型
  381. thisScene.scene.remove(g_HotMeshes[i]);
  382. g_HotMeshes[i].visible = false;
  383. //如果热点数据中有这个热点数据就删除
  384. g_HotMeshes.splice(i, 1);
  385. console.log("删除成功:" + hotId);
  386. }
  387. }
  388. that.closest("li").remove();
  389. this.spotList.find(".hotNum").text(this.spotList.find("ul li").length);
  390. }
  391. //添加热点模型
  392. Hotpoint.prototype.addHot = function (that, Hot, fn) {
  393. var position = that.reticule.position.toArray();
  394. var rotation = that.reticule.rotation.toArray().slice(0, 3);
  395. var sid = g_HotMeshes.length > 0 ? "sprite_" + (parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1) : "sprite_" + g_HotMeshes.length;
  396. var hot = new Hot(sid, { position: position, rotation: rotation, size: 1.05 }, that.model);
  397. that.model.hots[sid] = hot;
  398. g_HotStatus = false;
  399. that.mouseCouldBeClickToMove = false;
  400. $("#player").css("cursor", "");
  401. //添加完热点之后的回调函数
  402. if (g_HotMeshes && g_newHot.length === g_newHot.length++) {
  403. var thisScene = that;
  404. fn && fn.call(this, thisScene);
  405. }
  406. }
  407. //创建热点列表的dom
  408. Hotpoint.prototype.creatDom = function (data,index) {
  409. var _index = +index + 1;
  410. return "<li data-spid="+data.name+" id=ggg_s"+index+">"+
  411. "<div class=icon></div>"+
  412. "<div class=title>热点"+ _index +"</div>"+
  413. "<div class=DelConfirm>确定删除</div>"+
  414. "<div class=del></div>"+
  415. "</li>";
  416. }
  417. //添加热点列表
  418. Hotpoint.prototype.addHotList = function (data, index) {
  419. if (!data) return;
  420. this.spotList.children("ul").append(this.creatDom(data,index));
  421. //保存热点信息到热点dom元素中
  422. var spotList = $(".spotList ul").children("#ggg_s" + index);
  423. spotList[0].hotAttribute = g_HotMeshes[index];
  424. spotList.attr('data-spid', g_HotMeshes[index].belongHot.sid);
  425. }
  426. //添加热点音乐
  427. Hotpoint.prototype.addMusic = function () {
  428. var mediaUpload = $(".hotpointDetail .audio.mediaUpload");
  429. mediaUpload.find("input").on("change",function(){
  430. var file = this.files[0];
  431. mediaUpload.find(".innerBtn").text("替换");
  432. mediaUpload.find(".playBox").removeClass("hide");
  433. mediaUpload.find(".title").text(file.name);
  434. mediaUpload.find('#query-bgm').attr('href', URL.createObjectURL(file));
  435. });
  436. //删除音乐
  437. mediaUpload.on("click",".delete",function(){
  438. mediaUpload.find('#query-bgm').attr('href', "");
  439. mediaUpload.find(".playBox").addClass("hide");
  440. mediaUpload.find(".innerBtn").text("上传");
  441. mediaUpload.find("input").val("").removeAttr("data-hotbgm");
  442. })
  443. }
  444. //添加热点模型列表dom
  445. Hotpoint.prototype.inputList = function (text,val) {
  446. var _val = '';
  447. if(arguments[1]){
  448. _val = 'value='+val;
  449. }
  450. return '<div class="link"> <input class="text" type="text" placeholder='+text+' maxlength="40" spellcheck="false" '+_val+' > </div>'
  451. }
  452. //添加热点模型
  453. Hotpoint.prototype.addModel = function () {
  454. var text = this.inputList("请填写模型链接");
  455. this.hotpointDetail.find(".model .add").on('click', function () {
  456. $(this).closest(".model").find(".list").append(text)
  457. });
  458. this.hotpointDetail.find(".model .delete").on('click', function () {
  459. $(this).closest(".model").find(".list > div:last").remove();
  460. });
  461. }
  462. //添加网页链接
  463. Hotpoint.prototype.addwebPack = function () {
  464. var text = this.inputList("请填写网页链接","");
  465. this.hotpointDetail.find(".webPage .add").on('click', function () {
  466. $(this).closest(".webPage").find(".list").append(text)
  467. });
  468. this.hotpointDetail.find(".webPage .delete").on('click', function () {
  469. $(this).closest(".webPage").find(".list > div:last").remove();
  470. });
  471. }
  472. // 保存热点信息
  473. Hotpoint.prototype.saveHot = function () {
  474. var $layout = $(".edit-loading");
  475. var hotpointDetail = this.hotpointDetail;
  476. hotpointDetail.find(".tail .submit").on('click', function () {
  477. //显示loading
  478. $layout.removeClass('hide');
  479. var args = {};
  480. //热点标题
  481. var $title = hotpointDetail.find(".info input");
  482. //热点内容
  483. var $content = hotpointDetail.find(".info textarea");
  484. //热点图片
  485. var $images = hotpointDetail.find(".photo .edit-fun-images a.result");
  486. //热点视频
  487. var $videos = hotpointDetail.find(".video .edit-fun-images a.result");
  488. //热点视频的图片
  489. var $thums = hotpointDetail.find(".video .edit-fun-images .upload-thum");
  490. //热点模型
  491. var $modules = hotpointDetail.find(".model input");
  492. //热点内嵌网页
  493. var $iframes = hotpointDetail.find(".webPage input");
  494. //热点音乐
  495. var $miusc = hotpointDetail.find("#upload-hotBgm");
  496. new Promise(function (resolve, reject) {
  497. //获取热点图片所有的路径
  498. upload($images, 'images', resolve)
  499. }).then(function (imgUrls) {
  500. args.images = imgUrls
  501. //获取热点视频所有的路径
  502. return new Promise(function (resolve, reject) {
  503. upload($videos, 'images', resolve)
  504. })
  505. }).then(function (videoUrls) {
  506. args.video = videoUrls
  507. //获取热点视频图片所有的路径
  508. return new Promise(function (resolve, reject) {
  509. upload($thums, 'images', resolve)
  510. })
  511. }).then(function (thums) {
  512. args.video = args.video.map(function (video, index) {
  513. return {
  514. url: video,
  515. img: thums[index]
  516. }
  517. })
  518. }).then(function () {
  519. //获取热点音乐所有的路径
  520. //console.log($miusc)
  521. if ($miusc[0].files.length > 0) {
  522. return new Promise(function (resolve) {
  523. upload($miusc, 'miusc', function(res) {
  524. resolve(res[0])
  525. })
  526. })
  527. } else {
  528. return $miusc.attr('data-hotBgm')
  529. }
  530. }).then(function (src) {
  531. args.backgroundMusic = src
  532. })
  533. .then(function () {
  534. //获取热点标题、内容、内嵌网页、模型网页。
  535. args.title = $title.val()
  536. args.content = $content.val()
  537. var iframes = []
  538. for (var i = 0; i < $iframes.length; i++) {
  539. var iframe = $iframes.eq(i).val()
  540. iframe && iframes.push(iframe)
  541. }
  542. args.iframe = iframes
  543. var modules = []
  544. for (var i = 0; i < $modules.length; i++) {
  545. var module = $modules.eq(i).val()
  546. module && modules.push(module)
  547. }
  548. args.model = modules
  549. return args
  550. }).then(function (args) {
  551. //把获取的所有信息都保存在对应热点的dom元素里面
  552. hotpointDetail[0].targetDOM.infoAttribute = args;
  553. $layout.addClass('hide');
  554. hotpointDetail.addClass("atRight");
  555. })
  556. })
  557. function upload($files, type, cb) {
  558. var length = $files.length
  559. var rcount = 0
  560. var result = []
  561. Array.from($files).forEach(function (dFile) {
  562. //a 标签的success 是用来判断是否是已经上传过的文件
  563. //attr-thum 属性是视频的图片
  564. //videoURL 是判断是否有视频
  565. var $file = $(dFile)
  566. var $image = $file.find('img')
  567. if ($file.hasClass('success')) {
  568. if ($file.attr('attr-thum')) {
  569. result.push($file.attr('attr-thum'))
  570. } else if ($image.attr('videoURL')) {
  571. result.push($image.attr('videoURL'))
  572. } else {
  573. result.push($image.attr('src'))
  574. }
  575. return success(++rcount);
  576. } else {
  577. dFile = $file[0].localName === "input" ? $file[0] : $file[0].localName === "span" ? $file.find('input')[0] : $file.closest("li").find('.upload input')[0];
  578. }
  579. var file = (dFile.files && dFile.files[0]) || '';
  580. if (!file) return success(++rcount);
  581. uploadFile(file,'hot/' + type, function(rs){
  582. if (rs.code === 200) {
  583. result.push(rs.content)
  584. };
  585. success(++rcount);
  586. })
  587. })
  588. //判断当前队列元素是否处理成功
  589. function success() {
  590. if (rcount === length) {
  591. cb(result)
  592. }
  593. }
  594. success()
  595. }
  596. }
  597. //背景音乐
  598. var EditMiuse = function(){
  599. this.mediaUpload = $(".music .audio.mediaUpload");
  600. this.success = function(text,url){
  601. this.mediaUpload.find(".innerBtn").text("替换");
  602. this.mediaUpload.find(".playBox").removeClass("hide");
  603. this.mediaUpload.find(".title").text(text);
  604. this.mediaUpload.find('#query-bgm').attr('href', "//"+url)
  605. };
  606. this.delete = function(){
  607. this.mediaUpload.find('#query-bgm').attr('href', "");
  608. this.mediaUpload.find(".playBox").addClass("hide");
  609. this.mediaUpload.find(".innerBtn").text("上传");
  610. this.mediaUpload.find("input").val("");
  611. };
  612. var that = this;
  613. $('#upload-bgm').on('change', function () {
  614. var file = this.files[0];
  615. uploadMiuse(file,function(rs,file){
  616. if (rs.code === 200) {
  617. that.success(file.name,rs.content)
  618. }
  619. })
  620. });
  621. //删除音乐
  622. this.mediaUpload.on("click",".delete",function(){
  623. that.delete();
  624. })
  625. }
  626. EditMiuse.prototype.init = function(data){
  627. if(!data.backgroundMusic) return;
  628. this.success("backgound",data.backgroundMusic);
  629. }
  630. //导览编辑
  631. var EditGuide = function(){
  632. this.$list = $('#guide-list')
  633. }
  634. EditGuide.prototype.init = function(data){
  635. this.creatDom(data);
  636. //点击添加导览
  637. $('.addTour .innerBtn').on("click", function () {//点击截取视图
  638. var ev = document.createEvent("MouseEvent");//"MouseEvent"
  639. ev.initMouseEvent("snapshotBegin", true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  640. g_snapShotWidth = 200;
  641. g_snapShotHeight = 140;
  642. ev.__callback = function(imgData,info) {
  643. this.uploadGuide(imgData,info)
  644. }.bind(this);
  645. window.dispatchEvent(ev);
  646. }.bind(this));
  647. //修改导览的名字
  648. $('.tourList ul').on('click',function(ev){
  649. var $seft = $(ev.target)
  650. if ($seft.attr('data-oper') === 'tour-text') {
  651. $seft.siblings('input').removeClass('hide').closest('li').siblings().find('input').addClass('hide');
  652. $seft.siblings('input').focus();
  653. }
  654. if ($seft.attr('data-oper') === 'tour-delete') {
  655. var choice = confirm("你确定删除吗?");
  656. if (choice) {
  657. $seft.closest('li').remove();
  658. }
  659. else {
  660. return false
  661. }
  662. }
  663. }).on("change",function(ev){
  664. this.inputDone(ev)
  665. }.bind(this))
  666. $('.tourList ul input').on('blur',function(ev){
  667. this.inputDone(ev)
  668. }.bind(this)).on('keydown', function (ev) {
  669. ev.stopPropagation()
  670. })
  671. }
  672. EditGuide.prototype.creatDom = function(data){
  673. var $lis = [];
  674. var that = this;
  675. data.model.images.forEach(function (i,index) {
  676. if (i.thumbnail_signed_src) {
  677. var $li = $(that.dom(index ,i.name, i.thumbnail_signed_src));
  678. $li[0].data = i
  679. $lis.push($li)
  680. }
  681. })
  682. $(".tourList > ul").append($lis)
  683. }
  684. EditGuide.prototype.dom = function(index,title,img){
  685. return '<li>'+
  686. '<div>'+
  687. '<span>'+index+'</span>'+
  688. '<div class="line"></div>'+
  689. '</div>'+
  690. '<div>'+
  691. '<span class="guide-name" data-oper=tour-text>'+title+'</span>'+
  692. '<input maxlength="14" class="hide" data-oper=tour-input>'+
  693. '</div>'+
  694. '<div class="preview" >'+
  695. '<div style="background-image: url(//'+img+');" data-oper=tour-delete>'+
  696. '</div>'+
  697. '</div>'+
  698. '</li >';
  699. }
  700. EditGuide.prototype.inputDone = function(ev){
  701. var $seft = $(ev.target)
  702. if ($seft.attr('data-oper') === 'tour-input') {
  703. $seft.addClass('hide')
  704. $seft.text($seft.val() || '未命名');
  705. //更改导览横向列表的名字:
  706. $seft.siblings('span').text($seft.val() || '未命名');
  707. $seft.closest("li")[0].data.name = $seft.val() || '未命名';
  708. }
  709. }
  710. // 上传导览
  711. EditGuide.prototype.uploadGuide = function(urlData, guide) {
  712. uploadImg(urlData,function(rs){
  713. if (rs.code === 200) {
  714. var editGuide = new EditGuide();
  715. var sid = rs.content.substring(rs.content.lastIndexOf('/') + 1, rs.content.lastIndexOf('.'))
  716. var thumbnail_signed_src = rs.content
  717. var args = JSON.parse("{" + guide + "}")
  718. args.sid = sid
  719. args.name = sid
  720. args.thumbnail_signed_src = thumbnail_signed_src
  721. args.metadata = JSON.stringify({
  722. camera_mode: 0,
  723. camera_position: {
  724. x: args.metadata.camera_position[0],
  725. y: args.metadata.camera_position[1],
  726. z: args.metadata.camera_position[2]
  727. },
  728. camera_quaternion: {
  729. x: args.metadata.camera_quaternion[3],
  730. y: args.metadata.camera_quaternion[0],
  731. z: args.metadata.camera_quaternion[1],
  732. w: args.metadata.camera_quaternion[2]
  733. },
  734. ortho_zoom: -1,
  735. scan_id: args.metadata.scan_id,
  736. final_angle: 110,
  737. is_ortho: false
  738. })
  739. var index = $(".tourList ul li").length + 1;
  740. var $li = $(editGuide.dom(index,args.name,args.thumbnail_signed_src))
  741. $li[0].data = args
  742. $li.find('input').on('blur',function(ev){
  743. editGuide.inputDone(ev);
  744. })
  745. $(".tourList ul").append($li)
  746. }
  747. })
  748. }
  749. /* -- 以下是一些公用的方法 -- */
  750. //限制大小
  751. var restrictedSize = function(file,_size){
  752. //限制大小不大于8m
  753. var fileSize = 0;
  754. var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
  755. if (isIE && !file) {
  756. var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
  757. var _file = fileSystem.GetFile(filepath);
  758. fileSize = _file.Size;
  759. } else {
  760. fileSize = file.size;
  761. }
  762. var size = fileSize / 1024;
  763. var RSize = _size * 1024;
  764. if (size > RSize) {
  765. alert("文件不能大于"+_size+"M");
  766. return false;
  767. }
  768. if (size <= 0 ) {
  769. alert("文件大小不能为0M!");
  770. return false;
  771. }
  772. return true
  773. }
  774. //上传音乐
  775. var uploadMiuse = function(file,callback){
  776. if (!/audio\/\w+/.test(file.type)) {
  777. alert("文件必须为音乐!");
  778. return false;
  779. }
  780. //限制大小不大于8m
  781. if(!restrictedSize(file,8)){
  782. return false
  783. }
  784. uploadFile(file,'audio',callback);
  785. }
  786. //上传图片
  787. function uploadImg(urlData,callback){
  788. var bytes = window.atob(urlData.split(',')[1]); //去掉url的头,并转换为byte
  789. //处理异常,将ascii码小于0的转换为大于0
  790. var ab = new ArrayBuffer(bytes.length);
  791. var ia = new Uint8Array(ab);
  792. for (var i = 0; i < bytes.length; i++) {
  793. ia[i] = bytes.charCodeAt(i);
  794. }
  795. var blob = new Blob([ab], { type: 'image/jpeg' });
  796. uploadFile(blob,'hot/images',callback);
  797. }
  798. //上传文件
  799. function uploadFile(file,type,callback){
  800. $(".edit-loading").removeClass("hide");
  801. var formData = new FormData()
  802. formData.append('name', number)
  803. formData.append('dir', type)
  804. formData.append('random', true)
  805. formData.append('file', file)
  806. $.ajax({
  807. url: ceshi + '/uploadFile',
  808. data: formData,
  809. dataType: 'json',
  810. type: 'POST',
  811. cache: false,//上传文件无需缓存
  812. processData: false,//用于对data参数进行序列化处理 这里必须false
  813. contentType: false, //必须
  814. success: function (rs) {
  815. callback(rs,file);
  816. $(".edit-loading").addClass("hide");
  817. }
  818. })
  819. }