Skip to content

Commit b41b9f2

Browse files
committed
feat: 优化版本和语言选项加载逻辑,支持更多参数传递
修改了`loadEditionAndLanguage`方法,增加语言、版本和架构参数 拆分API端点为独立获取版本和语言选项 添加选项有效性检查逻辑
1 parent 6eb6bc1 commit b41b9f2

3 files changed

Lines changed: 93 additions & 18 deletions

File tree

src/hooks/useWinNewData.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ interface UseWinNewDataReturn {
3737
edition: string;
3838
architecture: 'all' | 'x64' | 'x86' | 'arm64';
3939
}) => Promise<void>;
40-
loadEditionAndLanguage: (systemCode: string, version: string) => Promise<void>;
40+
loadEditionAndLanguage: (
41+
systemCode: string,
42+
version: string,
43+
language: string,
44+
edition: string,
45+
architecture: 'all' | 'x64' | 'x86' | 'arm64'
46+
) => Promise<void>;
4147
handleDownload: (url: string) => void;
4248
handleCopy: (url: string) => Promise<void>;
4349
}
@@ -110,14 +116,26 @@ export function useWinNewData(): UseWinNewDataReturn {
110116
* 加载版本和语言选项
111117
*/
112118
const loadEditionAndLanguage = useCallback(
113-
async (systemCode: string, version: string) => {
119+
async (
120+
systemCode: string,
121+
version: string,
122+
language: string,
123+
edition: string,
124+
architecture: 'all' | 'x64' | 'x86' | 'arm64'
125+
) => {
114126
if (!systemCode || !version) {
115127
setEditionAndLanguage({ Language: [], Edition: [] });
116128
return;
117129
}
118130

119131
try {
120-
const data = await fetchEditionAndLanguageOptions(systemCode, version);
132+
const data = await fetchEditionAndLanguageOptions(
133+
systemCode,
134+
version,
135+
language,
136+
edition,
137+
architecture
138+
);
121139
setEditionAndLanguage(data);
122140
} catch (err) {
123141
console.error('Failed to load edition and language options:', err);

src/page/home/home.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ interface AllSystemSectionProps {
112112
filteredFiles: WinFileInfo[];
113113
isLoading: boolean;
114114
isLoadingOptions?: boolean;
115-
onLoadEditionAndLanguage: (systemCode: string, version: string) => Promise<void>;
115+
onLoadEditionAndLanguage: (
116+
systemCode: string,
117+
version: string,
118+
language: string,
119+
edition: string,
120+
architecture: 'all' | 'x64' | 'x86' | 'arm64'
121+
) => Promise<void>;
116122
onFilterChange: (filters: FilterState) => void;
117123
onDownload: (url: string) => void;
118124
onCopy: (url: string) => void;
@@ -140,10 +146,35 @@ const AllSystemSection: React.FC<AllSystemSectionProps> = ({
140146

141147
// 当版本变化时加载版本和语言选项
142148
useEffect(() => {
143-
if (filters.version) {
144-
onLoadEditionAndLanguage(filters.systemCode, filters.version);
149+
if (filters.systemCode && filters.version) {
150+
onLoadEditionAndLanguage(
151+
filters.systemCode,
152+
filters.version,
153+
filters.language,
154+
filters.edition,
155+
filters.architecture
156+
);
145157
}
146-
}, [filters.version, filters.systemCode, onLoadEditionAndLanguage]);
158+
}, [filters, onLoadEditionAndLanguage]);
159+
160+
useEffect(() => {
161+
if (!editionAndLanguage) return;
162+
163+
const hasLanguage =
164+
!filters.language ||
165+
editionAndLanguage.Language.some((item) => item.value === filters.language);
166+
const hasEdition =
167+
!filters.edition ||
168+
editionAndLanguage.Edition.some((item) => item.value === filters.edition);
169+
170+
if (!hasLanguage || !hasEdition) {
171+
setFilters((prev) => ({
172+
...prev,
173+
language: hasLanguage ? prev.language : '',
174+
edition: hasEdition ? prev.edition : '',
175+
}));
176+
}
177+
}, [editionAndLanguage, filters.language, filters.edition]);
147178

148179
// 当筛选条件变化时通知父组件
149180
useEffect(() => {

src/services/api.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const API_BASE = config.apiHost;
1717
const ENDPOINTS = {
1818
GET_FILE_LIST: '/winnew/file-list',
1919
GET_VERSION_OPTIONS: '/winnew/options/version',
20-
GET_EDITION_AND_LANGUAGE_OPTIONS: '/winnew/options/edition-language',
20+
GET_EDITION_OPTIONS: '/winnew/options/edition',
21+
GET_LANGUAGE_OPTIONS: '/winnew/options/language',
2122
} as const;
2223

2324
// 请求超时时间 (毫秒)
@@ -168,13 +169,11 @@ export async function fetchVersionOptions(signal?: AbortSignal): Promise<Version
168169
export async function fetchEditionAndLanguageOptions(
169170
systemCode: string,
170171
version: string,
172+
languageCode: string,
173+
edition: string,
174+
architecture: string,
171175
signal?: AbortSignal
172176
): Promise<EditionAndLanguage> {
173-
const queryString = buildQueryString({
174-
SystemCode: systemCode,
175-
Version: version,
176-
});
177-
178177
const controller = new AbortController();
179178
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT);
180179

@@ -183,12 +182,39 @@ export async function fetchEditionAndLanguageOptions(
183182
}
184183

185184
try {
186-
const response = await fetch(
187-
`${API_BASE}${ENDPOINTS.GET_EDITION_AND_LANGUAGE_OPTIONS}${queryString}`,
188-
{ signal: signal || controller.signal }
189-
);
185+
const finalSignal = signal || controller.signal;
186+
const [editionResponse, languageResponse] = await Promise.all([
187+
fetch(
188+
`${API_BASE}${ENDPOINTS.GET_EDITION_OPTIONS}${buildQueryString({
189+
SystemCode: systemCode,
190+
Version: version,
191+
LanguageCode: languageCode,
192+
Architecture: architecture,
193+
})}`,
194+
{ signal: finalSignal }
195+
),
196+
fetch(
197+
`${API_BASE}${ENDPOINTS.GET_LANGUAGE_OPTIONS}${buildQueryString({
198+
SystemCode: systemCode,
199+
Version: version,
200+
Edition: edition,
201+
Architecture: architecture,
202+
})}`,
203+
{ signal: finalSignal }
204+
),
205+
]);
206+
190207
clearTimeout(timeoutId);
191-
return handleResponse<EditionAndLanguage>(response);
208+
209+
const [editionData, languageData] = await Promise.all([
210+
handleResponse<{ Edition: EditionAndLanguage['Edition'] }>(editionResponse),
211+
handleResponse<{ Language: EditionAndLanguage['Language'] }>(languageResponse),
212+
]);
213+
214+
return {
215+
Edition: editionData.Edition || [],
216+
Language: languageData.Language || [],
217+
};
192218
} catch (error) {
193219
clearTimeout(timeoutId);
194220
throw error;

0 commit comments

Comments
 (0)