From b702662d415fbe949948b2ebe10f6edbac7fed52 Mon Sep 17 00:00:00 2001 From: Sleck <15660928620@163.com> Date: Wed, 19 Feb 2025 14:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=A4=E9=AB=98=E4=BA=AE=E5=A4=96=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E9=83=BD=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryContentWithDirHandle.tsx | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/src/pages/LotteryPage/LotteryContentWithDirHandle.tsx b/src/pages/LotteryPage/LotteryContentWithDirHandle.tsx index 9aba0cb..a59b258 100644 --- a/src/pages/LotteryPage/LotteryContentWithDirHandle.tsx +++ b/src/pages/LotteryPage/LotteryContentWithDirHandle.tsx @@ -13,6 +13,7 @@ import { } from "@ant-design/icons"; import { WorkshopPageContext } from "../WorkshopPage/WorkshopPageContext"; import { NOTION_DATABASE_LOTTERY, LotteryConfig, areLotteryConfigsEqual } from "../../services/lottery/lotteryNotionQueries"; +import { key } from "localforage"; const { Text } = Typography; const COMMODITY_PATH = "CodeFunCore/src/main/resources/net/easecation/codefuncore/lottery/notion/"; @@ -150,7 +151,7 @@ const LotteryContentWithDirHandle: React.FC = () => { // 校验两个 LotteryConfig 是否相同 const isEqual = areLotteryConfigsEqual(remotConfig, localConfig); - if (!isEqual) { + if (!isEqual && !modifiedKeys.includes(key)) { // console.log(`${key} 的配置有差异`); modifieds.push(key); } else { @@ -158,6 +159,7 @@ const LotteryContentWithDirHandle: React.FC = () => { } } }); + if(modifieds.length === 0) return; setModifiedKeys(modifieds); } @@ -218,7 +220,7 @@ const LotteryContentWithDirHandle: React.FC = () => { if (dirHandle && currentType) { loadLocalFile(); } - }, [dirHandle, currentType, currentTypes]); + }, [dirHandle, currentType, currentTypes, modifiedKeys]); // 远端数据加载 const handleLoadRemoteJson = async () => { @@ -237,7 +239,7 @@ const LotteryContentWithDirHandle: React.FC = () => { // 同步远端 JSON 到本地(一次性同步所有勾选的 key) const handleSyncRemoteJson = async () => { // 如果没有勾选任何 key,就使用 currentType 作为默认同步对象 - const keysToSync = checkedKeys.length > 0 ? checkedKeys : currentType ? [currentType] : []; + const keysToSync = checkedKeys.length > 0 ? checkedKeys : currentType ? [currentType] : []; if (!dirHandle || keysToSync.length === 0) { messageApi.error("请先选择至少一个要同步的 Key,或加载 Notion 数据"); @@ -250,6 +252,7 @@ const LotteryContentWithDirHandle: React.FC = () => { // 把最新的 currentTypes、missingTypes 做副本,方便批量更新 let newCurrentTypes = [...currentTypes]; let newMissingTypes = [...missingTypes]; + let newModifiedKeys = [...modifiedKeys]; // 逐个 key 同步到本地 for (const key of keysToSync) { @@ -267,8 +270,12 @@ const LotteryContentWithDirHandle: React.FC = () => { newMissingTypes = newMissingTypes.filter((t) => t !== key); newCurrentTypes.push(key); } + if (newModifiedKeys.includes(key)) { + newModifiedKeys = newModifiedKeys.filter((t) => t !== key); + } } + // 如果我们在循环中新增了 key 到 currentTypes,需要写回 notion.json if (newCurrentTypes.length !== currentTypes.length) { newCurrentTypes.sort(); // 按字母排序 @@ -283,8 +290,11 @@ const LotteryContentWithDirHandle: React.FC = () => { if (keysToSync.length === 1) { setCurrentType(keysToSync[0]); } + } else if (newModifiedKeys.length !== modifiedKeys.length) { + setModifiedKeys(newModifiedKeys); } + setCheckedKeys([]); // 提示成功 messageApi.success(`已同步 ${keysToSync.join(", ")} 到本地!`); } catch (error: any) { @@ -347,33 +357,43 @@ const LotteryContentWithDirHandle: React.FC = () => { {/* Notion JSON 数据 */} - Notion 数据 - - ) - } - > + style={{ flex: 2, minHeight: "80vh" }} + title={ + + Notion 数据 + + ) + } + > {remoteJsonMap[currentType || ""] ? ( ) : (