diff --git a/src/apis/dashboard/index.js b/src/apis/dashboard/index.js index d4476d3..6c6fb0a 100644 --- a/src/apis/dashboard/index.js +++ b/src/apis/dashboard/index.js @@ -9,7 +9,7 @@ import { POST_DASHBOARD_PRODUCT_TARGET_SETTING_API, GET_DASHBOARD_PRODUCT_TARGET_SETTING_API, GET_DASHBOARD_PRODUCT_HISTORY_API, - GET_DASHBOARD_PRODUCT_TASK_API + GET_DASHBOARD_PRODUCT_TASK_API, } from "./api"; import instance from "@/util/request"; import apihandler from "@/util/apihandler"; @@ -37,10 +37,9 @@ export const getDashboardDevice = async ({ option }) => { }; export const getDashboardOptionRealTimeData = async ({ option }) => { - const res = await instance.post( GET_DASHBOARD_REALTIME_DATA_API, { - option: parseInt(option), + const res = await instance.get(GET_DASHBOARD_REALTIME_DATA_API, { + params: { option: parseInt(option) }, }); - return apihandler(res.code, res.data, { msg: res.msg, code: res.code, @@ -91,7 +90,6 @@ export const getDashboardTemp = async ({ timeInterval, tempOption, }); - console.log(res); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, @@ -155,5 +153,4 @@ export const getDashboardProductTask = async () => { msg: res.msg, code: res.code, }); -} - +}; diff --git a/src/apis/productSetting/api.js b/src/apis/productSetting/api.js index 447190b..faf2dfe 100644 --- a/src/apis/productSetting/api.js +++ b/src/apis/productSetting/api.js @@ -2,3 +2,6 @@ export const POST_CHANGE_GROUP_VALUE_API = `api/Weight/ChangeGroupValue`; export const GET_CHECKWEIGHER_API = `/api/HistoryData/GetCheckWeigherNow`; export const POST_SETTING_TYPE_API = `/SituationRoom/SetProduct`; +export const GET_SETTING_INVENTORY_API = `/SituationRoom/GetInventory`; +export const POST_SETTING_INVENTORY_API = `/SituationRoom/SaveInventory`; +export const GET_SETTING_INVENTORY_LOG_API = `/SituationRoom/GetInventoryLog`; diff --git a/src/apis/productSetting/index.js b/src/apis/productSetting/index.js index 5dc7270..5930409 100644 --- a/src/apis/productSetting/index.js +++ b/src/apis/productSetting/index.js @@ -4,10 +4,13 @@ import { POST_CHANGE_GROUP_VALUE_API, GET_CHECKWEIGHER_API, POST_SETTING_TYPE_API, + GET_SETTING_INVENTORY_API, + POST_SETTING_INVENTORY_API, + GET_SETTING_INVENTORY_LOG_API, } from "./api"; export const postChangeGroupValue = async (data) => { - const res = await instance.post(POST_CHANGE_GROUP_VALUE_API,data); + const res = await instance.post(POST_CHANGE_GROUP_VALUE_API, data); return apihandler(res.code, res.data, { msg: res.msg, @@ -35,3 +38,37 @@ export const postProductSettingType = async (data) => { isSuccess: false, }); }; + +export const getSettingInventory = async () => { + const res = await instance.get(GET_SETTING_INVENTORY_API); + + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + isSuccess: false, + }); +}; + +export const postSettingInventory = async (data) => { + const res = await instance.post(POST_SETTING_INVENTORY_API, data); + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + isSuccess: false, + }); +}; + +export const getSettingInventoryLog = async ({ start_time, end_time }) => { + const res = await instance.get(GET_SETTING_INVENTORY_LOG_API, { + params: { + start_time, + end_time, + }, + }); + + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + isSuccess: false, + }); +}; diff --git a/src/components/chart/LiquidfillChart.vue b/src/components/chart/LiquidfillChart.vue index 62b3cc1..db0eddd 100644 --- a/src/components/chart/LiquidfillChart.vue +++ b/src/components/chart/LiquidfillChart.vue @@ -105,6 +105,18 @@ watch( { immediate: true } ); +// 新增監聽 title 變化 +watch( + () => props.title, + (newTitle) => { + if (chart.value) { + chartOption.value.title.text = newTitle; + chart.value.setOption(chartOption.value); + } + }, + { immediate: true } +); + defineExpose({ chart, }); diff --git a/src/components/customUI/Input.vue b/src/components/customUI/Input.vue index 6a0efeb..aac37e1 100644 --- a/src/components/customUI/Input.vue +++ b/src/components/customUI/Input.vue @@ -73,7 +73,7 @@ const curWidth = computed(() => { :disabled="disabled" :readonly="readonly" :required="required" - class="text-lg text-white bg-transparent w-full input input-bordered rounded-md px-3 border-info focus-within:border-info read-only:bg-base-300 read-only:text-zinc-500 read-only:border-0 read-only:focus-within:outline-0 read-only:focus:outline-0" + class="text-lg text-white bg-transparent w-full input input-bordered rounded-md px-3 border-info focus-within:border-info read-only:bg-base-300 read-only:text-zinc-300 read-only:border-0 read-only:focus-within:outline-0 read-only:focus:outline-0" /> { // formErrorMsg.value = scheme - if (scheme) { + if (scheme && scheme.fields) { formErrorMsg.value = Object.fromEntries( Object.keys(scheme.fields).map((f) => [f, ""]) ); @@ -41,9 +41,11 @@ export default function useFormErrorMessage(scheme) { }; const updateScheme = (scheme) => { - formErrorMsg.value = Object.fromEntries( - Object.keys(scheme.fields).map((f) => [f, ""]) - ); + if (scheme && scheme.fields) { + formErrorMsg.value = Object.fromEntries( + Object.keys(scheme.fields).map((f) => [f, ""]) + ); + } }; return { formErrorMsg, handleSubmit, handleErrorReset, updateScheme }; diff --git a/src/views/dashboard/components/DashboardDescriptionCard.vue b/src/views/dashboard/components/DashboardDescriptionCard.vue index ac77e8f..cf08655 100644 --- a/src/views/dashboard/components/DashboardDescriptionCard.vue +++ b/src/views/dashboard/components/DashboardDescriptionCard.vue @@ -1,30 +1,26 @@ \ No newline at end of file + diff --git a/src/views/dashboard/components/DashboardElectricity.vue b/src/views/dashboard/components/DashboardElectricity.vue index c8aa188..9e86df7 100644 --- a/src/views/dashboard/components/DashboardElectricity.vue +++ b/src/views/dashboard/components/DashboardElectricity.vue @@ -3,7 +3,7 @@ import LineChart from "@/components/chart/LineChart.vue"; import { SECOND_CHART_COLOR } from "@/constant"; import { getDashboardEnergy } from "@/apis/dashboard"; import { twMerge } from "tailwind-merge"; -import { ref, computed, onMounted, watch } from "vue"; +import { ref, computed, onMounted, watch, onUnmounted } from "vue"; import dayjs from "dayjs"; const weeks = ["週日", "週一", "週二", "週三", "週四", "週五", "週六"]; @@ -11,32 +11,30 @@ const weeks = ["週日", "週一", "週二", "週三", "週四", "週五", "週 const data = ref([]); const getEnergyData = async () => { const res = await getDashboardEnergy(); - console.log(res.data); - data.value = res.data; + if (res.isSuccess) { + data.value = res.data?.electric || []; + } else { + console.error("獲取用電量數據失敗:", res.message); + } }; -// 假資料產生器 -function generateFakeData() { - const names = ["上週", "本週"]; - const now = dayjs(); - return names.map((full_name, idx) => ({ - full_name, - data: Array.from({ length: 7 }).map((_, i) => ({ - time: now.subtract(6 - i, "day").toISOString(), - value: Math.round(Math.random() * 100 + 200 + idx * 50), // 200~350 - })), - })); -} +let timer = null; onMounted(() => { - // getEnergyData(); + getEnergyData(); + timer = setInterval(() => { + getEnergyData(); + }, 600000); // 每10分鐘 +}); - // // 每10分鐘 - // setInterval(() => { - // getEnergyData(); - // }, 600000); - - data.value = generateFakeData(); +onUnmounted(() => { + if (timer) { + clearInterval(timer); + timer = null; + } + if (electricity_chart.value && electricity_chart.value.chart) { + electricity_chart.value.chart.dispose(); + } }); const electricity_chart = ref(null); diff --git a/src/views/dashboard/components/DashboardFrozenTemp.vue b/src/views/dashboard/components/DashboardFrozenTemp.vue index 99d7015..0b43d0d 100644 --- a/src/views/dashboard/components/DashboardFrozenTemp.vue +++ b/src/views/dashboard/components/DashboardFrozenTemp.vue @@ -2,7 +2,7 @@ import LineChart from "@/components/chart/LineChart.vue"; import { SECOND_CHART_COLOR } from "@/constant"; import dayjs from "dayjs"; -import { ref, inject, onMounted, watch } from "vue"; +import { ref, onMounted, watch, onUnmounted } from "vue"; import { getDashboardTemp } from "@/apis/dashboard"; import useSearchParams from "@/hooks/useSearchParam"; @@ -55,86 +55,55 @@ const defaultChartOption = ref({ const frozen_temp_chart = ref(null); -// 假資料產生器 -function generateFakeFrozenData() { - const names = ["冷藏槽A", "冷藏槽B"]; - const now = dayjs(); - return names.map((full_name, idx) => ({ - full_name, - data: Array.from({ length: 12 }).map((_, i) => ({ - time: now.subtract(55 - i * 5, "minute").toISOString(), - value: Math.round(Math.random() * 3 + 2 + idx * 2), // 2~7度 - })), - })); -} + const data = ref([]); -const getData = async (timeInterval) => { - // showChartLoading(frozen_temp_chart.value.chart); +const getData = async () => { const res = await getDashboardTemp({ - timeInterval, // 時間間隔=>1.4.8 + timeInterval: 1, // 時間間隔=>1.4.8 tempOption: 2, // 1:即時溫度;2:冷藏溫度 }); - console.log(res); if (res.isSuccess) { - data.value = res.data?.freezer; + data.value = res.data || []; } }; -watch( - searchParams, - (newValue, oldValue) => { - if ( - newValue[intervalType] && - newValue[intervalType] !== oldValue[intervalType] - ) { - window.clearInterval(timeoutTimer.value); - getData(parseInt(newValue[intervalType])); - timeoutTimer.value = setInterval(() => { - getData(parseInt(newValue[intervalType])); - }, 60000); - } - }, - { - deep: true, +watch(data, (newValue) => { + if (newValue?.length > 0) { + frozen_temp_chart.value.chart.setOption({ + legend: { + data: newValue.map(({ full_name }) => full_name), + }, + xAxis: { + data: newValue[0]?.data.map(({ time }) => dayjs(time).format("HH:mm")), + }, + series: newValue.map(({ full_name, data: seriesData }, index) => ({ + name: full_name, + type: "line", + data: seriesData.map(({ value }) => value), + showSymbol: false, + itemStyle: { + color: SECOND_CHART_COLOR[index], + }, + })), + }); } -); +}); + +let timer = null; -watch( - data, - (newValue) => { - // clearChart(frozen_temp_chart.value.chart); - newValue.length > 0 && - frozen_temp_chart.value.chart.setOption({ - legend: { - data: newValue.map(({ full_name }) => full_name), - }, - xAxis: { - data: newValue[0]?.data.map(({ time }) => - dayjs(time).format("HH:mm") - ), - }, - series: newValue.map(({ full_name, data }, index) => ({ - name: full_name, - type: "line", - data: data.map(({ value }) => value), - showSymbol: false, - itemStyle: { - color: SECOND_CHART_COLOR[index], - }, - })), - }); - // frozen_temp_chart.value.chart.hideLoading(); - }, - { deep: true } -); -const timeoutTimer = ref(""); onMounted(() => { -// getData(1); -// timeoutTimer.value = setInterval(() => { -// getData(1); -// }, 60000); -data.value = generateFakeFrozenData(); + getData(); + timer = setInterval(() => { + getData(); + }, 60 * 1000); +}); + +onUnmounted(() => { + if (timer) { + clearInterval(timer); + timer = null; + } }); diff --git a/src/views/dashboard/components/DashboardImmediateTemp.vue b/src/views/dashboard/components/DashboardImmediateTemp.vue index 239c643..6bab240 100644 --- a/src/views/dashboard/components/DashboardImmediateTemp.vue +++ b/src/views/dashboard/components/DashboardImmediateTemp.vue @@ -2,28 +2,14 @@ import LineChart from "@/components/chart/LineChart.vue"; import { SECOND_CHART_COLOR } from "@/constant"; import dayjs from "dayjs"; -import { ref, watch, onMounted } from "vue"; +import { ref, watch, onMounted, onUnmounted } from "vue"; import useActiveBtn from "@/hooks/useActiveBtn"; import { getDashboardTemp } from "@/apis/dashboard"; import useSearchParams from "@/hooks/useSearchParam"; -import useDashboardOption from "@/hooks/useDashboardOption"; const { searchParams } = useSearchParams(); const intervalType = "immediateTemp"; -// 假資料產生器 -function generateFakeData() { - const names = ["二重釜-溫度", "調理鍋-溫度", "調理鍋-糖度"]; - const now = dayjs(); - return names.map((full_name, idx) => ({ - full_name, - data: Array.from({ length: 12 }).map((_, i) => ({ - time: now.subtract(55 - i * 5, "minute").toISOString(), - value: Math.round(Math.random() * 10 + 20 + idx * 5), // 20~35 - })), - })); -} - const other_real_temp_chart = ref(null); const defaultChartOption = ref({ tooltip: { @@ -39,10 +25,10 @@ const defaultChartOption = ref({ bottom: "0%", }, grid: { - top: "10%", + top: "5%", left: "0%", right: "0%", - bottom: "10%", + bottom: "20%", containLabel: true, }, xAxis: { @@ -72,7 +58,6 @@ const { items, changeActiveBtn, setItems, selectedBtn } = useActiveBtn(); const data = ref([]); onMounted(() => { - data.value = generateFakeData(); setItems([ { id: 1, @@ -94,58 +79,33 @@ onMounted(() => { }, ]); }); -// const getData = async (timeInterval, typeOption) => { -// // showChartLoading(other_real_temp_chart.value.chart); -// const res = await getDashboardTemp({ -// timeInterval, // 時間間隔=>1.4.8 -// tempOption: 1, // 1:即時溫度;2:冷藏溫度 -// typeOption, // 1:仙草;2:愛玉;3:紅茶 -// }); -// if (res.isSuccess) { -// data.value = res.data[selectedBtn.value.typeOption]; -// } -// }; -// const timeoutTimer = ref(""); +const getData = async (typeOption) => { + const res = await getDashboardTemp({ + timeInterval: 1, // 時間間隔=>1.4.8 + tempOption: 1, + typeOption, // 1:二重釜-溫度;2:調理鍋-溫度;3:二重釜-糖度 + }); + if (res.isSuccess) { + data.value = res.data || []; + } +}; -// watch( -// selectedBtn, -// (newValue) => { -// window.clearInterval(timeoutTimer.value); -// getData( -// parseInt(searchParams.value[intervalType] || 1), -// newValue.typeOption -// ); -// timeoutTimer.value = setInterval(() => { -// getData( -// parseInt(searchParams.value[intervalType] || 1), -// newValue.typeOption -// ); -// }, 60000); -// }, -// { -// deep: true, -// } -// ); +let timer = null; -// watch( -// searchParams, -// (newValue, oldValue) => { -// if ( -// newValue[intervalType] && -// newValue[intervalType] !== oldValue[intervalType] -// ) { -// window.clearInterval(timeoutTimer.value); -// getData(parseInt(newValue[intervalType]), selectedBtn.value.typeOption); -// timeoutTimer.value = setInterval(() => { -// getData(parseInt(newValue[intervalType]), selectedBtn.value.typeOption); -// }, 60000); -// } -// }, -// { -// deep: true, -// } -// ); +watch( + selectedBtn, + (newValue) => { + window.clearInterval(timer); + getData(newValue.key); + timer = setInterval(() => { + getData(newValue.key); + }, 60 * 1000); + }, + { + deep: true, + } +); watch(data, (newValue) => { // clearChart(other_real_temp_chart.value.chart); @@ -157,10 +117,10 @@ watch(data, (newValue) => { xAxis: { data: newValue[0]?.data.map(({ time }) => dayjs(time).format("HH:mm")), }, - series: newValue.map(({ full_name, data }, index) => ({ + series: newValue.map(({ full_name, data: seriesData }, index) => ({ name: full_name, type: "line", - data: data.map(({ value }) => value), + data: seriesData.map(({ value }) => value), showSymbol: false, itemStyle: { color: SECOND_CHART_COLOR[index], @@ -170,6 +130,13 @@ watch(data, (newValue) => { } // other_real_temp_chart.value.chart.hideLoading(); }); + +onUnmounted(() => { + if (timer) { + clearInterval(timer); + timer = null; + } +});