Spaces:
Running
Running
Upload 前端页面/core/侧边栏数据引擎.js
Browse files- 前端页面/core/侧边栏数据引擎.js +25 -18
前端页面/core/侧边栏数据引擎.js
CHANGED
|
@@ -184,11 +184,15 @@ export async function loadSidebarContent({
|
|
| 184 |
// 现统一收口到本函数:所有取数路径都先过滤、再切片,renderBatch 只负责渲染。
|
| 185 |
// 创作者Tab的 keyword 由后端搜索接口过滤,此处不做本地过滤(与原口径一致)。
|
| 186 |
const _applySearchScope = (dataArray) => {
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
| 189 |
};
|
| 190 |
|
| 191 |
// ========== 渲染函数:渲染一批数据(只渲染,过滤由 _applySearchScope 统一负责)==========
|
|
|
|
| 192 |
const renderBatch = (dataArray, append = false) => {
|
| 193 |
if (renderToken !== getRenderToken()) return;
|
| 194 |
|
|
@@ -209,7 +213,7 @@ export async function loadSidebarContent({
|
|
| 209 |
emptyState.textContent = t(keyword ? 'feedback.no_search_results' : 'feedback.no_list_data');
|
| 210 |
emptyState.setAttribute('role', 'status');
|
| 211 |
contentArea.replaceChildren(emptyState);
|
| 212 |
-
return 0;
|
| 213 |
}
|
| 214 |
|
| 215 |
// 渲染卡片
|
|
@@ -224,7 +228,7 @@ export async function loadSidebarContent({
|
|
| 224 |
cards.push(card);
|
| 225 |
fragment.appendChild(card);
|
| 226 |
// 检查是否是需要展开的卡片
|
| 227 |
-
if (expandItemId && data.id === expandItemId) {
|
| 228 |
targetCard = card;
|
| 229 |
}
|
| 230 |
});
|
|
@@ -256,25 +260,28 @@ export async function loadSidebarContent({
|
|
| 256 |
});
|
| 257 |
}
|
| 258 |
|
| 259 |
-
//
|
| 260 |
-
if (expandItemId && !targetCard && !append && canNavigate()) {
|
|
|
|
| 261 |
(async () => {
|
| 262 |
try {
|
| 263 |
const res = await api.getItemById(expandItemId);
|
| 264 |
if (!canNavigate()) return;
|
| 265 |
-
if (res.status ==
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
const view = module.createItemDetailView(res.data, currentUser);
|
| 269 |
-
if (!canNavigate()) {
|
| 270 |
-
view._cleanup?.();
|
| 271 |
-
return;
|
| 272 |
-
}
|
| 273 |
-
window.dispatchEvent(new CustomEvent("comfy-route-view", { detail: { view } }));
|
| 274 |
}
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
}
|
| 279 |
})();
|
| 280 |
}
|
|
|
|
| 184 |
// 现统一收口到本函数:所有取数路径都先过滤、再切片,renderBatch 只负责渲染。
|
| 185 |
// 创作者Tab的 keyword 由后端搜索接口过滤,此处不做本地过滤(与原口径一致)。
|
| 186 |
const _applySearchScope = (dataArray) => {
|
| 187 |
+
const scoped = !keyword || tab === "creators" ? dataArray : filterItemsByKeyword(dataArray, keyword);
|
| 188 |
+
if (!expandItemId || tab === "creators") return scoped;
|
| 189 |
+
const target = dataArray.find(item => String(item.id) === String(expandItemId));
|
| 190 |
+
if (!target) return scoped;
|
| 191 |
+
return [target, ...scoped.filter(item => String(item.id) !== String(expandItemId))];
|
| 192 |
};
|
| 193 |
|
| 194 |
// ========== 渲染函数:渲染一批数据(只渲染,过滤由 _applySearchScope 统一负责)==========
|
| 195 |
+
let targetLookupStarted = false;
|
| 196 |
const renderBatch = (dataArray, append = false) => {
|
| 197 |
if (renderToken !== getRenderToken()) return;
|
| 198 |
|
|
|
|
| 213 |
emptyState.textContent = t(keyword ? 'feedback.no_search_results' : 'feedback.no_list_data');
|
| 214 |
emptyState.setAttribute('role', 'status');
|
| 215 |
contentArea.replaceChildren(emptyState);
|
| 216 |
+
if (!expandItemId) return 0;
|
| 217 |
}
|
| 218 |
|
| 219 |
// 渲染卡片
|
|
|
|
| 228 |
cards.push(card);
|
| 229 |
fragment.appendChild(card);
|
| 230 |
// 检查是否是需要展开的卡片
|
| 231 |
+
if (expandItemId && String(data.id) === String(expandItemId)) {
|
| 232 |
targetCard = card;
|
| 233 |
}
|
| 234 |
});
|
|
|
|
| 260 |
});
|
| 261 |
}
|
| 262 |
|
| 263 |
+
// 目标不在列表快照中时补取,仍使用原榜单卡片展开。
|
| 264 |
+
if (expandItemId && !targetCard && !append && !targetLookupStarted && canNavigate()) {
|
| 265 |
+
targetLookupStarted = true;
|
| 266 |
(async () => {
|
| 267 |
try {
|
| 268 |
const res = await api.getItemById(expandItemId);
|
| 269 |
if (!canNavigate()) return;
|
| 270 |
+
if (res?.status !== "success" || !res.data || String(res.data.id) !== String(expandItemId)) {
|
| 271 |
+
showToast(t('notif.item_not_found'), "error");
|
| 272 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
}
|
| 274 |
+
const target = state.allData.find(item => String(item.id) === String(expandItemId)) || proxyImages([res.data])[0];
|
| 275 |
+
state.loader?.stop();
|
| 276 |
+
state.loader = null;
|
| 277 |
+
state.allData = [target, ...state.allData.filter(item => String(item.id) !== String(expandItemId))];
|
| 278 |
+
const scoped = _applySearchScope(state.allData);
|
| 279 |
+
renderBatch(scoped.slice(0, pageSize), false);
|
| 280 |
+
if (scoped.length > pageSize) {
|
| 281 |
+
_setupPaginationLoader(contentArea, state, pageSize, loadMoreData, keyword, tab, renderToken, getRenderToken);
|
| 282 |
+
}
|
| 283 |
+
} catch (_) {
|
| 284 |
+
if (canNavigate()) showToast(t('notif.load_item_failed'), "error");
|
| 285 |
}
|
| 286 |
})();
|
| 287 |
}
|