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;
|
|
|
|
|
};
|
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
|
|
|
|
|
>
|
|
|
|
|
<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>),
|
2023-04-12 10:47:51 +08:00
|
|
|
colSpan: 1
|
|
|
|
|
});
|
2022-02-25 09:24:56 +08:00
|
|
|
});
|
|
|
|
|
group.push(
|
|
|
|
|
<WeaSearchGroup
|
|
|
|
|
col={col || 1} // 高级搜索列布局列数
|
|
|
|
|
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-09-15 11:08:13 +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
|
|
|
);
|
2022-09-15 11:08:13 +08:00
|
|
|
|
2022-09-29 15:45:23 +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;
|
2022-09-15 11:08:13 +08:00
|
|
|
}
|
2022-09-29 15:45:23 +08:00
|
|
|
|