feat: 风险规则增加上传按钮+对应后端接口(七牛云)
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
<h2 style="margin:0">编辑: {{ editType }}</h2>
|
||||
<div style="display:flex;gap:8px">
|
||||
<el-button size="small" type="primary" @click="saveRules" :loading="saving">保存</el-button>
|
||||
<el-button size="small" @click="uploadRules" :loading="uploading">上传</el-button>
|
||||
<el-button size="small" @click="editType=''">返回列表</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -80,7 +81,7 @@
|
||||
<script setup>
|
||||
import api from '../api'; import { Refresh } from '@element-plus/icons-vue'
|
||||
|
||||
const loading = ref(false), saving = ref(false), sites = ref([]), rulesMap = ref({})
|
||||
const loading = ref(false), saving = ref(false), uploading = ref(false), sites = ref([]), rulesMap = ref({})
|
||||
const editType = ref(''), editorJson = ref('[]')
|
||||
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
|
||||
const parsed = computed(() => { try { return JSON.parse(editorJson.value) } catch { return [] } })
|
||||
@@ -113,6 +114,13 @@ const editRule = async (row) => {
|
||||
const sync = () => { editorJson.value = JSON.stringify(parsed.value, null, 2) }
|
||||
const remove = (idx) => { parsed.value.splice(idx,1); sync() }
|
||||
const addRule = () => { parsed.value.push({type:'TRAFFIC',name:'',metric:'',threshold:0,unit:'DAY',condition:'GT',level:'WARN'}); sync() }
|
||||
const uploadRules = async () => {
|
||||
uploading.value = true
|
||||
try { await api.raw.post('/risk-rules/'+editType.value+'/upload', { rules: parsed.value }); ElMessage.success('已上传') }
|
||||
catch { ElMessage.error('上传失败') }
|
||||
finally { uploading.value = false }
|
||||
}
|
||||
|
||||
const saveRules = async () => {
|
||||
saving.value = true
|
||||
try { await api.raw.post('/risk-rules/'+editType.value, { rules: parsed.value }); ElMessage.success('已保存'); editType.value=''; fetchAll() }
|
||||
|
||||
Reference in New Issue
Block a user