Slider.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\data\controller\base;
  3. use think\admin\Controller;
  4. use think\admin\model\SystemBase;
  5. /**
  6. * 图片内容管理
  7. * Class Slider
  8. * @package app\data\controller\base
  9. */
  10. class Slider extends Controller
  11. {
  12. /**
  13. * 跳转规则定义
  14. * @var string[]
  15. */
  16. protected $rules = [
  17. '#' => ['name' => '不跳转'],
  18. 'LK' => ['name' => '自定义链接'],
  19. 'NL' => ['name' => '新闻资讯列表'],
  20. 'NS' => ['name' => '新闻资讯详情', 'node' => 'data/news.item/select'],
  21. ];
  22. /**
  23. * 数据类型
  24. * @var string
  25. */
  26. protected $type = '图片内容';
  27. /**
  28. * 页面类型
  29. * @var array
  30. */
  31. protected $types = [];
  32. /**
  33. * 控制器初始化
  34. * @return void
  35. */
  36. protected function initialize()
  37. {
  38. $this->types = SystemBase::mk()->items($this->type);
  39. foreach ($this->types as &$type) {
  40. if (preg_match('/^(.*?)#(\d+)$/', $type['name'], $matches)) {
  41. $type['name'] = $matches[1];
  42. $type['number'] = $matches[2];
  43. } else {
  44. $type['number'] = 0;
  45. }
  46. }
  47. }
  48. /**
  49. * 图片内容管理
  50. * @auth true
  51. * @menu true
  52. */
  53. public function index()
  54. {
  55. $this->title = '图片内容管理';
  56. $this->fetch();
  57. }
  58. /**
  59. * 编辑图片内容
  60. * @auth true
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function edit()
  66. {
  67. $this->skey = input('get.type', '');
  68. $this->base = $this->types[$this->skey] ?? [];
  69. if (empty($this->base)) $this->error('未配置基础数据!');
  70. $this->number = $this->base['number'];
  71. $this->sysdata();
  72. }
  73. /**
  74. * 保存图片内容
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. */
  79. private function sysdata()
  80. {
  81. if ($this->request->isGet()) {
  82. $this->data = sysdata($this->skey);
  83. $this->title = "{$this->base['name']}管理";
  84. $this->fetch('form');
  85. } else {
  86. if (sysdata($this->skey, json_decode(input('data'), true))) {
  87. $this->success("{$this->base['name']}保存成功!");
  88. } else {
  89. $this->error("{$this->base['name']}保存失败,请稍候再试!");
  90. }
  91. }
  92. }
  93. }