update copilot state

这个提交包含在:
DESKTOP-FUDKNA8\znjsz 2024-04-18 11:22:53 +08:00
父节点 8075325f50
当前提交 d9bfbf0d9a
共有 3 个文件被更改,包括 157 次插入17 次删除

查看文件

@ -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
})

查看文件

@ -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 {

查看文件

@ -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();