get('/home/datamgr/v2/system_config?configName=DATAMGR, {}).then((res) => {
const data = (res && res.data) || {};
store.set('houseHoldBindMode', data.data);
});
get('/home/datamgr/v2/system_config?configName=DATAMGR,GRID', {}).then((res) => {
const data = res?.data?.data || {};
store.set('houseHoldBindMode', data.DATAMGR_BUIDLING_HOUSE_BIND_MODE);
store.set('isDutyGird', !!Number(data.DATAMGR_PATROL_FILTER_BY_DUTY_GRID));
});
const controlShowBySwitchChange = (flag) => {
form.validateFields().then((values) => {
const { displayFontCon, topCascadeField, linkageAssign, securityGrade } = values;
if (flag === 1) {
if (displayFontCon) {
if (!isShowDisplayFontCon) {
form.setFieldsValue({
relDisplayField: '',
relDisplayFieldValue: '',
displayFontConType: false,
selfDisplayFieldValue: '',
});
setRelateDisplayValueList([]);
}
}
setIsShowDisplayFontCon(displayFontCon);
setIsShowDisplayFontConType(false);
} else if (flag === 2) {
setIsShowTopCascadeField(topCascadeField);
} else if (flag === 3) {
setIsShowLinkageAssign(linkageAssign);
} else if (flag === 4) {
if (form.getFieldValue('securityGrade') === 'encryption-level') {
get(`/home/datamgr/v2/meta_field/encrypt_check/${fieldID}`, {}).then((res) => {
if (res && res.message) {
message.error(res.message, [5]);
}
});
}
form.setFieldsValue({
encryption: null,
desensitizationRule: null,
});
setIsShowEncryption(securityGrade === 'encryption-level');
setIsDesensitizationRule(securityGrade === 'internal-level');
}
});
};
const controlShowBySwitchChange = (flag) => {
form.validateFields().then((values) => {
const { displayFontCon, topCascadeField, linkageAssign, securityGrade, autoCode } = values;
switch (flag) {
case 1:
if (displayFontCon) {
if (!isShowDisplayFontCon) {
form.setFieldsValue({
relDisplayField: '',
relDisplayFieldValue: '',
displayFontConType: false,
selfDisplayFieldValue: '',
});
setRelateDisplayValueList([]);
}
}
setIsShowDisplayFontCon(displayFontCon);
setIsShowDisplayFontConType(false);
break;
case 2:
setIsShowTopCascadeField(topCascadeField);
break;
case 3:
setIsShowLinkageAssign(linkageAssign);
break;
case 4:
if (form.getFieldValue('securityGrade') === 'encryption-level') {
get(`/home/datamgr/v2/meta_field/encrypt_check/${fieldID}`, {}).then((res) => {
if (res && res.message) {
message.error(res.message, [5]);
}
});
}
form.setFieldsValue({
encryption: null,
desensitizationRule: null,
});
setIsShowEncryption(securityGrade === 'encryption-level');
setIsDesensitizationRule(securityGrade === 'internal-level');
break;
case 5:
setIsShowAutoCode(autoCode);
break;
default:
break;
}
});
};
- 拒绝魔法数字 用枚举代替,没有ts就用对象代替,上面switch就很典型
export const linkageAssignTypesEnum = {
equivalent: 1,
splicing: 2,
trinocular: 3,
dateCalculate: 4,
};
export const dateCalculateRulesEnum = {
add: 1,
subtract: 2,
};
-
import
除了兄弟结构用相对路径,其他情况一律用在 webpack 中配置的别名
import Overview from '@/pages/payy/dashboard_liaocheng/overviewHospital';
import Warning from '@/pages/paxy/dashboard_dark/warning';
import GridCheck from '@/pages/paxy/dashboard_dark/gridCheck';
import Security from '@/pages/paxy/dashboard_dark/security';
- 尽量使用 es6 语法,如解构,给定默认值,let,const,箭头函数,
await async
- 严格遵守eslint规范,不要随意使用disable注释去避开代码检查
- 确保单个函数单一职责代码不超过50行
- 别重复自己 消除重复代码,适当封装组件或方法
- 没必要不注释包括且限于
提供信息
&意图解释
&阐释
&警示
&TODO
- 用有意义的命名来定义逻辑判断条件
const isShowHeadImg = field.dataFieldAttr.isShowHeadImg;
const canShowFlag = field.dataFieldAttr.canShowFlag;
const isHideAutoValueField = (isEdit || isAdd) && field.dataFieldAttr.canAutoValue;
// 责任网格特殊处理
const isGridField = field?.fieldName.split('@')[1] === 'grid_name';
React相关
- Hook代替高阶组件HOC
- 文件,文件夹名使用小驼峰
- 组件引用时使用大驼峰
- 对于 render 函数返回内容过多时(50 行),尽量拆分组件, 表单例外。
const Left = () => {
const { hiddenLeft } = useContext(HomeContext);
return (
<TweenOne animation={{ left: '-30%', duration: 800 }} reverse={!hiddenLeft}>
<Overview />
<Warning type={2} />
<Security style={{ height: '23%' }} type={1} />
<GridCheck subBlockTitleText={'医患纠纷'} />
</TweenOne>
);
};
参考文献:
《代码整洁之道》
网友评论