-
安全庫存量: {{ inventory }} 頓
-
目標庫存量: {{ targetInventory }} 頓
-
{{ updateTime }}
+
+
+
安全存量: {{ safety_stock }} 頓
+
目前存量: {{ current_stock }} 頓
+
{{ updateTime }}
\ 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;
+ }
+});
diff --git a/src/views/dashboard/components/DashboardProduct.vue b/src/views/dashboard/components/DashboardProduct.vue
index bb11d45..00d1d1f 100644
--- a/src/views/dashboard/components/DashboardProduct.vue
+++ b/src/views/dashboard/components/DashboardProduct.vue
@@ -1,51 +1,29 @@
@@ -53,30 +31,13 @@ onMounted(() => {
原醋即時庫存量
-
-
@@ -86,9 +47,8 @@ onMounted(() => {
v-for="(card, index) in descriptionCards"
:key="index"
:title="card.title"
- :inventory="card.inventory"
- :targetInventory="card.targetInventory"
- :lastIncrease="card.lastIncrease"
+ :safety_stock="card.safety_stock"
+ :current_stock="card.current_stock"
:updateTime="card.updateTime"
/>
diff --git a/src/views/productSetting/components/InventorySettingAddModal.vue b/src/views/productSetting/components/InventorySettingAddModal.vue
index f0715f5..e4e3696 100644
--- a/src/views/productSetting/components/InventorySettingAddModal.vue
+++ b/src/views/productSetting/components/InventorySettingAddModal.vue
@@ -1,5 +1,5 @@
-
-
原醋庫存列表
-
-
-
-
-
-
+
+