From 0bc4b4202e63b6ab767e30ae28cbffc73e6dc745 Mon Sep 17 00:00:00 2001 From: cxx Date: Fri, 10 May 2024 14:15:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=B8=B8=E9=87=8F=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/constant.js | 27 +++++++++++++++++++++++++++ app/view/common/constantUtil.html | 15 +++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 app/service/constant.js create mode 100644 app/view/common/constantUtil.html diff --git a/app/service/constant.js b/app/service/constant.js new file mode 100644 index 0000000..606b1c4 --- /dev/null +++ b/app/service/constant.js @@ -0,0 +1,27 @@ +'use strict'; + +// ========================================常用 require start=========================================== +const Service = require('egg').Service; +const _ = require('lodash'); +// ========================================常用 require end============================================= + + +class ConstantService extends Service { + + async getConstantObj() { + const { jianghuKnex } = this.app; + const constantList = await jianghuKnex('_constant').select(); + constantList.forEach(constant => { + try { + constant.constantValue = JSON.parse(constant.constantValue); + } catch (e) { + console.error('parse constantValue error', constant.constantKey) + } + }); + const constantObj = _.mapValues(_.keyBy(constantList, 'constantKey'), 'constantValue'); + + return constantObj; + } +} + +module.exports = ConstantService; diff --git a/app/view/common/constantUtil.html b/app/view/common/constantUtil.html new file mode 100644 index 0000000..d3272e9 --- /dev/null +++ b/app/view/common/constantUtil.html @@ -0,0 +1,15 @@ + + + \ No newline at end of file