Index.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\api\controller;
  3. use ba\Tree;
  4. use think\facade\Db;
  5. use think\facade\Config;
  6. use app\common\controller\Frontend;
  7. class Index extends Frontend
  8. {
  9. protected $noNeedLogin = ['index'];
  10. public function initialize()
  11. {
  12. parent::initialize();
  13. }
  14. public function index()
  15. {
  16. if ($this->auth->isLogin()) {
  17. $rule = $this->auth->getMenus();
  18. // 首页加载的规则,验权,但过滤掉会员中心菜单
  19. foreach ($rule as $key => $item) {
  20. if (in_array($item['type'], ['menu_dir', 'menu'])) unset($rule[$key]);
  21. }
  22. $rule = array_values($rule);
  23. } else {
  24. $rule = Db::name('user_rule')
  25. ->where('status', '1')
  26. ->where('no_login_valid', 1)
  27. ->where('type', 'in', ['route', 'nav', 'button'])
  28. ->order('weigh', 'desc')
  29. ->select()
  30. ->toArray();
  31. $rule = Tree::instance()->assembleChild($rule);
  32. }
  33. $this->success('', [
  34. 'site' => [
  35. 'siteName' => get_sys_config('site_name'),
  36. 'recordNumber' => get_sys_config('record_number'),
  37. 'version' => get_sys_config('version'),
  38. 'cdnUrl' => full_url(),
  39. 'upload' => get_upload_config(),
  40. ],
  41. 'openMemberCenter' => Config::get('buildadmin.open_member_center'),
  42. 'rules' => $rule
  43. ]);
  44. }
  45. }