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