de8956f8
杨鑫
平台端 门店,菜单,角色
|
1
|
import { createApiClient } from "../lib/apiClient";
|
6ce07406
杨鑫
提交
|
2
|
import { authorizedPostBlobDownload, authorizedPostMultipartJson } from "../lib/batchFileHttp";
|
ef6b3255
杨鑫
修改BUG
|
3
4
5
6
7
8
9
|
import {
normalizeLocationFromApi,
type LocationCreateInput,
type LocationDto,
type LocationGetListInput,
type LocationUpdateInput,
type PagedResultDto,
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
} from "../types/location";
const api = createApiClient({
// 如果项目后续接入登录,可在这里加 token 获取逻辑
getToken: () => {
try {
return localStorage.getItem("access_token") ?? localStorage.getItem("token") ?? null;
} catch {
return null;
}
},
});
/**
* ABP Conventional Controller 默认路由通常为:
* - GET /api/app/location
* - POST /api/app/location
* 这里按该约定实现;如果后端实际路由不同,以 Swagger 为准调整 path。
*/
|
ef6b3255
杨鑫
修改BUG
|
29
30
31
32
33
|
function trimOrNullHours(v: string | null | undefined): string | null {
const t = (v ?? "").trim();
return t ? t : null;
}
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
34
|
export async function getLocations(input: LocationGetListInput, signal?: AbortSignal): Promise<PagedResultDto<LocationDto>> {
|
ef6b3255
杨鑫
修改BUG
|
35
|
const raw = await api.requestJson<PagedResultDto<LocationDto> & { items?: unknown[]; Items?: unknown[] }>({
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
36
37
38
39
40
41
42
43
44
45
46
47
48
|
path: "/location",
method: "GET",
query: {
SkipCount: input.skipCount,
MaxResultCount: input.maxResultCount,
Sorting: input.sorting,
Keyword: input.keyword,
Partner: input.partner,
GroupName: input.groupName,
State: input.state,
},
signal,
});
|
ef6b3255
杨鑫
修改BUG
|
49
50
51
|
const itemsRaw = raw.items ?? raw.Items ?? [];
const items = (Array.isArray(itemsRaw) ? itemsRaw : []).map((x) => normalizeLocationFromApi(x));
return { ...raw, items, totalCount: raw.totalCount ?? (raw as { TotalCount?: number }).TotalCount ?? items.length };
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
52
53
54
|
}
export async function createLocation(input: LocationCreateInput): Promise<LocationDto> {
|
ef6b3255
杨鑫
修改BUG
|
55
|
const raw = await api.requestJson<unknown>({
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
56
57
58
|
path: "/location",
method: "POST",
body: {
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
partner: input.partner,
groupName: input.groupName,
locationCode: input.locationCode,
locationName: input.locationName,
street: input.street,
city: input.city,
stateCode: input.stateCode,
country: input.country,
zipCode: input.zipCode,
phone: input.phone,
email: input.email,
latitude: input.latitude,
longitude: input.longitude,
state: input.state ?? true,
|
ef6b3255
杨鑫
修改BUG
|
73
|
operatingHours: trimOrNullHours(input.operatingHours ?? undefined),
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
74
75
|
},
});
|
ef6b3255
杨鑫
修改BUG
|
76
|
return normalizeLocationFromApi(raw);
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
77
78
79
80
81
82
83
84
|
}
/**
* ABP Conventional Controller 的 UpdateAsync 常见路由为:
* - PUT /api/app/location/{id}
* 以 Swagger 为准;若后端使用其它形式(如 /location?id=xxx),在此调整即可。
*/
export async function updateLocation(id: string, input: LocationUpdateInput): Promise<LocationDto> {
|
ef6b3255
杨鑫
修改BUG
|
85
|
const raw = await api.requestJson<unknown>({
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
path: `/location/${encodeURIComponent(id)}`,
method: "PUT",
body: {
partner: input.partner,
groupName: input.groupName,
locationCode: input.locationCode,
locationName: input.locationName,
street: input.street,
city: input.city,
stateCode: input.stateCode,
country: input.country,
zipCode: input.zipCode,
phone: input.phone,
email: input.email,
latitude: input.latitude,
longitude: input.longitude,
state: input.state ?? true,
|
ef6b3255
杨鑫
修改BUG
|
103
|
operatingHours: trimOrNullHours(input.operatingHours ?? undefined),
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
104
105
|
},
});
|
ef6b3255
杨鑫
修改BUG
|
106
|
return normalizeLocationFromApi(raw);
|
de8956f8
杨鑫
平台端 门店,菜单,角色
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
}
/**
* ABP Conventional Controller 的 DeleteAsync 常见路由为:
* - DELETE /api/app/location/{id}
* 以 Swagger 为准;若后端路由不同,在此调整 path。
*/
export async function deleteLocation(id: string): Promise<void> {
await api.requestJson<unknown>({
path: `/location/${encodeURIComponent(id)}`,
method: "DELETE",
});
}
|
63289723
杨鑫
提交
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/** 与列表筛选一致,用于模板下载外的 Excel 全量导出(不含分页)。 */
export type LocationExportQueryInput = {
sorting?: string;
keyword?: string;
partner?: string;
groupName?: string;
state?: boolean;
};
export type LocationBatchImportResultDto = {
successCount: number;
failCount: number;
skippedEmptyRows?: number;
errors?: Array<{
rowNumber?: number;
locationCode?: string;
message?: string;
}>;
};
export type LocationBulkUpdateItemVo = {
id: string;
partner?: string | null;
groupName?: string | null;
locationName: string;
street?: string | null;
city?: string | null;
stateCode?: string | null;
country?: string | null;
zipCode?: string | null;
phone?: string | null;
email?: string | null;
latitude?: number | null;
longitude?: number | null;
state?: boolean;
};
export type LocationBulkUpdateResultDto = {
successCount: number;
failCount: number;
errors?: Array<{ rowNumber?: number; id?: string; message?: string }>;
};
export async function downloadLocationImportTemplate(signal?: AbortSignal): Promise<void> {
|
6ce07406
杨鑫
提交
|
165
|
await authorizedPostBlobDownload({
|
63289723
杨鑫
提交
|
166
167
168
169
170
171
172
|
path: "/location/download-location-import-template",
defaultFileName: "Location-Manager-template.xlsx",
signal,
});
}
export async function exportLocationsExcel(input: LocationExportQueryInput, signal?: AbortSignal): Promise<void> {
|
6ce07406
杨鑫
提交
|
173
|
await authorizedPostBlobDownload({
|
63289723
杨鑫
提交
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
path: "/location/export-locations-excel",
query: {
Sorting: input.sorting,
Keyword: input.keyword,
Partner: input.partner,
GroupName: input.groupName,
State: input.state,
},
defaultFileName: "locations-export.xlsx",
signal,
});
}
export async function importLocationsBatch(file: File, signal?: AbortSignal): Promise<LocationBatchImportResultDto> {
return authorizedPostMultipartJson<LocationBatchImportResultDto>({
path: "/location/import-locations-batch",
fieldName: "file",
file,
signal,
});
}
export async function updateLocationsBulk(
body: { items: LocationBulkUpdateItemVo[] },
): Promise<LocationBulkUpdateResultDto> {
|
6ce07406
杨鑫
提交
|
199
|
// ABP:`UpdateLocationsBulkAsync` → `locations-bulk`(勿写 `update-locations-bulk`)
|
63289723
杨鑫
提交
|
200
|
return api.requestJson<LocationBulkUpdateResultDto>({
|
6ce07406
杨鑫
提交
|
201
|
path: "/location/locations-bulk",
|
63289723
杨鑫
提交
|
202
203
204
205
|
method: "PUT",
body,
});
}
|