refactor: 页面配置+风险规则改用纯CodeEditor(去掉表格模式)
This commit is contained in:
@@ -50,25 +50,11 @@
|
||||
<div v-if="editSiteId" style="margin-top:16px;padding:12px;background:#fafafa;border-radius:4px">
|
||||
<div style="margin-bottom:8px;display:flex;gap:8px;align-items:center">
|
||||
<strong>编辑: {{ editSiteId }}</strong>
|
||||
<el-radio-group v-model="editorMode" size="small">
|
||||
<el-radio-button label="table">表格</el-radio-button>
|
||||
<el-radio-button label="json">JSON</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<template v-if="editorMode==='table'">
|
||||
<el-table :data="editingEntries" stripe size="small" style="margin-bottom:8px">
|
||||
<el-table-column prop="key" label="key" width="100"><template #default="e"><el-input v-model="e.row.key" size="small"/></template></el-table-column>
|
||||
<el-table-column prop="label" label="名称" width="100"><template #default="e"><el-input v-model="e.row.label" size="small"/></template></el-table-column>
|
||||
<el-table-column prop="url" label="URL" min-width="200"><template #default="e"><el-input v-model="e.row.url" size="small"/></template></el-table-column>
|
||||
<el-table-column prop="method" label="方法" width="80"><template #default="e"><el-select v-model="e.row.method" size="small"><el-option label="GET" value="GET"/><el-option label="POST" value="POST"/></el-select></template></el-table-column>
|
||||
<el-table-column label="" width="50"><template #default="e"><el-button size="small" type="danger" text @click="editingEntries.splice(e.$index,1)">×</el-button></template></el-table-column>
|
||||
</el-table>
|
||||
<el-button size="small" @click="editingEntries.push({key:'',label:'',url:'{base}',method:'GET'})">+ 添加</el-button>
|
||||
</template>
|
||||
<div v-else style="height:300px;border-radius:4px;overflow:hidden;margin-bottom:8px">
|
||||
<div style="height:400px;border-radius:4px;overflow:hidden;margin-bottom:8px">
|
||||
<CodeEditor v-model="editorJson" language="json" />
|
||||
</div>
|
||||
<div style="margin-top:8px;display:flex;gap:8px">
|
||||
<div style="display:flex;gap:8px">
|
||||
<el-button size="small" type="primary" @click="savePages" :loading="saving">保存</el-button>
|
||||
<el-button size="small" @click="editSiteId=''">取消</el-button>
|
||||
</div>
|
||||
@@ -88,8 +74,7 @@ import api from '../api'
|
||||
|
||||
const loading = ref(false), saving = ref(false)
|
||||
const sites = ref([]), pagesMap = ref({})
|
||||
const editSiteId = ref(''), editorMode = ref('table'), editorJson = ref('')
|
||||
const editingEntries = ref([])
|
||||
const editSiteId = ref(''), editorJson = ref('')
|
||||
|
||||
const defaultPages = {
|
||||
nexusphp: [
|
||||
@@ -121,11 +106,6 @@ const defaults = computed(() => {
|
||||
|
||||
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
|
||||
|
||||
watch(editorMode, (m) => {
|
||||
if (m === 'json') editorJson.value = JSON.stringify(editingEntries.value, null, 2)
|
||||
else { try { editingEntries.value = JSON.parse(editorJson.value) } catch {} }
|
||||
})
|
||||
|
||||
const merged = computed(() => {
|
||||
return (Array.isArray(sites.value)?sites.value:[]).map(s => ({
|
||||
siteId: s.siteId,
|
||||
@@ -157,17 +137,13 @@ const fetchAll = async () => {
|
||||
|
||||
const loadDefault = (row) => {
|
||||
editSiteId.value = row.siteId
|
||||
editingEntries.value = JSON.parse(JSON.stringify(defaultPages[row.siteType] || defaultPages['nexusphp']))
|
||||
if (editingEntries.value.length === 0) editingEntries.value.push({key:'home',label:'首页',url:'{base}',method:'GET'})
|
||||
editorMode.value = 'table'
|
||||
editorJson.value = JSON.stringify(defaultPages[row.siteType] || defaultPages['nexusphp'], null, 2)
|
||||
window.scrollTo({top: document.body.scrollHeight, behavior:'smooth'})
|
||||
}
|
||||
|
||||
const editDefault = (dt) => {
|
||||
editSiteId.value = dt.type
|
||||
editingEntries.value = JSON.parse(JSON.stringify(dt.entries))
|
||||
if (editingEntries.value.length === 0) editingEntries.value.push({key:'home',label:'首页',url:'{base}',method:'GET'})
|
||||
editorMode.value = 'table'
|
||||
editorJson.value = JSON.stringify(dt.entries, null, 2)
|
||||
window.scrollTo({top: document.body.scrollHeight, behavior:'smooth'})
|
||||
}
|
||||
|
||||
@@ -182,17 +158,14 @@ const previewDefault = (dt) => {
|
||||
const toggleEdit = (row) => {
|
||||
if (editSiteId.value === row.siteId) { editSiteId.value = ''; return }
|
||||
editSiteId.value = row.siteId
|
||||
editorMode.value = 'table'
|
||||
try { editingEntries.value = JSON.parse(JSON.stringify(JSON.parse(row.entriesJson||'[]'))) }
|
||||
catch { editingEntries.value = [{key:'home',label:'首页',url:'{base}',method:'GET'}] }
|
||||
if (editingEntries.value.length===0) editingEntries.value.push({key:'home',label:'首页',url:'{base}',method:'GET'})
|
||||
try { editorJson.value = JSON.stringify(JSON.parse(row.entriesJson||'[]'), null, 2) }
|
||||
catch { editorJson.value = JSON.stringify([{key:'home',label:'首页',url:'{base}',method:'GET'}], null, 2) }
|
||||
}
|
||||
|
||||
const savePages = async () => {
|
||||
saving.value = true
|
||||
try {
|
||||
const entries = editorMode.value==='json' ? JSON.parse(editorJson.value) : editingEntries.value
|
||||
await api.raw.put('/sites/'+editSiteId.value+'/pages', { entries })
|
||||
await api.raw.put('/sites/'+editSiteId.value+'/pages', { entries: JSON.parse(editorJson.value) })
|
||||
ElMessage.success('已保存'); editSiteId.value = ''; fetchAll()
|
||||
} catch { ElMessage.error('保存失败') }
|
||||
finally { saving.value = false }
|
||||
|
||||
Reference in New Issue
Block a user