Files
KCGL/inventory-web/src/api/inbound/stock.ts
yueli 1d1ca1b89e feat(web): userStore 暴露所属公司,盘点相关 API 支持按公司传参
多设备协同盘点需要前端明确知道「在盘哪个公司」:

- userStore 从 JWT claim company_name 解出 companyName 并暴露,登录、
  刷新 token、登出时同步维护。后端 get_current_company_filter() 读的
  也是这个 claim,两侧口径一致。
- 新增 getStocktakeCompanies(),对应盘点页的公司下拉接口。
- 盘点 API 增加公司维度:scanStockByBarcode 加可选 company;
  getDraftMergedList / getAllStocktakeItems 加 company_name;
  updateStocktakeQuantity 加第二个参数。

公司标识一律走 query string 而非 body:后端 get_current_company_filter()
只读 request.args,POST 请求 body 里的 company_name 会被直接忽略。
2026-09-11 11:33:19 +08:00

138 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.

import request from '@/utils/request'
// 获取全量库存
// 修改前: url: '/api/v1/inbound/stock/all'
// 修改后: url: '/v1/inbound/stock/all'
export function getAllStock() {
return request({
url: '/v1/inbound/stock/all',
method: 'get'
})
}
// 分页库存列表(服务端分页,支持关键字搜索)
export function getStockList(params: { page?: number; pageSize?: number; keyword?: string }) {
return request({
url: '/v1/inbound/stock/list',
method: 'get',
params
})
}
// 扫码精确匹配库存(盘库/出库/借库通用,替代模糊搜索漏匹配问题)
// company: 跨域/超管场景下需显式指定公司;不传则由后端按 JWT 里的公司隔离
export function scanStockByBarcode(barcode: string, company?: string) {
return request({
url: '/v1/inbound/stock/scan',
method: 'get',
params: company ? { barcode, company_name: company } : { barcode }
})
}
// 打印出库选单
// 修改后: 去掉开头的 /api
export function printSelectionList(items: any[]) {
return request({
url: '/v1/inbound/stock/print/selection',
method: 'post',
data: { items }
})
}
// 打印盘点报告
// 修改后: 去掉开头的 /api
export function printStocktakeReport(data: any) {
return request({
url: '/v1/inbound/stock/print/stocktake',
method: 'post',
data
})
}
// 保存 BOM 结构
export function saveBom(data: { parent_id: number; children: any[] }) {
return request({
url: '/v1/bom',
method: 'post',
data
})
}
// 获取基础物料列表
export function getMaterialBaseList(params?: any) {
return request({
url: '/v1/bom/base/list',
method: 'get',
params
})
}
// 获取 BOM 父件列表
export function getBomParents() {
return request({
url: '/v1/bom/parents',
method: 'get'
})
}
// 获取指定BOM详情
export function getBom(parentId: number) {
return request({
url: `/v1/bom/${parentId}`,
method: 'get'
})
}
// 盘点物资合并列表(服务端 JOIN draft + stock替代前端全量加载+find
export function getDraftMergedList(params: {
session_id: string
keyword?: string
status_filter?: string
page?: number
pageSize?: number
company_name?: string
}) {
return request({
url: '/v1/inbound/stock/draft/merged-list',
method: 'get',
params
})
}
// 盘点页的公司下拉选项(超管拿到全部公司,普通用户只拿到本公司)
export function getStocktakeCompanies() {
return request({
url: '/v1/inbound/stock/stocktake/companies',
method: 'get'
})
}
// 获取应盘物资清单(盘点基数)
export function getAllStocktakeItems(params?: {
keyword?: string
session_id?: string
page?: number
pageSize?: number
company_name?: string
}) {
return request({
url: '/v1/inbound/stock/stocktake/all-items',
method: 'get',
params
})
}
// 更新盘点实盘数(手动修改)
// company 走 query string后端 get_current_company_filter 只读 request.args不读 body
export function updateStocktakeQuantity(
data: { stock_id: number; source_table: string; quantity: number; session_id?: string },
company?: string
) {
return request({
url: '/v1/inbound/stock/stocktake/update-quantity',
method: 'post',
params: company ? { company_name: company } : undefined,
data
})
}