From 02288e12a73c2bccd16b73fee9824525ad377968 Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Thu, 11 Jan 2024 14:35:51 +0800 Subject: [PATCH] =?UTF-8?q?(*)=20=E5=88=A4=E6=96=AD=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/auth/index.js | 6 ++++-- api/app/lib/controllers/bigScreen/index .js | 3 ++- .../lib/controllers/organization/authority.js | 3 ++- api/app/lib/controllers/organization/user.js | 12 ++++++++---- api/app/lib/utils/func.js | 17 +++++++++++++++++ 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 api/app/lib/utils/func.js diff --git a/api/app/lib/controllers/auth/index.js b/api/app/lib/controllers/auth/index.js index d5b049b..13b18a1 100644 --- a/api/app/lib/controllers/auth/index.js +++ b/api/app/lib/controllers/auth/index.js @@ -40,9 +40,10 @@ async function login(ctx, next) { expired: expired }); + const { judgeAgent } = ctx.app.fs.utils await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: '登录', parameter: null, userId: userInfo.id, @@ -135,9 +136,10 @@ async function logout(ctx) { } }); + const { judgeAgent } = ctx.app.fs.utils await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: '登出', parameter: null, userId: userInfo.userInfo.id, diff --git a/api/app/lib/controllers/bigScreen/index .js b/api/app/lib/controllers/bigScreen/index .js index dae060a..7949e73 100644 --- a/api/app/lib/controllers/bigScreen/index .js +++ b/api/app/lib/controllers/bigScreen/index .js @@ -158,10 +158,11 @@ async function getCapabilitiesInvoke(ctx, next) { const res = await ctx.app.iota.request.post(`/capabilities/invoke`, data) || {} + const { judgeAgent } = ctx.app.fs.utils const userId = ctx.fs.api.userId; await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: `下发泵站控制指令`, parameter: null, userId, diff --git a/api/app/lib/controllers/organization/authority.js b/api/app/lib/controllers/organization/authority.js index 6960c1e..649fb72 100644 --- a/api/app/lib/controllers/organization/authority.js +++ b/api/app/lib/controllers/organization/authority.js @@ -74,9 +74,10 @@ async function updateUserRes(ctx, next) { raw: true, transaction: transaction, }) + const { judgeAgent } = ctx.app.fs.utils await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: `修改 (${user.name}) 用户权限`, parameter: null, userId: operationUserId, diff --git a/api/app/lib/controllers/organization/user.js b/api/app/lib/controllers/organization/user.js index e5e469a..6ff6661 100644 --- a/api/app/lib/controllers/organization/user.js +++ b/api/app/lib/controllers/organization/user.js @@ -48,10 +48,11 @@ async function creatUser(ctx, next) { password: Hex.stringify(MD5(data.password)), delete: false, }) + const { judgeAgent } = ctx.app.fs.utils const userId = ctx.fs.api.userId; await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: `新建用户:${data.name}`, parameter: null, userId, @@ -96,10 +97,11 @@ async function updateUser(ctx, next) { where: { id } }); + const { judgeAgent } = ctx.app.fs.utils const userId = ctx.fs.api.userId; await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: `修改 (${data.name}) 用户信息`, parameter: null, userId, @@ -129,11 +131,12 @@ async function deleteUser(ctx, next) { returning: true, }); + const { judgeAgent } = ctx.app.fs.utils const userId = ctx.fs.api.userId; const userName = delUser[1].map(item => item.name).join() await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: `删除用户:${userName}`, parameter: null, userId, @@ -171,10 +174,11 @@ async function resetPwd(ctx, next) { returning: true, }, ); + const { judgeAgent } = ctx.app.fs.utils const userId = ctx.fs.api.userId; await models.OperationLog.create({ time: new Date().getTime(), - clientType: ctx.header['user-agent'], + clientType: judgeAgent(ctx.header['user-agent']), content: `修改 (${updateUser[1][0].name}) 用户密码`, parameter: null, userId, diff --git a/api/app/lib/utils/func.js b/api/app/lib/utils/func.js new file mode 100644 index 0000000..e037680 --- /dev/null +++ b/api/app/lib/utils/func.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = function (app, opts) { + const judgeAgent = (userAgent = '') => { + if (/miniProgram/i.test(userAgent)) { + return '小程序' + } else if (/Mobi|Android|iPhone/i.test(userAgent)) { + return '手机浏览器' + } else { + return 'PC浏览器' + } + } + + return { + judgeAgent, + } +} \ No newline at end of file