Pager.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\data\controller\base;
  3. use think\admin\Controller;
  4. use think\admin\model\SystemBase;
  5. /**
  6. * 页面内容管理
  7. * Class Pager
  8. * @package app\data\controller\base
  9. */
  10. class Pager extends Controller
  11. {
  12. /**
  13. * 字典类型
  14. * @var string
  15. */
  16. protected $type = '页面内容';
  17. /**
  18. * 页面类型
  19. * @var array
  20. */
  21. protected $types = [];
  22. /**
  23. * 控制器初始化
  24. * @return void
  25. */
  26. protected function initialize()
  27. {
  28. $this->types = SystemBase::mk()->items($this->type);
  29. }
  30. /**
  31. * 内容页面管理
  32. * @auth true
  33. * @menu true
  34. */
  35. public function index()
  36. {
  37. $this->title = '内容页面管理';
  38. $this->fetch();
  39. }
  40. /**
  41. * 内容页面编辑
  42. * @auth true
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. public function edit()
  48. {
  49. $this->skey = input('get.type', '');
  50. $this->base = $this->types[$this->skey] ?? [];
  51. if (empty($this->base)) $this->error('未配置基础数据!');
  52. $this->title = "编辑{$this->base['name']}";
  53. $this->sysdata();
  54. }
  55. /**
  56. * 显示并保存数据
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. private function sysdata()
  62. {
  63. if ($this->request->isGet()) {
  64. $this->data = sysdata($this->skey);
  65. $this->fetch('form');
  66. } elseif ($this->request->isPost()) {
  67. if (is_string(input('data'))) {
  68. $data = json_decode(input('data'), true) ?: [];
  69. } else {
  70. $data = $this->request->post();
  71. }
  72. if (sysdata($this->skey, $data) !== false) {
  73. $this->success('内容保存成功!', 'javascript:history.back()');
  74. } else {
  75. $this->error('内容保存失败,请稍候再试!');
  76. }
  77. }
  78. }
  79. }