From 1243068fc3efbde097f1f31a1c59984d74f740ed Mon Sep 17 00:00:00 2001 From: Timi Date: Wed, 5 Aug 2026 22:29:53 +0800 Subject: [PATCH] refactor event --- src/api/CustomerAPI.ts | 85 +++++++--- .../{RegistrationEventAPI.ts => EventAPI.ts} | 17 +- src/api/EventRecordAPI.ts | 150 ++++++++++++++++++ src/api/{GaoUserAPI.ts => ManagedUserAPI.ts} | 11 +- src/api/RegistrationEventRecordAPI.ts | 95 ----------- ...rdCalendar.vue => EventRecordCalendar.vue} | 61 +++---- ...ionEventSelector.vue => EventSelector.vue} | 9 +- src/pages/customer/QuickEntryPage.vue | 29 ++-- src/pages/customer/QuickSignInPage.vue | 99 ++++++------ src/pages/management/CustomerDataCharts.vue | 131 +++++++-------- src/pages/management/CustomerDetail.vue | 15 +- src/pages/management/CustomerEdit.vue | 5 +- src/pages/management/CustomerList.vue | 9 +- ...egistrationEventEdit.vue => EventEdit.vue} | 59 +++---- ...egistrationEventList.vue => EventList.vue} | 55 +++---- ...RecordDetail.vue => EventRecordDetail.vue} | 23 +-- ...ventRecordEdit.vue => EventRecordEdit.vue} | 85 +++++----- ...ventRecordList.vue => EventRecordList.vue} | 73 ++++----- ...egistrationEventSort.vue => EventSort.vue} | 35 ++-- src/pages/management/ManagementDataCharts.vue | 99 ++++++------ src/pages/management/ManagementQrCode.vue | 5 +- src/pages/management/PermissionEdit.vue | 11 +- src/pages/management/PermissionList.vue | 3 +- src/pages/management/PermissionSettings.vue | 3 +- src/pages/management/RoleEdit.vue | 11 +- src/pages/management/RoleList.vue | 3 +- src/pages/management/RolePermissionAssign.vue | 3 +- src/pages/management/UserDetail.vue | 43 ++--- src/pages/management/UserEdit.vue | 23 +-- src/pages/management/UserList.vue | 45 +++--- src/pages/management/UserRoleAssign.vue | 47 +++--- src/pages/tabs/CustomerTab.vue | 11 +- src/pages/tabs/ManagementTab.vue | 17 +- src/router/routes/customerRoutes.ts | 7 +- src/router/routes/registrationRoutes.ts | 45 +++--- src/store/permissionSettingsStore.ts | 19 +-- src/types/Customer.ts | 2 +- src/types/EventItem.ts | 20 +++ src/types/EventRecord.ts | 113 +++++++++++++ src/types/{GaoUser.ts => ManagedUser.ts} | 3 +- src/types/RegistrationEvent.ts | 19 --- src/types/RegistrationEventRecord.ts | 92 ----------- ...istrationEventRecord.ts => eventRecord.ts} | 5 +- src/utils/imageCompression.ts | 17 +- src/utils/{gaoPermission.ts => permission.ts} | 27 ++-- src/utils/{gaoRole.ts => role.ts} | 11 +- 46 files changed, 961 insertions(+), 789 deletions(-) rename src/api/{RegistrationEventAPI.ts => EventAPI.ts} (56%) create mode 100644 src/api/EventRecordAPI.ts rename src/api/{GaoUserAPI.ts => ManagedUserAPI.ts} (67%) delete mode 100644 src/api/RegistrationEventRecordAPI.ts rename src/components/{RegistrationEventRecordCalendar.vue => EventRecordCalendar.vue} (82%) rename src/components/{RegistrationEventSelector.vue => EventSelector.vue} (85%) rename src/pages/management/{RegistrationEventEdit.vue => EventEdit.vue} (90%) rename src/pages/management/{RegistrationEventList.vue => EventList.vue} (73%) rename src/pages/management/{RegistrationEventRecordDetail.vue => EventRecordDetail.vue} (79%) rename src/pages/management/{RegistrationEventRecordEdit.vue => EventRecordEdit.vue} (85%) rename src/pages/management/{RegistrationEventRecordList.vue => EventRecordList.vue} (85%) rename src/pages/management/{RegistrationEventSort.vue => EventSort.vue} (87%) create mode 100644 src/types/EventItem.ts create mode 100644 src/types/EventRecord.ts rename src/types/{GaoUser.ts => ManagedUser.ts} (87%) delete mode 100644 src/types/RegistrationEvent.ts delete mode 100644 src/types/RegistrationEventRecord.ts rename src/utils/{registrationEventRecord.ts => eventRecord.ts} (59%) rename src/utils/{gaoPermission.ts => permission.ts} (72%) rename src/utils/{gaoRole.ts => role.ts} (82%) diff --git a/src/api/CustomerAPI.ts b/src/api/CustomerAPI.ts index 88b77d8..7857992 100644 --- a/src/api/CustomerAPI.ts +++ b/src/api/CustomerAPI.ts @@ -1,6 +1,6 @@ import { axios, type Page, type PageResult } from "timi-web"; import type { Customer, CustomerDailyStatView, CustomerGenderStatView, CustomerInviteUpdateReq, CustomerSearchReq, CustomerTrendStatReq, QuickRegisterReq } from "@/types/Customer"; -import type { RegistrationEventRecord } from "@/types/RegistrationEventRecord"; +import type { EventRecord } from "@/types/EventRecord"; const BASE_URI = "/gao/customer"; @@ -9,15 +9,26 @@ async function list(req: Page): Promise> { } async function search(req: CustomerSearchReq): Promise { - return await axios.post(`${BASE_URI}/search`, req); + const [codeMatched, nameMatched] = await Promise.all([ + req.keyword ? nullableDetailByCode(req.keyword) : undefined, + req.keyword ? nullableDetailByName(req.keyword) : undefined + ]); + return [codeMatched, nameMatched].filter((item, index, list): item is Customer => !!item && index === list.findIndex(current => current?.id === item.id)); } async function searchPage(req: Page): Promise> { - return await axios.post(`${BASE_URI}/search/page`, req); + return await axios.post(`${BASE_URI}/list`, { + ...req, + equalsExample: buildCustomerListExample(req.equalsExample) + }); } async function exportExcel(req: CustomerSearchReq): Promise { - return await axios.post(`${BASE_URI}/export`, req, { + return await axios.post(`${BASE_URI}/export`, { + index: 0, + size: 100000, + equalsExample: buildCustomerListExample(req) + }, { responseType: "blob" }); } @@ -28,15 +39,15 @@ async function detail(id: string): Promise { }); } -async function detailByCode(code: string): Promise { - return await axios.post(`${BASE_URI}/detail/code`, undefined, { +async function nullableDetailByCode(code: string): Promise { + return await axios.post(`${BASE_URI}/find/code`, undefined, { params: { code } }); } -async function nullableDetailByCode(code: string): Promise { - return await axios.post(`${BASE_URI}/detail/code/nullable`, undefined, { - params: { code } +async function nullableDetailByName(name: string): Promise { + return await axios.post(`${BASE_URI}/find/name`, undefined, { + params: { name } }); } @@ -47,11 +58,29 @@ async function invitedList(introducerCustomerId: string): Promise { } async function create(req: Customer): Promise { - return await axios.post(`${BASE_URI}/create`, req); + const id = await axios.post(`${BASE_URI}/create`, req) as unknown as string; + return { + ...req, + id + }; } -async function quickRegister(req: QuickRegisterReq): Promise { - return await axios.post(`${BASE_URI}/quick/register`, req); +async function quickRegister(req: QuickRegisterReq): Promise { + const customer = await nullableDetailByCode(req.customerCode); + if (!customer?.id) { + throw new Error("客户不存在,无法登记"); + } + const record: EventRecord = { + customerId: customer.id, + eventId: req.eventId, + remark: req.remark, + attachmentIdList: req.attachmentIdList + }; + await axios.post("/gao/event/record/create", { + ...record, + eventId: req.eventId + }); + return record; } async function update(req: Customer): Promise { @@ -64,12 +93,17 @@ async function remove(id: string): Promise { }); } -async function createInvite(req: CustomerInviteUpdateReq): Promise { - return await axios.post(`${BASE_URI}/invite/create`, req); -} - async function updateInvite(req: CustomerInviteUpdateReq): Promise { - return await axios.post(`${BASE_URI}/invite/update`, req); + if (!req.introducerCustomerId) { + await deleteInvite(req.customerId); + return; + } + return await axios.post(`${BASE_URI}/invite/save`, undefined, { + params: { + customerId: req.customerId, + introducerCustomerId: req.introducerCustomerId + } + }); } async function deleteInvite(customerId: string): Promise { @@ -79,11 +113,20 @@ async function deleteInvite(customerId: string): Promise { } async function dailyStat(req: CustomerTrendStatReq): Promise { - return await axios.post(`${BASE_URI}/stat/daily`, req); + return await axios.post(`${BASE_URI}/state/daily`, req); } async function genderStat(): Promise { - return await axios.post(`${BASE_URI}/stat/gender`); + return await axios.post(`${BASE_URI}/state/gender`); +} + +function buildCustomerListExample(req?: CustomerSearchReq): Partial { + if (!req?.introducerCustomerId) { + return {}; + } + return { + introducerCustomerId: req.introducerCustomerId + }; } export default { @@ -92,16 +135,16 @@ export default { searchPage, exportExcel, detail, - detailByCode, nullableDetailByCode, + nullableDetailByName, invitedList, create, quickRegister, update, remove, - createInvite, updateInvite, deleteInvite, dailyStat, genderStat }; + diff --git a/src/api/RegistrationEventAPI.ts b/src/api/EventAPI.ts similarity index 56% rename from src/api/RegistrationEventAPI.ts rename to src/api/EventAPI.ts index 96efee2..f340410 100644 --- a/src/api/RegistrationEventAPI.ts +++ b/src/api/EventAPI.ts @@ -1,27 +1,27 @@ import { axios, type Page, type PageResult } from "timi-web"; -import type { RegistrationEvent } from "@/types/RegistrationEvent"; +import type { EventItem } from "@/types/EventItem"; -const BASE_URI = "/gao/registration-event"; +const BASE_URI = "/gao/event"; -async function list(req: Page): Promise> { +async function list(req: Page): Promise> { return await axios.post(`${BASE_URI}/list`, req); } -async function enabledList(): Promise { - return await axios.post(`${BASE_URI}/enabled/list`); +async function enabledList(): Promise { + return await axios.post(`${BASE_URI}/list/valid`); } -async function detail(id: string): Promise { +async function detail(id: string): Promise { return await axios.post(`${BASE_URI}/detail`, undefined, { params: { id } }); } -async function create(req: RegistrationEvent): Promise { +async function create(req: EventItem): Promise { return await axios.post(`${BASE_URI}/create`, req); } -async function update(req: RegistrationEvent): Promise { +async function update(req: EventItem): Promise { return await axios.post(`${BASE_URI}/update`, req); } @@ -44,3 +44,4 @@ export default { sort, remove }; + diff --git a/src/api/EventRecordAPI.ts b/src/api/EventRecordAPI.ts new file mode 100644 index 0000000..b077d30 --- /dev/null +++ b/src/api/EventRecordAPI.ts @@ -0,0 +1,150 @@ +import { axios, type Page, type PageResult } from "timi-web"; +import type { + CustomerEventRankResponse, + CustomerEventRankView, + EventRecord, + EventRecordCalendarView, + EventRecordCreateReq, + EventRecordDailyStatView, + EventRecordListItemView, + EventRecordPage, + EventRecordPageReq, + EventRecordTrendStatReq +} from "@/types/EventRecord"; + +const BASE_URI = "/gao/event/record"; + +async function list(req: Page): Promise> { + return await axios.post(`${BASE_URI}/list`, buildRecordPage(req)); +} + +async function detail(id: string): Promise { + return await axios.post(`${BASE_URI}/detail`, undefined, { + params: { id } + }); +} + +async function rangeList(req: EventRecordPage): Promise { + const result: PageResult = await axios.post(`${BASE_URI}/list`, buildRecordPage({ + index: 0, + size: 1000, + equalsExample: req + })); + return result.list; +} + +async function calendarRangeList(req: EventRecordPage): Promise { + const result = await rangeList(req); + return result.map(item => ({ + id: item.id, + customerId: item.customerId, + customerCode: item.customer?.code || "", + customerName: item.customer?.name || "", + eventId: item.eventId, + registeredAt: item.registeredAt + })); +} + +async function rangePage(req: Page): Promise> { + const result: PageResult = await axios.post(`${BASE_URI}/list`, buildRecordPage(req)); + return { + total: result.total, + list: result.list.map(item => ({ + id: item.id, + customerId: item.customerId, + customerName: item.customer?.name || "", + customerPhotoAttachmentId: item.customer?.attachmentList?.[0]?.id, + eventId: item.eventId, + eventName: item.event?.name || "", + registeredAt: item.registeredAt + })) + }; +} + +async function rangeExport(req: EventRecordPage): Promise { + return await axios.post(`${BASE_URI}/export`, buildRecordPage({ + index: 0, + size: 100000, + equalsExample: req + }), { + responseType: "blob" + }); +} + +async function create(req: EventRecordCreateReq): Promise { + const recordList = req.customerIdList.map(customerId => ({ + customerId, + eventId: req.eventId, + remark: req.remark, + registeredAt: req.registeredAt, + attachmentIdList: req.attachmentIdList + })); + for (const record of recordList) { + await axios.post(`${BASE_URI}/create`, record); + } + return recordList; +} + +async function update(req: EventRecord): Promise { + await axios.post(`${BASE_URI}/update`, req); +} + +async function remove(id: string): Promise { + await axios.post(`${BASE_URI}/delete`, undefined, { + params: { id } + }); +} + +async function customerRegistrationRank(req?: Partial): Promise { + const result: PageResult = await axios.post(`${BASE_URI}/rank`, buildRecordPage({ + index: 0, + size: 100, + equalsExample: req + })); + return result.list.map(item => ({ + rank: item.rank, + customerId: item.customerId, + customerCode: item.customer?.code || "", + customerName: item.customer?.name || "", + customerPhotoAttachmentId: item.customer?.attachmentList?.[0]?.id, + totalEventDays: item.totalEventDays, + totalEventCount: item.totalEventCount, + recentContinuousEventDays: item.recentContinuousEventDays, + latestRegisteredAt: item.latestRegisteredAt + })); +} + +async function allCustomerEventDailyStat(req: EventRecordTrendStatReq): Promise { + void req; + return []; +} + +function buildRecordPage(req: Page | Page>): EventRecordPageReq { + const equalsExample = req.equalsExample || {}; + const eventIdList = "eventIdList" in equalsExample ? equalsExample.eventIdList : undefined; + const singleEventId = "eventId" in equalsExample ? equalsExample.eventId : undefined; + return { + index: req.index, + size: req.size, + customerId: equalsExample.customerId, + eventIdList: eventIdList || (singleEventId ? [singleEventId] : undefined), + keyword: "keyword" in equalsExample ? equalsExample.keyword : undefined, + beginAt: "beginAt" in equalsExample ? equalsExample.beginAt : undefined, + endAt: "endAt" in equalsExample ? equalsExample.endAt : undefined + }; +} + +export default { + list, + detail, + rangeList, + calendarRangeList, + rangePage, + rangeExport, + create, + update, + remove, + customerRegistrationRank, + allCustomerEventDailyStat +}; + diff --git a/src/api/GaoUserAPI.ts b/src/api/ManagedUserAPI.ts similarity index 67% rename from src/api/GaoUserAPI.ts rename to src/api/ManagedUserAPI.ts index 21733bc..f7525d7 100644 --- a/src/api/GaoUserAPI.ts +++ b/src/api/ManagedUserAPI.ts @@ -1,23 +1,23 @@ import { axios, type Page, type PageResult, type Role } from "timi-web"; -import type { GaoUser } from "@/types/GaoUser"; +import type { ManagedUser } from "@/types/ManagedUser"; const BASE_URI = "/gao/user"; -async function list(req: Page): Promise> { +async function list(req: Page): Promise> { return await axios.post(`${BASE_URI}/list`, req); } -async function detail(id: string): Promise { +async function detail(id: string): Promise { return await axios.post(`${BASE_URI}/detail`, undefined, { params: { id } }); } -async function create(req: GaoUser): Promise { +async function create(req: ManagedUser): Promise { return await axios.post(`${BASE_URI}/create`, req); } -async function update(req: GaoUser): Promise { +async function update(req: ManagedUser): Promise { return await axios.post(`${BASE_URI}/update`, req); } @@ -39,3 +39,4 @@ export default { remove, roleList }; + diff --git a/src/api/RegistrationEventRecordAPI.ts b/src/api/RegistrationEventRecordAPI.ts deleted file mode 100644 index e5bd3fa..0000000 --- a/src/api/RegistrationEventRecordAPI.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { axios, type Page, type PageResult } from "timi-web"; -import type { - CustomerRegisterStatView, - CustomerRegistrationRankView, - RegistrationEventRecordCalendarView, - RegistrationEventRecord, - RegistrationEventRecordCreateReq, - RegistrationEventRecordDailyStatView, - RegistrationEventRecordListItemView, - RegistrationEventRecordRangeReq, - RegistrationEventRecordStatReq, - RegistrationEventRecordTrendStatReq -} from "@/types/RegistrationEventRecord"; - -const BASE_URI = "/gao/registration-event-record"; - -async function list(req: Page): Promise> { - return await axios.post(`${BASE_URI}/list`, req); -} - -async function detail(id: string): Promise { - return await axios.post(`${BASE_URI}/detail`, undefined, { - params: { id } - }); -} - -async function rangeList(req: RegistrationEventRecordRangeReq): Promise { - return await axios.post(`${BASE_URI}/range/list`, req); -} - -async function calendarRangeList(req: RegistrationEventRecordRangeReq): Promise { - return await axios.post(`${BASE_URI}/range/calendar/list`, req); -} - -async function rangePage(req: Page): Promise> { - return await axios.post(`${BASE_URI}/range/page`, req); -} - -async function rangeExport(req: RegistrationEventRecordRangeReq): Promise { - return await axios.post(`${BASE_URI}/range/export`, req, { - responseType: "blob" - }); -} - - -async function create(req: RegistrationEventRecordCreateReq): Promise { - return await axios.post(`${BASE_URI}/create`, req); -} - -async function update(req: RegistrationEventRecord): Promise { - await axios.post(`${BASE_URI}/update`, req); -} - -async function remove(id: string): Promise { - await axios.post(`${BASE_URI}/delete`, undefined, { - params: { id } - }); -} - -async function customerRangeStat(req: RegistrationEventRecordStatReq): Promise { - return await axios.post(`${BASE_URI}/customer/range/stat`, req); -} - -async function allCustomerRangeStat(req: RegistrationEventRecordStatReq): Promise { - return await axios.post(`${BASE_URI}/all-customer/range/stat`, req); -} - -async function customerRegistrationRank(req?: Partial): Promise { - return await axios.post(`${BASE_URI}/customer/registration-rank`, req); -} - -async function customerRegistrationEventDailyStat(req: RegistrationEventRecordTrendStatReq): Promise { - return await axios.post(`${BASE_URI}/customer/registration-event/daily/stat`, req); -} - -async function allCustomerRegistrationEventDailyStat(req: RegistrationEventRecordTrendStatReq): Promise { - return await axios.post(`${BASE_URI}/all-customer/registration-event/daily/stat`, req); -} - -export default { - list, - detail, - rangeList, - calendarRangeList, - rangePage, - rangeExport, - create, - update, - remove, - customerRangeStat, - allCustomerRangeStat, - customerRegistrationRank, - customerRegistrationEventDailyStat, - allCustomerRegistrationEventDailyStat -}; diff --git a/src/components/RegistrationEventRecordCalendar.vue b/src/components/EventRecordCalendar.vue similarity index 82% rename from src/components/RegistrationEventRecordCalendar.vue rename to src/components/EventRecordCalendar.vue index 21f57a4..d03d9c9 100644 --- a/src/components/RegistrationEventRecordCalendar.vue +++ b/src/components/EventRecordCalendar.vue @@ -14,12 +14,12 @@