salary-management-front/pc4mobx/hrmSalary/util/index.js

145 lines
4.6 KiB
JavaScript
Raw Normal View History

2023-04-12 10:47:51 +08:00
import { Spin } from "antd";
import { WeaSwitch } from "comsMobx";
import { WeaAlertPage, WeaFormItem, WeaHelpfulTip, WeaLocaleProvider, WeaSearchGroup } from "ecCom";
2022-02-25 09:24:56 +08:00
const getLabel = WeaLocaleProvider.getLabel;
2023-04-12 10:47:51 +08:00
// 获取condition的domKey值
export const getConditionDomkeys = (condition) => {
let domkeyList = [];
_.forEach(condition, item => {
const tmpV = _.reduce(item.items, (pre, cur) => {
return [...pre, cur["domkey"][0]];
}, []);
domkeyList = domkeyList.concat(tmpV);
2022-05-24 23:55:12 +08:00
});
2023-04-12 10:47:51 +08:00
return domkeyList;
};
// 获取condition的field集合
export const getConditionFields = (condition) => {
return _.reduce(condition, (pre, cur) => {
return {
...pre,
..._.reduce(cur.items, (pre1, cur1) => ({ ...pre1, [cur1["domkey"][0]]: cur1 }), {})
};
}, {});
};
2022-05-24 23:55:12 +08:00
2022-02-25 09:24:56 +08:00
// 渲染form表单: 一般对form的渲染都统一使用该方法
2023-04-23 11:28:18 +08:00
export const getSearchs = (form, condition, col, isCenter, onChange = () => void (0), title) => {
2022-02-25 09:24:56 +08:00
const { isFormInit } = form;
const formParams = form.getFormParams();
let group = [];
2023-04-12 10:47:51 +08:00
isFormInit && condition && condition.map(c => {
2022-02-25 09:24:56 +08:00
let items = [];
c.items.map(fields => {
items.push({
2023-04-12 10:47:51 +08:00
com: (
2022-02-25 09:24:56 +08:00
<WeaFormItem
label={`${fields.label}`} // label 标签的文本
2023-04-12 10:47:51 +08:00
labelCol={{ span: `${fields.labelcol}` }} // label标签占一行比例
wrapperCol={{ span: `${fields.fieldcol}` }} // 右侧控件占一行比例
2022-02-25 09:24:56 +08:00
error={form.getError(fields)} // 错误提示: 处理表单中有必填项,保存的校验
tipPosition="bottom" // 错误提示的显示位置: top/bottom
2023-07-12 14:34:07 +08:00
className={(fields.domkey[0] === "subcompanyName" || fields.domkey[0] === "departmentName") ? "hideFormItem" : ""}
2022-02-25 09:24:56 +08:00
>
<WeaSwitch
fieldConfig={fields}
form={form}
formParams={formParams}
2023-04-12 10:47:51 +08:00
onChange={onChange}
2022-02-25 09:24:56 +08:00
/>
2023-04-12 10:47:51 +08:00
{
fields.helpfulTitle &&
<WeaHelpfulTip title={fields.helpfulTitle} style={{ position: "absolute", right: "-20px", top: "25%" }}/>
}
2022-02-25 09:24:56 +08:00
</WeaFormItem>),
colSpan: 1,
hide: fields.hide
2023-04-12 10:47:51 +08:00
});
2022-02-25 09:24:56 +08:00
});
group.push(
<WeaSearchGroup
col={col || c.col || 1} // 高级搜索列布局列数
2022-02-25 09:24:56 +08:00
needTigger={true} // 是否开启收缩
2023-04-23 11:28:18 +08:00
title={c.title || title} // 高级搜索标题
2022-02-25 09:24:56 +08:00
showGroup={c.defaultshow} // 是否开启面板
items={items} // 条目数组数据
center={isCenter || false} // 内容是否居中:一般弹框需要
2023-04-12 10:47:51 +08:00
/>);
2022-02-25 09:24:56 +08:00
});
return group;
2023-04-12 10:47:51 +08:00
};
2022-02-25 09:24:56 +08:00
// 页面加载中效果处理
export const renderLoading = (loading) => (
<div className="wea-demo-loading">
2023-04-12 10:47:51 +08:00
<Spin spinning={loading}/>
2022-02-25 09:24:56 +08:00
</div>
2023-04-12 10:47:51 +08:00
);
2022-02-25 09:24:56 +08:00
// 无权限处理
export const renderNoright = () => (
<WeaAlertPage>
<div>
2023-04-12 10:47:51 +08:00
{getLabel(2012, "对不起,您暂时没有权限!")}
2022-02-25 09:24:56 +08:00
</div>
</WeaAlertPage>
2023-04-12 10:47:51 +08:00
);
2022-02-25 09:24:56 +08:00
// 暂无数据处理
export const renderNoData = () => (
<WeaAlertPage>
<div>
暂无数据
</div>
</WeaAlertPage>
2023-04-12 10:47:51 +08:00
);
//分页计算
2023-04-12 10:47:51 +08:00
export function calcPageNo(total, pageNo = 1, pageSize = 10, selectDelDataLen = 1) {
const totalPage = Math.ceil((total - selectDelDataLen) / pageSize); // 总页数
pageNo = pageNo > totalPage ? totalPage : pageNo;
pageNo = pageNo < 1 ? 1 : pageNo;
return pageNo;
}
2023-05-15 18:21:23 +08:00
//金额格式化
export const format_with_regex = (number) => {
return !(number + "").includes(".")
? // 就是说1-3位后面一定要匹配3位
(number + "").replace(/\d{1,3}(?=(\d{3})+$)/g, (match) => {
return match + ",";
})
: (number + "").replace(/\d{1,3}(?=(\d{3})+(\.))/g, (match) => {
return match + ",";
});
};
export const getDomkes = (conditions) => {
return _.reduce(conditions, (pre, cur) => ([...pre, ..._.map(cur.items, o => o.domkey[0])]), []);
};
2023-09-06 14:27:23 +08:00
export const padding0 = (num, length) => {
for (let len = ("" + num).length; len < length; len++) {
num = "0" + num;
}
return "0." + num;
};
2023-12-06 14:49:34 +08:00
export const toDecimal_n = (num, decimalPlaces) => {
if (num === null || !isFinite(num)) return null;
2023-12-06 14:49:34 +08:00
if (decimalPlaces < 0) return null;
const multiplier = Math.pow(10, decimalPlaces);
const roundedNum = Math.round(num * multiplier) / multiplier;
return roundedNum.toFixed(decimalPlaces);
2023-09-06 14:27:23 +08:00
};
//设置ifrme高度
export const getIframeParentHeight = (selector, total, extraHeight) => {
const dom = document.querySelector(selector);
let height = 280;
if (dom && total > 0) {
height = (parseFloat(dom.style.height) > 620 && total === 10) ? total * 48 + 108 : total < 10 ? (total + 1) * 48 + 108 : parseFloat(dom.style.height) - extraHeight;
}
return height;
};