<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                # 新建/application/controllers/common/base.js ``` const fs = require('fs'); const path = require('path'); var tools = require('../../../libs/tools'); var config = require(tools.rootPath + 'config'); var controller = require(tools.rootPath + 'libs/controller.js'); const functions = require(tools.appPath + 'functions'); var ejs = require('ejs'); module.exports = class extends controller { constructor() { super(); //上一頁地址 this.FORWARD = null; //請求地址 this.REQUEST_URI = null; //模板名稱 this.TPL = null; //req this.req = null; //res this.res = null; //session this._session = {}; //模板變量 this._template_var = {}; //模塊 this.MM = ''; //控制器 this.CC = ''; //操作 this.AA = ''; //是否是post請求 this.isPost = false; //是否是get請求 this.isGet = false; } //初始化方法 async init() { this.REQUEST_URI = this.req.REQUEST_URI; this.TPL = this.req.TPL; this._session = this.req.session; this.MM = this.req.MM; this.CC = this.req.CC; this.AA = this.req.AA; this.isPost = this.req.isPost; this.isGet = this.req.isGet; let FORWARD = this.post('FORWARD'); if (FORWARD) { this.FORWARD = encodeURI(FORWARD); } else { this.FORWARD = this.REQUEST_URI; } //other //ip地址 this.ip = this.req.headers['x-real-ip']; //瀏覽器標識 this.userAgent = this.req.headers["user-agent"]; this.assign({ MM: this.MM, CC: this.CC, AA: this.AA, FORWARD: this.FORWARD, REQUEST_URI: this.REQUEST_URI, VIEWROOT: tools.viewPath, }); return true; } //前置方法 async __before() { return true; } //消息提示函數 msg(code, msg = '', url = '', data = []) { if (code === true) code = 1; if (code === false) code = 0; if (!this.isAjax()) { let html = ''; if (code) { if (!msg) msg = '操作成功'; let jump = `location.href='${url}';`; if (!url) jump = "window.history.back();"; html = `<html><head><meta charset="utf-8"></head><body>加載中...<script>alert('${msg}');${jump}</script></body></html>`; } else { if (!msg) msg = '操作失敗'; html = `<html><head><meta charset="utf-8"></head><body>加載中...<script>alert('${msg}');window.history.back();</script></body></html>`; } return this.res.end(html); } else { if (code) { if (!msg) msg = '操作成功'; } else { if (!msg) msg = '操作失敗'; } let d = { 'code': code, 'msg': msg, 'url': url, 'data': data, }; return this.res.end(this.json(d)); } } //session操作函數 async session(name, val = '') { if (val === null) { delete this._session[name]; } if (val === '') { return typeof (this._session[name]) != 'undefined' ? this._session[name] : null; } if (name && val) { this._session[name] = val; } } //模板變量賦值函數 assign(obj, val = '') { if (typeof (obj) == 'string') { this._template_var[obj] = val; } else { Object.assign(this._template_var, obj); } } //加載模板函數 tpl(path = '', params = {}) { var f = path ? path : this.TPL; var str = fs.readFileSync(tools.viewPath + f + '.html', 'utf-8'); let p = this._template_var; Object.assign(p, params); return ejs.render(str, p); } //json函數 json(v) { return this.res.end(JSON.stringify(v)); } //跳轉函數 redirect(url) { this.res.redirect(url); } //post變量函數 post(key = '') { if (key) { return typeof (this.req.body[key]) != 'undefined' ? this.req.body[key] : null; } return typeof (this.req.body) != 'undefined' ? this.req.body : {}; } //get變量函數 get(key = '') { if (key) { return typeof (this.req.query[key]) != 'undefined' ? this.req.query[key] : null; } return typeof (this.req.query) != 'undefined' ? this.req.query : {}; } //是否是ajax請求 isAjax() { return this.req.xhr; } //referer函數 referer() { return this.REQUEST_URI; } //輸出函數 p(str) { console.log(str); this.res.end(str); } //model加載函數 model(name) { var m = require(tools.modelPath + name + '.js'); return new m(); } //操作調用函數 async action(controller, action = undefined, path = '') { let c = require(path ? path + '/' + controller : tools.controllerPath + controller); let object = new c(); object.req = this.req; object.res = this.res; await object.init(); await object.__before(); if (!action) return object; return await object[action](this.req, this.res); } }; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看