loader.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. var strUrl=window.location.href;
  2. var strIp = "";
  3. strIp = strUrl.split('//') [1].split('/')[0]
  4. // if(strIp == 'localhost:8080')
  5. // {
  6. // strIp = '172.16.50.4:18080'
  7. // }
  8. if(strIp == '127.0.0.1:8080')
  9. {
  10. strIp = '172.16.50.4:18080'
  11. }
  12. if(strIp == '172.16.30.57:8080')
  13. {
  14. strIp = '172.16.50.4:18080'
  15. }
  16. const urlBaseSet = {
  17. OSS: "https://bucket-model.oss-cn-beijing.aliyuncs.com",
  18. //CDN: "http://127.0.0.1:8080",
  19. //ICDN: "http://127.0.0.1:8080",
  20. //TCDN: "http://127.0.0.1:8080",
  21. //CDN: "https://modelcdn2.3dnest.cn",
  22. //ICDN: "https://infocdn2.3dnest.cn",
  23. //TCDN: "https://template2.3dnest.cn",
  24. //CDN: "http://172.16.50.4:18080",
  25. //ICDN: "http://172.16.50.4:18080",
  26. //TCDN: "http://172.16.50.4:18080",
  27. CDN: "http://" + strIp,
  28. ICDN: "http://" + strIp,
  29. TCDN: "http://" + strIp,
  30. EDIT: "/manager_house/model/rtiframedata/",
  31. };
  32. let modelId; // 模型id
  33. let modelVersion; // 模型版本号
  34. let modelSetting; // 模型版本设置
  35. let companyId; // 公司Id
  36. let globalSetting = null;
  37. // 获取页面对应的单个参数 start by ytj
  38. function getParams(key) {
  39. let search = window.location.search.replace(/^\?/, "");
  40. let pairs = search.split("&");
  41. let paramsMap = pairs.map(pair => {
  42. let [key, value] = pair.split("=");
  43. return [decodeURIComponent(key), decodeURIComponent(value)];
  44. }).reduce((res, [key, value]) => Object.assign(res, { [key]: value }), {});
  45. return paramsMap[key] || "";
  46. }
  47. // 获取页面对应的单个参数 end by ytj
  48. // 获取模型版本信息
  49. const getModelVesionUrl = (urlBaseSet)=>{
  50. modelId = getParams('m');
  51. let currentDate = new Date().getTime();
  52. return `${urlBaseSet.CDN }/${modelId}/version.txt?f=${currentDate}`
  53. }
  54. // 获取模型配置信息
  55. const getModelSettingUrl = (urlBaseSet,modelVersion,modelSetting)=>{
  56. return `${urlBaseSet.ICDN}/${modelId}/${modelVersion}/settings.txt?s=${ modelSetting}`
  57. }
  58. // 获取模型公司配置
  59. const getCompanySettingUrl = (companyId)=>{
  60. let currentDate = new Date().getTime();
  61. return `${urlBaseSet.TCDN} /company/${companyId}/company.txt?t=${currrentDate}`
  62. }
  63. const fetchData = (url) => {
  64. return new Promise((resolve, reject) => {
  65. const xhr = new XMLHttpRequest();
  66. xhr.open('GET', url);
  67. xhr.onload = () => {
  68. if (xhr.status >= 200 && xhr.status < 300) {
  69. resolve(JSON.parse(xhr.responseText));
  70. } else {
  71. reject(xhr.statusText);
  72. }
  73. };
  74. xhr.onerror = () => reject(xhr.statusText);
  75. xhr.send();
  76. });
  77. }
  78. // 这是我们的包装函数,它返回一个数组
  79. const awaitWrap = (promise) => {
  80. return promise
  81. .then(data => [null, data])
  82. .catch(err => [err, null]);
  83. }
  84. // 这是我们的主函数,它按顺序执行三个请求,并合并返回的数据
  85. const fetchAndCombine = async () => {
  86. console.log('房间加载start', Date.now())
  87. let combinedData = {};
  88. let backgroundBgUrl = `${urlBaseSet.ICDN}/${modelId}/https://infocdn2.3dnest.cn/881f840a_q8X6_b6f9_DAP/background.jpg?`
  89. try {
  90. let modelVersionUrl = getModelVesionUrl(urlBaseSet);
  91. const [err1, modelVersionData] = await awaitWrap(fetchData(modelVersionUrl));
  92. if (err1) {
  93. throw new Error(`Error fetching data from ${modelVersionUrl}: ${err1}`);
  94. }
  95. console.log('=====模型版本数据========',modelVersionData);
  96. // combinedData = { ...combinedData, ...modelVersionData };
  97. let modelSettingUrl = getModelSettingUrl(urlBaseSet,modelVersionData.version,modelVersionData.setting)
  98. const [err2, modelSettingData] = await awaitWrap(fetchData(modelSettingUrl));
  99. if (err2) throw new Error(`Error fetching data from url2: ${err2}`);
  100. // onsole.log('=====模型版本数据========',modelSettingData);
  101. // combinedData = { ...combinedData, ...modelSettingData };
  102. console.log('=====模型配置数据========',modelSettingData);
  103. if(!!modelSettingData?.basic?.user?.group&&!!modelSettingData?.basic?.user?.group>1){
  104. let companySettingUrl = getCompanySettingUrl(modelSettingData.basic.user.group)
  105. const [err3, data3] = await awaitWrap(fetchData(companySettingUrl));
  106. if (err3) throw new Error(`Error fetching data from url3: ${err3}`);
  107. }else {
  108. }
  109. let siteConf = {
  110. "type": "display",
  111. "versionpre": `${urlBaseSet.CDN}/${modelId}/`,
  112. "modelpre": `${urlBaseSet.CDN}/${modelId}/`,
  113. "infopre": `${urlBaseSet.ICDN}/${modelId}/`,
  114. "setpre": `${urlBaseSet.ICDN}/${modelId}/`
  115. }
  116. globalSetting = {
  117. modelId: modelId,
  118. settings: modelSettingData,
  119. version: modelVersionData,
  120. siteConf: siteConf,
  121. enterType: 3
  122. }
  123. return [null, globalSetting];
  124. // combinedData = { ...combinedData, ...data3 };
  125. } catch (error) {
  126. return [error, null];
  127. }
  128. return [null, globalSetting];
  129. }
  130. // 导出主函数
  131. export default fetchAndCombine;