优化下拉列表组件,修复若干BUG
This commit is contained in:
@@ -263,11 +263,28 @@ class Admin extends Backend
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉(Admin 无自定义,走父类默认列表)
|
||||
* 远程下拉(返回管理员列表供 remoteSelect 使用)
|
||||
*/
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
return parent::select($request);
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('login_failure,password,salt')
|
||||
->withJoin($this->withJoinTable ?? [], $this->withJoinType ?? 'LEFT')
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function checkGroupAuth(array $groups): ?Response
|
||||
|
||||
@@ -45,8 +45,7 @@ class User extends Backend
|
||||
}
|
||||
|
||||
if ($request->get('select') || $request->post('select')) {
|
||||
$this->_select();
|
||||
return $this->success();
|
||||
return $this->select($request);
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
@@ -182,6 +181,32 @@ class User extends Backend
|
||||
return $this->success('', ['row' => $row]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉数据(供 remoteSelect 使用)
|
||||
*/
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('password')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->visible(['admin' => ['username']])
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
|
||||
@@ -245,11 +245,11 @@ Route::get('/admin/security/dataRecycleLog/index', [\app\admin\controller\securi
|
||||
Route::post('/admin/security/dataRecycleLog/restore', [\app\admin\controller\security\DataRecycleLog::class, 'restore']);
|
||||
Route::get('/admin/security/dataRecycleLog/info', [\app\admin\controller\security\DataRecycleLog::class, 'info']);
|
||||
|
||||
// ==================== 兼容 ThinkPHP 风格 URL(module.Controller/action) ====================
|
||||
// 前端使用 /admin/user.Rule/index 格式,需转换为控制器调用
|
||||
// ==================== 兼容 ThinkPHP 风格 URL(module.Controller/action 或 module.sub.Controller/action) ====================
|
||||
// 前端使用 /admin/user.Rule/index、/admin/mall.pints.Order/index 等格式,需转换为控制器调用
|
||||
Route::add(
|
||||
['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'],
|
||||
'/admin/{controllerPart:[a-zA-Z]+\\.[a-zA-Z0-9]+}/{action}',
|
||||
'/admin/{controllerPart:[a-zA-Z0-9]+(?:\\.[a-zA-Z0-9]+)+}/{action}',
|
||||
function (\Webman\Http\Request $request, string $controllerPart, string $action) {
|
||||
$pos = strpos($controllerPart, '.');
|
||||
if ($pos === false) {
|
||||
@@ -257,7 +257,9 @@ Route::add(
|
||||
}
|
||||
$module = substr($controllerPart, 0, $pos);
|
||||
$controller = substr($controllerPart, $pos + 1);
|
||||
$class = '\\app\\admin\\controller\\' . strtolower($module) . '\\' . $controller;
|
||||
// 支持多级路径:pints.Order -> pints\Order,redemption.Order -> redemption\Order
|
||||
$controllerClass = str_replace('.', '\\', $controller);
|
||||
$class = '\\app\\admin\\controller\\' . strtolower($module) . '\\' . $controllerClass;
|
||||
if (!class_exists($class)) {
|
||||
return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
@@ -232,14 +232,16 @@ const getData = debounce((initValue: valueTypes = '') => {
|
||||
state.params.initValue = initValue
|
||||
getSelectData(props.remoteUrl, state.keyword, state.params)
|
||||
.then((res) => {
|
||||
let opts = res.data.options ? res.data.options : res.data.list
|
||||
const data = res?.data ?? {}
|
||||
let opts = data.options ?? data.list ?? []
|
||||
opts = Array.isArray(opts) ? opts : []
|
||||
if (typeof props.labelFormatter === 'function') {
|
||||
for (const key in opts) {
|
||||
opts[key][props.field] = props.labelFormatter(opts[key], key)
|
||||
}
|
||||
}
|
||||
state.options = opts
|
||||
state.total = res.data.total ?? 0
|
||||
state.total = data.total ?? 0
|
||||
state.optionValidityFlag = state.keyword || (typeof initValue === 'object' ? !isEmpty(initValue) : initValue) ? false : true
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
Reference in New Issue
Block a user