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