Beim Schreiben von js habe ich das Atom-Beautify-Plugin ausprobiert. Ich empfehle andere Plug-Ins, die formatieren können, hauptsächlich für die automatische Ausrichtung
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;
}
}
自动缩进:选中代码,然后 Edit -> Lines -> Auto Indent