增加userHook 没用dva, 修改新增评价模板禁用指标逻辑
This commit is contained in:
@ -590,7 +590,7 @@ const EvaluateTemplateTable: React.FC<EvaluateTemplateTableProps> = ({
|
||||
};
|
||||
|
||||
const filterColumns = (col: any) => {
|
||||
if ((isDetail || getUserRole() != 'admin') && ['level1Action', 'indicator_st_edit', 'base_indicator_edit', 'desc_indicator_edit', 'score_edit'].includes(col.key)) {
|
||||
if ((isDetail || getUserRole() != 'admin') && ['level1Action', 'indicatorStEditST', 'baseIndicatorEditST', 'descIndicatorEditST', 'scoreEditST'].includes(col.key)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { useState } from "react";
|
||||
|
||||
// 获取用户信息
|
||||
// 获取用户信息 这里没用dva, 因为包装组件写法复杂(当前框架),尤其是有form表单组件时
|
||||
export const useUser = () => {
|
||||
const [user, setUser] = useState<any>({
|
||||
role: 'admin',
|
||||
role: 'admin', // 模拟用户权限
|
||||
});
|
||||
const getUserInfo = ()=>{
|
||||
return user;
|
||||
|
@ -83,9 +83,8 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
const [templateList, setTemplateList] = useState<SupplierTemplateManage.TemplateItem[]>([]);
|
||||
|
||||
// 添加控制开关的状态 一级指标是否可增加(0.可增加、1.不可增加)
|
||||
const [indicatorStMore, setIndicatorStMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||
//二级指标是否可增加(0.可增加、1.不可增加)
|
||||
const [indicatorNdMore, setIndicatorNdMore] = useState<string>(IndicatorAddOption.CAN_ADD);
|
||||
|
||||
const [indicatorTypes, setIndicatorTypes] = useState<{ label: string; value: string }[]>([]);
|
||||
// 获取路由传递的数据
|
||||
const location = useLocation<LocationState>();
|
||||
@ -135,8 +134,11 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
categoryId: res.data.categoryId,
|
||||
status: res.data.status,
|
||||
copyTemplateId: res.data.copyTemplateId,
|
||||
//一级指标是否可追加
|
||||
indicatorStMore: res.data.indicatorStMore || IndicatorAddOption.CAN_ADD,
|
||||
//二级指标是否可追加
|
||||
indicatorNdMore: res.data.indicatorNdMore || IndicatorAddOption.CAN_ADD,
|
||||
//禁用指标类型 string(单选) 字典表 Indicator_type
|
||||
indicatorTypeMore: res.data.indicatorTypeMore || '',
|
||||
});
|
||||
|
||||
@ -299,22 +301,6 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
setTemplateData(data);
|
||||
};
|
||||
|
||||
// 处理开关变化
|
||||
const handleSwitchChange = (field: string, value: boolean) => {
|
||||
const newValue = value ? IndicatorAddOption.CAN_ADD : IndicatorAddOption.CANNOT_ADD;
|
||||
switch (field) {
|
||||
case 'indicatorStMore':
|
||||
setIndicatorStMore(newValue);
|
||||
form.setFieldsValue({ indicatorStMore: newValue });
|
||||
break;
|
||||
case 'indicatorNdMore':
|
||||
setIndicatorNdMore(newValue);
|
||||
form.setFieldsValue({ indicatorNdMore: newValue });
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
const searchTemplateInfoCopyToTemplateData = async (templateId: string) => {
|
||||
// 要求,如果选择模板时,需读取模板中的 indicatorStMore(一级指标是否可编辑) 和 indicatorNdMore(二级指标是否可编辑) 的值
|
||||
// 来动态设置 EvaluateTemplateTable 组件的value(templateData) 中的disable属性
|
||||
@ -325,31 +311,32 @@ const SupplierTemplateManageAdd: React.FC<PageProps> = ({ breadcrumb, dispatch }
|
||||
const res = await getTemplateDetail(templateId);
|
||||
if (res.success && res.data) {
|
||||
// 一级指标是否可编辑
|
||||
const indicatorStMoreStatus = res.data.indicatorStMore === IndicatorAddOption.CANNOT_ADD;
|
||||
// const indicatorStMoreStatus = res.data.indicatorStMore === IndicatorAddOption.CANNOT_ADD;
|
||||
// 二级指标是否可编辑
|
||||
const indicatorNdMoreStatus = res.data.indicatorNdMore === IndicatorAddOption.CANNOT_ADD;
|
||||
// const indicatorNdMoreStatus = res.data.indicatorNdMore === IndicatorAddOption.CANNOT_ADD;
|
||||
|
||||
// 只复制指标数据,不复制基础信息
|
||||
if (res.data.indicatorStList && res.data.indicatorStList.length > 0) {
|
||||
// 复制模板数据,但清除ID以创建新记录
|
||||
const copiedIndicatorStList = JSON.parse(JSON.stringify(res.data.indicatorStList)).map(
|
||||
(stItem: SupplierTemplateManage.IndicatorSt) => {
|
||||
// 通用类型指标禁用,其他类型指标不禁用 (如果当前是true 表示已禁用, 需要同时满足当前指标类型是通用类型)
|
||||
stItem.disabled = indicatorStMoreStatus && stItem.indicatorType === 'generalType';
|
||||
// 删除ID而不是设为undefined
|
||||
// delete stItem.id;
|
||||
stItem.indicatorNdList = stItem.indicatorNdList.map(
|
||||
(ndItem: SupplierTemplateManage.IndicatorNd) => {
|
||||
ndItem.disabled = indicatorNdMoreStatus;
|
||||
// delete ndItem.id;
|
||||
return ndItem;
|
||||
},
|
||||
);
|
||||
return stItem;
|
||||
},
|
||||
);
|
||||
// const copiedIndicatorStList = JSON.parse(JSON.stringify(res.data.indicatorStList)).map(
|
||||
// (stItem: SupplierTemplateManage.IndicatorSt) => {
|
||||
// // 通用类型指标禁用,其他类型指标不禁用 (如果当前是true 表示已禁用, 需要同时满足当前指标类型是通用类型)
|
||||
// stItem.disabled = indicatorStMoreStatus && stItem.indicatorType === 'generalType';
|
||||
// // 删除ID而不是设为undefined
|
||||
// // delete stItem.id;
|
||||
// stItem.indicatorNdList = stItem.indicatorNdList.map(
|
||||
// (ndItem: SupplierTemplateManage.IndicatorNd) => {
|
||||
// ndItem.disabled = indicatorNdMoreStatus;
|
||||
// // delete ndItem.id;
|
||||
// return ndItem;
|
||||
// },
|
||||
// );
|
||||
// return stItem;
|
||||
// },
|
||||
// );
|
||||
|
||||
setTemplateData(copiedIndicatorStList);
|
||||
// setTemplateData(copiedIndicatorStList);
|
||||
setTemplateData(res.data.indicatorStList);
|
||||
}
|
||||
} else {
|
||||
message.error(
|
||||
|
Reference in New Issue
Block a user