diff --git a/web/src/views/RiskRules.vue b/web/src/views/RiskRules.vue index e48026c..e9cd1b3 100644 --- a/web/src/views/RiskRules.vue +++ b/web/src/views/RiskRules.vue @@ -26,34 +26,47 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - +
+ + 表格编辑 + JSON 编辑 + +
+ +
- + 添加规则 保存
@@ -66,9 +79,16 @@ import api from '../api' const loading = ref(false), saving = ref(false) const rulesData = ref([]) const siteTypes = ['nexusphp','mtorrent','gazelle','unit3d'] -const editorVisible = ref(false), editorType = ref('') +const editorVisible = ref(false), editorType = ref(''), editorMode = ref('table'), editorJson = ref('') const editingRules = ref([]) +watch(editorMode, (m) => { + if (m === 'json') editorJson.value = JSON.stringify(editingRules.value, null, 2) + else { + try { editingRules.value = JSON.parse(editorJson.value) } catch { /* keep table */ } + } +}) + const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-' const merged = computed(() => { @@ -104,7 +124,8 @@ const showEditor = (row) => { const saveRules = async () => { saving.value = true try { - await api.raw.post('/risk-rules/' + editorType.value, { rules: editingRules.value }) + const rules = editorMode.value === 'json' ? JSON.parse(editorJson.value) : editingRules.value + await api.raw.post('/risk-rules/' + editorType.value, { rules }) ElMessage.success('已保存') editorVisible.value = false fetchAll() diff --git a/web/src/views/SitePages.vue b/web/src/views/SitePages.vue index 6130fc4..f1ce44f 100644 --- a/web/src/views/SitePages.vue +++ b/web/src/views/SitePages.vue @@ -28,26 +28,39 @@ - - - - - - - - - - - - - - - - - - + +
+ + 表格编辑 + JSON 编辑 + +
+ +
- + 添加入口 保存
@@ -59,7 +72,15 @@ import api from '../api' const loading = ref(false), saving = ref(false) const sites = ref([]), pagesMap = ref({}) -const editorVisible = ref(false), editorSiteId = ref(''), editingEntries = ref([]) +const editorVisible = ref(false), editorSiteId = ref(''), editorMode = ref('table'), editorJson = ref('') +const editingEntries = ref([]) + +watch(editorMode, (m) => { + if (m === 'json') editorJson.value = JSON.stringify(editingEntries.value, null, 2) + else { + try { editingEntries.value = JSON.parse(editorJson.value) } catch { /* keep table data */ } + } +}) const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-' @@ -104,7 +125,8 @@ const showEditor = (row) => { const savePages = async () => { saving.value = true try { - await api.raw.put('/sites/' + editorSiteId.value + '/pages', { entries: editingEntries.value }) + const entries = editorMode.value === 'json' ? JSON.parse(editorJson.value) : editingEntries.value + await api.raw.put('/sites/' + editorSiteId.value + '/pages', { entries }) ElMessage.success('已保存') editorVisible.value = false fetchAll()