ComponentsController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace addons\SmartForm\backend\controllers;
  3. use Yii;
  4. use common\controllers\AddonsController;
  5. use common\enums\StatusEnum;
  6. use PHPUnit\Util\Exception;
  7. use addons\SmartForm\common\models\AddonsSmartFormComponents; # 装修表单组件
  8. /**
  9. * 组件控制器
  10. *
  11. * Class ComponentsController
  12. * @package addons\SmartForm\backend\controllers
  13. */
  14. class ComponentsController extends BaseController
  15. {
  16. /**
  17. * @method actionIndex
  18. * 组件列表
  19. * @author zqh
  20. * @datetime 2022-04-27T16:30:11+0800
  21. * @return [type] [description]
  22. */
  23. public function actionIndex()
  24. {
  25. $retuest = Yii::$app->request;
  26. if ($retuest->isAjax) {
  27. if ($retuest->isGet) {
  28. $get = Yii::$app->request->get();
  29. // 检查提交的参数
  30. $res = Yii::$app->services->validate->validate($get,[
  31. [['id','keyword'], 'safe'],
  32. [['limit'],'default','value' => '15'],
  33. ]);
  34. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  35. # 搜索条件
  36. $where = [];
  37. if($get['keyword']) $where[] = ['like', 'name', $get['keyword']];
  38. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  39. # 排序
  40. $order = 'sort,created_at desc';
  41. # 显示字段
  42. $select = "id,code,title,group,icon,permission";
  43. $params = array('where' => $where, 'order'=>$order, 'select'=>$select, 'limit' => $get['limit']);
  44. # 分页返回
  45. $list = AddonsSmartFormComponents::listPage($params, false, true);
  46. $this->success('获取成功', $list);
  47. }
  48. } else {
  49. return $this->render($this->action->id,[
  50. ]);
  51. }
  52. }
  53. }