寫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;
}
}