Tabbar.php 1.4 KB

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