Bootstraptable.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\admin\controller\example;
  3. use app\common\controller\Backend;
  4. /**
  5. * 表格完整示例
  6. *
  7. * @icon fa fa-table
  8. * @remark 在使用Bootstrap-table中的常用方式,更多使用方式可查看:http://bootstrap-table.wenzhixin.net.cn/zh-cn/
  9. */
  10. class Bootstraptable extends Backend
  11. {
  12. /**
  13. * @var \app\admin\model\AdminLog
  14. */
  15. protected $model = null;
  16. /**
  17. * 无需鉴权的方法(需登录)
  18. * @var array
  19. */
  20. protected $noNeedRight = ['start', 'pause', 'change', 'detail', 'cxselect', 'searchlist'];
  21. /**
  22. * 快捷搜索的字段
  23. * @var string
  24. */
  25. protected $searchFields = 'id,title,url';
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = model('AdminLog');
  30. }
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. if ($this->request->isAjax()) {
  37. list($where, $sort, $order, $offset, $limit) = $this->buildparams(null);
  38. $list = $this->model
  39. ->where($where)
  40. ->order($sort, $order)
  41. ->limit($offset, $limit)
  42. ->paginate($limit);
  43. $result = array("total" => $list->total(), "rows" => $list->items(), "extend" => ['money' => mt_rand(100000, 999999), 'price' => 200]);
  44. return json($result);
  45. }
  46. return $this->view->fetch();
  47. }
  48. /**
  49. * 详情
  50. */
  51. public function detail($ids)
  52. {
  53. $row = $this->model->get(['id' => $ids]);
  54. if (!$row) {
  55. $this->error(__('No Results were found'));
  56. }
  57. if ($this->request->isAjax()) {
  58. $this->success("Ajax请求成功", null, ['id' => $ids]);
  59. }
  60. $this->view->assign("row", $row->toArray());
  61. return $this->view->fetch();
  62. }
  63. /**
  64. * 启用
  65. */
  66. public function start($ids = '')
  67. {
  68. $this->success("模拟启动成功");
  69. }
  70. /**
  71. * 暂停
  72. */
  73. public function pause($ids = '')
  74. {
  75. $this->success("模拟暂停成功");
  76. }
  77. /**
  78. * 切换
  79. */
  80. public function change($ids = '')
  81. {
  82. //你需要在此做具体的操作逻辑
  83. $this->success("模拟切换成功");
  84. }
  85. /**
  86. * 联动搜索
  87. */
  88. public function cxselect()
  89. {
  90. $type = $this->request->get('type');
  91. $group_id = $this->request->get('group_id');
  92. $list = null;
  93. if ($group_id !== '') {
  94. if ($type == 'group') {
  95. $groupIds = $this->auth->getChildrenGroupIds(true);
  96. $list = \app\admin\model\AuthGroup::where('id', 'in', $groupIds)->field('id as value, name')->select();
  97. } else {
  98. $adminIds = \app\admin\model\AuthGroupAccess::where('group_id', 'in', $group_id)->column('uid');
  99. $list = \app\admin\model\Admin::where('id', 'in', $adminIds)->field('id as value, username AS name')->select();
  100. }
  101. }
  102. $this->success('', null, $list);
  103. }
  104. /**
  105. * 搜索下拉列表
  106. */
  107. public function searchlist()
  108. {
  109. $result = $this->model->limit(10)->select();
  110. $searchlist = [];
  111. foreach ($result as $key => $value) {
  112. $searchlist[] = ['id' => $value['url'], 'name' => $value['url']];
  113. }
  114. $data = ['searchlist' => $searchlist];
  115. $this->success('', null, $data);
  116. }
  117. }