diff --git a/src/api/admin/CultureProtocolApi.ts b/src/api/admin/CultureProtocolApi.ts index a119f49..15ceb82 100644 --- a/src/api/admin/CultureProtocolApi.ts +++ b/src/api/admin/CultureProtocolApi.ts @@ -29,7 +29,7 @@ export class CultureProtocolApi extends HttpClient { this.request({ path: `/api/admin/culture-protocol/get`, method: 'GET', - query: params, + query: { id: params.id }, ...requestParams, }) diff --git a/src/api/admin/ProjectApi.ts b/src/api/admin/ProjectApi.ts new file mode 100644 index 0000000..2a3305b --- /dev/null +++ b/src/api/admin/ProjectApi.ts @@ -0,0 +1,63 @@ +import { ProjectPageInput, ProjectPageResponse, ProjectOutput, ProjectAddInput, ProjectUpdateInput } from '/@/api/types/projectType' +import { RequestParams } from './http-client' +import { ContentType, HttpClient } from './http-client' + +export class ProjectApi extends HttpClient { + /** + * 获取分页列表 + */ + getPage = (data: ProjectPageInput, params: RequestParams = {}) => + this.request({ + path: `/api/admin/project/get-page`, + method: 'POST', + body: data, + type: ContentType.Json, + ...params, + }) + + /** + * 获取单条数据 + */ + get = (params: { id: number }, requestParams: RequestParams = {}) => + this.request({ + path: `/api/admin/project/get`, + method: 'GET', + query: params, + ...requestParams, + }) + + /** + * 新增 + */ + add = (data: ProjectAddInput, params: RequestParams = {}) => + this.request({ + path: `/api/admin/project/add`, + method: 'POST', + body: data, + type: ContentType.Json, + ...params, + }) + + /** + * 更新 + */ + update = (data: ProjectUpdateInput, params: RequestParams = {}) => + this.request({ + path: `/api/admin/project/update`, + method: 'PUT', + body: data, + type: ContentType.Json, + ...params, + }) + + /** + * 软删除 + */ + softDelete = (params: { id: number }, requestParams: RequestParams = {}) => + this.request({ + path: `/api/admin/project/soft-delete`, + method: 'DELETE', + query: params, + ...requestParams, + }) +} \ No newline at end of file diff --git a/src/api/types/projectType.ts b/src/api/types/projectType.ts new file mode 100644 index 0000000..8787e82 --- /dev/null +++ b/src/api/types/projectType.ts @@ -0,0 +1,58 @@ +import { ServiceResponse } from './response'; +import { ServiceRequestPage } from './pageInput' +import { PageResponse } from './pageResponse' + +// 过滤条件 +export interface ProjectFilter { + /** 关键字搜索 */ + keyWord?: string | null + /** 部门ID */ + departmentId?: number | null +} + +// 项目DTO +export interface ProjectDto { + /** 主键Id */ + id?: number + /** 部门ID */ + departmentId?: number + /** 部门名称 */ + departmentName?: string | null + /** 项目编号 */ + projectNo?: string | null + /** 项目名称 */ + projectName?: string | null + /** 责任人ID */ + principalId?: number + /** 责任人姓名 */ + principalName?: string | null + /** 状态 */ + status?: boolean + /** 创建时间 */ + createdTime?: string | null + /** 修改时间 */ + modifiedTime?: string | null +} + +/** 项目添加和更新输入接口 */ +export interface ProjectAddInputAndUpdateInput { + /** 主键Id */ + id?: number + /** 部门ID */ + departmentId?: number + /** 项目编号 */ + projectNo?: string | null + /** 项目名称 */ + projectName?: string | null + /** 责任人ID */ + principalId?: number + /** 状态 */ + status?: boolean +} + +// API 类型定义 +export type ProjectPageInput = ServiceRequestPage; +export type ProjectPageResponse = PageResponse; +export type ProjectOutput = ServiceResponse; +export type ProjectAddInput = ProjectAddInputAndUpdateInput; +export type ProjectUpdateInput = ProjectAddInputAndUpdateInput; \ No newline at end of file diff --git a/src/views/admin/project/components/project-form.vue b/src/views/admin/project/components/project-form.vue new file mode 100644 index 0000000..a63b66a --- /dev/null +++ b/src/views/admin/project/components/project-form.vue @@ -0,0 +1,184 @@ + + + + + \ No newline at end of file diff --git a/src/views/admin/project/index.vue b/src/views/admin/project/index.vue new file mode 100644 index 0000000..009025d --- /dev/null +++ b/src/views/admin/project/index.vue @@ -0,0 +1,186 @@ + + + + + \ No newline at end of file diff --git a/src/views/admin/reactor/components/reactor-form.vue b/src/views/admin/reactor/components/reactor-form.vue index 2853c6c..32e3b41 100644 --- a/src/views/admin/reactor/components/reactor-form.vue +++ b/src/views/admin/reactor/components/reactor-form.vue @@ -371,7 +371,7 @@ import { PumpConfig, defaultPumpConfig, ReactorTypeEnumItem -} from '/@/api/types/ReactorType' +} from '/@/api/types/reactorType' import { toOptionsByValue } from '/@/utils/enum' import { EnumPressureUnit } from '/@/api/admin/enum-contracts' import eventBus from '/@/utils/mitt' diff --git a/src/views/admin/template/components/culture-protocol-form.vue b/src/views/admin/template/components/culture-protocol-form.vue index 1ed6ec4..462609f 100644 --- a/src/views/admin/template/components/culture-protocol-form.vue +++ b/src/views/admin/template/components/culture-protocol-form.vue @@ -357,7 +357,8 @@ const state = reactive({ selectedReactor: null as any, feedingTypeOptions: toOptionsByValue(EnumFeedingType), feedingOperatorOptions: toOptionsByValue(EnumFeedingOperator), - feedingCalculationModeOptions: toOptionsByValue(EnumFeedingCalculationMode) + feedingCalculationModeOptions: toOptionsByValue(EnumFeedingCalculationMode), + cultureProtocol: null as any }) const { form } = toRefs(state) @@ -381,9 +382,28 @@ const feedingPumpTabs = computed(() => { // 添加判断是否存在糖补料的计算属性 const hasGlucosePump = computed(() => { - return state.form.fixedFeedingPumps.some(pump => pump.isGlucose) + console.log('检查糖补料泵:', state.form.fixedFeedingPumps) + const hasGlucose = state.form.fixedFeedingPumps.some(pump => { + const isGlucose = pump.isGlucose === true + console.log(`泵${pump.feedingPumpNo} isGlucose:`, isGlucose) + return isGlucose + }) + console.log('是否存在糖补料泵:', hasGlucose) + return hasGlucose }) +// 监听补料培养基变化 +watch(() => state.form.fixedFeedingPumps, (newPumps) => { + console.log('补料泵配置变化:', newPumps) + newPumps.forEach(pump => { + if (pump.itemDefFeedingMediumID) { + const medium = state.mediumOptions.find(m => m.id === pump.itemDefFeedingMediumID) + pump.isGlucose = medium?.isGlucose ?? false + console.log(`泵${pump.feedingPumpNo} 更新isGlucose:`, pump.isGlucose) + } + }) +}, { deep: true }) + watch( () => feedingPumpTabs.value, (tabs) => { @@ -483,20 +503,34 @@ onMounted(() => { }) // 打开对话框 -const open = async (row: any = {}, isCopy = false) => { - proxy.$modal.loading() - - if (row.id > 0) { - const res = await new CultureProtocolApi().get({ id: row.id }, { loading: true }) +const open = async (id?: number) => { + // 重置对话框状态 + state.showDialog = true + activeTab.value = 'basic' + lastActiveTab.value = 'basic' + feedingTaskActiveTab.value = 'fixed' + // 重置表单数据 + reset() + // 获取数据 + if (id) { + const res = await new CultureProtocolApi().get({ id: id }, { loading: true }) if (res?.success) { - let formData = res.data as CultureProtocolDto - if (isCopy) { - formData.id = 0 - formData.cultureProtocolName = formData.cultureProtocolName + ' - 副本' - } - state.form = formData + const formData = { ...res.data } as CultureProtocolDto + formData.feedingTasks = formData.feedingTasks || [] + formData.autoGlucoseFeedingRules = formData.autoGlucoseFeedingRules || [] + formData.fixedFeedingPumps = formData.fixedFeedingPumps || [] + console.log('【编辑回显数据】', JSON.parse(JSON.stringify(formData))) + // 推荐用 Object.assign 保持响应式 + Object.assign(state.form, formData) + // 关键字段日志 + console.log('【fixedFeedingPumps】', state.form.fixedFeedingPumps) + console.log('【feedingTasks】', state.form.feedingTasks) + console.log('【autoGlucoseFeedingRules】', state.form.autoGlucoseFeedingRules) + } else { + console.warn('【编辑获取数据失败】', res) } } else { + // 设置默认值 state.form = { id: 0, cultureProtocolName: '', @@ -514,9 +548,11 @@ const open = async (row: any = {}, isCopy = false) => { fixedFeedingPumps: defaultPumps } } - - state.showDialog = true - proxy.$modal.closeLoading() + // 等待 DOM 更新 + await nextTick() + // tab渲染条件日志 + console.log('【hasGlucosePump】', hasGlucosePump.value) + console.log('【activeTab】', activeTab.value) } const defaultPumps = [ @@ -611,7 +647,7 @@ const checkGlucose = () => { }) // 校验培养天数 (开始)和培养天数 (结束)是否存在重叠 - const rules = state.form.autoGlucoseFeedingRules +const rules = state.form.autoGlucoseFeedingRules for (let i = 0; i < rules.length; i++) { for (let j = i + 1; j < rules.length; j++) { if (rules[i].cultureDayStarting < rules[j].cultureDayEnding && rules[i].cultureDayEnding > rules[j].cultureDayStarting) { @@ -628,6 +664,7 @@ const checkGlucose = () => { const onSure = async () => { if (!formRef.value) return + // 处理补料时间格式 state.form.feedingTasks.forEach(task => { if (task.feedingTime) { // 兼容 Date 对象或字符串 @@ -663,6 +700,8 @@ const onSure = async () => { console.error(state.form.id ? '修改失败:' : '新增失败:', error) } finally { state.sureLoading = false + activeTab.value = 'basic' + lastActiveTab.value = 'basic' } } }) @@ -840,11 +879,13 @@ const handleMediumChange = (index: number) => { const row = state.form.fixedFeedingPumps[index] if (!row) return - row.isGlucose = state.mediumOptions.find(item => item.id == row.itemDefFeedingMediumID)?.isGlucose ?? false + // 更新isGlucose状态 + const selectedMedium = state.mediumOptions.find(item => item.id === row.itemDefFeedingMediumID) + row.isGlucose = selectedMedium?.isGlucose ?? false // 校验重复的糖补料 if (row.isGlucose) { - const glucose = state.form.fixedFeedingPumps.find(item => item.isGlucose == true && item.feedingPumpNo != row.feedingPumpNo) + const glucose = state.form.fixedFeedingPumps.find(item => item.isGlucose === true && item.feedingPumpNo !== row.feedingPumpNo) if (glucose) { ElMessageBox.confirm('糖补料不能重复,请检查', '提示', { confirmButtonText: '确定', @@ -861,7 +902,11 @@ const handleMediumChange = (index: number) => { } // 校验重复的补料培养基 - const medium = state.form.fixedFeedingPumps.find(item => item.itemDefFeedingMediumID != undefined && item.itemDefFeedingMediumID == row.itemDefFeedingMediumID && item.feedingPumpNo != row.feedingPumpNo) + const medium = state.form.fixedFeedingPumps.find(item => + item.itemDefFeedingMediumID !== undefined && + item.itemDefFeedingMediumID === row.itemDefFeedingMediumID && + item.feedingPumpNo !== row.feedingPumpNo + ) if (medium) { proxy.$modal.msgWarning('补料培养基存在重复') } diff --git a/src/views/admin/template/index.vue b/src/views/admin/template/index.vue index f3f5f6e..9a54920 100644 --- a/src/views/admin/template/index.vue +++ b/src/views/admin/template/index.vue @@ -82,7 +82,7 @@ size="small" text type="primary" - @click="onEdit(row)" + @click="onEdit(row.id)" >编辑