配置项新增字段:说明 禁用

This commit is contained in:
yulixing 2019-07-24 16:17:53 +08:00
parent a916f76cf4
commit 3f52854058
2 changed files with 74 additions and 62 deletions

View File

@ -297,8 +297,9 @@ router.get('/sys_dics', async (req, res, next) => {
const type = req.query.type; const type = req.query.type;
try { try {
const cfgs = await SystemDic.find({ type: type, deleted: false }).select( const cfgs = await SystemDic.find({ type: type, deleted: false }).select(
'key value' 'key value comment disabled'
); );
res.json({ errcode: 0, errmsg: '', records: cfgs }); res.json({ errcode: 0, errmsg: '', records: cfgs });
} catch (err) { } catch (err) {
next(err); next(err);
@ -359,7 +360,10 @@ router.post('/save_sys_dic', async (req, res, next) => {
} }
recordDb.key = record.key; recordDb.key = record.key;
recordDb.value = val; recordDb.value = val;
recordDb.comment = record.comment;
recordDb.disabled = record.disabled;
recordDb.lastModifiedBy = user.username; recordDb.lastModifiedBy = user.username;
await recordDb.save(); await recordDb.save();
res.json({ res.json({
errcode: 0, errcode: 0,

View File

@ -1,36 +1,41 @@
'use strict'; 'use strict'
import mongoose from 'mongoose'; import mongoose from 'mongoose'
import dbUtil from '../../utils/db.util'; import dbUtil from '../../utils/db.util'
/** /**
* 字典表 * 字典表
*/ */
const Schema = mongoose.Schema; const Schema = mongoose.Schema
const SystemDicSchema = new mongoose.Schema({ const SystemDicSchema = new mongoose.Schema(
key: {type: String}, {
value: {type: Schema.Types.Mixed}, key: {type: String},
/** value: {type: Schema.Types.Mixed},
* 类型 /**
* system: 字典类型 * 类型
* platform: 平台 * system: 字典类型
* game_cfg: 游戏配置项目 * platform: 平台
* share_cfg: 游戏分享类型 * game_cfg: 游戏配置项目
* game_type: 游戏类型 * share_cfg: 游戏分享类型
* game_status: 游戏状态 * game_type: 游戏类型
* */ * game_status: 游戏状态
type: {type: String}, * */
// 备注 type: {type: String},
comment: {type: String}, // 备注
createdBy: {type: String, ref: 'Admin'}, comment: {type: String},
lastModifiedBy: {type: String, ref: 'Admin'}, // 是否启用
deleted: {type: Boolean, default: false}, disabled: {type: Boolean, default: false},
delete_time: {type: Date}, createdBy: {type: String, ref: 'Admin'},
deletedBy: {type: String, ref: 'Admin'}, lastModifiedBy: {type: String, ref: 'Admin'},
}, { deleted: {type: Boolean, default: false},
collection: 'system_dics', delete_time: {type: Date},
timestamps: true, deletedBy: {type: String, ref: 'Admin'},
}); },
{
collection: 'system_dics',
timestamps: true,
}
)
/** /**
* */ * */
@ -41,14 +46,13 @@ class SystemDicClass {
* @return {Promise} data * @return {Promise} data
* */ * */
static getDicMap(type) { static getDicMap(type) {
return this.find({type: type, deleted: false}) return this.find({type: type, deleted: false}).then(records => {
.then((records) => { const map = new Map()
const map = new Map(); for (const record of records) {
for (const record of records) { map.set(record.key, record.value)
map.set(record.key, record.value); }
} return map
return map; })
});
} }
/** /**
* 生成查询条件 * 生成查询条件
@ -57,55 +61,59 @@ class SystemDicClass {
* @return {Object} sortObj * @return {Object} sortObj
* */ * */
static generateQueryOpt(req) { static generateQueryOpt(req) {
let opt = {}; let opt = {}
const body = req.body; const body = req.body
const order = body.order; const order = body.order
const sort = body.sort ? body.sort : 'createdAt'; const sort = body.sort ? body.sort : 'createdAt'
const sortObj = {}; const sortObj = {}
sortObj[sort] = order === 'asc' ? 1 : -1; sortObj[sort] = order === 'asc' ? 1 : -1
if (body.keyStr) { if (body.keyStr) {
const orArr = [ const orArr = [
{key: {$regex: body.keyStr, $options: 'i'}}, {key: {$regex: body.keyStr, $options: 'i'}},
{value: {$regex: body.keyStr, $options: 'i'}}, {value: {$regex: body.keyStr, $options: 'i'}},
]; ]
opt = {$or: orArr}; opt = {$or: orArr}
} }
if (body.type && body.type !== 'all') { if (body.type && body.type !== 'all') {
opt.type = body.type; opt.type = body.type
} }
opt.deleted = false; opt.deleted = false
return {opt, sortObj}; return {opt, sortObj}
} }
/** /**
* 保存 * 保存
* @param {Object} req * @param {Object} req
* */ * */
static async saveWithReq(req) { static async saveWithReq(req) {
const body = req.body; const body = req.body
const data = body.data; const data = body.data
const ignoreKeySet = new Set(['createdAt', 'updatedAt', '__v', 'deleted', 'delete_time', 'deletedBy']); const ignoreKeySet = new Set([
let record; 'createdAt',
'updatedAt',
'__v',
'deleted',
'delete_time',
'deletedBy',
])
let record
if (data._id) { if (data._id) {
record = await this.findById(data._id); record = await this.findById(data._id)
} }
if (!record) { if (!record) {
record = new SystemDicModel({ record = new SystemDicModel({
createdBy: req.user.id, createdBy: req.user.id,
}); })
} }
for (const key in body.data) { for (const key in body.data) {
if ({}.hasOwnProperty.call(body.data, key) && !ignoreKeySet.has(key)) { if ({}.hasOwnProperty.call(body.data, key) && !ignoreKeySet.has(key)) {
record[key] = body.data[key]; record[key] = body.data[key]
} }
} }
return record.save(); return record.save()
} }
} }
SystemDicSchema.loadClass(SystemDicClass); SystemDicSchema.loadClass(SystemDicClass)
const conn = dbUtil.getConnGarfield();
export default conn.model('SystemDic', SystemDicSchema);
const conn = dbUtil.getConnGarfield()
export default conn.model('SystemDic', SystemDicSchema)