fix: 页面配置合并站点列表+风险规则默认全类型+修复api.raw调用
This commit is contained in:
@@ -4,15 +4,14 @@
|
||||
<el-card style="margin-top:20px">
|
||||
<div style="margin-bottom:12px;display:flex;gap:8px">
|
||||
<el-button @click="fetchAll" :loading="loading">刷新</el-button>
|
||||
<el-button type="primary" @click="showEditor('')">新建</el-button>
|
||||
</div>
|
||||
|
||||
<el-table :data="rules" stripe size="small" v-loading="loading" empty-text="暂无规则">
|
||||
<el-table :data="merged" stripe size="small" v-loading="loading" empty-text="暂无规则">
|
||||
<el-table-column prop="siteType" label="站点类型" width="120" />
|
||||
<el-table-column prop="version" label="版本" width="80" />
|
||||
<el-table-column label="规则数" width="80">
|
||||
<el-table-column prop="version" label="版本" width="80" align="center" />
|
||||
<el-table-column label="规则数" width="80" align="center">
|
||||
<template #default="s">
|
||||
<el-tag size="small">{{ getRuleCount(s.row) }}</el-tag>
|
||||
<el-tag size="small">{{ s.row.ruleCount || 0 }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="更新时间" width="160">
|
||||
@@ -20,14 +19,13 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="s">
|
||||
<el-button size="small" @click="showEditor(s.row.siteType, s.row)">编辑</el-button>
|
||||
<el-button size="small" type="danger" text @click="deleteRules(s.row.siteType)">删除</el-button>
|
||||
<el-button size="small" @click="showEditor(s.row)">编辑</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="editorVisible" :title="editorTitle" width="900px" destroy-on-close>
|
||||
<el-dialog v-model="editorVisible" :title="'风险规则: ' + editorType" width="900px" destroy-on-close>
|
||||
<el-table :data="editingRules" stripe size="small" style="margin-bottom:12px">
|
||||
<el-table-column prop="type" label="类型" width="90">
|
||||
<template #default="s"><el-select v-model="s.row.type" size="small"><el-option v-for="x in ['KILL','TRAFFIC','RATIO','LOGIN','HD']" :key="x" :label="x" :value="x"/></el-select></template>
|
||||
@@ -44,8 +42,8 @@
|
||||
<el-table-column prop="unit" label="单位" width="70">
|
||||
<template #default="s"><el-input v-model="s.row.unit" size="small" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="condition" label="条件" width="70">
|
||||
<template #default="s"><el-select v-model="s.row.condition" size="small"><el-option v-for="x in ['GT','LT','GTE','LTE','EQ']" :key="x" :label="x" :value="x"/></el-select></template>
|
||||
<el-table-column prop="condition" label="条件" width="80">
|
||||
<template #default="s"><el-select v-model="s.row.condition" size="small"><el-option v-for="x in ['GT','LT','GTE','LTE']" :key="x" :label="x" :value="x"/></el-select></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="level" label="级别" width="90">
|
||||
<template #default="s"><el-select v-model="s.row.level" size="small"><el-option v-for="x in ['CRITICAL','WARN','INFO']" :key="x" :label="x" :value="x"/></el-select></template>
|
||||
@@ -65,40 +63,48 @@
|
||||
<script setup>
|
||||
import api from '../api'
|
||||
|
||||
const loading = ref(false), saving = ref(false), rules = ref([])
|
||||
const editorVisible = ref(false), editorType = ref(''), editorTitle = ref('')
|
||||
const loading = ref(false), saving = ref(false)
|
||||
const rulesData = ref([])
|
||||
const siteTypes = ['nexusphp','mtorrent','gazelle','unit3d']
|
||||
const editorVisible = ref(false), editorType = ref('')
|
||||
const editingRules = ref([])
|
||||
|
||||
const fmt = (t) => t ? t.substring(0,19).replace('T',' ') : '-'
|
||||
const getRuleCount = (row) => { try { return JSON.parse(row.rulesJson || '[]').length } catch { return 0 } }
|
||||
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
|
||||
|
||||
const merged = computed(() => {
|
||||
const map = {}
|
||||
for (const r of rulesData.value) {
|
||||
const cnt = (() => { try { return JSON.parse(r.rulesJson || '[]').length } catch { return 0 } })()
|
||||
map[r.siteType] = { siteType: r.siteType, version: r.version, ruleCount: cnt, updatedAt: r.updatedAt, rulesJson: r.rulesJson }
|
||||
}
|
||||
// 补充未配置的类型
|
||||
for (const t of siteTypes) {
|
||||
if (!map[t]) map[t] = { siteType: t, version: null, ruleCount: 0, updatedAt: null, rulesJson: null }
|
||||
}
|
||||
return Object.values(map)
|
||||
})
|
||||
|
||||
const fetchAll = async () => {
|
||||
loading.value = true
|
||||
try { rules.value = (await api.get('/admin/risk-rules')).data || [] }
|
||||
catch { ElMessage.error('加载失败') }
|
||||
try {
|
||||
const r = await api.raw.get('/admin/risk-rules')
|
||||
rulesData.value = (r.data || r || [])
|
||||
} catch { ElMessage.error('加载失败') }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
const showEditor = (siteType, row) => {
|
||||
editorType.value = siteType
|
||||
editorTitle.value = siteType ? '编辑: ' + siteType : '新建风险规则'
|
||||
if (row) {
|
||||
try { editingRules.value = JSON.parse(JSON.stringify(JSON.parse(row.rulesJson || '[]'))) }
|
||||
catch { editingRules.value = [] }
|
||||
} else {
|
||||
editingRules.value = [{type:'KILL',name:'',metric:'',threshold:0,unit:'DAY',condition:'GT',level:'CRITICAL'}]
|
||||
}
|
||||
const showEditor = (row) => {
|
||||
editorType.value = row.siteType
|
||||
try { editingRules.value = JSON.parse(JSON.stringify(JSON.parse(row.rulesJson || '[]'))) }
|
||||
catch { editingRules.value = [{type:'KILL',name:'',metric:'',threshold:0,unit:'DAY',condition:'GT',level:'CRITICAL'}] }
|
||||
if (editingRules.value.length === 0) editingRules.value.push({type:'KILL',name:'',metric:'',threshold:0,unit:'DAY',condition:'GT',level:'CRITICAL'})
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
const editTypeInput = ref('')
|
||||
|
||||
const saveRules = async () => {
|
||||
const t = editorType.value || editTypeInput.value
|
||||
if (!t) { ElMessage.warning('请输入站点类型'); return }
|
||||
saving.value = true
|
||||
try {
|
||||
await api.post('/risk-rules/' + t, { rules: editingRules.value })
|
||||
await api.raw.post('/risk-rules/' + editorType.value, { rules: editingRules.value })
|
||||
ElMessage.success('已保存')
|
||||
editorVisible.value = false
|
||||
fetchAll()
|
||||
@@ -106,14 +112,5 @@ const saveRules = async () => {
|
||||
finally { saving.value = false }
|
||||
}
|
||||
|
||||
const deleteRules = async (siteType) => {
|
||||
if (!await ElMessageBox.confirm('确认删除 ' + siteType + ' 的风险规则?', '删除', { type: 'warning', confirmButtonText: '确定' }).catch(() => null)) return
|
||||
try {
|
||||
await api.delete('/admin/risk-rules/' + siteType)
|
||||
ElMessage.success('已删除')
|
||||
fetchAll()
|
||||
} catch { ElMessage.error('删除失败') }
|
||||
}
|
||||
|
||||
onMounted(fetchAll)
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user