From 253f182370f4496ea4c6daf0d8b90fa4542056a4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-FUDKNA8\\znjsz" Date: Sun, 28 Apr 2024 15:18:46 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=8E=A5=E5=8F=A3=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/home.js | 59 ++++++++++++++++++++------ src/views/copilot/efficiency/index.vue | 34 +++++++++++---- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/src/store/modules/home.js b/src/store/modules/home.js index bfab628..0843d43 100644 --- a/src/store/modules/home.js +++ b/src/store/modules/home.js @@ -65,13 +65,13 @@ const actions = { async initCopilot({ commit }, { period, source }) { const fetcher = { yield: getCopilotYield, - energy: null, - efficiency: null, + energy: getCopilotEnergy, + efficiency: getCopilotEfficiency, }[source]; // 获取产量数据 let { data: factoryList, type } = await fetcher(period); let targetList = null; - if (source === "yield") { + if (source === "yield" || source === "efficiency") { // 获取目标数据 let { data } = await fetcher(period, true); targetList = data; @@ -210,13 +210,33 @@ async function getHomeTarget() { return null; } -async function fetcher(type = "yield", params) { +function getUrl(copilot_module) { + let url = { + // 对比数据的 URL + comparison: "", + // 目标数据的 URL + target: "", + }; + switch (copilot_module) { + case "yield": + url.comparison = "/ip/prod-output/query-by-date"; + url.target = "/ip/prod-target/query-by-date"; + break; + case "energy": + break; + case "efficiency": + url.comparison = "/ip/prod-output/query-Rate-List"; + url.target = "/ip/prod-target/query-rate-target"; + break; + } + + return url; +} + +async function doFetch(copilot_module = "yield", fetch_target, params) { + const url = getUrl(copilot_module); const { code, data } = await axios.post( - type == "yield" - ? // 产量 数据 - "/ip/prod-output/query-by-date" - : // 目标数据 - "/ip/prod-target/query-by-date", + fetch_target ? url.target : url.comparison, { ...params, } @@ -224,17 +244,30 @@ async function fetcher(type = "yield", params) { if (code == 0) { return data; } - console.warn("getCopilotYield failed, code: ", code); + console.warn("[doFetch] failed, code: ", code); return null; } +function getCopilotYield(period, target = false) { + return getCopilotData("yield", period, target); +} + +function getCopilotEnergy(period, target = false) { + return getCopilotData("energy", period, target); +} + +function getCopilotEfficiency(period, target = false) { + return getCopilotData("efficiency", period, target); +} + /** * * @param {*} period 周期: 日周月年 * @param {*} target 是否获取目标数据:默认 否 * @returns */ -async function getCopilotYield(period, target = false) { +async function getCopilotData(copilot_module, period, target = false) { + if (!copilot_module) copilot_module = "yield"; // 请求参数,直接一次性获取所有工厂 let queryParams = { factorys: [], @@ -260,7 +293,7 @@ async function getCopilotYield(period, target = false) { } return { - data: await fetcher(target ? "target" : "yield", queryParams), - type: "yield", + data: await doFetch(copilot_module, target ? true : false, queryParams), + type: copilot_module, }; } diff --git a/src/views/copilot/efficiency/index.vue b/src/views/copilot/efficiency/index.vue index 55a1d4b..7ea9aab 100644 --- a/src/views/copilot/efficiency/index.vue +++ b/src/views/copilot/efficiency/index.vue @@ -7,23 +7,41 @@