优化webman-buildadmin框架
This commit is contained in:
@@ -143,6 +143,10 @@ class Crud extends Backend
|
||||
$this->langTsData['zh-cn']['quick Search Fields'] = implode('、', $quickSearchFieldZhCnTitle);
|
||||
$this->controllerData['attr']['quickSearchField'] = $quickSearchField;
|
||||
|
||||
if (array_key_exists('admin_id', $fieldsMap)) {
|
||||
$this->controllerData['attr']['autoFillAdminId'] = true;
|
||||
}
|
||||
|
||||
$weighKey = array_search('weigh', $fieldsMap);
|
||||
if ($weighKey !== false) {
|
||||
$this->indexVueData['enableDragSort'] = true;
|
||||
|
||||
@@ -96,11 +96,12 @@ class Helper
|
||||
|
||||
protected static array $attrType = [
|
||||
'controller' => [
|
||||
'preExcludeFields' => 'array|string',
|
||||
'quickSearchField' => 'string|array',
|
||||
'withJoinTable' => 'array',
|
||||
'defaultSortField' => 'string|array',
|
||||
'weighField' => 'string',
|
||||
'preExcludeFields' => 'array|string',
|
||||
'quickSearchField' => 'string|array',
|
||||
'withJoinTable' => 'array',
|
||||
'defaultSortField' => 'string|array',
|
||||
'weighField' => 'string',
|
||||
'autoFillAdminId' => 'bool',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -692,7 +693,14 @@ class Helper
|
||||
$modelMethodList = isset($modelData['relationMethodList']) ? array_merge($modelData['methods'], $modelData['relationMethodList']) : $modelData['methods'];
|
||||
$modelData['methods'] = $modelMethodList ? "\n" . implode("\n", $modelMethodList) : '';
|
||||
$modelData['append'] = self::buildModelAppend($modelData['append'] ?? []);
|
||||
$modelData['fieldType'] = self::buildModelFieldType($modelData['fieldType'] ?? []);
|
||||
$fieldType = $modelData['fieldType'] ?? [];
|
||||
if ($modelData['autoWriteTimestamp'] == 'true') {
|
||||
$fieldType = array_merge(
|
||||
['create_time' => 'integer', 'update_time' => 'integer'],
|
||||
$fieldType
|
||||
);
|
||||
}
|
||||
$modelData['fieldType'] = self::buildModelFieldType($fieldType);
|
||||
|
||||
if (isset($modelData['beforeInsertMixins']['snowflake'])) {
|
||||
$modelData['beforeInsert'] = self::assembleStub('mixins/model/beforeInsert', [
|
||||
@@ -726,6 +734,9 @@ class Helper
|
||||
$attrType = self::$attrType['controller'][$key] ?? '';
|
||||
if (is_array($item)) {
|
||||
$controllerAttr .= "\n" . self::tab() . "protected $attrType \$$key = ['" . implode("', '", $item) . "'];\n";
|
||||
} elseif ($attrType === 'bool') {
|
||||
$val = ($item === true || $item === 'true') ? 'true' : 'false';
|
||||
$controllerAttr .= "\n" . self::tab() . "protected $attrType \$$key = $val;\n";
|
||||
} elseif ($item) {
|
||||
$controllerAttr .= "\n" . self::tab() . "protected $attrType \$$key = '$item';\n";
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ class {%className%} extends Backend
|
||||
{%methods%}
|
||||
|
||||
/**
|
||||
* 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
|
||||
* add、edit、del、sortable 已由父类 Backend 实现,无需重写即可直接使用
|
||||
* 若需重写,请确保调用 initializeBackend($request) 并传入 Request 参数
|
||||
* 若模型有 admin_id 字段需自动填充,可设置 protected bool $autoFillAdminId = true
|
||||
*/
|
||||
}
|
||||
@@ -97,6 +97,9 @@ trait Backend
|
||||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||
$data[$this->dataLimitField] = $this->auth->id;
|
||||
}
|
||||
if ($this->autoFillAdminId && $this->dataLimitField === 'admin_id') {
|
||||
$data['admin_id'] = $this->auth->id;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
|
||||
Reference in New Issue
Block a user