loader.js 4.8 KB

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