From 137a3ed1f392a5bea9abc9704c5969784e1c9c6d Mon Sep 17 00:00:00 2001 From: liufumingren Date: Fri, 6 Nov 2026 00:21:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(principal):=20=E4=B8=BB=E4=BD=93=E5=90=AF?= =?UTF-8?q?=E7=94=A8/=E5=81=9C=E7=94=A8=E6=94=B9=E4=B8=BA=E4=BB=85?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=BB=B4=E6=8A=A4=EF=BC=8C=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=8E=E6=8E=A5=E5=8F=A3=E4=B8=8D=E5=8F=AF=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PUT /api/principals/{id} 不再接受 status 变更(变更时返回 403「主体的启用/停用只能由平台运维在数据库中维护」) - POST /api/principals 状态固定为启用,创建时传 status=0 直接 403;其它非白名单字段忽略 - 集团设置页面状态改为只读展示并提示由平台运维维护(去掉启用/禁用开关) - 前端 updatePrincipal 类型移除 status,接口契约说明同步更新 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- backend/app/contract/index.js | 4 +-- backend/app/controller/principal.js | 31 ++++++++++++++++--- frontend/src/api/principal.ts | 4 +-- .../src/views/Organization/GroupSettings.vue | 11 +++++-- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/backend/app/contract/index.js b/backend/app/contract/index.js index 3299136..26c4cf5 100644 --- a/backend/app/contract/index.js +++ b/backend/app/contract/index.js @@ -277,7 +277,7 @@ module.exports = { type: { type: 'integer', description: '主体类型:1自营 2加盟 3外部,默认1' }, contact_name: { type: 'string', description: '联系人' }, contact_phone: { type: 'string', description: '联系电话' }, - status: { type: 'integer', description: '状态:1启用 0禁用,默认1' }, + status: { type: 'integer', description: '主体状态固定为启用:启用/停用只能由平台运维在数据库中维护' }, remark: { type: 'string', description: '备注' }, }, updatePrincipalRequest: { @@ -285,7 +285,7 @@ module.exports = { type: { type: 'integer', description: '主体类型:1自营 2加盟 3外部' }, contact_name: { type: 'string', description: '联系人' }, contact_phone: { type: 'string', description: '联系电话' }, - status: { type: 'integer', description: '状态:1启用 0禁用' }, + status: { type: 'integer', description: '主体状态不接受接口修改:启用/停用只能由平台运维在数据库中维护' }, remark: { type: 'string', description: '备注' }, }, diff --git a/backend/app/controller/principal.js b/backend/app/controller/principal.js index 0c2577d..d74f225 100644 --- a/backend/app/controller/principal.js +++ b/backend/app/controller/principal.js @@ -3,8 +3,11 @@ const { Controller } = require('egg'); const { parsePagination, buildPageResult } = require('../lib/pagination'); -/** 允许更新的主体字段,避免请求体覆盖 id 等主键信息 */ -const WRITABLE_FIELDS = [ 'name', 'type', 'contact_name', 'contact_phone', 'status', 'remark' ]; +/** 允许更新的主体字段,避免请求体覆盖 id 等主键信息 + * 注意:不含 status —— 主体的启用/停用只能由平台运维直接在数据库中维护, + * 页面与接口都不允许普通用户自行启用或停用集团(否则会把自己锁死或被绕过)。 + */ +const WRITABLE_FIELDS = [ 'name', 'type', 'contact_name', 'contact_phone', 'remark' ]; /** * @controller PrincipalController 主体管理 @@ -94,7 +97,8 @@ class PrincipalController extends Controller { /** * @summary 新增主体 - * @description 主体名称 name 必填;创建者自动关联为该主体 owner(多租户隔离) + * @description 主体名称 name 必填;创建者自动关联为该主体 owner(多租户隔离); + * 主体状态固定为启用(启用/停用只能由平台运维在数据库中维护) * @router post /api/principals * @apikey * @request body createPrincipalRequest *body @@ -109,8 +113,18 @@ class PrincipalController extends Controller { ctx.body = { code: 400, message: 'name 为必填项' }; return; } + // 状态不接受入参:主体启用/停用只能由平台运维在数据库中维护 + if (ctx.request.body.status !== undefined && Number(ctx.request.body.status) !== 1) { + ctx.status = 403; + ctx.body = { code: 403, message: '主体的启用/停用只能由平台运维在数据库中维护' }; + return; + } - const principal = await ctx.model.Principal.create(ctx.request.body); + const payload = { status: 1 }; + WRITABLE_FIELDS.forEach(field => { + if (ctx.request.body[field] !== undefined) payload[field] = ctx.request.body[field]; + }); + const principal = await ctx.model.Principal.create(payload); // 将创建者关联为该主体的默认用户(owner),建立多租户归属关系 if (ctx.userId) { @@ -131,7 +145,7 @@ class PrincipalController extends Controller { /** * @summary 更新主体 - * @description 未传入的字段保持原值 + * @description 未传入的字段保持原值;不接受状态变更(主体启用/停用只能由平台运维在数据库中维护) * @router put /api/principals/{id} * @apikey * @request path integer *id 主体主键ID @@ -155,6 +169,13 @@ class PrincipalController extends Controller { return; } + // 状态不通过接口维护:避免普通用户自行启用/停用集团(停用后自身也会被锁在外面) + if (ctx.request.body.status !== undefined && Number(ctx.request.body.status) !== Number(principal.status)) { + ctx.status = 403; + ctx.body = { code: 403, message: '主体的启用/停用只能由平台运维在数据库中维护' }; + return; + } + const data = {}; WRITABLE_FIELDS.forEach(field => { if (ctx.request.body[field] !== undefined) data[field] = ctx.request.body[field]; diff --git a/frontend/src/api/principal.ts b/frontend/src/api/principal.ts index 61758ab..9e7b019 100644 --- a/frontend/src/api/principal.ts +++ b/frontend/src/api/principal.ts @@ -29,8 +29,8 @@ export function getPrincipal(id: number) { return get(`/principals/${id}`) } -/** 更新主体(组织架构 → 集团设置保存当前主体) */ -export function updatePrincipal(id: number, data: Partial & { status?: number }) { +/** 更新主体(集团设置保存当前主体);主体状态不接受接口修改,只能由平台运维在数据库中维护 */ +export function updatePrincipal(id: number, data: Partial) { return put<{ id: number }>(`/principals/${id}`, data) } diff --git a/frontend/src/views/Organization/GroupSettings.vue b/frontend/src/views/Organization/GroupSettings.vue index d73341d..e291c3b 100644 --- a/frontend/src/views/Organization/GroupSettings.vue +++ b/frontend/src/views/Organization/GroupSettings.vue @@ -77,7 +77,6 @@ async function handleSave() { type: form.type, contact_name: form.contact_name.trim(), contact_phone: form.contact_phone.trim(), - status: form.status, remark: form.remark.trim(), }) ElMessage.success('集团设置已保存') @@ -126,7 +125,10 @@ onMounted(fetchGroup) - + + {{ form.status === 1 ? '启用' : '已停用' }} + + 主体启用/停用由平台运维在后台维护,页面不可自行切换 @@ -161,4 +163,9 @@ onMounted(fetchGroup) max-width: 620px; margin-top: 8px; } +.status-hint { + margin-left: 10px; + font-size: 12px; + color: var(--el-text-color-secondary); +}