refactor: 移除配置JSON Tab,只保留Groovy脚本编辑器
This commit is contained in:
@@ -36,54 +36,31 @@
|
||||
<el-button size="small" @click="refresh" :loading="loading">刷新</el-button>
|
||||
<el-button size="small" @click="doBatchParse" :loading="parseLoading" v-if="selectedConfigId">重新解析</el-button>
|
||||
|
||||
<!-- 审批/拒绝/编辑(待审核配置) -->
|
||||
<!-- 审批/拒绝(待审核配置) -->
|
||||
<template v-if="selectedConfig?.status==='pending'">
|
||||
<el-divider direction="vertical" />
|
||||
<el-button size="small" type="success" @click="approveConfig" :loading="approving">审批通过</el-button>
|
||||
<el-button size="small" type="danger" @click="rejectConfig" :loading="rejecting">拒绝</el-button>
|
||||
<el-button size="small" @click="startEdit">编辑</el-button>
|
||||
</template>
|
||||
|
||||
<el-button size="small" @click="configVisible=true; configTab='script'" v-if="selectedConfigId">编辑脚本</el-button>
|
||||
<el-button size="small" text @click="configVisible=true; configTab='config'" v-if="selectedConfigId && selectedConfigJson">查看JSON</el-button>
|
||||
<el-button size="small" @click="configVisible=true" v-if="selectedConfigId">编辑脚本</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 配置/脚本弹窗 -->
|
||||
<el-dialog v-model="configVisible" title="适配配置 · v{{ selectedConfig?.version }}" width="880px" :close-on-click-modal="false">
|
||||
<el-tabs v-model="configTab" type="card" size="small">
|
||||
<el-tab-pane label="配置JSON" name="config">
|
||||
<div v-if="!selectedConfigJson" style="text-align:center;padding:40px;color:#909399">
|
||||
无 JSON 配置,已切换为纯 Groovy 方案
|
||||
</div>
|
||||
<template v-else-if="editing">
|
||||
<el-input v-model="editContent" type="textarea" :rows="22" style="font-family:monospace;font-size:12px" />
|
||||
</template>
|
||||
<pre v-else class="config-json" v-html="highlightedConfig"></pre>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="Groovy 脚本" name="script">
|
||||
<div v-if="scriptLoading" style="text-align:center;padding:20px;color:#909399">加载中...</div>
|
||||
<template v-else>
|
||||
<div style="margin-bottom:6px;font-size:11px;color:#909399">
|
||||
内置变量: <code>content</code>(页面内容) <code>url</code>(访问URL) <code>jsoup</code> <code>json</code> <code>utils</code>
|
||||
· 返回 Map{pageName,extracted,message} 或 List
|
||||
</div>
|
||||
<el-input v-model="scriptContent" type="textarea" :rows="22" style="font-family:monospace;font-size:12px"
|
||||
placeholder="def doc = jsoup.parse(content) def rows = [] doc.select('table tr').each { row -> rows << [ title: utils.text(utils.selectFirst(row,'td.name a')), size: utils.text(utils.selectFirst(row,'td.size')) ] } return [pageName:'search', extracted:rows]" />
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<!-- 脚本编辑弹窗 -->
|
||||
<el-dialog v-model="configVisible" title="Groovy 脚本 · v{{ selectedConfig?.version }}" width="880px" :close-on-click-modal="false">
|
||||
<div v-if="scriptLoading" style="text-align:center;padding:20px;color:#909399">加载中...</div>
|
||||
<template v-else>
|
||||
<div style="margin-bottom:6px;font-size:11px;color:#909399">
|
||||
内置变量: <code>content</code>(页面内容) <code>url</code>(访问URL) <code>jsoup</code> <code>json</code> <code>utils</code>
|
||||
· 返回 Map{pageName,extracted,message} 或 List
|
||||
</div>
|
||||
<el-input v-model="scriptContent" type="textarea" :rows="22" style="font-family:monospace;font-size:12px"
|
||||
placeholder="def doc = jsoup.parse(content) def rows = [] doc.select('table tr').each { row -> rows << [ title: utils.text(utils.selectFirst(row,'td.name a')), size: utils.text(utils.selectFirst(row,'td.size')) ] } return [pageName:'search', extracted:rows]" />
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button @click="configVisible=false">关闭</el-button>
|
||||
<template v-if="configTab==='config' && selectedConfigJson">
|
||||
<el-button v-if="editing" size="small" @click="cancelEdit">取消</el-button>
|
||||
<el-button type="primary" size="small" @click="editing? saveEdit() : startEdit()">
|
||||
{{ editing ? '保存JSON' : '编辑JSON' }}
|
||||
</el-button>
|
||||
</template>
|
||||
<template v-if="configTab==='script'">
|
||||
<el-button type="primary" size="small" @click="saveScript" :loading="saving">保存脚本</el-button>
|
||||
</template>
|
||||
<el-button type="primary" @click="saveScript" :loading="saving">保存脚本</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -177,12 +154,8 @@ const loading = ref(false)
|
||||
const parseLoading = ref(false)
|
||||
const selectedConfigId = ref(null)
|
||||
const selectedConfig = ref(null)
|
||||
const selectedConfigJson = ref('')
|
||||
const configVisible = ref(false)
|
||||
watch(configVisible, (v) => { if (v) { configTab.value='config'; loadScript() } })
|
||||
const configTab = ref('config')
|
||||
const editing = ref(false)
|
||||
const editContent = ref('')
|
||||
watch(configVisible, (v) => { if (v) loadScript() })
|
||||
const scriptContent = ref('')
|
||||
const scriptLoading = ref(false)
|
||||
const saving = ref(false)
|
||||
@@ -244,16 +217,6 @@ const onConfigChange = async () => {
|
||||
const cfg = allConfigVersions.value.find(v => v.id===selectedConfigId.value)
|
||||
if (!cfg) return
|
||||
selectedConfig.value = cfg
|
||||
editing.value = false
|
||||
try {
|
||||
if (cfg.status==='pending') {
|
||||
const r = await api.adminConfigs.getContent(cfg.id)
|
||||
selectedConfigJson.value = r.data?.content||''
|
||||
} else {
|
||||
const r = await api.configs.content(siteId, cfg.version)
|
||||
selectedConfigJson.value = typeof r.data==='string' ? r.data : JSON.stringify(r.data||{},null,2)
|
||||
}
|
||||
} catch { selectedConfigJson.value = '' }
|
||||
await doBatchParse()
|
||||
}
|
||||
|
||||
@@ -282,8 +245,6 @@ const refresh = async () => {
|
||||
}
|
||||
|
||||
// 编辑
|
||||
const startEdit = () => { editContent.value=selectedConfigJson.value; editing.value=true }
|
||||
const cancelEdit = () => { editing.value=false }
|
||||
const loadScript = async () => {
|
||||
if (!selectedConfig.value) return
|
||||
scriptLoading.value = true
|
||||
@@ -299,16 +260,6 @@ const saveScript = async () => {
|
||||
} catch(e) { ElMessage.error(e.response?.data?.message||'保存失败') }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
const saveEdit = async () => {
|
||||
saving.value = true
|
||||
try {
|
||||
await api.adminConfigs.updateContent(selectedConfig.value.id, editContent.value)
|
||||
selectedConfigJson.value = editContent.value; editing.value = false
|
||||
ElMessage.success('已保存'); doBatchParse()
|
||||
} catch(e) { ElMessage.error(e.response?.data?.message||'保存失败') }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
|
||||
const approveConfig = async () => {
|
||||
try { await ElMessageBox.confirm('确认审批?版本号将自动+1','审批配置',{confirmButtonText:'确认'}) } catch{return}
|
||||
approving.value = true
|
||||
@@ -345,22 +296,6 @@ const statusTag = (code) => {
|
||||
return 'danger'
|
||||
}
|
||||
|
||||
const highlightedConfig = computed(() => {
|
||||
try { return syntaxHighlight(JSON.stringify(JSON.parse(selectedConfigJson.value),null,2)) }
|
||||
catch { return escapeHtml(selectedConfigJson.value||'') }
|
||||
})
|
||||
const escapeHtml = (s) => { if(!s)return''; return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') }
|
||||
const syntaxHighlight = (json) => escapeHtml(json).replace(
|
||||
/("(\\u[a-fA-F0-9]{4}|\\[^u]|[^"\\])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
|
||||
(m) => {
|
||||
let cls='number'
|
||||
if(/^"/.test(m)) cls=/:$/.test(m)?'key':'string'
|
||||
else if(/true|false/.test(m)) cls='boolean'
|
||||
else if(/null/.test(m)) cls='null'
|
||||
return `<span class="${cls}">${m}</span>`
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
await refresh()
|
||||
await loadConfigs()
|
||||
|
||||
Reference in New Issue
Block a user