loader.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. let combinedData = {};
  87. let backgroundBgUrl = `${urlBaseSet.ICDN}/${modelId}/https://infocdn2.3dnest.cn/881f840a_q8X6_b6f9_DAP/background.jpg?`
  88. try {
  89. let modelVersionUrl = getModelVesionUrl(urlBaseSet);
  90. const [err1, modelVersionData] = await awaitWrap(fetchData(modelVersionUrl));
  91. if (err1) {
  92. throw new Error(`Error fetching data from ${modelVersionUrl}: ${err1}`);
  93. }
  94. console.log('=====模型版本数据========',modelVersionData);
  95. // combinedData = { ...combinedData, ...modelVersionData };
  96. let modelSettingUrl = getModelSettingUrl(urlBaseSet,modelVersionData.version,modelVersionData.setting)
  97. const [err2, modelSettingData] = await awaitWrap(fetchData(modelSettingUrl));
  98. if (err2) throw new Error(`Error fetching data from url2: ${err2}`);
  99. // onsole.log('=====模型版本数据========',modelSettingData);
  100. // combinedData = { ...combinedData, ...modelSettingData };
  101. console.log('=====模型配置数据========',modelSettingData);
  102. if(!!modelSettingData?.basic?.user?.group&&!!modelSettingData?.basic?.user?.group>1){
  103. let companySettingUrl = getCompanySettingUrl(modelSettingData.basic.user.group)
  104. const [err3, data3] = await awaitWrap(fetchData(companySettingUrl));
  105. if (err3) throw new Error(`Error fetching data from url3: ${err3}`);
  106. }else {
  107. }
  108. let siteConf = {
  109. "type": "display",
  110. "versionpre": `${urlBaseSet.CDN}/${modelId}/`,
  111. "modelpre": `${urlBaseSet.CDN}/${modelId}/`,
  112. "infopre": `${urlBaseSet.ICDN}/${modelId}/`,
  113. "setpre": `${urlBaseSet.ICDN}/${modelId}/`
  114. }
  115. globalSetting = {
  116. modelId: modelId,
  117. settings: modelSettingData,
  118. version: modelVersionData,
  119. siteConf: siteConf,
  120. enterType: 3
  121. }
  122. return [null, globalSetting];
  123. // combinedData = { ...combinedData, ...data3 };
  124. } catch (error) {
  125. return [error, null];
  126. }
  127. return [null, globalSetting];
  128. }
  129. // 导出主函数
  130. export default fetchAndCombine;