admin.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | admin.php 管理员表
  5. |--------------------------------------------------------------------------
  6. */
  7. # 定义几个常用的选项
  8. $status = 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::db('manage/role')->all());
  19. $admin = Dever::db('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为先查询是否存在,存在直接更新,不存在则插入, only为仅更新
  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则直接把当前值写入,第三个参数是直接替换当前的值,第四个参数是当前表里的字段名,一般为分类的id
  123. //'autocomplete' => array('auth.role?json=1', 'value', 'manage/role-check#name', 'cate_id'),
  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. #多级联动
  131. //'update' => 'linkage',//多级联动 option参数:请求地址(返回参数为level_num当前联动级数,level_id当前选择的id),参考area组件:dever package area
  132. //'option' => Dever::url('api.get', 'area'),
  133. 'email' => array
  134. (
  135. 'type' => 'varchar-150',
  136. 'name' => '邮箱-可用于登录,请准确填写,不允许重复',
  137. 'default' => '',
  138. 'desc' => '请输入邮箱',
  139. 'match' => Dever::rule('email'),
  140. 'update' => 'text',
  141. /*
  142. * 列表页搜索选项,这里的search或者update的值为
  143. * fulltext:全文检索,模糊匹配
  144. * text:精确匹配
  145. * exp:大小判断,仅能选择一项
  146. * select:选择器,需要option项
  147. * group:组选择器,需要option项
  148. * linkage:多级联动选择器,需要option项,值为联动数据接口地址,参考area组件 'option' => Dever::url('api.get', 'area'), 'list' => 'Dever::load("area/api.string", "{area}")',
  149. * exist:是否存在,需要exist项,基本配置为
  150. $source_id = array
  151. (
  152. 'yes' => '有值',
  153. 'no' => '没有值',
  154. 'no|2832' => '没有值或者有值为2832',
  155. 'yes|2832' => '有值并且过滤值为2829',
  156. '2832' => '查找',
  157. );
  158. * 如果search的值为数组,则认为是接口,需要从接口获取数据后再进行查找
  159. * 如'search' => array
  160. (
  161. 'api' => 'passport/user-all',//接口地址,最好是获取多条数据的地址
  162. 'col' => 'name',//要查询的字段
  163. 'result' => 'id',//返回的字段
  164. ),
  165. * 就是将本字段email当做passport/user-one的name字段来查找id
  166. */
  167. 'search' => 'fulltext',
  168. 'list' => true,
  169. # 在手机版或者小屏幕下,列表页的表格是否展示,1为展示,2、3、4、5、6均为在一定宽度下展示,详细参考:https://github.com/nadangergeo/RWD-Table-Patterns
  170. 'level' => 1,
  171. ),
  172. # 比较特殊的一些设置,不断添加中:
  173. /*
  174. 'cate' => array
  175. (
  176. 'type' => 'varchar-300',
  177. 'name' => '标签分类',
  178. 'default' => '1',
  179. 'desc' => '标签分类',
  180. 'match' => 'is_string',
  181. 'update' => 'select',
  182. 'option' => $cate,
  183. 'search' => 'fulltext',
  184. //'list' => true,
  185. 'control' => 'cate',
  186. ),
  187. # 标签,根据分类变化的标签
  188. 'tag' => array
  189. (
  190. 'type' => 'varchar-300',
  191. 'name' => '标签',
  192. 'default' => '',
  193. 'desc' => '标签',
  194. 'match' => 'is_string',
  195. 'update' => 'checkbox',
  196. # 新增接口 暂未实现
  197. 'adding' => 'tag/manage.getByCate?cate=',
  198. # 开启这个,需要将update更换为text类型,输入文字即可选择标签
  199. //'autocomplete' => array('tag/manage.getByName', 'id', 'tag/info-one#name'),
  200. 'search' => 'fulltext',
  201. //'list' => true,
  202. # 与上边的cate联动(ajax)
  203. 'show' => 'cate=tag/manage.getByCate?cate=',
  204. ),
  205. # 加载地图
  206. 'map' => array
  207. (
  208. 'type' => 'varchar-300',
  209. 'name' => '地理位置',
  210. 'default' => '',
  211. 'desc' => '地理位置',
  212. 'match' => 'is_string',
  213. # 如果是map,必须在config的base.php中设置map信息
  214. //'update' => 'map',
  215. 'search' => 'fulltext',
  216. //'list' => true,
  217. ),
  218. # 三级地区联动
  219. 'area' => array
  220. (
  221. 'type' => 'varchar-100',
  222. 'name' => '地区',
  223. 'default' => '',
  224. 'desc' => '地区',
  225. 'match' => 'is_string',
  226. 'search' => 'linkage',
  227. 'update' => 'linkage',//多级联动 option参数:请求地址(参数为level_num当前联动级数,level_id当前选择的id)
  228. 'option' => Dever::url('api.get', 'area'),
  229. 'list' => 'Dever::load("area/api.string", "{area}")',
  230. ),
  231. # 无限级联动
  232. 'category' => array
  233. (
  234. 'type' => 'varchar-500',
  235. 'name' => '分类',
  236. 'default' => '',
  237. 'desc' => '分类',
  238. 'match' => 'is_string',
  239. 'search' => 'linkage',
  240. //'update' => 'linkage',
  241. 'option' => Dever::url('api.get', 'category'),
  242. 'list' => 'Dever::load("category/api.string", "{category}")',
  243. ),
  244. # 属性管理
  245. 'attr' => array
  246. (
  247. 'type' => 'varchar-800',
  248. 'name' => '属性设置',
  249. 'default' => '',
  250. 'desc' => '属性设置',
  251. 'match' => 'option',
  252. 'update' => 'checkbox',
  253. 'option' => $attr,
  254. 'update_input' => '',
  255. 'update_input_default' => '',
  256. 'update_parent' => 'checkbox',
  257. ),
  258. # 属性管理 需要用这个来设置值
  259. 'attr_input' => array
  260. (
  261. 'type' => 'text-255',
  262. 'name' => '属性值设置',
  263. 'default' => '',
  264. 'desc' => '属性值设置',
  265. 'match' => 'option',
  266. ),
  267. */
  268. 'mobile' => array
  269. (
  270. 'type' => 'varchar-32',
  271. 'name' => '手机号',
  272. 'default' => '',
  273. 'desc' => '请输入手机号',
  274. 'match' => Dever::rule('mobile'),
  275. 'update' => 'text',
  276. 'search' => 'fulltext',
  277. 'list' => true,
  278. 'level' => 1,
  279. # 显示在table中
  280. //'list_table'=> '111',
  281. ),
  282. 'password' => array
  283. (
  284. 'type' => 'varchar-64',
  285. 'name' => '管理员密码',
  286. 'default' => '',
  287. 'desc' => '请输入管理员密码',
  288. 'match' => 'option',
  289. 'update' => 'password',
  290. 'callback' => 'hash.sha256',
  291. ),
  292. 'config' => array
  293. (
  294. 'type' => 'int-11',
  295. 'name' => '后台配置',
  296. 'default' => '1',
  297. 'desc' => '请选择后台配置',
  298. 'match' => 'is_numeric',
  299. 'option' => $config,
  300. 'update' => 'select',
  301. 'list' => true,
  302. ),
  303. 'role' => array
  304. (
  305. 'type' => 'varchar-100',
  306. 'name' => '角色',
  307. 'default' => '1',
  308. 'desc' => '请选择角色',
  309. 'match' => 'is_string',
  310. 'option' => $role,
  311. 'update' => 'checkbox',
  312. //'list' => true,
  313. ),
  314. 'group' => array
  315. (
  316. 'type' => 'int-11',
  317. 'name' => '分组',
  318. 'default' => '1',
  319. 'desc' => '请选择分组',
  320. 'match' => 'is_numeric',
  321. 'option' => $group,
  322. 'update' => 'select',
  323. //'list' => true,
  324. ),
  325. 'top' => array
  326. (
  327. 'type' => 'text-255',
  328. 'name' => '头部菜单-这里的头部菜单如果设置,则会覆盖角色中的头部菜单',
  329. 'default' => '',
  330. 'desc' => '请选择头部菜单',
  331. 'match' => 'option',
  332. 'update' => 'checkbox',
  333. 'option' => $top,
  334. ),
  335. 'state' => array
  336. (
  337. 'type' => 'tinyint-1',
  338. 'name' => '数据状态',
  339. 'default' => '1',
  340. 'desc' => '请选择状态',
  341. 'match' => 'is_numeric',
  342. //'option' => $option,
  343. //'update' => 'radio',
  344. //'list' => true,
  345. //'extend' => true,//扩展功能,该字段为虚拟字段,只在数据库中建立extend字段来保存 后续实现
  346. ),
  347. /*
  348. 提供冲突检测机制(乐观锁),保证高并发下的数据安全
  349. 这是模仿自 php 的 Memcached 扩展 后续实现
  350. 'token' => array
  351. (
  352. 'type' => 'int-11',
  353. 'name' => 'token',
  354. 'default' => '1',
  355. 'desc' => 'token',
  356. 'match' => 'is_numeric',
  357. ),
  358. */
  359. 'status' => array
  360. (
  361. 'type' => 'tinyint-1',
  362. 'name' => '状态',
  363. 'default' => '1',
  364. 'desc' => '请选择状态',
  365. 'match' => 'is_numeric',
  366. 'option' => $status,
  367. 'update' => 'radio',
  368. 'list' => true,
  369. 'edit' => true,
  370. ),
  371. 'cdate' => array
  372. (
  373. 'type' => 'int-11',
  374. 'name' => '录入时间',
  375. 'match' => array('is_numeric', DEVER_TIME),
  376. 'desc' => '',
  377. # 只有insert时才生效
  378. 'insert' => true,
  379. 'list' => 'date("Y-m-d H:i:s", {cdate})',
  380. ),
  381. ),
  382. 'manage' => array
  383. (
  384. 'delete' => false,
  385. // 载入自定义资源
  386. 'res' => array
  387. (
  388. 'js' => 'demo',
  389. 'css' => 'demo',
  390. ),
  391. # 快捷更新
  392. /*
  393. 'list_button' => array
  394. (
  395. 'edit' => array('审核', 'name'),
  396. ),
  397. */
  398. ),
  399. # 更新表结构
  400. 'alter' => array
  401. (
  402. 2 => array
  403. (
  404. //array('update', 'role', 'role', 'varchar-100 1 角色'),
  405. //array('add', 'config', 'config', 'int-11 1 配置'),
  406. ),
  407. 'version' => 2,
  408. ),
  409. # 默认值
  410. /*
  411. 'default' => array
  412. (
  413. 'col' => 'username,email,password,role,state,cdate',
  414. 'value' => array
  415. (
  416. //'"DMC","DMC@dever.cc","'. md5('admin_' . date('Y_m_d_H')) . '",1, 1,' . time(),
  417. '"admin","DMC@dever.cc","'. hash('sha256', 'admin_123') . '",1, 1,' . DEVER_TIME,
  418. ),
  419. ),
  420. */
  421. # 索引
  422. 'index' => array
  423. (
  424. # 索引名 => 索引id
  425. //'id' => 'id,state',
  426. ),
  427. # request 请求接口定义
  428. 'request' => array
  429. (
  430. # one 根据用户名和密码取一条数据
  431. 'user' => array
  432. (
  433. # 匹配的正则或函数 必填项
  434. 'where' => array
  435. (
  436. //'username' => '/^([A-Za-z0-9])/',
  437. //'username' => 'yes',
  438. 'email' => 'yes',
  439. 'status' => 1,
  440. 'state' => 1,
  441. //'password' => 'is_string',
  442. ),
  443. 'type' => 'one',
  444. # 为这个接口独立设置缓存
  445. 'cache' => true,
  446. ),
  447. # one 根据用户名和密码取一条数据
  448. 'email' => array
  449. (
  450. # 匹配的正则或函数 必填项
  451. 'where' => array
  452. (
  453. //'username' => '/^([A-Za-z0-9])/',
  454. //'username' => 'yes',
  455. 'email' => 'yes',
  456. 'status' => 1,
  457. 'state' => 1,
  458. //'password' => 'is_string',
  459. ),
  460. 'type' => 'one',
  461. # 为这个接口独立设置缓存
  462. 'cache' => true,
  463. ),
  464. # one 根据用户名和密码取一条数据
  465. 'mobile' => array
  466. (
  467. # 匹配的正则或函数 必填项
  468. 'where' => array
  469. (
  470. //'username' => '/^([A-Za-z0-9])/',
  471. //'username' => 'yes',
  472. 'mobile' => 'yes',
  473. 'status' => 1,
  474. 'state' => 1,
  475. //'password' => 'is_string',
  476. ),
  477. 'type' => 'one',
  478. # 为这个接口独立设置缓存
  479. 'cache' => true,
  480. ),
  481. # 更新密码
  482. 'password' => array
  483. (
  484. 'type' => 'update',
  485. 'where' => array
  486. (
  487. 'id' => 'yes',
  488. ),
  489. 'set' => array
  490. (
  491. 'password' => 'yes',
  492. ),
  493. ),
  494. ),
  495. );