127 lines
5.1 KiB
TypeScript
127 lines
5.1 KiB
TypeScript
import { get, post } from './request'
|
||
|
||
/** 应用/功能市场项 */
|
||
export interface AppItem {
|
||
AppUUID: string
|
||
AppCode: string
|
||
AppName: string
|
||
AppIcon: string
|
||
AppDesc: string
|
||
AppType: string
|
||
AuthRequired: number
|
||
MenuRootUUID?: string
|
||
AppSort?: number
|
||
/** 前端入口(真应用注册协议:安装后"打开应用"跳转目标) */
|
||
FrontendRoute?: string
|
||
FrontendType?: string
|
||
LegacySrc?: string
|
||
/** 市场页附加状态 */
|
||
TenantInstalled?: number
|
||
TenantAuth?: number
|
||
/** 指定公司安装状态(当前公司维度) */
|
||
CompanyInstalled?: number
|
||
/** 管理员视角:可管理范围内已装该应用的公司名列表(非管理员为空) */
|
||
InstalledCompanies?: string[]
|
||
UserEnabled?: number
|
||
ApplyStatus?: number
|
||
}
|
||
|
||
/** 管理员可安装应用的公司范围项 */
|
||
export interface CompanyScopeItem {
|
||
CompanyUUID: string
|
||
CompanyName: string
|
||
CompanyShort: string
|
||
/** 指定应用在各公司的安装状态(ManageCompanies 传 AppUUID 时返回) */
|
||
Installed?: number
|
||
}
|
||
|
||
/** RAM 角色粒度授权候选(当前租户启用角色) */
|
||
export interface RoleScopeItem {
|
||
RoleUUID: string
|
||
RoleName: string
|
||
}
|
||
|
||
/** 个人授权申请项(租户管理员审批台) */
|
||
export interface PendingItem {
|
||
UserAppUUID: string
|
||
UserUUID: string
|
||
AppUUID: string
|
||
AppName: string
|
||
AppCode: string
|
||
AppIcon: string
|
||
ApplyTime: string | null
|
||
}
|
||
|
||
/** 应用配置项(AppConfig 键值表) */
|
||
export interface AppConfigItem {
|
||
Key: string
|
||
Label: string
|
||
Value: string
|
||
Default: string
|
||
Secret: number
|
||
Placeholder: string
|
||
Updated: boolean
|
||
}
|
||
|
||
/** 应用/功能 API 客户端 */
|
||
export const appApi = {
|
||
/** 应用市场列表(附租户/公司安装/个人启用/申请状态) */
|
||
market: (): Promise<{ list: AppItem[]; total: number }> => get<{ list: AppItem[]; total: number }>('/API/App/Market'),
|
||
|
||
/** 我的应用(当前用户可用) */
|
||
myApps: (): Promise<{ list: AppItem[]; total: number }> => get<{ list: AppItem[]; total: number }>('/API/App/MyApps'),
|
||
|
||
/** 管理员可安装应用的公司列表(按权限范围)+ 租户角色列表(RAM 授权候选);
|
||
* 传 AppUUID 时附带各公司安装状态(Installed),供管理弹窗用 */
|
||
manageCompanies: (AppUUID?: string): Promise<{ Scope: string; Companies: CompanyScopeItem[]; Roles: RoleScopeItem[] }> =>
|
||
get<{ Scope: string; Companies: CompanyScopeItem[]; Roles: RoleScopeItem[] }>(
|
||
'/API/App/ManageCompanies',
|
||
AppUUID ? { AppUUID } : {},
|
||
),
|
||
|
||
/** 管理员:安装企业功能(不传 CompanyUUIDs=全租户;传 CompanyUUIDs=指定公司);
|
||
* GrantRoles=RAM 角色粒度授权(可选):指定角色可见该应用(安装范围内) */
|
||
install: (AppUUID: string, CompanyUUIDs?: string[], GrantRoles?: string[]): Promise<AppItem> =>
|
||
post<AppItem>('/API/App/Install', { AppUUID, CompanyUUIDs: CompanyUUIDs || [], GrantRoles: GrantRoles || [] }),
|
||
|
||
/** 管理员:停用企业功能(传 CompanyUUIDs=停用指定公司;TenantOnly=仅停用全租户;都不传=停全租户+当前公司) */
|
||
uninstall: (AppUUID: string, CompanyUUIDs?: string[], TenantOnly?: boolean): Promise<void> =>
|
||
post<void>('/API/App/Uninstall', { AppUUID, CompanyUUIDs: CompanyUUIDs || [], TenantOnly }),
|
||
|
||
/** 个人:启用应用 */
|
||
enable: (AppUUID: string): Promise<AppItem> => post<AppItem>('/API/App/Enable', { AppUUID }),
|
||
|
||
/** 个人:停用应用 */
|
||
disable: (AppUUID: string): Promise<void> => post<void>('/API/App/Disable', { AppUUID }),
|
||
|
||
/** 个人:申请企业授权 */
|
||
apply: (AppUUID: string): Promise<void> => post<void>('/API/App/Apply', { AppUUID }),
|
||
|
||
/** 租户管理员:审批个人授权申请 */
|
||
approve: (UserAppUUID: string, Approved: boolean): Promise<void> =>
|
||
post<void>('/API/App/Approve', { UserAppUUID, Approved }),
|
||
|
||
/** 租户管理员:待审批申请列表 */
|
||
pending: (): Promise<{ list: PendingItem[]; total: number }> => get<{ list: PendingItem[]; total: number }>('/API/App/Pending'),
|
||
|
||
/** 应用配置:读取(GET,CompanyUUID 可选——空=租户默认配置)/保存(POST,可指定公司) */
|
||
config: (AppUUID: string, CompanyUUID?: string): Promise<{ Configs: AppConfigItem[]; Total: number; Scope: string; CompanyUUID: string }> =>
|
||
get<{ Configs: AppConfigItem[]; Total: number; Scope: string; CompanyUUID: string }>(
|
||
'/API/App/Config',
|
||
CompanyUUID ? { AppUUID, CompanyUUID } : { AppUUID },
|
||
),
|
||
saveConfig: (AppUUID: string, Config: Record<string, string>, CompanyUUID?: string): Promise<{ Updated: string[] }> =>
|
||
post<{ Updated: string[] }>(
|
||
'/API/App/Config',
|
||
CompanyUUID ? { AppUUID, Config, CompanyUUID } : { AppUUID, Config },
|
||
),
|
||
/** 配置批量复制:把源配置(空=租户默认)复制到目标公司(覆盖同名键) */
|
||
copyConfig: (AppUUID: string, TargetCompanyUUIDs: string[], SourceCompanyUUID?: string): Promise<{ Copied: number }> =>
|
||
post<{ Copied: number }>(
|
||
'/API/App/Config/Copy',
|
||
SourceCompanyUUID
|
||
? { AppUUID, TargetCompanyUUIDs, SourceCompanyUUID }
|
||
: { AppUUID, TargetCompanyUUIDs },
|
||
),
|
||
}
|