"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_api = require("../../utils/api.js"); const utils_auth = require("../../utils/auth.js"); const _sfc_main = { __name: "index", setup(__props) { const keyword = common_vendor.ref(""); const loading = common_vendor.ref(false); const hasSearched = common_vendor.ref(false); const errorMsg = common_vendor.ref(""); const result = common_vendor.ref(null); const suggestions = common_vendor.ref([]); const showDropdown = common_vendor.ref(false); const searching = common_vendor.ref(false); const isLoggedIn = common_vendor.ref(false); let searchTimer = null; common_vendor.onMounted(() => { isLoggedIn.value = utils_auth.isLoggedIn(); }); common_vendor.onShow(() => { isLoggedIn.value = utils_auth.isLoggedIn(); common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" }); }); common_vendor.onHide(() => { showDropdown.value = false; }); const onInputFocus = () => { if (suggestions.value.length > 0) { showDropdown.value = true; } }; const onKeywordChange = (e) => { const value = e.detail.value; keyword.value = value; if (searchTimer) clearTimeout(searchTimer); if (!value || !value.trim()) { suggestions.value = []; showDropdown.value = false; return; } searching.value = true; showDropdown.value = true; searchTimer = setTimeout(async () => { try { const response = await utils_api.getSuggestions(value.trim()); if (response.code === 200 && response.data) { suggestions.value = Array.isArray(response.data) ? response.data : []; } else { suggestions.value = []; } } catch (err) { console.error("搜索建议错误:", err); suggestions.value = []; } finally { searching.value = false; } }, 300); }; const closeDropdown = () => { showDropdown.value = false; }; const onSelectSuggestion = (item) => { keyword.value = `${item.name} (${item.code})`; suggestions.value = []; showDropdown.value = false; doSearch(item.code); }; const handleSearchClick = () => { if (!isLoggedIn.value) { common_vendor.index.showModal({ title: "登录提示", content: "此功能需要登录后使用,是否前往登录?", confirmText: "去登录", cancelText: "取消", success: (res) => { if (res.confirm) { common_vendor.index.navigateTo({ url: "/pages/login/login" }); } } }); return; } onSearch(); }; const onSearch = () => { const kw = (keyword.value || "").trim(); if (!kw) { common_vendor.index.showToast({ title: "请输入股票代码或名称", icon: "none" }); return; } showDropdown.value = false; suggestions.value = []; let searchCode = kw; const codeMatch = kw.match(/\((\d{6})\)/); if (codeMatch) { searchCode = codeMatch[1]; } doSearch(searchCode); }; const doSearch = async (queryCode) => { loading.value = true; hasSearched.value = true; errorMsg.value = ""; result.value = null; showDropdown.value = false; suggestions.value = []; try { const res = await utils_api.searchStocks(queryCode); if (res.code === 200 && res.data) { result.value = res.data; } else { errorMsg.value = res.message || "未查询到相关股票数据"; } } catch (err) { errorMsg.value = "网络请求失败,请检查网络连接"; } finally { loading.value = false; } }; const getPriceClass = (changePercent) => { if (!changePercent) return ""; if (changePercent.startsWith("+")) return "price-up"; if (changePercent.startsWith("-")) return "price-down"; return ""; }; return (_ctx, _cache) => { return common_vendor.e({ a: showDropdown.value && suggestions.value.length > 0 }, showDropdown.value && suggestions.value.length > 0 ? { b: common_vendor.o(closeDropdown) } : {}, { c: common_vendor.o([($event) => keyword.value = $event.detail.value, onKeywordChange]), d: common_vendor.o(handleSearchClick), e: common_vendor.o(onInputFocus), f: keyword.value, g: common_vendor.o(handleSearchClick), h: showDropdown.value && suggestions.value.length > 0 }, showDropdown.value && suggestions.value.length > 0 ? { i: common_vendor.f(suggestions.value, (item, index, i0) => { return { a: common_vendor.t(item.name), b: common_vendor.t(item.code), c: index, d: common_vendor.o(($event) => onSelectSuggestion(item), index) }; }) } : {}, { j: showDropdown.value && searching.value }, showDropdown.value && searching.value ? {} : {}, { k: common_vendor.t(isLoggedIn.value ? "" : "(需登录)"), l: hasSearched.value }, hasSearched.value ? common_vendor.e({ m: loading.value }, loading.value ? {} : errorMsg.value ? { o: common_vendor.t(errorMsg.value) } : result.value ? common_vendor.e({ q: common_vendor.t(result.value.stockName), r: common_vendor.t(result.value.stockCode), s: common_vendor.t(result.value.currentPrice || "--"), t: common_vendor.n(getPriceClass(result.value.changePercent)), v: common_vendor.t(result.value.priceChange || "--"), w: common_vendor.t(result.value.changePercent || "--"), x: common_vendor.n(getPriceClass(result.value.changePercent)), y: result.value.currentPrice }, result.value.currentPrice ? { z: common_vendor.t(result.value.openPrice || "--"), A: common_vendor.t(result.value.highPrice || "--"), B: common_vendor.t(result.value.lowPrice || "--"), C: common_vendor.t(result.value.volume || "--"), D: common_vendor.t(result.value.amount || "--"), E: common_vendor.t(result.value.turnoverRate || "--") } : {}, { F: result.value.score }, result.value.score ? { G: common_vendor.t(result.value.score) } : {}, { H: result.value.history && result.value.history.length > 0 }, result.value.history && result.value.history.length > 0 ? { I: common_vendor.f(result.value.history, (item, idx, i0) => { return { a: common_vendor.t(item.date), b: common_vendor.t(item.score), c: common_vendor.n(item.score >= 90 ? "tag-danger" : item.score >= 80 ? "tag-success" : "tag-info"), d: idx }; }) } : {}, { J: result.value.factors && result.value.factors.length > 0 }, result.value.factors && result.value.factors.length > 0 ? { K: common_vendor.f(result.value.factors, (item, idx, i0) => { return { a: common_vendor.t(item.name), b: common_vendor.t(item.value), c: idx }; }) } : {}) : {}, { n: errorMsg.value, p: result.value }) : {}); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-83a5a03c"], ["__file", "D:/program/gupiao-wx/src/pages/index/index.vue"]]); wx.createPage(MiniProgramPage);