/**
 * 控制器基类
 *
 * @author CaiAoLin
 * @date 2017/6/29
 * @version
 */
import Moment from "moment";
import Url from "url";

class BaseController {

    /**
     * 页面title
     *
     * @var string
     */
    title = '';

    /**
     * 构造函数
     *
     * @return {void}
     */
    constructor() {
        if (new.target === BaseController) {
            throw new Error('BaseController不能实例化,只能继承使用。');
        }
    }

    /**
     * 初始化函数
     *
     * @param {object} request
     * @param {object} response
     * @param {function} next
     * @return {void}
     */
    init(request, response, next) {
        response.locals.title = 'test';

        // moment工具
        response.locals.moment = Moment;

        // url相关数据
        let urlInfo = Url.parse(request.originalUrl, true);
        response.locals.urlQuery = JSON.stringify(urlInfo.query);

        next();
    }
}

export default BaseController;