import axios from "@/utils/request"; function random_default() { return 0; let a = Math.floor(Math.random() * 1000); while (a < 600) { a = Math.floor(Math.random() * 1000); } return a; } /* 接口 */ async function getHomeInfo() { const { code, data } = await axios.post("/ip/prod-output/query-by-date", { factorys: [], date: 4, }); 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; } /* 状态 */ const state = { copilot: { /* 产量驾驶舱 */ yield: {}, /* 能源驾驶舱 */ energy: {}, /* 效率驾驶舱 */ efficiency: {}, }, home: { 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; }, SET_COPILOT_INFO: (state) => {}, }; const actions = { /** 初始化首页数据 */ async initHome({ commit }) { const dataArr = await getHomeInfo(); const targetArr = await getHomeTarget(); const chipInvest = { current: Array(7).fill(0), previous: Array(7).fill(0), }; // 芯片投入 const ftoInvest = { current: Array(7).fill(0), previous: Array(7).fill(0), }; // FTO投入 const chipOutput = { current: Array(7).fill(0), previous: Array(7).fill(0), target: Array(7).fill(0), }; // 芯片产出 const stdOutput = { current: Array(7).fill(0), previous: Array(7).fill(0), target: Array(7).fill(0), }; // 标准组件产出 const bipvOutput = { current: Array(7).fill(0), previous: Array(7).fill(0), target: Array(7).fill(0), }; // BIPV产出 if (dataArr) { for (const factory of dataArr) { /* 工厂索引 */ const factoryId = factory.factory; /* 收集目标数据 */ if (targetArr) { const target = targetArr.find((item) => item.factory === factoryId); if (target) { chipOutput.target.splice(factoryId, 1, target.chipYield ?? 0); stdOutput.target.splice(factoryId, 1, target.componentYield ?? 0); bipvOutput.target.splice(factoryId, 1, target.bipvProductOutput ?? 0); } } /* 收集芯片投入数据 */ chipInvest.current.splice( factoryId, 1, factory.inputNumber ?? random_default() ); chipInvest.previous.splice( factoryId, 1, factory.previousYearInputNumber ?? random_default() ); /* 收集FTO投入数据 */ ftoInvest.current.splice( factoryId, 1, factory.chipInput ?? random_default() ); ftoInvest.previous.splice( factoryId, 1, factory.previousYearChipInput ?? random_default() ); /* 收集产出数据 */ switch (factory.glassType) { case 0: // 玻璃芯片 产出 chipOutput.current.splice( factoryId, 1, factory.outputNumber ?? random_default() ); chipOutput.previous.splice( factoryId, 1, factory.previousYearOutputNumber ?? random_default() ); break; case 1: // 标准组件 产出 stdOutput.current.splice( factoryId, 1, factory.outputNumber ?? random_default() ); stdOutput.previous.splice( factoryId, 1, factory.previousYearOutputNumber ?? random_default() ); break; case 2: // BIPV 产出 bipvOutput.current.splice( factoryId, 1, factory.outputNumber ?? random_default() ); bipvOutput.previous.splice( factoryId, 1, factory.previousYearOutputNumber ?? random_default() ); break; } } /* 更新 state */ commit("SET_HOME_INFO", { ftoInvest, chipInvest, chipOutput, stdOutput, bipvOutput, }); } }, /** 初始化驾驶舱数据 */ async initCopilot({ commit }) {}, }; export default { namespaced: true, state, mutations, actions, };