yudao-init/src/store/modules/home.js

736 lines
20 KiB
JavaScript
Raw Normal View History

2024-04-18 17:01:10 +08:00
import axios from "@/utils/request";
2024-04-25 17:07:44 +08:00
import { deepClone } from "../../utils";
2024-04-24 16:31:27 +08:00
2024-04-18 17:01:10 +08:00
/* 状态 */
const state = {
copilot: {
/* 产量驾驶舱 */
2024-04-25 17:07:44 +08:00
yield: {
ftoInvest: null,
chipInvest: null,
chipOutput: null,
stdOutput: null,
bipvOutput: null,
},
2024-04-18 17:01:10 +08:00
/* 能源驾驶舱 */
2024-05-17 10:31:47 +08:00
energy: {
stockDOData: [],
waterList: {},
gasList: [],
elecList:{}
},
2024-04-18 17:01:10 +08:00
/* 效率驾驶舱 */
2024-05-08 16:38:05 +08:00
efficiency: {
chipOee: {
current: [],
previous: [],
2024-05-29 17:05:55 +08:00
target:[]
2024-05-08 16:38:05 +08:00
},
transformRate: {
current: [],
previous: [],
2024-05-29 17:05:55 +08:00
target:[]
2024-05-08 16:38:05 +08:00
},
chipRate: {
target: [],
current: [],
previous: [],
2024-05-11 16:40:29 +08:00
outputNumber:[],
2024-05-08 16:38:05 +08:00
},
stdRate: {
target: [],
current: [],
2024-05-29 17:05:55 +08:00
previous: [],
2024-05-11 16:40:29 +08:00
outputNumber:[]
2024-05-08 16:38:05 +08:00
},
},
2024-04-18 17:01:10 +08:00
},
home: {
2024-04-28 16:55:21 +08:00
/** 主页状态 */
2024-04-18 17:01:10 +08:00
ftoInvest: null,
chipInvest: null,
chipOutput: null,
stdOutput: null,
bipvOutput: null,
},
};
const mutations = {
SET_HOME_INFO: (state, payload) => {
state.home.ftoInvest = payload.ftoInvest;
state.home.chipInvest = payload.chipInvest;
state.home.chipOutput = payload.chipOutput;
state.home.stdOutput = payload.stdOutput;
state.home.bipvOutput = payload.bipvOutput;
},
2024-04-25 17:07:44 +08:00
SET_COPILOT_INFO: (state, { type, payload }) => {
switch (type) {
2024-04-24 16:31:27 +08:00
case "yield":
2024-04-25 17:07:44 +08:00
state.copilot.yield.ftoInvest = payload.ftoInvest;
state.copilot.yield.chipInvest = payload.chipInvest;
state.copilot.yield.chipOutput = payload.chipOutput;
state.copilot.yield.stdOutput = payload.stdOutput;
state.copilot.yield.bipvOutput = payload.bipvOutput;
2024-04-24 16:31:27 +08:00
break;
case "energy":
2024-05-17 10:31:47 +08:00
state.copilot.energy.stockDOData = payload.stockDOData;
state.copilot.energy.gasList = payload.gasList;
state.copilot.energy.waterList = payload.waterList;
state.copilot.energy.elecList = payload.elecList;
2024-04-24 16:31:27 +08:00
break;
case "efficiency":
2024-05-29 17:05:55 +08:00
state.copilot.efficiency.chipOeeRate = payload.chipOeeRate;
2024-05-08 16:38:05 +08:00
state.copilot.efficiency.transformRate = payload.transformRate;
state.copilot.efficiency.chipRate = payload.chipRate;
state.copilot.efficiency.stdRate = payload.stdRate;
2024-04-24 16:31:27 +08:00
break;
}
},
2024-04-18 17:01:10 +08:00
};
const actions = {
/** 初始化首页数据 */
async initHome({ commit }) {
const dataArr = await getHomeInfo();
2024-06-03 08:23:40 +08:00
console.log('dataArr', dataArr);
let preData = dataArr.previousProdOutputOutDO
let preFtoData = dataArr.previousProdOutputFtoDO
2024-05-20 10:20:37 +08:00
// const targetArr = await getHomeInfo();
2024-06-05 14:30:05 +08:00
// factoryListResponse, targetListResponse, prodOutputFtoListRes,preData,preFtoData
const payload = splitCurrentAndPrevious(dataArr.prodOutputOutDO, dataArr.prodTargetOutputDO,dataArr.prodOutputFtoDO,preData,preFtoData);
2024-04-25 17:07:44 +08:00
commit("SET_HOME_INFO", payload);
2024-04-18 17:01:10 +08:00
},
/** 初始化驾驶舱数据 */
2024-05-29 17:05:55 +08:00
async initCopilot({ commit }, { period,source,than}) {
2024-05-17 10:31:47 +08:00
// if (source == "energy") return;
2024-05-08 16:38:05 +08:00
2024-04-25 17:07:44 +08:00
const fetcher = {
yield: getCopilotYield,
2024-05-17 10:31:47 +08:00
energy: getCopilotEnergy,
2024-04-28 15:18:46 +08:00
efficiency: getCopilotEfficiency,
2024-04-25 17:07:44 +08:00
}[source];
2024-05-08 16:38:05 +08:00
const handler = {
yield: splitCurrentAndPrevious,
2024-05-17 10:31:47 +08:00
energy: splitCurrentAndPreviousB,
2024-05-08 16:38:05 +08:00
efficiency: splitCurrentAndPreviousA,
2024-05-10 11:10:42 +08:00
}[source]
2024-04-26 17:05:26 +08:00
// 获取产量数据
2024-05-29 17:05:55 +08:00
let { data: factoryList, type } = await fetcher(period,than)
// let targetList = null;
// if (source === "yield" || source === "efficiency") {
// // 获取目标数据
// let { data } = await fetcher(period,than, true)
// targetList = data
// }
// if (source == "energy") {
// let factoryData = factoryList
// const payload = handler(factoryData)
// commit("SET_COPILOT_INFO", { type, payload });
// } else {
2024-06-03 08:23:40 +08:00
console.log('factoryList',factoryList)
2024-05-20 10:20:37 +08:00
let factoryData = factoryList.prodOutputOutDO ? factoryList.prodOutputOutDO : factoryList.prodOutputRateDO
2024-05-29 17:05:55 +08:00
let preData = factoryList.previousProdOutputOutDO ? factoryList.previousProdOutputOutDO : factoryList.previousProdOutputRateDO
let preFtoData = factoryList.previousProdOutputFtoDO ? factoryList.previousProdOutputFtoDO : []
2024-05-20 10:20:37 +08:00
let prodOutputFtoDO = factoryList.prodOutputFtoDO ? factoryList.prodOutputFtoDO : []
2024-05-29 17:05:55 +08:00
let targetData = factoryList.prodTargetOutputDO ? factoryList.prodTargetOutputDO : factoryList.prodTargetRateDO
const payload = handler(factoryData,targetData,prodOutputFtoDO,preData,preFtoData)
2024-04-25 17:07:44 +08:00
commit("SET_COPILOT_INFO", { type, payload });
2024-05-17 10:31:47 +08:00
2024-05-29 17:05:55 +08:00
// }
2024-05-17 10:31:47 +08:00
2024-04-24 16:31:27 +08:00
},
2024-04-18 17:01:10 +08:00
};
export default {
namespaced: true,
state,
mutations,
actions,
};
2024-04-25 17:07:44 +08:00
2024-05-17 10:31:47 +08:00
function splitCurrentAndPreviousB(factoryListResponse) {
let factoryArr = [
{
id: 0,
name: '瑞昌中建材光电材料有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
{
id: 1,
name: '邯郸中建材光电材料有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
{
id: 2,
name: '中建材株洲光电材料有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
{
id: 3,
name: '佳木斯中建材光电材料有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
{
id: 4,
name: '成都中建材光电材料有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
{
id: 5,
name: '凯盛光伏材料有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
{
id: 6,
name: '蚌埠兴科玻璃有限公司',
stockData: [],
waterData: [],
elsData: [],
gasData: [],
},
]
if (factoryListResponse) {
for (let i in factoryListResponse.stockDO) {
const index = factoryArr.findIndex(item => item.id == factoryListResponse.stockDO[i].factory)
if (index != -1) {
factoryListResponse.stockDO[i].stockInfo.forEach(ele => {
factoryArr[index].stockData.push(ele)
});
}
}
let stockDOData = []
factoryArr.forEach((ele, index) => [
stockDOData[index] = [],
ele.stockData.forEach((item) => {
let obj = {}
obj.name = item.glassType == 0 ? '玻璃芯片' : item.glassType == 1 ? '标准组件' : item.glassType == 2 ? 'BIPV' : '定制组件'
obj.value = item.stockNumber
stockDOData[index].push(obj)
}),
])
let gasList = []
// if (factoryListResponse.gasDO) {
factoryListResponse.gasDO.forEach((ele) => {
gasList[ele.factory] = ele.totalEnergyValue
})
// }
// console.log(factoryListResponse.gasDO);
let waterObj = Object.groupBy(factoryListResponse.waterDO, ({ groupName }) => groupName)
let waterList = {
times: [],
0: [],
1: [],
2: [],
3: [],
4: [],
5: [],
6: [],
}
for (let i in waterObj) {
waterList.times.push(i)
waterObj[i].forEach((ele, index) => {
waterList[ele.factory].push(ele.totalEnergyValue)
})
}
let elecObj = Object.groupBy(factoryListResponse.elecDO, ({ groupName }) => groupName)
let elecList = {
times: [],
0: [],
1: [],
2: [],
3: [],
4: [],
5: [],
6: [],
}
for (let i in elecObj) {
elecList.times.push(i)
elecObj[i].forEach((ele, index) => {
elecList[ele.factory].push(ele.totalEnergyValue)
})
}
return {
stockDOData,
waterList,
gasList,
elecList,
};
} else {
let stockDOData = Array[7].fill([])
let waterList = {}
return {
stockDOData,
waterList,
gasList,
elecList
};
}
}
2024-05-29 17:05:55 +08:00
function splitCurrentAndPreviousA(factoryListResponse, targetListResponse, prodOutputFtoListRes,preData,preFtoData) {
console.log('工厂',targetListResponse);
2024-05-08 16:38:05 +08:00
// 初始数据
2024-05-29 17:05:55 +08:00
const { chipOeeRate, transformRate, chipRate, stdRate } = initA();
2024-05-10 11:10:42 +08:00
// factoryListResponse = [
// {
// factory: 0,
// oee: 0.8,
// previousYearOee: 0.7,
// componentConversionEfficiency: 0.8,
// previousYearComponentConversionEfficiency: 0.7,
// glassType: 0,
// yieldRate: 0.8,
// previousYearYieldRate: 0.7,
// chipYieldRate: 0.38,
// componentYieldRate: 0.73,
// },
// {
// factory: 1,
// oee: 0.8,
// previousYearOee: 0.7,
// componentConversionEfficiency: 0.8,
// previousYearComponentConversionEfficiency: 0.7,
// glassType: 1,
// yieldRate: 0.8,
// previousYearYieldRate: 0.7,
// chipYieldRate: 0.38,
// componentYieldRate: 0.73,
// },
// {
// factory: 2,
// oee: 0.8,
// previousYearOee: 0.7,
// componentConversionEfficiency: 0.8,
// previousYearComponentConversionEfficiency: 0.7,
// glassType: 1,
// yieldRate: 0.8,
// previousYearYieldRate: 0.7,
// chipYieldRate: 0.38,
// componentYieldRate: 0.73,
// },
// {
// factory: 3,
// oee: 0.8,
// previousYearOee: 0.7,
// componentConversionEfficiency: 0.8,
// previousYearComponentConversionEfficiency: 0.7,
// glassType: 0,
// yieldRate: 0.8,
// previousYearYieldRate: 0.7,
// chipYieldRate: 0.38,
// componentYieldRate: 0.73,
// },
// ];
2024-05-29 17:05:55 +08:00
if (preData && preData[0] != null) {
for (const factory of preData) {
const fId = getPreFactoryId(factory);
2024-06-05 14:14:12 +08:00
// chipInvest.previous[fId] = factory.previousYearInputNumber;
2024-05-29 17:05:55 +08:00
// chipOeeRate.current[fId] = factory.oee;
chipOeeRate.previous[fId] = factory.previousYearOee;
// 转化效率
transformRate.previous[fId] =factory.previousYearComponentConversionEfficiency ;
// 芯片良率 与 标准组件良率
if (![0, 1].includes(factory.glassType)) continue;
const _t = [chipRate, stdRate][factory.glassType]
// _t.current[fId] = factory.yieldRate ;
_t.previous[fId] = factory.previousYearYieldRate ;
// }
// debugger;
}
}
2024-05-08 16:38:05 +08:00
if (factoryListResponse) {
for (const factory of factoryListResponse) {
const fId = getFactoryId(factory);
// 获取目标值
if (targetListResponse) {
const {
chipYieldRate,
componentYieldRate,
chipOee,
componentConversionEfficiency,
2024-05-11 16:40:29 +08:00
componentYield
2024-05-29 17:05:55 +08:00
} = getFactoryTargetValueA(targetListResponse, fId)
2024-05-11 16:40:29 +08:00
stdRate.target[fId] = componentYieldRate
chipRate.target[fId] = chipYieldRate
2024-05-29 17:05:55 +08:00
chipOeeRate.target[fId] = chipOee
transformRate.target[fId] = componentConversionEfficiency
2024-05-08 16:38:05 +08:00
}
// 芯片OEE
2024-05-29 17:05:55 +08:00
chipOeeRate.current[fId] = factory.oee;
// chipOeeRate.previous[fId] = factory.previousYearOee;
2024-05-08 16:38:05 +08:00
// 转化效率
2024-05-29 17:05:55 +08:00
transformRate.current[fId] = factory.componentConversionEfficiency;
// transformRate.previous[fId] = factory.previousYearComponentConversionEfficiency ;
2024-05-08 16:38:05 +08:00
// 芯片良率 与 标准组件良率
if (![0, 1].includes(factory.glassType)) continue;
2024-05-11 16:40:29 +08:00
const _t = [chipRate, stdRate][factory.glassType]
_t.current[fId] = factory.yieldRate ;
2024-05-29 17:05:55 +08:00
// _t.previous[fId] = factory.previousYearYieldRate ;
2024-05-08 16:38:05 +08:00
}
2024-05-29 17:05:55 +08:00
// console.log('chipOeeRate',chipOeeRate);
2024-05-08 16:38:05 +08:00
return {
2024-05-29 17:05:55 +08:00
chipOeeRate,
2024-05-08 16:38:05 +08:00
transformRate,
chipRate,
stdRate,
};
}
}
2024-05-29 17:05:55 +08:00
function splitCurrentAndPrevious(factoryListResponse, targetListResponse, prodOutputFtoListRes,preData,preFtoData) {
2024-06-05 14:30:05 +08:00
console.log('prodOutputFtoListRes',preFtoData);
2024-05-07 10:23:38 +08:00
// 初始数据
2024-05-20 10:20:37 +08:00
const { chipInvest, ftoInvest, chipOutput, stdOutput, bipvOutput } = init()
if (prodOutputFtoListRes) {
for (const factory of prodOutputFtoListRes) {
console.log(factory);
const fId = getFactoryId(factory);
2024-05-29 17:05:55 +08:00
// const preFId = getPreFactoryId(factory);
// if (fId) {
2024-05-20 10:20:37 +08:00
ftoInvest.current[fId] = factory.chipInput;
2024-05-29 17:05:55 +08:00
// }
// if (preFId) {
// ftoInvest.previous[fId] = factory.previousYearChipInput;
// }
}
}
if (preFtoData) {
for (const factory of preFtoData) {
console.log(factory);
const fId = getPreFactoryId(factory);
// const preFId = getPreFactoryId(factory);
// if (fId) {
2024-05-20 10:20:37 +08:00
ftoInvest.previous[fId] = factory.previousYearChipInput;
2024-05-29 17:05:55 +08:00
// }
// if (preFId) {
// ftoInvest.previous[fId] = factory.previousYearChipInput;
// }
}
}
if (preData && preData[0] != null) {
for (const factory of preData) {
const fId = getPreFactoryId(factory);
chipInvest.previous[fId] = factory.previousYearInputNumber;
if (![0, 1, 2].includes(factory.previousGlassType)) continue;
const _t = [chipOutput, stdOutput, bipvOutput][factory.previousGlassType];
// if (fId) {
// _t.current[fId] = factory.outputNumber;
// }
// if (preFId) {
_t.previous[fId] = factory.previousYearOutputNumber
// }
// debugger;
2024-05-20 10:20:37 +08:00
}
}
2024-05-29 17:05:55 +08:00
// console.log('ftoInvest',ftoInvest)
if (factoryListResponse && factoryListResponse[0] != null) {
2024-04-25 17:07:44 +08:00
for (const factory of factoryListResponse) {
const fId = getFactoryId(factory);
2024-05-29 17:05:55 +08:00
// const preFId = getPreFactoryId(factory);
2024-04-25 17:07:44 +08:00
// 获取目标值
if (targetListResponse) {
const { chipYield, componentYield, bipvProductOutput } =
getFactoryTargetValue(targetListResponse, fId);
chipOutput.target[fId] = chipYield;
stdOutput.target[fId] = componentYield;
bipvOutput.target[fId] = bipvProductOutput;
}
// 芯片投入
2024-05-29 17:05:55 +08:00
chipInvest.current[fId] = factory.inputNumber;
2024-05-20 10:20:37 +08:00
2024-04-25 17:07:44 +08:00
// 产出数据, 0 - (玻璃)芯片产出, 1 - 标准组件产出, 2 - BIPV产出
2024-04-26 15:44:04 +08:00
// 因为后端写的垃圾数据,所以这里要做一下判断
2024-04-26 17:05:26 +08:00
if (![0, 1, 2].includes(factory.glassType)) continue;
2024-04-25 17:07:44 +08:00
const _t = [chipOutput, stdOutput, bipvOutput][factory.glassType];
2024-05-29 17:05:55 +08:00
_t.current[fId] = factory.outputNumber;
2024-04-25 17:07:44 +08:00
}
return {
chipInvest,
2024-05-20 10:20:37 +08:00
// ftoInvest,
2024-04-25 17:07:44 +08:00
ftoInvest,
chipOutput,
stdOutput,
bipvOutput,
};
2024-05-29 17:05:55 +08:00
}else{
return {
chipInvest,
// ftoInvest,
ftoInvest,
chipOutput,
stdOutput,
bipvOutput,
}
2024-04-25 17:07:44 +08:00
}
}
function getFactoryId(factory) {
return factory.factory;
}
2024-05-29 17:05:55 +08:00
function getPreFactoryId(factory) {
return factory.previousFactory;
}
2024-04-25 17:07:44 +08:00
function getFactoryTargetValue(targetList, factoryId) {
const target = targetList.find((item) => item.factory === factoryId);
if (target) {
return {
// 自带模拟数据了.... random_default
2024-05-29 17:05:55 +08:00
chipYield: target.chipYield ?? 0,
componentYield: target.componentYield ?? 0,
bipvProductOutput: target.bipvProductOutput ?? 0,
2024-04-25 17:07:44 +08:00
};
}
return {
2024-05-29 17:05:55 +08:00
chipYield: 0,
componentYield: 0,
bipvProductOutput: 0,
2024-04-25 17:07:44 +08:00
};
}
2024-05-08 16:38:05 +08:00
/**
* 获取 芯片良率目标值 标准组件良率目标值
* @param {*} targetList 目标值列表
* @param {*} factoryId 工厂ID
* @returns
*/
function getFactoryTargetValueA(targetList, factoryId) {
2024-05-11 16:40:29 +08:00
const target = targetList.find((item) => item.factory === factoryId)
2024-05-08 16:38:05 +08:00
if (target) {
return {
2024-05-29 17:05:55 +08:00
chipYieldRate: target.chipYieldRate ?? 0,
componentYieldRate: target.componentYieldRate ?? 0,
componentYield: target.componentYield ?? 0,
// componentYield: target.componentYield ?? 0,
chipOee: target.chipOee ?? 0,
2024-05-08 16:38:05 +08:00
};
}
return {
2024-05-11 16:40:29 +08:00
chipYieldRate:0,
componentYieldRate:0,
2024-05-29 17:05:55 +08:00
componentYield: 0,
chipOee:0,
2024-05-08 16:38:05 +08:00
};
}
/**
*
* @returns 初始化 效率模块里 初始状态值
*/
function initA() {
const t_ = {
current: Array(7).fill(0),
previous: Array(7).fill(0),
};
// 芯片OEE
// 转化效率
// 标准组件良率
const stdRate = {
...deepClone(t_),
target: Array(7).fill(0),
};
// 芯片良率
2024-05-29 17:05:55 +08:00
const transformRate = deepClone(stdRate);
2024-05-08 16:38:05 +08:00
const chipRate = deepClone(stdRate);
2024-05-29 17:05:55 +08:00
const chipOeeRate = deepClone(stdRate);
2024-05-08 16:38:05 +08:00
return {
2024-05-29 17:05:55 +08:00
chipOeeRate,
2024-05-08 16:38:05 +08:00
transformRate,
chipRate,
stdRate,
};
}
2024-04-28 16:55:21 +08:00
/**
2024-05-07 10:23:38 +08:00
*
2024-05-08 16:38:05 +08:00
* @returns 初始化 产量模块里 初始状态值
2024-04-28 16:55:21 +08:00
*/
2024-04-25 17:07:44 +08:00
function init() {
const t_ = {
current: Array(7).fill(0),
previous: Array(7).fill(0),
};
// 芯片投入
const chipInvest = deepClone(t_);
// FTO投入
const ftoInvest = deepClone(t_);
// 芯片产出
const chipOutput = {
...deepClone(t_),
target: Array(7).fill(0),
};
// 标准组件产出
const stdOutput = deepClone(chipOutput);
// BIPV产出
const bipvOutput = deepClone(chipOutput);
return {
2024-04-28 16:55:21 +08:00
chipInvest, // 芯片投入
ftoInvest, // FTO投入
chipOutput, // 芯片产出
stdOutput, // 标准组件产出
bipvOutput, // BIPV产出
2024-04-25 17:07:44 +08:00
};
}
2024-05-08 16:38:05 +08:00
function random_default(min = 0, max = 1) {
// return 0;
let a = Math.floor(Math.random() * max);
while (a < min) {
a = Math.floor(Math.random() * max);
2024-04-25 17:07:44 +08:00
}
return a;
}
/* 接口 */
async function getHomeInfo() {
2024-05-10 11:10:42 +08:00
const { code, data } = await axios.post("ip/prod-output/cockpitData", {
2024-04-25 17:07:44 +08:00
factorys: [],
date: 4,
2024-05-29 17:05:55 +08:00
mode:0
2024-04-25 17:07:44 +08:00
});
if (code == 0) {
return data;
}
console.warn("getHomeInfo failed, code: ", code);
return null;
}
async function getHomeTarget() {
const { code, data } = await axios.post("/ip/prod-target/query-by-date", {
factorys: [],
date: 4,
});
if (code == 0) {
return data;
}
console.warn("getHomeTarget failed, code: ", code);
return null;
}
2024-04-28 15:18:46 +08:00
function getUrl(copilot_module) {
let url = {
// 对比数据的 URL
comparison: "",
// 目标数据的 URL
2024-05-17 10:31:47 +08:00
// target: "",
2024-04-28 15:18:46 +08:00
};
switch (copilot_module) {
case "yield":
2024-05-10 11:10:42 +08:00
url.comparison = "ip/prod-output/cockpitData";
// url.target = "/ip/prod-target/query-by-date";
2024-04-28 15:18:46 +08:00
break;
case "energy":
2024-05-17 10:31:47 +08:00
url.comparison = "ip/prod-output/cockpitComprehensiveDataMonitor";
2024-04-28 15:18:46 +08:00
break;
case "efficiency":
2024-05-10 11:10:42 +08:00
url.comparison = "ip/prod-output/cockpitDataRate";
// url.target = "/ip/prod-target/query-rate-target";
2024-04-28 15:18:46 +08:00
break;
}
return url;
}
async function doFetch(copilot_module = "yield", fetch_target, params) {
const url = getUrl(copilot_module);
2024-04-26 17:05:26 +08:00
const { code, data } = await axios.post(
2024-05-10 11:10:42 +08:00
url.comparison,
2024-04-26 17:05:26 +08:00
{
...params,
}
);
2024-04-25 17:07:44 +08:00
if (code == 0) {
return data;
}
2024-04-28 15:18:46 +08:00
console.warn("[doFetch] failed, code: ", code);
2024-04-25 17:07:44 +08:00
return null;
}
2024-04-28 16:55:21 +08:00
/**
2024-05-07 10:23:38 +08:00
*
2024-04-28 16:55:21 +08:00
* @param {*} period 日周月年1,2,3,4
* @param {*} target 是否获取目标数据
2024-05-07 10:23:38 +08:00
* @returns
2024-04-28 16:55:21 +08:00
*/
2024-05-29 17:05:55 +08:00
function getCopilotYield(period,than,target = false) {
return getCopilotData("yield", period,than, target);
2024-04-28 15:18:46 +08:00
}
function getCopilotEnergy(period, target = false) {
2024-05-29 17:05:55 +08:00
return getCopilotData("energy", period,than, target);
2024-04-28 15:18:46 +08:00
}
2024-05-29 17:05:55 +08:00
function getCopilotEfficiency(period,than, target = false) {
return getCopilotData("efficiency", period,than, target);
2024-04-28 15:18:46 +08:00
}
2024-04-26 17:05:26 +08:00
/**
*
* @param {*} period 周期 日周月年
* @param {*} target 是否获取目标数据默认
* @returns
*/
2024-05-29 17:05:55 +08:00
async function getCopilotData(copilot_module, period,than, target = false) {
2024-04-28 15:18:46 +08:00
if (!copilot_module) copilot_module = "yield";
2024-04-25 17:07:44 +08:00
// 请求参数,直接一次性获取所有工厂
let queryParams = {
factorys: [],
date: 4,
2024-05-29 17:05:55 +08:00
mode:0
2024-04-25 17:07:44 +08:00
};
switch (period) {
case "日":
queryParams.date = 1;
break;
case "周":
queryParams.date = 2;
break;
case "月":
queryParams.date = 3;
break;
case "年":
queryParams.date = 4;
break;
default:
queryParams.date = 1;
break;
}
2024-05-29 17:05:55 +08:00
switch (than) {
case "同比":
queryParams.mode = 0;
break;
case "环比":
queryParams.mode = 1;
break;
}
2024-04-26 17:05:26 +08:00
return {
2024-04-28 15:18:46 +08:00
data: await doFetch(copilot_module, target ? true : false, queryParams),
type: copilot_module,
2024-04-26 17:05:26 +08:00
};
2024-04-25 17:07:44 +08:00
}