From 921d28f9ce7fcc47b9b8312f92080643eddfe75a Mon Sep 17 00:00:00 2001 From: gongfuxiang Date: Sun, 23 Jan 2022 18:30:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=96=B0=E5=A2=9E=E6=9D=83?= =?UTF-8?q?=E9=99=90=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Plugins.php | 14 + app/admin/controller/Pluginsadmin.php | 2 +- app/admin/controller/Role.php | 3 +- app/admin/view/default/article/save_info.html | 2 +- app/admin/view/default/power/index.html | 68 ++--- app/admin/view/default/role/detail.html | 36 ++- app/admin/view/default/role/save_info.html | 73 +++-- app/service/AdminPowerService.php | 27 +- app/service/AdminRoleService.php | 252 +++++++++++++----- app/service/AdminService.php | 1 + app/service/PluginsAdminService.php | 33 ++- config/shopxo.php | 10 +- public/static/admin/default/css/power.css | 24 +- public/static/admin/default/css/role.css | 33 +-- public/static/admin/default/js/power.js | 22 +- 15 files changed, 411 insertions(+), 189 deletions(-) diff --git a/app/admin/controller/Plugins.php b/app/admin/controller/Plugins.php index 0b23641fd..82e467813 100755 --- a/app/admin/controller/Plugins.php +++ b/app/admin/controller/Plugins.php @@ -84,6 +84,20 @@ class Plugins extends Common } } + // 插件权限校验 + $power_plugins = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$this->admin['id']); + if(empty($power_plugins) || !array_key_exists($params['data_request']['pluginsname'], $power_plugins)) + { + $msg = '无权限使用该插件'; + if(IS_AJAX) + { + return DataReturn($msg, -5000); + } else { + MyViewAssign('msg', $msg); + return MyView('public/tips_error'); + } + } + // 应用名称/控制器/方法 $pluginsname = $params['data_request']['pluginsname']; $pluginscontrol = strtolower($params['data_request']['pluginscontrol']); diff --git a/app/admin/controller/Pluginsadmin.php b/app/admin/controller/Pluginsadmin.php index 5789f295d..feef2f539 100755 --- a/app/admin/controller/Pluginsadmin.php +++ b/app/admin/controller/Pluginsadmin.php @@ -69,7 +69,7 @@ class Pluginsadmin extends Common if($this->view_type == 'home') { // 插件列表 - $ret = PluginsAdminService::PluginsList(); + $ret = PluginsAdminService::PluginsList(['is_power'=>true]); MyViewAssign('data_list', $ret['data']); // 插件更新信息 diff --git a/app/admin/controller/Role.php b/app/admin/controller/Role.php index 0113b9489..1b20f038d 100644 --- a/app/admin/controller/Role.php +++ b/app/admin/controller/Role.php @@ -136,7 +136,7 @@ class Role extends Common } } - // 菜单列表 + // 权限列表 $power = AdminRoleService::RolePowerEditData($params); MyViewAssign('power', $power); @@ -148,6 +148,7 @@ class Role extends Common 'is_backend' => true, 'role_id' => isset($params['id']) ? $params['id'] : 0, 'data' => &$data, + 'power' => &$power, 'params' => &$params, ])); diff --git a/app/admin/view/default/article/save_info.html b/app/admin/view/default/article/save_info.html index be635e23f..daf60d54e 100755 --- a/app/admin/view/default/article/save_info.html +++ b/app/admin/view/default/article/save_info.html @@ -31,7 +31,7 @@
- +
diff --git a/app/admin/view/default/power/index.html b/app/admin/view/default/power/index.html index b6a6656a6..b9f88a17e 100755 --- a/app/admin/view/default/power/index.html +++ b/app/admin/view/default/power/index.html @@ -14,7 +14,7 @@
- +
@@ -86,41 +86,41 @@ - +
diff --git a/app/admin/view/default/role/detail.html b/app/admin/view/default/role/detail.html index dae634523..c5600394c 100644 --- a/app/admin/view/default/role/detail.html +++ b/app/admin/view/default/role/detail.html @@ -6,14 +6,38 @@ {__block__} - +
-
权限项
+
菜单权限
-
    - {{foreach $data.items as $item}} -
  • {{$item}}
  • - {{/foreach}} + +
+
+ + +
+
插件权限
+
+
diff --git a/app/admin/view/default/role/save_info.html b/app/admin/view/default/role/save_info.html index c4c7fa9e4..7e8293981 100755 --- a/app/admin/view/default/role/save_info.html +++ b/app/admin/view/default/role/save_info.html @@ -15,33 +15,56 @@
- -
+ +
+ +
diff --git a/app/service/AdminPowerService.php b/app/service/AdminPowerService.php index 07cf3d32e..9b9dde23c 100755 --- a/app/service/AdminPowerService.php +++ b/app/service/AdminPowerService.php @@ -12,6 +12,7 @@ namespace app\service; use think\facade\Db; use app\service\AdminService; +use app\service\AdminRoleService; /** * 权限菜单服务层 @@ -188,21 +189,23 @@ class AdminPowerService { foreach($admin as $id) { - MyCache(MyConfig('shopxo.cache_admin_power_key').$id, null); MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$id, null); + MyCache(MyConfig('shopxo.cache_admin_power_key').$id, null); + MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$id, null); } } } - + /** * 管理员权限菜单初始化 - * @author Devil + * @author Devil * @blog http://gong.gg/ * @version 1.0.0 - * @date 2018-12-06 + * @date 2022-01-23 * @desc description + * @param [boolean] $is_refresh [是否强制刷新] */ - public static function PowerMenuInit() + public static function PowerMenuInit($is_refresh = false) { // 基础参数 $admin = AdminService::LoginInfo(); @@ -212,9 +215,10 @@ class AdminPowerService // 读取缓存数据 $admin_left_menu = MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin_id); $admin_power = MyCache(MyConfig('shopxo.cache_admin_power_key').$admin_id); + $admin_plugins = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin_id); // 缓存没数据则从数据库重新读取 - if((($role_id > 0 || $admin_id == 1) && empty($admin_left_menu)) || MyEnv('app_debug')) + if((($role_id > 0 || $admin_id == 1) && empty($admin_left_menu)) || $is_refresh || MyEnv('app_debug')) { // 获取一级数据 if($admin_id == 1 || $role_id == 1) @@ -229,6 +233,7 @@ class AdminPowerService // 有数据,则处理子级数据 if(!empty($admin_left_menu)) { + // 菜单权限 foreach($admin_left_menu as $k=>$v) { // 是否存在控制器和方法 @@ -294,9 +299,19 @@ class AdminPowerService unset($admin_left_menu[$k]); } } + + // 插件权限 + if($admin_id == 1 || $role_id == 1) + { + $plugins_data = AdminRoleService::PluginsList(); + $admin_plugins = empty($plugins_data) ? [] : array_column($plugins_data, 'name', 'plugins'); + } else { + $admin_plugins = Db::name('RolePlugins')->where(['role_id'=>$role_id])->column('name', 'plugins'); + } } MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin_id, $admin_left_menu); MyCache(MyConfig('shopxo.cache_admin_power_key').$admin_id, $admin_power); + MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin_id, $admin_plugins); } return true; } diff --git a/app/service/AdminRoleService.php b/app/service/AdminRoleService.php index 6655ff26c..de267e32d 100644 --- a/app/service/AdminRoleService.php +++ b/app/service/AdminRoleService.php @@ -12,6 +12,7 @@ namespace app\service; use think\facade\Db; use app\service\AdminPowerService; +use app\service\PluginsAdminService; /** * 角色服务层 @@ -42,29 +43,50 @@ class AdminRoleService $data = Db::name('Role')->field($field)->where($where)->order($order_by)->limit($m, $n)->select()->toArray(); if(!empty($data)) { - // 获取对应权限数据 - $powers = []; + // 获取对应菜单权限数据 + $power_list = []; $ids = array_column($data, 'id'); $powers_data = Db::name('Role')->alias('r')->join('role_power rp', 'rp.role_id = r.id')->join('power p', 'rp.power_id = p.id')->where(['r.id'=>$ids])->field('rp.role_id, rp.power_id, p.name')->select()->toArray(); if(!empty($powers_data)) { foreach($powers_data as $p) { - $powers[$p['role_id']][] = $p['name']; + $power_list[$p['role_id']][] = $p['name']; } } + + // 获取插件权限 + $power_plugins_list = []; + $powers_data = Db::name('Role')->alias('r')->join('role_plugins rp', 'rp.role_id = r.id')->where(['r.id'=>$ids])->field('rp.role_id, rp.plugins, rp.name')->select()->toArray(); + if(!empty($powers_data)) + { + foreach($powers_data as $p) + { + $power_plugins_list[$p['role_id']][] = $p['name']; + } + } + + // 是否存在超级管理角色组 // 超级管理员数据库中并没存储关联关系,所以这里直接读取全部权限菜单 if(in_array(1, $ids)) { - $powers[1] = Db::name('Power')->column('name'); + // 全部菜单 + $power_list[1] = Db::name('Power')->column('name'); + + // 全部插件 + $plugins_data = self::PluginsList(); + $power_plugins_list[1] = empty($plugins_data) ? [] : array_column($plugins_data, 'name'); } // 循环处理数据 foreach($data as &$v) { - // 对应权限数据 - $v['items'] = array_key_exists($v['id'], $powers) ? $powers[$v['id']] : []; + // 对应菜单权限数据 + $v['power'] = array_key_exists($v['id'], $power_list) ? $power_list[$v['id']] : []; + + // 对应插件权限数据 + $v['power_plugins'] = array_key_exists($v['id'], $power_plugins_list) ? $power_plugins_list[$v['id']] : []; // 时间 $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']); @@ -138,7 +160,6 @@ class AdminRoleService { // 当前角色关联的所有菜单id $action = empty($params['role_id']) ? [] : Db::name('RolePower')->where(['role_id'=>$params['role_id']])->column('power_id'); - // 权限列表 $power_field = 'id,name,is_show'; $power = Db::name('Power')->field($power_field)->where(['pid'=>0])->order('sort')->select()->toArray(); @@ -161,7 +182,32 @@ class AdminRoleService } } } - return $power; + + // 插件权限 + $plugins = []; + $action = empty($params['role_id']) ? [] : Db::name('RolePlugins')->where(['role_id'=>$params['role_id']])->column('plugins'); + // 插件列表 + $plugins_data = self::PluginsList(); + if(!empty($plugins_data)) + { + foreach($plugins_data as $pv) + { + if(!empty($pv['plugins']) && !empty($pv['name']) && !empty($pv['logo'])) + { + $plugins[] = [ + 'plugins' => $pv['plugins'], + 'name' => $pv['name'], + 'logo' => $pv['logo'], + 'is_power' => (empty($action) || !in_array($pv['plugins'], $action)) ? 'no' : 'ok', + ]; + } + } + } + + return [ + 'power' => $power, + 'plugins' => $plugins, + ]; } /** @@ -201,79 +247,115 @@ class AdminRoleService return DataReturn($ret, -1); } - // 开启事务 + // 启动事务 Db::startTrans(); - // 角色数据更新 - $role_data = [ - 'name' => $params['name'], - 'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0, - 'upd_time' => time(), - ]; + // 捕获异常 + try { + // 角色数据更新 + $role_data = [ + 'name' => $params['name'], + 'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0, + 'upd_time' => time(), + ]; - // 不存在添加,则更新 - if(empty($params['id'])) - { - $role_data['add_time'] = time(); - $role_id = Db::name('Role')->insertGetId($role_data); - } else { - // 是否包含删除超级管理员角色 - if($params['id'] == 1) + // 不存在添加,则更新 + if(empty($params['id'])) { - return DataReturn('超级管理员角色不可编辑', -1); - } - - // 更新 - if(Db::name('Role')->where(['id'=>$params['id']])->update($role_data) !== false) - { - $role_id = $params['id']; - } - } - if(empty($role_id)) - { - Db::rollback(); - return DataReturn('角色数据保存失败', -2); - } - - // 权限关联数据删除 - if(Db::name('RolePower')->where(['role_id'=>$role_id])->delete() === false) - { - Db::rollback(); - return DataReturn('角色权限操作失败', -3); - } - - // 权限关联数据添加 - if(!empty($params['power_id'])) - { - $rp_data = []; - foreach(explode(',', $params['power_id']) as $power_id) - { - if(!empty($power_id)) + $role_data['add_time'] = time(); + $role_id = Db::name('Role')->insertGetId($role_data); + } else { + // 是否包含删除超级管理员角色 + if($params['id'] == 1) { - $rp_data[] = [ - 'role_id' => $role_id, - 'power_id' => $power_id, - 'add_time' => time(), - ]; + throw new \Exception('超级管理员角色不可编辑'); + } + + // 更新 + if(Db::name('Role')->where(['id'=>$params['id']])->update($role_data) !== false) + { + $role_id = $params['id']; } } - if(!empty($rp_data)) + if(empty($role_id)) { - if(Db::name('RolePower')->insertAll($rp_data) < count($rp_data)) + throw new \Exception('角色数据保存失败'); + } + + // 菜单权限数据删除 + if(Db::name('RolePower')->where(['role_id'=>$role_id])->delete() === false) + { + throw new \Exception('角色菜单权限操作失败'); + } + + // 菜单权限数据添加 + if(!empty($params['power_id'])) + { + $rp_data = []; + foreach(explode(',', $params['power_id']) as $power_id) { - Db::rollback(); - return DataReturn('角色权限添加失败', -10); + if(!empty($power_id)) + { + $rp_data[] = [ + 'role_id' => $role_id, + 'power_id' => $power_id, + 'add_time' => time(), + ]; + } + } + if(!empty($rp_data)) + { + if(Db::name('RolePower')->insertAll($rp_data) < count($rp_data)) + { + throw new \Exception('角色菜单权限添加失败'); + } } } + + // 插件权限删除 + if(Db::name('RolePlugins')->where(['role_id'=>$role_id])->delete() === false) + { + throw new \Exception('角色插件权限操作失败'); + } + + // 插件权限数据添加 + if(!empty($params['plugins'])) + { + $plugins_data = self::PluginsList(); + $plugins_list = empty($plugins_data) ? [] : array_column($plugins_data, null, 'plugins'); + $rp_data = []; + foreach(explode(',', $params['plugins']) as $plugins) + { + if(!empty($plugins) && array_key_exists($plugins, $plugins_list)) + { + $rp_data[] = [ + 'role_id' => $role_id, + 'name' => $plugins_list[$plugins]['name'], + 'plugins' => $plugins, + 'add_time' => time(), + ]; + } + } + if(!empty($rp_data)) + { + if(Db::name('RolePlugins')->insertAll($rp_data) < count($rp_data)) + { + throw new \Exception('角色插件权限添加失败'); + } + } + } + + // 提交事务 + Db::commit(); + + // 清除用户权限数据 + AdminPowerService::PowerCacheDelete(); + + return DataReturn('操作成功', 0); + } catch(\Exception $e) { + Db::rollback(); + return DataReturn($e->getMessage(), -1); } - - // 提交事务 - Db::commit(); - - // 清除用户权限数据 - AdminPowerService::PowerCacheDelete(); - - return DataReturn('操作成功', 0); } /** @@ -307,7 +389,7 @@ class AdminRoleService Db::startTrans(); // 删除角色 - if(Db::name('Role')->where(['id'=>$params['ids']])->delete() !== false && Db::name('RolePower')->where(['role_id'=>$params['ids']])->delete() !== false) + if(Db::name('Role')->where(['id'=>$params['ids']])->delete() !== false && Db::name('RolePower')->where(['role_id'=>$params['ids']])->delete() !== false && Db::name('RolePlugins')->where(['role_id'=>$params['ids']])->delete() !== false) { // 提交事务 Db::commit(); @@ -321,5 +403,35 @@ class AdminRoleService Db::rollback(); return DataReturn('删除失败', -100); } + + /** + * 获取插件列表 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-01-23 + * @desc description + * @param [array] $params [输入参数] + */ + public static function PluginsList($params = []) + { + $result = []; + $res = PluginsAdminService::PluginsList(); + if(!empty($res['data'])) + { + // 已安装的插件 + if(!empty($res['data']['db_data'])) + { + $result = $res['data']['db_data']; + } + + // 未安装的插件 + if(!empty($res['data']['dir_data'])) + { + $result = array_merge($result, $res['data']['dir_data']); + } + } + return $result; + } } ?> \ No newline at end of file diff --git a/app/service/AdminService.php b/app/service/AdminService.php index 401f054d2..bba445271 100755 --- a/app/service/AdminService.php +++ b/app/service/AdminService.php @@ -508,6 +508,7 @@ class AdminService // 清空权限缓存数据 MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin['id'], null); MyCache(MyConfig('shopxo.cache_admin_power_key').$admin['id'], null); + MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin['id'], null); // 权限菜单初始化 AdminPowerService::PowerMenuInit(); diff --git a/app/service/PluginsAdminService.php b/app/service/PluginsAdminService.php index d2a99ff1b..d1bf2cc40 100755 --- a/app/service/PluginsAdminService.php +++ b/app/service/PluginsAdminService.php @@ -14,6 +14,8 @@ use think\facade\Db; use app\service\PluginsService; use app\service\ResourcesService; use app\service\SqlConsoleService; +use app\service\AdminPowerService; +use app\service\AdminService; /** * 应用管理服务层 @@ -53,6 +55,23 @@ class PluginsAdminService { if($dh = opendir($plugins_dir)) { + // 是否需要校验权限 + $power_plugins = []; + $is_power = (isset($params['is_power']) && $params['is_power'] == true); + if($is_power) + { + // 获取当前登录账户的插件权限 + $admin = AdminService::LoginInfo(); + if(!empty($admin)) + { + $res = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin['id']); + if(!empty($res)) + { + $power_plugins = $res; + } + } + } + // 获取数据库已安装插件 $temp_data = Db::name('Plugins')->order(self::$plugins_order_by)->column('*', 'plugins'); @@ -67,9 +86,18 @@ class PluginsAdminService { // 获取数据库配置信息 $base = $config['base']; - $db_config = array_key_exists($base['plugins'], $temp_data) ? $temp_data[$base['plugins']] : []; + + // 是否需要判断权限 + if($is_power == true) + { + if(empty($power_plugins) || !array_key_exists($base['plugins'], $power_plugins)) + { + continue; + } + } // 数据组装 + $db_config = array_key_exists($base['plugins'], $temp_data) ? $temp_data[$base['plugins']] : []; $dir_data[$base['plugins']] = [ 'id' => empty($db_config['id']) ? 0 : $db_config['id'], 'plugins' => $base['plugins'], @@ -1026,6 +1054,9 @@ php; } $plugins = $ret['data']; + // 强制刷新用户权限缓存 + AdminPowerService::PowerMenuInit(true); + // 附件同步到数据库 ResourcesService::AttachmentDiskFilesToDb('plugins_'.$plugins); diff --git a/config/shopxo.php b/config/shopxo.php index c9628e328..17be8c358 100755 --- a/config/shopxo.php +++ b/config/shopxo.php @@ -36,12 +36,12 @@ return [ // 默认编码 'default_charset' => 'utf-8', - // 后端缓存key列表 - // 权限缓存存储key - 'cache_admin_power_key' => 'cache_admin_power_', - - // 菜单列表 + // 后端菜单缓存key列表 + // 菜单权限缓存存储key + // 插件权限缓存存储key 'cache_admin_left_menu_key' => 'cache_admin_left_menu_', + 'cache_admin_power_key' => 'cache_admin_power_', + 'cache_admin_power_plugins_key' => 'cache_admin_power_plugins_', // 公共缓存key列表 diff --git a/public/static/admin/default/css/power.css b/public/static/admin/default/css/power.css index 015ebebe0..223f65cfc 100644 --- a/public/static/admin/default/css/power.css +++ b/public/static/admin/default/css/power.css @@ -1,16 +1,10 @@ -/** - * 权限添加/编辑 - */ -.tree-list li { list-style-type: none; padding-left: 5px !important; } -.tree-list li label { display: inline; } -.list-find { margin: 0px 0px 5px 35px; overflow: hidden; padding-top: 5px !important; } -.tree-list i { width: 10px; } -.list-find li { line-height: 26px; } -.list-find span { font-weight: normal; } -.tree-list li { border:1px dashed #d3ebf7; background: #f5fafd; padding: 6px 10px; } -.list-find li { background: #ecf8ff; float: left; margin: 0px 10px 10px 0px; } -.list-find li input[type="checkbox"] { vertical-align: text-top; } -@media only screen and (min-width: 641px) { - .list-submit, .find-submit { display: none; } - .list-find li:hover .find-submit, .tree-list li:hover .list-submit { display: block !important; } +.tree-list li { + list-style-type: none; +} +.tree-list li .item-content { + border:1px dashed #ceecff; + background: #ddf2ff; +} +.tree-list li .stretch { + cursor: pointer; } \ No newline at end of file diff --git a/public/static/admin/default/css/role.css b/public/static/admin/default/css/role.css index 015ebebe0..f82f2234d 100755 --- a/public/static/admin/default/css/role.css +++ b/public/static/admin/default/css/role.css @@ -1,16 +1,19 @@ -/** - * 权限添加/编辑 - */ -.tree-list li { list-style-type: none; padding-left: 5px !important; } -.tree-list li label { display: inline; } -.list-find { margin: 0px 0px 5px 35px; overflow: hidden; padding-top: 5px !important; } -.tree-list i { width: 10px; } -.list-find li { line-height: 26px; } -.list-find span { font-weight: normal; } -.tree-list li { border:1px dashed #d3ebf7; background: #f5fafd; padding: 6px 10px; } -.list-find li { background: #ecf8ff; float: left; margin: 0px 10px 10px 0px; } -.list-find li input[type="checkbox"] { vertical-align: text-top; } -@media only screen and (min-width: 641px) { - .list-submit, .find-submit { display: none; } - .list-find li:hover .find-submit, .tree-list li:hover .list-submit { display: block !important; } +.tree-list li { + list-style-type: none; +} +.tree-list li .item-content { + border:1px dashed #ceecff; + background: #ddf2ff; +} +.tree-list li label, +.tree-list li label input[type="checkbox"] { + cursor: pointer; + margin: 0; +} +.tree-list li label input[type="checkbox"], +.tree-list li label span { + vertical-align: middle; +} +.list-find li label span { + font-weight: normal; } \ No newline at end of file diff --git a/public/static/admin/default/js/power.js b/public/static/admin/default/js/power.js index 7ba7d1831..7ab34a543 100755 --- a/public/static/admin/default/js/power.js +++ b/public/static/admin/default/js/power.js @@ -3,7 +3,7 @@ $(function() /** * 展开/关闭 */ - $('.tree-list i').on('click', function() + $('.tree-list i.stretch').on('click', function() { if($(this).hasClass('am-icon-plus')) { @@ -13,7 +13,7 @@ $(function() $(this).removeClass('am-icon-minus-square'); $(this).addClass('am-icon-plus'); } - $(this).parent().next('.list-find').toggle(100); + $(this).parents('li').next('ul.list-find').toggle(100); }); /** @@ -21,21 +21,23 @@ $(function() */ $('.submit-add').on('click', function() { - // 更改窗口名称 - $title = $('#power-save-win').find('.am-popup-title'); - $title.text($title.data('add-title')); + // 移除菜单禁止状态 + $('form select[name="pid"]').removeAttr('disabled'); // 清空表单 FormDataFill({"id":"", "pid":0, "name":"", "control":"", "action":"", "icon":"", "sort":0, "is_show":1}); - // 移除菜单禁止状态 - $('form select[name="pid"]').removeAttr('disabled'); - // 校验成功状态增加失去焦点 $('form').find('.am-field-valid').each(function() { $(this).blur(); }); + + // 更改窗口名称 + var $popup = $('#power-save-win'); + $title = $popup.find('.am-popup-title'); + $title.text($title.data('add-title')); + $popup.modal('open'); }); /** @@ -44,7 +46,8 @@ $(function() $('.submit-edit').on('click', function() { // 更改窗口名称 - $title = $('#power-save-win').find('.am-popup-title'); + var $popup = $('#power-save-win'); + $title = $popup.find('.am-popup-title'); $title.text($title.data('edit-title')); // 父级禁用菜单列表选择 @@ -54,5 +57,6 @@ $(function() } else { $('form select[name="pid"]').removeAttr('disabled'); } + $popup.modal('open'); }); }); \ No newline at end of file