测试单元bug修复
parent
0948ed7c62
commit
88f358df33
|
|
@ -33,10 +33,9 @@ JWT_REDIS_EXPIRE_MINUTES = 30
|
||||||
# 数据库类型,可选的有'mysql'、'postgresql',默认为'mysql'
|
# 数据库类型,可选的有'mysql'、'postgresql',默认为'mysql'
|
||||||
DB_TYPE = 'mysql'
|
DB_TYPE = 'mysql'
|
||||||
# 数据库主机
|
# 数据库主机
|
||||||
DB_HOST = '123.57.81.127'
|
DB_HOST = 'localhost'
|
||||||
#'localhost'
|
|
||||||
# 数据库端口
|
# 数据库端口
|
||||||
DB_PORT = 3306
|
DB_PORT = 3307
|
||||||
# 数据库用户名
|
# 数据库用户名
|
||||||
DB_USERNAME = 'cpy_admin'
|
DB_USERNAME = 'cpy_admin'
|
||||||
#'root'
|
#'root'
|
||||||
|
|
@ -58,9 +57,9 @@ DB_POOL_TIMEOUT = 30
|
||||||
|
|
||||||
# -------- Redis配置 --------
|
# -------- Redis配置 --------
|
||||||
# Redis主机
|
# Redis主机
|
||||||
REDIS_HOST = '127.0.0.1'
|
REDIS_HOST = 'localhost'
|
||||||
# Redis端口
|
# Redis端口
|
||||||
REDIS_PORT = 6379
|
REDIS_PORT = 6380
|
||||||
# Redis用户名
|
# Redis用户名
|
||||||
REDIS_USERNAME = ''
|
REDIS_USERNAME = ''
|
||||||
# Redis密码
|
# Redis密码
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,12 @@ class Test_itemModel(BaseModel):
|
||||||
eut_type_id: Optional[int] = Field(default=None, description='产品类别ID')
|
eut_type_id: Optional[int] = Field(default=None, description='产品类别ID')
|
||||||
eut_type_name: Optional[str] = Field(default=None, description='产品类别名称')
|
eut_type_name: Optional[str] = Field(default=None, description='产品类别名称')
|
||||||
condition_form_id: Optional[int] = Field(default=None, description='测试条件表单模板ID')
|
condition_form_id: Optional[int] = Field(default=None, description='测试条件表单模板ID')
|
||||||
|
condition_form_name: Optional[str] = Field(default=None, description='测试条件表单模板名称')
|
||||||
condition_data: Optional[str] = Field(default=None, description='测试条件填写数据JSON')
|
condition_data: Optional[str] = Field(default=None, description='测试条件填写数据JSON')
|
||||||
result_form_id: Optional[int] = Field(default=None, description='测试结果表单模板ID')
|
result_form_id: Optional[int] = Field(default=None, description='测试结果表单模板ID')
|
||||||
condition_json: Optional[str] = Field(default=None, description='测试条件模板JSON(旧)')
|
result_form_name: Optional[str] = Field(default=None, description='测试结果表单模板名称')
|
||||||
config_json: Optional[str] = Field(default=None, description='测试结果模板JSON(旧)')
|
condition_json: Optional[str] = Field(default=None, description='测试条件模板JSON(动态获取)')
|
||||||
|
config_json: Optional[str] = Field(default=None, description='测试结果模板JSON(动态获取)')
|
||||||
memo: Optional[str] = Field(default=None, description='备注说明')
|
memo: Optional[str] = Field(default=None, description='备注说明')
|
||||||
update_by: Optional[int] = Field(default=None, description='更新者')
|
update_by: Optional[int] = Field(default=None, description='更新者')
|
||||||
update_time: Optional[datetime] = Field(default=None, description='修改时间')
|
update_time: Optional[datetime] = Field(default=None, description='修改时间')
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from config.constant import CommonConstant
|
||||||
from exceptions.exception import ServiceException
|
from exceptions.exception import ServiceException
|
||||||
from module_admin.entity.vo.common_vo import CrudResponseModel
|
from module_admin.entity.vo.common_vo import CrudResponseModel
|
||||||
from module_admin.system.dao.test_item_dao import Test_itemDao
|
from module_admin.system.dao.test_item_dao import Test_itemDao
|
||||||
|
from module_admin.system.dao.test_form_dao import TestFormDao
|
||||||
from module_admin.system.entity.vo.test_item_vo import DeleteTest_itemModel, Test_itemModel, Test_itemPageQueryModel
|
from module_admin.system.entity.vo.test_item_vo import DeleteTest_itemModel, Test_itemModel, Test_itemPageQueryModel
|
||||||
from utils.common_util import CamelCaseUtil
|
from utils.common_util import CamelCaseUtil
|
||||||
from utils.excel_util import ExcelUtil
|
from utils.excel_util import ExcelUtil
|
||||||
|
|
@ -27,9 +28,43 @@ class Test_itemService:
|
||||||
:return: 测试单元列表信息对象
|
:return: 测试单元列表信息对象
|
||||||
"""
|
"""
|
||||||
test_item_list_result = await Test_itemDao.get_test_item_list(query_db, query_object, is_page)
|
test_item_list_result = await Test_itemDao.get_test_item_list(query_db, query_object, is_page)
|
||||||
|
|
||||||
|
# 如果是分页结果,处理rows;如果是列表,直接处理
|
||||||
|
if isinstance(test_item_list_result, dict) and 'rows' in test_item_list_result:
|
||||||
|
rows = test_item_list_result['rows']
|
||||||
|
for item in rows:
|
||||||
|
await cls._enrich_form_data(query_db, item)
|
||||||
|
test_item_list_result['rows'] = rows
|
||||||
|
elif isinstance(test_item_list_result, list):
|
||||||
|
for item in test_item_list_result:
|
||||||
|
await cls._enrich_form_data(query_db, item)
|
||||||
|
|
||||||
return test_item_list_result
|
return test_item_list_result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def _enrich_form_data(cls, query_db: AsyncSession, item: dict):
|
||||||
|
"""
|
||||||
|
根据表单模板ID动态获取最新的表单JSON数据
|
||||||
|
|
||||||
|
:param query_db: orm对象
|
||||||
|
:param item: 测试单元数据字典
|
||||||
|
"""
|
||||||
|
# 获取测试条件表单模板
|
||||||
|
condition_form_id = item.get('conditionFormId') or item.get('condition_form_id')
|
||||||
|
if condition_form_id:
|
||||||
|
form = await TestFormDao.get_by_id(query_db, condition_form_id)
|
||||||
|
if form:
|
||||||
|
item['conditionJson'] = form.form_json
|
||||||
|
item['condition_form_name'] = form.name
|
||||||
|
|
||||||
|
# 获取测试结果表单模板
|
||||||
|
result_form_id = item.get('resultFormId') or item.get('result_form_id')
|
||||||
|
if result_form_id:
|
||||||
|
form = await TestFormDao.get_by_id(query_db, result_form_id)
|
||||||
|
if form:
|
||||||
|
item['configJson'] = form.form_json
|
||||||
|
item['result_form_name'] = form.name
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def add_test_item_services(cls, query_db: AsyncSession, page_object: Test_itemModel):
|
async def add_test_item_services(cls, query_db: AsyncSession, page_object: Test_itemModel):
|
||||||
|
|
@ -107,11 +142,35 @@ class Test_itemService:
|
||||||
test_item = await Test_itemDao.get_test_item_detail_by_id(query_db, id=id)
|
test_item = await Test_itemDao.get_test_item_detail_by_id(query_db, id=id)
|
||||||
if test_item:
|
if test_item:
|
||||||
result = Test_itemModel(**CamelCaseUtil.transform_result(test_item))
|
result = Test_itemModel(**CamelCaseUtil.transform_result(test_item))
|
||||||
|
# 动态获取最新的表单模板数据
|
||||||
|
await cls._enrich_form_data_for_model(query_db, result)
|
||||||
else:
|
else:
|
||||||
result = Test_itemModel(**dict())
|
result = Test_itemModel(**dict())
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def _enrich_form_data_for_model(cls, query_db: AsyncSession, model: Test_itemModel):
|
||||||
|
"""
|
||||||
|
根据表单模板ID动态获取最新的表单JSON数据(用于Model对象)
|
||||||
|
|
||||||
|
:param query_db: orm对象
|
||||||
|
:param model: 测试单元Model对象
|
||||||
|
"""
|
||||||
|
# 获取测试条件表单模板
|
||||||
|
if model.condition_form_id:
|
||||||
|
form = await TestFormDao.get_by_id(query_db, model.condition_form_id)
|
||||||
|
if form:
|
||||||
|
model.condition_json = form.form_json
|
||||||
|
model.condition_form_name = form.name
|
||||||
|
|
||||||
|
# 获取测试结果表单模板
|
||||||
|
if model.result_form_id:
|
||||||
|
form = await TestFormDao.get_by_id(query_db, model.result_form_id)
|
||||||
|
if form:
|
||||||
|
model.config_json = form.form_json
|
||||||
|
model.result_form_name = form.name
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def export_test_item_list_services(test_item_list: List):
|
async def export_test_item_list_services(test_item_list: List):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -94,14 +94,16 @@
|
||||||
<el-table-column label="名称" align="center" prop="name" />
|
<el-table-column label="名称" align="center" prop="name" />
|
||||||
<el-table-column label="测试类别" align="center" prop="testCategoryName" />
|
<el-table-column label="测试类别" align="center" prop="testCategoryName" />
|
||||||
<el-table-column label="产品类别" align="center" prop="eutTypeName" />
|
<el-table-column label="产品类别" align="center" prop="eutTypeName" />
|
||||||
<el-table-column label="测试条件" align="center" width="100">
|
<el-table-column label="测试条件" align="center" width="150">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-tag :type="scope.row.conditionFormId ? 'success' : 'danger'">{{ scope.row.conditionFormId ? '已配置' : '未配置' }}</el-tag>
|
<el-tag v-if="scope.row.conditionFormId" type="success">{{ scope.row.conditionFormName || '已配置' }}</el-tag>
|
||||||
|
<el-tag v-else type="danger">未配置</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="测试结果" align="center" width="100">
|
<el-table-column label="测试结果" align="center" width="150">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-tag :type="scope.row.resultFormId ? 'success' : 'danger'">{{ scope.row.resultFormId ? '已配置' : '未配置' }}</el-tag>
|
<el-tag v-if="scope.row.resultFormId" type="success">{{ scope.row.resultFormName || '已配置' }}</el-tag>
|
||||||
|
<el-tag v-else type="danger">未配置</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="备注说明" align="center" prop="memo" />
|
<el-table-column label="备注说明" align="center" prop="memo" />
|
||||||
|
|
@ -375,16 +377,20 @@ export default {
|
||||||
/** 查询测试单元列表 */
|
/** 查询测试单元列表 */
|
||||||
async getList() {
|
async getList() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
await Promise.all([
|
|
||||||
this.getTestCategoryOptions(),
|
// 确保表单选项已加载
|
||||||
this.getEutTypeOptions()
|
if (this.conditionFormOptions.length === 0 || this.resultFormOptions.length === 0) {
|
||||||
]);
|
await this.loadFormOptions();
|
||||||
|
}
|
||||||
|
|
||||||
listTest_item(this.queryParams).then(response => {
|
listTest_item(this.queryParams).then(response => {
|
||||||
this.test_itemList = response.rows.map(item => ({
|
this.test_itemList = response.rows.map(item => ({
|
||||||
...item,
|
...item,
|
||||||
testCategoryName: this.testCategoryOptions.find(opt => opt.value === item.testCategoryId)?.label || '',
|
testCategoryName: this.testCategoryOptions.find(opt => opt.value === item.testCategoryId)?.label || '',
|
||||||
eutTypeName: this.typeEutOptions.find(opt => opt.value === item.eutTypeId)?.label || ''
|
eutTypeName: this.typeEutOptions.find(opt => opt.value === item.eutTypeId)?.label || '',
|
||||||
|
// 使用后端返回的表单名称,如果没有则从本地选项查找
|
||||||
|
conditionFormName: item.conditionFormName || this.conditionFormOptions.find(opt => opt.id === item.conditionFormId)?.name || '',
|
||||||
|
resultFormName: item.resultFormName || this.resultFormOptions.find(opt => opt.id === item.resultFormId)?.name || ''
|
||||||
}));
|
}));
|
||||||
this.total = response.total;
|
this.total = response.total;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
@ -413,15 +419,14 @@ export default {
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
},
|
},
|
||||||
/** 加载表单选项 */
|
/** 加载表单选项 */
|
||||||
loadFormOptions() {
|
async loadFormOptions() {
|
||||||
// 加载测试条件表单
|
// 加载测试条件表单
|
||||||
listTest_form_by_type('CONDITION').then(response => {
|
const conditionRes = await listTest_form_by_type('CONDITION');
|
||||||
this.conditionFormOptions = response.data || [];
|
this.conditionFormOptions = conditionRes.data || [];
|
||||||
});
|
|
||||||
// 加载测试结果表单
|
// 加载测试结果表单
|
||||||
listTest_form_by_type('RESULT').then(response => {
|
const resultRes = await listTest_form_by_type('RESULT');
|
||||||
this.resultFormOptions = response.data || [];
|
this.resultFormOptions = resultRes.data || [];
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/** 测试条件表单选择变化 */
|
/** 测试条件表单选择变化 */
|
||||||
handleConditionFormChange(formId) {
|
handleConditionFormChange(formId) {
|
||||||
|
|
@ -487,6 +492,23 @@ export default {
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
// 预处理方法定义 - 移到外部以便在 data 和 methods 中都能访问
|
||||||
|
const uploadMethods = {};
|
||||||
|
const varPattern = /v-model="(\w+)"|:file-list="(\w+)"|:action="(\w+)"|:before-upload="(\w+)"/g;
|
||||||
|
let match;
|
||||||
|
while ((match = varPattern.exec(cleanTemplate)) !== null) {
|
||||||
|
const varName = match[4]; // before-upload 方法
|
||||||
|
if (varName) {
|
||||||
|
uploadMethods[varName] = function(file) {
|
||||||
|
const isLt10M = file.size / 1024 / 1024 < 10;
|
||||||
|
if (!isLt10M) {
|
||||||
|
this.$message.error('上传文件大小不能超过 10MB!');
|
||||||
|
}
|
||||||
|
return isLt10M;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 创建动态表单组件
|
// 创建动态表单组件
|
||||||
const DynamicForm = {
|
const DynamicForm = {
|
||||||
template: `
|
template: `
|
||||||
|
|
@ -503,29 +525,19 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
// 自动扫描模板中引用的变量,补充默认值
|
// 自动扫描模板中引用的变量,补充默认值
|
||||||
const extraData = {};
|
const extraData = {};
|
||||||
const uploadMethods = {};
|
|
||||||
const token = getToken();
|
const token = getToken();
|
||||||
const varPattern = /v-model="(\w+)"|:file-list="(\w+)"|:action="(\w+)"|:before-upload="(\w+)"/g;
|
const varPattern2 = /v-model="(\w+)"|:file-list="(\w+)"|:action="(\w+)"|:before-upload="(\w+)"/g;
|
||||||
let match;
|
let match2;
|
||||||
while ((match = varPattern.exec(cleanTemplate)) !== null) {
|
while ((match2 = varPattern2.exec(cleanTemplate)) !== null) {
|
||||||
const varName = match[1] || match[2] || match[3] || match[4];
|
const varName = match2[1] || match2[2] || match2[3] || match2[4];
|
||||||
if (varName && varName !== 'formData' && !varName.startsWith('formData.')) {
|
if (varName && varName !== 'formData' && !varName.startsWith('formData.')) {
|
||||||
if (match[2]) {
|
if (match2[2]) {
|
||||||
// file-list 变量
|
// file-list 变量
|
||||||
extraData[varName] = [];
|
extraData[varName] = [];
|
||||||
} else if (match[3]) {
|
} else if (match2[3]) {
|
||||||
// action 变量
|
// action 变量
|
||||||
extraData[varName] = process.env.VUE_APP_BASE_API + '/common/upload';
|
extraData[varName] = process.env.VUE_APP_BASE_API + '/common/upload';
|
||||||
} else if (match[4]) {
|
} else if (match2[1] && !match2[1].startsWith('formData')) {
|
||||||
// before-upload 方法 - 记录到methods中,不放data
|
|
||||||
uploadMethods[varName] = function(file) {
|
|
||||||
const isLt10M = file.size / 1024 / 1024 < 10;
|
|
||||||
if (!isLt10M) {
|
|
||||||
this.$message.error('上传文件大小不能超过 10MB!');
|
|
||||||
}
|
|
||||||
return isLt10M;
|
|
||||||
};
|
|
||||||
} else if (match[1] && !match[1].startsWith('formData')) {
|
|
||||||
extraData[varName] = null;
|
extraData[varName] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -608,14 +620,20 @@ export default {
|
||||||
this.title = "添加测试单元";
|
this.title = "添加测试单元";
|
||||||
},
|
},
|
||||||
/** 修改按钮操作 */
|
/** 修改按钮操作 */
|
||||||
handleUpdate(row) {
|
async handleUpdate(row) {
|
||||||
this.reset();
|
this.reset();
|
||||||
// const id = row.id || this.ids;
|
const id = row.id || this.ids[0];
|
||||||
// getTest_item(id).then(response => {
|
|
||||||
this.form = row;
|
// 确保表单选项已加载
|
||||||
|
if (this.conditionFormOptions.length === 0 || this.resultFormOptions.length === 0) {
|
||||||
|
await this.loadFormOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
getTest_item(id).then(response => {
|
||||||
|
this.form = response.data;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "修改测试单元";
|
this.title = "修改测试单元";
|
||||||
// });
|
});
|
||||||
},
|
},
|
||||||
/** 提交按钮 */
|
/** 提交按钮 */
|
||||||
submitForm() {
|
submitForm() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue