Slider.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. //'XW' => ['name' => '新闻资讯详情', 'node' => 'admin/xw/index'],
  22. ];
  23. /**
  24. * 数据类型
  25. * @var string
  26. */
  27. protected $type = '图片内容';
  28. /**
  29. * 页面类型
  30. * @var array
  31. */
  32. protected $types = [];
  33. /**
  34. * 控制器初始化
  35. * @return void
  36. */
  37. protected function initialize()
  38. {
  39. $this->types = SystemBase::mk()->items($this->type);
  40. foreach ($this->types as &$type) {
  41. if (preg_match('/^(.*?)#(\d+)$/', $type['name'], $matches)) {
  42. $type['name'] = $matches[1];
  43. $type['number'] = $matches[2];
  44. } else {
  45. $type['number'] = 0;
  46. }
  47. }
  48. }
  49. /**
  50. * 图片内容管理
  51. * @auth true
  52. * @menu true
  53. */
  54. public function index()
  55. {
  56. $this->title = '图片内容管理';
  57. $this->fetch();
  58. }
  59. /**
  60. * 编辑图片内容
  61. * @auth true
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function edit()
  67. {
  68. $this->skey = input('get.type', '');
  69. $this->base = $this->types[$this->skey] ?? [];
  70. if (empty($this->base)) $this->error('未配置基础数据!');
  71. $this->number = $this->base['number'];
  72. $this->sysdata();
  73. }
  74. /**
  75. * 保存图片内容
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. private function sysdata()
  81. {
  82. if ($this->request->isGet()) {
  83. $this->data = sysdata($this->skey);
  84. $this->title = "{$this->base['name']}管理";
  85. $this->fetch('form');
  86. } else {
  87. if (sysdata($this->skey, json_decode(input('data'), true))) {
  88. $this->success("{$this->base['name']}保存成功!");
  89. } else {
  90. $this->error("{$this->base['name']}保存失败,请稍候再试!");
  91. }
  92. }
  93. }
  94. }