登录流程:
- login() 不再设置 userInfo,由 router guard 触发 getInfo() + 路由生成
- validate() 从 callback 改为 Promise 式,修复异步链断裂
- getInfo() 适配 /auth/me 扁平响应结构
动态路由:
- import.meta.glob 替代 Vite 不支持的多级动态 import
- 目录菜单检测: !component || 'Layout' 而非仅 'Layout'
- resolveComponent 支持多种 key 格式 + 后缀匹配兜底
侧边栏:
- menu.title → menu.name (匹配后端字段)
- 空 path 目录节点加 fallback index
门店管理:
- StoreController: region_id 改 nullable, 新增 contact/capacity/description 验证
- has('status') → filled('status') 修复空字符串导致列表为空
- capacity null → 0 兜底,避免 NOT NULL 约束报错
- 前端: capacity 初始值 '' → 1, handleSubmit 过滤冗余字段
- region 列渲染 region.name 而非 [object Object]
- 新增 stores 表迁移: contact/capacity/description 列
种子数据:
- DatabaseSeeder 改用 InitSeeder
- createMenus() 补全 52 个叶子页面菜单 (13 模块)
- 目录菜单添加 path 属性
其他:
- vite proxy 端口 8000 → 8001
- request.js 添加 Accept: application/json
- UserStatus 枚举值对齐 (Active=1, Disabled=0)
- 新增 positions/index.vue 页面
87 lines
2.7 KiB
PHP
87 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\System;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Store;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class StoreController extends Controller
|
|
{
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$query = Store::with('region');
|
|
|
|
if ($request->keyword) {
|
|
$query->where('name', 'like', "%{$request->keyword}%");
|
|
}
|
|
if ($request->filled('status')) {
|
|
$query->where('status', $request->status);
|
|
}
|
|
|
|
$stores = $query->orderByDesc('id')
|
|
->paginate($request->input('page_size', 20));
|
|
|
|
return $this->paginate($stores);
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'region_id' => 'nullable|exists:regions,id',
|
|
'name' => 'required|string|max:100',
|
|
'code' => 'nullable|string|max:20|unique:stores,code',
|
|
'address' => 'nullable|string|max:255',
|
|
'phone' => 'nullable|string|max:20',
|
|
'contact' => 'nullable|string|max:50',
|
|
'capacity' => 'nullable|integer|min:0|max:9999',
|
|
'description' => 'nullable|string|max:500',
|
|
'status' => 'in:0,1',
|
|
]);
|
|
|
|
// capacity 列有 NOT NULL + default(0),空值时用默认值
|
|
$data['capacity'] = $data['capacity'] ?? 0;
|
|
|
|
$store = Store::create($data);
|
|
return $this->success($store, '创建成功');
|
|
}
|
|
|
|
public function show(Store $store): JsonResponse
|
|
{
|
|
$store->load('region');
|
|
return $this->success($store);
|
|
}
|
|
|
|
public function update(Request $request, Store $store): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'region_id' => 'nullable|exists:regions,id',
|
|
'name' => 'string|max:100',
|
|
'code' => 'nullable|string|max:20|unique:stores,code,' . $store->id,
|
|
'address' => 'nullable|string|max:255',
|
|
'phone' => 'nullable|string|max:20',
|
|
'contact' => 'nullable|string|max:50',
|
|
'capacity' => 'nullable|integer|min:0|max:9999',
|
|
'description' => 'nullable|string|max:500',
|
|
'status' => 'in:0,1',
|
|
]);
|
|
|
|
if (array_key_exists('capacity', $data) && $data['capacity'] === null) {
|
|
$data['capacity'] = 0;
|
|
}
|
|
|
|
$store->update($data);
|
|
return $this->success($store, '更新成功');
|
|
}
|
|
|
|
public function destroy(Store $store): JsonResponse
|
|
{
|
|
if ($store->users()->exists()) {
|
|
return $this->error('该门店下还有员工,无法删除');
|
|
}
|
|
$store->delete();
|
|
return $this->success(null, '删除成功');
|
|
}
|
|
}
|