IndexController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. use app\admin\model\AdminMenuModel;
  15. class IndexController extends AdminBaseController
  16. {
  17. public function initialize()
  18. {
  19. $adminSettings = cmf_get_option('admin_settings');
  20. if (empty($adminSettings['admin_password']) || $this->request->path() == $adminSettings['admin_password']) {
  21. $adminId = cmf_get_current_admin_id();
  22. if (empty($adminId)) {
  23. session("__LOGIN_BY_CMF_ADMIN_PW__", 1);//设置后台登录加密码
  24. }
  25. }
  26. parent::initialize();
  27. }
  28. /**
  29. * 后台首页
  30. */
  31. public function index()
  32. {
  33. $content = hook_one('admin_index_index_view');
  34. if (!empty($content)) {
  35. return $content;
  36. }
  37. $adminMenuModel = new AdminMenuModel();
  38. $menus = cache('admin_menus_' . cmf_get_current_admin_id(), '', null, 'admin_menus');
  39. if (empty($menus)) {
  40. $menus = $adminMenuModel->menuTree();
  41. cache('admin_menus_' . cmf_get_current_admin_id(), $menus, null, 'admin_menus');
  42. }
  43. $this->assign("menus", $menus);
  44. $result = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select();
  45. $menusTmp = array();
  46. foreach ($result as $item){
  47. //去掉/ _ 全部小写。作为索引。
  48. $indexTmp = $item['app'].$item['controller'].$item['action'];
  49. $indexTmp = preg_replace("/[\\/|_]/","",$indexTmp);
  50. $indexTmp = strtolower($indexTmp);
  51. $menusTmp[$indexTmp] = $item;
  52. }
  53. $this->assign("menus_js_var",json_encode($menusTmp));
  54. //$admin = Db::name("user")->where('id', cmf_get_current_admin_id())->find();
  55. //$this->assign('admin', $admin);
  56. return $this->fetch();
  57. }
  58. }