写js,试了试atom-beautify这个插件,不是很喜欢,推荐一下其它能 format 的插件吧,主要为了自动对齐,代码风格希望是这样的:
cg_query: (req, res) => {
console.log('------查询------');
console.log('phone: ', req.body.phone);
console.log('token: ', req.header('token'));
// token 验证通过
// 输入号码合法则进行后续操作
let reg = /^1\d{10}$/;// 11 位数字,以 1 开头
if (req.body.phone && reg.test(req.body.phone)) {
model.UserModel.findOne({ phone: req.body.phone }, 'asset', (err, result) => {
console.log('result: ', result);
try {
console.log(result.asset);
let a = {
currentGoldSum: result.asset.currentGoldSum,
cgEarningsSum: result.asset.cgEarningsSum,
cgEarningsYtd: result.asset.cgEarningsYtd
};
res.json({code: 0, msg: '查询成功', asset: a});
return;
} catch (e) {
console.log(e);
}
if (err) {
console.log('db error: ', err);
}
res.json({code:-1, msg: '查询失败'});
return;
});
} else {
res.json({code:-2, msg: '非法输入'});
return;
}
}