fix: 推荐品种下拉改用缓存 main_code,避免加载卡住。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+35
-13
@@ -1,4 +1,35 @@
|
||||
(function () {
|
||||
var recommendedGroupsCache = null;
|
||||
var recommendedGroupsPromise = null;
|
||||
|
||||
function loadRecommendedGroups() {
|
||||
if (recommendedGroupsCache) {
|
||||
return Promise.resolve(recommendedGroupsCache);
|
||||
}
|
||||
if (recommendedGroupsPromise) {
|
||||
return recommendedGroupsPromise;
|
||||
}
|
||||
recommendedGroupsPromise = fetch('/api/symbols/recommended')
|
||||
.then(function (r) {
|
||||
if (!r.ok) {
|
||||
throw new Error('HTTP ' + r.status);
|
||||
}
|
||||
return r.json();
|
||||
})
|
||||
.then(function (groups) {
|
||||
recommendedGroupsCache = Array.isArray(groups) ? groups : [];
|
||||
return recommendedGroupsCache;
|
||||
})
|
||||
.catch(function () {
|
||||
recommendedGroupsCache = null;
|
||||
throw new Error('load failed');
|
||||
})
|
||||
.finally(function () {
|
||||
recommendedGroupsPromise = null;
|
||||
});
|
||||
return recommendedGroupsPromise;
|
||||
}
|
||||
|
||||
function formatSub(item) {
|
||||
var sub = '同花顺 ' + item.ths_code +
|
||||
(item.market_code ? ' · ' + item.market_code : '') +
|
||||
@@ -47,7 +78,6 @@
|
||||
let abortCtrl = null;
|
||||
const cache = new Map();
|
||||
let mainsCache = null;
|
||||
let mainsLoading = false;
|
||||
|
||||
function hideDropdown() {
|
||||
dropdown.classList.remove('show');
|
||||
@@ -135,16 +165,9 @@
|
||||
renderGrouped(mainsCache, q);
|
||||
return;
|
||||
}
|
||||
if (mainsLoading) {
|
||||
dropdown.innerHTML = '<div class="symbol-option">正在加载推荐品种…</div>';
|
||||
dropdown.classList.add('show');
|
||||
return;
|
||||
}
|
||||
mainsLoading = true;
|
||||
dropdown.innerHTML = '<div class="symbol-option">正在加载推荐品种…</div>';
|
||||
dropdown.classList.add('show');
|
||||
fetch('/api/symbols/recommended')
|
||||
.then(function (r) { return r.json(); })
|
||||
loadRecommendedGroups()
|
||||
.then(function (groups) {
|
||||
mainsCache = groups;
|
||||
if (!groups.length) {
|
||||
@@ -156,10 +179,9 @@
|
||||
showMarketMains(filterQ, onEmpty);
|
||||
})
|
||||
.catch(function () {
|
||||
hideDropdown();
|
||||
})
|
||||
.finally(function () {
|
||||
mainsLoading = false;
|
||||
dropdown.innerHTML =
|
||||
'<div class="symbol-option">推荐品种加载失败,请刷新页面或输入合约代码搜索</div>';
|
||||
dropdown.classList.add('show');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user