feat(G2-4): 升级预算页为多作用域模式
这个提交包含在:
+32
-6
@@ -1,10 +1,30 @@
|
||||
import { apiRequestData } from "./http";
|
||||
|
||||
export type BudgetScopeType = "global" | "department_legacy" | "cost_center_scoped" | "invalid";
|
||||
|
||||
export type BudgetPool = {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
scopeType: BudgetScopeType;
|
||||
departmentId: string | null;
|
||||
legalEntityId: string | null;
|
||||
costCenterId: string | null;
|
||||
department: {
|
||||
id: string;
|
||||
name: string;
|
||||
} | null;
|
||||
legalEntity: {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
} | null;
|
||||
costCenter: {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
legalEntityId: string;
|
||||
} | null;
|
||||
status: "active" | "archived";
|
||||
periodStart: string | null;
|
||||
periodEnd: string | null;
|
||||
@@ -27,28 +47,34 @@ export type BudgetListResponse = {
|
||||
export type BudgetListQuery = {
|
||||
status?: "active" | "archived";
|
||||
departmentId?: string;
|
||||
legalEntityId?: string;
|
||||
costCenterId?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
};
|
||||
|
||||
function toQueryString(query: BudgetListQuery = {}) {
|
||||
function toQueryString(query: Record<string, string | number | undefined>) {
|
||||
const params = new URLSearchParams();
|
||||
if (query.status) params.set("status", query.status);
|
||||
if (query.departmentId) params.set("departmentId", query.departmentId);
|
||||
if (query.page != null) params.set("page", String(query.page));
|
||||
if (query.pageSize != null) params.set("pageSize", String(query.pageSize));
|
||||
for (const [key, value] of Object.entries(query)) {
|
||||
if (value == null || value === "") {
|
||||
continue;
|
||||
}
|
||||
params.set(key, String(value));
|
||||
}
|
||||
const encoded = params.toString();
|
||||
return encoded ? `?${encoded}` : "";
|
||||
}
|
||||
|
||||
export async function fetchBudgets(query: BudgetListQuery = {}) {
|
||||
return apiRequestData<BudgetListResponse>(`/api/budgets${toQueryString(query)}`);
|
||||
return apiRequestData<BudgetListResponse>(`/api/budgets${toQueryString(query as Record<string, string | number | undefined>)}`);
|
||||
}
|
||||
|
||||
export async function createBudget(payload: {
|
||||
code: string;
|
||||
name: string;
|
||||
departmentId?: string | null;
|
||||
legalEntityId?: string | null;
|
||||
costCenterId?: string | null;
|
||||
periodStart: string;
|
||||
periodEnd: string;
|
||||
allocatedAmount: string;
|
||||
|
||||
在新工单中引用
屏蔽一个用户