From d9bfbf0d9a4aafb78b62d7837aa8096d01d43b0b Mon Sep 17 00:00:00 2001 From: "DESKTOP-FUDKNA8\\znjsz" Date: Thu, 18 Apr 2024 11:22:53 +0800 Subject: [PATCH] update copilot state --- src/store/index.js | 4 +- src/store/modules/home.js | 162 +++++++++++++++++++++++++++++++++++--- src/views/index.vue | 8 +- 3 files changed, 157 insertions(+), 17 deletions(-) diff --git a/src/store/index.js b/src/store/index.js index 116d6d6..9e98a78 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,6 +6,7 @@ import tagsView from './modules/tagsView' import permission from './modules/permission' import settings from './modules/settings' import dict from './modules/dict' +import copilot from './modules/home' import getters from './getters' Vue.use(Vuex) @@ -17,7 +18,8 @@ const store = new Vuex.Store({ tagsView, permission, settings, - dict + dict, + copilot }, getters }) diff --git a/src/store/modules/home.js b/src/store/modules/home.js index 2b2919d..32bcc10 100644 --- a/src/store/modules/home.js +++ b/src/store/modules/home.js @@ -1,20 +1,164 @@ +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 = { - info: null + copilot: { + /* 产量驾驶舱 */ + yield: {}, + /* 能源驾驶舱 */ + energy: {}, + /* 效率驾驶舱 */ + efficiency: {}, + }, + home: { + ftoInvest: null, + chipInvest: null, + chipOutput: null, + stdOutput: null, + bipvOutput: null, + }, }; const mutations = { - SET_INFO: (state) => { - state.info = state - }, + 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 = { - setInfo({ commit }, ) { - commit("SET_INFO", ); - }, - closeSideBar({ commit }, { withoutAnimation }) { - commit("CLOSE_SIDEBAR", withoutAnimation); + /** 初始化首页数据 */ + async initHome({ commit }) { + const dataArr = await getHomeInfo(); + 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), + }; // 芯片产出 + const stdOutput = []; // 标准组件产出 + const bipvOutput = { + current: Array(7).fill(0), + previous: Array(7).fill(0), + }; // BIPV产出 + + if (dataArr) { + console.log("copilot init home--->", dataArr); + for (const factory of dataArr) { + /* 工厂索引 */ + const factoryId = factory.factory; + /* 收集芯片投入数据 */ + 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: + // 标准组件 产出 + 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 { diff --git a/src/views/index.vue b/src/views/index.vue index 0f07e8b..7512619 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -108,13 +108,7 @@ export default { }; }, mounted() { - this.$axios - .post("/ip/prod-target/query-by-date", { factorys: [], date: 4 }) - .then((res) => { - if (res.data && Array.isArray(res.data)) { - this.$store.dispatch("home/setInfo", res.data); - } - }); + this.$store.dispatch('copilot/initHome'); this.$nextTick(() => { this.initPins();