123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- var strUrl=window.location.href;
- var strIp = "";
- strIp = strUrl.split('//') [1].split('/')[0]
- if(strIp == 'localhost:8080')
- {
- strIp = '172.16.50.4:18080'
- }
- if(strIp == '127.0.0.1:8080')
- {
- strIp = '172.16.50.4:18080'
- }
- if(strIp == '172.16.30.57:8080')
- {
- strIp = '172.16.50.4:18080'
- }
- const urlBaseSet = {
- OSS: "https://bucket-model.oss-cn-beijing.aliyuncs.com",
- //CDN: "http://127.0.0.1:8080",
- //ICDN: "http://127.0.0.1:8080",
- //TCDN: "http://127.0.0.1:8080",
- //CDN: "https://modelcdn2.3dnest.cn",
- //ICDN: "https://infocdn2.3dnest.cn",
- //TCDN: "https://template2.3dnest.cn",
- //CDN: "http://172.16.50.4:18080",
- //ICDN: "http://172.16.50.4:18080",
- //TCDN: "http://172.16.50.4:18080",
- CDN: "http://" + strIp,
- ICDN: "http://" + strIp,
- TCDN: "http://" + strIp,
- EDIT: "/manager_house/model/rtiframedata/",
- };
- let modelId; // 模型id
- let modelVersion; // 模型版本号
- let modelSetting; // 模型版本设置
- let companyId; // 公司Id
- let globalSetting = null;
- // 获取页面对应的单个参数 start by ytj
- function getParams(key) {
- let search = window.location.search.replace(/^\?/, "");
- let pairs = search.split("&");
- let paramsMap = pairs.map(pair => {
- let [key, value] = pair.split("=");
- return [decodeURIComponent(key), decodeURIComponent(value)];
- }).reduce((res, [key, value]) => Object.assign(res, { [key]: value }), {});
- return paramsMap[key] || "";
- }
- // 获取页面对应的单个参数 end by ytj
- // 获取模型版本信息
- const getModelVesionUrl = (urlBaseSet)=>{
- modelId = getParams('m');
- let currentDate = new Date().getTime();
- return `${urlBaseSet.CDN }/${modelId}/version.txt?f=${currentDate}`
- }
- // 获取模型配置信息
- const getModelSettingUrl = (urlBaseSet,modelVersion,modelSetting)=>{
- return `${urlBaseSet.ICDN}/${modelId}/${modelVersion}/settings.txt?s=${ modelSetting}`
- }
- // 获取模型公司配置
- const getCompanySettingUrl = (companyId)=>{
- let currentDate = new Date().getTime();
- return `${urlBaseSet.TCDN} /company/${companyId}/company.txt?t=${currrentDate}`
- }
- const fetchData = (url) => {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.open('GET', url);
- xhr.onload = () => {
- if (xhr.status >= 200 && xhr.status < 300) {
- resolve(JSON.parse(xhr.responseText));
- } else {
- reject(xhr.statusText);
- }
- };
- xhr.onerror = () => reject(xhr.statusText);
- xhr.send();
- });
- }
-
- // 这是我们的包装函数,它返回一个数组
- const awaitWrap = (promise) => {
- return promise
- .then(data => [null, data])
- .catch(err => [err, null]);
- }
-
- // 这是我们的主函数,它按顺序执行三个请求,并合并返回的数据
- const fetchAndCombine = async () => {
- let combinedData = {};
- let backgroundBgUrl = `${urlBaseSet.ICDN}/${modelId}/https://infocdn2.3dnest.cn/881f840a_q8X6_b6f9_DAP/background.jpg?`
- try {
- let modelVersionUrl = getModelVesionUrl(urlBaseSet);
- const [err1, modelVersionData] = await awaitWrap(fetchData(modelVersionUrl));
- if (err1) {
- throw new Error(`Error fetching data from ${modelVersionUrl}: ${err1}`);
- }
- console.log('=====模型版本数据========',modelVersionData);
- // combinedData = { ...combinedData, ...modelVersionData };
- let modelSettingUrl = getModelSettingUrl(urlBaseSet,modelVersionData.version,modelVersionData.setting)
- const [err2, modelSettingData] = await awaitWrap(fetchData(modelSettingUrl));
- if (err2) throw new Error(`Error fetching data from url2: ${err2}`);
- // onsole.log('=====模型版本数据========',modelSettingData);
- // combinedData = { ...combinedData, ...modelSettingData };
- console.log('=====模型配置数据========',modelSettingData);
- if(!!modelSettingData?.basic?.user?.group&&!!modelSettingData?.basic?.user?.group>1){
- let companySettingUrl = getCompanySettingUrl(modelSettingData.basic.user.group)
- const [err3, data3] = await awaitWrap(fetchData(companySettingUrl));
- if (err3) throw new Error(`Error fetching data from url3: ${err3}`);
- }else {
- }
- let siteConf = {
- "type": "display",
- "versionpre": `${urlBaseSet.CDN}/${modelId}/`,
- "modelpre": `${urlBaseSet.CDN}/${modelId}/`,
- "infopre": `${urlBaseSet.ICDN}/${modelId}/`,
- "setpre": `${urlBaseSet.ICDN}/${modelId}/`
-
- }
- globalSetting = {
- modelId: modelId,
- settings: modelSettingData,
- version: modelVersionData,
- siteConf: siteConf,
- enterType: 3
- }
- return [null, globalSetting];
- // combinedData = { ...combinedData, ...data3 };
- } catch (error) {
- return [error, null];
- }
-
- return [null, globalSetting];
- }
-
- // 导出主函数
- export default fetchAndCombine;
-
|