From f820e28540e3d61953e72a8a2a9aff1cb8ac5f8f Mon Sep 17 00:00:00 2001 From: chaoszhu Date: Thu, 25 Jul 2024 22:24:59 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8Dgroup&ssh=20ID?= =?UTF-8?q?=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/controller/group.js | 11 +- server/app/controller/ssh.js | 1 + server/app/db.js | 2 +- web/src/views/group/index.vue | 191 ++++++++++----------------------- 4 files changed, 66 insertions(+), 139 deletions(-) diff --git a/server/app/controller/group.js b/server/app/controller/group.js index 30c2f20..7737d2f 100644 --- a/server/app/controller/group.js +++ b/server/app/controller/group.js @@ -13,7 +13,7 @@ const addGroupList = async ({ res, request }) => { let { body: { name, index } } = request if (!name) return res.fail({ data: false, msg: '参数错误' }) let groupList = await readGroupList() - let group = { id: randomStr(), name, index } + let group = { name, index } groupList.push(group) await writeGroupList(groupList) res.success({ data: '新增成功' }) @@ -24,9 +24,10 @@ const updateGroupList = async ({ res, request }) => { let { body: { name, index } } = request if (!id || !name) return res.fail({ data: false, msg: '参数错误' }) let groupList = await readGroupList() - let idx = groupList.findIndex(item => item.id === id) - let group = { id, name, index: Number(index) || 0 } + let idx = groupList.findIndex(item => item._id === id) if (idx === -1) return res.fail({ data: false, msg: `分组ID${ id }不存在` }) + const { _id } = groupList[idx] + let group = { _id, name, index: Number(index) || 0 } groupList.splice(idx, 1, group) await writeGroupList(groupList) res.success({ data: '修改成功' }) @@ -36,13 +37,13 @@ const removeGroup = async ({ res, request }) => { let { params: { id } } = request if (id === 'default') return res.fail({ data: false, msg: '保留分组, 禁止删除' }) let groupList = await readGroupList() - let idx = groupList.findIndex(item => item.id === id) + let idx = groupList.findIndex(item => item._id === id) if (idx === -1) return res.fail({ msg: '分组不存在' }) // 移除分组将所有该分组下host分配到default中去 let hostList = await readHostList() hostList = hostList?.map((item) => { - if (item.group === groupList[idx].id) item.group = 'default' + if (item.group === groupList[idx]._id) item.group = 'default' return item }) await writeHostList(hostList) diff --git a/server/app/controller/ssh.js b/server/app/controller/ssh.js index 8ae1125..7cad4fa 100644 --- a/server/app/controller/ssh.js +++ b/server/app/controller/ssh.js @@ -52,6 +52,7 @@ const updateSSH = async ({ res, request }) => { record[authType] = await AESEncryptSync(clearSSHKey) console.log(`${ authType }__commonKey加密存储: `, record[authType]) } + record._id = sshRecord[idx]._id sshRecord.splice(idx, 1, record) await writeSSHRecord(sshRecord) consola.info('修改凭证:', name) diff --git a/server/app/db.js b/server/app/db.js index af121e4..4a9f993 100644 --- a/server/app/db.js +++ b/server/app/db.js @@ -75,7 +75,7 @@ function initGroupDB() { } else { if (count === 0) { consola.log('初始化groupDB✔') - const defaultData = [{ 'id': 'default', 'name': '默认分组', 'index': 0 }] + const defaultData = [{ '_id': 'default', 'name': '默认分组', 'index': 0 }] await writeGroupList(defaultData) } } diff --git a/web/src/views/group/index.vue b/web/src/views/group/index.vue index 6c809b8..3b6f4a6 100644 --- a/web/src/views/group/index.vue +++ b/web/src/views/group/index.vue @@ -1,64 +1,14 @@