优化下拉列表组件,修复若干BUG

This commit is contained in:
2026-03-19 09:50:06 +08:00
parent 9b9ff7f13a
commit abcb9b7b9a
4 changed files with 56 additions and 10 deletions

View File

@@ -263,11 +263,28 @@ class Admin extends Backend
} }
/** /**
* 远程下拉(Admin 无自定义,走父类默认列表 * 远程下拉(返回管理员列表供 remoteSelect 使用
*/ */
public function select(Request $request): Response 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 private function checkGroupAuth(array $groups): ?Response

View File

@@ -45,8 +45,7 @@ class User extends Backend
} }
if ($request->get('select') || $request->post('select')) { if ($request->get('select') || $request->post('select')) {
$this->_select(); return $this->select($request);
return $this->success();
} }
list($where, $alias, $limit, $order) = $this->queryBuilder(); list($where, $alias, $limit, $order) = $this->queryBuilder();
@@ -182,6 +181,32 @@ class User extends Backend
return $this->success('', ['row' => $row]); 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(),
]);
}
/** /**
* 删除 * 删除
*/ */

View File

@@ -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::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']); Route::get('/admin/security/dataRecycleLog/info', [\app\admin\controller\security\DataRecycleLog::class, 'info']);
// ==================== 兼容 ThinkPHP 风格 URLmodule.Controller/action ==================== // ==================== 兼容 ThinkPHP 风格 URLmodule.Controller/action 或 module.sub.Controller/action ====================
// 前端使用 /admin/user.Rule/index 格式,需转换为控制器调用 // 前端使用 /admin/user.Rule/index、/admin/mall.pints.Order/index 等格式,需转换为控制器调用
Route::add( Route::add(
['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'], ['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) { function (\Webman\Http\Request $request, string $controllerPart, string $action) {
$pos = strpos($controllerPart, '.'); $pos = strpos($controllerPart, '.');
if ($pos === false) { if ($pos === false) {
@@ -257,7 +257,9 @@ Route::add(
} }
$module = substr($controllerPart, 0, $pos); $module = substr($controllerPart, 0, $pos);
$controller = substr($controllerPart, $pos + 1); $controller = substr($controllerPart, $pos + 1);
$class = '\\app\\admin\\controller\\' . strtolower($module) . '\\' . $controller; // 支持多级路径pints.Order -> pints\Orderredemption.Order -> redemption\Order
$controllerClass = str_replace('.', '\\', $controller);
$class = '\\app\\admin\\controller\\' . strtolower($module) . '\\' . $controllerClass;
if (!class_exists($class)) { if (!class_exists($class)) {
return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE)); return new Response(404, ['Content-Type' => 'application/json'], json_encode(['code' => 404, 'msg' => '404 Not Found', 'data' => []], JSON_UNESCAPED_UNICODE));
} }

View File

@@ -232,14 +232,16 @@ const getData = debounce((initValue: valueTypes = '') => {
state.params.initValue = initValue state.params.initValue = initValue
getSelectData(props.remoteUrl, state.keyword, state.params) getSelectData(props.remoteUrl, state.keyword, state.params)
.then((res) => { .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') { if (typeof props.labelFormatter === 'function') {
for (const key in opts) { for (const key in opts) {
opts[key][props.field] = props.labelFormatter(opts[key], key) opts[key][props.field] = props.labelFormatter(opts[key], key)
} }
} }
state.options = opts 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 state.optionValidityFlag = state.keyword || (typeof initValue === 'object' ? !isEmpty(initValue) : initValue) ? false : true
}) })
.finally(() => { .finally(() => {