"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 historyData = common_vendor.ref(null); const suggestions = common_vendor.ref([]); const showDropdown = common_vendor.ref(false); const isLoggedIn = common_vendor.ref(false); let timer = null; common_vendor.onMounted(() => { isLoggedIn.value = utils_auth.isLoggedIn(); console.log("[首页] 登录状态:", isLoggedIn.value); }); common_vendor.onShow(() => { isLoggedIn.value = utils_auth.isLoggedIn(); common_vendor.index.setNavigationBarTitle({ title: "量化交易大师" }); }); const handleSearchClick = async () => { console.log("=== 点击搜索按钮 ==="); console.log("当前登录状态:", isLoggedIn.value); if (!isLoggedIn.value) { console.log("未登录,跳转到登录页"); common_vendor.index.showModal({ title: "登录提示", content: "此功能需要登录后使用,是否前往登录?", confirmText: "去登录", cancelText: "取消", success: (res) => { if (res.confirm) { common_vendor.index.navigateTo({ url: "/pages/login/login" }); } } }); return; } console.log("已登录,执行搜索"); onSearch(); }; const onKeywordChange = (e) => { const value = e.detail.value; keyword.value = value; console.log("输入关键词:", value); if (timer) { clearTimeout(timer); } timer = setTimeout(() => { doSearchSuggestions(value); }, 500); }; const doSearchSuggestions = async (kw) => { if (!kw || !kw.trim()) { suggestions.value = []; showDropdown.value = false; return; } try { const response = await utils_api.getSuggestions(kw.trim()); console.log("模糊查询返回数据:", response); const list = response.code === 200 && response.data ? response.data : []; suggestions.value = Array.isArray(list) ? list : []; showDropdown.value = suggestions.value.length > 0; console.log("下拉框状态:", { showDropdown: showDropdown.value, suggestionsLength: suggestions.value.length }); } catch (err) { console.error("模糊查询错误:", err); suggestions.value = []; showDropdown.value = false; } }; const onSelectSuggestion = (item) => { const searchText = `${item.name} (${item.code})`; keyword.value = searchText; suggestions.value = []; showDropdown.value = false; doSearch(item.code); }; const onSearch = () => { const kw = (keyword.value || "").trim(); if (!kw) { common_vendor.index.showToast({ title: "请输入股票代码或名称", icon: "none" }); return; } 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; historyData.value = null; suggestions.value = []; showDropdown.value = false; try { const [stockRes, historyRes] = await Promise.all([ utils_api.searchStocks(queryCode), utils_api.searchStockHistory(queryCode) ]); if (stockRes.code === 200 && stockRes.data) { result.value = stockRes.data; } else { errorMsg.value = stockRes.message || "未查询到相关股票数据"; } if (historyRes.code === 200 && historyRes.data && historyRes.data.found) { historyData.value = historyRes.data; console.log("历史数据:", historyData.value); } } catch (err) { errorMsg.value = "网络请求失败,请检查网络连接"; } finally { loading.value = false; } }; const onInputBlur = () => { setTimeout(() => { showDropdown.value = false; }, 300); }; const getPriceClass = (changePercent) => { if (!changePercent) return ""; if (changePercent.startsWith("+")) return "price-up"; if (changePercent.startsWith("-")) return "price-down"; return ""; }; const getChangeClass = (value) => { if (value === null || value === void 0) return ""; const num = parseFloat(value); if (num > 0) return "price-up"; if (num < 0) return "price-down"; return ""; }; const formatPercent = (value) => { if (value === null || value === void 0) return "--"; const num = parseFloat(value); const prefix = num > 0 ? "+" : ""; return `${prefix}${num.toFixed(2)}%`; }; const formatAmount = (value) => { if (!value) return "--"; const num = parseFloat(value); if (num >= 1e8) { return (num / 1e8).toFixed(2) + "亿"; } else if (num >= 1e4) { return (num / 1e4).toFixed(2) + "万"; } return num.toFixed(2); }; const formatStrengthScore = (value) => { if (value === null || value === void 0) return "--"; const num = parseFloat(value); const prefix = num >= 0 ? "+" : ""; return `${prefix}${num.toFixed(2)}`; }; return (_ctx, _cache) => { return common_vendor.e({ a: common_vendor.o([($event) => keyword.value = $event.detail.value, onKeywordChange]), b: common_vendor.o(handleSearchClick), c: common_vendor.o(onInputBlur), d: keyword.value, e: common_vendor.o(handleSearchClick), f: showDropdown.value && suggestions.value && suggestions.value.length > 0 }, showDropdown.value && suggestions.value && suggestions.value.length > 0 ? { g: 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) }; }) } : {}, { h: common_vendor.t(isLoggedIn.value ? "" : "(需登录)"), i: hasSearched.value }, hasSearched.value ? common_vendor.e({ j: loading.value }, loading.value ? {} : errorMsg.value ? { l: common_vendor.t(errorMsg.value) } : result.value ? common_vendor.e({ n: common_vendor.t(result.value.stockName), o: common_vendor.t(result.value.stockCode), p: common_vendor.t(result.value.currentPrice || "--"), q: common_vendor.n(getPriceClass(result.value.changePercent)), r: common_vendor.t(result.value.priceChange || "--"), s: common_vendor.t(result.value.changePercent || "--"), t: common_vendor.n(getPriceClass(result.value.changePercent)), v: result.value.currentPrice }, result.value.currentPrice ? { w: common_vendor.t(result.value.openPrice || "--"), x: common_vendor.t(result.value.highPrice || "--"), y: common_vendor.t(result.value.lowPrice || "--"), z: common_vendor.t(result.value.volume || "--"), A: common_vendor.t(result.value.amount || "--"), B: common_vendor.t(result.value.turnoverRate || "--") } : {}, { C: result.value.score }, result.value.score ? { D: common_vendor.t(result.value.score) } : {}, { E: historyData.value && (historyData.value.strengthScore !== null || historyData.value.highTrend !== null) }, historyData.value && (historyData.value.strengthScore !== null || historyData.value.highTrend !== null) ? common_vendor.e({ F: common_vendor.t(historyData.value.recordDate), G: historyData.value.strengthScore !== null && historyData.value.strengthScore !== void 0 }, historyData.value.strengthScore !== null && historyData.value.strengthScore !== void 0 ? { H: common_vendor.t(formatStrengthScore(historyData.value.strengthScore)), I: common_vendor.n(historyData.value.strengthScore >= 0 ? "capsule-up" : "capsule-down") } : {}, { J: historyData.value.closePrice }, historyData.value.closePrice ? { K: common_vendor.t(historyData.value.closePrice) } : {}, { L: historyData.value.changePercent }, historyData.value.changePercent ? { M: common_vendor.t(formatPercent(historyData.value.changePercent)), N: common_vendor.n(getChangeClass(historyData.value.changePercent)) } : {}, { O: historyData.value.totalAmount }, historyData.value.totalAmount ? { P: common_vendor.t(formatAmount(historyData.value.totalAmount)) } : {}, { Q: historyData.value.circulationMarketValue }, historyData.value.circulationMarketValue ? { R: common_vendor.t(formatAmount(historyData.value.circulationMarketValue)) } : {}, { S: historyData.value.mainRisePeriod }, historyData.value.mainRisePeriod ? { T: common_vendor.t(historyData.value.mainRisePeriod) } : {}, { U: historyData.value.recentLimitUp }, historyData.value.recentLimitUp ? { V: common_vendor.t(historyData.value.recentLimitUp) } : {}, { W: historyData.value.highTrend !== null && historyData.value.highTrend !== void 0 }, historyData.value.highTrend !== null && historyData.value.highTrend !== void 0 ? common_vendor.e({ X: historyData.value.dayHighestPrice }, historyData.value.dayHighestPrice ? { Y: common_vendor.t(historyData.value.dayHighestPrice) } : {}, { Z: historyData.value.dayLowestPrice }, historyData.value.dayLowestPrice ? { aa: common_vendor.t(historyData.value.dayLowestPrice) } : {}, { ab: historyData.value.dayClosePrice }, historyData.value.dayClosePrice ? { ac: common_vendor.t(historyData.value.dayClosePrice) } : {}, { ad: common_vendor.t(formatPercent(historyData.value.highTrend)), ae: common_vendor.n(getChangeClass(historyData.value.highTrend)) }) : {}) : {}, { af: result.value.history && result.value.history.length > 0 }, result.value.history && result.value.history.length > 0 ? { ag: common_vendor.f(result.value.history, (item, index, 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: index }; }) } : {}, { ah: result.value.factors && result.value.factors.length > 0 }, result.value.factors && result.value.factors.length > 0 ? { ai: common_vendor.f(result.value.factors, (item, index, i0) => { return { a: common_vendor.t(item.name), b: common_vendor.t(item.value), c: index }; }) } : {}) : {}, { k: errorMsg.value, m: result.value }) : {}); }; } }; const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao/gupiao-wx/src/pages/index/index.vue"]]); wx.createPage(MiniProgramPage);