feat/object-dataset-interactions #6
|
|
@ -1,66 +1,68 @@
|
|||
# 对象视图 / 数据集视图 交互操作 — 进度 · 问题 · 下步计划
|
||||
# 对象视图 / 数据集视图 交互操作 — 实现计划
|
||||
|
||||
依据:`D:\Projects\GEOPRO\Geopro3.0 菜单.xlsx`「客户端」页签(对象列表 / 数据集列表 交互规则)。
|
||||
约定:二维/三维视图相关交互**先占位**;其余尽量接真实后端。
|
||||
配套:API 实地研究见 `../specs/2026-06-13-batch2-object-dataset-dialogs.md`。
|
||||
依据:`D:\Projects\GEOPRO\Geopro3.0 菜单.xlsx`「客户端」页签(菜单/交互规格,权威)。
|
||||
后端提交体:见 `../specs/2026-06-13-batch2-object-dataset-dialogs.md`(§B 提交体 / §E 源码补全,**均已由线上压缩源码确证**)。
|
||||
约定:二维/三维相关交互先占位;插件机制**暂缓**(待与用户深入讨论)。
|
||||
|
||||
---
|
||||
|
||||
## 一、已完成(已编译 + 单测通过;写操作待真实提交验证)
|
||||
## 一、已完成(已编译 + 单测通过)
|
||||
|
||||
### Batch 1 — 交互骨架 + 读联动 + 删除 + 筛选(已并入本分支)
|
||||
- **ApiClient**:补 `putJsonAsync` / `deleteAsync`。
|
||||
- **删除**(真实 DELETE):`deleteObjectAsync`(GS/TM) / `deleteDatasetAsync`;控制器 `deleteObject`/`deleteDataset` + `mutationSucceeded/Failed`,成功后刷新结构 / 数据集列表。
|
||||
- **对象树右键菜单**(9 项):属性、异常详情(`showObjectExceptions`,GS→收集其下 TM 复用 setCheckedTms)真实接现有面板;删除真实;显示隐藏/定位=2D/3D 占位。
|
||||
- **数据集右键菜单**:数据集详情、属性 真实;删除真实。
|
||||
- **快速筛选器**:对象树(全选测线/取消/反选);数据集(类型多选 + 创建日期,客户端隐藏不匹配行)。
|
||||
- **数据集单击 tooltip**:名称/类型/创建时间。
|
||||
- **手势修复 #1**:点对象树复选框只切勾选、不再触发"选中"重载(viewport 事件过滤 + 复选框命中判定)。
|
||||
### Batch 1 — 交互骨架 + 读联动 + 删除 + 筛选
|
||||
- ApiClient `putJsonAsync`/`deleteAsync`;删除真实(GS/TM/DS)+ 控制器 `mutationSucceeded/Failed` + 刷新。
|
||||
- 对象树右键菜单(9 项):属性/异常详情/删除 真实;显示隐藏/定位=占位。
|
||||
- 数据集右键菜单:详情/属性/删除 真实。
|
||||
- 快速筛选器(对象树、数据集);数据集单击 tooltip;手势修复 #1(复选框命中判定)。
|
||||
|
||||
### Batch 2(本轮)— 动态表单引擎 + 编辑保存 + 新建 TM + 插件列表
|
||||
- **动态表单引擎** `DynamicFormEditor`:按 `project/getDynamicForm` 字段元信息渲染
|
||||
comp1=文本(dtype2/3 数字+范围校验) / comp4=下拉(optionsObject) / comp6=日期 / comp7=日期时间 /
|
||||
comp8=多行;必填(requiredType==1)标红 *;编辑态用 properties 预填。
|
||||
- **ObjectFormDialog**:拉真实 schema → 渲染 → 校验 → 提交。
|
||||
- **编辑保存**:右键编辑 → PUT `/business/{gs|tm}Object` → 成功刷新结构,失败回显后端 msg。
|
||||
- **新建 TM**:右键 GS → `queryTmType` 选型 → 空表单 → POST(带 structParentId/structParentConfType)。
|
||||
- **插件子菜单**:数据集右键「插件」列出真实 `model/list`(启动缓存);点击=占位 toast。
|
||||
- 数据层:`EditableForm`/`TmTypeOption`/`ModelInfo` DTO + parse;`StructNode.typeId`;
|
||||
repo `loadEditableFormAsync`/`queryTmTypesAsync`/`submitObjectAsync`/`listModelsAsync`;
|
||||
controller `currentProjectId()`。
|
||||
### Batch 2 — 动态表单引擎 + 编辑/新建(⚠️ 提交体字段需修正,见下)
|
||||
- `DynamicFormEditor`(按 getDynamicForm 渲染)、`ObjectFormDialog`(拉 schema→渲染→校验→提交)。
|
||||
- 编辑保存 PUT、新建 TM POST、插件列出 `model/list`(点击占位)。
|
||||
- 数据层 DTO/parse/repo/controller 齐备。
|
||||
|
||||
> ⚠️ Batch 2 的**提交体字段是早期错误版本**(`typeId/type/structParentId/structParentConfType`),
|
||||
> 与源码确证的真实字段不符,须按下方 P0 修正后才能真正保存成功。
|
||||
|
||||
---
|
||||
|
||||
## 二、已知问题 / 风险
|
||||
## 二、关键认知(2026-06-15,源码已确证)
|
||||
|
||||
1. **保存/新建请求体为推断**(最高优先级风险)
|
||||
- OpenAPI 未文档化 POST/PUT body;原版前端在 Vue 组件动态拼装,压缩代码难 100% 还原。
|
||||
- 当前发送 `{typeId,id,type,projectId,properties:{fieldCode:值}}`(新建另带父上下文)。
|
||||
- **需用户真实提交验证**:失败时对话框回显后端 msg;用户提供浏览器 Network 真实 body 后定版。
|
||||
|
||||
2. **动态表单只读规则未定**:原版禁用了"测量值"字段(名称/电极数/间距/线长,落在 properties)。
|
||||
无显式 disabled 标志可依,当前一律可编辑(不发请求时无害);接保存后需确认规则。
|
||||
|
||||
3. **菜单文档与实现的不一致**(用户已知,暂不改):
|
||||
- 项目根("也是一个 GS")当前为不可选中/勾选的纯容器。
|
||||
- GS 勾选用 Qt 自动三态,会改写子 TM 勾选态;文档 rule4 要求"屏蔽不改状态、可恢复"(随 2D/3D 做)。
|
||||
- GS 选中是否返回其下全部 ds,未实测后端。
|
||||
|
||||
4. **2D/3D 相关交互**:显示/隐藏、定位、双击地图获焦 — 按约定占位。
|
||||
- 提交体以 **bundle 源码为准**(线上前端真实请求构造,OpenAPI 为有误的生成文档)。详见 spec §B / §E。
|
||||
- 菜单规格以 **xlsx 为准**(现有菜单结构已对齐,勿按原型删减)。
|
||||
- 已确证:GS/TM 提交体字段、`properties.<fieldCode>` 嵌套、displayComponentType 全集映射、
|
||||
requiredType(1=必填 / 2=只读 / 其他=可选)、导出 body。
|
||||
- **唯一开放点:插件机制**(web 无"ds→插件"交互,xlsx 为客户端原创设计)→ 暂缓,待讨论。
|
||||
|
||||
---
|
||||
|
||||
## 三、下一步计划
|
||||
## 三、实现计划(不含插件;每步带验证)
|
||||
|
||||
| 优先 | 任务 | 前置 |
|
||||
| 优先 | 任务 | 验证 |
|
||||
|---|---|---|
|
||||
| P0 | 用户实测 编辑保存 / 新建TM / 删除;据真实 body 定版字段 | 用户测试 |
|
||||
| P1 | 新建 GS(GS 类型来源:研究原版「项目结构\添加」,疑似需 gsTypeId) | Playwright |
|
||||
| P1 | 导入 DS 向导(TM.dsList 选类型 → query/script → 文件 → checkImport → import;含 multipart 上传) | 抓 import 细节 |
|
||||
| P2 | 导出对话框(queryExportObject 选对象 + 模板 → templateExport/export) | 抓 export body |
|
||||
| P2 | 插件「关联过滤 + 调用」(某 ds 适用哪些模型 + 模型任务流) | 研究原版 |
|
||||
| P3 | 动态表单只读规则、GS 三态语义(与 2D/3D 批次合并)、项目根可选中 | — |
|
||||
| **P0** | **修提交体字段**(`ObjectFormDialog.onConfirm`):GS→`{gsTypeId, parentId(仅新建), name, responsiblePersonName, properties}`;TM→`{tmTypeId, parentId, parentType:"1", name, properties}`(+编辑 id)。删除 `typeId/type/structParentId/structParentConfType`。 | 字段比对 spec §B;真实保存成功(写操作留用户实测) |
|
||||
| **P0** | **`DynamicFormEditor` 按 §E.1 全集重写控件映射**:1/5文本·2只读·3复选·4下拉·6日期·7时间·8日期时间·9多行·10数字·11树选·默认步进数字;`requiredType` 2=只读禁用。 | 各 comp 类型渲染正确、只读字段禁用 |
|
||||
| **P0** | **顶层固定字段**:GS 加 `gsTypeId` 下拉(来源 `GET /business/project/gsList/{projectId}` → `[{name,gsTypeId}]`) + `responsiblePersonName` + `name`;TM 新建加 `tmTypeId` 下拉(来源 `queryTmType?projectId=&gsId=`) + `name`。 | 新建表单含这些项;编辑态正确预填/禁用 |
|
||||
| **P1** | **项目根节点按 GS 处理**:可右键「新增检测对象(GS)/新增方法对象(TM)/属性」;`parentId`=根 id。 | 根节点弹菜单、新建走对应对话框 |
|
||||
| **P1** | **新建 GS 打通**:右键新建GS → getDynamicForm(type=1,无id) → 表单 → `POST /gsObject`。 | 弹表单、提交(写操作留用户实测) |
|
||||
| **P1** | **新建 TM 修正**:方法类型 `queryTmType`;提交体随 P0;父对象=右键节点。 | 弹表单、提交 |
|
||||
| **P2** | **导入 DS 向导**:TM 右键「导入DS(1..n)」→ 选类型 → getDynamicForm(type=6 脚本参数) → 选文件 → `checkImport` → `import`(multipart `{file,dsTypeId,projectId,structParentConfType,structParentId,scriptCode,scriptParamListJsonStr}`)。 | 流程走通、文件上传 |
|
||||
| **P2** | **导出对话框**:数据集右键「导出」→ 选模板 → `POST /templateExport/export {dsObjectIdList:[该ds],templateId}`;模板来源 localStorage `template`.fileTemplateList / `queryFileType`。 | 导出触发 |
|
||||
|
||||
### 提交体捕获方法(不动生产数据的前提下尽量做)
|
||||
- 优先:用户在原系统真实操作一次,复制 Network 请求体。
|
||||
- 备选:继续分析 `index-*.js` 路由分包中数据管理组件的保存处理逻辑。
|
||||
---
|
||||
|
||||
## 三补、其余"可做但未做"的编辑操作(2026-06-15 盘点)
|
||||
|
||||
| 优先 | 任务 | 来源/接口 | 状态 |
|
||||
|---|---|---|---|
|
||||
| **P1** | **#1 数据集描述编辑保存**(原版"数据集属性可编辑"实为**富文本描述/备注**编辑) | 加载 `GET /dsObject/getDetail/{id}`.attachedParameters.deltaContent;保存 `PUT /dsObject/updateDsObject/ {dsObjectId, description, attachedParameters:{deltaContent}}`(源码确证) | **本轮做**:客户端无 Quill,简化为纯文本/富文本 QTextEdit,deltaContent 用最小 delta 承载 |
|
||||
| **P1** | **#3 面板级「添加+」按钮**(对象列表→新建GS/TM;数据集列表→导入) | 纯前端,复用现有 newGs/newTm/import 入口 | **本轮做** |
|
||||
| P2 | #4 异常→异常体 拖拽合并(对象异常面板) | `exception/*`(合并接口待查) | 未做 |
|
||||
| P2 | #5 数据集任务:新增处理任务/保存处理结果 | 与模型/插件流程耦合 | 未做(随插件) |
|
||||
| P3 | #2 属性面板内联编辑 + 实时跳转(属性指向另一 ds 时点击跳转新建详情页) | — | 未做 |
|
||||
| P3 | #6 数据详情处理类编辑(异常标注/色阶/白化/滤波/另存为) | 与渲染耦合 | 未做(随 2D/3D 或专项) |
|
||||
|
||||
## 四、暂缓 / 排除
|
||||
|
||||
- **插件机制**(spec §E.3):web 无对应交互,需产品/后端决策(客户端反查 `model/list`+各模型 `dsObjectList`,或后端加"按 ds 列模型"接口)。**待与用户深入讨论后再实现。**
|
||||
- **2D/3D 相关**:显示/隐藏、定位、双击地图获焦 —— 占位,随 2D/3D 批次。
|
||||
- GS 勾选三态语义(屏蔽不改状态、可恢复)、项目根勾选 —— 随 2D/3D 批次。
|
||||
- 动态表单只读规则细节:以 §E.1 的 `displayComponentType=2` / `requiredType=2` 为准。
|
||||
|
|
|
|||
|
|
@ -6,6 +6,123 @@ projectTypeId `1445121423155200`)所得。API 经页面 token replay + 真实
|
|||
> 口径:成功码 `code==200`;列表载荷在 `data`(非对象时包成 `data.value`)。
|
||||
> token 头 `geomativeauthorization`;base `http://tenant.geomative.cn/pop-api`。
|
||||
|
||||
---
|
||||
|
||||
## 更新(2026-06-15):权威来源已厘清,前述"⚠️未捕获"壁垒解除
|
||||
|
||||
三个来源各司其职,别再混用:
|
||||
- **xlsx「客户端」页签** = 客户端菜单/交互**规格(权威)**。
|
||||
- **原 web 压缩 bundle = 提交体的"地面真相"(首要权威)**:线上正在跑、能成功建对象的真实前端代码,它发什么服务端就收什么。
|
||||
bundle 抓 `http://tenant.geomative.cn/static/js/` 各路由 chunk 后 grep 还原:
|
||||
`GsForm-*.js`(GS表单) / `tmForm-D7d9h9Nb.js`(TM表单,数据管理页) / `ImportForm-*.js`(导入) / `projectStructure-*.js`。
|
||||
- **`docs/apis` OpenAPI = 交叉校验(次级)**:自动生成、已知有缺漏/错标(如 GS 名称字段标成 `projectName`)。**与 bundle 冲突时以 bundle 为准**,并在 §B 并列标注、留一次真实请求验证。
|
||||
- **原型 `prototype.geomative.cn`** = 粗略视觉 mockup,菜单画不全,**不作为菜单删减依据**。
|
||||
|
||||
### A. xlsx 规定的菜单(= 现有实现已对齐,勿按原型删减)
|
||||
|
||||
| 区域 | 菜单/动作(xlsx 原文) | 对话框来源(xlsx 标注) |
|
||||
|---|---|---|
|
||||
| 对象-添加+ | 新建GS(当前为TM时无效)、新建TM | GS→`项目配置\项目结构\添加`;TM→`数据管理\新增方法对象` |
|
||||
| 对象-右键 | 显示/隐藏、定位、属性、异常详情、编辑、新建GS、新建TM、导入DS(1..n)、删除 | 编辑→`数据管理\编辑`;导入→`数据管理\导入` |
|
||||
| 数据集-添加+ | 新建/导入一个数据集 | `数据管理\可新建数据类型\导入` |
|
||||
| 数据集-右键 | 数据集详情、属性、插件1/2/3…、导出、删除 | 导出→`批量导出\文件导出` |
|
||||
|
||||
注:xlsx 第32行"显示项目(**也是一个GS**)"——**项目根本身就是 GS 节点**。最强证据是真实数据:`queryProjectStruct` 返回的结构里确有 TM(type=2) 直接挂在项目根(type=1) 下(如 NERT1、"123")——若根不允许建 TM,该数据无从产生。故**项目根(作为 GS)允许新建 TM**。
|
||||
|
||||
### B. 提交体(**bundle 为准,OpenAPI 并列校验**,替换下文旧"⚠️未捕获")
|
||||
|
||||
bundle 还原(= 客户端应照此发送):
|
||||
```
|
||||
POST /business/gsObject { gsTypeId, parentId, projectId, name, responsiblePersonName, properties }
|
||||
PUT /business/gsObject { gsTypeId, id, projectId, name, responsiblePersonName, properties } // 编辑无 parentId
|
||||
· gsTypeId(测试对象类型)、responsiblePersonName(负责人)、name 为顶层固定字段;动态字段在 properties
|
||||
· parentId 仅 POST 用 = 右键所在节点 id(含项目根)
|
||||
|
||||
POST /business/tmObject { tmTypeId, name, properties, projectId, parentId, parentType:"1" }
|
||||
PUT /business/tmObject { tmTypeId, id, name, properties, projectId, parentId, parentType:"1" }
|
||||
· bundle 中 create/edit 用同一 spread,故 PUT 也带 parentId/parentType
|
||||
· parentId = 右键所在节点 id(GS 或项目根);parentType 恒字符串 "1"
|
||||
|
||||
POST /business/dsObject/import (参数走 query string;file 为 multipart 上传项)
|
||||
{ file*, dsTypeId*, projectId*, structParentConfType*(int), structParentId*, scriptCode?, scriptParamListJsonStr?, aliasName? }
|
||||
· 选脚本先 getDynamicForm(typeId=scriptId, type=6) 取脚本参数;checkImport 校验坐标
|
||||
```
|
||||
getDynamicForm 的 `type`:**1=GS对象 / 2=TM对象 / 6=导入脚本参数**(已确认)。
|
||||
|
||||
**✅ 线上实测已确认(intercept-abort,未写库):动态字段嵌套在 `properties.<fieldCode>` 下。**
|
||||
证据:编辑弹窗真实字段 DOM id —— GS `properties_topography/geotechnical/climate/hydrology`、TM `properties_supervisor/notes` 等;顶层固定字段(gsTypeId/responsiblePersonName/name、tmTypeId/name)与 properties 分开渲染。
|
||||
|
||||
**bundle ↔ OpenAPI 冲突(已由压缩源码分析确证,以 bundle 为准;OpenAPI 为文档生成误差):**
|
||||
下表结论来自 GsForm/tmForm 压缩源码还原(= 线上前端真实请求构造)。线上 app 正是发这些 body 且能成功建/改对象,故服务端接受度亦由线上运行佐证。OpenAPI 的 `projectName`/整数等是自动生成的文档误差,不采信。
|
||||
| 字段 | bundle(线上真实代码) | OpenAPI(生成文档) | 取舍 | 实测状态(含源码分析) |
|
||||
|---|---|---|---|---|
|
||||
| GS 名称 | 顶层 `name` | POST 标 `projectName`、PUT 无 | 用 `name`(projectName 系 DTO 误标) | ✅ 源码已证 |
|
||||
| TM 名称 | 顶层 `name` | 无 `name` | 用 `name`(OpenAPI 漏列) | ✅ 源码已证 |
|
||||
| `parentType` | 字符串 `"1"` | integer | 发字符串 `"1"` | ✅ 源码已证 |
|
||||
| PUT tmObject 的 parentId/parentType | 带(create/edit 同一 spread) | 无 | 带(匹配线上) | ✅ 源码已证 |
|
||||
| 动态字段位置 `properties.<code>` | 是 | —— | 随 bundle | ✅ 源码 + 运行时双证 |
|
||||
> 注:拦截-阻断的运行时抓包在本数据集走不通(变更表单必填项多、arco 校验拦截、且不写生产库),但**源码分析已足以确证 body**,无需真实写入。
|
||||
|
||||
### C. 客户端待改项(对照现有实现)
|
||||
|
||||
1. **`ObjectFormDialog` 提交体字段错误**(最关键):
|
||||
- 现:`{typeId, type, projectId, id?, properties}` + extraBody `{structParentId, structParentConfType}`
|
||||
- 应(按 bundle):GS→`{gsTypeId, parentId(仅新建), name, responsiblePersonName, properties}`;
|
||||
TM→`{tmTypeId, parentId, parentType:"1", name, properties}`(+ 编辑加 id)
|
||||
- `structParentId/structParentConfType` 是**导入**的字段,被误用于新建对象(OpenAPI 证实这两字段只在 `dsObject/import` 出现)。
|
||||
2. **项目根节点**:现为"非交互无菜单",应按 GS 处理(提供 新建GS/新建TM/属性,依 xlsx 第32行 + 真实数据"TM 挂根")。
|
||||
3. **新建TM 方法类型来源**(决策):**用 `queryTmType?projectId=&gsId=`**——带 gsId 能按所选 GS 过滤方法类型,比 web 全局 tmMethodList 更准。
|
||||
4. **父对象确定逻辑**(决策):客户端**不复刻** web 数据管理页"先选左树"的选择器;**父对象 = 右键所在节点**(GS 或项目根),`parentId` 直接取该节点 id。
|
||||
5. **`DynamicFormEditor` 顶层固定字段**:GS 须含 gsTypeId 下拉 + responsiblePersonName + name;TM 新建须含 tmTypeId 下拉 + name。
|
||||
6. `displayComponentType` 全集映射 —— **已由源码确证**,见 §E.1。
|
||||
|
||||
### D. 状态(原"待确认"已全部由源码分析落地)
|
||||
- ✅ `displayComponentType` 完整映射 → §E.1
|
||||
- ✅ 导出 body → §E.2
|
||||
- ✅ 插件机制 → §E.3(结论:web 无"ds→插件"菜单,客户端此项为原创设计,需产品决策)
|
||||
- §B 字段已由源码确证,**不再需要真实写入回证**。
|
||||
- (`PUT /dsObject/updateDsObject` body OpenAPI 已定义 `{dsObjectId, description, attachedParameters, ...}`,见下文第六节。)
|
||||
|
||||
### E. 源码补全(FieldItem / 导出 / 插件,均来自压缩源码)
|
||||
|
||||
**E.1 `displayComponentType` → 控件(FieldItem `index-1LyDq-Qg.js`,权威全集)**
|
||||
| 值 | 控件 | 备注 |
|
||||
|---|---|---|
|
||||
| 1 | a-input 单行文本 | |
|
||||
| 2 | a-input **禁用** | 只读文本 |
|
||||
| 3 | a-checkbox | label=item.name |
|
||||
| 4 | a-select 下拉 | options=optionsObject |
|
||||
| 5 | a-input 单行文本 | 同 1 |
|
||||
| 6 | a-date-picker 日期 | |
|
||||
| 7 | a-time-picker 时间 | |
|
||||
| 8 | a-date-picker show-time | 日期时间 `YYYY-MM-DD HH:mm:ss` |
|
||||
| 9 | a-textarea 多行文本 | |
|
||||
| 10 | a-input-number 数字 | |
|
||||
| 11 | a-tree-select 树选择 | data=optionsObject, fieldNames{key:value,title:label,children:childList} |
|
||||
| 其他 | a-input-number mode=button | 步进数字 |
|
||||
- 字段路径 `${fieldPrefix=properties}.${fieldCode}` → 确认动态值在 `properties.<fieldCode>`。
|
||||
- **`requiredType` 语义纠正:1=必填可编辑;2=只读禁用(`disabled: isDisabled||requiredType===2`,required 仅 ===1);其他=可选可编辑。**
|
||||
- comp 类型由后端按类型配置(如"测区"把地形地貌配成 6=日期选择器),客户端按本表渲染即可。
|
||||
|
||||
**E.2 导出 body(ExportModal `ExportModal-DWdo-HxP.js`,两套)**
|
||||
```
|
||||
模板导出 POST /business/templateExport/export { dsObjectIdList:[ds ids], templateId }
|
||||
文件导出 POST /business/dataFileExport/export { idList:[ds ids], fileType [, startTime, endTime] }
|
||||
// startTime/endTime 仅 fileType==5(时序数据)
|
||||
文件下载 POST /business/dataFileExport/download (responseType=blob)
|
||||
```
|
||||
- `selectType`(checked/currentPage) 仅决定取哪些 id,不进 body。
|
||||
- 批量导出页流程:选数据类型/时间范围 → 勾选文件(ds ids) → 「导出」开 ExportModal(选模板) → 提交。
|
||||
- 客户端数据集右键「导出」(单 ds, 按模板) → `templateExport/export { dsObjectIdList:[该ds], templateId }`;模板来自 localStorage `template`.fileTemplateList 或 `dataFileExport/queryFileType`。
|
||||
|
||||
**E.3 插件机制(结论:web 无对应交互,客户端为原创设计)**
|
||||
- web 中**没有**"数据集右键→插件"菜单。模型从模型管理页按类型用专用 Modal 调起(resipy=ERT反演、gprpy=GPR处理 等,见 `resipyModel-*.js`/`gprpyModel-*.js`/`modelManage-*.js`)。
|
||||
- 关联方向是**模型→可用数据集**:`GET /business/model/{scriptType}/dsObjectList/{projectId}`(如 `model/resipy/dsObjectList/{projectId}`),即每个模型声明它能跑哪些 ds。
|
||||
- 全局模型目录:`GET /business/model/list`;任务分页:`POST /business/model/task/page`。
|
||||
- xlsx 的"插件1/2/3 = 列出与当前 ds 关联的插件"是**客户端原创**(ds→模型 的反向)。web 无单一直达接口,需:用 model/list + 各模型 dsObjectList 反查匹配,或后端新增"按 ds 列模型"接口。**此项需产品/后端决策,非源码可定。**
|
||||
|
||||
---
|
||||
|
||||
## 一、项目结构(已用于现有功能)
|
||||
`GET /business/projectStruct/queryProjectStruct/{projectId}`
|
||||
→ 扁平节点 `[{id,parentId,name,type(1=GS,2=TM),typeName,typeId,confCode,collectTime}]`,根 parentId="0"。
|
||||
|
|
@ -50,12 +167,12 @@ GS「测区」formList 含:创建人/创建日期(comp6)/名称(comp1)/创建
|
|||
→ `[{label:"瞬变电磁方法", value:<tmTypeId>, code:"TEM01"}]`
|
||||
新建流程:选 GS → queryTmType 选方法类型 → getDynamicForm(typeId,type=2,无id) 取空表单 → 填 → POST。
|
||||
|
||||
### ⚠️ 未捕获(真实壁垒,不可猜)
|
||||
- `POST /business/gsObject`(新建GS body)
|
||||
- `POST /business/tmObject`(新建TM body)
|
||||
- `PUT /business/gsObject` / `PUT /business/tmObject`(更新 body)
|
||||
实测:点「确定」时必填项为空→前端校验拦截,未发 PUT。要抓须填完必填项保存(会改数据)。
|
||||
- `PUT /business/dsObject/updateDsObject`(更新DS body)
|
||||
### ~~⚠️ 未捕获(真实壁垒,不可猜)~~ → 已解除,见上「更新 §B」
|
||||
~~下列 body 当时认为不可得;实为 OpenAPI requestBody + bundle 已给出,参见文首「更新 §B」。~~
|
||||
- ~~`POST /business/gsObject`~~ → 见 §B
|
||||
- ~~`POST /business/tmObject`~~ → 见 §B
|
||||
- ~~`PUT /business/gsObject` / `PUT /business/tmObject`~~ → 见 §B
|
||||
- `PUT /business/dsObject/updateDsObject`(更新DS body)仍待确认
|
||||
|
||||
## 三、删除(已实现 Batch1)
|
||||
`DELETE /business/gsObject/{id}` `DELETE /business/tmObject/{id}` `DELETE /business/dsObject/{id}`
|
||||
|
|
@ -81,13 +198,15 @@ TM 的 getDetail.dsList = 该 TM 可承载的 ds 类型 `[{dsTypeId,nameChn,name
|
|||
`POST /business/model/task/page` → 模型任务分页(用于"数据集任务"面板)。
|
||||
|
||||
## 实施建议顺序
|
||||
1. 动态表单引擎 `DynamicFormEditor`(Qt):按 formList 渲染 comp1/6/7/8 + 下拉(optionsObject) + 必填校验 + 只读核心字段;编辑用 properties 预填。**先在原版逐一核实 displayComponentType 全集映射。**
|
||||
2. 编辑对象(最先打通:getDynamicForm 取 schema → 编辑器 → PUT)。**先捕获 PUT body。**
|
||||
3. 新建 GS / 新建 TM(queryTmType → 空表单 → POST)。**先捕获 POST body。**
|
||||
4. 导入 DS(dsList 选类型 → query/script → 文件 → checkImport → import)。**先捕获 import 细节。**
|
||||
5. 导出(queryExportObject 选对象 + 模板 → export)。**先捕获 export body。**
|
||||
6. 插件子菜单(model/list 列出;调用/关联逻辑待定)。
|
||||
> body 已由「更新 §B」给出,下列"先捕获"前置多数已不需要;仅 §D 三项仍待确认。
|
||||
1. 动态表单引擎 `DynamicFormEditor`(Qt):按 formList 渲染 comp1/6/7/8 + 下拉(optionsObject) + 必填校验 + 只读核心字段;编辑用 properties 预填;GS/TM 顶层固定字段(§C-5:gsTypeId/responsiblePersonName/name、tmTypeId/name)。**displayComponentType 全集映射仍需核实。**
|
||||
2. **修编辑/新建提交体字段**(§C-1):GS→gsTypeId+parentId(仅新建)+name+responsiblePersonName;TM→tmTypeId+parentId+parentType:"1"+name。
|
||||
3. 项目根菜单按 GS 处理(§C-2);新建TM 类型用 queryTmType(§C-3);父对象=右键节点(§C-4)。
|
||||
4. 导入 DS(dsList 选类型 → query/script → 文件 → checkImport → import,body 见 §B)。
|
||||
5. 导出(queryExportObject 选对象 + 模板 → export)。**export body 待确认(§D)。**
|
||||
6. 插件子菜单(model/list 列出;调用/关联逻辑待定,§D)。
|
||||
|
||||
## 捕获提交载荷的方法(已在原版页面注入录制器 window.__rec)
|
||||
在 Playwright 浏览器对原系统执行一次「编辑保存/新建保存/导入/导出」(填完必填项),
|
||||
即可从 `window.__rec` 读到真实 method+url+body。这是落地步骤 2-5 的前置。
|
||||
即可从 `window.__rec` 读到真实 method+url+body。
|
||||
注:编辑/新建/导入的 body 已由 bundle 还原(§B),此法现仅用于**验证 §B 冲突表 4 项**与**捕获导出 export body**(会改数据,谨慎)。
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ add_executable(geopro_desktop WIN32
|
|||
panels/ObjectTreePanel.cpp
|
||||
panels/DynamicFormView.cpp
|
||||
panels/DynamicFormEditor.cpp
|
||||
panels/ObjectAttrPanel.cpp
|
||||
panels/DatasetAttrPanel.cpp
|
||||
panels/ObjectExceptionPanel.cpp
|
||||
panels/DescriptionPanel.cpp
|
||||
panels/chart/RawDataChartView.cpp
|
||||
|
|
@ -55,6 +57,8 @@ add_executable(geopro_desktop WIN32
|
|||
CentralScene.cpp
|
||||
ProjectListDialog.cpp
|
||||
ObjectFormDialog.cpp
|
||||
ImportDatasetDialog.cpp
|
||||
ExportDatasetDialog.cpp
|
||||
SettingsDialog.cpp
|
||||
Logging.cpp)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
#include "ExportDatasetDialog.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Theme.hpp"
|
||||
#include "api/NavLoads.hpp"
|
||||
#include "api/NavRequest.hpp"
|
||||
#include "repo/IAsyncProjectRepository.hpp"
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
ExportDatasetDialog::ExportDatasetDialog(geopro::data::IAsyncProjectRepository& repo,
|
||||
QString dsObjectId, QString tmTypeBaseConfId,
|
||||
QWidget* parent)
|
||||
: QDialog(parent), repo_(repo), dsObjectId_(std::move(dsObjectId)),
|
||||
tmTypeBaseConfId_(std::move(tmTypeBaseConfId)) {
|
||||
setModal(true);
|
||||
setWindowTitle(QStringLiteral("导出数据集"));
|
||||
setMinimumWidth(geopro::app::scaledPx(400));
|
||||
|
||||
auto* lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kMd,
|
||||
geopro::app::space::kLg, geopro::app::space::kMd);
|
||||
lay->setSpacing(geopro::app::space::kMd);
|
||||
|
||||
auto* fl = new QFormLayout();
|
||||
templateCombo_ = new QComboBox(this);
|
||||
fl->addRow(QStringLiteral("导出模板"), templateCombo_);
|
||||
lay->addLayout(fl);
|
||||
|
||||
status_ = new QLabel(QStringLiteral("加载模板…"), this);
|
||||
geopro::app::applyTokenizedStyleSheet(status_, QStringLiteral("color:{{text/disabled}};"));
|
||||
lay->addWidget(status_);
|
||||
|
||||
auto* btnRow = new QHBoxLayout();
|
||||
btnRow->addStretch();
|
||||
auto* cancel = new QPushButton(QStringLiteral("取消"), this);
|
||||
okBtn_ = new QPushButton(QStringLiteral("导出"), this);
|
||||
okBtn_->setDefault(true);
|
||||
okBtn_->setEnabled(false);
|
||||
btnRow->addWidget(cancel);
|
||||
btnRow->addWidget(okBtn_);
|
||||
lay->addLayout(btnRow);
|
||||
|
||||
QObject::connect(cancel, &QPushButton::clicked, this, &QDialog::reject);
|
||||
QObject::connect(okBtn_, &QPushButton::clicked, this, &ExportDatasetDialog::onConfirm);
|
||||
|
||||
loadTemplates();
|
||||
}
|
||||
|
||||
ExportDatasetDialog::~ExportDatasetDialog() {
|
||||
// 析构时取消在途请求,避免回调命中已销毁的 this。
|
||||
if (tplReq_) tplReq_->abort();
|
||||
if (expReq_) expReq_->abort();
|
||||
}
|
||||
|
||||
void ExportDatasetDialog::loadTemplates() {
|
||||
if (tplReq_) tplReq_->abort();
|
||||
tplReq_ = repo_.queryExportTemplatesAsync(tmTypeBaseConfId_.toStdString());
|
||||
QObject::connect(tplReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
templates_ = qvariant_cast<std::vector<geopro::data::ExportTemplate>>(v);
|
||||
if (templates_.empty()) {
|
||||
status_->setText(QStringLiteral("无可用导出模板"));
|
||||
return;
|
||||
}
|
||||
status_->setVisible(false);
|
||||
for (const auto& t : templates_)
|
||||
templateCombo_->addItem(QString::fromStdString(t.name), QString::fromStdString(t.id));
|
||||
okBtn_->setEnabled(true);
|
||||
});
|
||||
QObject::connect(tplReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("加载模板失败:%1").arg(msg));
|
||||
});
|
||||
}
|
||||
|
||||
void ExportDatasetDialog::onConfirm() {
|
||||
const QString templateId = templateCombo_->currentData().toString();
|
||||
if (templateId.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("校验"), QStringLiteral("请选择导出模板"));
|
||||
return;
|
||||
}
|
||||
// 模板导出 body(spec §E.2):{ dsObjectIdList:[该ds], templateId }。
|
||||
QJsonObject body{{QStringLiteral("dsObjectIdList"), QJsonArray{dsObjectId_}},
|
||||
{QStringLiteral("templateId"), templateId}};
|
||||
|
||||
okBtn_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("导出中…"));
|
||||
status_->setVisible(true);
|
||||
if (expReq_) expReq_->abort();
|
||||
expReq_ = repo_.exportDatasetAsync(QJsonDocument(body).toJson(QJsonDocument::Compact).toStdString());
|
||||
QObject::connect(expReq_, &geopro::data::NavRequest::done, this, [this](const QVariant&) {
|
||||
emit exported();
|
||||
accept();
|
||||
});
|
||||
QObject::connect(expReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("导出失败:%1").arg(msg));
|
||||
okBtn_->setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
#pragma once
|
||||
#include <QDialog>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
#include "repo/RepoTypes.hpp"
|
||||
|
||||
namespace geopro::data {
|
||||
class IAsyncProjectRepository;
|
||||
class NavRequest;
|
||||
} // namespace geopro::data
|
||||
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
// 导出对话框(数据集右键「导出」):选模板 → POST templateExport/export
|
||||
// { dsObjectIdList:[该ds], templateId }(spec §E.2)。
|
||||
// 模板来源 templateExport/queryDataType/{tmTypeBaseConfId};ds 右键上下文无 tmTypeBaseConfId 时
|
||||
// 传 dsTypeBaseConfId 占位(TODO:来源待精确),无模板时下拉为空、导出按钮禁用。
|
||||
class ExportDatasetDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExportDatasetDialog(geopro::data::IAsyncProjectRepository& repo, QString dsObjectId,
|
||||
QString tmTypeBaseConfId, QWidget* parent = nullptr);
|
||||
~ExportDatasetDialog() override;
|
||||
|
||||
signals:
|
||||
void exported();
|
||||
|
||||
private:
|
||||
void loadTemplates();
|
||||
void onConfirm();
|
||||
|
||||
geopro::data::IAsyncProjectRepository& repo_;
|
||||
QString dsObjectId_;
|
||||
QString tmTypeBaseConfId_;
|
||||
std::vector<geopro::data::ExportTemplate> templates_;
|
||||
|
||||
QComboBox* templateCombo_ = nullptr;
|
||||
QLabel* status_ = nullptr;
|
||||
QPushButton* okBtn_ = nullptr;
|
||||
QPointer<geopro::data::NavRequest> tplReq_;
|
||||
QPointer<geopro::data::NavRequest> expReq_;
|
||||
};
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -0,0 +1,266 @@
|
|||
#include "ImportDatasetDialog.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QFileDialog>
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QVBoxLayout>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "Theme.hpp"
|
||||
#include "api/NavLoads.hpp"
|
||||
#include "api/NavRequest.hpp"
|
||||
#include "panels/DynamicFormEditor.hpp"
|
||||
#include "repo/IAsyncProjectRepository.hpp"
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
namespace {
|
||||
constexpr int kFormTypeScript = 6; // getDynamicForm type=6:导入脚本参数
|
||||
constexpr int kStructConfTm = 2; // structParentConfType:TM=2
|
||||
} // namespace
|
||||
|
||||
ImportDatasetDialog::ImportDatasetDialog(geopro::data::IAsyncProjectRepository& repo,
|
||||
QString projectId, QString tmObjectId, QWidget* parent)
|
||||
: QDialog(parent), repo_(repo), projectId_(std::move(projectId)),
|
||||
tmObjectId_(std::move(tmObjectId)) {
|
||||
setModal(true);
|
||||
setWindowTitle(QStringLiteral("导入数据集"));
|
||||
setMinimumSize(geopro::app::scaledPx(480), geopro::app::scaledPx(520));
|
||||
|
||||
auto* lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
|
||||
status_ = new QLabel(QStringLiteral("加载数据类型…"), this);
|
||||
status_->setAlignment(Qt::AlignCenter);
|
||||
geopro::app::applyTokenizedStyleSheet(status_,
|
||||
QStringLiteral("color:{{text/disabled}};padding:12px;"));
|
||||
lay->addWidget(status_);
|
||||
|
||||
auto* form = new QWidget(this);
|
||||
auto* fl = new QFormLayout(form);
|
||||
fl->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kMd,
|
||||
geopro::app::space::kLg, 0);
|
||||
fl->setLabelAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
fl->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
||||
|
||||
typeCombo_ = new QComboBox(form);
|
||||
fl->addRow(QStringLiteral("数据类型"), typeCombo_);
|
||||
scriptCombo_ = new QComboBox(form);
|
||||
fl->addRow(QStringLiteral("导入脚本"), scriptCombo_);
|
||||
|
||||
auto* fileRow = new QWidget(form);
|
||||
auto* fileLay = new QHBoxLayout(fileRow);
|
||||
fileLay->setContentsMargins(0, 0, 0, 0);
|
||||
fileEdit_ = new QLineEdit(fileRow);
|
||||
fileEdit_->setReadOnly(true);
|
||||
fileEdit_->setPlaceholderText(QStringLiteral("选择导入文件…"));
|
||||
auto* browse = new QPushButton(QStringLiteral("浏览…"), fileRow);
|
||||
fileLay->addWidget(fileEdit_, 1);
|
||||
fileLay->addWidget(browse);
|
||||
fl->addRow(QStringLiteral("文件"), fileRow);
|
||||
lay->addWidget(form);
|
||||
|
||||
auto* paramLabel = new QLabel(QStringLiteral("脚本参数"), this);
|
||||
geopro::app::applyTokenizedStyleSheet(
|
||||
paramLabel, QStringLiteral("color:{{text/secondary}};padding:%1px %2px 0;")
|
||||
.arg(geopro::app::space::kSm)
|
||||
.arg(geopro::app::space::kLg));
|
||||
lay->addWidget(paramLabel);
|
||||
|
||||
auto* scroll = new QScrollArea(this);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setFrameShape(QFrame::NoFrame);
|
||||
paramEditor_ = new DynamicFormEditor();
|
||||
scroll->setWidget(paramEditor_);
|
||||
lay->addWidget(scroll, 1);
|
||||
|
||||
auto* btnRow = new QHBoxLayout();
|
||||
btnRow->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kSm,
|
||||
geopro::app::space::kLg, geopro::app::space::kMd);
|
||||
btnRow->addStretch();
|
||||
auto* cancel = new QPushButton(QStringLiteral("取消"), this);
|
||||
okBtn_ = new QPushButton(QStringLiteral("导入"), this);
|
||||
okBtn_->setDefault(true);
|
||||
okBtn_->setEnabled(false);
|
||||
btnRow->addWidget(cancel);
|
||||
btnRow->addWidget(okBtn_);
|
||||
lay->addLayout(btnRow);
|
||||
|
||||
QObject::connect(cancel, &QPushButton::clicked, this, &QDialog::reject);
|
||||
QObject::connect(browse, &QPushButton::clicked, this, &ImportDatasetDialog::chooseFile);
|
||||
QObject::connect(okBtn_, &QPushButton::clicked, this, &ImportDatasetDialog::onConfirm);
|
||||
QObject::connect(typeCombo_, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
[this](int) { onTypeChanged(); });
|
||||
QObject::connect(scriptCombo_, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
[this](int) { onScriptChanged(); });
|
||||
|
||||
loadTypes();
|
||||
}
|
||||
|
||||
ImportDatasetDialog::~ImportDatasetDialog() {
|
||||
// 析构时取消在途请求,避免回调命中已销毁的 this。
|
||||
if (typeReq_) typeReq_->abort();
|
||||
if (scriptReq_) scriptReq_->abort();
|
||||
if (formReq_) formReq_->abort();
|
||||
if (checkReq_) checkReq_->abort();
|
||||
if (importReq_) importReq_->abort();
|
||||
}
|
||||
|
||||
void ImportDatasetDialog::loadTypes() {
|
||||
if (typeReq_) typeReq_->abort();
|
||||
typeReq_ = repo_.loadTmImportTypesAsync(tmObjectId_.toStdString());
|
||||
QObject::connect(typeReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
types_ = qvariant_cast<std::vector<geopro::data::DsImportType>>(v);
|
||||
if (types_.empty()) {
|
||||
status_->setText(QStringLiteral("该方法对象下无可导入的数据类型"));
|
||||
return;
|
||||
}
|
||||
status_->setVisible(false);
|
||||
for (const auto& t : types_)
|
||||
typeCombo_->addItem(QString::fromStdString(t.name),
|
||||
QString::fromStdString(t.dsTypeId));
|
||||
});
|
||||
QObject::connect(typeReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("加载数据类型失败:%1").arg(msg));
|
||||
});
|
||||
}
|
||||
|
||||
void ImportDatasetDialog::onTypeChanged() {
|
||||
scriptCombo_->clear();
|
||||
scripts_.clear();
|
||||
const int idx = typeCombo_->currentIndex();
|
||||
if (idx < 0 || idx >= static_cast<int>(types_.size())) return;
|
||||
const QString dsTypeId = typeCombo_->currentData().toString();
|
||||
if (scriptReq_) scriptReq_->abort();
|
||||
// tmTypeBaseConfId:暂用 TM 对象 id 占位(query/script 需方法基础配置 id)。TODO:来源待精确。
|
||||
scriptReq_ = repo_.queryImportScriptsAsync(dsTypeId.toStdString(), tmObjectId_.toStdString());
|
||||
QObject::connect(scriptReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
scripts_ = qvariant_cast<std::vector<geopro::data::ScriptOption>>(v);
|
||||
for (const auto& s : scripts_) {
|
||||
// itemData 同时携带 scriptId/scriptCode,取值不再依赖 scripts_ 同序索引。
|
||||
QVariantMap d{{QStringLiteral("scriptId"), QString::fromStdString(s.scriptId)},
|
||||
{QStringLiteral("scriptCode"), QString::fromStdString(s.scriptCode)}};
|
||||
scriptCombo_->addItem(QString::fromStdString(s.name), d);
|
||||
}
|
||||
if (scripts_.empty()) {
|
||||
paramEditor_->setForm({}); // 无脚本:清空参数区
|
||||
okBtn_->setEnabled(!filePath_.isEmpty());
|
||||
}
|
||||
});
|
||||
QObject::connect(scriptReq_, &geopro::data::NavRequest::failed, this, [this](const QString&) {
|
||||
// 脚本可选:失败不阻塞导入(部分类型无脚本)。
|
||||
okBtn_->setEnabled(!filePath_.isEmpty());
|
||||
});
|
||||
}
|
||||
|
||||
void ImportDatasetDialog::onScriptChanged() {
|
||||
const int idx = scriptCombo_->currentIndex();
|
||||
if (idx < 0) return;
|
||||
const QString scriptId = scriptCombo_->currentData().toMap()
|
||||
.value(QStringLiteral("scriptId")).toString();
|
||||
if (scriptId.isEmpty()) return;
|
||||
if (formReq_) formReq_->abort();
|
||||
// 脚本参数表单:getDynamicForm(typeId=scriptId, type=6)。
|
||||
formReq_ = repo_.loadEditableFormAsync(scriptId.toStdString(), std::string(), kFormTypeScript,
|
||||
projectId_.toStdString());
|
||||
QObject::connect(formReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
paramEditor_->setForm(qvariant_cast<geopro::data::EditableForm>(v));
|
||||
});
|
||||
QObject::connect(formReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
// 参数表单加载失败:清空参数区,避免脏参数随导入提交。
|
||||
paramEditor_->setForm({});
|
||||
status_->setText(QStringLiteral("加载脚本参数失败:%1").arg(msg));
|
||||
});
|
||||
}
|
||||
|
||||
void ImportDatasetDialog::chooseFile() {
|
||||
const QString p = QFileDialog::getOpenFileName(this, QStringLiteral("选择导入文件"));
|
||||
if (p.isEmpty()) return;
|
||||
filePath_ = p;
|
||||
fileEdit_->setText(p);
|
||||
okBtn_->setEnabled(true);
|
||||
}
|
||||
|
||||
void ImportDatasetDialog::onConfirm() {
|
||||
if (filePath_.isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("校验"), QStringLiteral("请选择导入文件"));
|
||||
return;
|
||||
}
|
||||
QString missing;
|
||||
if (!paramEditor_->validateRequired(&missing)) {
|
||||
QMessageBox::warning(this, QStringLiteral("校验"),
|
||||
QStringLiteral("请填写脚本参数:%1").arg(missing));
|
||||
return;
|
||||
}
|
||||
const QString dsTypeId = typeCombo_->currentData().toString();
|
||||
const QString scriptCode = scriptCombo_->currentData().toMap()
|
||||
.value(QStringLiteral("scriptCode")).toString();
|
||||
|
||||
// 脚本参数 → scriptParamListJsonStr({fieldCode: 值} 序列化)。
|
||||
// TODO:原版 scriptParamListJsonStr 确切结构未捕获,此处用 properties 形态,失败时按服务端 msg 校正。
|
||||
QJsonObject paramObj;
|
||||
const auto params = paramEditor_->collectValues();
|
||||
for (auto it = params.constBegin(); it != params.constEnd(); ++it)
|
||||
paramObj.insert(it.key(), it.value());
|
||||
const QString scriptParamJson =
|
||||
QString::fromUtf8(QJsonDocument(paramObj).toJson(QJsonDocument::Compact));
|
||||
|
||||
// import 参数走 query string(spec §B)。
|
||||
QUrlQuery q;
|
||||
q.addQueryItem(QStringLiteral("dsTypeId"), dsTypeId);
|
||||
q.addQueryItem(QStringLiteral("projectId"), projectId_);
|
||||
q.addQueryItem(QStringLiteral("structParentConfType"), QString::number(kStructConfTm));
|
||||
q.addQueryItem(QStringLiteral("structParentId"), tmObjectId_);
|
||||
if (!scriptCode.isEmpty()) q.addQueryItem(QStringLiteral("scriptCode"), scriptCode);
|
||||
if (!params.isEmpty()) q.addQueryItem(QStringLiteral("scriptParamListJsonStr"), scriptParamJson);
|
||||
const QString queryString = q.query(QUrl::FullyEncoded);
|
||||
|
||||
// 先 checkImport 校验(坐标/轨迹文件存在性等),通过后 import。
|
||||
QJsonObject checkBody{{QStringLiteral("dsTypeId"), dsTypeId},
|
||||
{QStringLiteral("projectId"), projectId_},
|
||||
{QStringLiteral("structParentConfType"), kStructConfTm},
|
||||
{QStringLiteral("structParentId"), tmObjectId_}};
|
||||
|
||||
okBtn_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("校验中…"));
|
||||
status_->setVisible(true);
|
||||
if (checkReq_) checkReq_->abort();
|
||||
checkReq_ = repo_.checkImportAsync(
|
||||
QJsonDocument(checkBody).toJson(QJsonDocument::Compact).toStdString());
|
||||
QObject::connect(checkReq_, &geopro::data::NavRequest::done, this,
|
||||
[this, queryString](const QVariant&) {
|
||||
status_->setText(QStringLiteral("导入中…"));
|
||||
if (importReq_) importReq_->abort();
|
||||
importReq_ = repo_.importDatasetAsync(queryString.toStdString(),
|
||||
filePath_.toStdString());
|
||||
QObject::connect(importReq_, &geopro::data::NavRequest::done, this,
|
||||
[this](const QVariant&) {
|
||||
emit imported();
|
||||
accept();
|
||||
});
|
||||
QObject::connect(importReq_, &geopro::data::NavRequest::failed, this,
|
||||
[this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("导入失败:%1").arg(msg));
|
||||
okBtn_->setEnabled(true);
|
||||
});
|
||||
});
|
||||
QObject::connect(checkReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("校验失败:%1").arg(msg));
|
||||
okBtn_->setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
#pragma once
|
||||
#include <QDialog>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
#include "repo/RepoTypes.hpp"
|
||||
|
||||
namespace geopro::data {
|
||||
class IAsyncProjectRepository;
|
||||
class NavRequest;
|
||||
} // namespace geopro::data
|
||||
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
class DynamicFormEditor;
|
||||
|
||||
// 导入数据集向导(TM 右键「导入DS」)。流程(spec §B / 第四节):
|
||||
// 1) 选数据类型(来源 TM getDetail.dsList,canImport=true)
|
||||
// 2) 选脚本(dsObject/query/script)→ getDynamicForm(typeId=scriptId, type=6) 取脚本参数表单
|
||||
// 3) 选文件
|
||||
// 4) POST dsObject/checkImport 校验 → POST dsObject/import(multipart)
|
||||
// 注:部分接口细节(scriptParamListJsonStr 结构、checkImport body)以源码/服务端为准;
|
||||
// 不全处做合理骨架并标注 TODO,提交体失败时回显服务端 msg。
|
||||
class ImportDatasetDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImportDatasetDialog(geopro::data::IAsyncProjectRepository& repo, QString projectId,
|
||||
QString tmObjectId, QWidget* parent = nullptr);
|
||||
~ImportDatasetDialog() override;
|
||||
|
||||
signals:
|
||||
void imported(); // 导入成功(调用方刷新数据列表)
|
||||
|
||||
private:
|
||||
void loadTypes();
|
||||
void onTypeChanged();
|
||||
void onScriptChanged();
|
||||
void chooseFile();
|
||||
void onConfirm();
|
||||
|
||||
geopro::data::IAsyncProjectRepository& repo_;
|
||||
QString projectId_;
|
||||
QString tmObjectId_;
|
||||
QString filePath_;
|
||||
std::vector<geopro::data::DsImportType> types_;
|
||||
std::vector<geopro::data::ScriptOption> scripts_;
|
||||
|
||||
QComboBox* typeCombo_ = nullptr;
|
||||
QComboBox* scriptCombo_ = nullptr;
|
||||
QLineEdit* fileEdit_ = nullptr;
|
||||
DynamicFormEditor* paramEditor_ = nullptr;
|
||||
QLabel* status_ = nullptr;
|
||||
QPushButton* okBtn_ = nullptr;
|
||||
|
||||
QPointer<geopro::data::NavRequest> typeReq_;
|
||||
QPointer<geopro::data::NavRequest> scriptReq_;
|
||||
QPointer<geopro::data::NavRequest> formReq_;
|
||||
QPointer<geopro::data::NavRequest> checkReq_;
|
||||
QPointer<geopro::data::NavRequest> importReq_;
|
||||
};
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -2,22 +2,30 @@
|
|||
|
||||
#include <utility>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QJsonDocument>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Theme.hpp"
|
||||
#include "api/NavLoads.hpp" // Q_DECLARE_METATYPE(EditableForm)
|
||||
#include "api/NavLoads.hpp" // Q_DECLARE_METATYPE(EditableForm) / GsTypeOption
|
||||
#include "api/NavRequest.hpp"
|
||||
#include "panels/DynamicFormEditor.hpp"
|
||||
#include "repo/IAsyncProjectRepository.hpp"
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
namespace {
|
||||
constexpr int kConfGs = 1;
|
||||
constexpr int kConfTm = 2;
|
||||
} // namespace
|
||||
|
||||
ObjectFormDialog::ObjectFormDialog(geopro::data::IAsyncProjectRepository& repo, QString projectId,
|
||||
QWidget* parent)
|
||||
: QDialog(parent), repo_(repo), projectId_(std::move(projectId)) {
|
||||
|
|
@ -37,8 +45,15 @@ ObjectFormDialog::ObjectFormDialog(geopro::data::IAsyncProjectRepository& repo,
|
|||
auto* scroll = new QScrollArea(this);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setFrameShape(QFrame::NoFrame);
|
||||
auto* content = new QWidget();
|
||||
auto* contentLay = new QVBoxLayout(content);
|
||||
contentLay->setContentsMargins(0, 0, 0, 0);
|
||||
contentLay->setSpacing(0);
|
||||
topBox_ = new QWidget(content); // 顶层固定字段容器(buildTopFields 重填)
|
||||
contentLay->addWidget(topBox_);
|
||||
editor_ = new DynamicFormEditor();
|
||||
scroll->setWidget(editor_);
|
||||
contentLay->addWidget(editor_, 1);
|
||||
scroll->setWidget(content);
|
||||
lay->addWidget(scroll, 1);
|
||||
|
||||
auto* btnRow = new QHBoxLayout();
|
||||
|
|
@ -58,30 +73,162 @@ ObjectFormDialog::ObjectFormDialog(geopro::data::IAsyncProjectRepository& repo,
|
|||
}
|
||||
|
||||
void ObjectFormDialog::editObject(const QString& typeId, const QString& objectId, int confType,
|
||||
const QString& displayName) {
|
||||
const QString& displayName, const QString& parentId) {
|
||||
confType_ = confType;
|
||||
objectId_ = objectId;
|
||||
typeId_ = typeId;
|
||||
parentId_ = parentId; // TM 编辑 PUT 须带真实父 GS/根 id(GS 编辑忽略)
|
||||
setWindowTitle(QStringLiteral("编辑 — %1").arg(displayName));
|
||||
load(typeId, objectId, confType, displayName);
|
||||
buildTopFields();
|
||||
nameEdit_->setText(displayName); // 编辑态:用对象名预填并禁用
|
||||
loadForm(typeId, objectId);
|
||||
}
|
||||
|
||||
void ObjectFormDialog::newObject(const QString& typeId, int confType, const QString& displayName) {
|
||||
confType_ = confType;
|
||||
void ObjectFormDialog::newGs(const QString& parentId) {
|
||||
confType_ = kConfGs;
|
||||
objectId_.clear();
|
||||
typeId_ = typeId;
|
||||
setWindowTitle(QStringLiteral("新建 %1").arg(displayName));
|
||||
load(typeId, QString(), confType, displayName);
|
||||
parentId_ = parentId;
|
||||
typeId_.clear();
|
||||
setWindowTitle(QStringLiteral("新建检测对象"));
|
||||
buildTopFields();
|
||||
loadGsTypes(); // 拉类型 → 选第一项 → 加载动态表单
|
||||
}
|
||||
|
||||
void ObjectFormDialog::load(const QString& typeId, const QString& objectId, int confType,
|
||||
const QString& titleHint) {
|
||||
(void)titleHint;
|
||||
void ObjectFormDialog::newTm(const QString& parentId) {
|
||||
confType_ = kConfTm;
|
||||
objectId_.clear();
|
||||
parentId_ = parentId;
|
||||
typeId_.clear();
|
||||
setWindowTitle(QStringLiteral("新建方法对象"));
|
||||
buildTopFields();
|
||||
loadTmTypes(); // 拉全局方法类型 → 选第一项 → 加载动态表单(type=2)
|
||||
}
|
||||
|
||||
// 顶层固定字段:按 confType 与 新建/编辑 决定。整体重建 topBox_。
|
||||
void ObjectFormDialog::buildTopFields() {
|
||||
typeCombo_ = nullptr;
|
||||
typeNameLabel_ = nullptr;
|
||||
nameEdit_ = nullptr;
|
||||
responsibleEdit_ = nullptr;
|
||||
|
||||
// 清空旧布局/控件。
|
||||
if (auto* old = topBox_->layout()) {
|
||||
QLayoutItem* it = nullptr;
|
||||
while ((it = old->takeAt(0)) != nullptr) {
|
||||
if (it->widget()) it->widget()->deleteLater();
|
||||
delete it;
|
||||
}
|
||||
delete old;
|
||||
}
|
||||
|
||||
auto* fl = new QFormLayout(topBox_);
|
||||
fl->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kMd,
|
||||
geopro::app::space::kLg, 0);
|
||||
fl->setLabelAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
fl->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
||||
fl->setHorizontalSpacing(geopro::app::space::kMd);
|
||||
fl->setVerticalSpacing(geopro::app::space::kSm);
|
||||
|
||||
const bool isCreate = objectId_.isEmpty();
|
||||
|
||||
if (isCreate) {
|
||||
// 新建 GS/TM:类型下拉(数据源 gsList / tmList,选择后重载动态表单)。
|
||||
const QString label =
|
||||
confType_ == kConfTm ? QStringLiteral("方法类型") : QStringLiteral("对象类型");
|
||||
typeCombo_ = new QComboBox(topBox_);
|
||||
fl->addRow(label, typeCombo_);
|
||||
QObject::connect(typeCombo_, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
[this](int) {
|
||||
const QString tid = typeCombo_->currentData().toString();
|
||||
if (!tid.isEmpty()) {
|
||||
typeId_ = tid;
|
||||
loadForm(tid, QString());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 编辑:类型名只读展示。
|
||||
typeNameLabel_ = new QLabel(topBox_);
|
||||
geopro::app::applyTokenizedStyleSheet(typeNameLabel_,
|
||||
QStringLiteral("color:{{text/secondary}};"));
|
||||
fl->addRow(QStringLiteral("类型"), typeNameLabel_);
|
||||
}
|
||||
|
||||
nameEdit_ = new QLineEdit(topBox_);
|
||||
nameEdit_->setPlaceholderText(QStringLiteral("名称"));
|
||||
if (!isCreate) nameEdit_->setEnabled(false); // 编辑态名称禁用
|
||||
fl->addRow(QStringLiteral("名称"), nameEdit_);
|
||||
|
||||
if (confType_ == kConfGs) {
|
||||
responsibleEdit_ = new QLineEdit(topBox_);
|
||||
responsibleEdit_->setPlaceholderText(QStringLiteral("负责人"));
|
||||
fl->addRow(QStringLiteral("负责人"), responsibleEdit_);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectFormDialog::loadGsTypes() {
|
||||
status_->setText(QStringLiteral("加载类型…"));
|
||||
status_->setVisible(true);
|
||||
okBtn_->setEnabled(false);
|
||||
if (typeReq_) typeReq_->abort();
|
||||
typeReq_ = repo_.queryGsTypesAsync(projectId_.toStdString());
|
||||
QObject::connect(typeReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
const auto types = qvariant_cast<std::vector<geopro::data::GsTypeOption>>(v);
|
||||
if (types.empty()) {
|
||||
status_->setText(QStringLiteral("无可用对象类型"));
|
||||
return;
|
||||
}
|
||||
if (typeCombo_) {
|
||||
for (const auto& t : types)
|
||||
typeCombo_->addItem(QString::fromStdString(t.name),
|
||||
QString::fromStdString(t.gsTypeId));
|
||||
// 触发 currentIndexChanged → 加载首个类型的动态表单。
|
||||
if (typeCombo_->count() > 0) {
|
||||
typeId_ = typeCombo_->itemData(0).toString();
|
||||
loadForm(typeId_, QString());
|
||||
}
|
||||
}
|
||||
});
|
||||
QObject::connect(typeReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("加载类型失败:%1").arg(msg));
|
||||
status_->setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
void ObjectFormDialog::loadTmTypes() {
|
||||
status_->setText(QStringLiteral("加载类型…"));
|
||||
status_->setVisible(true);
|
||||
okBtn_->setEnabled(false);
|
||||
if (typeReq_) typeReq_->abort();
|
||||
typeReq_ = repo_.queryTmMethodTypesAsync(projectId_.toStdString());
|
||||
QObject::connect(typeReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
const auto types = qvariant_cast<std::vector<geopro::data::TmTypeOption>>(v);
|
||||
if (types.empty()) {
|
||||
status_->setText(QStringLiteral("无可用方法类型"));
|
||||
return;
|
||||
}
|
||||
if (typeCombo_) {
|
||||
for (const auto& t : types)
|
||||
typeCombo_->addItem(QString::fromStdString(t.label),
|
||||
QString::fromStdString(t.value));
|
||||
// 触发 currentIndexChanged → 加载首个类型的动态表单(type=2)。
|
||||
if (typeCombo_->count() > 0) {
|
||||
typeId_ = typeCombo_->itemData(0).toString();
|
||||
loadForm(typeId_, QString());
|
||||
}
|
||||
}
|
||||
});
|
||||
QObject::connect(typeReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("加载类型失败:%1").arg(msg));
|
||||
status_->setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
void ObjectFormDialog::loadForm(const QString& typeId, const QString& objectId) {
|
||||
status_->setText(QStringLiteral("加载中…"));
|
||||
status_->setVisible(true);
|
||||
okBtn_->setEnabled(false);
|
||||
if (req_) req_->abort();
|
||||
req_ = repo_.loadEditableFormAsync(typeId.toStdString(), objectId.toStdString(), confType,
|
||||
req_ = repo_.loadEditableFormAsync(typeId.toStdString(), objectId.toStdString(), confType_,
|
||||
projectId_.toStdString());
|
||||
QObject::connect(req_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
const auto form = qvariant_cast<geopro::data::EditableForm>(v);
|
||||
|
|
@ -95,27 +242,46 @@ void ObjectFormDialog::load(const QString& typeId, const QString& objectId, int
|
|||
});
|
||||
}
|
||||
|
||||
// 按 spec §B 拼提交体。
|
||||
QJsonObject ObjectFormDialog::buildBody() const {
|
||||
QJsonObject props;
|
||||
const auto values = editor_->collectValues();
|
||||
for (auto it = values.constBegin(); it != values.constEnd(); ++it)
|
||||
props.insert(it.key(), it.value());
|
||||
|
||||
const bool isCreate = objectId_.isEmpty();
|
||||
QJsonObject body;
|
||||
body.insert(QStringLiteral("name"), nameEdit_ ? nameEdit_->text() : QString());
|
||||
body.insert(QStringLiteral("projectId"), projectId_);
|
||||
body.insert(QStringLiteral("properties"), props);
|
||||
if (!isCreate) body.insert(QStringLiteral("id"), objectId_);
|
||||
|
||||
if (confType_ == kConfGs) {
|
||||
body.insert(QStringLiteral("gsTypeId"), typeId_);
|
||||
body.insert(QStringLiteral("responsiblePersonName"),
|
||||
responsibleEdit_ ? responsibleEdit_->text() : QString());
|
||||
if (isCreate) body.insert(QStringLiteral("parentId"), parentId_); // GS 编辑无 parentId
|
||||
} else {
|
||||
body.insert(QStringLiteral("tmTypeId"), typeId_);
|
||||
body.insert(QStringLiteral("parentId"), parentId_); // create/edit 同一 spread
|
||||
body.insert(QStringLiteral("parentType"), QStringLiteral("1")); // 恒字符串 "1"
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
void ObjectFormDialog::onConfirm() {
|
||||
if (nameEdit_ && nameEdit_->text().trimmed().isEmpty()) {
|
||||
QMessageBox::warning(this, QStringLiteral("校验"), QStringLiteral("请填写名称"));
|
||||
return;
|
||||
}
|
||||
QString missing;
|
||||
if (!editor_->validateRequired(&missing)) {
|
||||
QMessageBox::warning(this, QStringLiteral("校验"),
|
||||
QStringLiteral("请填写必填项:%1").arg(missing));
|
||||
return;
|
||||
}
|
||||
values_ = editor_->collectValues();
|
||||
|
||||
// 拼装提交体(推断结构:identity + properties;与原版 getDynamicForm 对称)。
|
||||
// 注:保存 body 未经真实提交核实,确切字段以服务端为准——失败时把后端 msg 回显,便于校正。
|
||||
QJsonObject props;
|
||||
for (auto it = values_.constBegin(); it != values_.constEnd(); ++it)
|
||||
props.insert(it.key(), it.value());
|
||||
QJsonObject body = extraBody_; // 新建的父对象上下文(编辑为空)
|
||||
body.insert(QStringLiteral("typeId"), typeId_);
|
||||
body.insert(QStringLiteral("type"), confType_);
|
||||
body.insert(QStringLiteral("projectId"), projectId_);
|
||||
if (!objectId_.isEmpty()) body.insert(QStringLiteral("id"), objectId_);
|
||||
body.insert(QStringLiteral("properties"), props);
|
||||
|
||||
const QJsonObject body = buildBody();
|
||||
const bool isCreate = objectId_.isEmpty();
|
||||
okBtn_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("提交中…"));
|
||||
|
|
|
|||
|
|
@ -12,52 +12,68 @@ class NavRequest;
|
|||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
class DynamicFormEditor;
|
||||
|
||||
// 对象新建/编辑对话框:用 project/getDynamicForm 拉取可编辑表单 schema,由 DynamicFormEditor 渲染。
|
||||
// 编辑:editObject(typeId, objectId, confType)(带 properties 预填)。
|
||||
// 新建:newObject(typeId, confType)(空表单)。
|
||||
// 「确定」做必填校验并收集字段值(values())。提交载荷接口尚未接入:调用方据 result()==Accepted
|
||||
// 读取 values() 自行处理(当前仅用于演示引擎;保存接口待原版载荷捕获后接入)。
|
||||
// 对象新建/编辑对话框:顶层固定字段(name / GS:gsTypeId+responsiblePersonName / TM:tmTypeId) +
|
||||
// 动态字段表单(DynamicFormEditor,来源 project/getDynamicForm 的 properties)。
|
||||
// 编辑:editObject(typeId, objectId, confType)(带 properties 预填,name/type 禁用)。
|
||||
// 新建 GS:newGs(parentId)(dialog 拉 gsList 渲染 gsTypeId 下拉,切换重载动态表单)。
|
||||
// 新建 TM:newTm(parentId)(dialog 拉 tmList 渲染 tmTypeId 下拉,切换重载动态表单,与 GS 对称)。
|
||||
// 提交体字段严格按 spec §B:
|
||||
// POST gsObject {gsTypeId, parentId, projectId, name, responsiblePersonName, properties}
|
||||
// PUT gsObject {gsTypeId, id, projectId, name, responsiblePersonName, properties}
|
||||
// POST tmObject {tmTypeId, name, properties, projectId, parentId, parentType:"1"}
|
||||
// PUT tmObject {tmTypeId, id, name, properties, projectId, parentId, parentType:"1"}
|
||||
class ObjectFormDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ObjectFormDialog(geopro::data::IAsyncProjectRepository& repo, QString projectId,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
// parentId=该对象父 GS/项目根 id(TM 编辑 PUT 用;GS 编辑忽略)。
|
||||
void editObject(const QString& typeId, const QString& objectId, int confType,
|
||||
const QString& displayName);
|
||||
void newObject(const QString& typeId, int confType, const QString& displayName);
|
||||
// 新建时附加的请求体字段(如父 GS:structParentId / structParentConfType)。编辑无需。
|
||||
void setCreateExtra(const QJsonObject& extra) { extraBody_ = extra; }
|
||||
|
||||
QMap<QString, QString> values() const { return values_; }
|
||||
QString objectId() const { return objectId_; }
|
||||
int confType() const { return confType_; }
|
||||
const QString& displayName, const QString& parentId);
|
||||
// 新建 GS:拉 gsList 让用户选类型,parentId=右键所在节点(含项目根) id。
|
||||
void newGs(const QString& parentId);
|
||||
// 新建 TM:拉 tmList(全局方法类型)让用户选类型,parentId=右键所在节点(GS/项目根) id。
|
||||
void newTm(const QString& parentId);
|
||||
|
||||
signals:
|
||||
void submitted(int confType); // 提交成功(调用方据此刷新结构)
|
||||
|
||||
private:
|
||||
void load(const QString& typeId, const QString& objectId, int confType, const QString& titleHint);
|
||||
void buildTopFields(); // 按 confType / 新建·编辑 建顶层固定字段
|
||||
void loadForm(const QString& typeId, const QString& objectId); // 拉动态表单
|
||||
void loadGsTypes(); // 新建 GS:拉 gsList 填充下拉
|
||||
void loadTmTypes(); // 新建 TM:拉 tmList 填充下拉
|
||||
void onConfirm();
|
||||
QJsonObject buildBody() const; // 按 spec §B 拼提交体
|
||||
|
||||
geopro::data::IAsyncProjectRepository& repo_;
|
||||
QString projectId_;
|
||||
QString objectId_;
|
||||
QString typeId_;
|
||||
int confType_ = 0;
|
||||
QJsonObject extraBody_;
|
||||
QMap<QString, QString> values_;
|
||||
QString objectId_; // 编辑非空;新建空
|
||||
QString typeId_; // gsTypeId / tmTypeId(GS 新建时随下拉变化)
|
||||
QString parentId_; // 新建父节点 id
|
||||
int confType_ = 0; // 1=GS 2=TM
|
||||
|
||||
// 顶层固定字段控件(按 confType 创建其一)。
|
||||
QComboBox* typeCombo_ = nullptr; // GS/TM 新建:选类型(数据源 gsList / tmList)
|
||||
QLabel* typeNameLabel_ = nullptr; // 编辑:类型名只读展示
|
||||
QLineEdit* nameEdit_ = nullptr; // name(编辑禁用)
|
||||
QLineEdit* responsibleEdit_ = nullptr; // GS:responsiblePersonName
|
||||
|
||||
DynamicFormEditor* editor_ = nullptr;
|
||||
QWidget* topBox_ = nullptr; // 顶层字段容器(重建时整体替换)
|
||||
QLabel* status_ = nullptr;
|
||||
QPushButton* okBtn_ = nullptr;
|
||||
QPointer<geopro::data::NavRequest> req_;
|
||||
QPointer<geopro::data::NavRequest> subReq_;
|
||||
QPointer<geopro::data::NavRequest> typeReq_; // gsList / tmList 拉取(新建 GS/TM 共用)
|
||||
};
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
|
|||
233
src/app/main.cpp
233
src/app/main.cpp
|
|
@ -41,7 +41,6 @@
|
|||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QListWidgetItem>
|
||||
#include <QInputDialog>
|
||||
#include <QJsonObject>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
|
@ -92,6 +91,7 @@
|
|||
#include "CentralScene.hpp"
|
||||
#include "ProjectListDialog.hpp"
|
||||
#include "ObjectFormDialog.hpp"
|
||||
#include "ImportDatasetDialog.hpp"
|
||||
#include "WorkbenchNavController.hpp"
|
||||
#include "api/NavRequest.hpp"
|
||||
#include "api/NavLoads.hpp"
|
||||
|
|
@ -108,6 +108,8 @@
|
|||
#include "panels/DatasetListPanel.hpp"
|
||||
#include "panels/DatasetDetailPanel.hpp"
|
||||
#include "panels/DynamicFormView.hpp"
|
||||
#include "panels/ObjectAttrPanel.hpp"
|
||||
#include "panels/DatasetAttrPanel.hpp"
|
||||
#include "panels/ObjectExceptionPanel.hpp"
|
||||
|
||||
#include "CameraPreset.hpp"
|
||||
|
|
@ -460,7 +462,7 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
|
||||
// 右上 dock:异常列表 / 对象属性 合并为带 Tab 表头的面板(对齐原型上半)。
|
||||
auto* exceptionPanel = new geopro::app::ObjectExceptionPanel();
|
||||
auto* objAttrView = new geopro::app::DynamicFormView();
|
||||
auto* objAttrView = new geopro::app::ObjectAttrPanel(projectRepo);
|
||||
|
||||
auto anomalyPanel = geopro::app::buildTabbedPanel(
|
||||
{{geopro::app::Glyph::Anomaly, QStringLiteral("对象异常"), exceptionPanel, true},
|
||||
|
|
@ -481,8 +483,8 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
rightDock->setWidget(anomalyPanel.container);
|
||||
auto* rightArea = dockManager->addDockWidget(ads::RightDockWidgetArea, rightDock);
|
||||
|
||||
// 右下 dock:属性(数据集属性,键值;对齐原型下半,独立面板)。
|
||||
auto* propView = new geopro::app::DynamicFormView();
|
||||
// 右下 dock:属性(数据集属性,上半只读元字段 + 下半可编辑描述)。
|
||||
auto* propView = new geopro::app::DatasetAttrPanel(projectRepo);
|
||||
auto* propDock = new ads::CDockWidget(QStringLiteral("数据集属性"));
|
||||
propDock->setWidget(
|
||||
wrapWithHeader(geopro::app::Glyph::Property, QStringLiteral("数据集属性"), propView));
|
||||
|
|
@ -511,14 +513,15 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
|
||||
// ── 单击左下数据列表的采集批次(DS) → 属性表单 + 聚焦详情已开页 ──
|
||||
QObject::connect(datasetList, &QTreeWidget::itemClicked, datasetList,
|
||||
[&nav, &detailCtrl](QTreeWidgetItem* item, int) {
|
||||
[&nav, &detailCtrl, propView](QTreeWidgetItem* item, int) {
|
||||
if (item->data(0, geopro::app::kDsLoadMoreRole).toBool()) {
|
||||
nav.loadMoreData();
|
||||
return;
|
||||
}
|
||||
const QString dsId = item->data(0, geopro::app::kDsIdRole).toString();
|
||||
if (dsId.isEmpty()) return;
|
||||
nav.selectDataset(dsId); // 属性表单(现状)
|
||||
nav.selectDataset(dsId); // 只读元字段表单(datasetDetailLoaded)
|
||||
propView->selectDataset(dsId); // 可编辑描述:回填 + 启用保存
|
||||
detailCtrl.focusDataset(dsId); // 单击=聚焦已开页
|
||||
});
|
||||
|
||||
|
|
@ -703,6 +706,26 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
&geopro::controller::WorkbenchNavController::selectObject);
|
||||
QObject::connect(objectTree, &geopro::app::ObjectTreePanel::checkedTmsChanged, &nav,
|
||||
&geopro::controller::WorkbenchNavController::setCheckedTms);
|
||||
// 单击对象 → 对象属性面板渲染可编辑表单(projectId 取当前项目;项目根只读占位)。
|
||||
QObject::connect(objectTree, &geopro::app::ObjectTreePanel::objectSelectedForEdit, objAttrView,
|
||||
[objAttrView, objectTree, &nav](const QString& id, int confType,
|
||||
const QString& typeId, const QString& name,
|
||||
bool isRoot) {
|
||||
objAttrView->loadObject(nav.currentProjectId(), typeId, id, confType, name,
|
||||
isRoot, objectTree->parentObjectId(id));
|
||||
});
|
||||
|
||||
// 当前选中的 TM id(confType==2 时记录,其它选中清空):数据集面板「上传」按钮据此定父对象。
|
||||
auto currentTmId = std::make_shared<QString>();
|
||||
QObject::connect(objectTree, &geopro::app::ObjectTreePanel::objectClicked, &window,
|
||||
[currentTmId](const QString& objectId, int confType) {
|
||||
*currentTmId = (confType == 2) ? objectId : QString();
|
||||
});
|
||||
// 切项目/重建结构 → 旧选中 TM 失效,清空(避免「上传」按钮误用跨项目的 TM)。
|
||||
QObject::connect(&nav, &geopro::controller::WorkbenchNavController::structureLoaded, &window,
|
||||
[currentTmId](const QString&, const std::vector<geopro::data::StructNode>&) {
|
||||
currentTmId->clear();
|
||||
});
|
||||
|
||||
// ── 交互操作接线(对象/数据集视图:右键菜单 + 快速筛选 + 增删,2D/3D 相关占位)────────
|
||||
auto* anomalyTabGroup = anomalyPanel.tabGroup; // 捕指针(anomalyPanel 为局部,勿按引用捕获)
|
||||
|
|
@ -719,11 +742,14 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
// 对象树右键菜单动作路由。
|
||||
QObject::connect(
|
||||
objectTree, &geopro::app::ObjectTreePanel::contextActionRequested, &window,
|
||||
[&nav, &projectRepo, &window, anomalyTabGroup, toast](
|
||||
[&nav, &projectRepo, &window, anomalyTabGroup, toast, objAttrView, objectTree](
|
||||
const QString& action, const QString& id, int confType, const QString& typeId,
|
||||
const QString& name) {
|
||||
if (action == QStringLiteral("properties")) {
|
||||
nav.selectObject(id, confType);
|
||||
// 右键「属性」:用可编辑面板渲染(与左键单击同口径)。
|
||||
objAttrView->loadObject(nav.currentProjectId(), typeId, id, confType, name, false,
|
||||
objectTree->parentObjectId(id));
|
||||
if (anomalyTabGroup)
|
||||
if (auto* b = anomalyTabGroup->button(1)) b->click(); // 切到「对象属性」页签
|
||||
} else if (action == QStringLiteral("exceptionDetail")) {
|
||||
|
|
@ -742,7 +768,7 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
auto* dlg = new geopro::app::ObjectFormDialog(projectRepo, nav.currentProjectId(),
|
||||
&window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->editObject(typeId, id, confType, name);
|
||||
dlg->editObject(typeId, id, confType, name, objectTree->parentObjectId(id));
|
||||
QObject::connect(dlg, &geopro::app::ObjectFormDialog::submitted, &window,
|
||||
[&nav, toast](int) {
|
||||
toast(QStringLiteral("保存成功"));
|
||||
|
|
@ -750,57 +776,61 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
});
|
||||
dlg->open();
|
||||
} else if (action == QStringLiteral("newTm")) {
|
||||
// 新建 TM:先查该 GS 下可建的方法类型 → 选型 → 空表单 → 提交(POST,带父 GS 上下文)。
|
||||
auto* req = projectRepo.queryTmTypesAsync(nav.currentProjectId().toStdString(),
|
||||
id.toStdString());
|
||||
QObject::connect(
|
||||
req, &geopro::data::NavRequest::done, &window,
|
||||
[&projectRepo, &nav, &window, toast, id, name](const QVariant& v) {
|
||||
const auto types =
|
||||
qvariant_cast<std::vector<geopro::data::TmTypeOption>>(v);
|
||||
if (types.empty()) {
|
||||
toast(QStringLiteral("「%1」下无可新建的方法类型").arg(name));
|
||||
return;
|
||||
}
|
||||
QString chosenId, chosenLabel;
|
||||
if (types.size() == 1) {
|
||||
chosenId = QString::fromStdString(types[0].value);
|
||||
chosenLabel = QString::fromStdString(types[0].label);
|
||||
} else {
|
||||
QStringList labels;
|
||||
for (const auto& t : types) labels << QString::fromStdString(t.label);
|
||||
bool ok = false;
|
||||
const QString pick = QInputDialog::getItem(
|
||||
&window, QStringLiteral("新建 TM"), QStringLiteral("选择方法类型:"),
|
||||
labels, 0, false, &ok);
|
||||
if (!ok) return;
|
||||
chosenId = QString::fromStdString(types[labels.indexOf(pick)].value);
|
||||
chosenLabel = pick;
|
||||
}
|
||||
auto* dlg = new geopro::app::ObjectFormDialog(
|
||||
projectRepo, nav.currentProjectId(), &window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->setCreateExtra(QJsonObject{{QStringLiteral("structParentId"), id},
|
||||
{QStringLiteral("structParentConfType"), 1}});
|
||||
dlg->newObject(chosenId, 2, chosenLabel);
|
||||
QObject::connect(dlg, &geopro::app::ObjectFormDialog::submitted, &window,
|
||||
[&nav, toast](int) {
|
||||
toast(QStringLiteral("新建成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
dlg->open();
|
||||
});
|
||||
QObject::connect(req, &geopro::data::NavRequest::failed, &window,
|
||||
[toast](const QString& msg) {
|
||||
toast(QStringLiteral("加载方法类型失败:%1").arg(msg));
|
||||
// 新建 TM:对话框拉 tmList(全局方法类型)选类型 → getDynamicForm(type=2) → POST /tmObject。
|
||||
// 父对象:在 GS/项目根上=该节点;在 TM 上=其父 GS/根(即新建同级 TM)。
|
||||
const QString tmParent =
|
||||
(confType == 2) ? objectTree->parentObjectId(id) : id;
|
||||
auto* dlg = new geopro::app::ObjectFormDialog(projectRepo, nav.currentProjectId(),
|
||||
&window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->newTm(tmParent);
|
||||
QObject::connect(dlg, &geopro::app::ObjectFormDialog::submitted, &window,
|
||||
[&nav, toast](int) {
|
||||
toast(QStringLiteral("新建成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
dlg->open();
|
||||
} else if (action == QStringLiteral("newGs")) {
|
||||
// 新建 GS:对话框拉 gsList 选类型 → getDynamicForm(type=1) → POST /gsObject。
|
||||
// 父对象 = 右键所在节点(GS/项目根) id。
|
||||
auto* dlg = new geopro::app::ObjectFormDialog(projectRepo, nav.currentProjectId(),
|
||||
&window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->newGs(id);
|
||||
QObject::connect(dlg, &geopro::app::ObjectFormDialog::submitted, &window,
|
||||
[&nav, toast](int) {
|
||||
toast(QStringLiteral("新建成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
dlg->open();
|
||||
} else if (action == QStringLiteral("importDs")) {
|
||||
// 导入 DS:TM 右键 → 选数据类型/脚本/文件 → checkImport → import(multipart)。
|
||||
auto* dlg = new geopro::app::ImportDatasetDialog(projectRepo, nav.currentProjectId(),
|
||||
id, &window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QObject::connect(dlg, &geopro::app::ImportDatasetDialog::imported, &window,
|
||||
[&nav, toast]() {
|
||||
toast(QStringLiteral("导入成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
dlg->open();
|
||||
} else if (action == QStringLiteral("showHide") || action == QStringLiteral("locate")) {
|
||||
toast(QStringLiteral("「%1」需要二维/三维视图,开发中").arg(name));
|
||||
} else { // newGs(GS 类型来源待研究)/ importDs(导入向导待接入)
|
||||
} else {
|
||||
toast(QStringLiteral("该功能开发中,即将接入"));
|
||||
}
|
||||
});
|
||||
|
||||
// 对象属性面板保存成功 → toast + 刷新结构(重载当前项目,回填最新属性)。
|
||||
QObject::connect(objAttrView, &geopro::app::ObjectAttrPanel::saved, &window,
|
||||
[&nav, toast]() {
|
||||
toast(QStringLiteral("保存成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
// 数据集属性面板描述保存成功 → toast。
|
||||
QObject::connect(propView, &geopro::app::DatasetAttrPanel::saved, &window,
|
||||
[toast]() { toast(QStringLiteral("描述已保存")); });
|
||||
|
||||
// 增删改结果 → 状态栏反馈(成功后控制器已自行刷新)。
|
||||
QObject::connect(&nav, &geopro::controller::WorkbenchNavController::mutationSucceeded, &window,
|
||||
[toast](const QString& msg) { toast(msg); });
|
||||
|
|
@ -828,11 +858,41 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
m.exec(objFilterBtn->mapToGlobal(QPoint(0, objFilterBtn->height())));
|
||||
});
|
||||
}
|
||||
// 对象树表头「新建对象」按钮 → 占位(对话框待 Batch2)。
|
||||
// 对象树表头「新建对象」按钮 → 小菜单(新建检测对象/新建方法对象,复用右键 newGs/newTm 流程)。
|
||||
// 父对象 = 当前选中节点;未选中则取项目根(由 ObjectTreePanel::currentParentForNew 决定)。
|
||||
if (auto* objAddBtn = findHeaderAction(objectBox, geopro::app::Glyph::Plus)) {
|
||||
objAddBtn->setToolTip(QStringLiteral("新建对象"));
|
||||
QObject::connect(objAddBtn, &QToolButton::clicked, &window,
|
||||
[toast]() { toast(QStringLiteral("新建对象功能开发中,即将接入")); });
|
||||
QObject::connect(
|
||||
objAddBtn, &QToolButton::clicked, objectTree,
|
||||
[objAddBtn, objectTree, &projectRepo, &nav, &window, toast]() {
|
||||
const QString parentId = objectTree->currentParentForNew();
|
||||
if (parentId.isEmpty()) {
|
||||
toast(QStringLiteral("请先选择项目"));
|
||||
return;
|
||||
}
|
||||
// 与右键 newGs/newTm 完全一致的对话框流程(文案统一:新建检测对象/新建方法对象)。
|
||||
auto openForm = [&projectRepo, &nav, &window, toast, parentId](bool gs) {
|
||||
auto* dlg = new geopro::app::ObjectFormDialog(projectRepo, nav.currentProjectId(),
|
||||
&window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
if (gs) dlg->newGs(parentId); else dlg->newTm(parentId);
|
||||
QObject::connect(dlg, &geopro::app::ObjectFormDialog::submitted, &window,
|
||||
[&nav, toast](int) {
|
||||
toast(QStringLiteral("新建成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
dlg->open();
|
||||
};
|
||||
// 按选中类型决定菜单项:选 项目根/GS → 新建GS+TM;选 TM → 仅新建TM(同级)。
|
||||
// 父对象由 currentParentForNew() 统一给出(TM→父GS、GS/根→自身、未选→根),三种情况均正确。
|
||||
QMenu m(objectTree);
|
||||
if (objectTree->currentSelectedConfType() != 2) // 非 TM:可新建检测对象(GS)
|
||||
m.addAction(QStringLiteral("新建检测对象"), objectTree,
|
||||
[openForm]() { openForm(true); });
|
||||
m.addAction(QStringLiteral("新建方法对象"), objectTree,
|
||||
[openForm]() { openForm(false); });
|
||||
m.exec(objAddBtn->mapToGlobal(QPoint(0, objAddBtn->height())));
|
||||
});
|
||||
}
|
||||
|
||||
// 模型/插件目录:全局一次性拉取并缓存,供数据集右键「插件」子菜单同步填充。
|
||||
|
|
@ -849,7 +909,8 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
datasetList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(
|
||||
datasetList, &QWidget::customContextMenuRequested, datasetList,
|
||||
[datasetList, &detailCtrl, &nav, &window, toast, modelsCache](const QPoint& pos) {
|
||||
[datasetList, &detailCtrl, &nav, &projectRepo, &window, toast, modelsCache, propView](
|
||||
const QPoint& pos) {
|
||||
QTreeWidgetItem* item = datasetList->itemAt(pos);
|
||||
if (!item || item->data(0, geopro::app::kDsLoadMoreRole).toBool()) return;
|
||||
const QString dsId = item->data(0, geopro::app::kDsIdRole).toString();
|
||||
|
|
@ -861,8 +922,10 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
[&detailCtrl, dsId, ddCode, dsName]() {
|
||||
detailCtrl.openDataset(dsId, ddCode, dsName);
|
||||
});
|
||||
menu.addAction(QStringLiteral("属性"), datasetList,
|
||||
[&nav, dsId]() { nav.selectDataset(dsId); });
|
||||
menu.addAction(QStringLiteral("属性"), datasetList, [&nav, propView, dsId]() {
|
||||
nav.selectDataset(dsId); // 只读元字段
|
||||
propView->selectDataset(dsId); // 可编辑描述
|
||||
});
|
||||
menu.addSeparator();
|
||||
QMenu* plugins = menu.addMenu(QStringLiteral("插件"));
|
||||
if (modelsCache->empty()) {
|
||||
|
|
@ -875,8 +938,11 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
});
|
||||
}
|
||||
}
|
||||
menu.addAction(QStringLiteral("导出…"), datasetList,
|
||||
[toast]() { toast(QStringLiteral("导出功能开发中,即将接入")); });
|
||||
menu.addAction(QStringLiteral("导出…"), datasetList, [toast]() {
|
||||
// ds 右键上下文拿不到 tmTypeBaseConfId,空配置打开会直接「加载模板失败」。
|
||||
// 暂不开对话框,提示改用批量导出(ExportDatasetDialog 保留供有 confId 场景调用)。
|
||||
toast(QStringLiteral("从此处导出暂不可用(缺方法配置),请从批量导出使用"));
|
||||
});
|
||||
menu.addSeparator();
|
||||
menu.addAction(QStringLiteral("删除"), datasetList, [&nav, &window, dsId, dsName]() {
|
||||
const auto r = QMessageBox::question(
|
||||
|
|
@ -939,18 +1005,47 @@ void buildWorkbench(QMainWindow& window, geopro::data::LocalSampleRepository& re
|
|||
m.exec(dsFilterBtn->mapToGlobal(QPoint(0, dsFilterBtn->height())));
|
||||
});
|
||||
}
|
||||
// 数据集表头「上传」按钮 → 占位(导入向导待 Batch2)。
|
||||
// 数据集表头「上传」按钮 → 导入数据集(复用 ImportDatasetDialog,父对象=当前选中 TM)。
|
||||
// 未选中 TM 时按钮禁用并提示先选方法对象(随选中变化动态启停)。
|
||||
if (auto* dsUploadBtn = findHeaderAction(datasetBox, geopro::app::Glyph::Upload)) {
|
||||
dsUploadBtn->setToolTip(QStringLiteral("导入数据集"));
|
||||
QObject::connect(dsUploadBtn, &QToolButton::clicked, &window,
|
||||
[toast]() { toast(QStringLiteral("导入数据集功能开发中,即将接入")); });
|
||||
dsUploadBtn->setToolTip(QStringLiteral("导入数据集(需先选方法对象)"));
|
||||
auto syncUploadEnabled = [dsUploadBtn, currentTmId]() {
|
||||
const bool hasTm = !currentTmId->isEmpty();
|
||||
dsUploadBtn->setEnabled(hasTm);
|
||||
dsUploadBtn->setToolTip(hasTm ? QStringLiteral("导入数据集…")
|
||||
: QStringLiteral("导入数据集(需先选方法对象)"));
|
||||
};
|
||||
syncUploadEnabled(); // 初始:未选 TM → 禁用
|
||||
QObject::connect(objectTree, &geopro::app::ObjectTreePanel::objectClicked, dsUploadBtn,
|
||||
[syncUploadEnabled](const QString&, int) { syncUploadEnabled(); });
|
||||
QObject::connect(&nav, &geopro::controller::WorkbenchNavController::structureLoaded,
|
||||
dsUploadBtn,
|
||||
[syncUploadEnabled](const QString&,
|
||||
const std::vector<geopro::data::StructNode>&) {
|
||||
syncUploadEnabled();
|
||||
});
|
||||
QObject::connect(
|
||||
dsUploadBtn, &QToolButton::clicked, &window,
|
||||
[currentTmId, &projectRepo, &nav, &window, toast]() {
|
||||
if (currentTmId->isEmpty()) {
|
||||
toast(QStringLiteral("请先选择方法对象(TM)再导入数据集"));
|
||||
return;
|
||||
}
|
||||
auto* dlg = new geopro::app::ImportDatasetDialog(
|
||||
projectRepo, nav.currentProjectId(), *currentTmId, &window);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
QObject::connect(dlg, &geopro::app::ImportDatasetDialog::imported, &window,
|
||||
[&nav, toast]() {
|
||||
toast(QStringLiteral("导入成功"));
|
||||
nav.switchProject(nav.currentProjectId());
|
||||
});
|
||||
dlg->open();
|
||||
});
|
||||
}
|
||||
|
||||
// 控制器详情/异常/数据集表单 → 三个被动面板。
|
||||
QObject::connect(&nav, &geopro::controller::WorkbenchNavController::objectDetailLoaded, objAttrView,
|
||||
[objAttrView](const QString&, const geopro::data::DynamicForm& form) {
|
||||
objAttrView->setForm(form);
|
||||
});
|
||||
// 控制器异常/数据集表单 → 被动面板。
|
||||
// 对象属性改为可编辑面板:由 ObjectTreePanel::objectSelectedForEdit 直接驱动(见下),
|
||||
// 不再消费只读的 objectDetailLoaded。
|
||||
QObject::connect(&nav, &geopro::controller::WorkbenchNavController::exceptionTreeLoaded,
|
||||
exceptionPanel,
|
||||
[exceptionPanel, anomalyBadge](
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
#include "panels/DatasetAttrPanel.hpp"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Theme.hpp"
|
||||
#include "api/NavRequest.hpp"
|
||||
#include "panels/DynamicFormView.hpp"
|
||||
#include "repo/IAsyncProjectRepository.hpp"
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
DatasetAttrPanel::DatasetAttrPanel(geopro::data::IAsyncProjectRepository& repo, QWidget* parent)
|
||||
: QWidget(parent), repo_(repo) {
|
||||
auto* lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
|
||||
// 上半:只读元字段(复用 DynamicFormView)。
|
||||
metaView_ = new DynamicFormView(this);
|
||||
metaView_->showMessage(QStringLiteral("(单击数据集查看属性)"));
|
||||
lay->addWidget(metaView_, 1);
|
||||
|
||||
// 下半:可编辑描述区。
|
||||
auto* descBox = new QWidget(this);
|
||||
auto* descLay = new QVBoxLayout(descBox);
|
||||
descLay->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kSm,
|
||||
geopro::app::space::kLg, geopro::app::space::kMd);
|
||||
descLay->setSpacing(geopro::app::space::kXs);
|
||||
|
||||
auto* hint = new QLabel(QStringLiteral("描述(备注)"), descBox);
|
||||
geopro::app::applyTokenizedStyleSheet(hint, QStringLiteral("color:{{text/secondary}};"));
|
||||
descLay->addWidget(hint);
|
||||
|
||||
descEdit_ = new QTextEdit(descBox);
|
||||
descEdit_->setAcceptRichText(false); // 纯文本(与服务端 delta 纯文本往返一致)
|
||||
descEdit_->setEnabled(false);
|
||||
descEdit_->setMaximumHeight(geopro::app::scaledPx(120));
|
||||
descLay->addWidget(descEdit_);
|
||||
|
||||
auto* btnRow = new QHBoxLayout();
|
||||
status_ = new QLabel(QString(), descBox);
|
||||
geopro::app::applyTokenizedStyleSheet(status_, QStringLiteral("color:{{text/disabled}};"));
|
||||
btnRow->addWidget(status_, 1);
|
||||
saveBtn_ = new QPushButton(QStringLiteral("保存"), descBox);
|
||||
saveBtn_->setEnabled(false);
|
||||
btnRow->addWidget(saveBtn_);
|
||||
descLay->addLayout(btnRow);
|
||||
|
||||
lay->addWidget(descBox);
|
||||
|
||||
QObject::connect(saveBtn_, &QPushButton::clicked, this, &DatasetAttrPanel::onSave);
|
||||
}
|
||||
|
||||
void DatasetAttrPanel::setForm(const geopro::data::DynamicForm& form) {
|
||||
metaView_->setForm(form);
|
||||
}
|
||||
|
||||
void DatasetAttrPanel::showMessage(const QString& message) {
|
||||
dsObjectId_.clear();
|
||||
metaView_->showMessage(message);
|
||||
descEdit_->clear();
|
||||
descEdit_->setEnabled(false);
|
||||
saveBtn_->setEnabled(false);
|
||||
status_->clear();
|
||||
}
|
||||
|
||||
void DatasetAttrPanel::selectDataset(const QString& dsObjectId) {
|
||||
// 切换数据集:中止在途保存,避免旧 save 回调串台触发 saved()/启用按钮。
|
||||
if (saveReq_) saveReq_->abort();
|
||||
dsObjectId_ = dsObjectId;
|
||||
descEdit_->setEnabled(false);
|
||||
saveBtn_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("加载描述…"));
|
||||
|
||||
if (loadReq_) loadReq_->abort();
|
||||
loadReq_ = repo_.loadDatasetDetailAsync(dsObjectId.toStdString());
|
||||
QObject::connect(loadReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
descEdit_->setPlainText(v.toString()); // payload=QString(现有描述纯文本)
|
||||
descEdit_->setEnabled(true);
|
||||
saveBtn_->setEnabled(true);
|
||||
status_->clear();
|
||||
});
|
||||
QObject::connect(loadReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
// 加载失败仍允许编辑/保存(视为新建描述),仅提示。
|
||||
descEdit_->setEnabled(true);
|
||||
saveBtn_->setEnabled(true);
|
||||
status_->setText(QStringLiteral("加载描述失败:%1(可直接编辑保存)").arg(msg));
|
||||
});
|
||||
}
|
||||
|
||||
void DatasetAttrPanel::onSave() {
|
||||
if (dsObjectId_.isEmpty()) return;
|
||||
const QString text = descEdit_->toPlainText();
|
||||
// 最小 Quill delta:[{ insert: <文本 + "\n"> }],承载纯文本与服务端往返。
|
||||
const QJsonArray deltaOps{QJsonObject{{QStringLiteral("insert"), text + QStringLiteral("\n")}}};
|
||||
const QJsonObject body{
|
||||
{QStringLiteral("dsObjectId"), dsObjectId_},
|
||||
{QStringLiteral("description"), text},
|
||||
{QStringLiteral("attachedParameters"),
|
||||
QJsonObject{{QStringLiteral("deltaContent"), deltaOps}}}};
|
||||
|
||||
saveBtn_->setEnabled(false);
|
||||
descEdit_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("保存中…"));
|
||||
if (saveReq_) saveReq_->abort();
|
||||
saveReq_ =
|
||||
repo_.updateDatasetAsync(QJsonDocument(body).toJson(QJsonDocument::Compact).toStdString());
|
||||
QObject::connect(saveReq_, &geopro::data::NavRequest::done, this, [this](const QVariant&) {
|
||||
descEdit_->setEnabled(true);
|
||||
saveBtn_->setEnabled(true);
|
||||
status_->clear();
|
||||
emit saved();
|
||||
});
|
||||
QObject::connect(saveReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("保存失败:%1").arg(msg));
|
||||
descEdit_->setEnabled(true);
|
||||
saveBtn_->setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
#include "repo/RepoTypes.hpp"
|
||||
|
||||
namespace geopro::data {
|
||||
class IAsyncProjectRepository;
|
||||
class NavRequest;
|
||||
} // namespace geopro::data
|
||||
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QTextEdit;
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
class DynamicFormView;
|
||||
|
||||
// 数据集属性面板(右下「数据集属性」):上半只读元字段(DynamicForm)+ 下半可编辑描述 + 保存。
|
||||
// 元字段无写接口,仅展示(datasetDetailLoaded 推送的 DynamicForm)。
|
||||
// 描述可写:PUT dsObject/updateDsObject/ body
|
||||
// { dsObjectId, description:<纯文本>, attachedParameters:{ deltaContent:[{ insert:<文本+"\n"> }] } }
|
||||
// 描述文本经 loadDatasetDetailAsync(GET getDetail) 回填(payload=QString)。
|
||||
class DatasetAttrPanel : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DatasetAttrPanel(geopro::data::IAsyncProjectRepository& repo, QWidget* parent = nullptr);
|
||||
|
||||
void setForm(const geopro::data::DynamicForm& form); // 元字段只读展示
|
||||
void showMessage(const QString& message); // 空/占位
|
||||
void selectDataset(const QString& dsObjectId); // 选中 → 回填描述、启用保存
|
||||
|
||||
signals:
|
||||
void saved(); // 描述保存成功
|
||||
|
||||
private:
|
||||
void onSave();
|
||||
|
||||
geopro::data::IAsyncProjectRepository& repo_;
|
||||
QString dsObjectId_;
|
||||
|
||||
DynamicFormView* metaView_ = nullptr;
|
||||
QTextEdit* descEdit_ = nullptr;
|
||||
QLabel* status_ = nullptr;
|
||||
QPushButton* saveBtn_ = nullptr;
|
||||
QPointer<geopro::data::NavRequest> loadReq_;
|
||||
QPointer<geopro::data::NavRequest> saveReq_;
|
||||
};
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#include "panels/DynamicFormEditor.hpp"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDate>
|
||||
#include <QDateEdit>
|
||||
|
|
@ -11,6 +12,8 @@
|
|||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QTimeEdit>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Theme.hpp"
|
||||
|
|
@ -21,37 +24,82 @@ namespace {
|
|||
// fieldDataType:2=整数 3=浮点 4=字符串 5=日期 6=日期时间 8=枚举 10=设备 11=人员。
|
||||
constexpr int kDtInt = 2;
|
||||
constexpr int kDtFloat = 3;
|
||||
// displayComponentType。
|
||||
constexpr int kCompText = 1;
|
||||
constexpr int kCompSelect = 4;
|
||||
constexpr int kCompDate = 6;
|
||||
constexpr int kCompDateTime = 7;
|
||||
constexpr int kCompMultiline = 8;
|
||||
|
||||
// 必填字段标签:名称 + 红色 *。
|
||||
// displayComponentType(全集,来源 spec §E.1,权威)。
|
||||
constexpr int kCompText = 1; // 单行文本
|
||||
constexpr int kCompTextDisabled = 2; // 单行文本(只读禁用)
|
||||
constexpr int kCompCheckbox = 3; // 复选框
|
||||
constexpr int kCompSelect = 4; // 下拉
|
||||
constexpr int kCompText2 = 5; // 单行文本(同 1)
|
||||
constexpr int kCompDate = 6; // 日期
|
||||
constexpr int kCompTime = 7; // 时间
|
||||
constexpr int kCompDateTime = 8; // 日期时间 YYYY-MM-DD HH:mm:ss
|
||||
constexpr int kCompMultiline = 9; // 多行文本
|
||||
constexpr int kCompNumber = 10; // 数字
|
||||
constexpr int kCompTreeSelect = 11; // 树选择(无现成控件,用 QComboBox 兜底)
|
||||
// 其余 = 步进数字(QSpinBox/QDoubleSpinBox)。
|
||||
|
||||
// requiredType:1=必填可编辑;2=只读禁用;其他=可选可编辑(spec §E.1)。
|
||||
constexpr int kRequiredYes = 1;
|
||||
constexpr int kRequiredReadonly = 2;
|
||||
|
||||
bool isReadonly(const data::EditField& f) {
|
||||
// requiredType==2 只读;或 comp==2 只读文本;fromProps 的核心测量值通常也不可改(核心字段)。
|
||||
return f.required == kRequiredReadonly || f.comp == kCompTextDisabled ||
|
||||
(f.useType == 1 && f.fromProps);
|
||||
}
|
||||
|
||||
// 必填字段标签:名称 + 红色 *(仅 requiredType==1)。
|
||||
QString labelText(const data::EditField& f) {
|
||||
QString t = QString::fromStdString(f.name);
|
||||
if (f.required == 1)
|
||||
if (f.required == kRequiredYes)
|
||||
t += QStringLiteral(" <span style='color:%1'>*</span>")
|
||||
.arg(QString::fromUtf8(geopro::app::semantic::kDanger));
|
||||
return t;
|
||||
}
|
||||
|
||||
// 把 optionsObject 顶层平铺为 (label,value) 对。childList 暂未递归;comp11 树选择用
|
||||
// QComboBox 兜底降级(见 buildWidget),故仅平铺顶层项。
|
||||
void flattenOptions(const std::vector<data::EditFieldOption>& opts, QComboBox* cb) {
|
||||
for (const auto& o : opts)
|
||||
cb->addItem(QString::fromStdString(o.label), QString::fromStdString(o.value));
|
||||
}
|
||||
|
||||
// 给整数输入框装 QIntValidator,并按 limitMin/limitMax(可空)设上下界。
|
||||
void applyIntRange(QLineEdit* le, const data::EditField& f) {
|
||||
auto* v = new QIntValidator(le);
|
||||
bool ok1 = false, ok2 = false;
|
||||
const int lo = QString::fromStdString(f.limitMin).toInt(&ok1);
|
||||
const int hi = QString::fromStdString(f.limitMax).toInt(&ok2);
|
||||
if (ok1) v->setBottom(lo);
|
||||
if (ok2) v->setTop(hi);
|
||||
le->setValidator(v);
|
||||
}
|
||||
|
||||
// 按字段建取值控件并预填。
|
||||
QWidget* buildWidget(const data::EditField& f) {
|
||||
const QString val = QString::fromStdString(f.value);
|
||||
const bool ro = isReadonly(f);
|
||||
switch (f.comp) {
|
||||
case kCompSelect: {
|
||||
case kCompCheckbox: {
|
||||
auto* cbx = new QCheckBox(QString::fromStdString(f.name));
|
||||
const QString lower = val.trimmed().toLower();
|
||||
cbx->setChecked(lower == QStringLiteral("1") || lower == QStringLiteral("true"));
|
||||
if (ro) cbx->setEnabled(false);
|
||||
return cbx;
|
||||
}
|
||||
case kCompSelect:
|
||||
case kCompTreeSelect: {
|
||||
auto* cb = new QComboBox();
|
||||
if (f.options.empty()) {
|
||||
cb->addItem(QStringLiteral("(选项待接入)"));
|
||||
cb->setEnabled(false);
|
||||
cb->setEditable(true);
|
||||
cb->setCurrentText(val);
|
||||
} else {
|
||||
for (const auto& o : f.options)
|
||||
cb->addItem(QString::fromStdString(o.label), QString::fromStdString(o.value));
|
||||
flattenOptions(f.options, cb);
|
||||
const int idx = cb->findData(val);
|
||||
if (idx >= 0) cb->setCurrentIndex(idx);
|
||||
}
|
||||
if (ro) cb->setEnabled(false);
|
||||
return cb;
|
||||
}
|
||||
case kCompDate: {
|
||||
|
|
@ -60,38 +108,57 @@ QWidget* buildWidget(const data::EditField& f) {
|
|||
de->setDisplayFormat(QStringLiteral("yyyy-MM-dd"));
|
||||
const QDate d = QDate::fromString(val.left(10), QStringLiteral("yyyy-MM-dd"));
|
||||
de->setDate(d.isValid() ? d : QDate::currentDate());
|
||||
if (ro) de->setEnabled(false);
|
||||
return de;
|
||||
}
|
||||
case kCompTime: {
|
||||
auto* te = new QTimeEdit();
|
||||
te->setDisplayFormat(QStringLiteral("HH:mm:ss"));
|
||||
const QTime t = QTime::fromString(val, QStringLiteral("HH:mm:ss"));
|
||||
te->setTime(t.isValid() ? t : QTime::currentTime());
|
||||
if (ro) te->setEnabled(false);
|
||||
return te;
|
||||
}
|
||||
case kCompDateTime: {
|
||||
auto* dt = new QDateTimeEdit();
|
||||
dt->setCalendarPopup(true);
|
||||
dt->setDisplayFormat(QStringLiteral("yyyy-MM-dd HH:mm:ss"));
|
||||
const QDateTime v = QDateTime::fromString(val, QStringLiteral("yyyy-MM-dd HH:mm:ss"));
|
||||
dt->setDateTime(v.isValid() ? v : QDateTime::currentDateTime());
|
||||
if (ro) dt->setEnabled(false);
|
||||
return dt;
|
||||
}
|
||||
case kCompMultiline: {
|
||||
auto* te = new QPlainTextEdit();
|
||||
te->setPlainText(val);
|
||||
te->setFixedHeight(geopro::app::scaledPx(64));
|
||||
if (ro) te->setReadOnly(true);
|
||||
return te;
|
||||
}
|
||||
case kCompText:
|
||||
default: {
|
||||
case kCompNumber: {
|
||||
auto* le = new QLineEdit();
|
||||
le->setText(val);
|
||||
if (f.dataType == kDtFloat) {
|
||||
le->setValidator(new QDoubleValidator(le));
|
||||
} else {
|
||||
applyIntRange(le, f);
|
||||
}
|
||||
if (ro) le->setReadOnly(true);
|
||||
return le;
|
||||
}
|
||||
case kCompText:
|
||||
case kCompText2:
|
||||
case kCompTextDisabled:
|
||||
default: {
|
||||
// 其余未知 comp 类型 + 文本类:单行文本(comp2 / 只读时禁用)。
|
||||
auto* le = new QLineEdit();
|
||||
le->setText(val);
|
||||
if (f.comp != kCompText) le->setPlaceholderText(QStringLiteral("(控件类型 %1)").arg(f.comp));
|
||||
if (f.dataType == kDtInt) {
|
||||
auto* v = new QIntValidator(le);
|
||||
bool ok1 = false, ok2 = false;
|
||||
const int lo = QString::fromStdString(f.limitMin).toInt(&ok1);
|
||||
const int hi = QString::fromStdString(f.limitMax).toInt(&ok2);
|
||||
if (ok1) v->setBottom(lo);
|
||||
if (ok2) v->setTop(hi);
|
||||
le->setValidator(v);
|
||||
applyIntRange(le, f);
|
||||
} else if (f.dataType == kDtFloat) {
|
||||
le->setValidator(new QDoubleValidator(le));
|
||||
}
|
||||
if (ro) le->setReadOnly(true);
|
||||
return le;
|
||||
}
|
||||
}
|
||||
|
|
@ -99,14 +166,24 @@ QWidget* buildWidget(const data::EditField& f) {
|
|||
|
||||
QString readWidget(int comp, QWidget* w) {
|
||||
switch (comp) {
|
||||
case kCompCheckbox:
|
||||
if (auto* cbx = qobject_cast<QCheckBox*>(w))
|
||||
return cbx->isChecked() ? QStringLiteral("1") : QStringLiteral("0");
|
||||
return {};
|
||||
case kCompSelect:
|
||||
case kCompTreeSelect:
|
||||
if (auto* cb = qobject_cast<QComboBox*>(w)) {
|
||||
const QVariant d = cb->currentData();
|
||||
return d.isValid() ? d.toString() : cb->currentText();
|
||||
}
|
||||
return {};
|
||||
case kCompDate:
|
||||
if (auto* de = qobject_cast<QDateEdit*>(w)) return de->date().toString(QStringLiteral("yyyy-MM-dd"));
|
||||
if (auto* de = qobject_cast<QDateEdit*>(w))
|
||||
return de->date().toString(QStringLiteral("yyyy-MM-dd"));
|
||||
return {};
|
||||
case kCompTime:
|
||||
if (auto* te = qobject_cast<QTimeEdit*>(w))
|
||||
return te->time().toString(QStringLiteral("HH:mm:ss"));
|
||||
return {};
|
||||
case kCompDateTime:
|
||||
if (auto* dt = qobject_cast<QDateTimeEdit*>(w))
|
||||
|
|
@ -122,8 +199,8 @@ QString readWidget(int comp, QWidget* w) {
|
|||
}
|
||||
|
||||
bool widgetEmpty(int comp, QWidget* w) {
|
||||
const QString v = readWidget(comp, w);
|
||||
return v.trimmed().isEmpty();
|
||||
if (comp == kCompCheckbox) return false; // 复选框总有值
|
||||
return readWidget(comp, w).trimmed().isEmpty();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
|
@ -167,7 +244,8 @@ void DynamicFormEditor::setForm(const data::EditableForm& form) {
|
|||
e.code = QString::fromStdString(f.code);
|
||||
e.name = QString::fromStdString(f.name);
|
||||
e.comp = f.comp;
|
||||
e.required = (f.required == 1);
|
||||
e.required = (f.required == kRequiredYes);
|
||||
e.readonly = isReadonly(f);
|
||||
e.widget = w;
|
||||
entries_.push_back(e);
|
||||
}
|
||||
|
|
@ -185,7 +263,8 @@ QMap<QString, QString> DynamicFormEditor::collectValues() const {
|
|||
|
||||
bool DynamicFormEditor::validateRequired(QString* missingName) const {
|
||||
for (const auto& e : entries_) {
|
||||
if (e.required && widgetEmpty(e.comp, e.widget)) {
|
||||
// 只读字段即使空也不拦(其值由后端核心字段或测量值产生)。
|
||||
if (e.required && !e.readonly && widgetEmpty(e.comp, e.widget)) {
|
||||
if (missingName) *missingName = e.name;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ class QLabel;
|
|||
namespace geopro::app {
|
||||
|
||||
// 动态表单编辑器:按 EditableForm 的字段元信息渲染可编辑控件(对齐原版 project/getDynamicForm)。
|
||||
// displayComponentType:1=单行文本(按 dataType 2/3 加整数/浮点校验) 4=下拉(optionsObject)
|
||||
// 6=日期 7=日期时间 8=多行文本;其余回退单行文本。
|
||||
// 编辑态用 properties 预填;requiredType==1 字段标注红色 *。
|
||||
// displayComponentType(spec §E.1 全集):1/5=单行文本 2=只读文本 3=复选框 4=下拉(optionsObject)
|
||||
// 6=日期 7=时间 8=日期时间 9=多行文本 10=数字 11=树选择(QComboBox 兜底);其余=步进数字。
|
||||
// requiredType:1=必填可编辑(标红*) 2=只读禁用 其他=可选可编辑。
|
||||
// 编辑态用 properties 预填;核心字段(fieldUseType=1)的测量值只读。
|
||||
// 注:本控件只负责"渲染 + 收集 + 必填校验",不发请求;提交载荷接入由上层处理。
|
||||
class DynamicFormEditor : public QWidget {
|
||||
Q_OBJECT
|
||||
|
|
@ -31,6 +32,7 @@ private:
|
|||
QString name;
|
||||
int comp = 1;
|
||||
bool required = false;
|
||||
bool readonly = false; // 只读(comp2 / requiredType2 / 核心测量值):不参与必填校验
|
||||
QWidget* widget = nullptr; // 取值控件
|
||||
};
|
||||
QVector<Entry> entries_;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,195 @@
|
|||
#include "panels/ObjectAttrPanel.hpp"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Theme.hpp"
|
||||
#include "api/NavLoads.hpp" // Q_DECLARE_METATYPE(EditableForm)
|
||||
#include "api/NavRequest.hpp"
|
||||
#include "panels/DynamicFormEditor.hpp"
|
||||
#include "repo/IAsyncProjectRepository.hpp"
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
namespace {
|
||||
constexpr int kConfGs = 1;
|
||||
} // namespace
|
||||
|
||||
ObjectAttrPanel::ObjectAttrPanel(geopro::data::IAsyncProjectRepository& repo, QWidget* parent)
|
||||
: QWidget(parent), repo_(repo) {
|
||||
auto* lay = new QVBoxLayout(this);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
lay->setSpacing(0);
|
||||
|
||||
status_ = new QLabel(QStringLiteral("(选中对象后显示其属性)"), this);
|
||||
status_->setAlignment(Qt::AlignCenter);
|
||||
geopro::app::applyTokenizedStyleSheet(status_,
|
||||
QStringLiteral("color:{{text/disabled}};padding:16px;"));
|
||||
lay->addWidget(status_);
|
||||
|
||||
scroll_ = new QScrollArea(this);
|
||||
scroll_->setWidgetResizable(true);
|
||||
scroll_->setFrameShape(QFrame::NoFrame);
|
||||
auto* content = new QWidget();
|
||||
auto* contentLay = new QVBoxLayout(content);
|
||||
contentLay->setContentsMargins(0, 0, 0, 0);
|
||||
contentLay->setSpacing(0);
|
||||
topBox_ = new QWidget(content); // 顶层固定字段(rebuildTopFields 重填)
|
||||
contentLay->addWidget(topBox_);
|
||||
editor_ = new DynamicFormEditor();
|
||||
contentLay->addWidget(editor_, 1);
|
||||
scroll_->setWidget(content);
|
||||
lay->addWidget(scroll_, 1);
|
||||
|
||||
auto* btnRow = new QHBoxLayout();
|
||||
btnRow->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kSm,
|
||||
geopro::app::space::kLg, geopro::app::space::kMd);
|
||||
btnRow->addStretch();
|
||||
saveBtn_ = new QPushButton(QStringLiteral("保存"), this);
|
||||
saveBtn_->setEnabled(false);
|
||||
btnRow->addWidget(saveBtn_);
|
||||
lay->addLayout(btnRow);
|
||||
|
||||
QObject::connect(saveBtn_, &QPushButton::clicked, this, &ObjectAttrPanel::onSave);
|
||||
|
||||
// 初始:无选中 → 隐藏编辑区,仅占位提示。
|
||||
scroll_->setVisible(false);
|
||||
saveBtn_->setVisible(false);
|
||||
}
|
||||
|
||||
void ObjectAttrPanel::showMessage(const QString& message) {
|
||||
objectId_.clear();
|
||||
status_->setText(message);
|
||||
status_->setVisible(true);
|
||||
scroll_->setVisible(false);
|
||||
saveBtn_->setVisible(false);
|
||||
}
|
||||
|
||||
void ObjectAttrPanel::loadObject(const QString& projectId, const QString& typeId,
|
||||
const QString& objectId, int confType, const QString& displayName,
|
||||
bool isRoot, const QString& parentId) {
|
||||
// 切换对象:中止在途保存,避免旧 save 回调串台触发 saved()/启用按钮。
|
||||
if (saveReq_) saveReq_->abort();
|
||||
if (isRoot) { // 项目根:只读占位(仅右键可新建/属性)
|
||||
showMessage(QStringLiteral("(项目根节点不可编辑)"));
|
||||
return;
|
||||
}
|
||||
projectId_ = projectId;
|
||||
confType_ = confType;
|
||||
objectId_ = objectId;
|
||||
typeId_ = typeId;
|
||||
parentId_ = parentId;
|
||||
|
||||
scroll_->setVisible(true);
|
||||
saveBtn_->setVisible(true);
|
||||
saveBtn_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("加载中…"));
|
||||
status_->setVisible(true);
|
||||
|
||||
rebuildTopFields();
|
||||
if (nameEdit_) nameEdit_->setText(displayName); // 编辑态:名称预填(沿用对话框语义)
|
||||
|
||||
if (formReq_) formReq_->abort();
|
||||
formReq_ = repo_.loadEditableFormAsync(typeId.toStdString(), objectId.toStdString(), confType,
|
||||
projectId_.toStdString());
|
||||
QObject::connect(formReq_, &geopro::data::NavRequest::done, this, [this](const QVariant& v) {
|
||||
const auto form = qvariant_cast<geopro::data::EditableForm>(v);
|
||||
editor_->setForm(form);
|
||||
status_->setVisible(false);
|
||||
saveBtn_->setEnabled(true);
|
||||
});
|
||||
QObject::connect(formReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("加载失败:%1").arg(msg));
|
||||
status_->setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
// 顶层固定字段:编辑态(类型只读 + 名称 + GS 负责人),与 ObjectFormDialog 编辑态一致。
|
||||
void ObjectAttrPanel::rebuildTopFields() {
|
||||
nameEdit_ = nullptr;
|
||||
responsibleEdit_ = nullptr;
|
||||
|
||||
if (auto* old = topBox_->layout()) {
|
||||
QLayoutItem* it = nullptr;
|
||||
while ((it = old->takeAt(0)) != nullptr) {
|
||||
if (it->widget()) it->widget()->deleteLater();
|
||||
delete it;
|
||||
}
|
||||
delete old;
|
||||
}
|
||||
|
||||
auto* fl = new QFormLayout(topBox_);
|
||||
fl->setContentsMargins(geopro::app::space::kLg, geopro::app::space::kMd,
|
||||
geopro::app::space::kLg, 0);
|
||||
fl->setLabelAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
fl->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
||||
fl->setHorizontalSpacing(geopro::app::space::kMd);
|
||||
fl->setVerticalSpacing(geopro::app::space::kSm);
|
||||
|
||||
nameEdit_ = new QLineEdit(topBox_);
|
||||
nameEdit_->setEnabled(false); // 编辑态名称禁用(与对话框一致)
|
||||
fl->addRow(QStringLiteral("名称"), nameEdit_);
|
||||
|
||||
if (confType_ == kConfGs) {
|
||||
responsibleEdit_ = new QLineEdit(topBox_);
|
||||
responsibleEdit_->setPlaceholderText(QStringLiteral("负责人"));
|
||||
fl->addRow(QStringLiteral("负责人"), responsibleEdit_);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectAttrPanel::onSave() {
|
||||
QString missing;
|
||||
if (!editor_->validateRequired(&missing)) {
|
||||
QMessageBox::warning(this, QStringLiteral("校验"),
|
||||
QStringLiteral("请填写必填项:%1").arg(missing));
|
||||
return;
|
||||
}
|
||||
|
||||
// 提交体口径同 ObjectFormDialog::buildBody 编辑态(spec §B PUT)。
|
||||
QJsonObject props;
|
||||
const auto values = editor_->collectValues();
|
||||
for (auto it = values.constBegin(); it != values.constEnd(); ++it)
|
||||
props.insert(it.key(), it.value());
|
||||
|
||||
QJsonObject body;
|
||||
body.insert(QStringLiteral("name"), nameEdit_ ? nameEdit_->text() : QString());
|
||||
body.insert(QStringLiteral("projectId"), projectId_);
|
||||
body.insert(QStringLiteral("properties"), props);
|
||||
body.insert(QStringLiteral("id"), objectId_);
|
||||
if (confType_ == kConfGs) {
|
||||
body.insert(QStringLiteral("gsTypeId"), typeId_);
|
||||
body.insert(QStringLiteral("responsiblePersonName"),
|
||||
responsibleEdit_ ? responsibleEdit_->text() : QString());
|
||||
} else {
|
||||
body.insert(QStringLiteral("tmTypeId"), typeId_);
|
||||
body.insert(QStringLiteral("parentId"), parentId_); // 该 TM 的父 GS/项目根 id
|
||||
body.insert(QStringLiteral("parentType"), QStringLiteral("1"));
|
||||
}
|
||||
|
||||
saveBtn_->setEnabled(false);
|
||||
status_->setText(QStringLiteral("提交中…"));
|
||||
status_->setVisible(true);
|
||||
if (saveReq_) saveReq_->abort();
|
||||
saveReq_ = repo_.submitObjectAsync(
|
||||
confType_, false, QJsonDocument(body).toJson(QJsonDocument::Compact).toStdString());
|
||||
QObject::connect(saveReq_, &geopro::data::NavRequest::done, this, [this](const QVariant&) {
|
||||
status_->setVisible(false);
|
||||
saveBtn_->setEnabled(true);
|
||||
emit saved();
|
||||
});
|
||||
QObject::connect(saveReq_, &geopro::data::NavRequest::failed, this, [this](const QString& msg) {
|
||||
status_->setText(QStringLiteral("提交失败:%1").arg(msg));
|
||||
status_->setVisible(true);
|
||||
saveBtn_->setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
#pragma once
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
|
||||
namespace geopro::data {
|
||||
class IAsyncProjectRepository;
|
||||
class NavRequest;
|
||||
} // namespace geopro::data
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
class QFormLayout;
|
||||
class QScrollArea;
|
||||
|
||||
namespace geopro::app {
|
||||
|
||||
class DynamicFormEditor;
|
||||
|
||||
// 对象属性面板(右上 Tab「对象属性」):可编辑动态表单 + 保存。
|
||||
// 顶层固定字段与 ObjectFormDialog 编辑态一致:name(可改) / 类型只读 / GS 负责人。
|
||||
// 动态字段来自 project/getDynamicForm(DynamicFormEditor 渲染)。
|
||||
// 仅编辑既有对象(无新建/类型下拉);提交体口径与 ObjectFormDialog::buildBody 编辑态相同:
|
||||
// PUT gsObject {gsTypeId,id,projectId,name,responsiblePersonName,properties}(无 parentId)
|
||||
// PUT tmObject {tmTypeId,id,name,properties,projectId,parentId,parentType:"1"}
|
||||
// 注:TM 编辑须带真实 parentId(该 TM 的父 GS/项目根 id,由调用方经
|
||||
// ObjectTreePanel::parentObjectId 解析后传入);GS 编辑不带 parentId。
|
||||
class ObjectAttrPanel : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ObjectAttrPanel(geopro::data::IAsyncProjectRepository& repo, QWidget* parent = nullptr);
|
||||
|
||||
// 单击对象 → 渲染可编辑表单。isRoot=项目根(只读占位,不可编辑)。
|
||||
// projectId 随当前项目动态传入(面板长生命周期,不在构造期固化)。
|
||||
// parentId=该对象父 GS/项目根 id(TM 编辑 PUT 用;GS 编辑忽略)。
|
||||
void loadObject(const QString& projectId, const QString& typeId, const QString& objectId,
|
||||
int confType, const QString& displayName, bool isRoot,
|
||||
const QString& parentId);
|
||||
void showMessage(const QString& message); // 空/占位
|
||||
|
||||
signals:
|
||||
void saved(); // 保存成功(调用方据此 toast/刷新)
|
||||
|
||||
private:
|
||||
void rebuildTopFields();
|
||||
void onSave();
|
||||
|
||||
geopro::data::IAsyncProjectRepository& repo_;
|
||||
QString projectId_;
|
||||
QString objectId_;
|
||||
QString typeId_;
|
||||
QString parentId_; // TM 编辑 PUT 的父 GS/根 id(GS 编辑不用)
|
||||
int confType_ = 0;
|
||||
|
||||
QLabel* status_ = nullptr;
|
||||
QScrollArea* scroll_ = nullptr;
|
||||
QWidget* topBox_ = nullptr;
|
||||
QLineEdit* nameEdit_ = nullptr;
|
||||
QLineEdit* responsibleEdit_ = nullptr;
|
||||
DynamicFormEditor* editor_ = nullptr;
|
||||
QPushButton* saveBtn_ = nullptr;
|
||||
QPointer<geopro::data::NavRequest> formReq_;
|
||||
QPointer<geopro::data::NavRequest> saveReq_;
|
||||
};
|
||||
|
||||
} // namespace geopro::app
|
||||
|
|
@ -26,29 +26,31 @@ namespace {
|
|||
constexpr int kRoleObjId = Qt::UserRole + 2; // 节点对象 id(GS/TM 都存)
|
||||
constexpr int kRoleConfType = Qt::UserRole + 3; // 1=GS 2=TM
|
||||
constexpr int kRoleTypeId = Qt::UserRole + 4; // 类型 id(编辑调 getDynamicForm 用)
|
||||
constexpr int kRoleIsRoot = Qt::UserRole + 5; // 项目根标记(按 GS 处理,但仅 新建GS/TM/属性)
|
||||
constexpr int kConfTypeGs = 1; // GS(工区)
|
||||
constexpr int kConfTypeTm = 2; // TM 叶子
|
||||
|
||||
// topLevel=true 仅用于项目根:渲染为非交互容器(既不可勾选,也不发 objectClicked)。
|
||||
// topLevel=true 仅用于项目根:按 GS 处理(xlsx 第32行 + 真实数据 TM 挂根),
|
||||
// 携带其 id/typeId,可右键 新建GS/TM/属性;勾选随 2D/3D 批次暂不开放。
|
||||
void addNodes(QTreeWidgetItem* parent, const std::vector<data::dto::StructTreeNode>& nodes,
|
||||
bool topLevel) {
|
||||
for (const auto& n : nodes) {
|
||||
auto* item = new QTreeWidgetItem(parent);
|
||||
item->setText(0, QString::fromStdString(n.node.name));
|
||||
item->setData(0, kRoleObjId, QString::fromStdString(n.node.id));
|
||||
item->setData(0, kRoleTypeId, QString::fromStdString(n.node.typeId));
|
||||
if (topLevel) {
|
||||
// 项目根:非交互容器(不设 kRoleObjId/kRoleConfType,不可勾选)。
|
||||
// 项目根:作为 GS 承载(id 携带),不可勾选;菜单仅 新建GS/TM/属性。
|
||||
item->setData(0, kRoleConfType, kConfTypeGs);
|
||||
item->setData(0, kRoleIsRoot, true);
|
||||
} else if (n.isTm) {
|
||||
item->setData(0, kRoleConfType, kConfTypeTm);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(0, Qt::Unchecked);
|
||||
} else {
|
||||
item->setData(0, kRoleObjId, QString::fromStdString(n.node.id));
|
||||
item->setData(0, kRoleTypeId, QString::fromStdString(n.node.typeId));
|
||||
if (n.isTm) {
|
||||
item->setData(0, kRoleConfType, kConfTypeTm);
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(0, Qt::Unchecked);
|
||||
} else {
|
||||
item->setData(0, kRoleConfType, kConfTypeGs); // GS
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
|
||||
item->setCheckState(0, Qt::Unchecked);
|
||||
}
|
||||
item->setData(0, kRoleConfType, kConfTypeGs); // GS
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
|
||||
item->setCheckState(0, Qt::Unchecked);
|
||||
}
|
||||
addNodes(item, n.children, false); // 子层永远非顶层
|
||||
}
|
||||
|
|
@ -81,9 +83,15 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|||
pressOnCheckbox_ = false;
|
||||
return;
|
||||
}
|
||||
const bool isRoot = item->data(0, kRoleIsRoot).toBool();
|
||||
const QString id = item->data(0, kRoleObjId).toString();
|
||||
const int confType = item->data(0, kRoleConfType).toInt();
|
||||
if (!id.isEmpty() && confType != 0) emit objectClicked(id, confType);
|
||||
if (id.isEmpty() || confType == 0) return;
|
||||
const QString typeId = item->data(0, kRoleTypeId).toString();
|
||||
// 对象属性面板:项目根也发(携 isRoot=true,面板据此显只读占位)。
|
||||
emit objectSelectedForEdit(id, confType, typeId, item->text(0), isRoot);
|
||||
if (isRoot) return; // 项目根:不联动数据列表/异常(仅右键操作 + 属性占位)
|
||||
emit objectClicked(id, confType);
|
||||
});
|
||||
// 勾选变化:GS 级联会触发多次 itemChanged,用 0ms 单发合并成一次「收集勾选叶子并发射」。
|
||||
QObject::connect(tree_, &QTreeWidget::itemChanged, this, [this](QTreeWidgetItem*, int) {
|
||||
|
|
@ -106,17 +114,19 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|||
});
|
||||
|
||||
// 右键菜单(对齐菜单文档:显示/隐藏、定位、属性、异常详情、编辑、新建GS/TM、导入DS、删除)。
|
||||
// GS 才显示「新建GS/TM/导入DS」(TM 为叶子不可承载子对象)。项目根节点不弹菜单。
|
||||
// 项目根=新建GS/TM/属性;GS=全项(+新建GS/TM);TM=全项(+导入DS,无新建GS)。
|
||||
tree_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(tree_, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos) {
|
||||
QTreeWidgetItem* item = tree_->itemAt(pos);
|
||||
if (!item) return;
|
||||
const QString id = item->data(0, kRoleObjId).toString();
|
||||
const int confType = item->data(0, kRoleConfType).toInt();
|
||||
if (id.isEmpty() || confType == 0) return; // 项目根:非交互容器
|
||||
if (id.isEmpty() || confType == 0) return;
|
||||
const QString typeId = item->data(0, kRoleTypeId).toString();
|
||||
const QString name = item->text(0);
|
||||
const bool isRoot = item->data(0, kRoleIsRoot).toBool();
|
||||
const bool isGs = (confType == kConfTypeGs);
|
||||
const bool isTm = (confType == kConfTypeTm);
|
||||
QMenu menu(this);
|
||||
auto add = [&](const QString& text, const QString& action) {
|
||||
menu.addAction(text, this,
|
||||
|
|
@ -124,6 +134,15 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|||
emit contextActionRequested(action, id, confType, typeId, name);
|
||||
});
|
||||
};
|
||||
if (isRoot) {
|
||||
// 项目根(按 GS):仅 新建检测对象(GS) / 新建方法对象(TM) / 属性。
|
||||
add(QStringLiteral("新建检测对象"), QStringLiteral("newGs"));
|
||||
add(QStringLiteral("新建方法对象"), QStringLiteral("newTm"));
|
||||
menu.addSeparator();
|
||||
add(QStringLiteral("属性"), QStringLiteral("properties"));
|
||||
menu.exec(tree_->viewport()->mapToGlobal(pos));
|
||||
return;
|
||||
}
|
||||
add(QStringLiteral("显示 / 隐藏"), QStringLiteral("showHide"));
|
||||
add(QStringLiteral("定位"), QStringLiteral("locate"));
|
||||
menu.addSeparator();
|
||||
|
|
@ -132,9 +151,15 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
|||
menu.addSeparator();
|
||||
add(QStringLiteral("编辑"), QStringLiteral("edit"));
|
||||
if (isGs) {
|
||||
add(QStringLiteral("新建 GS"), QStringLiteral("newGs"));
|
||||
add(QStringLiteral("新建 TM"), QStringLiteral("newTm"));
|
||||
add(QStringLiteral("导入 DS…"), QStringLiteral("importDs"));
|
||||
// GS 节点:新建检测对象 / 新建方法对象。(TM 节点上不显示「新建检测对象」——xlsx:tm 上新建GS 无效。)
|
||||
add(QStringLiteral("新建检测对象"), QStringLiteral("newGs"));
|
||||
add(QStringLiteral("新建方法对象"), QStringLiteral("newTm"));
|
||||
}
|
||||
if (isTm) {
|
||||
// TM 节点:仅「新建方法对象」(同级,父=该 TM 的父 GS/根)+ 导入 DS。
|
||||
// (xlsx:tm 上新建GS 无效,故不显示「新建检测对象」。)
|
||||
add(QStringLiteral("新建方法对象"), QStringLiteral("newTm"));
|
||||
add(QStringLiteral("导入数据集…"), QStringLiteral("importDs"));
|
||||
}
|
||||
menu.addSeparator();
|
||||
add(QStringLiteral("删除"), QStringLiteral("delete"));
|
||||
|
|
@ -198,6 +223,60 @@ void ObjectTreePanel::invertTmChecks() {
|
|||
emit tree_->itemChanged(nullptr, 0);
|
||||
}
|
||||
|
||||
QString ObjectTreePanel::currentParentForNew() const {
|
||||
if (!tree_) return {};
|
||||
// 新建对象的父必须是 GS/项目根(GS 可挂 GS/根;TM 父恒为 GS/根)。
|
||||
// 选中 TM 时不能以 TM 作父,上溯到其最近的 GS/根 祖先。
|
||||
if (QTreeWidgetItem* cur = tree_->currentItem()) {
|
||||
if (cur->data(0, kRoleConfType).toInt() == kConfTypeTm) {
|
||||
for (QTreeWidgetItem* p = cur->parent(); p; p = p->parent()) {
|
||||
const QString pid = p->data(0, kRoleObjId).toString();
|
||||
if (!pid.isEmpty() && p->data(0, kRoleConfType).toInt() == kConfTypeGs) return pid;
|
||||
}
|
||||
// TM 无 GS/根祖先(异常)→ 回落项目根
|
||||
} else {
|
||||
const QString id = cur->data(0, kRoleObjId).toString();
|
||||
if (!id.isEmpty()) return id; // GS 或 项目根
|
||||
}
|
||||
}
|
||||
// 未选中或上溯失败:回落到项目根节点(顶层首个,setStructure 保证结构含项目根)。
|
||||
if (tree_->topLevelItemCount() > 0)
|
||||
return tree_->topLevelItem(0)->data(0, kRoleObjId).toString();
|
||||
return {};
|
||||
}
|
||||
|
||||
int ObjectTreePanel::currentSelectedConfType() const {
|
||||
if (!tree_) return 0;
|
||||
QTreeWidgetItem* cur = tree_->currentItem();
|
||||
if (!cur) return 0;
|
||||
// 项目根 confType 也存为 GS(1),故 root/GS 同归为 1;TM=2。
|
||||
return cur->data(0, kRoleConfType).toInt();
|
||||
}
|
||||
|
||||
QString ObjectTreePanel::parentObjectId(const QString& objectId) const {
|
||||
if (!tree_ || objectId.isEmpty()) return {};
|
||||
// 按 id 定位树项。
|
||||
QTreeWidgetItem* found = nullptr;
|
||||
std::function<void(QTreeWidgetItem*)> find = [&](QTreeWidgetItem* node) {
|
||||
for (int i = 0; i < node->childCount() && !found; ++i) {
|
||||
QTreeWidgetItem* c = node->child(i);
|
||||
if (c->data(0, kRoleObjId).toString() == objectId) {
|
||||
found = c;
|
||||
return;
|
||||
}
|
||||
find(c);
|
||||
}
|
||||
};
|
||||
find(tree_->invisibleRootItem());
|
||||
if (!found) return {};
|
||||
// 上溯到最近的 GS/根祖先(口径同 currentParentForNew 的 TM 上溯)。
|
||||
for (QTreeWidgetItem* p = found->parent(); p; p = p->parent()) {
|
||||
const QString pid = p->data(0, kRoleObjId).toString();
|
||||
if (!pid.isEmpty() && p->data(0, kRoleConfType).toInt() == kConfTypeGs) return pid;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void ObjectTreePanel::setStructure(const QString& projectName,
|
||||
const std::vector<data::StructNode>& nodes) {
|
||||
const QSignalBlocker block(tree_); // 重建触发 itemChanged,先屏蔽
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ public:
|
|||
void setAllTmsChecked(bool checked); // 全选 / 全不选
|
||||
void invertTmChecks(); // 反选
|
||||
|
||||
// 面板「新建对象」按钮用:新建对象的父节点 id。
|
||||
// 优先当前选中节点 id;未选中时回落到项目根节点 id;树空则空串。
|
||||
QString currentParentForNew() const;
|
||||
|
||||
// 编辑 TM 用:取某对象的父 GS/项目根 id(TM 上溯到最近的 GS/根祖先)。
|
||||
// GS/根本身无需父 → 返回空串;找不到该对象或无 GS/根祖先 → 空串。
|
||||
QString parentObjectId(const QString& objectId) const;
|
||||
|
||||
// 面板「新建对象」按钮按类型决定菜单:当前选中节点的 confType(1=GS/项目根,2=TM,0=未选)。
|
||||
// 选 项目根/GS → 可新建 GS + TM;选 TM → 仅新建 TM(同级)。
|
||||
int currentSelectedConfType() const;
|
||||
|
||||
protected:
|
||||
// 区分「选中」与「勾选」手势:监视 viewport 鼠标按下是否落在复选框指示区,
|
||||
// 落在复选框上则该次 itemClicked 不发 objectClicked(避免勾选顺带重载数据集列表)。
|
||||
|
|
@ -31,6 +43,9 @@ protected:
|
|||
signals:
|
||||
// confType: 1=GS 2=TM。单击行(驱动数据列表 + 对象属性)。
|
||||
void objectClicked(const QString& objectId, int confType);
|
||||
// 单击行(含项目根,带 typeId/name/isRoot):驱动对象属性面板的可编辑表单。
|
||||
void objectSelectedForEdit(const QString& objectId, int confType, const QString& typeId,
|
||||
const QString& name, bool isRoot);
|
||||
// 当前全部被勾选的 TM 叶子 id(已合并发射)。
|
||||
void checkedTmsChanged(const QStringList& tmObjectIds);
|
||||
// 右键菜单动作(action 取值见 .cpp;objectId/confType/typeId 为右键命中项,name 用于确认框/标题)。
|
||||
|
|
|
|||
|
|
@ -154,16 +154,82 @@ NavRequest* ApiProjectRepository::loadEditableFormAsync(const std::string& typeI
|
|||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::queryTmTypesAsync(const std::string& projectId,
|
||||
const std::string& gsId) {
|
||||
const QString path = QStringLiteral("/business/tmObject/queryTmType?projectId=%1&gsId=%2")
|
||||
.arg(enc(projectId), enc(gsId));
|
||||
NavRequest* ApiProjectRepository::queryTmMethodTypesAsync(const std::string& projectId) {
|
||||
// 全局方法类型:GET /business/project/tmList/{projectId} → value:[{tmTypeId, name, ...}]。
|
||||
const QString path = QStringLiteral("/business/project/tmList/%1").arg(enc(projectId));
|
||||
auto* call = api_.getAsync(path);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse& r) {
|
||||
return QVariant::fromValue(dto::parseTmTypes(r.data.value(QStringLiteral("value")).toArray()));
|
||||
return QVariant::fromValue(
|
||||
dto::parseTmMethodTypes(r.data.value(QStringLiteral("value")).toArray()));
|
||||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::queryGsTypesAsync(const std::string& projectId) {
|
||||
const QString path = QStringLiteral("/business/project/gsList/%1").arg(enc(projectId));
|
||||
auto* call = api_.getAsync(path);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse& r) {
|
||||
return QVariant::fromValue(dto::parseGsTypes(r.data.value(QStringLiteral("value")).toArray()));
|
||||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::loadTmImportTypesAsync(const std::string& tmObjectId) {
|
||||
// 复用 TM getDetail:其 dsList 含可承载的数据类型(canImport=true 的可导入)。
|
||||
const QString path = QStringLiteral("/business/tmObject/getDetail/%1").arg(enc(tmObjectId));
|
||||
auto* call = api_.getAsync(path);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse& r) {
|
||||
return QVariant::fromValue(
|
||||
dto::parseDsImportTypes(r.data.value(QStringLiteral("dsList")).toArray()));
|
||||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::queryImportScriptsAsync(const std::string& dsTypeId,
|
||||
const std::string& tmTypeBaseConfId) {
|
||||
const QString path = QStringLiteral("/business/dsObject/query/script?dsTypeId=%1&tmTypeBaseConfId=%2")
|
||||
.arg(enc(dsTypeId), enc(tmTypeBaseConfId));
|
||||
auto* call = api_.getAsync(path);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse& r) {
|
||||
return QVariant::fromValue(dto::parseScripts(r.data.value(QStringLiteral("value")).toArray()));
|
||||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::checkImportAsync(const std::string& bodyJson) {
|
||||
const QJsonObject body = QJsonDocument::fromJson(QByteArray::fromStdString(bodyJson)).object();
|
||||
auto* call = api_.postJsonAsync(QStringLiteral("/business/dsObject/checkImport"), body);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse&) { return QVariant::fromValue(true); },
|
||||
&isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::importDatasetAsync(const std::string& queryString,
|
||||
const std::string& filePath) {
|
||||
QString path = QStringLiteral("/business/dsObject/import");
|
||||
if (!queryString.empty()) path += QStringLiteral("?") + QString::fromStdString(queryString);
|
||||
// 参数走 query string,file 为 multipart 上传项(spec §B)。
|
||||
auto* call = api_.postMultipartAsync(path, QMap<QString, QString>{},
|
||||
QStringLiteral("file"), QString::fromStdString(filePath));
|
||||
if (!call) return new FailedNavRequest(QStringLiteral("无法读取所选文件"));
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse&) { return QVariant::fromValue(true); },
|
||||
&isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::queryExportTemplatesAsync(const std::string& tmTypeBaseConfId) {
|
||||
if (tmTypeBaseConfId.empty())
|
||||
return new FailedNavRequest(QStringLiteral("缺少方法类型配置,无法取导出模板"));
|
||||
const QString path =
|
||||
QStringLiteral("/business/templateExport/queryDataType/%1").arg(enc(tmTypeBaseConfId));
|
||||
auto* call = api_.getAsync(path);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse& r) {
|
||||
return QVariant::fromValue(
|
||||
dto::parseExportTemplates(r.data.value(QStringLiteral("value")).toArray()));
|
||||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::exportDatasetAsync(const std::string& bodyJson) {
|
||||
const QJsonObject body = QJsonDocument::fromJson(QByteArray::fromStdString(bodyJson)).object();
|
||||
auto* call = api_.postJsonAsync(QStringLiteral("/business/templateExport/export"), body);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse&) { return QVariant::fromValue(true); },
|
||||
&isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::submitObjectAsync(int confType, bool isCreate,
|
||||
const std::string& bodyJson) {
|
||||
const QString path = (confType == 1) ? QStringLiteral("/business/gsObject")
|
||||
|
|
@ -182,4 +248,32 @@ NavRequest* ApiProjectRepository::listModelsAsync() {
|
|||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::loadDatasetDetailAsync(const std::string& dsObjectId) {
|
||||
const QString path = QStringLiteral("/business/dsObject/getDetail/%1").arg(enc(dsObjectId));
|
||||
auto* call = api_.getAsync(path);
|
||||
// 取现有描述纯文本:attachedParameters.deltaContent(Quill delta ops)各 insert 串接。
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse& r) {
|
||||
const QJsonArray ops = r.data.value(QStringLiteral("attachedParameters"))
|
||||
.toObject()
|
||||
.value(QStringLiteral("deltaContent"))
|
||||
.toArray();
|
||||
QString text;
|
||||
for (const auto& op : ops) {
|
||||
const QJsonValue ins = op.toObject().value(QStringLiteral("insert"));
|
||||
if (ins.isString()) text += ins.toString(); // 仅串接纯文本 insert(忽略嵌入对象)
|
||||
}
|
||||
// 剥单个尾随换行:保存侧 insert 末尾固定补 "\n"(Quill 习惯),回填时去掉以免往返累积空行。
|
||||
if (text.endsWith(QLatin1Char('\n'))) text.chop(1);
|
||||
return QVariant::fromValue(text);
|
||||
}, &isFailureA);
|
||||
}
|
||||
|
||||
NavRequest* ApiProjectRepository::updateDatasetAsync(const std::string& bodyJson) {
|
||||
const QJsonObject body = QJsonDocument::fromJson(QByteArray::fromStdString(bodyJson)).object();
|
||||
// 末尾斜杠为服务端实证要求(updateDsObject/)。
|
||||
auto* call = api_.putJsonAsync(QStringLiteral("/business/dsObject/updateDsObject/"), body);
|
||||
return new ApiNavRequest(call, [](const net::ApiResponse&) { return QVariant::fromValue(true); },
|
||||
&isFailureA);
|
||||
}
|
||||
|
||||
} // namespace geopro::data
|
||||
|
|
|
|||
|
|
@ -29,9 +29,20 @@ public:
|
|||
NavRequest* deleteDatasetAsync(const std::string& dsObjectId) override;
|
||||
NavRequest* loadEditableFormAsync(const std::string& typeId, const std::string& objectId,
|
||||
int confType, const std::string& projectId) override;
|
||||
NavRequest* queryTmTypesAsync(const std::string& projectId, const std::string& gsId) override;
|
||||
NavRequest* queryTmMethodTypesAsync(const std::string& projectId) override;
|
||||
NavRequest* queryGsTypesAsync(const std::string& projectId) override;
|
||||
NavRequest* loadTmImportTypesAsync(const std::string& tmObjectId) override;
|
||||
NavRequest* queryImportScriptsAsync(const std::string& dsTypeId,
|
||||
const std::string& tmTypeBaseConfId) override;
|
||||
NavRequest* checkImportAsync(const std::string& bodyJson) override;
|
||||
NavRequest* importDatasetAsync(const std::string& queryString,
|
||||
const std::string& filePath) override;
|
||||
NavRequest* queryExportTemplatesAsync(const std::string& tmTypeBaseConfId) override;
|
||||
NavRequest* exportDatasetAsync(const std::string& bodyJson) override;
|
||||
NavRequest* submitObjectAsync(int confType, bool isCreate, const std::string& bodyJson) override;
|
||||
NavRequest* listModelsAsync() override;
|
||||
NavRequest* loadDatasetDetailAsync(const std::string& dsObjectId) override;
|
||||
NavRequest* updateDatasetAsync(const std::string& bodyJson) override;
|
||||
|
||||
private:
|
||||
net::ApiClient& api_;
|
||||
|
|
|
|||
|
|
@ -13,5 +13,9 @@ Q_DECLARE_METATYPE(geopro::data::DynamicForm)
|
|||
Q_DECLARE_METATYPE(std::vector<geopro::data::ExceptionRow>)
|
||||
Q_DECLARE_METATYPE(geopro::data::EditableForm)
|
||||
Q_DECLARE_METATYPE(std::vector<geopro::data::TmTypeOption>)
|
||||
Q_DECLARE_METATYPE(std::vector<geopro::data::GsTypeOption>)
|
||||
Q_DECLARE_METATYPE(std::vector<geopro::data::DsImportType>)
|
||||
Q_DECLARE_METATYPE(std::vector<geopro::data::ScriptOption>)
|
||||
Q_DECLARE_METATYPE(std::vector<geopro::data::ExportTemplate>)
|
||||
Q_DECLARE_METATYPE(std::vector<geopro::data::ModelInfo>)
|
||||
// bool 已内置 QMetaType。
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
#include "IApiCall.hpp"
|
||||
|
||||
|
|
@ -36,4 +37,20 @@ private:
|
|||
bool aborted_ = false;
|
||||
};
|
||||
|
||||
// 立即失败句柄:本地前置条件不满足(如文件打开失败)时返回,异步 emit failed(message)。
|
||||
class FailedNavRequest : public NavRequest {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FailedNavRequest(QString message, QObject* parent = nullptr)
|
||||
: NavRequest(parent), message_(std::move(message)) {
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
emit failed(message_);
|
||||
deleteLater();
|
||||
});
|
||||
}
|
||||
void abort() override { deleteLater(); }
|
||||
private:
|
||||
QString message_;
|
||||
};
|
||||
|
||||
} // namespace geopro::data
|
||||
|
|
|
|||
|
|
@ -246,7 +246,8 @@ EditableForm parseEditableForm(const QJsonObject& data, int confType) {
|
|||
ef.code = str(f, "fieldCode");
|
||||
ef.name = str(f, "fieldName");
|
||||
ef.comp = f.value(QStringLiteral("displayComponentType")).toInt(1);
|
||||
ef.required = f.value(QStringLiteral("requiredType")).toInt(2);
|
||||
// requiredType 缺省按 0=可选可编辑(避免误判只读;2 才是只读禁用)。
|
||||
ef.required = f.value(QStringLiteral("requiredType")).toInt(0);
|
||||
ef.dataType = f.value(QStringLiteral("fieldDataType")).toInt(4);
|
||||
ef.useType = f.value(QStringLiteral("fieldUseType")).toInt(2);
|
||||
ef.sort = f.value(QStringLiteral("displaySort")).toInt();
|
||||
|
|
@ -275,15 +276,81 @@ EditableForm parseEditableForm(const QJsonObject& data, int confType) {
|
|||
return form;
|
||||
}
|
||||
|
||||
std::vector<TmTypeOption> parseTmTypes(const QJsonArray& arr) {
|
||||
std::vector<TmTypeOption> parseTmMethodTypes(const QJsonArray& arr) {
|
||||
// tmList 项:{tmTypeId, baseConfId, name, confCode, ...} → label=name, value=tmTypeId, code=confCode。
|
||||
std::vector<TmTypeOption> out;
|
||||
out.reserve(static_cast<size_t>(arr.size()));
|
||||
for (const QJsonValue& v : arr) {
|
||||
const QJsonObject o = v.toObject();
|
||||
TmTypeOption t;
|
||||
t.label = str(o, "label");
|
||||
t.value = o.value(QStringLiteral("value")).toVariant().toString().toStdString();
|
||||
t.code = str(o, "code");
|
||||
t.label = str(o, "name");
|
||||
t.value = o.value(QStringLiteral("tmTypeId")).toVariant().toString().toStdString();
|
||||
t.code = str(o, "confCode");
|
||||
out.push_back(std::move(t));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<GsTypeOption> parseGsTypes(const QJsonArray& arr) {
|
||||
std::vector<GsTypeOption> out;
|
||||
out.reserve(static_cast<size_t>(arr.size()));
|
||||
for (const QJsonValue& v : arr) {
|
||||
const QJsonObject o = v.toObject();
|
||||
GsTypeOption g;
|
||||
g.name = str(o, "name");
|
||||
// 兼容字段名:优先 gsTypeId,回退 id / value。
|
||||
g.gsTypeId = o.value(QStringLiteral("gsTypeId")).toVariant().toString().toStdString();
|
||||
if (g.gsTypeId.empty()) g.gsTypeId = o.value(QStringLiteral("id")).toVariant().toString().toStdString();
|
||||
if (g.gsTypeId.empty()) g.gsTypeId = o.value(QStringLiteral("value")).toVariant().toString().toStdString();
|
||||
out.push_back(std::move(g));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<DsImportType> parseDsImportTypes(const QJsonArray& arr) {
|
||||
std::vector<DsImportType> out;
|
||||
out.reserve(static_cast<size_t>(arr.size()));
|
||||
for (const QJsonValue& v : arr) {
|
||||
const QJsonObject o = v.toObject();
|
||||
DsImportType d;
|
||||
d.dsTypeId = o.value(QStringLiteral("dsTypeId")).toVariant().toString().toStdString();
|
||||
// 类型名优先中文 nameChn,回退 name / nameEng。
|
||||
d.name = str(o, "nameChn");
|
||||
if (d.name.empty()) d.name = str(o, "name");
|
||||
if (d.name.empty()) d.name = str(o, "nameEng");
|
||||
d.canImport = o.value(QStringLiteral("canImport")).toBool();
|
||||
if (d.canImport) out.push_back(std::move(d));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<ScriptOption> parseScripts(const QJsonArray& arr) {
|
||||
std::vector<ScriptOption> out;
|
||||
out.reserve(static_cast<size_t>(arr.size()));
|
||||
for (const QJsonValue& v : arr) {
|
||||
const QJsonObject o = v.toObject();
|
||||
ScriptOption s;
|
||||
// 脚本参数 getDynamicForm 需 typeId=scriptId;兼容 id/scriptId 字段名。
|
||||
s.scriptId = o.value(QStringLiteral("scriptId")).toVariant().toString().toStdString();
|
||||
if (s.scriptId.empty()) s.scriptId = o.value(QStringLiteral("id")).toVariant().toString().toStdString();
|
||||
s.scriptCode = str(o, "scriptCode");
|
||||
s.name = str(o, "name");
|
||||
if (s.name.empty()) s.name = str(o, "scriptName");
|
||||
out.push_back(std::move(s));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<ExportTemplate> parseExportTemplates(const QJsonArray& arr) {
|
||||
std::vector<ExportTemplate> out;
|
||||
out.reserve(static_cast<size_t>(arr.size()));
|
||||
for (const QJsonValue& v : arr) {
|
||||
const QJsonObject o = v.toObject();
|
||||
ExportTemplate t;
|
||||
t.id = o.value(QStringLiteral("id")).toVariant().toString().toStdString();
|
||||
if (t.id.empty()) t.id = o.value(QStringLiteral("templateId")).toVariant().toString().toStdString();
|
||||
t.name = str(o, "name");
|
||||
if (t.name.empty()) t.name = str(o, "templateName");
|
||||
out.push_back(std::move(t));
|
||||
}
|
||||
return out;
|
||||
|
|
|
|||
|
|
@ -48,8 +48,20 @@ DynamicForm parseDynamicForm(const QJsonObject& data);
|
|||
// confType 由调用方传入(1=GS 2=TM)。
|
||||
EditableForm parseEditableForm(const QJsonObject& data, int confType);
|
||||
|
||||
// tmObject/queryTmType 的 data["value"] 数组 → TM 类型选项 [{label,value,code}]。
|
||||
std::vector<TmTypeOption> parseTmTypes(const QJsonArray& arr);
|
||||
// project/tmList/{projectId} 的 data["value"] 数组 → TM 方法类型选项(label=name, value=tmTypeId, code=confCode)。
|
||||
std::vector<TmTypeOption> parseTmMethodTypes(const QJsonArray& arr);
|
||||
|
||||
// project/gsList/{projectId} 的 data["value"] 数组 → GS 类型选项 [{name, gsTypeId}]。
|
||||
std::vector<GsTypeOption> parseGsTypes(const QJsonArray& arr);
|
||||
|
||||
// TM getDetail 的 dsList 数组 → 可导入数据类型(仅含 canImport=true 的项)。
|
||||
std::vector<DsImportType> parseDsImportTypes(const QJsonArray& arr);
|
||||
|
||||
// dsObject/query/script 的 data["value"] 数组 → 导入脚本选项。
|
||||
std::vector<ScriptOption> parseScripts(const QJsonArray& arr);
|
||||
|
||||
// 导出模板列表(templateExport/queryDataType 等)的 data["value"] 数组 → 模板选项。
|
||||
std::vector<ExportTemplate> parseExportTemplates(const QJsonArray& arr);
|
||||
|
||||
// model/list 的 data["value"] 数组 → 模型/插件 [{id,scriptCode,scriptName,operationType}]。
|
||||
std::vector<ModelInfo> parseModels(const QJsonArray& arr);
|
||||
|
|
|
|||
|
|
@ -32,15 +32,37 @@ public:
|
|||
// 可编辑动态表单(新建/编辑对象):objectId 空=新建(仅取空表单),非空=编辑(含 properties 预填)。
|
||||
virtual NavRequest* loadEditableFormAsync(const std::string& typeId, const std::string& objectId,
|
||||
int confType, const std::string& projectId) = 0; // EditableForm
|
||||
// 某 GS 下可新建的 TM 方法类型列表。
|
||||
virtual NavRequest* queryTmTypesAsync(const std::string& projectId,
|
||||
const std::string& gsId) = 0; // std::vector<TmTypeOption>
|
||||
// 项目可建的 TM 方法类型列表(全局,GET /business/project/tmList/{projectId} → [{tmTypeId, name, ...}])。
|
||||
virtual NavRequest* queryTmMethodTypesAsync(const std::string& projectId) = 0; // std::vector<TmTypeOption>
|
||||
// 项目可建的 GS 测试对象类型列表(GET /business/project/gsList/{projectId})。
|
||||
virtual NavRequest* queryGsTypesAsync(const std::string& projectId) = 0; // std::vector<GsTypeOption>
|
||||
// 某 TM 可导入的数据类型(来源 TM getDetail.dsList,仅 canImport=true)。
|
||||
virtual NavRequest* loadTmImportTypesAsync(const std::string& tmObjectId) = 0; // std::vector<DsImportType>
|
||||
// 某数据类型可用的导入脚本(GET /business/dsObject/query/script)。
|
||||
virtual NavRequest* queryImportScriptsAsync(const std::string& dsTypeId,
|
||||
const std::string& tmTypeBaseConfId) = 0; // std::vector<ScriptOption>
|
||||
// 导入前坐标/轨迹文件校验(POST /business/dsObject/checkImport)。bodyJson=校验请求体。payload=bool。
|
||||
virtual NavRequest* checkImportAsync(const std::string& bodyJson) = 0; // bool
|
||||
// 导入数据集(POST /business/dsObject/import,multipart:参数走 query string,file 上传)。
|
||||
// queryString 含 dsTypeId/projectId/structParent*/scriptCode/scriptParamListJsonStr 等;
|
||||
// filePath = 本地文件路径(multipart "file" 项)。payload=bool。
|
||||
virtual NavRequest* importDatasetAsync(const std::string& queryString,
|
||||
const std::string& filePath) = 0; // bool
|
||||
// 导出可选模板列表(按方法类型 templateExport/queryDataType/{tmTypeBaseConfId})。
|
||||
virtual NavRequest* queryExportTemplatesAsync(const std::string& tmTypeBaseConfId) = 0; // std::vector<ExportTemplate>
|
||||
// 模板导出(POST /business/templateExport/export)。bodyJson=导出请求体。payload=bool。
|
||||
virtual NavRequest* exportDatasetAsync(const std::string& bodyJson) = 0; // bool
|
||||
// 提交对象(confType 1=GS 2=TM):isCreate=true→POST(新建),false→PUT(编辑)。
|
||||
// bodyJson 为序列化后的请求体(由上层按 getDynamicForm 结构拼装)。payload=bool。
|
||||
virtual NavRequest* submitObjectAsync(int confType, bool isCreate,
|
||||
const std::string& bodyJson) = 0; // bool
|
||||
// 模型/插件列表(数据集右键「插件」用)。
|
||||
virtual NavRequest* listModelsAsync() = 0; // std::vector<ModelInfo>
|
||||
// 数据集详情(GET dsObject/getDetail/{id})→ 现有描述纯文本(attachedParameters.deltaContent
|
||||
// 的各 insert 串接;无则空串)。payload=QString。
|
||||
virtual NavRequest* loadDatasetDetailAsync(const std::string& dsObjectId) = 0; // QString(描述文本)
|
||||
// 更新数据集描述(PUT dsObject/updateDsObject/,注意末尾斜杠)。bodyJson=请求体。payload=bool。
|
||||
virtual NavRequest* updateDatasetAsync(const std::string& bodyJson) = 0; // bool
|
||||
};
|
||||
|
||||
} // namespace geopro::data
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ struct DynamicForm { std::string name; std::vector<DynamicFormGroup> groups; };
|
|||
struct EditFieldOption { std::string label, value; }; // 下拉项
|
||||
struct EditField {
|
||||
std::string code, name; // fieldCode(提交键)/ fieldName(标签)
|
||||
int comp = 1; // displayComponentType: 1=文本 4=下拉 6=日期 7=日期时间 8=多行
|
||||
int required = 2; // requiredType: 1=必填 2=非必填
|
||||
int comp = 1; // displayComponentType: 1/5=文本 2=只读文本 3=复选 4=下拉 6=日期 7=时间 8=日期时间 9=多行 10=数字 11=树选
|
||||
int required = 0; // requiredType: 1=必填可编辑 2=只读禁用 其他(含0)=可选可编辑
|
||||
int dataType = 4; // fieldDataType: 2=整数 3=浮点 4=字符串 5=日期 6=日期时间 ...
|
||||
int useType = 2; // fieldUseType: 1=核心字段
|
||||
int sort = 0; // displaySort
|
||||
|
|
@ -67,6 +67,18 @@ struct EditableForm {
|
|||
// TM 类型项(新建 TM 选择方法类型用,来源 tmObject/queryTmType)。
|
||||
struct TmTypeOption { std::string label, value, code; };
|
||||
|
||||
// GS 类型项(新建 GS 选择测试对象类型用,来源 project/gsList/{projectId} → [{name, gsTypeId}])。
|
||||
struct GsTypeOption { std::string name, gsTypeId; };
|
||||
|
||||
// 导入 DS 可选数据类型(来源 TM getDetail.dsList,仅 canImport=true 进入选择)。
|
||||
struct DsImportType { std::string dsTypeId, name; bool canImport = false; };
|
||||
|
||||
// 导入脚本项(来源 dsObject/query/script,type=6 getDynamicForm 取脚本参数)。
|
||||
struct ScriptOption { std::string scriptId, scriptCode, name; };
|
||||
|
||||
// 导出模板项(来源 templateExport/queryDataType 等;下拉选择 templateId)。
|
||||
struct ExportTemplate { std::string id, name; };
|
||||
|
||||
// 模型/插件(数据集右键「插件」列表用,来源 model/list)。
|
||||
struct ModelInfo { std::string id, scriptCode, scriptName; int operationType = 0; };
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#include "ApiCall.hpp"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QHttpMultiPart>
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
|
@ -66,4 +69,42 @@ IApiCall* ApiClient::deleteAsync(const QString& path) {
|
|||
return new ApiCall(reply);
|
||||
}
|
||||
|
||||
IApiCall* ApiClient::postMultipartAsync(const QString& path,
|
||||
const QMap<QString, QString>& formFields,
|
||||
const QString& fileFieldName, const QString& filePath) {
|
||||
// 文件项:必须可读,否则放弃请求(multipart 无文件会被服务端拒)。
|
||||
auto* file = new QFile(filePath);
|
||||
if (!file->open(QIODevice::ReadOnly)) {
|
||||
delete file;
|
||||
return nullptr;
|
||||
}
|
||||
auto* multi = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
||||
file->setParent(multi); // 随 multipart 释放
|
||||
|
||||
for (auto it = formFields.constBegin(); it != formFields.constEnd(); ++it) {
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||
QStringLiteral("form-data; name=\"%1\"").arg(it.key()));
|
||||
part.setBody(it.value().toUtf8());
|
||||
multi->append(part);
|
||||
}
|
||||
|
||||
QHttpPart filePart;
|
||||
filePart.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
QStringLiteral("application/octet-stream"));
|
||||
filePart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||
QStringLiteral("form-data; name=\"%1\"; filename=\"%2\"")
|
||||
.arg(fileFieldName, QFileInfo(filePath).fileName()));
|
||||
filePart.setBodyDevice(file);
|
||||
multi->append(filePart);
|
||||
|
||||
// multipart 自带 boundary 的 Content-Type:用不含 JSON 头的请求,只保留 token。
|
||||
QNetworkRequest req{QUrl(impl_->baseUrl + path)};
|
||||
if (!impl_->token.isEmpty()) req.setRawHeader(QByteArray(kTokenHeader), impl_->token.toUtf8());
|
||||
|
||||
QNetworkReply* reply = impl_->nam.post(req, multi);
|
||||
multi->setParent(reply); // multipart 生命周期绑定到 reply
|
||||
return new ApiCall(reply);
|
||||
}
|
||||
|
||||
} // namespace geopro::net
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -42,6 +43,11 @@ public:
|
|||
IApiCall* putJsonAsync(const QString& path, const QJsonObject& body);
|
||||
// DELETE:后端多数以路径 id 标识资源、无请求体。
|
||||
IApiCall* deleteAsync(const QString& path);
|
||||
// multipart/form-data POST(文件上传)。path 可含 query string(导入参数走 query);
|
||||
// formFields = 额外文本表单项(name→value);fileFieldName/filePath = 单个文件项。
|
||||
// 文件读取失败(路径不存在/不可读)返回 nullptr,调用方据此报错。
|
||||
IApiCall* postMultipartAsync(const QString& path, const QMap<QString, QString>& formFields,
|
||||
const QString& fileFieldName, const QString& filePath);
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
|
|
|
|||
|
|
@ -71,13 +71,34 @@ struct StubAsyncRepo : data::IAsyncProjectRepository {
|
|||
const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* queryTmTypesAsync(const std::string&, const std::string&) override {
|
||||
data::NavRequest* queryTmMethodTypesAsync(const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* queryGsTypesAsync(const std::string&) override { return new StubNavRequest; }
|
||||
data::NavRequest* loadTmImportTypesAsync(const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* queryImportScriptsAsync(const std::string&, const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* checkImportAsync(const std::string&) override { return new StubNavRequest; }
|
||||
data::NavRequest* importDatasetAsync(const std::string&, const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* queryExportTemplatesAsync(const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* exportDatasetAsync(const std::string&) override { return new StubNavRequest; }
|
||||
data::NavRequest* submitObjectAsync(int, bool, const std::string&) override {
|
||||
return lastMutate = new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* listModelsAsync() override { return new StubNavRequest; }
|
||||
data::NavRequest* loadDatasetDetailAsync(const std::string&) override {
|
||||
return new StubNavRequest;
|
||||
}
|
||||
data::NavRequest* updateDatasetAsync(const std::string&) override {
|
||||
return lastMutate = new StubNavRequest;
|
||||
}
|
||||
StubNavRequest* lastMutate = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -309,3 +309,69 @@ TEST(NavDto, GroupExceptionsAllLooseWhenNoConsortium) {
|
|||
EXPECT_TRUE(g.consortia.empty());
|
||||
EXPECT_EQ(g.loose.size(), 2u);
|
||||
}
|
||||
|
||||
TEST(NavDto, ParseGsTypesMapsNameAndId) {
|
||||
const auto arr = arrOf(R"([
|
||||
{"name":"测区","gsTypeId":"gt1"},
|
||||
{"name":"测点","id":"gt2"}
|
||||
])");
|
||||
const auto types = dto::parseGsTypes(arr);
|
||||
ASSERT_EQ(types.size(), 2u);
|
||||
EXPECT_EQ(types[0].name, "测区");
|
||||
EXPECT_EQ(types[0].gsTypeId, "gt1");
|
||||
EXPECT_EQ(types[1].gsTypeId, "gt2"); // 回退 id
|
||||
}
|
||||
|
||||
TEST(NavDto, ParseDsImportTypesKeepsOnlyCanImport) {
|
||||
const auto arr = arrOf(R"([
|
||||
{"dsTypeId":"d1","nameChn":"电阻率","canImport":true},
|
||||
{"dsTypeId":"d2","nameChn":"轨迹","canImport":false}
|
||||
])");
|
||||
const auto t = dto::parseDsImportTypes(arr);
|
||||
ASSERT_EQ(t.size(), 1u);
|
||||
EXPECT_EQ(t[0].dsTypeId, "d1");
|
||||
EXPECT_EQ(t[0].name, "电阻率");
|
||||
EXPECT_TRUE(t[0].canImport);
|
||||
}
|
||||
|
||||
TEST(NavDto, ParseEditableFormPreservesCompAndRequired) {
|
||||
const auto data = QJsonDocument::fromJson(QByteArray(R"({
|
||||
"typeId":"tt1","name":"测区",
|
||||
"formList":[{"groupName":"基本","groupSort":0,"values":[
|
||||
{"fieldCode":"topography","fieldName":"地形","displayComponentType":8,"requiredType":2,"displaySort":1},
|
||||
{"fieldCode":"device","fieldName":"设备","displayComponentType":4,"requiredType":1,"displaySort":0,
|
||||
"optionsObject":[{"label":"A","value":"a"}]}
|
||||
]}],
|
||||
"properties":{"topography":"山地"}
|
||||
})")).object();
|
||||
const auto f = dto::parseEditableForm(data, 1);
|
||||
EXPECT_EQ(f.confType, 1);
|
||||
ASSERT_EQ(f.groups.size(), 1u);
|
||||
ASSERT_EQ(f.groups[0].fields.size(), 2u);
|
||||
// 已按 displaySort 排序:device(sort0) 在前。
|
||||
EXPECT_EQ(f.groups[0].fields[0].code, "device");
|
||||
EXPECT_EQ(f.groups[0].fields[0].comp, 4);
|
||||
EXPECT_EQ(f.groups[0].fields[0].required, 1);
|
||||
ASSERT_EQ(f.groups[0].fields[0].options.size(), 1u);
|
||||
EXPECT_EQ(f.groups[0].fields[0].options[0].value, "a");
|
||||
// topography:comp8 只读、有 properties 预填。
|
||||
EXPECT_EQ(f.groups[0].fields[1].comp, 8);
|
||||
EXPECT_EQ(f.groups[0].fields[1].required, 2);
|
||||
EXPECT_EQ(f.groups[0].fields[1].value, "山地");
|
||||
EXPECT_TRUE(f.groups[0].fields[1].fromProps);
|
||||
}
|
||||
|
||||
TEST(NavDto, ParseEditableFormDefaultsRequiredTypeToOptional) {
|
||||
// 缺省 requiredType → required==0(语义:可选可编辑,非必填亦非只读)。
|
||||
const auto data = QJsonDocument::fromJson(QByteArray(R"({
|
||||
"typeId":"tt1","name":"测区",
|
||||
"formList":[{"groupName":"基本","groupSort":0,"values":[
|
||||
{"fieldCode":"note","fieldName":"备注","displayComponentType":1,"displaySort":0}
|
||||
]}],
|
||||
"properties":{}
|
||||
})")).object();
|
||||
const auto f = dto::parseEditableForm(data, 1);
|
||||
ASSERT_EQ(f.groups.size(), 1u);
|
||||
ASSERT_EQ(f.groups[0].fields.size(), 1u);
|
||||
EXPECT_EQ(f.groups[0].fields[0].required, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue