Compare commits
4 Commits
9058fa29fb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b039b7abe | |||
| 0429cf62c4 | |||
| effde58a53 | |||
| 2bb589c4e5 |
@@ -581,6 +581,13 @@ class Crud extends Backend
|
||||
|
||||
private function parseModelMethods($field, &$modelData): void
|
||||
{
|
||||
// MySQL bigint/int 时间戳字段:显式声明为 integer,避免 ThinkORM 自动时间戳写入 'now' 字符串
|
||||
if (in_array($field['name'] ?? '', ['create_time', 'update_time', 'createtime', 'updatetime'], true)
|
||||
&& in_array($field['type'] ?? '', ['int', 'bigint'], true)
|
||||
) {
|
||||
$modelData['fieldType'][$field['name']] = 'integer';
|
||||
}
|
||||
|
||||
if (($field['designType'] ?? '') == 'array') {
|
||||
$modelData['fieldType'][$field['name']] = 'json';
|
||||
} elseif (!in_array($field['name'], ['create_time', 'update_time', 'updatetime', 'createtime'])
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace {%namespace%};
|
||||
{%use%}
|
||||
use app\common\controller\Backend;
|
||||
use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
/**
|
||||
* {%tableComment%}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
* 查看
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(): void
|
||||
protected function _index(): Response
|
||||
{
|
||||
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
||||
if ($this->request->param('select')) {
|
||||
$this->select();
|
||||
if ($this->request && $this->request->get('select')) {
|
||||
return $this->select($this->request);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,13 +18,14 @@
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
{%relationVisibleFields%}
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
$this->success('', [
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
public function initialize(): void
|
||||
protected function initController(WebmanRequest $request): ?Response
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new \{%modelNamespace%}\{%modelName%}();{%filterRule%}
|
||||
return null;
|
||||
}
|
||||
@@ -50,6 +50,7 @@ trait Backend
|
||||
$res = $this->model
|
||||
->field($this->indexField)
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->with($this->withJoinTable)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
@@ -301,7 +302,40 @@ trait Backend
|
||||
/**
|
||||
* 加载为 select(远程下拉选择框)数据,子类可覆盖
|
||||
*/
|
||||
protected function _select(): void
|
||||
protected function _select(): Response
|
||||
{
|
||||
if (empty($this->model)) {
|
||||
return $this->success('', [
|
||||
'list' => [],
|
||||
'total' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
$pk = $this->model->getPk();
|
||||
|
||||
// 远程下拉只要求包含主键与可显示字段;这里尽量返回主键 + quickSearch 字段,避免全量字段带来性能问题
|
||||
$fields = [$pk];
|
||||
$quickSearchArr = is_array($this->quickSearchField) ? $this->quickSearchField : explode(',', (string) $this->quickSearchField);
|
||||
foreach ($quickSearchArr as $f) {
|
||||
$f = trim((string) $f);
|
||||
if ($f === '') continue;
|
||||
$f = str_contains($f, '.') ? substr($f, strrpos($f, '.') + 1) : $f;
|
||||
if ($f !== '' && !in_array($f, $fields, true)) {
|
||||
$fields[] = $f;
|
||||
}
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->field($fields)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,9 +214,8 @@ class Backend extends Api
|
||||
public function select(WebmanRequest $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
$this->_select();
|
||||
return $this->success();
|
||||
if ($response instanceof Response) return $response;
|
||||
return $this->_select();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -204,7 +204,24 @@ if (!function_exists('get_controller_path')) {
|
||||
if (count($parts) < 2) {
|
||||
return $parts[0] ?? null;
|
||||
}
|
||||
return implode('/', array_slice($parts, 1, -1)) ?: $parts[1];
|
||||
$segments = array_slice($parts, 1, -1);
|
||||
if ($segments === []) {
|
||||
return $parts[1] ?? null;
|
||||
}
|
||||
// ThinkPHP 风格段 game.Config -> game/config,与 $request->controller 解析结果一致(否则权限节点对不上)
|
||||
$normalized = [];
|
||||
foreach ($segments as $seg) {
|
||||
if (str_contains($seg, '.')) {
|
||||
$dotPos = strpos($seg, '.');
|
||||
$mod = substr($seg, 0, $dotPos);
|
||||
$ctrl = substr($seg, $dotPos + 1);
|
||||
$normalized[] = strtolower($mod);
|
||||
$normalized[] = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $ctrl));
|
||||
} else {
|
||||
$normalized[] = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $seg));
|
||||
}
|
||||
}
|
||||
return implode('/', $normalized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user