2021SC@SDUSC
src/controller/home/detail.js
根据名称推测,应该是和细节相关的内容。细节这个词语用在这里不太合适,或许应该称之为详情更合适一些。和上一个文件同样的是,整个文件仅由一个module.exports组成:module.exports = class extends think.cmswing.center {}// 详情页[核心];
async indexAction() {
/* 标识正确性检测 */
const id = this.get('id') || 0;
// if(!(id && think.isString(id))){
// this.fail('文档ID错误!');
// } //if(!(id && think.isString(id))){
// this.fail('文档ID错误!');
// }
注释掉了id错误的情况,让我们来看看为什么——因为进行了或0,所以在出现错误的时候使得id为0而不是报出错误,这样做有什么用意呢?或许我们看到对id的相关处理时就能看到对应的解决办法了。
/* 获取详细信息 */
const document = this.model('cmswing/document');
let info = await document.detail(id);
if (info.errno == 702) {
const error = this.controller('cmswing/error');
return error.noAction(info.errmsg);
}
获取document,令info是根据id找到的detail。如果错误是某种类型,就返回错误。这里的逻辑非常清楚。
/* 页码检测 */
// TODO
let roleid = 8;// 游客
// 访问控制
if (this.is_login) {
roleid = await this.model('member').where({
id: th