From 444065d49643350fc5923d91c2db4978666af71b Mon Sep 17 00:00:00 2001 From: li Date: Sat, 14 Mar 2026 18:15:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=83=A8=E9=97=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=A9=BA/=E8=81=8C=E5=8A=A1=E6=97=A0=E6=B3=95=E5=90=AF?= =?UTF-8?q?=E7=94=A8=20=E2=80=94=20fetchTree=E9=80=82=E9=85=8D=E6=A0=91?= =?UTF-8?q?=E5=BD=A2API=E5=93=8D=E5=BA=94,=20positions=E8=A1=A8=E5=8A=A0st?= =?UTF-8?q?atus/code/description=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/System/PositionController.php | 6 +++++ backend/app/Models/Position.php | 2 +- ...005_add_status_code_to_positions_table.php | 24 +++++++++++++++++++ .../src/views/system/departments/index.vue | 16 +++++++++---- 4 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 backend/database/migrations/2026_03_14_000005_add_status_code_to_positions_table.php diff --git a/backend/app/Http/Controllers/Admin/System/PositionController.php b/backend/app/Http/Controllers/Admin/System/PositionController.php index 2bea1b7..4ed08a4 100644 --- a/backend/app/Http/Controllers/Admin/System/PositionController.php +++ b/backend/app/Http/Controllers/Admin/System/PositionController.php @@ -21,7 +21,10 @@ class PositionController extends Controller { $data = $request->validate([ 'name' => 'required|string|max:50', + 'code' => 'nullable|string|max:50', 'sort' => 'nullable|integer', + 'status' => 'in:0,1', + 'description' => 'nullable|string|max:255', ]); $data['store_id'] = auth()->user()->store_id; @@ -34,7 +37,10 @@ class PositionController extends Controller { $data = $request->validate([ 'name' => 'string|max:50', + 'code' => 'nullable|string|max:50', 'sort' => 'nullable|integer', + 'status' => 'in:0,1', + 'description' => 'nullable|string|max:255', ]); $position->update($data); diff --git a/backend/app/Models/Position.php b/backend/app/Models/Position.php index d546705..b532308 100644 --- a/backend/app/Models/Position.php +++ b/backend/app/Models/Position.php @@ -9,5 +9,5 @@ class Position extends Model { use BelongsToStore; - protected $fillable = ['store_id', 'name', 'sort']; + protected $fillable = ['store_id', 'name', 'code', 'sort', 'status', 'description']; } diff --git a/backend/database/migrations/2026_03_14_000005_add_status_code_to_positions_table.php b/backend/database/migrations/2026_03_14_000005_add_status_code_to_positions_table.php new file mode 100644 index 0000000..35d58c8 --- /dev/null +++ b/backend/database/migrations/2026_03_14_000005_add_status_code_to_positions_table.php @@ -0,0 +1,24 @@ +string('code', 50)->nullable()->after('name')->comment('职务编码'); + $table->tinyInteger('status')->default(1)->after('sort')->comment('1启用 0停用'); + $table->string('description', 255)->nullable()->after('status')->comment('备注'); + }); + } + + public function down(): void + { + Schema::table('positions', function (Blueprint $table) { + $table->dropColumn(['code', 'status', 'description']); + }); + } +}; diff --git a/frontend/src/views/system/departments/index.vue b/frontend/src/views/system/departments/index.vue index 58a679c..1f38feb 100644 --- a/frontend/src/views/system/departments/index.vue +++ b/frontend/src/views/system/departments/index.vue @@ -74,9 +74,15 @@ async function fetchTree() { loading.value = true try { const res = await departmentApi.getList({ per_page: 500 }) - const flat = res.data?.list || res.data?.data || [] - flatDepts.value = flat.map(d => ({ id: d.id, name: d.name })) - treeData.value = buildTree(flat) + // Backend already returns a tree array directly in res.data + if (Array.isArray(res.data)) { + treeData.value = res.data + flatDepts.value = flattenTree(res.data) + } else { + const flat = res.data?.list || res.data?.data || [] + flatDepts.value = flat.map(d => ({ id: d.id, name: d.name })) + treeData.value = buildTree(flat) + } } catch { // } finally { @@ -84,9 +90,9 @@ async function fetchTree() { } } -function buildTree(nodes, parentId = null) { +function buildTree(nodes, parentId = 0) { return nodes - .filter(n => (n.parent_id ?? null) === parentId) + .filter(n => (n.parent_id ?? 0) === parentId) .map(n => ({ ...n, children: buildTree(nodes, n.id) })) }