初始提交:OCI 面板前端(含 GenAI 网关一期)
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import {
|
||||
mockNotifyEvents,
|
||||
mockSecuritySetting,
|
||||
mockSystemLogs,
|
||||
mockTaskSetting,
|
||||
mockTelegramSetting,
|
||||
} from './mock'
|
||||
import { mockOn, mocked, request } from './request'
|
||||
import type {
|
||||
AboutInfo,
|
||||
NotifyEventsSetting,
|
||||
NotifyTemplateItem,
|
||||
SecuritySetting,
|
||||
SystemLogPage,
|
||||
TaskSetting,
|
||||
TelegramSetting,
|
||||
} from '@/types/api'
|
||||
|
||||
export function getTelegramSetting(): Promise<TelegramSetting> {
|
||||
if (mockOn) return mocked({ ...mockTelegramSetting })
|
||||
return request('/settings/telegram')
|
||||
}
|
||||
|
||||
export interface UpdateTelegramBody {
|
||||
enabled: boolean
|
||||
/** 缺省表示沿用已保存的 token,空串表示清除 */
|
||||
botToken?: string
|
||||
chatId: string
|
||||
}
|
||||
|
||||
export function updateTelegramSetting(body: UpdateTelegramBody): Promise<TelegramSetting> {
|
||||
if (mockOn) {
|
||||
mockTelegramSetting.enabled = body.enabled
|
||||
mockTelegramSetting.chatId = body.chatId
|
||||
if (body.botToken !== undefined) {
|
||||
mockTelegramSetting.tokenSet = body.botToken !== ''
|
||||
mockTelegramSetting.tokenTail = body.botToken.length >= 8 ? body.botToken.slice(-4) : ''
|
||||
}
|
||||
return mocked({ ...mockTelegramSetting }, 400)
|
||||
}
|
||||
return request('/settings/telegram', { method: 'PUT', body })
|
||||
}
|
||||
|
||||
export function testTelegram(): Promise<void> {
|
||||
if (mockOn) return mocked(undefined, 800)
|
||||
return request('/settings/telegram/test', { method: 'POST' })
|
||||
}
|
||||
|
||||
export function getNotifyEvents(): Promise<NotifyEventsSetting> {
|
||||
if (mockOn) return mocked({ ...mockNotifyEvents })
|
||||
return request('/settings/notify-events')
|
||||
}
|
||||
|
||||
/** 全量保存五个事件开关,返回最新值 */
|
||||
export function updateNotifyEvents(body: NotifyEventsSetting): Promise<NotifyEventsSetting> {
|
||||
if (mockOn) {
|
||||
Object.assign(mockNotifyEvents, body)
|
||||
return mocked({ ...mockNotifyEvents }, 400)
|
||||
}
|
||||
return request('/settings/notify-events', { method: 'PUT', body })
|
||||
}
|
||||
|
||||
export function listNotifyTemplates(): Promise<NotifyTemplateItem[]> {
|
||||
if (mockOn)
|
||||
return mocked([
|
||||
{
|
||||
kind: 'task_fail',
|
||||
label: '任务失败',
|
||||
vars: ['task_name', 'error'],
|
||||
defaultTemplate: '❌ 任务失败:{{task_name}}\n{{error}}',
|
||||
template: '',
|
||||
},
|
||||
])
|
||||
return request<{ items: NotifyTemplateItem[] }>('/settings/notify-templates').then((r) => r.items)
|
||||
}
|
||||
|
||||
/** 保存单个通知模板;空串清除自定义(恢复默认) */
|
||||
export function updateNotifyTemplate(kind: string, template: string): Promise<void> {
|
||||
if (mockOn) return mocked(undefined, 300)
|
||||
return request(`/settings/notify-templates/${kind}`, { method: 'PUT', body: { template } })
|
||||
}
|
||||
|
||||
/** 用示例变量渲染并发送测试消息;template 非空时按编辑中内容渲染(不落库) */
|
||||
export function testNotifyTemplate(kind: string, template: string): Promise<void> {
|
||||
if (mockOn) return mocked(undefined, 600)
|
||||
return request(`/settings/notify-templates/${kind}/test`, { method: 'POST', body: { template } })
|
||||
}
|
||||
|
||||
export function getTaskSetting(): Promise<TaskSetting> {
|
||||
if (mockOn) return mocked({ ...mockTaskSetting })
|
||||
return request('/settings/task')
|
||||
}
|
||||
|
||||
/** 保存任务行为设置,返回最新值;阈值越界(1-10 之外)后端返回 400 */
|
||||
export function updateTaskSetting(body: TaskSetting): Promise<TaskSetting> {
|
||||
if (mockOn) {
|
||||
Object.assign(mockTaskSetting, body)
|
||||
return mocked({ ...mockTaskSetting }, 400)
|
||||
}
|
||||
return request('/settings/task', { method: 'PUT', body })
|
||||
}
|
||||
|
||||
export function getSecuritySetting(): Promise<SecuritySetting> {
|
||||
if (mockOn) return mocked({ ...mockSecuritySetting })
|
||||
return request('/settings/security')
|
||||
}
|
||||
|
||||
/** 保存安全设置,返回最新值;越界或非法后端返回 400,保存后立即生效 */
|
||||
export function updateSecuritySetting(body: SecuritySetting): Promise<SecuritySetting> {
|
||||
if (mockOn) {
|
||||
Object.assign(mockSecuritySetting, body)
|
||||
return mocked({ ...mockSecuritySetting }, 400)
|
||||
}
|
||||
return request('/settings/security', { method: 'PUT', body })
|
||||
}
|
||||
|
||||
export interface SystemLogParams {
|
||||
page: number
|
||||
pageSize: number
|
||||
/** 关键字,对路径与用户名模糊匹配 */
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
export function listSystemLogs(params: SystemLogParams): Promise<SystemLogPage> {
|
||||
if (mockOn) {
|
||||
const kw = (params.keyword ?? '').toLowerCase()
|
||||
const filtered = kw
|
||||
? mockSystemLogs.filter(
|
||||
(l) => l.path.toLowerCase().includes(kw) || l.username.toLowerCase().includes(kw),
|
||||
)
|
||||
: mockSystemLogs
|
||||
const start = (params.page - 1) * params.pageSize
|
||||
return mocked({
|
||||
items: filtered.slice(start, start + params.pageSize),
|
||||
total: filtered.length,
|
||||
})
|
||||
}
|
||||
return request('/system-logs', { query: { ...params } })
|
||||
}
|
||||
|
||||
// ---- 关于 ----
|
||||
/** 构建与运行环境信息(设置 · 关于) */
|
||||
export function getAbout(): Promise<AboutInfo> {
|
||||
if (mockOn)
|
||||
return mocked({
|
||||
version: 'v1.0.0',
|
||||
buildTime: '2026-07-09T12:00Z',
|
||||
goVersion: 'go1.26.4',
|
||||
platform: 'linux/amd64',
|
||||
})
|
||||
return request('/about')
|
||||
}
|
||||
Reference in New Issue
Block a user