manage.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. //管理js文件 获取modeldata.js 判断是否有特殊的字段,如果有就先加载SpecialScene.js 里面有对特殊场景处理的代码 否则就直接加载main
  2. var Manage = function(){
  3. this.weixinURL = "https://res.wx.qq.com/open/js/jweixin-1.2.0.js",
  4. this.time = "?"+new Date().getTime();
  5. this.loadAudio();
  6. // this.loadWeixin();
  7. }
  8. //动态加载js文件
  9. Manage.prototype.LoadJs = function(_files, succes){
  10. /* 已加载文件缓存列表,用于判断文件是否已加载过,若已加载则不再次加载*/
  11. var classcodes = [];
  12. var FileArray = [];
  13. if (typeof _files === "object") {
  14. FileArray = _files;
  15. } else {
  16. /*如果文件列表是字符串,则用,切分成数组*/
  17. if (typeof _files === "string") {
  18. FileArray = _files.split(",");
  19. }
  20. }
  21. if (FileArray != null && FileArray.length > 0) {
  22. var LoadedCount = 0;
  23. for (var i = 0; i < FileArray.length; i++) {
  24. loadFile(FileArray[i], function() {
  25. LoadedCount++;
  26. if (LoadedCount == FileArray.length) {
  27. try {
  28. succes();
  29. }
  30. catch(err) {
  31. console.log("err: 您未定义回调");
  32. }
  33. }
  34. })
  35. }
  36. }
  37. /*加载JS文件,url:文件路径,success:加载成功回调函数*/
  38. function loadFile(url, success) {
  39. if (!FileIsExt(classcodes, url)) {
  40. var _ThisType = GetFileType(url);
  41. var ThisType = _ThisType.indexOf("?") == -1 ? _ThisType : _ThisType.substring(0,_ThisType.indexOf("?"));
  42. var fileObj = null;
  43. if (ThisType == ".js") {
  44. fileObj = document.createElement('script');
  45. fileObj.src = url;
  46. } else if (ThisType == ".css") {
  47. fileObj = document.createElement('link');
  48. fileObj.href = url;
  49. fileObj.type = "text/css";
  50. fileObj.rel = "stylesheet";
  51. } else if (ThisType == ".less") {
  52. fileObj = document.createElement('link');
  53. fileObj.href = url;
  54. fileObj.type = "text/css";
  55. fileObj.rel = "stylesheet/less";
  56. }
  57. success = success || function() {};
  58. fileObj.onload = fileObj.onreadystatechange = function() {
  59. if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
  60. success();
  61. classcodes.push(url)
  62. }
  63. }
  64. document.getElementsByTagName('head')[0].appendChild(fileObj);
  65. } else {
  66. success();
  67. }
  68. }
  69. /*获取文件类型,后缀名,小写*/
  70. function GetFileType(url) {
  71. if (url != null && url.length > 0) {
  72. return url.substr(url.lastIndexOf(".")).toLowerCase();
  73. }
  74. return "";
  75. }
  76. /*文件是否已加载*/
  77. function FileIsExt(FileArray, _url) {
  78. if (FileArray != null && FileArray.length > 0) {
  79. var len = FileArray.length;
  80. for (var i = 0; i < len; i++) {
  81. if (FileArray[i] == _url) {
  82. return true;
  83. }
  84. }
  85. }
  86. return false;
  87. }
  88. };
  89. //获取页面url后面的参数
  90. Manage.prototype.number = function(variable) {
  91. var query = window.location.search.substring(1);
  92. var vars = query.split("&");
  93. for (var i=0;i<vars.length;i++) {
  94. var pair = vars[i].split("=");
  95. if(pair[0] == variable){return pair[1];}
  96. }
  97. return(false);
  98. };
  99. Manage.prototype.loadWeixin = function() {
  100. var that = this;
  101. this.LoadJs(that.weixinURL+that.time,function(){ });
  102. }
  103. Manage.prototype.loadAudio = function() { //相关:g_tourAudio \ g_playAudio
  104. g_bgAudio = new Audio;
  105. g_bgAudio.loop = true;
  106. g_bgAudio.autoplay = false;
  107. g_bgAudio.id = "bgaudio";
  108. //https://www.cnblogs.com/interdrp/p/4211883.html 部分资料
  109. g_bgAudio.load(); // iOS 9 还需要额外的 load 一下, 否则直接 play 无效
  110. var play = function(){
  111. //if(window.tourAudioSta) return;
  112. // this.switchBgmState(true)
  113. document.removeEventListener("touchstart",play);
  114. document.removeEventListener("click",play);
  115. $('#player').unbind("touchstart", play);
  116. }.bind(this);
  117. g_bgAudio.oncanplay = ()=>{
  118. // this.switchBgmState(true)
  119. }
  120. document.addEventListener("WeixinJSBridgeReady", ()=> {
  121. // this.switchBgmState(true)
  122. }, false);
  123. document.addEventListener("touchstart", play);//ios需要加个事件才能播放 不能自动播放;如果还有浏览器不行,换成别的交互事件
  124. document.addEventListener("click", play);
  125. $('#player').bind("touchstart", play);
  126. g_bgAudio.addEventListener('ended', ()=>{
  127. this.switchBgmState(true)
  128. });
  129. $("#volume").find("a").on("click", ()=> {
  130. if($("#volume img")[0].src.indexOf("btn_on.png")>-1)
  131. {
  132. this.switchBgmState(true);
  133. }
  134. else if($("#volume img")[0].src.indexOf("btn_off.png")>-1)
  135. {
  136. this.switchBgmState(false);
  137. }
  138. })
  139. }
  140. Manage.prototype.switchBgmState = function(state){
  141. if(!g_bgAudio || !g_bgAudio.src) return;
  142. var played = function(){
  143. console.log('begin play bgm');
  144. g_play = 1;
  145. g_playAudio = g_bgAudio;
  146. $("#volume a img").attr("src", "./static/images/Volume btn_off.png")
  147. $("#volume").attr("title", "关闭声音");
  148. g_tourAudio && g_tourAudio.pause()
  149. }
  150. var paused = function(){
  151. g_play = 0;
  152. g_playAudio == g_bgAudio && (g_playAudio = null)
  153. $("#volume a img").attr("src", "./static/images/Volume btn_on.png")
  154. $("#volume").attr("title", "打开声音");
  155. }
  156. if(state ){
  157. g_bgAudio.play();
  158. if(g_bgAudio.paused){
  159. paused()
  160. }else{
  161. played()
  162. return true
  163. }
  164. }else{
  165. g_bgAudio.pause();
  166. paused()
  167. }
  168. g_bgAudio.pauseByHot = false
  169. g_bgAudio.pauseByTour = false
  170. }
  171. Manage.prototype.weixinShare = function() {
  172. console.log("weixinShare")
  173. $.ajax({
  174. url: 'https://www.4dage.com/wechat/jssdk/share/',
  175. type: "post",
  176. data: {
  177. 'uri': location.href.split('#')[0], //当前页面地址
  178. 'name': "四维5号" //哪个公众号,对应上方的名称
  179. },
  180. dataType: "jsonp",
  181. jsonpCallback: "success_jsonp",
  182. success: function (data, textStatus) {
  183. wx.config({
  184. debug: false,
  185. appId: data.appId,
  186. timestamp: data.timestamp,
  187. nonceStr: data.nonceStr,
  188. signature: data.signature,
  189. jsApiList: ['checkJsApi', 'onMenuShareTimeline',
  190. 'onMenuShareAppMessage', 'onMenuShareQQ',
  191. 'onMenuShareWeibo']
  192. });
  193. },
  194. error: function (XMLHttpRequest, textStatus, errorThrown) {
  195. console.log("jsonp.error:" + textStatus);
  196. }
  197. });
  198. var success_jsonp = function(json){
  199. console.log(json);
  200. };
  201. wx.ready(function(){
  202. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  203. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  204. //分享到朋友圈
  205. console.log(g_weixinObj)
  206. wx.onMenuShareTimeline({
  207. title: g_weixinObj.title||'', // 分享标题
  208. link: g_weixinObj.lineLink||'', // 分享链接
  209. imgUrl: g_weixinObj.imgUrl||'', // 分享图标
  210. desc: g_weixinObj.desc||''
  211. });
  212. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  213. wx.onMenuShareAppMessage({
  214. title: g_weixinObj.title, // 分享标题
  215. desc: g_weixinObj.desc, // 分享描述
  216. link: g_weixinObj.lineLink, // 分享链接
  217. imgUrl: g_weixinObj.imgUrl, // 分享图标
  218. type: '', // 分享类型,music、video或link,不填默认为link
  219. dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
  220. });
  221. wx.onMenuShareWeibo({
  222. title: g_weixinObj.title, // 分享标题
  223. desc: g_weixinObj.desc, // 分享描述
  224. link: g_weixinObj.lineLink, // 分享链接
  225. imgUrl: g_weixinObj.imgUrl, // 分享图标
  226. success: function () {
  227. // 用户确认分享后执行的回调函数
  228. },
  229. cancel: function () {
  230. // 用户取消分享后执行的回调函数
  231. }
  232. });
  233. wx.onMenuShareQZone({
  234. title: g_weixinObj.title, // 分享标题
  235. desc: g_weixinObj.desc, // 分享描述
  236. link: g_weixinObj.lineLink, // 分享链接
  237. imgUrl: g_weixinObj.imgUrl, // 分享图标
  238. success: function () {
  239. // 用户确认分享后执行的回调函数
  240. },
  241. cancel: function () {
  242. // 用户取消分享后执行的回调函数
  243. }
  244. });
  245. wx.onMenuShareQQ({
  246. title: g_weixinObj.title, // 分享标题
  247. desc: g_weixinObj.desc, // 分享描述
  248. link: g_weixinObj.lineLink, // 分享链接
  249. imgUrl: g_weixinObj.imgUrl, // 分享图标
  250. success: function () {
  251. // 用户确认分享后执行的回调函数
  252. },
  253. cancel: function () {
  254. // 用户取消分享后执行的回调函数
  255. }
  256. });
  257. wx.error(function(res){
  258. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  259. });
  260. });
  261. }
  262. Manage.prototype.dealURL = function(src, type){
  263. //music: "///super.4dage.com/data/LYW/edit/20200928_151633415.mp3"
  264. //"https://super.4dage.com/data/LYW/edit/20200928_165319399.jpg"]
  265. if(window.isLocal && settings.localPrefix!=void 0){//本地将线上的前缀替换
  266. var oldPrefixs = ["https://super.4dage.com/", "http://super.4dage.com/", "///super.4dage.com/"]
  267. for(let i=0;i<oldPrefixs.length;i++){
  268. if(src.includes(oldPrefixs[i])){
  269. return src.replace(oldPrefixs[i], settings.localPrefix)
  270. break;
  271. }
  272. }
  273. console.error("没有找到合适的本地链接")
  274. return src
  275. }else{
  276. return src
  277. }
  278. }
  279. var manage = new Manage();
  280. //公用的函数
  281. function getQueryVariable(variable)
  282. {
  283. var query = window.location.search.substring(1);
  284. var vars = query.split("&");
  285. for (var i=0;i<vars.length;i++) {
  286. var pair = vars[i].split("=");
  287. if(pair[0] == variable){return pair[1];}
  288. }
  289. return(false);
  290. }
  291. //隐藏公司Logo
  292. function showLogo(){
  293. $("#myCompany").hide();
  294. $("#loaderCoBrandName").hide();
  295. $("#title-logo").hide();
  296. $(".title-container").css("justify-content","center")
  297. }
  298. //czj 添加随机的时间
  299. function randomTime(){
  300. return new Date()
  301. }
  302. function matcher(data){
  303. if(!data || !g_version ) return data;
  304. delete data.model.vision_version;
  305. var _data = {
  306. files: {
  307. "templates": ["images/images{{number}}/{{filename}}"]
  308. },
  309. model :{
  310. sid :window.number,
  311. camera_start:
  312. data.model.images && data.model.images.length != 0 ?
  313. {
  314. camera: {
  315. zoom: "-1",
  316. quaternion: [
  317. JSON.parse(data.model.images[0].metadata).camera_quaternion.z,
  318. JSON.parse(data.model.images[0].metadata).camera_quaternion.w,
  319. JSON.parse(data.model.images[0].metadata).camera_quaternion.x,
  320. JSON.parse(data.model.images[0].metadata).camera_quaternion.y
  321. ]
  322. },
  323. pano: { uuid: JSON.parse(data.model.images[0].metadata).scan_id },
  324. mode: "0"
  325. }
  326. : ''
  327. },
  328. sid: window.number,
  329. hoticon: {
  330. default: "https://super.4dage.com/images/4dagePoint2.png",
  331. higt: "https://super.4dage.com/images/4dagePoint.png"
  332. },
  333. special: "false",
  334. weixinDesc: ""
  335. };
  336. $.extend(true,data,_data)
  337. return data;
  338. }
  339. function hotMatcher(data){
  340. if(!data || !g_version) return data;
  341. data.tourAudio = data.audio;
  342. return data;
  343. }
  344. //兼容一代的場景
  345. //請求地址統一管理
  346. var g_onePregix = "https://bigscene.4dage.com/" //对应一代 http://www.4dmodel.com/SuperPanoramic/index.html?m=55
  347. var g_version = manage.number("version");
  348. g_version === "one" ? g_Prefix = g_onePregix : '';