'use strict';
const Base = require('../base');

/**
 * 项目首页
 */
class HomeController extends Base {

  /**
   * [loginValidate 登录验证]
   * @author       szjcomo
   * @createTime 2020-08-03
   * @return     {[type]}   [description]
   */
  get loginValidate() {
    const that = this;
    return {
      username: that.ctx.rules.name('用户名')
        .required(),
    };
  }

  /**
   * [index 访问首页]
   * @author       szjcomo
   * @createTime 2020-08-03
   * @return     {[type]}   [description]
   */
  async index() {
    const that = this;
    try {
      // let result = await that.app.model.AdminUser.query('select * from szj_admin_user');
      const data = await that.ctx.validate(that.loginValidate, await that.ctx.getParse());
      return that.ctx.appJson(that.app.szjcomo.appResult('hi,szjcomo', data, false));
    } catch (err) {
      console.log(err);
      return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
    }
  }
}

module.exports = HomeController;