From 7a22c233fe34016c0e77bfa538f192437d2107ac Mon Sep 17 00:00:00 2001 From: aixianling Date: Thu, 14 Jul 2022 10:50:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E5=88=B6=E9=A1=B9=E7=9B=AE=E6=89=93?= =?UTF-8?q?=E5=8C=85=E6=8E=A5=E5=8F=A3=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rest/custom/add.js | 5 ++--- src/rest/custom/detail.js | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/rest/custom/add.js b/src/rest/custom/add.js index 1299a39..7fe4d4e 100644 --- a/src/rest/custom/add.js +++ b/src/rest/custom/add.js @@ -3,11 +3,10 @@ module.exports = { action: "/node/custom/addOrUpdate", method: "post", execute: (request, response) => { - let form = request.body - delete form.appList + let {id, name, type, customPath, apps, createTime, dist, version, zipTime, download, error, extra} = request.body dbUtils.addOrUpdate({ table: 'node_custom_config', - form + form: {id, name, type, customPath, apps, createTime, dist, version, zipTime, download, error, extra} }).then(data => { response.send({code: 0, data}) }).catch(err => { diff --git a/src/rest/custom/detail.js b/src/rest/custom/detail.js index f952aa6..67ace8e 100644 --- a/src/rest/custom/detail.js +++ b/src/rest/custom/detail.js @@ -5,15 +5,22 @@ module.exports = { execute: (request, response) => { let {id} = request.query dbUtils.detail({table: 'node_custom_config', id}).then(data => { - if (data.apps) { - data.apps = JSON.parse(data.apps) - if (data.apps?.length > 0) - dbUtils.query(`select * from node_wechat_apps where id in (${data.apps.map(e=>`'${e}'`)?.toString()})`).then(res => { - data.appList = res - response.send({code: 0, data}) - }) - else response.send({code: 0, data}) - } else response.send({code: 0, data}) + data.apps = JSON.parse(data.apps || "[]") + data.extra = JSON.parse(data.extra || null) + Promise.all([ + dbUtils.query(`select * from node_wechat_apps where id in (${data.apps?.map(e=>`'${e}'`)?.toString()})`) + .then(res => data.appList = [data.appList, res].flat()), + dbUtils.query(`select * from node_wechat_apps where type='${data.type}' and id like '%project_${data.customPath}%'`) + .then(res => data.appList = [data.appList, res].flat()) + ]).then(() => { + data.appList = data.appList.filter(Boolean).map(e => { + if (data.type == 'mp') { + e.tabbar = e.id == data.extra?.tabBar.list?.[2].id + } + return e + }) + response.send({code: 0, data}) + }) }).catch(err => { response.send({code: 1, err: err?.sqlMessage || err || ""}) })