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