Files
crawler-plugin/admin-frontend-vue/src/pages/shop/shop-manage-api.ts
T
huangzd1997 29641e20a7 task-95(店铺中心): 实现店铺删除确认
新增 shop-manage-delete.ts(删除确认文案 + 删除后目标页回退) 并在
shop-manage-api.ts 增加 deleteShopManage(DELETE /api/admin/shop-manages/{id})。

TDD: task-95.test.ts 8 用例先 RED 后 GREEN。
2026-09-05 16:50:16 +08:00

81 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 店铺列表/分组/新增/编辑/凭证适配(任务 88-93):/api/admin/shop-manages 系端点 + 归一与解析。 */
import { http } from '@/api/http'
import { unwrap } from '@/api/envelope'
import { parseShopManagePage, toShopSummary } from './shop-manage-model.ts'
import { parseShopManageGroups } from './shop-group-model.ts'
import { toShopCredential } from './shop-credential-model.ts'
import {
normalizeShopListParams,
toShopManagePageQuery,
type ShopCredential,
type ShopGroupOption,
type ShopManageListParams,
type ShopPageResult,
type ShopSummary,
} from './shop-dto.ts'
import {
toShopManageCreateRequest,
toShopManageUpdateRequest,
validateShopManageForm,
type ShopManageFormValues,
} from './shop-manage-form-model.ts'
export const SHOP_MANAGE_ENDPOINT = '/api/admin/shop-manages'
export async function fetchShopManageList(params: Partial<ShopManageListParams> = {}): Promise<ShopPageResult> {
const normalized = normalizeShopListParams(params)
const { data } = await http.get<unknown>(SHOP_MANAGE_ENDPOINT, { params: toShopManagePageQuery(normalized) })
return parseShopManagePage(data)
}
export const SHOP_MANAGE_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
/** 加载店铺分组下拉选项(超级管理员取全部,普通管理员由后端限定可访问分组)。 */
export async function fetchShopManageGroups(): Promise<ShopGroupOption[]> {
const { data } = await http.get<unknown>(SHOP_MANAGE_GROUPS_ENDPOINT)
return parseShopManageGroups(data)
}
/** 提交新增店铺:先校验(失败抛首条错误不发请求),POST /api/admin/shop-manages,解析返回记录。 */
export async function submitCreateShopManage(form: ShopManageFormValues, createdById: number): Promise<ShopSummary> {
const { valid, errors } = validateShopManageForm(form)
if (!valid) {
throw new Error(Object.values(errors)[0] || '店铺表单校验未通过')
}
const { data } = await http.post<unknown>(SHOP_MANAGE_ENDPOINT, toShopManageCreateRequest(form, createdById))
const item = toShopSummary(unwrap<unknown>(data))
if (!item) {
throw new Error('新增店铺响应异常:未返回有效记录')
}
return item
}
/** 提交编辑店铺:先校验(失败抛首条错误不发请求)PUT /api/admin/shop-manages/{id}。 */
export async function submitUpdateShopManage(id: number, form: ShopManageFormValues): Promise<ShopSummary> {
const { valid, errors } = validateShopManageForm(form)
if (!valid) {
throw new Error(Object.values(errors)[0] || '店铺表单校验未通过')
}
const { data } = await http.put<unknown>(`${SHOP_MANAGE_ENDPOINT}/${id}`, toShopManageUpdateRequest(form))
const item = toShopSummary(unwrap<unknown>(data))
if (!item) {
throw new Error('更新店铺响应异常:未返回有效记录')
}
return item
}
/** 读取店铺明文凭据:GET /api/admin/shop-manages/{id}/credential?shop_name=…;明文仅在内存短时使用。 */
export async function fetchShopCredential(id: number, shopName: string): Promise<ShopCredential> {
const { data } = await http.get<unknown>(`${SHOP_MANAGE_ENDPOINT}/${id}/credential`, { params: { shop_name: shopName } })
const credential = toShopCredential(unwrap<unknown>(data))
if (!credential) {
throw new Error('读取店铺凭证响应异常:未返回有效记录')
}
return credential
}
/** 删除店铺:DELETE /api/admin/shop-manages/{id};成功后由调用方按目标页刷新。 */
export async function deleteShopManage(id: number): Promise<void> {
await http.delete<unknown>(`${SHOP_MANAGE_ENDPOINT}/${id}`)
}