feat(ctrt): 完成 CTRT-01~03 响应契约统一 - 三端拦截器+portal_token清理+调用点适配
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// =============================================================================
|
||||
// 企微IT智能服务台 — 阶段5 自动化闭环 状态管理(Pinia Store,管理后台)
|
||||
// =============================================================================
|
||||
// 说明:管理自动化场景配置、规则版本、运营指标。
|
||||
// 约定:api 返回包装对象,调用方统一从 res.data.data 取业务数据。
|
||||
// =============================================================================
|
||||
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type {
|
||||
ScenarioConfig,
|
||||
RuleVersion,
|
||||
AutoMetrics,
|
||||
UpdateScenarioPayload,
|
||||
PublishVersionPayload,
|
||||
} from '@/api/automation'
|
||||
import {
|
||||
getAutomationConfigs,
|
||||
updateAutomationConfig,
|
||||
publishConfigVersion,
|
||||
getConfigVersions,
|
||||
getAutomationMetrics,
|
||||
} from '@/api/automation'
|
||||
|
||||
export const useAutomationStore = defineStore('automation', () => {
|
||||
// ------------------------------------------------------------------------
|
||||
// 状态
|
||||
// ------------------------------------------------------------------------
|
||||
const scenarios = ref<ScenarioConfig[]>([])
|
||||
const versions = ref<RuleVersion[]>([])
|
||||
const metrics = ref<AutoMetrics | null>(null)
|
||||
const loading = ref(false)
|
||||
const currentScenarioKey = ref<string>('')
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 配置(场景开关)
|
||||
// ------------------------------------------------------------------------
|
||||
async function loadScenarios(): Promise<void> {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await getAutomationConfigs()
|
||||
scenarios.value = res.data.data
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function updateScenario(
|
||||
id: string,
|
||||
payload: UpdateScenarioPayload,
|
||||
): Promise<ScenarioConfig> {
|
||||
const res = await updateAutomationConfig(id, payload)
|
||||
const updated = res.data.data
|
||||
// 本地同步,避免整表刷新
|
||||
const idx = scenarios.value.findIndex((s) => s.id === id)
|
||||
if (idx >= 0) scenarios.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 规则版本(灰度)
|
||||
// ------------------------------------------------------------------------
|
||||
async function loadVersions(scenarioKey: string): Promise<void> {
|
||||
currentScenarioKey.value = scenarioKey
|
||||
const res = await getConfigVersions(scenarioKey)
|
||||
versions.value = res.data.data
|
||||
}
|
||||
|
||||
async function publishVersion(
|
||||
id: string,
|
||||
payload: PublishVersionPayload,
|
||||
): Promise<RuleVersion> {
|
||||
const res = await publishConfigVersion(id, payload)
|
||||
const created = res.data.data
|
||||
versions.value.unshift(created)
|
||||
return created
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 指标
|
||||
// ------------------------------------------------------------------------
|
||||
async function loadMetrics(): Promise<void> {
|
||||
const res = await getAutomationMetrics()
|
||||
metrics.value = res.data.data
|
||||
}
|
||||
|
||||
return {
|
||||
scenarios,
|
||||
versions,
|
||||
metrics,
|
||||
loading,
|
||||
currentScenarioKey,
|
||||
loadScenarios,
|
||||
updateScenario,
|
||||
loadVersions,
|
||||
publishVersion,
|
||||
loadMetrics,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user