JS添加全局变量ROOT_PATH

This commit is contained in:
邹景立 2017-02-15 11:39:01 +08:00
parent b2ae279be7
commit 8e7d948f30
5 changed files with 85 additions and 61 deletions

View File

@ -8,7 +8,13 @@ use library\Node;
use library\Tools; use library\Tools;
use think\Db; use think\Db;
/**
* 系统后台管理管理
*
* @package app\admin\controller
* @author Anyon <zoujingli@qq.com>
* @date 2017/02/15
*/
class Menu extends BasicAdmin { class Menu extends BasicAdmin {
/** /**
@ -23,29 +29,22 @@ class Menu extends BasicAdmin {
*/ */
protected $table = 'SystemMenu'; protected $table = 'SystemMenu';
/**
* 关闭分页
* @var bool
*/
protected $_page_on = false;
/** /**
* 定义菜单链接打开方式 * 定义菜单链接打开方式
* @var array * @var array
*/ */
protected $targetList = array( protected $targetList = [
'_self' => '本窗口打开', '_self' => '本窗口打开',
'_blank' => '新窗口打开', '_blank' => '新窗口打开',
'_parent' => '父窗口打开', '_parent' => '父窗口打开',
'_top' => '顶级窗口打开', '_top' => '顶级窗口打开',
); ];
/** /**
* 菜单列表 * 菜单列表
*/ */
public function index() { public function index() {
$db = Db::name($this->table); parent::_list($this->table, false);
parent::_list($db, false);
} }
/** /**

View File

@ -10,6 +10,7 @@
<link rel="stylesheet" href="__STATIC__/theme/default/css/console.css"> <link rel="stylesheet" href="__STATIC__/theme/default/css/console.css">
<link rel="stylesheet" href="__STATIC__/theme/default/css/animate.css"> <link rel="stylesheet" href="__STATIC__/theme/default/css/animate.css">
{block name="style"}{/block} {block name="style"}{/block}
<script>window.ROOT_PATH='__ROOT__';</script>
<script src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script> <script src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>
<script src="__STATIC__/admin/app.js"></script> <script src="__STATIC__/admin/app.js"></script>
</head> </head>

View File

@ -3,6 +3,7 @@
namespace controller; namespace controller;
use think\Controller; use think\Controller;
use think\Db;
use think\db\Query; use think\db\Query;
/** /**
@ -14,17 +15,47 @@ use think\db\Query;
*/ */
class BasicAdmin extends Controller { class BasicAdmin extends Controller {
/**
* 默认操作数据表
* @var string
*/
protected $table;
/**
* 默认检查用户登录状态
* @var bool
*/
protected $checkLogin = true;
/**
* 默认检查节点访问权限
* @var bool
*/
protected $checkAuth = true;
/** /**
* 后台权限控制初始化方法 * 后台权限控制初始化方法
*/ */
public function _initialize() { public function _initialize() {
if (!$this->isLogin()) { # 用户登录状态检查
$this->redirect('@admin/login'); if ($this->checkLogin || $this->checkAuth) {
if (!$this->isLogin()) {
$this->redirect('@admin/login');
}
} }
// 初始化赋值常用变量 # 节点访问权限检查
if ($this->checkLogin && $this->checkAuth) {
$node = strtolower($this->request->module() . '/' . $this->request->controller() . '/' . $this->request->action());
if (!auth($node)) {
$this->error('抱歉,您没有访问该模块的权限!');
}
}
# 初始化赋值常用变量
if ($this->request->isGet()) { if ($this->request->isGet()) {
$this->assign('classuri', strtolower($this->request->module() . '/' . $this->request->controller())); $class_uri = strtolower($this->request->module() . '/' . $this->request->controller());
$this->assign('classuri', $class_uri);
} }
} }
/** /**
@ -48,9 +79,8 @@ class BasicAdmin extends Controller {
* @return array|string * @return array|string
*/ */
protected function _list($db = null, $is_page = true, $is_display = true, $total = false) { protected function _list($db = null, $is_page = true, $is_display = true, $total = false) {
is_null($db) && $db = db($this->table); is_null($db) && $db = Db::name($this->table);
is_string($db) && $db = db($db); is_string($db) && $db = Db::name($db);
!$db->getTable() && $db->setTable($this->table);
# 列表排序默认处理 # 列表排序默认处理
if ($this->request->isPost() && $this->request->post('action') === 'resort') { if ($this->request->isPost() && $this->request->post('action') === 'resort') {
$data = $this->request->post(); $data = $this->request->post();
@ -67,7 +97,7 @@ class BasicAdmin extends Controller {
if ($is_page) { if ($is_page) {
$row_page = $this->request->get('rows', cookie('rows'), 'intval'); $row_page = $this->request->get('rows', cookie('rows'), 'intval');
cookie('rows', $row_page >= 10 ? $row_page : 10); cookie('rows', $row_page >= 10 ? $row_page : 10);
$page = $db->paginate($row_page, $total, ['query' => input('get.')]); $page = $db->paginate($row_page, $total, ['query' => $this->request->get()]);
$result['list'] = $page->all(); $result['list'] = $page->all();
$result['page'] = preg_replace(['|href="(.*?)"|', '|pagination|'], ['data-open="$1" href="javascript:void(0);"', 'pagination pull-right'], $page->render()); $result['page'] = preg_replace(['|href="(.*?)"|', '|pagination|'], ['data-open="$1" href="javascript:void(0);"', 'pagination pull-right'], $page->render());
} else { } else {
@ -101,8 +131,7 @@ class BasicAdmin extends Controller {
$this->_callback('_form_filter', $vo); $this->_callback('_form_filter', $vo);
$result = Data::save($db, $vo, $pk, $where); $result = Data::save($db, $vo, $pk, $where);
if (false !== $this->_callback('_form_result', $result)) { if (false !== $this->_callback('_form_result', $result)) {
$back = $pk_value === '' ? 'javascript:history.back();' : 'javascript:$.form.reload();'; $result !== false ? $this->success('恭喜,保存成功哦!', ($pk_value === '' ? null : '')) : $this->error('保存失败,请稍候再试!');
$result !== false ? $this->success('恭喜,保存成功哦!', $back) : $this->error('保存失败,请稍候再试!');
} }
return $result; return $result;
} }

View File

@ -37,7 +37,7 @@ require.config({
'admin.listen': {deps: ['jquery', 'jquery.cookies', 'admin.plugs']}, 'admin.listen': {deps: ['jquery', 'jquery.cookies', 'admin.plugs']},
}, },
deps: ['css!//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css'], deps: ['css!//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css'],
// urlArgs: "t=" + (new Date()).getTime() urlArgs: "t=" + (new Date()).getTime()
}); });
window.WEB_SOCKET_SWF_LOCATION = "//cdn.bootcss.com/web-socket-js/1.0.0/WebSocketMain.swf"; window.WEB_SOCKET_SWF_LOCATION = "//cdn.bootcss.com/web-socket-js/1.0.0/WebSocketMain.swf";

View File

@ -166,7 +166,7 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
!!data.url ? (window.location.href = data.url) : $.form.reload(); !!data.url ? (window.location.href = data.url) : $.form.reload();
}); });
} }
self.error(data.msg, 3000, function () { self.error(data.msg, 3, function () {
!!data.url && (window.location.href = data.url); !!data.url && (window.location.href = data.url);
}); });
}; };
@ -179,7 +179,7 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
/** /**
* 表单构造函数 * 表单构造函数
* @returns {common_L11._form} * @private
*/ */
function _form() { function _form() {
this.version = '2.0'; this.version = '2.0';
@ -189,13 +189,13 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
/** /**
* 异步加载的数据 * 异步加载的数据
* @param {type} url 请求的地址 * @param url 请求的地址
* @param {json|form|$form} data 额外请求数据 * @param data 额外请求数据
* @param {type} type 提交的类型 GET|POST * @param type 提交的类型 GET|POST
* @param {type} callback 成功后的回调方法 * @param callback 成功后的回调方法
* @param {type} loading 是否显示加载层 * @param loading 是否显示加载层
* @param {type} tips 提示消息 * @param tips 提示消息
* @param {type} time 消息提示时间 * @param time 消息提示时间
*/ */
_form.prototype.load = function (url, data, type, callback, loading, tips, time) { _form.prototype.load = function (url, data, type, callback, loading, tips, time) {
var self = this; var self = this;
@ -244,10 +244,10 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
}); });
}); });
}; };
/** /**
* 动态HTML事件重载 * 动态HTML事件重载
* @param {type} $container * @param $container
* @returns {undefined}
*/ */
_form.prototype.reInit = function ($container) { _form.prototype.reInit = function ($container) {
$.validate.listen.call(this); $.validate.listen.call(this);
@ -266,15 +266,15 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
/* 自动给必填字符加上样式 @zoujingli @by 2016-05-11 */ /* 自动给必填字符加上样式 @zoujingli @by 2016-05-11 */
$container.find('[required]').parent().prevAll('label').addClass('label-required'); $container.find('[required]').parent().prevAll('label').addClass('label-required');
}; };
/** /**
* 加载HTML到目标位置 * 加载HTML到目标位置
* @param {type} url * @param url
* @param {type} data * @param data
* @param {type} target * @param target
* @param {type} callback * @param callback
* @param {type} loading * @param loading
* @param {type} tips * @param tips
* @returns {undefined}
*/ */
_form.prototype.open = function (url, data, target, callback, loading, tips) { _form.prototype.open = function (url, data, target, callback, loading, tips) {
data && (typeof (data) === 'object') && (data = $.param(data)); data && (typeof (data) === 'object') && (data = $.param(data));
@ -284,25 +284,21 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
return $.msg.auto(res); return $.msg.auto(res);
} }
var $container = $('.layer-main-container').html(res); var $container = $('.layer-main-container').html(res);
function reinit() {
/* 事件重载 */
$.form.reInit($container);
}
reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000); reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000);
return (typeof callback === 'function') && callback.call(this); return (typeof callback === 'function') && callback.call(this);
function reinit() {
$.form.reInit($container);
}
}, loading, tips); }, loading, tips);
}; };
/** /**
* 加载HTML到弹出层 * 加载HTML到弹出层
* @param {type} url * @param url
* @param {type} data * @param data
* @param {type} callback * @param callback
* @param {type} loading * @param loading
* @param {type} tips * @param tips
* @returns {undefined}
*/ */
_form.prototype.modal = function (url, data, callback, loading, tips) { _form.prototype.modal = function (url, data, callback, loading, tips) {
data && (typeof (data) === 'object') && (data = $.param(data)); data && (typeof (data) === 'object') && (data = $.param(data));
@ -333,24 +329,21 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
/** /**
* 显示HTML到中主内容区 * 显示HTML到中主内容区
* @param {type} html * @param html
* @returns {undefined}
*/ */
_form.prototype.show = function (html) { _form.prototype.show = function (html) {
var $container = $('.layer-main-container').html(html); var $container = $('.layer-main-container').html(html);
reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000);
function reinit() { function reinit() {
$.validate.listen.call(this); $.validate.listen.call(this);
$container.find('h3').addClass('animated fadeIn container-animated'); $container.find('h3').addClass('animated fadeIn container-animated');
} }
reinit.call(this), setTimeout(reinit, 500), setTimeout(reinit, 1000);
}; };
/** /**
* 打开一个iframe窗口 * 打开一个iframe窗口
* @param {type} url * @param url
* @returns {unresolved} * @param title
*/ */
_form.prototype.iframe = function (url, title) { _form.prototype.iframe = function (url, title) {
return layer.open({ return layer.open({
@ -365,13 +358,15 @@ define(['zeroclipboard', 'jquery', 'layui'], function (ZeroClipboard) {
/** /**
* 关闭FORM框 * 关闭FORM框
* @returns {undefined} * @return {*|jQuery}
*/ */
_form.prototype.close = function () { _form.prototype.close = function () {
return $(this._modal).modal('hide'); return $(this._modal).modal('hide');
}; };
/*刷新当前页面*/ /**
* 刷新当前页面
*/
_form.prototype.reload = function () { _form.prototype.reload = function () {
window.onhashchange.call(this); window.onhashchange.call(this);
}; };