100 lines
3.1 KiB
TypeScript
100 lines
3.1 KiB
TypeScript
import request from '@/config/axios'
|
|||
|
|
import type { MenuVO } from '@/api/system/menu'
|
||
|
|
import type { RoleVO } from '@/api/system/role'
|
||
|
|
import type { TagVO } from '@/api/system/tag'
|
||
|
|
|
||
|
|
/** 配置范围与后端枚举保持一致,仅用于文件和本次操作。 */
|
||
|
|
export enum ApplicationConfigSection {
|
||
|
|
MENUS = 'MENUS',
|
||
|
|
ROLES = 'ROLES',
|
||
|
|
TAGS = 'TAGS'
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 应用注册下独立授权的配置迁移按钮。 */
|
||
|
|
export const ApplicationConfigPermission = {
|
||
|
|
EXPORT: 'system:application:config-export',
|
||
|
|
IMPORT: 'system:application:config-import'
|
||
|
|
} as const
|
||
|
|
|
||
|
|
export const applicationConfigSections = [
|
||
|
|
{ value: ApplicationConfigSection.MENUS, label: '菜单配置' },
|
||
|
|
{ value: ApplicationConfigSection.ROLES, label: '角色配置(含权限绑定)' },
|
||
|
|
{ value: ApplicationConfigSection.TAGS, label: '数据权限定义' }
|
||
|
|
]
|
||
|
|
|
||
|
|
/** 与后端导入策略保持一致。 */
|
||
|
|
export enum ApplicationConfigImportMode {
|
||
|
|
MERGE = 'MERGE',
|
||
|
|
REPLACE = 'REPLACE'
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 完整应用配置文件,引用现有字段,不包含人员授权、密钥或接入配置。 */
|
||
|
|
export interface ApplicationConfigPackage {
|
||
|
|
formatVersion: number
|
||
|
|
complete: boolean
|
||
|
|
sections?: ApplicationConfigSection[]
|
||
|
|
applicationName: string
|
||
|
|
applicationCode: string
|
||
|
|
menus: Omit<MenuVO, 'createTime'>[]
|
||
|
|
roles: Omit<RoleVO, 'createTime' | 'tags'>[]
|
||
|
|
tags: Omit<TagVO, 'createTime' | 'roleCount'>[]
|
||
|
|
roleMenus: { roleId: number; menuId: number }[]
|
||
|
|
roleTags: { roleId: number; tagId: number; tagValue?: string }[]
|
||
|
|
departments: { id: number; name: string; orgCode?: string }[]
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ApplicationConfigChange {
|
||
|
|
category: string
|
||
|
|
action: string
|
||
|
|
name: string
|
||
|
|
detail: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ApplicationConfigDeptMapping {
|
||
|
|
sourceId: number
|
||
|
|
sourceName: string
|
||
|
|
sourceCode?: string
|
||
|
|
targetId?: number
|
||
|
|
targetName?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ApplicationConfigPreview {
|
||
|
|
token?: string
|
||
|
|
sourceName: string
|
||
|
|
sourceCode: string
|
||
|
|
targetName: string
|
||
|
|
targetCode: string
|
||
|
|
codeMismatch: boolean
|
||
|
|
changes: ApplicationConfigChange[]
|
||
|
|
errors: string[]
|
||
|
|
warnings: string[]
|
||
|
|
departments: ApplicationConfigDeptMapping[]
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 按实际变更在后端逐项校验已有增删改与授权权限。 */
|
||
|
|
export const previewApplicationConfig = (data: {
|
||
|
|
applicationId: number
|
||
|
|
mode: ApplicationConfigImportMode
|
||
|
|
sections: ApplicationConfigSection[]
|
||
|
|
config: ApplicationConfigPackage
|
||
|
|
departmentMappings: Record<number, number>
|
||
|
|
includePresets: boolean
|
||
|
|
}): Promise<ApplicationConfigPreview> =>
|
||
|
|
request.post({ url: '/system/application/config/preview', data })
|
||
|
|
|
||
|
|
export const exportApplicationConfig = (
|
||
|
|
applicationId: number,
|
||
|
|
sections?: ApplicationConfigSection[]
|
||
|
|
): Promise<ApplicationConfigPackage> =>
|
||
|
|
request.get({
|
||
|
|
url: '/system/application/config/export',
|
||
|
|
params: { applicationId, sections: sections?.join(',') }
|
||
|
|
})
|
||
|
|
|
||
|
|
/** 正式执行只提交服务端凭证,不能在确认后偷偷更换文件或目标。 */
|
||
|
|
export const importApplicationConfig = (
|
||
|
|
token: string,
|
||
|
|
confirmCodeMismatch: boolean
|
||
|
|
): Promise<boolean> =>
|
||
|
|
request.post({ url: '/system/application/config/import', data: { token, confirmCodeMismatch } })
|