feat(ui): 重构项目内模型参数配置页面

This commit is contained in:
wkc
2026-03-09 09:08:27 +08:00
parent b604981f37
commit ba7471fddb

View File

@@ -1,29 +1,19 @@
<template> <template>
<div class="param-config-container"> <div class="param-config-container">
<!-- 模型选择区域 --> <!-- 模型参数卡片组垂直堆叠 -->
<div class="filter-section"> <div class="model-cards-container">
<el-form :inline="true" :model="queryParams"> <div
<el-form-item label="模型名称"> v-for="model in modelGroups"
<el-select
v-model="queryParams.modelCode"
placeholder="请选择模型"
@change="handleModelChange"
>
<el-option
v-for="model in modelList"
:key="model.modelCode" :key="model.modelCode"
:label="model.modelName" class="model-card"
:value="model.modelCode" >
/> <!-- 模型标题 -->
</el-select> <div class="model-header">
</el-form-item> <h3>{{ model.modelName }}</h3>
</el-form>
</div> </div>
<!-- 参数配置表格 --> <!-- 参数表格 -->
<div class="table-section"> <el-table :data="model.params" border style="width: 100%">
<h3>阈值参数配置</h3>
<el-table :data="paramList" border style="width: 100%">
<el-table-column label="监测项" prop="paramName" width="200" /> <el-table-column label="监测项" prop="paramName" width="200" />
<el-table-column label="描述" prop="paramDesc" /> <el-table-column label="描述" prop="paramDesc" />
<el-table-column label="阈值设置" width="200"> <el-table-column label="阈值设置" width="200">
@@ -31,29 +21,29 @@
<el-input <el-input
v-model="row.paramValue" v-model="row.paramValue"
placeholder="请输入阈值" placeholder="请输入阈值"
@input="markAsModified(row)" @input="markAsModified(model.modelCode, row)"
/> />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="单位" prop="paramUnit" width="120" /> <el-table-column label="单位" prop="paramUnit" width="120" />
</el-table> </el-table>
</div> </div>
</div>
<!-- 操作按钮 --> <!-- 统一保存按钮 -->
<div class="button-section"> <div class="button-section">
<el-button <el-button type="primary" @click="handleSaveAll" :loading="saving">
type="primary" 保存所有修改
@click="handleSave"
:loading="saving"
>
保存配置
</el-button> </el-button>
<span v-if="modifiedCount > 0" class="modified-tip">
已修改 {{ modifiedCount }} 个参数
</span>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { listModels, listParams, saveParams } from "@/api/ccdi/modelParam"; import { listAllParams, saveAllParams } from "@/api/ccdi/modelParam";
export default { export default {
name: 'ParamConfig', name: 'ParamConfig',
@@ -69,105 +59,106 @@ export default {
}, },
data() { data() {
return { return {
modelList: [], // 模型参数数据(按模型分组)
queryParams: { modelGroups: [],
modelCode: undefined, // 修改记录(记录哪些参数被修改过)
projectId: this.projectId modifiedParams: new Map(),
}, // 保存状态
paramList: [],
saving: false saving: false
} }
}, },
computed: {
/** 计算已修改参数数量 */
modifiedCount() {
let count = 0;
this.modifiedParams.forEach(params => {
count += params.size;
});
return count;
}
},
watch: { watch: {
projectId(newVal) { projectId(newVal) {
this.queryParams.projectId = newVal if (newVal) {
this.loadModelList() this.loadAllParams();
}
} }
}, },
created() { created() {
this.loadModelList() if (this.projectId) {
this.loadAllParams();
}
}, },
methods: { methods: {
/** 加载模型列表 */ /** 加载所有模型参数 */
async loadModelList() { async loadAllParams() {
try { try {
const res = await listModels({ projectId: this.projectId }) const res = await listAllParams({ projectId: this.projectId });
this.modelList = res.data this.modelGroups = res.data.models;
if (this.modelList.length > 0) { // 清空修改记录
this.queryParams.modelCode = this.modelList[0].modelCode this.modifiedParams.clear();
this.loadParamList()
}
} catch (error) { } catch (error) {
this.$message.error('加载模型列表失败:' + error.message) this.$message.error('加载参数失败:' + error.message);
console.error('加载模型列表失败', error) console.error('加载参数失败', error);
} }
}, },
/** 加载参数列表 */ /** 标记参数为已修改 */
async loadParamList() { markAsModified(modelCode, row) {
try { if (!this.modifiedParams.has(modelCode)) {
const res = await listParams(this.queryParams) this.modifiedParams.set(modelCode, new Set());
this.paramList = res.data
} catch (error) {
this.$message.error('加载参数列表失败:' + error.message)
console.error('加载参数列表失败', error)
} }
this.modifiedParams.get(modelCode).add(row.paramCode);
}, },
/** 模型切换 */ /** 保存所有修改 */
handleModelChange() { async handleSaveAll() {
this.loadParamList()
},
/** 标记为已修改 */
markAsModified(row) {
row.modified = true
},
/** 保存配置 */
async handleSave() {
// 验证是否有修改 // 验证是否有修改
const modifiedParams = this.paramList.filter(item => item.modified) if (this.modifiedCount === 0) {
if (modifiedParams.length === 0) { this.$message.info('没有需要保存的修改');
this.$message.info('没有需要保存的修改') return;
return
} }
// 验证参数 // 构造保存数据(只包含修改过的参数
const invalidParams = modifiedParams.filter(
item => !item.paramValue || item.paramValue.trim() === ''
)
if (invalidParams.length > 0) {
this.$message.error('请填写所有参数值')
return
}
// 构造保存数据
const saveDTO = { const saveDTO = {
projectId: this.projectId, projectId: this.projectId,
modelCode: this.queryParams.modelCode, models: []
params: modifiedParams.map(item => ({ };
paramCode: item.paramCode,
paramValue: item.paramValue this.modifiedParams.forEach((paramCodes, modelCode) => {
})) const modelGroup = this.modelGroups.find(m => m.modelCode === modelCode);
const modifiedParamList = modelGroup.params
.filter(p => paramCodes.has(p.paramCode))
.map(p => ({
paramCode: p.paramCode,
paramValue: p.paramValue
}));
if (modifiedParamList.length > 0) {
saveDTO.models.push({
modelCode: modelCode,
params: modifiedParamList
});
} }
});
// 保存 // 保存
this.saving = true this.saving = true;
try { try {
await saveParams(saveDTO) await saveAllParams(saveDTO);
this.$message.success('保存成功') this.$message.success('保存成功');
// 清修改记并重新加载 // 清修改记并重新加载
this.paramList.forEach(item => { item.modified = false }) this.modifiedParams.clear();
await this.loadParamList() await this.loadAllParams();
} catch (error) { } catch (error) {
if (error.response && error.response.data && error.response.data.msg) { if (error.response && error.response.data && error.response.data.msg) {
this.$message.error('保存失败:' + error.response.data.msg) this.$message.error('保存失败:' + error.response.data.msg);
} else { } else {
this.$message.error('保存失败:' + error.message) this.$message.error('保存失败:' + error.message);
} }
console.error('保存失败', error);
} finally { } finally {
this.saving = false this.saving = false;
} }
} }
} }
@@ -181,24 +172,26 @@ export default {
min-height: 400px; min-height: 400px;
} }
.filter-section { .model-cards-container {
padding: 15px;
background: #fff;
border-radius: 4px;
margin-bottom: 20px; margin-bottom: 20px;
} }
.table-section { .model-card {
padding: 20px;
background: #fff; background: #fff;
border-radius: 4px; border-radius: 4px;
padding: 20px;
margin-bottom: 20px; margin-bottom: 20px;
border: 1px solid #e4e7ed;
.model-header {
margin-bottom: 15px;
h3 { h3 {
font-size: 16px; font-size: 16px;
font-weight: bold; font-weight: bold;
color: #333; color: #333;
margin: 0 0 15px 0; margin: 0;
}
} }
} }
@@ -207,5 +200,11 @@ export default {
background: #fff; background: #fff;
border-radius: 4px; border-radius: 4px;
text-align: left; text-align: left;
.modified-tip {
margin-left: 15px;
color: #909399;
font-size: 14px;
}
} }
</style> </style>