修复智能气阀归属互斥选择

选择任一新归属时自动清空其他归属,保留提交防御校验和审计接口,并补充专项检查、中文操作日志及项目文档。
This commit is contained in:
czl231
2026-08-13 20:14:56 +08:00
parent 8c5e0468c2
commit 81920d43e8
5 changed files with 115 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
# 智能气阀归属互斥选择操作日志
操作时间2026-08-13
操作类型:修改
影响模块:平台总后台智能气阀归属变更
## 操作前状态
归属变更弹窗同时展示库房、气站、配送点和用户。管理员选择新归属前必须手动清空原归属;同时存在多个值时,提交阶段才提示“智能气阀只能选择一个当前归属”。
## 具体操作
1. 选择任一非空归属时,立即清空另外三个互斥归属。
2. 更新弹窗提示,明确说明自动清空行为。
3. 保留提交前的多重归属防御校验。
4. 保留四个归属字段的完整提交,以便后端清除原归属并记录审计历史。
## 操作后状态
管理员只需选择目标归属,无需逐项手动清空。一个智能气阀仍然最多只有一个当前归属。
## 代码变更
- `frontend/platform_admin/src/views/resource/ResourceActionDialog.vue`:增加归属互斥清空逻辑。
- `frontend/platform_admin/scripts/check-product-ownership-action.mjs`:增加静态回归检查。
- `frontend/platform_admin/package.json`:注册归属检查命令。
## 验证结果
- `npm.cmd run product-ownership:check`:通过,确认选择时自动清空并保留提交防御。
- `npm.cmd run resource-pages:check`:通过,详情 46 类、新建 25 类、编辑 23 类。
- `npm.cmd run build`通过TypeScript 类型检查与 Vite 生产构建成功。
- `git diff --check`:通过,未发现空白符错误。
## 风险评估
修改仅作用于智能气阀归属专用弹窗,不改变数据库、接口字段、后端校验和审计规则。提交阶段继续拒绝异常多重归属。

View File

@@ -0,0 +1,33 @@
# 项目文档:智能气阀归属互斥选择 v1.0
## 1. 项目概述
智能气阀归属变更支持库房、气站、配送点和用户四类目标,但当前归属最多一个。前端选择目标后自动清空其他归属,后端继续负责最终合法性校验和归属历史记录。
## 2. 目录结构说明
```text
platforms/
├── frontend/platform_admin/
│ ├── src/views/resource/ResourceActionDialog.vue
│ └── scripts/check-product-ownership-action.mjs
└── docs/
├── 项目文档_智能气阀归属互斥选择_v1.0.md
└── 操作日志_智能气阀归属互斥选择_20260813.md
```
## 3. 核心行为
- 弹窗打开时保留当前归属,便于管理员确认现状。
- 选择新的非空归属时,前端自动清空另外三个字段。
- 主动清空当前字段不会自动选择其他归属。
- 提交时仍发送全部四个归属字段,空字符串表示清除旧关系。
- 提交前继续执行最多一个归属的防御校验。
## 4. 接口兼容性
继续使用 `PUT /product_info/:identity`,不新增或修改请求字段。动作、原因、备注和后端审计行为保持不变。
## 5. 维护指南
新增归属类型时,必须同步更新互斥字段集合、后端合法性校验、归属历史模型和回归检查,不得只增加一个下拉控件。

View File

@@ -22,6 +22,7 @@
"staff-organization:check": "node scripts/check-staff-organization-linkage.mjs",
"staff-relations:check": "node scripts/check-staff-relation-policy.mjs",
"user-address-display:check": "node scripts/check-user-address-relation-display.mjs",
"product-ownership:check": "node scripts/check-product-ownership-action.mjs",
"resource-search:check": "node scripts/check-resource-search.mjs",
"audit:platform": "node scripts/check-backend-contract.mjs",
"lint": "biome lint .",

View File

@@ -0,0 +1,27 @@
/**
* 功能:检查智能气阀归属弹窗保留互斥选择和提交防御。
* 版本v1.0.0
*/
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
const componentUrl = new URL(
'../src/views/resource/ResourceActionDialog.vue',
import.meta.url,
);
const source = await readFile(fileURLToPath(componentUrl), 'utf8');
const requiredFragments = [
'@change-relation="changeRelation"',
'ownershipKeys.includes(field.key)',
'if (key !== field.key) form[key] = undefined',
"Message.warning('智能气阀只能选择一个当前归属')",
"payload[key] = String(form[key] ?? '')",
];
for (const fragment of requiredFragments) {
if (!source.includes(fragment)) {
throw new Error(`智能气阀归属互斥检查缺少实现:${fragment}`);
}
}
console.log('智能气阀归属互斥检查通过:选择时自动清空,提交时保留防御校验。');

View File

@@ -16,7 +16,7 @@
这是高风险操作可能改变业务状态且无法直接撤销请确认目标记录和填写内容准确
</a-alert>
<a-alert v-if="isOwnershipAction" class="action-alert" type="warning" show-icon>
智能气阀只能有一个当前归属选择新归属前请清空原归属操作会写入审计记录
智能气阀只能有一个当前归属选择新归属后会自动清空其他归属操作会写入审计记录
</a-alert>
<a-form :model="form" layout="vertical">
<ResourceFieldForm
@@ -25,6 +25,7 @@
:required-keys="requiredKeys"
:relation-options="relations.options"
:relation-loading="relations.loading"
@change-relation="changeRelation"
@search-relation="searchRelation"
/>
</a-form>
@@ -75,6 +76,21 @@ function searchRelation(field: ResourceField, keyword: string) {
relations.searchField(field, keyword);
}
/** 选择智能气阀的新归属时清空其余互斥归属,避免提交非法多重归属。 */
function changeRelation(field: ResourceField, value: unknown) {
if (
!isOwnershipAction.value ||
!ownershipKeys.includes(field.key) ||
value == null ||
String(value).trim() === ''
) {
return;
}
for (const key of ownershipKeys) {
if (key !== field.key) form[key] = undefined;
}
}
watch(
() => [props.visible, props.action?.name] as const,
async ([visible]) => {