fix: 修复页面间状态丢失问题并优化选择页面
- 修复选择审批人后再选择抄送人导致状态丢失的问题 - 使用独立的 sessionStorage key (selectedApprovers, selectedCc) - 组件每次挂载时从 sessionStorage 恢复状态 - 只在提交/保存成功后清除 sessionStorage - 优化人员选择页面布局和样式 - 更新 CLAUDE.md 文档记录问题和解决方案 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\BusinessTripService;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
|
||||
class BusinessTripController extends BaseController
|
||||
{
|
||||
private BusinessTripService $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new BusinessTripService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取路由参数
|
||||
*/
|
||||
private function getRouteParam(Request $request, string $name, $default = null)
|
||||
{
|
||||
$route = $request->route;
|
||||
if ($route && method_exists($route, 'param')) {
|
||||
return $route->param($name) ?? $default;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取出差申请列表
|
||||
*/
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
$userId = $this->getUserId($request);
|
||||
$type = $request->get('type', 'my');
|
||||
$page = (int) $request->get('page', 1);
|
||||
$pageSize = (int) $request->get('page_size', 20);
|
||||
|
||||
$result = $this->service->getList($userId, $type, $page, $pageSize);
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取出差申请详情
|
||||
*/
|
||||
public function detail(Request $request): Response
|
||||
{
|
||||
$id = (int) $this->getRouteParam($request, 'id');
|
||||
if (!$id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$detail = $this->service->getDetail($id);
|
||||
|
||||
return $this->success($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出差申请(草稿)
|
||||
*/
|
||||
public function create(Request $request): Response
|
||||
{
|
||||
$userId = $this->getUserId($request);
|
||||
$data = $request->post();
|
||||
$data = $data ?? [];
|
||||
|
||||
// 验证必填字段
|
||||
if (empty($data['reason'])) {
|
||||
return $this->error('请输入出差原因');
|
||||
}
|
||||
|
||||
if (empty($data['itineraries']) || !is_array($data['itineraries'])) {
|
||||
return $this->error('请至少添加一条行程');
|
||||
}
|
||||
|
||||
// 验证行程数据
|
||||
foreach ($data['itineraries'] as $index => $itinerary) {
|
||||
if (empty($itinerary['start_time'])) {
|
||||
return $this->error("行程" . ($index + 1) . ":请选择开始时间");
|
||||
}
|
||||
if (empty($itinerary['destination'])) {
|
||||
return $this->error("行程" . ($index + 1) . ":请输入目的地");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$businessTrip = $this->service->createDraft($userId, $data);
|
||||
return $this->success($businessTrip, '创建成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新出差申请
|
||||
*/
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$userId = $this->getUserId($request);
|
||||
$id = (int) $this->getRouteParam($request, 'id');
|
||||
if (!$id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$data = $request->post();
|
||||
$data = $data ?? [];
|
||||
|
||||
try {
|
||||
$businessTrip = $this->service->update($userId, $id, $data);
|
||||
return $this->success($businessTrip, '更新成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交出差申请
|
||||
*/
|
||||
public function submit(Request $request): Response
|
||||
{
|
||||
$userId = $this->getUserId($request);
|
||||
$id = (int) $this->getRouteParam($request, 'id');
|
||||
if (!$id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
$data = $request->post();
|
||||
$data = $data ?? [];
|
||||
|
||||
$approvers = $data['approvers'] ?? [];
|
||||
$ccUsers = $data['cc_users'] ?? [];
|
||||
|
||||
if (empty($approvers)) {
|
||||
return $this->error('请选择审批人');
|
||||
}
|
||||
|
||||
try {
|
||||
$businessTrip = $this->service->submit($userId, $id, $approvers, $ccUsers);
|
||||
return $this->success($businessTrip, '提交成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消出差申请
|
||||
*/
|
||||
public function cancel(Request $request): Response
|
||||
{
|
||||
$userId = $this->getUserId($request);
|
||||
$id = (int) $this->getRouteParam($request, 'id');
|
||||
if (!$id) {
|
||||
return $this->error('参数错误');
|
||||
}
|
||||
|
||||
try {
|
||||
$businessTrip = $this->service->cancel($userId, $id);
|
||||
return $this->success($businessTrip, '取消成功');
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user