admin.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | admin.php 管理员表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $option = array
  9. (
  10. 1 => '普通',
  11. 2 => '封禁',
  12. );
  13. $cur = Dever::load('manage/auth.data', false);
  14. $desc = '';
  15. if($cur['role'] > 1)
  16. {
  17. $desc = $cur['username'] . ',你好,你可以在此管理你的下属账号';
  18. $child = array_keys(Dever::load('manage/role-all'));
  19. $admin = Dever::load('manage/admin_role-list', array
  20. (
  21. 'col' => 'admin_id|admin_id',
  22. 'option' => array
  23. (
  24. 'role_id' => array('yes', 'in'),
  25. ),
  26. 'option_role_id' => implode(',', $child),
  27. ));
  28. # 配置当前列表页的参数 只能查看自己下属的管理员
  29. Dever::$global['model']['manage/admin-list'] = array
  30. (
  31. 'option' => array
  32. (
  33. 'id' => array('yes', 'in'),
  34. ),
  35. 'option_id' => $admin ? array_keys($admin) : -1,
  36. );
  37. }
  38. $role = function()
  39. {
  40. return Dever::load('manage/role-all');
  41. };
  42. $group = function()
  43. {
  44. return Dever::load('manage/group-all');
  45. };
  46. $config = function()
  47. {
  48. return Dever::load('manage/config-all');
  49. };
  50. # 获取头部菜单list 建议这里使用匿名函数
  51. $top = function()
  52. {
  53. $data = Dever::load('manage/top.all');
  54. $data['state'] = 1;
  55. return $data;
  56. };
  57. return array
  58. (
  59. # 表名
  60. 'name' => 'admin',
  61. # 显示给用户看的名称
  62. 'lang' => '管理账户设置',
  63. 'desc' => $desc,
  64. # 这个表不使用cache功能
  65. //'cache' => false,
  66. /*
  67. # 用到哪个后台菜单上,对应项目的key
  68. 'menu' => 'project_niuyou_main',
  69. # 后台菜单排序
  70. 'order' => 10,
  71. # 显示到后台快捷发布中,值为排序
  72. 'fast' => 1,
  73. */
  74. 'order' => 9,
  75. # 检测email必须唯一
  76. 'check' => 'email',
  77. # 同步更新另外一个或多个表的数据
  78. 'sync' => array
  79. (
  80. 'manage/admin_role' => array
  81. (
  82. # 更新另外一个表的字段 => 本表的字段
  83. 'where' => array('admin_id', 'id'),
  84. # 要更新的数据
  85. 'update' => array('role_id' => 'role'),
  86. # 同步更新的类型,delete为先删再插入,update为直接更新
  87. 'type' => 'delete',
  88. )
  89. ),
  90. /*该方法用check替代
  91. 'start' => array
  92. (
  93. 'update' => 'manage/auth.check',
  94. 'insert' => 'manage/auth.check',
  95. ),
  96. */
  97. 'end' => array
  98. (
  99. 'update' => 'manage/auth.update',
  100. ),
  101. # 数据结构
  102. 'struct' => array
  103. (
  104. 'id' => array
  105. (
  106. 'type' => 'int-11',
  107. 'name' => '管理员ID',
  108. 'default' => '',
  109. 'desc' => '',
  110. 'match' => 'is_numeric',
  111. 'search' => 'order',
  112. 'list' => true,
  113. ),
  114. 'username' => array
  115. (
  116. 'type' => 'varchar-24',
  117. 'name' => '管理员名',
  118. 'default' => '',
  119. 'desc' => '请输入管理员名',
  120. 'match' => 'is_string',
  121. 'update' => 'text',
  122. # 自动完成功能,第一个参数是请求的地址,请自行实现,第二个参数是要使用的字段,共有id和value两个选择,id会特殊处理,value则直接把当前值写入,第三个参数是直接替换当前的值
  123. //'autocomplete' => array('auth.role?json=1', 'value', 'manage/role-check#name'),
  124. 'autocomplete' => array('auth.role?json=1'),
  125. 'search' => 'order,fulltext',
  126. 'list' => true,
  127. # 绑定js脚本,更新时使用,第一个参数是执行的方式,第二个参数执行的方法,第三个参数是传值。
  128. //'bind' => array('onblur', 'loading', array('url' => Dever::url("auth.blur"))),
  129. ),
  130. 'email' => array
  131. (
  132. 'type' => 'varchar-150',
  133. 'name' => '邮箱-可用于登录,请准确填写,不允许重复',
  134. 'default' => '',
  135. 'desc' => '请输入邮箱',
  136. 'match' => Dever::rule('email'),
  137. 'update' => 'text',
  138. 'search' => 'fulltext',
  139. 'list' => true,
  140. ),
  141. 'mobile' => array
  142. (
  143. 'type' => 'varchar-32',
  144. 'name' => '联系电话',
  145. 'default' => '',
  146. 'desc' => '请输入用户联系电话',
  147. 'match' => 'option',
  148. 'update' => 'text',
  149. 'search' => 'fulltext',
  150. 'list' => true,
  151. # 显示在table中
  152. //'list_table'=> '111',
  153. ),
  154. 'password' => array
  155. (
  156. 'type' => 'varchar-64',
  157. 'name' => '管理员密码',
  158. 'default' => '',
  159. 'desc' => '请输入管理员密码',
  160. 'match' => 'option',
  161. 'update' => 'password',
  162. 'callback' => 'hash.sha256',
  163. ),
  164. 'config' => array
  165. (
  166. 'type' => 'int-11',
  167. 'name' => '后台配置',
  168. 'default' => '1',
  169. 'desc' => '请选择后台配置',
  170. 'match' => 'is_numeric',
  171. 'option' => $config,
  172. 'update' => 'select',
  173. 'list' => true,
  174. ),
  175. 'role' => array
  176. (
  177. 'type' => 'varchar-100',
  178. 'name' => '角色',
  179. 'default' => '1',
  180. 'desc' => '请选择角色',
  181. 'match' => 'is_string',
  182. 'option' => $role,
  183. 'update' => 'checkbox',
  184. //'list' => true,
  185. ),
  186. 'group' => array
  187. (
  188. 'type' => 'int-11',
  189. 'name' => '分组',
  190. 'default' => '1',
  191. 'desc' => '请选择分组',
  192. 'match' => 'is_numeric',
  193. 'option' => $group,
  194. 'update' => 'select',
  195. //'list' => true,
  196. ),
  197. 'top' => array
  198. (
  199. 'type' => 'text-255',
  200. 'name' => '头部菜单-这里的头部菜单如果设置,则会覆盖角色中的头部菜单',
  201. 'default' => '',
  202. 'desc' => '请选择头部菜单',
  203. 'match' => 'option',
  204. 'update' => 'checkbox',
  205. 'option' => $top,
  206. ),
  207. 'state' => array
  208. (
  209. 'type' => 'tinyint-1',
  210. 'name' => '状态',
  211. 'default' => '1',
  212. 'desc' => '请选择状态',
  213. 'match' => 'is_numeric',
  214. 'option' => $option,
  215. 'update' => 'radio',
  216. 'list' => true,
  217. ),
  218. 'cdate' => array
  219. (
  220. 'type' => 'int-11',
  221. 'name' => '录入时间',
  222. 'match' => array('is_numeric', DEVER_TIME),
  223. 'desc' => '',
  224. # 只有insert时才生效
  225. 'insert' => true,
  226. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  227. ),
  228. ),
  229. # 更新表结构
  230. 'alter' => array
  231. (
  232. 2 => array
  233. (
  234. array('update', 'role', 'role', 'varchar-100 1 角色'),
  235. array('add', 'config', 'config', 'int-11 1 配置'),
  236. ),
  237. 'version' => 2,
  238. ),
  239. # 默认值
  240. 'default' => array
  241. (
  242. 'col' => 'username,email,password,role,state,cdate',
  243. 'value' => array
  244. (
  245. //'"DMC","DMC@dever.cc","'. md5('admin_' . date('Y_m_d_H')) . '",1, 1,' . time(),
  246. '"admin","DMC@dever.cc","'. hash('sha256', 'admin_123') . '",1, 1,' . DEVER_TIME,
  247. ),
  248. ),
  249. # 索引
  250. 'index' => array
  251. (
  252. # 索引名 => 索引id
  253. //'id' => 'id,state',
  254. ),
  255. # request 请求接口定义
  256. 'request' => array
  257. (
  258. # one 根据用户名和密码取一条数据
  259. 'user' => array
  260. (
  261. # 匹配的正则或函数 必填项
  262. 'where' => array
  263. (
  264. //'username' => '/^([A-Za-z0-9])/',
  265. //'username' => 'yes',
  266. 'email' => 'yes',
  267. //'password' => 'is_string',
  268. ),
  269. 'type' => 'one',
  270. # 为这个接口独立设置缓存
  271. 'cache' => true,
  272. ),
  273. # 更新密码
  274. 'password' => array
  275. (
  276. 'type' => 'update',
  277. 'where' => array
  278. (
  279. 'id' => 'yes',
  280. ),
  281. 'set' => array
  282. (
  283. 'password' => 'yes',
  284. ),
  285. ),
  286. ),
  287. );