diff --git a/src/api/StoreChartAPI.ts b/src/api/StoreChartAPI.ts index 80e3d53..ec357e6 100644 --- a/src/api/StoreChartAPI.ts +++ b/src/api/StoreChartAPI.ts @@ -1,30 +1,48 @@ import { axios } from "timi-web"; +import EventAPI from "@/api/EventAPI"; +import StoreAPI from "@/api/StoreAPI"; import type { CustomerDailyStatView, CustomerGenderStatView } from "@/types/Customer"; -import type { StoreChartReq, StoreEventRecordCalendarView, StoreEventRecordDailyStatView, StoreEventRecordNumberValueDailyStatView } from "@/types/Store"; +import type { EventItem } from "@/types/EventItem"; +import type { StoreBusinessDay, StoreChartReq, StoreEventRecordCalendarView, StoreEventRecordDailyStatView, StoreEventRecordNumberValueDailyStatView } from "@/types/Store"; +import { getStoreChartCache } from "@/utils/storeChartCache"; import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store"; const BASE_URI = "/gao/store/chart"; async function customerDailyStat(req: StoreChartReq): Promise { - return await axios.post(`${BASE_URI}/customer/daily`, withCurrentStoreId(req)); + const request = withCurrentStoreId(req); + return await getStoreChartCache(`customer-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/customer/daily`, request)); } async function customerGenderStat(): Promise { - return await axios.post(`${BASE_URI}/customer/gender`, undefined, { - params: { storeId: getCurrentStoreId() } - }); + const storeId = getCurrentStoreId(); + return await getStoreChartCache(`customer-gender:${storeId}`, async () => await axios.post(`${BASE_URI}/customer/gender`, undefined, { + params: { storeId } + })); } async function eventRecordDailyStat(req: StoreChartReq): Promise { - return await axios.post(`${BASE_URI}/event/record/daily`, withCurrentStoreId(req)); + const request = withCurrentStoreId(req); + return await getStoreChartCache(`event-record-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/daily`, request)); } async function eventRecordNumberValueDailyStat(req: StoreChartReq): Promise { - return await axios.post(`${BASE_URI}/event/record/number-value/daily`, withCurrentStoreId(req)); + const request = withCurrentStoreId(req); + return await getStoreChartCache(`event-record-number-value-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/number-value/daily`, request)); } async function eventRecordCalendar(req: StoreChartReq): Promise { - return await axios.post(`${BASE_URI}/event/record/calendar`, withCurrentStoreId(req)); + const request = withCurrentStoreId(req); + return await getStoreChartCache(`event-record-calendar:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/calendar`, request)); +} + +async function listValidEvents(): Promise { + const storeId = getCurrentStoreId(); + return await getStoreChartCache(`valid-events:${storeId}`, async () => await EventAPI.listValid()); +} + +async function businessDayCalendar(storeId: string, beginDateValue: number, endDateValue: number): Promise { + return await getStoreChartCache(`business-day-calendar:${storeId}:${beginDateValue}:${endDateValue}`, async () => await StoreAPI.businessDayCalendar(storeId, beginDateValue, endDateValue)); } export default { @@ -32,5 +50,7 @@ export default { customerGenderStat, eventRecordDailyStat, eventRecordNumberValueDailyStat, - eventRecordCalendar + eventRecordCalendar, + listValidEvents, + businessDayCalendar }; diff --git a/src/pages/store/component/StoreChartSummary.vue b/src/pages/store/component/StoreChartSummary.vue index ea3c8d5..a2892ae 100644 --- a/src/pages/store/component/StoreChartSummary.vue +++ b/src/pages/store/component/StoreChartSummary.vue @@ -9,7 +9,6 @@