Files
crawler-plugin/admin-frontend-vue/src/pages/shop/shop-manage-api.ts
T
huangzd1997 79b6f76654 fix(jd-database): 亚马逊侧分组下拉按平台归属过滤——京东档组不再漏进亚马逊侧(2026-11-22 用户口径「京东创建的分组就归属京东 下拉就只能显示京东分组管理的 亚马逊的也是同理」)
- shop-manage-api.ts::fetchShopManageGroups / dedupe-total-api.ts::fetchDedupeTotalGroups 恒带 platform=amazon(company_id 条件透传不变,后端 listGroups 本就支持该参数,零后端改动)——查询ASIN/跟价/去重/外观专利清理 4 个亚马逊域页面的分组下拉此前会把京东-团队/测试1111 等 jd 档组漏进来
- 京东侧无需改动:三条建组路径(分组管理页按平台 tab、京东分类弹窗直建恒 jd、后端缺省 amazon)打档正确,JdCategoryScopeService.retainJdPlatformGroups 平台闸已在线上(本轮云助手只读探针实证:测试1111=公司4阿华66 11-18 京东档建的合法工作组;admin 平台超管看所有、公司超管看公司下所有=现行口径,用户拍板维持)
- 测试:新增 tests/group-dropdown-platform-scope.test.ts(恒 amazon+company_id 透传不丢+分组管理页仍跟平台 tab 反向钉);company-tab-wiring.test.ts 精确行钉同步;source-pin-ledger.json 重生成(+1 文件/+2 例/+2 钉,delta 仅本窗)
- 验证:vue-tsc rc=0;后管全量 node --test 1959/1959 绿;fast 闸后管面 9 格全绿(分 8.8,账本 2026-11-22T16:1x);客户端/用户端红格为另窗在飞件非本笔
2026-11-22 16:19:43 +08:00

89 lines
4.4 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)
// normalizeShopListParams 与 toShopManagePageQuery 都是白名单构造(不点名 companyId),
// 所以公司值只能从原始 params 读:写成 normalized.companyId 是 TS 绿、运行时恒 undefined。
const query = toShopManagePageQuery(normalized)
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get<unknown>(SHOP_MANAGE_ENDPOINT, { params: query })
return parseShopManagePage(data)
}
export const SHOP_MANAGE_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
/** 加载店铺分组下拉选项(超级管理员取全部,管理员由后端限定可访问分组)。 */
/** 分组下拉:打的是与分组管理页同一个 GET /groups,所以它也必须跟着公司 tab 收窄,
* 否则店铺列表窄了、下拉里还选得到别家的组。 */
export async function fetchShopManageGroups(companyId?: number | null): Promise<ShopGroupOption[]> {
// platform 恒 'amazon'(2026-11-22 用户口径「亚马逊的也是同理」):店铺/查询ASIN/跟价页是
// 亚马逊域,京东档分组(platform='jd')不得混进本下拉——与分组管理页按平台 tab 过滤同口径。
const { data } = await http.get<unknown>(SHOP_MANAGE_GROUPS_ENDPOINT, { params: { platform: 'amazon', ...(companyId != null ? { company_id: companyId } : {}) } })
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}`)
}