山东大学软件工程应用与实践-cmswing-第七周

2021SC@SDUSC

本周我们来解析cmswing文件夹下最后一个核心文件:modindexbase.js。

1.

  async __before() {
    await super.__before();
    const getCategory = this.get('category') ? this.get('category').split('-')[0].slice(1) : false;
    if (this.get('category') || this.get('cid')) {
      this.m_cate = await this.category(getCategory || this.get('cid'));

      this.mod = await this.model('cmswing/model').get_model(this.m_cate.model);
      if (think.isEmpty(this.mod)) {
        const error = this.controller('cmswing/error');
        return error.noAction('模型不存在或被禁用!');
      }

      this.meta_title = this.m_cate.meta_title ? this.m_cate.meta_title : this.m_cate.title; 
      this.keywords = this.m_cate.keywords ? this.m_cate.keywords : ''; 
      this.description = this.m_cate.description ? this.m_cate.description : ''; 
    }
  }

modindexbase.js中的__before()与modadminbase.js的__before()一样,规定了模型公共参数,继承了父类__before(admin.js中),执行验证登录、用户信息等操作的代码,不同的是,modindexbase.js中的__before()在这之后是用了一个嵌套的if语句,通过this.category(getCategory || this.get('cid'))来获取当前模型栏目id,通过this.model('cmswing/model').get_model(this.m_cate.model)来获取当前模型信息,然后通过内部的if语句来判断this.mod方法的返回值是否为空,以此来判断当前模型是否存在或被禁用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值