edit.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. //编辑界面
  2. var EditingInterface = function(n){
  3. this.n = n;
  4. //功能按钮
  5. this.mainBtn = $(".edit-hot-active"),
  6. //创建编辑热点的功能
  7. this.editHot = new EditHot(),
  8. //创建二级编辑的界面
  9. // this.editFun = new EditFun();
  10. //初始化所有基本元素和功能
  11. this.initiate();
  12. loadInfoAttrites()
  13. }
  14. //初始化界面
  15. EditingInterface.prototype.initiate = function(){
  16. $(".edit-wrap").fadeIn();
  17. this.editHot.init(this.n);
  18. this.onClick();
  19. // this.editFun.init();
  20. }
  21. EditingInterface.prototype.onClick = function(){
  22. var that = this;
  23. this.mainBtn.on("mousedown touchstart", function() {
  24. g_HotStatus = g_HotStatus == "add" ? null : "add";
  25. switch(g_HotStatus)
  26. {
  27. case "add":
  28. $("#player").css("cursor","cell");
  29. break
  30. }
  31. })
  32. }
  33. //一级编辑界面,编辑热点的功能
  34. var EditHot = function(){
  35. this.ele = $(".edit-hot-num"),
  36. this.dataL = null, //获取最新创建热点的索引
  37. this.children = null; //创建的热点信息
  38. }
  39. EditHot.prototype.creatDom = function(index) {
  40. return "<li id='ggg_s"+index+"'>"
  41. + "<div class='edit-hotTitle'>"
  42. + "<span>热点<i class='edit-hotTitle-i'></i></span>"
  43. + "<div class='edit-remHot' data-id data-name >删除</div>"
  44. + "</div>"
  45. + "<div class='edit-content'>"
  46. + "<div class='edit-hot-data'>"
  47. + "<div>"
  48. + "<p>position:</p>"
  49. + "<p>x:<span class='edit-hot-data-p-x'></span></p>"
  50. + "<p>y:<span class='edit-hot-data-p-y'></span></p>"
  51. + "<p>z:<span class='edit-hot-data-p-z'></span></p>"
  52. + "<p>rotation:</p>"
  53. + "<p>x:<span class='edit-hot-data-r-x'></span></p>"
  54. + "<p>y:<span class='edit-hot-data-r-y'></span></p>"
  55. + "<p>z:<span class='edit-hot-data-r-z'></span></p>"
  56. + "</div>"
  57. + "<div class='edit-hot-editor'>"
  58. + '<div><span>编辑热点</span></div>'
  59. + "</div>"
  60. + "</div>"
  61. + "</div>"
  62. + "</li>"
  63. }
  64. //打开页面初始化编辑界面
  65. EditHot.prototype.init = function(n){
  66. for (var i = 0; i < g_HotMeshes.length; i++) {
  67. this.ele.append(this.addHotList(g_HotMeshes, i));
  68. this.fillText(i);
  69. this.hotAn(i);
  70. if(n) this.remHot(n,i),this.clickEdithotBtn(i);
  71. }
  72. document.querySelector(".edit-wrap").addEventListener("mousewheel",function(event){
  73. event.stopPropagation()
  74. });
  75. }
  76. EditHot.prototype.fillText = function(index){
  77. var target = this.ele.children("#ggg_s" + index);
  78. target.find(".edit-hotTitle-i").text(index +1 );
  79. target.find(".edit-remHot").attr({"data-id":g_HotMeshes[index].id,"data-name":g_HotMeshes[index].name});
  80. target.find(".edit-hot-data-p-x").text(g_HotMeshes[index].position.x);
  81. target.find(".edit-hot-data-p-y").text(g_HotMeshes[index].position.y);
  82. target.find(".edit-hot-data-p-z").text(g_HotMeshes[index].position.z);
  83. target.find(".edit-hot-data-r-x").text(g_HotMeshes[index].rotation.x);
  84. target.find(".edit-hot-data-r-y").text(g_HotMeshes[index].rotation.y);
  85. target.find(".edit-hot-data-r-z").text(g_HotMeshes[index].rotation.z);
  86. if (target[0]) {
  87. target[0].hotAttribute = g_HotMeshes[index]
  88. target.attr('data-spid', g_HotMeshes[index].belongHot.sid)
  89. }
  90. }
  91. EditHot.prototype.hotAn = function(index){
  92. let $li = $(".edit-hot-num > #ggg_s"+index)
  93. $li.find('.edit-hotTitle').on("click",function(){
  94. var next = $(this).next();
  95. if(next.height() == 0){
  96. next.css("height","155px");
  97. }else{
  98. next.css("height","0");
  99. }
  100. })
  101. $li.find('.edit-remHot').on("click", function (ev) {
  102. ev.stopPropagation()
  103. $li.remove()
  104. })
  105. }
  106. EditHot.prototype.addHotList = function(data, index){
  107. if(!data) return;
  108. this.dataL = data.length - 1;
  109. this.ele.append(this.creatDom(index));
  110. this.fillText(this.dataL);
  111. }
  112. //删除热点
  113. EditHot.prototype.remHot = function(index,thisScene){
  114. var deleteHot = $(".edit-remHot").eq(index),hotId,hotName;
  115. deleteHot.on("click",function(){
  116. hotId = $(this).attr("data-id");
  117. hotName = $(this).attr("data-name");
  118. for (var i = 0; i < g_HotMeshes.length; i++) {
  119. if(g_HotMeshes[i].id == hotId){
  120. //在场景中删除这个热点模型
  121. thisScene.sceneRenderer.scene.remove(g_HotMeshes[i]);
  122. g_HotMeshes[i].visible=false;
  123. //如果热点数据中有这个热点数据就删除
  124. // if(g_newHot && g_newHot.hasOwnProperty(hotName)){
  125. // delete g_newHot[hotName];
  126. // }
  127. g_HotMeshes.splice(i,1);
  128. console.log("删除成功:"+hotId);
  129. $(this).closest("li").remove();
  130. }
  131. }
  132. })
  133. }
  134. //点击编辑热点弹出二级编辑框
  135. EditHot.prototype.clickEdithotBtn = function(index){
  136. $("#ggg_s"+index+" .edit-hot-editor").on("click",function(){
  137. showHotEdit(index)
  138. })
  139. }
  140. //二级编辑界面,主要编辑功能,热点功能
  141. var EditFun = function(){}
  142. EditFun.prototype.init = function(){
  143. this.addFun("addImg","添加图片",this.addImg);
  144. this.addFun("addText","添加文字",this.addText);
  145. this.addFun("addVideo","添加视频",this.addVideo);
  146. this.saveBtn();
  147. }
  148. //添加功能
  149. EditFun.prototype.addFun = function(className,text,fn){
  150. var creatDom = '<li class=edit-function-'+className+'><div><span>'+text+'</span><div></li>';
  151. $(".edit-function-console").append(creatDom);
  152. fn(className);
  153. }
  154. //保存按钮
  155. EditFun.prototype.saveBtn = function(){
  156. $(".edit-function-save").on("click",function(){
  157. $(".edit-function-wrap").hide();
  158. })
  159. }
  160. //添加图片
  161. EditFun.prototype.addImg = function(className){
  162. var files = ["js/webuploader.html5only.min.js"+manage.time,"js/diyUpload.js"+manage.time,"css/diyUpload.css"+manage.time],
  163. imgText = '<div id="test" ></div>';
  164. $(".edit-function-"+className).attr("id","box").append(imgText).children('div').eq(0).hide();
  165. manage.LoadJs(files,function(){
  166. $('#test').diyUpload({
  167. url:'',
  168. success:function( data ) {
  169. console.info( data );
  170. },
  171. error:function( err ) {
  172. console.info( err );
  173. },
  174. buttonText : '添加图片'
  175. });
  176. });
  177. }
  178. //添加文字
  179. EditFun.prototype.addText = function(className){
  180. var textBtn = $(".edit-function-"+className),
  181. richText = '<div class="richText"><div id="toolbar">\
  182. <span>Size:</span>\
  183. <select id="size">\
  184. <option value="3">3</option>\
  185. <option value="4">4</option>\
  186. <option value="5">5</option>\
  187. <option value="6">6</option>\
  188. <option value="7">7</option>\
  189. </select>\
  190. <span>Color:</span>\
  191. <select id="color">\
  192. <option value="black" style="color:black">Black</option>\
  193. <option value="gray" style="color:gray">Gray</option>\
  194. <option value="brown" style="color:brown">Brown</option>\
  195. <option value="red" style="color:red">Red</option>\
  196. <option value="pink" style="color:pink">Pink</option>\
  197. <option value="yellow" style="color:yellow">Yellow</option>\
  198. <option value="orange" style="color:orange">Orange</option>\
  199. <option value="blue" style="color:blue">Blue</option>\
  200. <option value="Green" style="color:green">Green</option>\
  201. </select>\
  202. <span><strong>B</strong></span>\
  203. <input type="checkbox" id="bold">\
  204. <span style="text-decoration:underline">U</span>\
  205. <input type="checkbox" id="underline">\
  206. </div>\
  207. <div class="edit-F-text" contenteditable="true"></div></div>';
  208. textBtn.append(richText);
  209. textBtn.children("div").eq(0).on("click",function(){
  210. var richTextAn = $(this).next();
  211. if(richTextAn.height() == 0){
  212. richTextAn.height("350px");
  213. }else{
  214. richTextAn.height("0");
  215. }
  216. })
  217. $(".edit-F-text").on("keydown",function(event){
  218. event.stopPropagation()
  219. });
  220. function addEvent(id,obj){
  221. $('.richText').find(id).on("change",function(){
  222. $('.edit-F-text').focus();
  223. switch(obj[0])
  224. {
  225. case "FontSize":
  226. obj[2] = parseInt($('#size').val());
  227. break;
  228. case "ForeColor":
  229. obj[2] = $('#color').val();
  230. break;
  231. }
  232. document.execCommand(obj[0],obj[1],obj[2]);
  233. });
  234. }
  235. addEvent("#size",["FontSize",false]);
  236. addEvent("#color",["ForeColor",false]);
  237. addEvent("#bold",["Bold"]);
  238. addEvent("#underline",["Underline"]);
  239. }
  240. //添加视频
  241. EditFun.prototype.addVideo = function(className){
  242. console.log(className);
  243. }
  244. //点击屏幕判断当前处于什么编辑状态,因为需要获取场景的n对象和r对象,所有把这些方法放在main.js里点击屏幕事件里执行
  245. var DownInterface = function(){
  246. this.editHot = new EditHot();
  247. }
  248. DownInterface.prototype.state = function(that,Hot){
  249. switch(g_HotStatus)
  250. {
  251. case "add":
  252. this.addHot(that,Hot,function(thisScene){
  253. this.editHot.addHotList(g_HotMeshes, g_HotMeshes.length - 1);
  254. this.editHot.hotAn(this.editHot.dataL);
  255. this.editHot.remHot(this.editHot.dataL,thisScene);
  256. this.editHot.clickEdithotBtn(this.editHot.dataL);
  257. });
  258. break;
  259. case "delete":
  260. break;
  261. }
  262. }
  263. //添加热点模型
  264. DownInterface.prototype.addHot = function(that,Hot,fn){
  265. var position = that.reticule.position.toArray();
  266. var rotation = that.reticule.rotation.toArray().slice(0,3);
  267. var sid = g_HotMeshes.length > 0 ? "sprite_"+( parseInt(g_HotMeshes[g_HotMeshes.length - 1].name.substring(7)) + 1 ) : "sprite_" + g_HotMeshes.length;
  268. var hot = new Hot(sid, {position:position, rotation:rotation, size:1.05}, that.model);
  269. //g_newHot.push(hot);
  270. that.model.hots[sid] = hot;
  271. //$('#addHot textarea')[0].value+=('添加热点:\r"'+sid + '":{ "position":['+position+'], "rotation":['+rotation+']},\r');
  272. //logData('添加热点:\r"'+sid + '":{ "position":['+position+'], "rotation":['+rotation+']},\r')
  273. g_HotStatus = false;
  274. that.mouseCouldBeClickToMove=false;
  275. $("#player").css("cursor","");
  276. //添加完热点之后的回调函数
  277. if(g_HotMeshes && g_newHot.length === g_newHot.length++){
  278. var thisScene = that;
  279. fn && fn.call(this,thisScene);
  280. }
  281. }
  282. // 加载所有热点的信息
  283. function loadInfoAttrites () {
  284. $.ajax(g_Prefix + "data/" + window.number + "/hot/js/data.js" + "?" + Date.now(), { dataType: "json" })
  285. .then(function (infos) {
  286. Object.keys(infos).forEach(function(key) {
  287. $('.edit-hot-num > li[data-spid="' + key + '"]')[0] && ($('.edit-hot-num > li[data-spid="'+key+'"]')[0].infoAttribute = infos[key])
  288. })
  289. })
  290. }
  291. (function () {
  292. // 热点tab切换
  293. var $heads = $('.edit-function-header a')
  294. var $body = $('.edit-function-body > div')
  295. $heads.on('click', function() {
  296. $body.hide().removeClass('active');
  297. $heads.removeClass('active')
  298. $(this).addClass('active')
  299. $('.edit-function-body > div[data-label="' + $(this).attr('data-tab')+'"]')
  300. .show()
  301. .addClass('active')
  302. })
  303. $heads.eq(0).trigger('click')
  304. // 输入框阻止事件
  305. $('#edit-title,#edit-content,.func-edit-items,#info-name,#info-summary').on('keydown', function (ev) {
  306. ev.stopPropagation();
  307. })
  308. // 模型与网页加载
  309. $('.insert-bottom').on('click', function () {
  310. $(this).prev().append('<label><span>热点' + $(this).attr('attr-label') + ': </span><input type="text"></label>')
  311. })
  312. })();
  313. (function () {
  314. // 视频预览控制
  315. var $videoLayout = $('.fun-view-video')
  316. $videoLayout.find('span').on('click', function() {
  317. $videoLayout.hide();
  318. $videoLayout.find('video').attr('src', '')[0].pause()
  319. })
  320. // 图片加载回调
  321. function imageSuccess(file) {
  322. if (!/image\/\w+/.test(file.type)) {
  323. alert("文件必须为图片!");
  324. return false;
  325. }
  326. var img = new Image()
  327. img.src = URL.createObjectURL(file);
  328. return img
  329. }
  330. // 视频加载回调
  331. function videoSuccess(file, $elayout) {
  332. if (!/video\/\w+/.test(file.type)) {
  333. alert("视频必须为map4格式!");
  334. return false;
  335. }
  336. $elayout.append('<span class="upload-thum">上传封面<i><input type="file"></i></span>')
  337. return '<img src="./images/play.png" class="play-video" videoURL="' + URL.createObjectURL(file) +'">'
  338. }
  339. // 视频封面回调
  340. function thumSuccess(file, $elayout) {
  341. if (!/image\/\w+/.test(file.type)) {
  342. alert("文件必须为图片!");
  343. return false;
  344. }
  345. $elayout.parent().find('img').attr('src', URL.createObjectURL(file))
  346. }
  347. // 图片与视频加载
  348. function fileHandle() {
  349. var $seft = $(this)
  350. var $layout = $seft.parent()
  351. var $elayout = $layout.parent()
  352. var $pplayout = $elayout.parent()
  353. var type = $pplayout.attr('type')
  354. var $close = $(document.createElement('span'))
  355. var file = file = this.files[0];
  356. var fnc = type === 'image' ? imageSuccess :
  357. type === 'video' ? videoSuccess : thumSuccess
  358. var $dom = fnc(file, $elayout)
  359. if (type === 'image' || type === 'video') {
  360. if (!$dom) return $seft.val('')
  361. $layout.append($close)
  362. $layout.addClass('result')
  363. var $addLayout = $(document.createElement('a'))
  364. var $addInput = $('<input type="file">')
  365. $addLayout.append($addInput)
  366. var $din = $(document.createElement('div'));
  367. $din.append($addLayout)
  368. $elayout.parent().append($din)
  369. $layout.append($dom)
  370. }
  371. }
  372. // 图片与视频加载
  373. $('.edit-fun-images').on('change', function (ev) {
  374. if (ev.target.tagName.toUpperCase() === 'INPUT') {
  375. fileHandle.call(ev.target)
  376. }
  377. })
  378. $('.edit-fun-images').on('click', function(ev) {
  379. var $tag = $(ev.target)
  380. var tagName = ev.target.tagName.toUpperCase()
  381. if (tagName === 'SPAN') {
  382. var $resf = $(ev.target)
  383. $resf.parent().parent().remove()
  384. } else if (tagName === 'IMG' && $tag.hasClass('play-video')) {
  385. $videoLayout
  386. .css('display', 'flex')
  387. .find('video')
  388. .attr('src', $tag.attr('videoURL'))[0]
  389. .play()
  390. }
  391. })
  392. })();
  393. function showHotEdit(index) {
  394. var $layout = $(".edit-function-wrap")
  395. $layout.css("display", "flex")
  396. $layout[0].targetDOM = $(".edit-hot-num > li").eq(index)[0];
  397. var info = $layout[0].targetDOM.infoAttribute || {}
  398. info.title = info.title || ''
  399. info.content = info.content || ''
  400. info.iframe = info.iframe || []
  401. info.model = info.model || []
  402. info.images = info.images || []
  403. info.video = info.video || []
  404. var iframesHTML = info.iframe.map(function(iframe) {
  405. return '<label><span>热点网页: </span><input type="text" value="' + iframe + '"></label>'
  406. })
  407. var modulesHTML = info.model.map(function (module) {
  408. return '<label><span>热点模型: </span><input type="text" value="' + module + '"></label>'
  409. })
  410. var imagesHTML = info.images.map(function (image) {
  411. return '<div><a class="hasHover result success"><span></span><img src="' + image + '"></a></div>'
  412. })
  413. var videosHTML = info.video.map(function (ly) {
  414. return '<div><a class="hasHover result success"><span></span><img class="play-video" videoURL="' + ly.url + '" src="' + ly.img + '"></a><span class="upload-thum success result" attr-thum="' + ly.img+'">上传封面<i><input type="file"></i></span></div>'
  415. })
  416. imagesHTML.push('<div><a><input type="file"></a></div>')
  417. videosHTML.push('<div><a><input type="file"></a></div>')
  418. $('#edit-iframes').html(iframesHTML.join(''))
  419. $('#edit-modules').html(modulesHTML.join(''))
  420. $('.edit-fun-images[type="image"]').html(imagesHTML.join(''))
  421. $('.edit-fun-images[type="video"]').html(videosHTML.join(''))
  422. $('#edit-title').val(info.title)
  423. $('#edit-content').val(info.content)
  424. }
  425. // 保存热点信息
  426. (function() {
  427. var $layout = $(".edit-function-wrap")
  428. $('#edit-submit').on('click', function () {
  429. $layout.addClass('loadding')
  430. var args = {}
  431. var $title = $('#edit-title')
  432. var $content = $('#edit-content')
  433. var $images = $('.edit-fun-images[type="image"] a.result')
  434. var $videos = $('.edit-fun-images[type="video"] a.result')
  435. var $thums = $('.edit-fun-images[type="video"] .upload-thum')
  436. var $iframes = $('#edit-iframes input')
  437. var $modules = $('#edit-modules input')
  438. new Promise(function(resolve, reject) {
  439. upload($images, 'images', resolve)
  440. }).then(function(imgUrls) {
  441. args.images = imgUrls
  442. return new Promise(function (resolve, reject) {
  443. upload($videos, 'images', resolve)
  444. })
  445. }).then(function(videoUrls) {
  446. args.video = videoUrls
  447. return new Promise(function (resolve, reject) {
  448. upload($thums, 'images', resolve)
  449. })
  450. }).then(function(thums){
  451. args.video = args.video.map(function (video, index) {
  452. return {
  453. url: video,
  454. img: thums[index]
  455. }
  456. })
  457. }).then(function() {
  458. args.title = $title.val()
  459. args.content = $content.val()
  460. var iframes = []
  461. for (var i = 0; i < $iframes.length; i++) {
  462. var iframe = $iframes.eq(i).val()
  463. iframe && iframes.push(iframe)
  464. }
  465. args.iframe = iframes
  466. var modules = []
  467. for (var i = 0; i < $modules.length; i++) {
  468. var module = $modules.eq(i).val()
  469. module && modules.push(module)
  470. }
  471. args.model = modules
  472. return args
  473. }).then(function(args) {
  474. $layout[0].targetDOM.infoAttribute = args
  475. $layout.removeClass('loadding')
  476. $layout.hide()
  477. })
  478. })
  479. function upload ($files, type, cb) {
  480. var length = $files.length
  481. var rcount = 0
  482. var result = []
  483. Array.from($files).forEach(function(dFile) {
  484. var $file = $(dFile)
  485. var $image = $file.find('img')
  486. if ($file.hasClass('success')) {
  487. if ($file.attr('attr-thum')) {
  488. console.log($files, $file)
  489. result.push($file.attr('attr-thum'))
  490. } else if ($image.attr('videoURL')) {
  491. result.push($image.attr('videoURL'))
  492. } else {
  493. result.push($image.attr('src'))
  494. }
  495. return success(++rcount);
  496. } else {
  497. dFile = $file.find('input')[0]
  498. }
  499. var file = dFile.files[0]
  500. if (!file) return success(++rcount);
  501. var formData = new FormData()
  502. formData.append('name', number)
  503. formData.append('dir', 'hot/' + type)
  504. formData.append('random', true)
  505. formData.append('file', file)
  506. $.ajax({
  507. url: '/uploadFile',
  508. data: formData,
  509. dataType: 'json',
  510. type: 'POST',
  511. cache: false,//上传文件无需缓存
  512. processData: false,//用于对data参数进行序列化处理 这里必须false
  513. contentType: false, //必须
  514. success: function (rs) {
  515. if (rs.code === 200) {
  516. result.push(rs.content)
  517. }
  518. success(++rcount)
  519. }
  520. })
  521. })
  522. function success() {
  523. if (rcount === length) {
  524. cb(result)
  525. }
  526. }
  527. success()
  528. }
  529. })();
  530. // 上传导览
  531. function uploadGuide(urlData, guide) {
  532. var bytes = window.atob(urlData.split(',')[1]); //去掉url的头,并转换为byte
  533. //处理异常,将ascii码小于0的转换为大于0
  534. var ab = new ArrayBuffer(bytes.length);
  535. var ia = new Uint8Array(ab);
  536. for (var i = 0; i < bytes.length; i++) {
  537. ia[i] = bytes.charCodeAt(i);
  538. }
  539. var blob = new Blob([ab], { type: 'image/jpeg' });
  540. var formData = new FormData()
  541. formData.append('name', number)
  542. formData.append('dir', 'hot/images')
  543. formData.append('random', true)
  544. formData.append('file', blob)
  545. $.ajax({
  546. url: '/uploadFile',
  547. data: formData,
  548. dataType: 'json',
  549. type: 'POST',
  550. cache: false,//上传文件无需缓存
  551. processData: false,//用于对data参数进行序列化处理 这里必须false
  552. contentType: false, //必须
  553. success: function (rs) {
  554. if (rs.code === 200) {
  555. var sid = rs.content.substring(rs.content.lastIndexOf('\\') + 1, rs.content.lastIndexOf('.'))
  556. var thumbnail_signed_src = rs.content
  557. var args = JSON.parse("{"+guide+"}")
  558. args.sid = sid
  559. args.name = sid
  560. args.thumbnail_signed_src = thumbnail_signed_src
  561. args.metadata = JSON.stringify({
  562. camera_mode: 0,
  563. camera_position: {
  564. x: args.metadata.camera_position[0],
  565. y: args.metadata.camera_position[1],
  566. z: args.metadata.camera_position[2]
  567. },
  568. camera_quaternion: {
  569. x: args.metadata.camera_quaternion[3],
  570. y: args.metadata.camera_quaternion[0],
  571. z: args.metadata.camera_quaternion[1],
  572. w: args.metadata.camera_quaternion[2]
  573. },
  574. ortho_zoom: -1,
  575. scan_id: args.metadata.scan_id,
  576. final_angle: 110,
  577. is_ortho: false
  578. })
  579. console.log(args)
  580. var $li = $('<li><span><img src="' + args.thumbnail_signed_src + '"></span><input type="text" data-oper="change-name" value="' + args.name +'"> <a data-oper="delete">删除</a></li>')
  581. $li[0].data = args
  582. $('#guide-list').append($li)
  583. }
  584. }
  585. })
  586. }
  587. // 热点 导览选项卡切换
  588. (function() {
  589. var $heads = $('#oper-tabs a')
  590. var $bodys = $(Array.from($heads).map(function($item) {
  591. return get$dom($item.getAttribute('show-tab'))
  592. }).join(','))
  593. function get$dom(attr) {
  594. attr = '[data-tab="' + attr + '"]'
  595. return '.edit-bg' + attr + ',.edit-header' + attr
  596. }
  597. $heads.on('click', function() {
  598. var $active = $(get$dom($(this).attr('show-tab')))
  599. $bodys.removeClass('active')
  600. $heads.removeClass('active')
  601. $(this).addClass('active')
  602. $active.addClass('active')
  603. }).eq(0).trigger('click');
  604. })();
  605. // 导览列表,并注册事件
  606. (function() {
  607. var $list = $('#guide-list')
  608. $.ajax(g_Prefix + "data/" + window.number + "/someData.json" + "?" + Date.now(), { dataType: "json" })
  609. .done(function(data) {
  610. var $lis = []
  611. data.model.images.forEach(function(i) {
  612. if (i.thumbnail_signed_src) {
  613. var $li = $('<li><span><img src="' + i.thumbnail_signed_src + '"></span><input type="text" data-oper="change-name" value="' + i.name +'"><a data-oper="delete">删除</a></li>')
  614. $li[0].data = i
  615. $lis.push($li)
  616. }
  617. })
  618. $list.append($lis)
  619. initInfo(data)
  620. })
  621. $list.on('click', function(ev) {
  622. var $seft = $(ev.target)
  623. if ($seft.attr('data-oper') === 'delete') {
  624. $seft.parent().remove();
  625. }
  626. }).on('change', function(ev) {
  627. var $seft = $(ev.target)
  628. if ($seft.attr('data-oper') === 'change-name') {
  629. console.log($seft.val())
  630. $seft.parent()[0].data.name = $seft.val()
  631. }
  632. })
  633. })();
  634. $('.edit-save button').on('click', function () {
  635. var guides = Array.from($('#guide-list li')).map(function (dom) {
  636. return dom.data
  637. })
  638. var hots = {}
  639. Array.from($('.edit-hot-num > li')).forEach(function (dom) {
  640. hots[dom.hotAttribute.belongHot.sid] = {
  641. position: {
  642. x: dom.hotAttribute.position.x,
  643. y: dom.hotAttribute.position.y,
  644. z: dom.hotAttribute.position.z
  645. },
  646. rotation: {
  647. x: dom.hotAttribute.rotation.x,
  648. y: dom.hotAttribute.rotation.y,
  649. z: dom.hotAttribute.rotation.z
  650. },
  651. infoAttribute: dom.infoAttribute
  652. }
  653. })
  654. var info = {
  655. name: $('#info-name').val(),
  656. summary: $('#info-summary').val(),
  657. backgroundMusic: $('#query-bgm').attr('href'),
  658. hoticon: JSON.parse($('#hoticon').val()),
  659. camera_start: $('#camera-start')[0].data
  660. }
  661. console.log({
  662. hots: hots,
  663. name: number,
  664. guides: guides,
  665. info: info
  666. })
  667. $.ajax({
  668. method: 'POST',
  669. url: '/savesetting',
  670. data: {
  671. hots: hots,
  672. name: number,
  673. guides: guides,
  674. info: info
  675. },
  676. success: function (data) {
  677. if (data.code === 200) {
  678. alert('修改成功')
  679. location.reload()
  680. }
  681. }
  682. })
  683. });
  684. // 其他信息初始化
  685. function initInfo(data) {
  686. var $options = $('#hoticon option')
  687. $('#info-name').val(data.model.name)
  688. $('#info-summary').val(data.model.summary)
  689. for (var i = 0; i < $options.length; i++) {
  690. if ($options.eq(i).val() === JSON.stringify(data.hoticon)) {
  691. $options.eq(i).attr("selected", true);
  692. }
  693. }
  694. if (data.backgroundMusic) {
  695. $('#query-bgm').attr('href', data.backgroundMusic)
  696. $('#upload-bgm + p').html('替换音乐')
  697. } else {
  698. $('#query-bgm').hide()
  699. $('#upload-bgm + p').html('上传音乐')
  700. }
  701. $('#camera-start')[0].data = data.model.camera_start
  702. }
  703. // 音乐上传
  704. $('#upload-bgm').on('change', function() {
  705. var file = this.files[0];
  706. if (!/audio\/\w+/.test(file.type)) {
  707. alert("文件必须为音乐!");
  708. return false;
  709. }
  710. var formData = new FormData()
  711. formData.append('dir', 'audio')
  712. formData.append('random', true)
  713. formData.append('file', file)
  714. $.ajax({
  715. url: '/uploadFile',
  716. data: formData,
  717. dataType: 'json',
  718. type: 'POST',
  719. cache: false,//上传文件无需缓存
  720. processData: false,//用于对data参数进行序列化处理 这里必须false
  721. contentType: false, //必须
  722. success: function (rs) {
  723. if (rs.code === 200) {
  724. $('#query-bgm').attr('href', rs.content)
  725. $('#upload-bgm + p').html('替换音乐')
  726. }
  727. }
  728. })
  729. })
  730. // 修改场景名称 添加初始位置 添加背景音乐 修改导览得名称
  731. function getSeft(seft) {
  732. $('#camera-start').on('click', function () {
  733. var snap = JSON.parse("{"+seft.getSnapAngleInfo() + "}")
  734. this.data.camera.quaternion = snap.metadata.camera_quaternion
  735. this.data.pano.uuid = snap.metadata.scan_id
  736. })
  737. }