query = $this->buildQuery($dbQuery); // 数据列表排序自动处理 if ($this->app->request->isPost() && $this->app->request->post('action') === 'sort') { if (in_array('sort', $this->query->getTableFields())) { if ($this->app->request->has($pk = $this->query->getPk() ?: 'id', 'post')) { $map = [$pk => $this->app->request->post($pk, 0)]; $data = ['sort' => intval($this->app->request->post('sort', 0))]; if ($this->app->db->table($this->query->getTable())->where($map)->update($data) !== false) { $this->class->success(lang('think_library_sort_success'), ''); } } } $this->class->error(lang('think_library_sort_error')); } // 列表分页及结果集处理 if ($page) { if (empty($limit)) { $limit = $this->app->request->get('limit', $this->app->cookie->get('limit', 20)); if (intval($this->app->request->get('not_cache_limit', 0)) < 1) { $this->app->cookie->set('limit', ($limit = intval($limit >= 10 ? $limit : 20)) . ''); } } [$options, $query] = ['', $this->app->request->get()]; $pager = $this->query->paginate(['list_rows' => $limit, 'query' => $query], $total); foreach ([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 300, 400, 500, 600] as $num) { [$query['limit'], $query['page'], $selects] = [$num, 1, $limit === $num ? 'selected' : '']; if (stripos($this->app->request->get('spm', '-'), 'm-') === 0) { $url = sysuri('admin/index/index') . '#' . $this->app->request->baseUrl() . '?' . urldecode(http_build_query($query)); } else { $url = $this->app->request->baseUrl() . '?' . urldecode(http_build_query($query)); } $options .= ""; } $selects = ""; $pagetext = lang('think_library_page_html', [$pager->total(), $selects, $pager->lastPage(), $pager->currentPage()]); $pagehtml = "
{$pagetext}{$pager->render()}
"; if (stripos($this->app->request->get('spm', '-'), 'm-') === 0) { $this->class->assign('pagehtml', preg_replace('|href="(.*?)"|', 'data-open="$1" onclick="return false" href="$1"', $pagehtml)); } else { $this->class->assign('pagehtml', $pagehtml); } $result = ['page' => ['limit' => $limit, 'total' => $pager->total(), 'pages' => $pager->lastPage(), 'current' => $pager->currentPage()], 'list' => $pager->items()]; } else { $pager = $this->query->select(); $result = ['page' => ['limit' => $pager->count(), 'total' => 1, 'pages' => 1, 'current' => 1], 'list' => $pager->toArray()]; } if (false !== $this->class->callback('_page_filter', $result['list']) && $display) { if ($this->app->request->get('output') === 'json') { $this->class->success('JSON-DATA', $result); } else { $this->class->fetch($template, $result); } } return $result; } }