123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | role.php 角色表
- |--------------------------------------------------------------------------
- */
- # 定义几个常用的选项
- $option = array
- (
- 1 => '可用',
- 2 => '不可用',
- );
- # 获取头部菜单list 建议这里使用匿名函数
- $top = function()
- {
- $data = Dever::load('manage/top.all');
- $data['state'] = 1;
- return $data;
- };
- # 操作权限控制
- $oper = array
- (
- 1 => '浏览',
- 2 => '检索',
- 3 => '更新',
- 4 => '新增',
- 5 => '删除',
- );
- # 是否只能管理自己发布的内容
- $self = array
- (
- 1 => '是',
- 2 => '否',
- );
- # 获取当前登录管理员的所属角色,除id为1外,其余的角色只能管理本角色级别之下的子角色
- $cur = Dever::load('manage/auth.data');
- //print_r($cur);die;
- $desc = '';
- if($cur['role'] > 1)
- {
- $desc = $cur['username'] . ',你好,你可以在此管理你的下属角色';
- # 配置当前列表页的参数
- Dever::$global['model']['manage/role-all'] = Dever::$global['model']['manage/role-list'] = array
- (
- 'option_role_id' => $cur['role'],
- );
- $temp = explode(',', $cur['oper']);
- foreach($oper as $k => $v)
- {
- if(!in_array($k, $temp))
- {
- unset($oper[$k]);
- }
- }
- }
- # 获取权限list 建议这里使用匿名函数
- $auth = function() use($cur)
- {
- if($cur['role'] > 1)
- {
- $auth = Dever::load('manage/auth.get', false);
- }
- else
- {
- $auth = Dever::load('manage/auth.get', true);
- }
- return $auth;
- };
- $role = function() use($cur)
- {
- $param = $array = array();
- if($cur['role'] > 1)
- {
- $param['option_id'] = $cur['role'];
- }
- else
- {
- $array = array(-1 => array('name' => '无'));
- }
-
- $data = Dever::load('manage/role-main', $param);
- if($data)
- {
- $array += $data;
- }
- return $array;
- };
- # 获取权限list 建议这里使用匿名函数
- $auth_data = function()
- {
- $auth_data = Dever::load('manage/auth.getByData');
- return $auth_data;
- };
- //print_r($auth);die;
- $config = array
- (
- # 表名
- 'name' => 'role',
- # 显示给用户看的名称
- 'lang' => '管理角色设置',
- 'desc' => $desc,
- 'order' => 8,
- # 表类型 值为\innodb\myisam\,默认为innodb,仅在mysql类型有效
- 'type' => 'innodb',
- # 数据结构
- 'struct' => array
- (
- 'id' => array
- (
- 'type' => 'int-11',
- 'name' => '角色ID',
- 'default' => '',
- 'desc' => '',
- 'match' => 'is_numeric',
- 'search' => 'order',
- 'list' => true,
- ),
- 'hr0' => array
- (
- 'name' => '基本设置',
- 'class' => '',//本项必须填写
- 'attr' => '',
- ),
-
- 'name' => array
- (
- 'type' => 'varchar-24',
- 'name' => '角色名',
- 'default' => '',
- 'desc' => '请输入角色名',
- 'match' => 'is_string',
- 'update' => 'text',
- 'search' => 'fulltext',
- 'list_name' => '角色名',//定义列表页的名称
- 'list' => true,
- 'edit' => true,
- ),
- 'role_id' => array
- (
- 'type' => 'int-11',
- 'name' => '上级角色',
- 'default' => '-1',
- 'desc' => '请选择上级角色',
- 'match' => 'is_numeric',
- 'update' => 'select',
- 'search' => 'order,select',
- 'list' => '{role_id}',
- 'option' => $role,
- 'edit' => true,
- ),
- 'self' => array
- (
- 'type' => 'tinyint-1',
- 'name' => '是否只能管理自己发布的内容-请在需要此项权限的表中增加[数据查询时影响的字段]',
- 'default' => '2',
- 'desc' => '请选择是否只能管理自己发布的内容',
- 'match' => 'option',
- 'update' => 'radio',
- 'option' => $self,
- 'auth' => '"{my_role_id}"==1',
- ),
- 'col_select' => array
- (
- 'type' => 'varchar-30',
- 'name' => '数据查询时影响的字段-该项影响数据查询,如果在表中增加该字段,则后台在查询数据时自动查询当前管理员的id下的数据,多个用逗号隔开,与[是否只能管理自己发布的内容]相关',
- 'default' => 'admin_founder',
- 'desc' => '数据更新时影响的字段',
- 'match' => 'option',
- 'update' => 'text',
- 'auth' => '"{my_role_id}"==1',
- ),
- 'col_insert' => array
- (
- 'type' => 'varchar-30',
- 'name' => '数据插入时影响的字段-该项影响数据插入,如果在表中增加该字段,则后台操作时自动为该字段赋值为当前管理员的id,多个用逗号隔开',
- 'default' => 'admin_founder',
- 'desc' => '数据插入时影响的字段',
- 'match' => 'option',
- 'update' => 'text',
- 'auth' => '"{my_role_id}"==1',
- ),
- 'col_update' => array
- (
- 'type' => 'varchar-30',
- 'name' => '数据更新时影响的字段-该项影响数据更新,如果在表中增加该字段,则后台操作时自动为该字段赋值为当前管理员的id,多个用逗号隔开',
- 'default' => 'admin_editor',
- 'desc' => '数据更新时影响的字段',
- 'match' => 'option',
- 'update' => 'text',
- 'auth' => '"{my_role_id}"==1',
- ),
-
- /*
- //启用复制其他字段的值
- 'testname' => array
- (
- 'type' => 'varchar-24',
- 'name' => '角色名',
- 'default' => '',
- 'desc' => '请输入角色名',
- 'match' => 'is_string',
- 'update' => 'copy.name',//直接复制name的值
- 'search' => 'order,fulltext',
- 'list' => true,
- ),
- //当前的字段属于另外一个表,主要不要有type
- 'manage-role_test-name'=> array
- (
- 'name' => '测试名',
- 'default' => '',
- 'desc' => '请输入角色名',
- 'match' => 'option',
- 'update' => 'text',//直接复制name的值
- # 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
- 'sync' => array('id', 'role_id'),
- 'list' => true,
- ),
- */
-
-
- #设置分割条
- /*
- 'hr1' => array
- (
- 'name' => '基本信息',
- 'class' => '',//本项必须填写
- 'attr' => '',
- ),
- */
-
- 'oper' => array
- (
- 'type' => 'varchar-24',
- 'name' => '操作权限',
- 'default' => array(1,2,3),
- 'desc' => '请选择操作权限',
- 'match' => 'is_string',
- 'update' => 'checkbox',
- 'option' => $oper,
- ),
- 'hr1' => array
- (
- 'name' => '菜单权限设置',
- 'class' => '',//本项必须填写
- 'attr' => '',
- ),
- 'auth' => array
- (
- 'type' => 'text-255',
- 'name' => '左侧菜单',
- 'default' => '',
- 'desc' => '请选择左侧菜单',
- 'match' => 'option',
- 'update' => 'checkbox',
- //每个项对应的一个input以及父级更新的类型
- //'update_input' => '数量',
- //'update_parent' => 'radio',
- 'option' => $auth,
- ),
- 'top' => array
- (
- 'type' => 'text-255',
- 'name' => '右侧头部菜单',
- 'default' => '',
- 'desc' => '请选择右侧头部菜单',
- 'match' => 'option',
- 'update' => 'checkbox',
- 'option' => $top,
- ),
- 'auth_data' => array
- (
- 'type' => 'text-255',
- 'name' => '数据权限',
- 'default' => '',
- 'desc' => '数据权限',
- 'match' => 'option',
- 'update' => 'checkbox',
- //每个项对应的一个input以及父级更新的类型
- //'update_input' => '数量',
- //'update_parent' => 'radio',
- 'option' => $auth_data,
- ),
- ),
- # 更新表结构 请注意,新增字段已经无需在此增加add了,直接在struct中新增即可。如果是更新字段和删除字段,还需在此加相应配置,并且修改最新的版本号。
- /*
- 'alter' => array
- (
- 1 => array
- (
- array('add', 'top', 'top', 'text-255 头部菜单'),//新增字段
- array('update', 't1', 't2', 'text-255 头部菜单'),//更新字段
- array('delete', 't1'), //删除字段
- ),
- 'version' => 1,
- ),
- */
-
- # 默认值
- 'default' => array
- (
- 'col' => 'name,oper,auth,role_id,col_update,col_insert,col_select,state,cdate',
- 'value' => array
- (
- '"系统管理员","1,2,3,4,5","all",-1,"admin","admin","admin",1,' . time(),
- '"普通管理员","1,2,3,4,5","",-1,"admin","admin","admin",1,' . time(),
- ),
- ),
-
- # 索引
- /*
- 'index' => array
- (
- 1 => array
- (
- # 索引名 => 索引id 如果有后缀.unique,则为建立索引的类型,如id,state.unique
- 'id' => 'id,state',
- ),
-
- # 版本号 更改版本号会更新当前表的索引
- 'version' => 1,
- ),
- */
- # 头部菜单权限管理
- //'auth' => 'customer-project',
-
- # 后台管理 此处的功能全部开放
- 'manage' => array
- (
- # 自定义列表页面
- //'page_list' => 'test',
- # 自定义页面
- /*
- 'page' => 'test',
- # 后台banner
- 'banner' => array
- (
- 'img' => 'Dever::load("project/data.customer#img")',
- 'name' => 'Dever::load("project/data.customer#name")',
- ),
- */
- # 更新数据时,要显示的按钮,这里填写js脚本事件即可。保存当前数据可为固定参数:"save-data",复制数据为:copy-data
- /*
- 'update_button' => array
- (
- '提交保存' => 'save-data',
- '放弃保存' => "msg({status:1,msg:'yes'})",
- '复制数据' => 'copy-datas',
- ),
- */
-
- # 列表页的类型
- //'list_type' => 'parent',
- # 启动自动保存功能
- //'save' => true,
- # 启动预览功能
- 'preview' => true,
-
- # 开启报表下载
- # 涉及到报表下载,如果想使用phpexcel,请用composer安装phpexcel:require中添加 ,"phpoffice/phpexcel": "1.8.1",
- # 否则请使用框架自带的csv
- 'excel' => true,
- # 开启批量管理
- 'mul' => true,
- # 开启主动统计,需要人工选择选项来确定统计的项,有别于被动统计,实现中
- //'stat' => 'top,auth,state,oper,role_id,reorder',//值为不显示的字段,无需输入id和cdate
-
-
- # 列表页每个元素管理下的button,其中'update'为编辑、'delete'为删除,其他可以自定义。
- 'list_button' => array('update' => '编辑'),
-
- # 列表头部的button,多个直接添加字段即可
- 'button' => array
- (
- //'更新接口' => 'manage/api.update',
- )
- ),
- # request 请求接口定义
- 'request' => array
- (
- # all 取所有数据
- 'alls' => array
- (
- # 匹配的正则或函数 选填项
- 'option' => array
- (
- 'name' => array('is_string', 'like'),
- 'state' => 1,
- ),
- 'type' => 'all',
- 'order' => array('id', 'desc'),
- 'col' => '*,name as value,name as label|id',//这里为了做autocomplete进行测试,必须输出value和label
- ),
- # main 取所有主栏目
- 'main' => array
- (
- 'where' => array
- (
- //'role_id' => -1,
- 'state' => 1,
- ),
- 'option' => array
- (
- 'id' => array('yes', 'in'),
- ),
- 'type' => 'all',
- 'order' => array('reorder` desc,`id', 'desc'),
- 'col' => '*|id',
- ),
-
- # 取所有下级栏目
- 'child' => array
- (
- 'where' => array
- (
- 'role_id' => array('1', '>='),
- 'state' => 1,
- ),
- 'type' => 'all',
- 'order' => array('reorder` desc,`id', 'desc'),
- 'col' => '*|role_id|id|',
- ),
-
- # 带有*号前缀的,可以直接接口访问
- '*get' => array
- (
- # 匹配的正则或函数 选填项
- 'where' => array
- (
- 'id' => array('is_string', 'in'),
- ),
- 'type' => 'all',
- 'order' => array('id', 'desc'),
- 'col' => '*',
- ),
-
- # get 根据role的id取多条数据
- 'get' => array
- (
- # 匹配的正则或函数 选填项
- 'where' => array
- (
- 'id' => array('is_string', 'in'),
- ),
- 'type' => 'all',
- 'order' => array('id', 'desc'),
- 'col' => '*|id',
- ),
- ),
- );
- $project = Dever::load('manage/auth-project');
- #Dever::debug('test');
- if($project)
- {
- $config['struct']['hr2'] = array
- (
- 'name' => '项目精细权限设置',
- 'class' => '',//本项必须填写
- 'attr' => '',
- );
- $project_auth = Dever::load('manage/auth.all');
- foreach($project as $k => $v)
- {
- $config['struct']['auth_' . $v['project']] = array
- (
- 'type' => 'text-255',
- 'name' => $v['project_name'] . '下的权限设置',
- 'default' => '',
- 'desc' => '请选择' . $v['project_name'] . '下的权限设置',
- 'match' => 'option',
- 'update' => 'checkbox',
- 'option' => $project_auth[$v['project']],
- );
- }
- }
- $config['struct']['reorder'] = array
- (
- 'type' => 'int-11',
- 'name' => '排序-数值越大越靠前',
- 'default' => '1',
- 'desc' => '请输入排序',
- 'match' => 'option',
- 'update' => 'text',
- 'search' => 'order',
- 'list' => true,
- 'order' => 'desc',
- 'edit' => true,
- );
- $config['struct']['state'] = array
- (
- 'type' => 'tinyint-1',
- 'name' => '状态',
- 'default' => '1',
- 'desc' => '请选择状态',
- 'match' => 'is_numeric',
- //'option' => $option,
- //'update' => 'radio',
- //'list' => true,
- /*
- //启用位运算,仅支持与操作,数据保存时,将从0开始加起,一般用于站点之类的保存,慎用,测试需将radio改成checkbox
- 'bit' => array
- (
- 1 => 1,//1为对应的值,100为保存到数据库中的值
- 2 => 10,
- //4 => 100,
- ),
- */
- );
- $config['struct']['status'] = array
- (
- 'type' => 'tinyint-1',
- 'name' => '状态',
- 'default' => '1',
- 'desc' => '请选择状态',
- 'match' => 'is_numeric',
- 'option' => $option,
- //'update' => 'radio',
- //'list' => true,
- //'edit' => true,
- /*
- //启用位运算,仅支持与操作,数据保存时,将从0开始加起,一般用于站点之类的保存,慎用,测试需将radio改成checkbox
- 'bit' => array
- (
- 1 => 1,//1为对应的值,100为保存到数据库中的值
- 2 => 10,
- //4 => 100,
- ),
- */
- );
- $config['struct']['cdate'] = array
- (
- 'type' => 'int-11',
- 'name' => '录入时间',
- 'match' => array('is_numeric', time()),
- 'desc' => '',
- # 只有insert时才生效
- 'insert' => true,
- # 加入搜索时间区间段
- 'search' => 'date',
- 'list' => 'date("Y-m-d H:i:s", {cdate})',
- );
- return $config;
|