Tabbar.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\TabbarModel;
  5. use think\facade\Cache;
  6. class Tabbar extends BaseController
  7. {
  8. public function update(): \think\response\Json
  9. {
  10. $user = $this->getUser(true);
  11. if ($user) {
  12. $tabbar = $this->request->post("tabbar", []);
  13. if (is_array($tabbar)) {
  14. $is = TabbarModel::where("user_id", $user['user_id'])->find();
  15. if ($is) {
  16. $is->tabs = $tabbar;
  17. $is->save();
  18. } else {
  19. TabbarModel::create(["user_id" => $user['user_id'], "tabs" => $tabbar]);
  20. }
  21. return $this->success('ok');
  22. }
  23. }
  24. return $this->error('保存失败');
  25. }
  26. public function get(): \think\response\Json
  27. {
  28. $user = $this->getUser();
  29. if ($user) {
  30. $data = TabbarModel::where("user_id",$user['user_id'])->find();
  31. if ($data) {
  32. return $this->success('ok', $data['tabs']);
  33. }
  34. }
  35. $config = $this->systemSetting('defaultTab', '/static/defaultTab.json', true);
  36. if ($config) {
  37. $fp = joinPath(public_path(), $config);
  38. if (!file_exists($fp)) {
  39. $fp = public_path() . 'static/defaultTab.json';
  40. }
  41. if (file_exists($fp)) {
  42. $file = file_get_contents($fp);
  43. $json = json_decode($file, true);
  44. return $this->success('ok', $json['tabbar'] ?? []);
  45. }
  46. }
  47. return $this->success('ok', []);
  48. }
  49. }