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); +}