fix(notice): 解决通知公告功能中的多个问题
- 添加防止表单重复提交的机制,避免用户多次点击导致数据重复 - 修复分子公司选择框中"全部"选项与其他选项冲突的问题 - 完善分子公司数据加载逻辑,在列表开头添加"全部"选项 - 优化表单提交按钮的加载状态显示和禁用控制 - 修复阅读记录页面中布尔值判断的潜在问题 - 统一组件底部的连接器导出格式master
parent
3739401833
commit
2d89f175f5
|
|
@ -12,6 +12,7 @@ function Add(props) {
|
|||
const queryParams = useGetUrlQuery();
|
||||
const [form] = Form.useForm();
|
||||
const [corpData, setCorpData] = useState([]);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const contentValue = Form.useWatch("content", form);
|
||||
const publishScope = Form.useWatch("publishScope", form);
|
||||
|
||||
|
|
@ -25,6 +26,20 @@ function Add(props) {
|
|||
}
|
||||
}, [publishScope]);
|
||||
|
||||
// 监听分子公司选择变化,处理"全部"选项逻辑
|
||||
const publishCorpinfoIdsValue = Form.useWatch("publishCorpinfoIds", form);
|
||||
useEffect(() => {
|
||||
if (!publishCorpinfoIdsValue || publishCorpinfoIdsValue.length === 0) return;
|
||||
|
||||
const hasAll = publishCorpinfoIdsValue.includes("ALL");
|
||||
const hasOther = publishCorpinfoIdsValue.some(id => id !== "ALL");
|
||||
|
||||
// 如果同时选择了"全部"和其他选项,只保留"全部"
|
||||
if (hasAll && hasOther) {
|
||||
form.setFieldValue("publishCorpinfoIds", ["ALL"]);
|
||||
}
|
||||
}, [publishCorpinfoIdsValue]);
|
||||
|
||||
useEffect(() => {
|
||||
if (queryParams["id"]) {
|
||||
props["noticeInfo"]({ id: queryParams["id"] }).then((res) => {
|
||||
|
|
@ -53,16 +68,22 @@ function Add(props) {
|
|||
item.bianma = item.id;
|
||||
item.name = item.corpName;
|
||||
});
|
||||
// 在开头添加"全部"选项
|
||||
const allOption = { bianma: "ALL", name: "全部" };
|
||||
setCorpData([allOption, ...res.data]);
|
||||
}
|
||||
setCorpData(res.data);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const onSubmit = async () => {
|
||||
// 防止重复提交
|
||||
if (submitting) return;
|
||||
setSubmitting(true);
|
||||
|
||||
try {
|
||||
await form.validateFields(); // 触发表单校验
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
setSubmitting(false);
|
||||
return; // 阻止后续逻辑
|
||||
}
|
||||
const values = await form.validateFields();
|
||||
|
|
@ -73,8 +94,17 @@ function Add(props) {
|
|||
}
|
||||
// 将分子公司数组转换为字符串
|
||||
if (values.publishCorpinfoIds && Array.isArray(values.publishCorpinfoIds)) {
|
||||
values.publishCorpinfoIds = values.publishCorpinfoIds.join(",");
|
||||
// 如果选择了"全部",则提取所有分子公司ID(排除"ALL")
|
||||
if (values.publishCorpinfoIds.includes("ALL")) {
|
||||
const allIds = corpData
|
||||
.filter(item => item.bianma !== "ALL")
|
||||
.map(item => item.bianma);
|
||||
values.publishCorpinfoIds = allIds.join(",");
|
||||
} else {
|
||||
values.publishCorpinfoIds = values.publishCorpinfoIds.join(",");
|
||||
}
|
||||
}
|
||||
|
||||
if (queryParams["id"]) {
|
||||
values.id = queryParams["id"];
|
||||
props["noticeEdit"](values).then((res) => {
|
||||
|
|
@ -82,14 +112,17 @@ function Add(props) {
|
|||
message.success("编辑成功!");
|
||||
window.history.back();
|
||||
}
|
||||
}).finally(() => {
|
||||
setSubmitting(false);
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
props["noticeAdd"](values).then((res) => {
|
||||
if (res.success) {
|
||||
message.success("新增成功!");
|
||||
window.history.back();
|
||||
}
|
||||
}).finally(() => {
|
||||
setSubmitting(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -98,20 +131,18 @@ function Add(props) {
|
|||
<Page
|
||||
headerTitle={isReadOnly ? "查看" : queryParams["id"] ? "编辑" : "新增"}
|
||||
extraActionButtons={!isReadOnly && (
|
||||
<div style={{ textAlign: "center", height: 50, marginTop: 15 }} className="no-print">
|
||||
<Button
|
||||
type="primary"
|
||||
style={{ marginRight: 20 }}
|
||||
onClick={onSubmit}
|
||||
loading={props.noticeLoading}
|
||||
>
|
||||
提交
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={onSubmit}
|
||||
loading={submitting}
|
||||
disabled={submitting}
|
||||
>
|
||||
提交
|
||||
</Button>
|
||||
)}
|
||||
>
|
||||
<FormBuilder
|
||||
loading={props.noticeLoading}
|
||||
loading={submitting}
|
||||
form={form}
|
||||
span={24}
|
||||
showActionButtons={false}
|
||||
|
|
@ -174,4 +205,4 @@ function Add(props) {
|
|||
);
|
||||
}
|
||||
|
||||
export default Connect([NS_NOTICE, NS_CORPINFO], true)(Add);
|
||||
export default Connect([NS_NOTICE, NS_CORPINFO], true)(Add);
|
||||
|
|
@ -62,7 +62,7 @@ function NoticeReadRecordView(props) {
|
|||
<Page
|
||||
headerTitle="查看"
|
||||
extraActionButtons={
|
||||
noticeReadRecordInfo.requireReply && !noticeReadRecordInfo.replyContent && (
|
||||
!!noticeReadRecordInfo.requireReply && !noticeReadRecordInfo.replyContent && (
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={handleReply}
|
||||
|
|
@ -128,4 +128,4 @@ function NoticeReadRecordView(props) {
|
|||
);
|
||||
}
|
||||
|
||||
export default Connect([NS_NoticeReadRecord], true)(NoticeReadRecordView);
|
||||
export default Connect([NS_NoticeReadRecord], true)(NoticeReadRecordView);
|
||||
Loading…
Reference in New Issue