开单计划增加决策理由;品种联想加速;复盘支持品种匹配
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+42
-14
@@ -1,4 +1,14 @@
|
||||
(function () {
|
||||
function formatSub(item) {
|
||||
return '同花顺 ' + item.ths_code +
|
||||
(item.market_code ? ' · ' + item.market_code : '') +
|
||||
' · ' + (item.exchange || '');
|
||||
}
|
||||
|
||||
function formatInputLabel(item) {
|
||||
return item.input_label || (item.name + ' ' + item.ths_code);
|
||||
}
|
||||
|
||||
function initSymbolInput(wrapper) {
|
||||
const input = wrapper.querySelector('.symbol-input');
|
||||
const hiddenThs = wrapper.querySelector('input[name="symbol"]');
|
||||
@@ -8,19 +18,21 @@
|
||||
const dropdown = wrapper.querySelector('.symbol-dropdown');
|
||||
const selectedEl = wrapper.querySelector('.symbol-selected');
|
||||
let timer = null;
|
||||
let abortCtrl = null;
|
||||
const cache = new Map();
|
||||
|
||||
function hideDropdown() {
|
||||
dropdown.classList.remove('show');
|
||||
}
|
||||
|
||||
function selectItem(item) {
|
||||
input.value = item.name;
|
||||
const label = formatInputLabel(item);
|
||||
input.value = label;
|
||||
hiddenThs.value = item.ths_code;
|
||||
hiddenName.value = item.name;
|
||||
if (hiddenMarket) hiddenMarket.value = item.market_code || '';
|
||||
if (hiddenSina) hiddenSina.value = item.sina_code || '';
|
||||
selectedEl.textContent = '同花顺: ' + item.ths_code +
|
||||
(item.market_code ? ' (' + item.market_code + ')' : '');
|
||||
selectedEl.textContent = formatSub(item);
|
||||
hideDropdown();
|
||||
}
|
||||
|
||||
@@ -33,9 +45,7 @@
|
||||
const div = document.createElement('div');
|
||||
div.className = 'symbol-option';
|
||||
div.innerHTML = item.display +
|
||||
'<div class="sub">同花顺 ' + item.ths_code +
|
||||
(item.market_code ? ' · ' + item.market_code : '') +
|
||||
' · ' + item.exchange + '</div>';
|
||||
'<div class="sub">' + formatSub(item) + '</div>';
|
||||
div.addEventListener('mousedown', function (e) {
|
||||
e.preventDefault();
|
||||
selectItem(item);
|
||||
@@ -46,6 +56,29 @@
|
||||
dropdown.classList.add('show');
|
||||
}
|
||||
|
||||
function search(q) {
|
||||
if (cache.has(q)) {
|
||||
renderItems(cache.get(q));
|
||||
return;
|
||||
}
|
||||
if (abortCtrl) {
|
||||
abortCtrl.abort();
|
||||
}
|
||||
abortCtrl = new AbortController();
|
||||
fetch('/api/symbols/search?q=' + encodeURIComponent(q), {
|
||||
signal: abortCtrl.signal,
|
||||
})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (items) {
|
||||
cache.set(q, items);
|
||||
renderItems(items);
|
||||
})
|
||||
.catch(function (err) {
|
||||
if (err && err.name === 'AbortError') return;
|
||||
hideDropdown();
|
||||
});
|
||||
}
|
||||
|
||||
input.addEventListener('input', function () {
|
||||
hiddenThs.value = '';
|
||||
hiddenName.value = '';
|
||||
@@ -59,11 +92,8 @@
|
||||
}
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(function () {
|
||||
fetch('/api/symbols/search?q=' + encodeURIComponent(q))
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(renderItems)
|
||||
.catch(function () { hideDropdown(); });
|
||||
}, 300);
|
||||
search(q);
|
||||
}, 120);
|
||||
});
|
||||
|
||||
input.addEventListener('blur', function () {
|
||||
@@ -73,9 +103,7 @@
|
||||
input.addEventListener('focus', function () {
|
||||
const q = input.value.trim();
|
||||
if (q && !hiddenThs.value) {
|
||||
fetch('/api/symbols/search?q=' + encodeURIComponent(q))
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(renderItems);
|
||||
search(q);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user