manage.js 12 KB

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