59e51671
“wangming”
1
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
165
166
167
168
169
170
171
|
import { fetchWithOfflineCache } from '../utils/sqliteSync'
/** GET /api/app/us-app-auth/my-profile → UsAppMyProfileOutputDto */
export interface UsAppMyProfileOutputDto {
fullName: string
email: string
phone: string
employeeId: string
roleDisplay: string
primaryRoleCode: string | null
}
export interface UsAppChangePasswordInput {
currentPassword: string
newPassword: string
confirmNewPassword: string
}
/** GET /api/app/us-app-auth/location-detail/{locationId} */
export interface UsAppLocationDetailOutputDto {
locationId: string
locationName: string
fullAddress: string
storePhone: string
operatingHours: string
managerName: string
managerPhone: string
}
export type { UsAppBoundLocationDto }
export interface UsAppLoginInput {
email: string
password: string
uuid?: string
code?: string
}
export interface UsAppLoginOutputDto {
token: string
refreshToken: string
locations: UsAppBoundLocationDto[]
}
function normalizeLocation(raw: Record<string, unknown>): UsAppBoundLocationDto {
return {
id: String(raw.id ?? raw.Id ?? ''),
locationCode: String(raw.locationCode ?? raw.LocationCode ?? ''),
locationName: String(raw.locationName ?? raw.LocationName ?? ''),
fullAddress: String(raw.fullAddress ?? raw.FullAddress ?? ''),
state: raw.state !== false && raw.State !== false,
}
}
function normalizeLoginOutput(raw: unknown): UsAppLoginOutputDto {
const o = raw as Record<string, unknown>
const locs = o.locations ?? o.Locations
const arr = Array.isArray(locs) ? locs : []
return {
token: String(o.token ?? o.Token ?? ''),
refreshToken: String(o.refreshToken ?? o.RefreshToken ?? ''),
locations: arr.map((x) => normalizeLocation(x as Record<string, unknown>)),
}
}
function normalizeLocationList(raw: unknown): UsAppBoundLocationDto[] {
const arr = Array.isArray(raw) ? raw : []
return arr.map((x) => normalizeLocation(x as Record<string, unknown>))
}
/** POST /api/app/us-app-auth/login(401 不触发全局跳转) */
export async function usAppLogin(input: UsAppLoginInput): Promise<UsAppLoginOutputDto> {
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/login',
method: 'POST',
skipUnauthorizedRedirect: true,
data: {
email: input.email.trim(),
password: input.password,
...(input.uuid ? { uuid: input.uuid } : {}),
...(input.code != null ? { code: input.code } : {}),
},
})
return normalizeLoginOutput(raw)
}
/** GET /api/app/us-app-auth/my-locations */
export async function usAppFetchMyLocations(): Promise<UsAppBoundLocationDto[]> {
return fetchWithOfflineCache('auth', 'my-locations', async () => {
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/my-locations',
method: 'GET',
auth: true,
})
return normalizeLocationList(raw)
})
}
function normalizeMyProfile(raw: unknown): UsAppMyProfileOutputDto {
const o = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
const pr = o.primaryRoleCode ?? o.PrimaryRoleCode
return {
fullName: String(o.fullName ?? o.FullName ?? ''),
email: String(o.email ?? o.Email ?? ''),
phone: String(o.phone ?? o.Phone ?? ''),
employeeId: String(o.employeeId ?? o.EmployeeId ?? ''),
roleDisplay: String(o.roleDisplay ?? o.RoleDisplay ?? ''),
primaryRoleCode: pr == null || pr === '' ? null : String(pr),
}
}
/** GET /api/app/us-app-auth/my-profile */
export async function usAppFetchMyProfile(): Promise<UsAppMyProfileOutputDto> {
return fetchWithOfflineCache('auth', 'my-profile', async () => {
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/my-profile',
method: 'GET',
auth: true,
})
return normalizeMyProfile(unwrapIfNeeded(raw))
})
}
function unwrapIfNeeded(raw: unknown): unknown {
if (raw == null || typeof raw !== 'object') return raw
const o = raw as Record<string, unknown>
if ('result' in o && o.result !== undefined) return o.result
if (o.data !== undefined) return o.data
if (o.Data !== undefined) return o.Data
return raw
}
function normalizeLocationDetail(raw: unknown): UsAppLocationDetailOutputDto {
const o = (unwrapIfNeeded(raw) ?? {}) as Record<string, unknown>
return {
locationId: String(o.locationId ?? o.LocationId ?? ''),
locationName: String(o.locationName ?? o.LocationName ?? ''),
fullAddress: String(o.fullAddress ?? o.FullAddress ?? ''),
storePhone: String(o.storePhone ?? o.StorePhone ?? ''),
operatingHours: String(o.operatingHours ?? o.OperatingHours ?? ''),
managerName: String(o.managerName ?? o.ManagerName ?? ''),
managerPhone: String(o.managerPhone ?? o.ManagerPhone ?? ''),
}
}
/**
* GET /api/app/us-app-auth/location-detail/{locationId}
* 文档:locationId 为路径参数;需当前用户已绑定该门店。
*/
export async function usAppFetchLocationDetail(locationId: string): Promise<UsAppLocationDetailOutputDto> {
const id = (locationId || '').trim()
return fetchWithOfflineCache('auth', `location-detail:${id}`, async () => {
const raw = await usAppApiRequest<unknown>({
path: `/api/app/us-app-auth/location-detail/${encodeURIComponent(id)}`,
method: 'GET',
auth: true,
})
return normalizeLocationDetail(raw)
})
}
/** POST /api/app/us-app-auth/change-password */
|
540ac0e3
杨鑫
前端修改bug
|
172
173
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
function normalizeCompanyOption(raw: Record<string, unknown>): AuthScopeCompanyOption {
return {
id: String(raw.id ?? raw.Id ?? '').trim(),
partnerName: String(raw.partnerName ?? raw.PartnerName ?? '').trim(),
state: raw.state !== false && raw.State !== false,
}
}
function normalizeRegionOption(raw: Record<string, unknown>): AuthScopeRegionOption {
return {
id: String(raw.id ?? raw.Id ?? '').trim(),
groupName: String(raw.groupName ?? raw.GroupName ?? '').trim(),
partnerId: String(raw.partnerId ?? raw.PartnerId ?? '').trim(),
state: raw.state !== false && raw.State !== false,
}
}
function normalizeScopeLocationOption(raw: Record<string, unknown>): AuthScopeLocationOption {
return {
id: String(raw.id ?? raw.Id ?? '').trim(),
locationCode: String(raw.locationCode ?? raw.LocationCode ?? '').trim(),
locationName: String(raw.locationName ?? raw.LocationName ?? '').trim(),
fullAddress: String(raw.fullAddress ?? raw.FullAddress ?? '').trim(),
state: raw.state !== false && raw.State !== false,
partnerId: String(raw.partnerId ?? raw.PartnerId ?? '').trim() || undefined,
groupId: String(raw.groupId ?? raw.GroupId ?? '').trim() || undefined,
groupName: String(raw.groupName ?? raw.GroupName ?? '').trim() || undefined,
}
}
function normalizeScopeLocationList(raw: unknown): AuthScopeLocationOption[] {
const arr = Array.isArray(raw) ? raw : []
return arr
.map((x) => normalizeScopeLocationOption(x as Record<string, unknown>))
.filter((x) => x.id)
}
/** GET /api/app/us-app-auth/admin-scope-companies */
export async function usAppFetchAdminScopeCompanies(): Promise<AuthScopeCompanyOption[]> {
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/admin-scope-companies',
method: 'GET',
auth: true,
})
const list = unwrapApiPayload<unknown>(raw)
const arr = Array.isArray(list) ? list : []
return arr
.map((x) => normalizeCompanyOption(x as Record<string, unknown>))
.filter((x) => x.id)
}
/** GET /api/app/us-app-auth/admin-scope-regions */
export async function usAppFetchAdminScopeRegions(partnerId: string): Promise<AuthScopeRegionOption[]> {
const pid = partnerId.trim()
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/admin-scope-regions',
method: 'GET',
auth: true,
data: { partnerId: pid },
})
const list = unwrapApiPayload<unknown>(raw)
const arr = Array.isArray(list) ? list : []
return arr
.map((x) => normalizeRegionOption(x as Record<string, unknown>))
.filter((x) => x.id)
}
/** GET /api/app/us-app-auth/admin-scope-locations */
export async function usAppFetchAdminScopeLocations(
partnerId: string,
groupId: string,
): Promise<AuthScopeLocationOption[]> {
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/admin-scope-locations',
method: 'GET',
auth: true,
data: {
partnerId: partnerId.trim(),
groupId: groupId.trim(),
},
})
return normalizeScopeLocationList(unwrapApiPayload(raw))
}
/** POST /api/app/us-app-auth/select-admin-scope-location */
export async function usAppSelectAdminScopeLocation(
input: UsAppSelectAdminScopeLocationInput,
): Promise<AuthScopeSelectLocationOutput> {
const raw = await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/select-admin-scope-location',
method: 'POST',
auth: true,
data: {
partnerId: input.partnerId.trim(),
groupId: input.groupId.trim(),
locationId: input.locationId.trim(),
},
})
const o = (unwrapApiPayload(raw) ?? {}) as Record<string, unknown>
const locRaw = (o.location ?? o.Location ?? {}) as Record<string, unknown>
return {
partnerId: String(o.partnerId ?? o.PartnerId ?? '').trim(),
partnerName: String(o.partnerName ?? o.PartnerName ?? '').trim(),
groupId: String(o.groupId ?? o.GroupId ?? '').trim(),
groupName: String(o.groupName ?? o.GroupName ?? '').trim(),
location: normalizeLocation(locRaw),
}
}
|
59e51671
“wangming”
1
|
281
282
283
284
285
286
287
288
289
290
291
292
|
export async function usAppChangePassword(input: UsAppChangePasswordInput): Promise<void> {
await usAppApiRequest<unknown>({
path: '/api/app/us-app-auth/change-password',
method: 'POST',
auth: true,
data: {
currentPassword: input.currentPassword,
newPassword: input.newPassword,
confirmNewPassword: input.confirmNewPassword,
},
})
}
|