diff --git a/.env.dev b/.env.dev index 6ee8268..f62007f 100644 --- a/.env.dev +++ b/.env.dev @@ -5,6 +5,7 @@ ENV = 'development' VUE_APP_TITLE = 芋道管理系统 # 芋道管理系统/开发环境 +# VUE_APP_BASE_API = 'http://192.168.1.61:48080' VUE_APP_BASE_API = 'http://glass.kszny.picaiba.com' # 路由懒加载 diff --git a/package.json b/package.json index 0a67be3..d920609 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "highlight.js": "^11.9.0", "js-beautify": "^1.15.1", "jsencrypt": "3.3.1", + "lodash": "^4.17.21", "mockjs": "^1.1.0", "moment": "^2.30.1", "nprogress": "0.2.0", diff --git a/src/store/modules/home.js b/src/store/modules/home.js index e9f8163..bfab628 100644 --- a/src/store/modules/home.js +++ b/src/store/modules/home.js @@ -1,4 +1,180 @@ import axios from "@/utils/request"; +import { deepClone } from "../../utils"; + +/* 状态 */ +const state = { + copilot: { + /* 产量驾驶舱 */ + yield: { + ftoInvest: null, + chipInvest: null, + chipOutput: null, + stdOutput: null, + bipvOutput: null, + }, + /* 能源驾驶舱 */ + 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, { type, payload }) => { + switch (type) { + case "yield": + 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; + break; + case "energy": + state.copilot.energy = payload.data; + break; + case "efficiency": + state.copilot.efficiency = payload.data; + break; + } + }, +}; + +const actions = { + /** 初始化首页数据 */ + async initHome({ commit }) { + const dataArr = await getHomeInfo(); + const targetArr = await getHomeTarget(); + const payload = splitCurrentAndPrevious(dataArr, targetArr); + commit("SET_HOME_INFO", payload); + }, + /** 初始化驾驶舱数据 */ + async initCopilot({ commit }, { period, source }) { + const fetcher = { + yield: getCopilotYield, + energy: null, + efficiency: null, + }[source]; + // 获取产量数据 + let { data: factoryList, type } = await fetcher(period); + let targetList = null; + if (source === "yield") { + // 获取目标数据 + let { data } = await fetcher(period, true); + targetList = data; + } + const payload = splitCurrentAndPrevious(factoryList, targetList); + commit("SET_COPILOT_INFO", { type, payload }); + }, +}; + +export default { + namespaced: true, + state, + mutations, + actions, +}; + +// utils function +function splitCurrentAndPrevious(factoryListResponse, targetListResponse) { + const { chipInvest, ftoInvest, chipOutput, stdOutput, bipvOutput } = init(); + if (factoryListResponse) { + for (const factory of factoryListResponse) { + const fId = getFactoryId(factory); + // 获取目标值 + if (targetListResponse) { + const { chipYield, componentYield, bipvProductOutput } = + getFactoryTargetValue(targetListResponse, fId); + chipOutput.target[fId] = chipYield; + stdOutput.target[fId] = componentYield; + bipvOutput.target[fId] = bipvProductOutput; + } + // 芯片投入 + chipInvest.current[fId] = factory.inputNumber; + chipInvest.previous[fId] = factory.previousYearInputNumber; + // FTO投入 + ftoInvest.current[fId] = factory.chipInput; + ftoInvest.previous[fId] = factory.previousYearChipInput; + // 产出数据, 0 - (玻璃)芯片产出, 1 - 标准组件产出, 2 - BIPV产出 + // 因为后端写的垃圾数据,所以这里要做一下判断 + if (![0, 1, 2].includes(factory.glassType)) continue; + const _t = [chipOutput, stdOutput, bipvOutput][factory.glassType]; + _t.current[fId] = factory.outputNumber; + _t.previous[fId] = factory.previousYearOutputNumber; + // debugger; + } + + return { + chipInvest, + ftoInvest, + chipOutput, + stdOutput, + bipvOutput, + }; + } +} + +function getFactoryId(factory) { + return factory.factory; +} + +function getFactoryTargetValue(targetList, factoryId) { + const target = targetList.find((item) => item.factory === factoryId); + if (target) { + return { + // 自带模拟数据了.... random_default + chipYield: target.chipYield ?? random_default(), + componentYield: target.componentYield ?? random_default(), + bipvProductOutput: target.bipvProductOutput ?? random_default(), + }; + } + return { + chipYield: random_default(), + componentYield: random_default(), + bipvProductOutput: random_default(), + }; +} + +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 { + chipInvest, + ftoInvest, + chipOutput, + stdOutput, + bipvOutput, + }; +} function random_default() { return 0; @@ -34,162 +210,57 @@ async function getHomeTarget() { 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 function fetcher(type = "yield", params) { + const { code, data } = await axios.post( + type == "yield" + ? // 产量 数据 + "/ip/prod-output/query-by-date" + : // 目标数据 + "/ip/prod-target/query-by-date", + { + ...params, } - }, - /** 初始化驾驶舱数据 */ - async initCopilot({ commit }) {}, -}; + ); + if (code == 0) { + return data; + } + console.warn("getCopilotYield failed, code: ", code); + return null; +} -export default { - namespaced: true, - state, - mutations, - actions, -}; +/** + * + * @param {*} period 周期: 日周月年 + * @param {*} target 是否获取目标数据:默认 否 + * @returns + */ +async function getCopilotYield(period, target = false) { + // 请求参数,直接一次性获取所有工厂 + let queryParams = { + factorys: [], + date: 4, + }; + + 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; + } + + return { + data: await fetcher(target ? "target" : "yield", queryParams), + type: "yield", + }; +} diff --git a/src/views/copilot/components/charts/BipvOutput.vue b/src/views/copilot/components/charts/BipvOutput.vue index 174c704..dba836b 100644 --- a/src/views/copilot/components/charts/BipvOutput.vue +++ b/src/views/copilot/components/charts/BipvOutput.vue @@ -6,7 +6,7 @@ --> diff --git a/src/views/copilot/components/charts/ChipOutput.vue b/src/views/copilot/components/charts/ChipOutput.vue index 539720b..099dd42 100644 --- a/src/views/copilot/components/charts/ChipOutput.vue +++ b/src/views/copilot/components/charts/ChipOutput.vue @@ -6,7 +6,7 @@ --> diff --git a/src/views/copilot/components/charts/StdOutput.vue b/src/views/copilot/components/charts/StdOutput.vue index e09df94..064b8b6 100644 --- a/src/views/copilot/components/charts/StdOutput.vue +++ b/src/views/copilot/components/charts/StdOutput.vue @@ -6,7 +6,7 @@ --> + + diff --git a/src/views/copilot/components/charts/base/CityData.vue b/src/views/copilot/components/charts/base/CityData.vue new file mode 100644 index 0000000..2f539f9 --- /dev/null +++ b/src/views/copilot/components/charts/base/CityData.vue @@ -0,0 +1,148 @@ + + + + + + + diff --git a/src/views/copilot/components/charts/base/CityItem.vue b/src/views/copilot/components/charts/base/CityItem.vue new file mode 100644 index 0000000..2dbaf02 --- /dev/null +++ b/src/views/copilot/components/charts/base/CityItem.vue @@ -0,0 +1,58 @@ + + + + + + + diff --git a/src/views/copilot/components/charts/base/CityName.vue b/src/views/copilot/components/charts/base/CityName.vue new file mode 100644 index 0000000..d6fda61 --- /dev/null +++ b/src/views/copilot/components/charts/base/CityName.vue @@ -0,0 +1,55 @@ + + + + + + + diff --git a/src/views/copilot/components/charts/base/CityValue.vue b/src/views/copilot/components/charts/base/CityValue.vue new file mode 100644 index 0000000..9c42ab7 --- /dev/null +++ b/src/views/copilot/components/charts/base/CityValue.vue @@ -0,0 +1,127 @@ + + + + + + + diff --git a/src/views/copilot/components/charts/base/DoubleRingChart.vue b/src/views/copilot/components/charts/base/DoubleRingChart.vue index 15b90d5..76be992 100644 --- a/src/views/copilot/components/charts/base/DoubleRingChart.vue +++ b/src/views/copilot/components/charts/base/DoubleRingChart.vue @@ -12,9 +12,7 @@
{{ item.label }} - {{ - item.value.toLocaleString() - }} + {{ item.value | numberFilter }}
@@ -23,7 +21,7 @@ diff --git a/src/views/copilot/components/charts/base/double-ring-chart-options.js b/src/views/copilot/components/charts/base/double-ring-chart-options.js index b41cd15..743f820 100644 --- a/src/views/copilot/components/charts/base/double-ring-chart-options.js +++ b/src/views/copilot/components/charts/base/double-ring-chart-options.js @@ -1,4 +1,10 @@ -export default { +export default ({ + titleValue, + subtitle, + previousSum, + currentSum, + targetSum, +}) => ({ grid: { left: 0, right: 0, @@ -8,16 +14,16 @@ export default { }, tooltip: {}, title: { - text: "78%", - left: "50%", - top: "40%", + text: titleValue, + left: "49%", + top: "39%", textAlign: "center", textStyle: { fontWeight: 600, fontSize: 32, color: "#fffd", }, - subtext: "\u200224年累计产出\u2002", + subtext: `\u2002${subtitle}\u2002`, subtextStyle: { fontSize: 14, fontWeight: 100, @@ -26,17 +32,17 @@ export default { }, }, series: [ - // 背景 series - 2024计划 + // 背景 series { type: "pie", - name: "2024目标", + name: "当前目标", radius: ["70%", "85%"], center: ["50%", "52%"], emptyCircleStyle: { color: "#042c5f33", }, }, - // 数据 series - 2024累计 + // 数据 series { type: "pie", radius: ["70%", "85%"], @@ -44,15 +50,14 @@ export default { avoidLabelOvervlap: false, label: { show: false, - // position: "center", }, labelLine: { show: false, }, data: [ { - value: 90, - name: "2024累计产出", + value: currentSum, + name: "当前累计产出", selected: false, itemStyle: { borderJoin: "round", @@ -73,8 +78,16 @@ export default { }, }, { - value: 20, - name: "-", + value: + targetSum > currentSum + ? targetSum - currentSum + : targetSum == 0 + ? currentSum == 0 + ? 1 + : 0 + : 0, + + name: "未达成累计", itemStyle: { color: "transparent" }, label: { show: false }, }, @@ -94,8 +107,8 @@ export default { }, data: [ { - value: 90, - name: "2023累计产出", + value: previousSum, + name: "上期累计产出", selected: false, itemStyle: { borderJoin: "round", @@ -116,7 +129,12 @@ export default { }, }, { - value: 20, + value: + targetSum > previousSum + ? targetSum - previousSum + : previousSum == 0 + ? 1 + : 0, name: "-", itemStyle: { color: "transparent" }, label: { show: false }, @@ -124,4 +142,4 @@ export default { ], }, ], -}; +}); diff --git a/src/views/copilot/components/charts/base/icon.png b/src/views/copilot/components/charts/base/icon.png new file mode 100644 index 0000000..03c1a4c Binary files /dev/null and b/src/views/copilot/components/charts/base/icon.png differ diff --git a/src/views/copilot/components/select.vue b/src/views/copilot/components/select.vue index 4ecf30f..ae818f3 100644 --- a/src/views/copilot/components/select.vue +++ b/src/views/copilot/components/select.vue @@ -33,9 +33,28 @@ export default { }, data() { return { - currentActive: '', + currentActive: this.options[0], }; }, + watch: { + currentActive: { + handler(val) { + this.$emit( + "update:active", + [ + "瑞昌", + "邯郸", + "株洲", + "佳木斯", + "成都", + "凯盛光伏", + "蚌埠兴科", + ].indexOf(val) + ); + }, + immediate: true, + }, + }, computed: {}, methods: {}, }; @@ -55,7 +74,7 @@ button { padding: 8px 12px; cursor: pointer; position: relative; - transition: all .3s; + transition: all 0.3s; } button.active, diff --git a/src/views/copilot/container.vue b/src/views/copilot/container.vue index 97d3803..2bb12b8 100644 --- a/src/views/copilot/container.vue +++ b/src/views/copilot/container.vue @@ -42,6 +42,14 @@ export default { period: "日", }; }, + // mounted() { + // document.body.style.minHeight = "1024px"; + // document.body.style.minWidth = "1550px"; + // }, + // destroyed() { + // document.body.style.minHeight = "1024px"; + // document.body.style.minWidth = "1550px"; + // }, }; diff --git a/src/views/copilot/yield/index.vue b/src/views/copilot/yield/index.vue index 2bc0134..b35ed84 100644 --- a/src/views/copilot/yield/index.vue +++ b/src/views/copilot/yield/index.vue @@ -9,22 +9,22 @@
- + - + - +
- - + + + + + +
@@ -33,8 +33,9 @@ import Container from "../components/Container.vue"; import StdOutputVue from "../components/charts/StdOutput.vue"; import ChipOutputVue from "../components/charts/ChipOutput.vue"; - +import FtoInvestVue from "../components/charts/FtoInvest.vue"; import BipvOutputVue from "../components/charts/BipvOutput.vue"; +import ChipInvestVue from "../components/charts/ChipInvest.vue"; export default { name: "YieldCopilot", @@ -43,13 +44,32 @@ export default { StdOutput: StdOutputVue, ChipOutput: ChipOutputVue, BipvOutput: BipvOutputVue, + FtoInvest: FtoInvestVue, + ChipInvest: ChipInvestVue, + }, + props: { + period: { + type: String, + default: "日", + }, }, - props: {}, data() { return {}; }, - computed: {}, - methods: {}, + watch: { + period: { + handler(val) { + val && this.fetchData(val); + }, + immediate: true, + }, + }, + methods: { + fetchData(period = "日") { + console.log(`产量驾驶舱,获取${period}数据`); + this.$store.dispatch("copilot/initCopilot", { period, source: "yield" }); + }, + }, };