6d3f6a0a8e
- 会话摘要增加软删除时间字段 - 后台聊天列表显示前台已删除状态并保留消息查看入口
1263 lines
31 KiB
TypeScript
1263 lines
31 KiB
TypeScript
/** 既有权限业务与数字人运营的统一后台接口。 */
|
|
import { http } from "@/utils/http";
|
|
|
|
/**
|
|
* 门店权限后台的业务接口层。
|
|
*
|
|
* 页面只依赖这里导出的类型和方法,避免在视图组件中散落接口路径、
|
|
* 响应结构和状态枚举。后端统一挂在 `/api` 前缀下,由 Vite 代理转发。
|
|
*/
|
|
const API_PREFIX = "/api";
|
|
const EMPLOYEE_OPTION_PAGE_SIZE = 100;
|
|
|
|
/** 后端员工与门店共用的启停状态枚举。 */
|
|
export type EmployeeStatus = "ACTIVE" | "INACTIVE";
|
|
export type StoreStatus = "ACTIVE" | "INACTIVE";
|
|
export type EmployeeStatusTagVariant = "success" | "warning" | "default";
|
|
|
|
export interface EmployeeStatusTag {
|
|
code: "EMPLOYEE_ACTIVE" | "EMPLOYEE_INACTIVE" | "STORE_INACTIVE";
|
|
label: string;
|
|
variant: EmployeeStatusTagVariant;
|
|
}
|
|
|
|
/** 员工列表中展示的角色摘要。 */
|
|
export interface RoleSummary {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface Employee {
|
|
id: number;
|
|
storeId: number;
|
|
storeName: string;
|
|
storeStatus: StoreStatus;
|
|
name: string;
|
|
phone: string;
|
|
status: EmployeeStatus;
|
|
statusTags: EmployeeStatusTag[];
|
|
remark: string | null;
|
|
roles: RoleSummary[];
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface StoreOption {
|
|
id: number;
|
|
name: string;
|
|
address: string | null;
|
|
phone: string | null;
|
|
}
|
|
|
|
export interface RoleOption {
|
|
id: number;
|
|
code: string;
|
|
name: string;
|
|
description: string | null;
|
|
isSystem: boolean;
|
|
}
|
|
|
|
export interface Store extends StoreOption {
|
|
status: StoreStatus;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface StoreDetail extends Store {
|
|
employees: Employee[];
|
|
}
|
|
|
|
export interface Role extends RoleOption {
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface PermissionPolicyMenu {
|
|
key: string;
|
|
title: string;
|
|
actions: string[];
|
|
}
|
|
|
|
export interface PermissionPolicy {
|
|
roleId: number;
|
|
roleCode: string;
|
|
roleName: string;
|
|
roleDescription: string | null;
|
|
isSystem: boolean;
|
|
editable: boolean;
|
|
scope: string;
|
|
permissions: string[];
|
|
menus: PermissionPolicyMenu[];
|
|
}
|
|
|
|
export interface PermissionDefinition {
|
|
code: string;
|
|
title: string;
|
|
description: string;
|
|
groupKey: string;
|
|
groupTitle: string;
|
|
}
|
|
|
|
export interface PermissionDefinitionGroup {
|
|
key: string;
|
|
title: string;
|
|
permissions: PermissionDefinition[];
|
|
}
|
|
|
|
export interface PermissionDefinitionMenu {
|
|
key: string;
|
|
title: string;
|
|
icon?: string;
|
|
permission: string;
|
|
actions: string[];
|
|
actionLabels: Record<string, string>;
|
|
}
|
|
|
|
export interface PermissionDefinitions {
|
|
permissions: PermissionDefinition[];
|
|
groups: PermissionDefinitionGroup[];
|
|
menus: PermissionDefinitionMenu[];
|
|
}
|
|
|
|
/** 列表接口是服务端分页,筛选条件统一通过查询参数传递。 */
|
|
export interface PageParams {
|
|
page: number;
|
|
pageSize: number;
|
|
}
|
|
|
|
export interface EmployeeListParams extends PageParams {
|
|
storeId?: number;
|
|
status?: EmployeeStatus;
|
|
keyword?: string;
|
|
}
|
|
|
|
export type EmployeeOptionParams = Partial<
|
|
Pick<EmployeeListParams, "storeId" | "status" | "keyword">
|
|
>;
|
|
|
|
export interface StoreListParams extends PageParams {
|
|
includeInactive?: boolean;
|
|
status?: StoreStatus;
|
|
keyword?: string;
|
|
}
|
|
|
|
export interface RoleListParams extends PageParams {
|
|
keyword?: string;
|
|
isSystem?: boolean;
|
|
}
|
|
|
|
export interface StorePayload {
|
|
name: string;
|
|
address?: string | null;
|
|
phone?: string | null;
|
|
status: StoreStatus;
|
|
}
|
|
|
|
export interface RolePayload {
|
|
code: string;
|
|
name: string;
|
|
description?: string | null;
|
|
}
|
|
|
|
export interface EmployeePayload {
|
|
storeId: number;
|
|
name: string;
|
|
phone: string;
|
|
status: EmployeeStatus;
|
|
remark?: string | null;
|
|
roleIds: number[];
|
|
}
|
|
|
|
export interface EmployeePasswordPayload {
|
|
oldPassword: string;
|
|
newPassword: string;
|
|
}
|
|
|
|
export interface EmployeePasswordResetPayload {
|
|
reason: string;
|
|
}
|
|
|
|
export interface EmployeePasswordResetResult {
|
|
employeeId: number;
|
|
temporaryPassword: string;
|
|
}
|
|
|
|
export type AnnouncementImportance = "NORMAL" | "IMPORTANT" | "URGENT";
|
|
export type AnnouncementStatus = "DRAFT" | "PUBLISHED" | "ARCHIVED";
|
|
export type AnnouncementTargetScope =
|
|
| "ALL_STORES"
|
|
| "STORES"
|
|
| "ROLES"
|
|
| "EMPLOYEES";
|
|
|
|
export interface Announcement {
|
|
id: number;
|
|
title: string;
|
|
content: string;
|
|
importance: AnnouncementImportance;
|
|
targetScope: AnnouncementTargetScope;
|
|
targetStoreIds: number[];
|
|
targetRoleIds: number[];
|
|
targetEmployeeIds: number[];
|
|
status: AnnouncementStatus;
|
|
publisherName: string | null;
|
|
publishedAt: string | null;
|
|
readCount: number;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface AnnouncementListParams extends PageParams {
|
|
status?: AnnouncementStatus;
|
|
importance?: AnnouncementImportance;
|
|
keyword?: string;
|
|
}
|
|
|
|
export interface AnnouncementPayload {
|
|
title: string;
|
|
content: string;
|
|
importance: AnnouncementImportance;
|
|
targetScope: AnnouncementTargetScope;
|
|
targetStoreIds: number[];
|
|
targetRoleIds: number[];
|
|
targetEmployeeIds: number[];
|
|
}
|
|
|
|
export type TaskStatus = "PENDING" | "IN_PROGRESS" | "COMPLETED" | "CANCELLED";
|
|
export type TaskPriority = "LOW" | "NORMAL" | "HIGH" | "URGENT";
|
|
|
|
export interface TaskEvent {
|
|
id: number;
|
|
action: string;
|
|
remark: string | null;
|
|
operatorName: string | null;
|
|
createdAt: string;
|
|
}
|
|
|
|
export interface Task {
|
|
id: number;
|
|
title: string;
|
|
description: string | null;
|
|
storeId: number;
|
|
storeName: string;
|
|
assigneeIds: number[];
|
|
assigneeNames: string[];
|
|
status: TaskStatus;
|
|
priority: TaskPriority;
|
|
deadlineAt: string | null;
|
|
creatorName: string | null;
|
|
events?: TaskEvent[];
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface TaskListParams extends PageParams {
|
|
storeId?: number;
|
|
employeeId?: number;
|
|
status?: TaskStatus;
|
|
priority?: TaskPriority;
|
|
keyword?: string;
|
|
}
|
|
|
|
export interface TaskPayload {
|
|
title: string;
|
|
description?: string | null;
|
|
storeId: number;
|
|
assigneeIds: number[];
|
|
priority: TaskPriority;
|
|
deadlineAt?: string | null;
|
|
}
|
|
|
|
export type ShiftStatus = "SCHEDULED" | "CANCELLED" | "COMPLETED";
|
|
|
|
export interface Shift {
|
|
id: number;
|
|
storeId: number;
|
|
storeName: string;
|
|
employeeId: number;
|
|
employeeName: string;
|
|
position: string;
|
|
startAt: string;
|
|
endAt: string;
|
|
status: ShiftStatus;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface ShiftListParams extends PageParams {
|
|
storeId?: number;
|
|
employeeId?: number;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}
|
|
|
|
export interface ShiftPayload {
|
|
storeId: number;
|
|
employeeId: number;
|
|
position: string;
|
|
startAt: string;
|
|
endAt: string;
|
|
}
|
|
|
|
export interface CredentialAudit {
|
|
id: number;
|
|
operatorName: string;
|
|
targetEmployeeName: string;
|
|
targetEmployeePhone: string | null;
|
|
storeName: string | null;
|
|
action: string;
|
|
operatedAt: string;
|
|
ip: string | null;
|
|
userAgent: string | null;
|
|
reason: string;
|
|
}
|
|
|
|
export interface CredentialAuditListParams extends PageParams {
|
|
operatorId?: number;
|
|
targetEmployeeId?: number;
|
|
storeId?: number;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}
|
|
|
|
/** access-manage 后端普通响应包裹结构。 */
|
|
export interface ApiResult<T> {
|
|
success: boolean;
|
|
data: T;
|
|
}
|
|
|
|
export interface Pagination {
|
|
page: number;
|
|
pageSize: number;
|
|
total: number;
|
|
totalPages: number;
|
|
}
|
|
|
|
export interface PaginatedData<T> {
|
|
items: T[];
|
|
pagination: Pagination;
|
|
}
|
|
|
|
type LegacyAnnouncementImportance = "LOW" | "HIGH";
|
|
type BackendAnnouncementTargetType = "ALL" | "STORE" | "ROLE" | "EMPLOYEE";
|
|
type BackendConcreteAnnouncementTargetType = Exclude<
|
|
BackendAnnouncementTargetType,
|
|
"ALL"
|
|
>;
|
|
|
|
interface BackendAnnouncementTarget {
|
|
type: BackendConcreteAnnouncementTargetType;
|
|
id: number;
|
|
}
|
|
|
|
interface BackendAnnouncement {
|
|
id: number;
|
|
title: string;
|
|
content: string;
|
|
level?: AnnouncementImportance | LegacyAnnouncementImportance;
|
|
importance?: AnnouncementImportance | LegacyAnnouncementImportance;
|
|
status: AnnouncementStatus;
|
|
targetType?: BackendAnnouncementTargetType;
|
|
targetScope?: AnnouncementTargetScope;
|
|
targets?: BackendAnnouncementTarget[];
|
|
targetStoreIds?: number[];
|
|
targetRoleIds?: number[];
|
|
targetEmployeeIds?: number[];
|
|
publisherName?: string | null;
|
|
publishedAt: string | null;
|
|
readCount?: number;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
type BackendAnnouncementPayload = Omit<
|
|
AnnouncementPayload,
|
|
| "importance"
|
|
| "targetScope"
|
|
| "targetStoreIds"
|
|
| "targetRoleIds"
|
|
| "targetEmployeeIds"
|
|
> & {
|
|
level: AnnouncementImportance;
|
|
targetType: BackendAnnouncementTargetType;
|
|
targets: BackendAnnouncementTarget[];
|
|
};
|
|
|
|
type BackendTaskStatus = TaskStatus | "CANCELED";
|
|
|
|
interface BackendTaskAssignee {
|
|
id: number;
|
|
name: string;
|
|
phone?: string | null;
|
|
}
|
|
|
|
interface BackendTaskEvent {
|
|
id: number;
|
|
action?: string;
|
|
eventType?: string;
|
|
remark?: string | null;
|
|
comment?: string | null;
|
|
operatorName?: string | null;
|
|
createdAt: string;
|
|
}
|
|
|
|
interface BackendTask {
|
|
id: number;
|
|
title: string;
|
|
description: string | null;
|
|
storeId: number | null;
|
|
storeName: string | null;
|
|
assignees?: BackendTaskAssignee[];
|
|
assigneeIds?: number[];
|
|
assigneeNames?: string[];
|
|
status: BackendTaskStatus;
|
|
priority: TaskPriority;
|
|
dueAt?: string | null;
|
|
deadlineAt?: string | null;
|
|
creatorName?: string | null;
|
|
events?: BackendTaskEvent[];
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
type BackendTaskPayload = Omit<TaskPayload, "deadlineAt"> & {
|
|
dueAt?: string | null;
|
|
assignees?: number[];
|
|
};
|
|
|
|
type BackendShiftStatus = ShiftStatus | "CANCELED";
|
|
|
|
interface BackendShift {
|
|
id: number;
|
|
storeId: number;
|
|
storeName: string;
|
|
employeeId: number;
|
|
employeeName: string;
|
|
roleName?: string | null;
|
|
position?: string | null;
|
|
startAt: string;
|
|
endAt: string;
|
|
status: BackendShiftStatus;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
type BackendShiftPayload = Omit<ShiftPayload, "position"> & {
|
|
roleName?: string | null;
|
|
status?: "SCHEDULED";
|
|
};
|
|
|
|
interface BackendCredentialAudit {
|
|
id: number;
|
|
actorName?: string | null;
|
|
operatorName?: string | null;
|
|
targetEmployeeName: string;
|
|
targetEmployeePhone?: string | null;
|
|
storeName?: string | null;
|
|
action: string;
|
|
createdAt?: string;
|
|
operatedAt?: string;
|
|
ip: string | null;
|
|
userAgent: string | null;
|
|
reason: string | null;
|
|
}
|
|
|
|
function mapApiResult<T, R>(
|
|
result: ApiResult<T>,
|
|
mapper: (data: T) => R
|
|
): ApiResult<R> {
|
|
return {
|
|
...result,
|
|
data: mapper(result.data)
|
|
};
|
|
}
|
|
|
|
function mapPaginatedData<T, R>(
|
|
data: PaginatedData<T>,
|
|
mapper: (item: T) => R
|
|
): PaginatedData<R> {
|
|
return {
|
|
...data,
|
|
items: data.items.map(mapper)
|
|
};
|
|
}
|
|
|
|
function hasOwn<T extends object>(data: T, key: keyof T) {
|
|
return Object.prototype.hasOwnProperty.call(data, key);
|
|
}
|
|
|
|
function toBackendDateTime(value?: string | null) {
|
|
if (value === undefined) return undefined;
|
|
if (!value) return null;
|
|
|
|
const normalizedValue = value.includes("T") ? value : value.replace(" ", "T");
|
|
const date = new Date(normalizedValue);
|
|
|
|
return Number.isNaN(date.getTime()) ? value : date.toISOString();
|
|
}
|
|
|
|
function normalizeAnnouncementImportance(
|
|
value?: AnnouncementImportance | LegacyAnnouncementImportance | null
|
|
): AnnouncementImportance {
|
|
if (value === "URGENT" || value === "IMPORTANT" || value === "NORMAL") {
|
|
return value;
|
|
}
|
|
|
|
return value === "HIGH" ? "IMPORTANT" : "NORMAL";
|
|
}
|
|
|
|
function toBackendAnnouncementTargetType(
|
|
scope: AnnouncementTargetScope
|
|
): BackendAnnouncementTargetType {
|
|
const scopeMap: Record<
|
|
AnnouncementTargetScope,
|
|
BackendAnnouncementTargetType
|
|
> = {
|
|
ALL_STORES: "ALL",
|
|
STORES: "STORE",
|
|
ROLES: "ROLE",
|
|
EMPLOYEES: "EMPLOYEE"
|
|
};
|
|
|
|
return scopeMap[scope];
|
|
}
|
|
|
|
function toAnnouncementTargetScope(
|
|
targetType?: BackendAnnouncementTargetType
|
|
): AnnouncementTargetScope {
|
|
const targetTypeMap: Record<
|
|
BackendAnnouncementTargetType,
|
|
AnnouncementTargetScope
|
|
> = {
|
|
ALL: "ALL_STORES",
|
|
STORE: "STORES",
|
|
ROLE: "ROLES",
|
|
EMPLOYEE: "EMPLOYEES"
|
|
};
|
|
|
|
return targetTypeMap[targetType ?? "ALL"];
|
|
}
|
|
|
|
function getAnnouncementTargetIds(
|
|
targets: BackendAnnouncementTarget[],
|
|
type: BackendConcreteAnnouncementTargetType
|
|
) {
|
|
return targets
|
|
.filter(target => target.type === type)
|
|
.map(target => target.id);
|
|
}
|
|
|
|
function toBackendAnnouncementPayload(
|
|
data: Partial<AnnouncementPayload>
|
|
): Partial<BackendAnnouncementPayload> {
|
|
const payload: Partial<BackendAnnouncementPayload> = {};
|
|
|
|
if (hasOwn(data, "title")) payload.title = data.title;
|
|
if (hasOwn(data, "content")) payload.content = data.content;
|
|
if (hasOwn(data, "importance")) {
|
|
payload.level = normalizeAnnouncementImportance(data.importance);
|
|
}
|
|
|
|
if (hasOwn(data, "targetScope")) {
|
|
payload.targetType = toBackendAnnouncementTargetType(
|
|
data.targetScope ?? "ALL_STORES"
|
|
);
|
|
}
|
|
|
|
if (
|
|
hasOwn(data, "targetScope") ||
|
|
hasOwn(data, "targetStoreIds") ||
|
|
hasOwn(data, "targetRoleIds") ||
|
|
hasOwn(data, "targetEmployeeIds")
|
|
) {
|
|
const targetType =
|
|
payload.targetType ??
|
|
toBackendAnnouncementTargetType(data.targetScope ?? "ALL_STORES");
|
|
const targetIds =
|
|
targetType === "STORE"
|
|
? (data.targetStoreIds ?? [])
|
|
: targetType === "ROLE"
|
|
? (data.targetRoleIds ?? [])
|
|
: targetType === "EMPLOYEE"
|
|
? (data.targetEmployeeIds ?? [])
|
|
: [];
|
|
|
|
payload.targets =
|
|
targetType === "ALL"
|
|
? []
|
|
: targetIds.map(id => ({
|
|
type: targetType,
|
|
id
|
|
}));
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
|
|
function normalizeAnnouncement(
|
|
announcement: BackendAnnouncement
|
|
): Announcement {
|
|
const targets = announcement.targets ?? [];
|
|
const targetScope =
|
|
announcement.targetScope ??
|
|
toAnnouncementTargetScope(announcement.targetType);
|
|
|
|
return {
|
|
id: announcement.id,
|
|
title: announcement.title,
|
|
content: announcement.content,
|
|
importance: normalizeAnnouncementImportance(
|
|
announcement.level ?? announcement.importance
|
|
),
|
|
targetScope,
|
|
targetStoreIds:
|
|
announcement.targetStoreIds ?? getAnnouncementTargetIds(targets, "STORE"),
|
|
targetRoleIds:
|
|
announcement.targetRoleIds ?? getAnnouncementTargetIds(targets, "ROLE"),
|
|
targetEmployeeIds:
|
|
announcement.targetEmployeeIds ??
|
|
getAnnouncementTargetIds(targets, "EMPLOYEE"),
|
|
status: announcement.status,
|
|
publisherName: announcement.publisherName ?? null,
|
|
publishedAt: announcement.publishedAt,
|
|
readCount: announcement.readCount ?? 0,
|
|
createdAt: announcement.createdAt,
|
|
updatedAt: announcement.updatedAt
|
|
};
|
|
}
|
|
|
|
function normalizeTaskStatus(status: BackendTaskStatus): TaskStatus {
|
|
return status === "CANCELED" ? "CANCELLED" : status;
|
|
}
|
|
|
|
function normalizeShiftStatus(status: BackendShiftStatus): ShiftStatus {
|
|
return status === "CANCELED" ? "CANCELLED" : status;
|
|
}
|
|
|
|
function toBackendTaskStatus(status?: BackendTaskStatus) {
|
|
return status === "CANCELED" ? "CANCELLED" : status;
|
|
}
|
|
|
|
function normalizeTask(task: BackendTask): Task {
|
|
const assignees = task.assignees ?? [];
|
|
|
|
return {
|
|
id: task.id,
|
|
title: task.title,
|
|
description: task.description,
|
|
storeId: task.storeId ?? 0,
|
|
storeName: task.storeName ?? "-",
|
|
assigneeIds: task.assigneeIds ?? assignees.map(assignee => assignee.id),
|
|
assigneeNames:
|
|
task.assigneeNames ?? assignees.map(assignee => assignee.name),
|
|
status: normalizeTaskStatus(task.status),
|
|
priority: task.priority,
|
|
deadlineAt: task.deadlineAt ?? task.dueAt ?? null,
|
|
creatorName: task.creatorName ?? null,
|
|
events: task.events?.map(event => ({
|
|
id: event.id,
|
|
action: event.action ?? event.eventType ?? "",
|
|
remark: event.remark ?? event.comment ?? null,
|
|
operatorName: event.operatorName ?? null,
|
|
createdAt: event.createdAt
|
|
})),
|
|
createdAt: task.createdAt,
|
|
updatedAt: task.updatedAt
|
|
};
|
|
}
|
|
|
|
function toBackendTaskPayload(
|
|
data: Partial<TaskPayload>
|
|
): Partial<BackendTaskPayload> {
|
|
const payload = { ...data } as Partial<BackendTaskPayload> &
|
|
Partial<TaskPayload>;
|
|
|
|
delete payload.deadlineAt;
|
|
|
|
if (hasOwn(data, "deadlineAt")) {
|
|
payload.dueAt = toBackendDateTime(data.deadlineAt);
|
|
}
|
|
|
|
if (hasOwn(data, "assigneeIds")) {
|
|
payload.assignees = data.assigneeIds;
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
|
|
function normalizeShift(shift: BackendShift): Shift {
|
|
return {
|
|
id: shift.id,
|
|
storeId: shift.storeId,
|
|
storeName: shift.storeName,
|
|
employeeId: shift.employeeId,
|
|
employeeName: shift.employeeName,
|
|
position: shift.position ?? shift.roleName ?? "",
|
|
startAt: shift.startAt,
|
|
endAt: shift.endAt,
|
|
status: normalizeShiftStatus(shift.status),
|
|
createdAt: shift.createdAt,
|
|
updatedAt: shift.updatedAt
|
|
};
|
|
}
|
|
|
|
function toBackendShiftPayload(
|
|
data: Partial<ShiftPayload>
|
|
): Partial<BackendShiftPayload> {
|
|
const payload = { ...data } as Partial<BackendShiftPayload> &
|
|
Partial<ShiftPayload>;
|
|
|
|
delete payload.position;
|
|
|
|
if (hasOwn(data, "position")) {
|
|
payload.roleName = data.position?.trim() || null;
|
|
}
|
|
if (hasOwn(data, "startAt")) {
|
|
payload.startAt = toBackendDateTime(data.startAt) ?? "";
|
|
}
|
|
if (hasOwn(data, "endAt")) {
|
|
payload.endAt = toBackendDateTime(data.endAt) ?? "";
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
|
|
function normalizeCredentialAudit(
|
|
audit: BackendCredentialAudit
|
|
): CredentialAudit {
|
|
return {
|
|
id: audit.id,
|
|
operatorName: audit.operatorName ?? audit.actorName ?? "-",
|
|
targetEmployeeName: audit.targetEmployeeName,
|
|
targetEmployeePhone: audit.targetEmployeePhone ?? null,
|
|
storeName: audit.storeName ?? null,
|
|
action: audit.action,
|
|
operatedAt: audit.operatedAt ?? audit.createdAt ?? "",
|
|
ip: audit.ip,
|
|
userAgent: audit.userAgent,
|
|
reason: audit.reason ?? ""
|
|
};
|
|
}
|
|
|
|
export type PermissionPolicyResult = ApiResult<PermissionPolicy[]>;
|
|
export type PermissionDefinitionsResult = ApiResult<PermissionDefinitions>;
|
|
|
|
/** 门店接口:管理门店基础资料,并给员工下拉选项提供数据源。 */
|
|
export const listStoreOptions = () => {
|
|
return http.request<ApiResult<StoreOption[]>>("get", `${API_PREFIX}/stores`);
|
|
};
|
|
|
|
export const listAllStores = (
|
|
params?: Pick<StoreListParams, "includeInactive">
|
|
) => {
|
|
return http.request<ApiResult<Store[]>>("get", `${API_PREFIX}/stores`, {
|
|
params
|
|
});
|
|
};
|
|
|
|
export const listStores = (params: StoreListParams) => {
|
|
return http.request<ApiResult<PaginatedData<Store>>>(
|
|
"get",
|
|
`${API_PREFIX}/stores`,
|
|
{ params }
|
|
);
|
|
};
|
|
|
|
export const listRoles = () => {
|
|
return http.request<ApiResult<Role[]>>("get", `${API_PREFIX}/roles`);
|
|
};
|
|
|
|
export const listRolePage = (params: RoleListParams) => {
|
|
return http.request<ApiResult<PaginatedData<Role>>>(
|
|
"get",
|
|
`${API_PREFIX}/roles`,
|
|
{ params }
|
|
);
|
|
};
|
|
|
|
export const getStore = (id: number) => {
|
|
return http.request<ApiResult<StoreDetail>>(
|
|
"get",
|
|
`${API_PREFIX}/stores/${id}`
|
|
);
|
|
};
|
|
|
|
export const createStore = (data: StorePayload) => {
|
|
return http.request<ApiResult<Store>>("post", `${API_PREFIX}/stores`, {
|
|
data
|
|
});
|
|
};
|
|
|
|
export const updateStore = (id: number, data: Partial<StorePayload>) => {
|
|
return http.request<ApiResult<Store>>("patch", `${API_PREFIX}/stores/${id}`, {
|
|
data
|
|
});
|
|
};
|
|
|
|
export const deleteStore = (id: number) => {
|
|
return http.request<void>("delete", `${API_PREFIX}/stores/${id}`);
|
|
};
|
|
|
|
export const removeStoreEmployee = (storeId: number, employeeId: number) => {
|
|
return http.request<void>(
|
|
"delete",
|
|
`${API_PREFIX}/stores/${storeId}/employees/${employeeId}`
|
|
);
|
|
};
|
|
|
|
/** 角色接口:维护员工可绑定的权限角色。 */
|
|
export const getRole = (id: number) => {
|
|
return http.request<ApiResult<Role>>("get", `${API_PREFIX}/roles/${id}`);
|
|
};
|
|
|
|
export const createRole = (data: RolePayload) => {
|
|
return http.request<ApiResult<Role>>("post", `${API_PREFIX}/roles`, {
|
|
data
|
|
});
|
|
};
|
|
|
|
export const updateRole = (id: number, data: Partial<RolePayload>) => {
|
|
return http.request<ApiResult<Role>>("patch", `${API_PREFIX}/roles/${id}`, {
|
|
data
|
|
});
|
|
};
|
|
|
|
export const deleteRole = (id: number) => {
|
|
return http.request<void>("delete", `${API_PREFIX}/roles/${id}`);
|
|
};
|
|
|
|
/** 员工接口:员工列表由后端分页,编辑时按 id 重新拉取完整角色绑定。 */
|
|
export const listEmployees = (params: EmployeeListParams) => {
|
|
return http.request<ApiResult<PaginatedData<Employee>>>(
|
|
"get",
|
|
`${API_PREFIX}/employees`,
|
|
{ params }
|
|
);
|
|
};
|
|
|
|
export const listEmployeeOptions = async (
|
|
params: EmployeeOptionParams = {}
|
|
): Promise<ApiResult<Employee[]>> => {
|
|
const items: Employee[] = [];
|
|
let page = 1;
|
|
let totalPages = 1;
|
|
|
|
do {
|
|
const result = await listEmployees({
|
|
...params,
|
|
page,
|
|
pageSize: EMPLOYEE_OPTION_PAGE_SIZE
|
|
});
|
|
|
|
items.push(...result.data.items);
|
|
totalPages = result.data.pagination.totalPages;
|
|
page += 1;
|
|
} while (page <= totalPages);
|
|
|
|
return {
|
|
success: true,
|
|
data: items
|
|
};
|
|
};
|
|
|
|
export const getEmployee = (id: number) => {
|
|
return http.request<ApiResult<Employee>>(
|
|
"get",
|
|
`${API_PREFIX}/employees/${id}`
|
|
);
|
|
};
|
|
|
|
export const createEmployee = (data: EmployeePayload) => {
|
|
return http.request<ApiResult<Employee>>("post", `${API_PREFIX}/employees`, {
|
|
data
|
|
});
|
|
};
|
|
|
|
export const updateEmployee = (id: number, data: Partial<EmployeePayload>) => {
|
|
return http.request<ApiResult<Employee>>(
|
|
"patch",
|
|
`${API_PREFIX}/employees/${id}`,
|
|
{ data }
|
|
);
|
|
};
|
|
|
|
export const updateEmployeeStatus = (id: number, status: EmployeeStatus) => {
|
|
return http.request<ApiResult<Employee>>(
|
|
"patch",
|
|
`${API_PREFIX}/employees/${id}/status`,
|
|
{ data: { status } }
|
|
);
|
|
};
|
|
|
|
export const updateEmployeePassword = (
|
|
id: number,
|
|
data: EmployeePasswordPayload
|
|
) => {
|
|
return http.request<ApiResult<Employee>>(
|
|
"patch",
|
|
`${API_PREFIX}/employees/${id}/password`,
|
|
{ data }
|
|
);
|
|
};
|
|
|
|
export const resetEmployeePassword = (
|
|
id: number,
|
|
data: EmployeePasswordResetPayload
|
|
) => {
|
|
return http.request<ApiResult<EmployeePasswordResetResult>>(
|
|
"post",
|
|
`${API_PREFIX}/admin/employees/${id}/password/reset`,
|
|
{ data }
|
|
);
|
|
};
|
|
|
|
export const deleteEmployee = (id: number) => {
|
|
return http.request<void>("delete", `${API_PREFIX}/employees/${id}`);
|
|
};
|
|
|
|
/** 权限接口:读取权限定义、查看角色策略,并把权限点分配给角色。 */
|
|
export const getPermissionPolicies = () => {
|
|
return http.request<PermissionPolicyResult>(
|
|
"get",
|
|
`${API_PREFIX}/permissions/policies`
|
|
);
|
|
};
|
|
|
|
export const getPermissionDefinitions = () => {
|
|
return http.request<PermissionDefinitionsResult>(
|
|
"get",
|
|
`${API_PREFIX}/permissions/definitions`
|
|
);
|
|
};
|
|
|
|
export const updateRolePermissions = (
|
|
roleId: number,
|
|
permissions: string[]
|
|
) => {
|
|
return http.request<ApiResult<PermissionPolicy>>(
|
|
"put",
|
|
`${API_PREFIX}/permissions/roles/${roleId}`,
|
|
{
|
|
data: { permissions }
|
|
}
|
|
);
|
|
};
|
|
|
|
/** 员工工作台运营接口:公告、任务、排班和凭据审计均按后台 admin 路径对接。 */
|
|
export const listAnnouncements = (params: AnnouncementListParams) => {
|
|
const { importance, ...restParams } = params;
|
|
|
|
return http
|
|
.request<ApiResult<PaginatedData<BackendAnnouncement>>>(
|
|
"get",
|
|
`${API_PREFIX}/admin/announcements`,
|
|
{
|
|
params: {
|
|
...restParams,
|
|
level: importance
|
|
}
|
|
}
|
|
)
|
|
.then(result =>
|
|
mapApiResult(result, data =>
|
|
mapPaginatedData(data, normalizeAnnouncement)
|
|
)
|
|
);
|
|
};
|
|
|
|
export const createAnnouncement = (data: AnnouncementPayload) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendAnnouncement>
|
|
>("post", `${API_PREFIX}/admin/announcements`, { data: toBackendAnnouncementPayload(data) })
|
|
.then(result => mapApiResult(result, normalizeAnnouncement));
|
|
};
|
|
|
|
export const updateAnnouncement = (
|
|
id: number,
|
|
data: Partial<AnnouncementPayload>
|
|
) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendAnnouncement>
|
|
>("patch", `${API_PREFIX}/admin/announcements/${id}`, { data: toBackendAnnouncementPayload(data) })
|
|
.then(result => mapApiResult(result, normalizeAnnouncement));
|
|
};
|
|
|
|
export const publishAnnouncement = (id: number) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendAnnouncement>
|
|
>("post", `${API_PREFIX}/admin/announcements/${id}/publish`)
|
|
.then(result => mapApiResult(result, normalizeAnnouncement));
|
|
};
|
|
|
|
export const archiveAnnouncement = (id: number) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendAnnouncement>
|
|
>("post", `${API_PREFIX}/admin/announcements/${id}/archive`)
|
|
.then(result => mapApiResult(result, normalizeAnnouncement));
|
|
};
|
|
|
|
export const listTasks = (params: TaskListParams) => {
|
|
return http
|
|
.request<ApiResult<PaginatedData<BackendTask>>>(
|
|
"get",
|
|
`${API_PREFIX}/admin/tasks`,
|
|
{
|
|
params: {
|
|
...params,
|
|
status: toBackendTaskStatus(params.status)
|
|
}
|
|
}
|
|
)
|
|
.then(result =>
|
|
mapApiResult(result, data => mapPaginatedData(data, normalizeTask))
|
|
);
|
|
};
|
|
|
|
export const createTask = (data: TaskPayload) => {
|
|
return http
|
|
.request<ApiResult<BackendTask>>("post", `${API_PREFIX}/admin/tasks`, {
|
|
data: toBackendTaskPayload(data)
|
|
})
|
|
.then(result => mapApiResult(result, normalizeTask));
|
|
};
|
|
|
|
export const updateTask = (id: number, data: Partial<TaskPayload>) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendTask>
|
|
>("patch", `${API_PREFIX}/admin/tasks/${id}`, { data: toBackendTaskPayload(data) })
|
|
.then(result => mapApiResult(result, normalizeTask));
|
|
};
|
|
|
|
export const cancelTask = (id: number) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendTask>
|
|
>("post", `${API_PREFIX}/admin/tasks/${id}/cancel`)
|
|
.then(result => mapApiResult(result, normalizeTask));
|
|
};
|
|
|
|
export const listShifts = (params: ShiftListParams) => {
|
|
return http
|
|
.request<
|
|
ApiResult<PaginatedData<BackendShift>>
|
|
>("get", `${API_PREFIX}/admin/shifts`, { params })
|
|
.then(result =>
|
|
mapApiResult(result, data => mapPaginatedData(data, normalizeShift))
|
|
);
|
|
};
|
|
|
|
export const createShift = (data: ShiftPayload) => {
|
|
return http
|
|
.request<ApiResult<BackendShift>>("post", `${API_PREFIX}/admin/shifts`, {
|
|
data: toBackendShiftPayload(data)
|
|
})
|
|
.then(result => mapApiResult(result, normalizeShift));
|
|
};
|
|
|
|
export const updateShift = (id: number, data: Partial<ShiftPayload>) => {
|
|
return http
|
|
.request<
|
|
ApiResult<BackendShift>
|
|
>("patch", `${API_PREFIX}/admin/shifts/${id}`, { data: toBackendShiftPayload(data) })
|
|
.then(result => mapApiResult(result, normalizeShift));
|
|
};
|
|
|
|
export const cancelShift = (id: number) => {
|
|
return http.request<void>("delete", `${API_PREFIX}/admin/shifts/${id}`);
|
|
};
|
|
|
|
export const listCredentialAudits = (params: CredentialAuditListParams) => {
|
|
return http
|
|
.request<
|
|
ApiResult<PaginatedData<BackendCredentialAudit>>
|
|
>("get", `${API_PREFIX}/admin/credential-audits`, { params })
|
|
.then(result =>
|
|
mapApiResult(result, data =>
|
|
mapPaginatedData(data, normalizeCredentialAudit)
|
|
)
|
|
);
|
|
};
|
|
|
|
/** 数字人运营接口,管理配置不进入前台 BFF。 */
|
|
|
|
/** 统一响应结构。 */
|
|
export type Result<T> = { success: boolean; data: T };
|
|
/** 数字人后台 API,复用已有 JWT 拦截器。 */
|
|
export async function digital<T>(
|
|
path: string,
|
|
method: "get" | "post" | "put" | "patch" | "delete" = "get",
|
|
data?: unknown
|
|
): Promise<T> {
|
|
try {
|
|
const result = await http.request<Result<T>>(
|
|
method,
|
|
`/api/digital-admin/${path}`,
|
|
data === undefined ? undefined : { data }
|
|
);
|
|
return result.data;
|
|
} catch (error) {
|
|
const response = (
|
|
error as { response?: { data?: { error?: { message?: string } } } }
|
|
).response;
|
|
throw new Error(
|
|
response?.data?.error?.message ??
|
|
(error instanceof Error ? error.message : "请求失败")
|
|
);
|
|
}
|
|
}
|
|
/** 内容编辑表单,保留完整协议字段。 */
|
|
export type Content = {
|
|
id: string;
|
|
kind: "character" | "worldbook" | "preset";
|
|
name: string;
|
|
status: string;
|
|
version?: number;
|
|
body: {
|
|
description: string;
|
|
personality: string;
|
|
scenario: string;
|
|
greeting: string;
|
|
alternateGreetings: string[];
|
|
examples: string;
|
|
systemPrompt: string;
|
|
gender: string;
|
|
age: number;
|
|
cover: string;
|
|
tags: string[];
|
|
bookIds: string[];
|
|
presetId?: string;
|
|
entries: Entry[];
|
|
temperature: number;
|
|
maxTokens: number;
|
|
contextBudget: number;
|
|
worldBudget: number;
|
|
source: string;
|
|
};
|
|
};
|
|
/** 世界书条目。 */
|
|
export type Entry = {
|
|
id: string;
|
|
name: string;
|
|
keys: string[];
|
|
secondaryKeys: string[];
|
|
content: string;
|
|
constant: boolean;
|
|
enabled: boolean;
|
|
priority: number;
|
|
position: string;
|
|
caseSensitive: boolean;
|
|
scanDepth: number;
|
|
};
|
|
/** 组比例以万分比保存,key使用A至Z,0%组仍可用于人工指定。 */
|
|
export type ExperimentGroup = { key: string; weight: number; value: unknown };
|
|
/** 测试方案:动态分组的返回值遵循已注册类型的数据契约。 */
|
|
export type Experiment = {
|
|
id: string;
|
|
name: string;
|
|
scope: string;
|
|
runtime?: string | null;
|
|
sceneName?: string;
|
|
state: "draft" | "running" | "paused" | "finished";
|
|
revision?: number;
|
|
config: {
|
|
audience: "all" | "new" | "existing" | "specified";
|
|
cutoff?: string;
|
|
accounts: string[];
|
|
traffic: number;
|
|
groups: ExperimentGroup[];
|
|
winner?: string;
|
|
description: string;
|
|
typeRevision?: number;
|
|
};
|
|
};
|
|
|
|
/** 动态注册的业务实验类型,接入状态由调用证据与人工验收共同决定。 */
|
|
export type ExperimentType = {
|
|
id: string;
|
|
name: string;
|
|
description: string;
|
|
consumerKey: string;
|
|
valueType: "string" | "number" | "boolean" | "json";
|
|
defaultValue: unknown;
|
|
contract: {
|
|
fixedValues?: { A: unknown; B: unknown };
|
|
labels?: { A: string; B: string };
|
|
optionsSource?: string;
|
|
};
|
|
enabled: number;
|
|
builtin: number;
|
|
runtime: string | null;
|
|
revision: number;
|
|
contractRevision: number;
|
|
integrationState: "pending" | "confirmed";
|
|
lastSeenAt: string | null;
|
|
lastSeenRevision: number | null;
|
|
confirmedAt: string | null;
|
|
confirmedBy: string | null;
|
|
integrationNotes: string;
|
|
hasPlans: number;
|
|
};
|
|
/** 用户分组页面的账号与只读判定。 */
|
|
export type ExperimentUser = {
|
|
account: string;
|
|
username: string;
|
|
name: string;
|
|
status: string;
|
|
createdAt: string;
|
|
decision: null | {
|
|
variant: string | null;
|
|
reason: string;
|
|
value: unknown;
|
|
revision: number;
|
|
};
|
|
override: null | {
|
|
variant: string;
|
|
reason: string;
|
|
expiresAt: string;
|
|
bypassAudience: number;
|
|
};
|
|
assignment: null | { variant: string; createdAt: string };
|
|
};
|
|
|
|
/** 独立 C 端用户的后台公开资料,不含密码/令牌或员工权限。 */
|
|
export type DigitalUser = {
|
|
id: number;
|
|
account: string;
|
|
username: string;
|
|
displayName: string;
|
|
status: "ACTIVE" | "INACTIVE";
|
|
/** 账号未保存内容偏好时默认开启,后端在生成时读取实际值。 */
|
|
nsfwEnabled?: boolean;
|
|
createdAt: string;
|
|
lastLoginAt: string | null;
|
|
conversations: number;
|
|
messages: number;
|
|
};
|
|
/** 用户所属会话的只读摘要,包含前台已删除但后台保留的记录。 */
|
|
export type UserConversation = {
|
|
id: string;
|
|
deletedAt: string | null;
|
|
title: string;
|
|
characterId: string;
|
|
characterName: string;
|
|
messages: number;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
};
|
|
/** 持久化聊天消息;包括已停止、失败和被替换的历史版本。 */
|
|
export type UserChatMessage = {
|
|
id: string;
|
|
role: "user" | "assistant";
|
|
content: string;
|
|
status: string;
|
|
pinned: number;
|
|
sequenceId: number;
|
|
createdAt: string;
|
|
};
|