role.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | role.php 角色表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $option = array
  9. (
  10. 1 => '可用',
  11. 2 => '不可用',
  12. );
  13. # 获取头部菜单list 建议这里使用匿名函数
  14. $top = function()
  15. {
  16. $data = Dever::load('manage/top.all');
  17. $data['state'] = 1;
  18. return $data;
  19. };
  20. # 操作权限控制
  21. $oper = array
  22. (
  23. 1 => '浏览',
  24. 2 => '检索',
  25. 3 => '更新',
  26. 4 => '新增',
  27. 5 => '删除',
  28. );
  29. # 是否只能管理自己发布的内容
  30. $self = array
  31. (
  32. 1 => '是',
  33. 2 => '否',
  34. );
  35. # 获取当前登录管理员的所属角色,除id为1外,其余的角色只能管理本角色级别之下的子角色
  36. $cur = Dever::load('manage/auth.data');
  37. //print_r($cur);die;
  38. $desc = '';
  39. if($cur['role'] > 1)
  40. {
  41. $desc = $cur['username'] . ',你好,你可以在此管理你的下属角色';
  42. # 配置当前列表页的参数
  43. Dever::$global['model']['manage/role-all'] = Dever::$global['model']['manage/role-list'] = array
  44. (
  45. 'option_role_id' => $cur['role'],
  46. );
  47. $temp = explode(',', $cur['oper']);
  48. foreach($oper as $k => $v)
  49. {
  50. if(!in_array($k, $temp))
  51. {
  52. unset($oper[$k]);
  53. }
  54. }
  55. }
  56. # 获取权限list 建议这里使用匿名函数
  57. $auth = function() use($cur)
  58. {
  59. if($cur['role'] > 1)
  60. {
  61. $auth = Dever::load('manage/auth.get', false);
  62. }
  63. else
  64. {
  65. $auth = Dever::load('manage/auth.get', true);
  66. }
  67. return $auth;
  68. };
  69. $role = function() use($cur)
  70. {
  71. $param = $array = array();
  72. if($cur['role'] > 1)
  73. {
  74. $param['option_id'] = $cur['role'];
  75. }
  76. else
  77. {
  78. $array = array(-1 => array('name' => '无'));
  79. }
  80. $data = Dever::load('manage/role-main', $param);
  81. if($data)
  82. {
  83. $array += $data;
  84. }
  85. return $array;
  86. };
  87. //print_r($auth);die;
  88. $config = array
  89. (
  90. # 表名
  91. 'name' => 'role',
  92. # 显示给用户看的名称
  93. 'lang' => '管理角色设置',
  94. 'desc' => $desc,
  95. 'order' => 8,
  96. # 表类型 值为\innodb\myisam\,默认为innodb,仅在mysql类型有效
  97. 'type' => 'innodb',
  98. # 数据结构
  99. 'struct' => array
  100. (
  101. 'id' => array
  102. (
  103. 'type' => 'int-11',
  104. 'name' => '角色ID',
  105. 'default' => '',
  106. 'desc' => '',
  107. 'match' => 'is_numeric',
  108. 'search' => 'order',
  109. 'list' => true,
  110. ),
  111. 'name' => array
  112. (
  113. 'type' => 'varchar-24',
  114. 'name' => '角色名',
  115. 'default' => '',
  116. 'desc' => '请输入角色名',
  117. 'match' => 'is_string',
  118. 'update' => 'text',
  119. 'search' => 'fulltext',
  120. 'list_name' => '角色名',//定义列表页的名称
  121. 'list' => true,
  122. 'edit' => true,
  123. ),
  124. 'role_id' => array
  125. (
  126. 'type' => 'int-11',
  127. 'name' => '上级角色',
  128. 'default' => '-1',
  129. 'desc' => '请选择上级角色',
  130. 'match' => 'is_numeric',
  131. 'update' => 'select',
  132. 'search' => 'order,select',
  133. 'list' => '{role_id}',
  134. 'option' => $role,
  135. 'edit' => true,
  136. ),
  137. 'self' => array
  138. (
  139. 'type' => 'tinyint-1',
  140. 'name' => '是否只能管理自己发布的内容-请在需要此项权限的表中增加[数据查询时影响的字段]',
  141. 'default' => '2',
  142. 'desc' => '请选择是否只能管理自己发布的内容',
  143. 'match' => 'option',
  144. 'update' => 'radio',
  145. 'option' => $self,
  146. 'auth' => '{my_role_id}==1',
  147. ),
  148. 'col_select' => array
  149. (
  150. 'type' => 'varchar-30',
  151. 'name' => '数据查询时影响的字段-该项影响数据查询,如果在表中增加该字段,则后台在查询数据时自动查询当前管理员的id下的数据,多个用逗号隔开,与[是否只能管理自己发布的内容]相关',
  152. 'default' => '',
  153. 'desc' => '数据更新时影响的字段',
  154. 'match' => 'option',
  155. 'update' => 'text',
  156. 'auth' => '{my_role_id}==1',
  157. ),
  158. 'col_insert' => array
  159. (
  160. 'type' => 'varchar-30',
  161. 'name' => '数据插入时影响的字段-该项影响数据插入,如果在表中增加该字段,则后台操作时自动为该字段赋值为当前管理员的id,多个用逗号隔开',
  162. 'default' => '',
  163. 'desc' => '数据插入时影响的字段',
  164. 'match' => 'option',
  165. 'update' => 'text',
  166. 'auth' => '{my_role_id}==1',
  167. ),
  168. 'col_update' => array
  169. (
  170. 'type' => 'varchar-30',
  171. 'name' => '数据更新时影响的字段-该项影响数据更新,如果在表中增加该字段,则后台操作时自动为该字段赋值为当前管理员的id,多个用逗号隔开',
  172. 'default' => '',
  173. 'desc' => '数据更新时影响的字段',
  174. 'match' => 'option',
  175. 'update' => 'text',
  176. 'auth' => '{my_role_id}==1',
  177. ),
  178. /*
  179. //启用复制其他字段的值
  180. 'testname' => array
  181. (
  182. 'type' => 'varchar-24',
  183. 'name' => '角色名',
  184. 'default' => '',
  185. 'desc' => '请输入角色名',
  186. 'match' => 'is_string',
  187. 'update' => 'copy.name',//直接复制name的值
  188. 'search' => 'order,fulltext',
  189. 'list' => true,
  190. ),
  191. //当前的字段属于另外一个表,主要不要有type
  192. 'manage-role_test-name'=> array
  193. (
  194. 'name' => '测试名',
  195. 'default' => '',
  196. 'desc' => '请输入角色名',
  197. 'match' => 'option',
  198. 'update' => 'text',//直接复制name的值
  199. # 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
  200. 'sync' => array('id', 'role_id'),
  201. 'list' => true,
  202. ),
  203. */
  204. #设置分割条
  205. /*
  206. 'hr1' => array
  207. (
  208. 'name' => '基本信息',
  209. 'class' => '',//本项必须填写
  210. 'attr' => '',
  211. ),
  212. */
  213. 'oper' => array
  214. (
  215. 'type' => 'varchar-24',
  216. 'name' => '操作权限',
  217. 'default' => array(1,2,3),
  218. 'desc' => '请选择操作权限',
  219. 'match' => 'is_string',
  220. 'update' => 'checkbox',
  221. 'option' => $oper,
  222. ),
  223. 'hr1' => array
  224. (
  225. 'name' => '菜单权限设置',
  226. 'class' => '',//本项必须填写
  227. 'attr' => '',
  228. ),
  229. 'auth' => array
  230. (
  231. 'type' => 'text-255',
  232. 'name' => '左侧菜单',
  233. 'default' => '',
  234. 'desc' => '请选择左侧菜单',
  235. 'match' => 'option',
  236. 'update' => 'checkbox',
  237. //每个项对应的一个input以及父级更新的类型
  238. //'update_input' => '数量',
  239. //'update_parent' => 'radio',
  240. 'option' => $auth,
  241. ),
  242. 'top' => array
  243. (
  244. 'type' => 'text-255',
  245. 'name' => '右侧头部菜单',
  246. 'default' => '',
  247. 'desc' => '请选择右侧头部菜单',
  248. 'match' => 'option',
  249. 'update' => 'checkbox',
  250. 'option' => $top,
  251. ),
  252. ),
  253. # 更新表结构 请注意,新增字段已经无需在此增加add了,直接在struct中新增即可。如果是更新字段和删除字段,还需在此加相应配置,并且修改最新的版本号。
  254. /*
  255. 'alter' => array
  256. (
  257. 1 => array
  258. (
  259. array('add', 'top', 'top', 'text-255 头部菜单'),//新增字段
  260. array('update', 't1', 't2', 'text-255 头部菜单'),//更新字段
  261. array('delete', 't1'), //删除字段
  262. ),
  263. 'version' => 1,
  264. ),
  265. */
  266. # 默认值
  267. 'default' => array
  268. (
  269. 'col' => 'name,oper,auth,role_id,col_update,col_insert,col_select,state,cdate',
  270. 'value' => array
  271. (
  272. '"系统管理员","1,2,3,4,5","all",-1,"admin","admin","admin",1,' . time(),
  273. '"普通管理员","1,2,3,4,5","",-1,"admin","admin","admin",1,' . time(),
  274. ),
  275. ),
  276. # 索引
  277. /*
  278. 'index' => array
  279. (
  280. 1 => array
  281. (
  282. # 索引名 => 索引id 如果有后缀.unique,则为建立索引的类型,如id,state.unique
  283. 'id' => 'id,state',
  284. ),
  285. # 版本号 更改版本号会更新当前表的索引
  286. 'version' => 1,
  287. ),
  288. */
  289. # 头部菜单权限管理
  290. //'auth' => 'customer-project',
  291. # 后台管理 此处的功能全部开放
  292. 'manage' => array
  293. (
  294. # 自定义列表页面
  295. //'page_list' => 'test',
  296. # 自定义页面
  297. /*
  298. 'page' => 'test',
  299. # 后台banner
  300. 'banner' => array
  301. (
  302. 'img' => 'Dever::load("project/data.customer#img")',
  303. 'name' => 'Dever::load("project/data.customer#name")',
  304. ),
  305. */
  306. # 更新数据时,要显示的按钮,这里填写js脚本事件即可。保存当前数据可为固定参数:"save-data",复制数据为:copy-data
  307. /*
  308. 'update_button' => array
  309. (
  310. '提交保存' => 'save-data',
  311. '放弃保存' => "msg({status:1,msg:'yes'})",
  312. '复制数据' => 'copy-datas',
  313. ),
  314. */
  315. # 列表页的类型
  316. //'list_type' => 'parent',
  317. # 启动自动保存功能
  318. //'save' => true,
  319. # 启动预览功能
  320. 'preview' => true,
  321. # 开启报表下载
  322. # 涉及到报表下载,如果想使用phpexcel,请用composer安装phpexcel:require中添加 ,"phpoffice/phpexcel": "1.8.1",
  323. # 否则请使用框架自带的csv
  324. 'excel' => true,
  325. # 开启批量管理
  326. 'mul' => true,
  327. # 开启主动统计,需要人工选择选项来确定统计的项,有别于被动统计,实现中
  328. //'stat' => 'top,auth,state,oper,role_id,reorder',//值为不显示的字段,无需输入id和cdate
  329. # 列表页每个元素管理下的button,其中'update'为编辑、'delete'为删除,其他可以自定义。
  330. 'list_button' => array('update' => '编辑'),
  331. # 列表头部的button,多个直接添加字段即可
  332. 'button' => array
  333. (
  334. //'更新接口' => 'manage/api.update',
  335. )
  336. ),
  337. # request 请求接口定义
  338. 'request' => array
  339. (
  340. # all 取所有数据
  341. 'alls' => array
  342. (
  343. # 匹配的正则或函数 选填项
  344. 'option' => array
  345. (
  346. 'name' => array('is_string', 'like'),
  347. 'state' => 1,
  348. ),
  349. 'type' => 'all',
  350. 'order' => array('id', 'desc'),
  351. 'col' => '*,name as value,name as label|id',//这里为了做autocomplete进行测试,必须输出value和label
  352. ),
  353. # main 取所有主栏目
  354. 'main' => array
  355. (
  356. 'where' => array
  357. (
  358. //'role_id' => -1,
  359. 'state' => 1,
  360. ),
  361. 'option' => array
  362. (
  363. 'id' => array('yes', 'in'),
  364. ),
  365. 'type' => 'all',
  366. 'order' => array('reorder` desc,`id', 'desc'),
  367. 'col' => '*|id',
  368. ),
  369. # 取所有下级栏目
  370. 'child' => array
  371. (
  372. 'where' => array
  373. (
  374. 'role_id' => array('1', '>='),
  375. 'state' => 1,
  376. ),
  377. 'type' => 'all',
  378. 'order' => array('reorder` desc,`id', 'desc'),
  379. 'col' => '*|role_id|id|',
  380. ),
  381. # 带有*号前缀的,可以直接接口访问
  382. '*get' => array
  383. (
  384. # 匹配的正则或函数 选填项
  385. 'where' => array
  386. (
  387. 'id' => array('is_string', 'in'),
  388. ),
  389. 'type' => 'all',
  390. 'order' => array('id', 'desc'),
  391. 'col' => '*',
  392. ),
  393. # get 根据role的id取多条数据
  394. 'get' => array
  395. (
  396. # 匹配的正则或函数 选填项
  397. 'where' => array
  398. (
  399. 'id' => array('is_string', 'in'),
  400. ),
  401. 'type' => 'all',
  402. 'order' => array('id', 'desc'),
  403. 'col' => '*|id',
  404. ),
  405. ),
  406. );
  407. $project = Dever::load('manage/auth-project');
  408. #Dever::debug('test');
  409. if($project)
  410. {
  411. $config['struct']['hr2'] = array
  412. (
  413. 'name' => '项目精细权限设置',
  414. 'class' => '',//本项必须填写
  415. 'attr' => '',
  416. );
  417. $project_auth = Dever::load('manage/auth.all');
  418. foreach($project as $k => $v)
  419. {
  420. $config['struct']['auth_' . $v['project']] = array
  421. (
  422. 'type' => 'text-255',
  423. 'name' => $v['project_name'] . '下的权限设置',
  424. 'default' => '',
  425. 'desc' => '请选择' . $v['project_name'] . '下的权限设置',
  426. 'match' => 'option',
  427. 'update' => 'checkbox',
  428. 'option' => $project_auth[$v['project']],
  429. );
  430. }
  431. }
  432. $config['struct']['reorder'] = array
  433. (
  434. 'type' => 'int-11',
  435. 'name' => '排序-数值越大越靠前',
  436. 'default' => '1',
  437. 'desc' => '请输入排序',
  438. 'match' => 'option',
  439. 'update' => 'text',
  440. 'search' => 'order',
  441. 'list' => true,
  442. 'order' => 'desc',
  443. 'edit' => true,
  444. );
  445. $config['struct']['state'] = array
  446. (
  447. 'type' => 'tinyint-1',
  448. 'name' => '状态',
  449. 'default' => '1',
  450. 'desc' => '请选择状态',
  451. 'match' => 'is_numeric',
  452. //'option' => $option,
  453. //'update' => 'radio',
  454. //'list' => true,
  455. /*
  456. //启用位运算,仅支持与操作,数据保存时,将从0开始加起,一般用于站点之类的保存,慎用,测试需将radio改成checkbox
  457. 'bit' => array
  458. (
  459. 1 => 1,//1为对应的值,100为保存到数据库中的值
  460. 2 => 10,
  461. //4 => 100,
  462. ),
  463. */
  464. );
  465. $config['struct']['status'] = array
  466. (
  467. 'type' => 'tinyint-1',
  468. 'name' => '状态',
  469. 'default' => '1',
  470. 'desc' => '请选择状态',
  471. 'match' => 'is_numeric',
  472. 'option' => $option,
  473. //'update' => 'radio',
  474. //'list' => true,
  475. //'edit' => true,
  476. /*
  477. //启用位运算,仅支持与操作,数据保存时,将从0开始加起,一般用于站点之类的保存,慎用,测试需将radio改成checkbox
  478. 'bit' => array
  479. (
  480. 1 => 1,//1为对应的值,100为保存到数据库中的值
  481. 2 => 10,
  482. //4 => 100,
  483. ),
  484. */
  485. );
  486. $config['struct']['cdate'] = array
  487. (
  488. 'type' => 'int-11',
  489. 'name' => '录入时间',
  490. 'match' => array('is_numeric', time()),
  491. 'desc' => '',
  492. # 只有insert时才生效
  493. 'insert' => true,
  494. # 加入搜索时间区间段
  495. 'search' => 'date',
  496. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  497. );
  498. return $config;