feat: 站点增加标签+简介字段+表单编辑双向同步
This commit is contained in:
@@ -72,6 +72,12 @@
|
||||
<el-form-item label="地址">
|
||||
<el-input v-model="form.urlsStr" type="textarea" :rows="2" @input="formToJson" placeholder="一行一个" />
|
||||
</el-form-item>
|
||||
<el-form-item label="标签">
|
||||
<el-input v-model="form.tagsStr" @input="formToJson" placeholder="用逗号分隔" />
|
||||
</el-form-item>
|
||||
<el-form-item label="简介">
|
||||
<el-input v-model="form.desc" type="textarea" :rows="2" @input="formToJson" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型">
|
||||
<el-select v-model="form.siteType" @change="formToJson" style="width:100%">
|
||||
<el-option v-for="t in ['nexusphp','mtorrent','gazelle','unit3d','unknown']" :key="t" :label="t" :value="t" />
|
||||
@@ -93,12 +99,16 @@ import api from '../api'
|
||||
|
||||
const loading = ref(false), saving = ref(false), pendingCount = ref(0)
|
||||
const sites = ref([]), editSiteId = ref(''), editorJson = ref('{}'), jsonError = ref(false)
|
||||
const form = reactive({ siteId:'', namesStr:'', urlsStr:'', siteType:'nexusphp', status:'active' })
|
||||
const form = reactive({ siteId:'', namesStr:'', urlsStr:'', tagsStr:'', desc:'', siteType:'nexusphp', status:'active' })
|
||||
let syncing = false
|
||||
|
||||
const jsonToForm = () => {
|
||||
try { const s = JSON.parse(editorJson.value); form.siteId = s.siteId||''; form.namesStr = (s.names||[]).join('\n'); form.urlsStr = (s.urls||[]).join('\n'); form.siteType = s.siteType||'nexusphp'; form.status = s.status||'active'; jsonError.value = false }
|
||||
catch { jsonError.value = true }
|
||||
try {
|
||||
const s = JSON.parse(editorJson.value)
|
||||
form.siteId = s.siteId||''; form.namesStr = (s.names||[]).join('\n'); form.urlsStr = (s.urls||[]).join('\n')
|
||||
form.tagsStr = (s.tags||[]).join(','); form.desc = s.description||''; form.siteType = s.siteType||'nexusphp'; form.status = s.status||'active'
|
||||
jsonError.value = false
|
||||
} catch { jsonError.value = true }
|
||||
}
|
||||
|
||||
const formToJson = () => {
|
||||
@@ -107,7 +117,8 @@ const formToJson = () => {
|
||||
editorJson.value = JSON.stringify({
|
||||
siteId: form.siteId, names: (form.namesStr||'').split('\n').map(s=>s.trim()).filter(Boolean),
|
||||
urls: (form.urlsStr||'').split('\n').map(s=>s.trim()).filter(Boolean),
|
||||
siteType: form.siteType, status: form.status,
|
||||
tags: (form.tagsStr||'').split(',').map(s=>s.trim()).filter(Boolean),
|
||||
description: form.desc||'', siteType: form.siteType, status: form.status,
|
||||
}, null, 2)
|
||||
nextTick(() => { syncing = false })
|
||||
}
|
||||
@@ -128,7 +139,7 @@ const refresh = async () => {
|
||||
|
||||
const editSite = (row) => {
|
||||
editSiteId.value = row.siteId
|
||||
editorJson.value = JSON.stringify({siteId:row.siteId,names:row.names,urls:row.urls,siteType:row.siteType,status:row.status||'active'}, null, 2)
|
||||
editorJson.value = JSON.stringify({siteId:row.siteId,names:row.names,urls:row.urls,tags:row.tags||[],description:row.description||'',siteType:row.siteType,status:row.status||'active'}, null, 2)
|
||||
}
|
||||
|
||||
const newSite = () => {
|
||||
@@ -141,7 +152,7 @@ const saveSite = async () => {
|
||||
try {
|
||||
const s = JSON.parse(editorJson.value)
|
||||
if (!s.siteId) { ElMessage.warning('siteId不能为空'); return }
|
||||
await api.raw.put('/admin/sites/'+s.siteId, {names:s.names||[],urls:s.urls||[],siteType:s.siteType||'unknown',status:s.status||'active'})
|
||||
await api.raw.put('/admin/sites/'+s.siteId, {names:s.names||[],urls:s.urls||[],tags:s.tags||[],description:s.description||'',siteType:s.siteType||'unknown',status:s.status||'active'})
|
||||
ElMessage.success('已保存'); editSiteId.value = ''; refresh()
|
||||
} catch { ElMessage.error('保存失败') }
|
||||
finally { saving.value = false }
|
||||
|
||||
Reference in New Issue
Block a user