role.ts 1.28 KB
// 角色与权限矩阵接口(PRD §7 角色管理,权限矩阵在详情抽屉内配置)
// 继承 ApiClient,共享 http 与 RSA 加签/验签。
import { ApiClient } from '../core/client';
import type { PageResult } from '../core/types';

export interface RoleItem {
  id: string;
  roleName: string;
  roleCode: string;
  remark?: string;
  createTime?: string;
}

export interface PermissionMatrix {
  roleId: string;
  groups: {
    group: string;
    items: { key: string; label: string; checked: boolean }[];
  }[];
}

class Role extends ApiClient {
  list(params: Record<string, unknown> = {}) {
    return this.get<PageResult<RoleItem>>('/store/role/list', params);
  }

  create(payload: Partial<RoleItem>) {
    return this.post<string>('/store/role/create', payload);
  }

  update(id: string, payload: Partial<RoleItem>) {
    return this.post<null>('/store/role/update', { id, ...payload });
  }

  remove(id: string) {
    return this.del<null>(`/store/role/delete/${id}`);
  }

  getPermissions(roleId: string) {
    return this.get<PermissionMatrix>('/store/role/permissions', { roleId });
  }

  savePermissions(roleId: string, groups: PermissionMatrix['groups']) {
    return this.post<null>('/store/role/permissions/save', { roleId, groups });
  }
}

export const role = new Role();