From d978f7048d65eebe6fb90e253c7875b420458eb0 Mon Sep 17 00:00:00 2001 From: hjhan Date: Mon, 13 Jul 2026 13:30:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=97=A5=E7=BB=88=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E8=81=94=E6=83=B3=E9=80=BB=E8=BE=91=E6=8A=BD=E6=88=90?= =?UTF-8?q?=E5=85=B1=E4=BA=AB=20eodUnderlyingSuggest.js=20=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E6=8B=89=E9=9D=99=E9=BB=98=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 三编辑页重复的 eodSuggest/eodRenderSuggest/eodHideSuggest/checkSubmitData/初始化 抽成 eodUnderlyingSuggest.js 一处引用,禁止逐页复制内联脚本 - 修复静默 bug:cshtml 缺 #eodSuggestBox 容器且 class 无 CSS 导致下拉从未渲染;改为 JS 动态创建盒子+样式内联 - 修复点选 ReferenceError:回调由对象字面量求值改为 window['lookup'+kind] 安全解析+typeof 校验 --- .../Views/EodPrice/eodBondPriceEdit.cshtml | 69 +------------- .../Views/EodPrice/eodFuturePriceEdit.cshtml | 69 +------------- .../Views/EodPrice/eodStockPriceEdit.cshtml | 69 +------------- .../Scripts/app/eod/eodUnderlyingSuggest.js | 90 +++++++++++++++++++ 4 files changed, 93 insertions(+), 204 deletions(-) create mode 100644 YLErpWeb/wwwroot/Scripts/app/eod/eodUnderlyingSuggest.js diff --git a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml index 417f5c25..923f7313 100644 --- a/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodBondPriceEdit.cshtml @@ -6,17 +6,8 @@ } @section JS { + }
diff --git a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml index 966f360a..5e6400c7 100644 --- a/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodFuturePriceEdit.cshtml @@ -6,17 +6,8 @@ } @section JS { + } diff --git a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml index b7403e24..923c7f24 100644 --- a/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml +++ b/YLErpWeb/Views/EodPrice/eodStockPriceEdit.cshtml @@ -6,17 +6,8 @@ } @section JS { + } diff --git a/YLErpWeb/wwwroot/Scripts/app/eod/eodUnderlyingSuggest.js b/YLErpWeb/wwwroot/Scripts/app/eod/eodUnderlyingSuggest.js new file mode 100644 index 00000000..1c806676 --- /dev/null +++ b/YLErpWeb/wwwroot/Scripts/app/eod/eodUnderlyingSuggest.js @@ -0,0 +1,90 @@ +// 日终价格编辑页公共逻辑:标的代码输入联想(服务端模糊匹配 + 原生下拉) +// 由 eodBondPriceEdit / eodFuturePriceEdit / eodStockPriceEdit 三个页面共用,避免重复代码。 +// 下拉盒子由本文件动态创建、样式全部内联,不依赖任何 HTML 容器或外部 CSS。 + +$(function () { + $(".datepicker").datepicker({ changeMonth: true, changeYear: true, showButtonPanel: true, showOtherMonths: true, selectOtherMonths: true }); + $(".form-group").addClass("col-md-6"); + ensureEodSuggestBox(); +}); + +function checkSubmitData() { + var pass = $('#form1').valid(); + return pass; +} + +var _eodSuggestTimer = null; +var _eodSuggestActiveInput = null; + +function ensureEodSuggestBox() { + if (document.getElementById('eodSuggestBox')) return; + var box = document.createElement('div'); + box.id = 'eodSuggestBox'; + box.style.cssText = 'display:none;position:fixed;z-index:9999;background:#fff;border:1px solid #ccc;' + + 'max-height:240px;overflow:auto;box-shadow:0 2px 8px rgba(0,0,0,.15);font-size:13px;'; + document.body.appendChild(box); +} + +// 服务端模糊联想:输入时按需查前20条匹配(代码或名称),原生下拉,不用插件 +function eodSuggest(input, kind) { + _eodSuggestActiveInput = input; + clearTimeout(_eodSuggestTimer); + var q = (input.value || '').trim(); + if (q.length < 1) { eodHideSuggest(); return; } + _eodSuggestTimer = setTimeout(function () { + main.post('/eodPrice/SuggestUnderlyingForEod', { q: q, kind: kind }).done(function (res) { + if (res.success && res.obj && res.obj.length) { + eodRenderSuggest(res.obj, input, kind); + } else { + eodHideSuggest(); + } + }); + }, 250); +} + +function eodRenderSuggest(list, input, kind) { + var box = document.getElementById('eodSuggestBox'); + if (!box) return; + box.innerHTML = ''; + list.forEach(function (item) { + var div = document.createElement('div'); + div.style.cssText = 'padding:6px 10px;cursor:pointer;white-space:nowrap;border-bottom:1px solid #f0f0f0;'; + div.onmouseenter = function () { div.style.background = '#f2f6ff'; }; + div.onmouseleave = function () { div.style.background = '#fff'; }; + + var code = document.createElement('span'); + code.style.cssText = 'display:inline-block;min-width:90px;font-weight:600;color:#333;'; + code.textContent = item.Code; + var name = document.createElement('span'); + name.style.cssText = 'display:inline-block;color:#888;margin-left:10px;'; + name.textContent = item.Name || ''; + + div.appendChild(code); div.appendChild(name); + div.onmousedown = function (e) { + e.preventDefault(); + input.value = item.Code; + eodHideSuggest(); + // 按 kind 安全解析各页面自定义的 lookup 回调(函数名字符串,避免引用未定义函数导致 ReferenceError) + var fnName = { bond: 'lookupBond', future: 'lookupFuture', stock: 'lookupStock' }[kind]; + if (fnName && typeof window[fnName] === 'function') window[fnName](); + }; + box.appendChild(div); + }); + var r = input.getBoundingClientRect(); + box.style.left = r.left + 'px'; + box.style.top = (r.bottom + 2) + 'px'; + box.style.width = Math.max(r.width, 240) + 'px'; + box.style.display = 'block'; +} + +function eodHideSuggest() { + var b = document.getElementById('eodSuggestBox'); + if (b) b.style.display = 'none'; +} + +document.addEventListener('click', function (e) { + var b = document.getElementById('eodSuggestBox'); + if (b && b.style.display === 'block' && !b.contains(e.target) && e.target !== _eodSuggestActiveInput) { + b.style.display = 'none'; + } +});