|
|
@@ -12,63 +12,21 @@ const _sfc_main = {
|
|
|
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;
|
|
|
+ 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: "量化交易大师" });
|
|
|
});
|
|
|
- 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 = () => {
|
|
|
+ const handleSearchClick = async () => {
|
|
|
+ console.log("=== 点击搜索按钮 ===");
|
|
|
+ console.log("当前登录状态:", isLoggedIn.value);
|
|
|
if (!isLoggedIn.value) {
|
|
|
+ console.log("未登录,跳转到登录页");
|
|
|
common_vendor.index.showModal({
|
|
|
title: "登录提示",
|
|
|
content: "此功能需要登录后使用,是否前往登录?",
|
|
|
@@ -76,22 +34,63 @@ const _sfc_main = {
|
|
|
cancelText: "取消",
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
- common_vendor.index.navigateTo({ url: "/pages/login/login" });
|
|
|
+ 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" });
|
|
|
+ common_vendor.index.showToast({
|
|
|
+ title: "请输入股票代码或名称",
|
|
|
+ icon: "none"
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
- showDropdown.value = false;
|
|
|
- suggestions.value = [];
|
|
|
let searchCode = kw;
|
|
|
const codeMatch = kw.match(/\((\d{6})\)/);
|
|
|
if (codeMatch) {
|
|
|
@@ -104,8 +103,8 @@ const _sfc_main = {
|
|
|
hasSearched.value = true;
|
|
|
errorMsg.value = "";
|
|
|
result.value = null;
|
|
|
- showDropdown.value = false;
|
|
|
suggestions.value = [];
|
|
|
+ showDropdown.value = false;
|
|
|
try {
|
|
|
const res = await utils_api.searchStocks(queryCode);
|
|
|
if (res.code === 200 && res.data) {
|
|
|
@@ -119,6 +118,11 @@ const _sfc_main = {
|
|
|
loading.value = false;
|
|
|
}
|
|
|
};
|
|
|
+ const onInputBlur = () => {
|
|
|
+ setTimeout(() => {
|
|
|
+ showDropdown.value = false;
|
|
|
+ }, 300);
|
|
|
+ };
|
|
|
const getPriceClass = (changePercent) => {
|
|
|
if (!changePercent)
|
|
|
return "";
|
|
|
@@ -130,18 +134,14 @@ const _sfc_main = {
|
|
|
};
|
|
|
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) => {
|
|
|
+ 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),
|
|
|
@@ -150,61 +150,59 @@ const _sfc_main = {
|
|
|
};
|
|
|
})
|
|
|
} : {}, {
|
|
|
- j: showDropdown.value && searching.value
|
|
|
- }, showDropdown.value && searching.value ? {} : {}, {
|
|
|
- k: common_vendor.t(isLoggedIn.value ? "" : "(需登录)"),
|
|
|
- l: hasSearched.value
|
|
|
+ h: common_vendor.t(isLoggedIn.value ? "" : "(需登录)"),
|
|
|
+ i: hasSearched.value
|
|
|
}, hasSearched.value ? common_vendor.e({
|
|
|
- m: loading.value
|
|
|
+ j: loading.value
|
|
|
}, loading.value ? {} : errorMsg.value ? {
|
|
|
- o: common_vendor.t(errorMsg.value)
|
|
|
+ l: 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 || "--"),
|
|
|
+ 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: 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
|
|
|
+ v: 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 || "--")
|
|
|
+ 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 || "--")
|
|
|
} : {}, {
|
|
|
- F: result.value.score
|
|
|
+ C: result.value.score
|
|
|
}, result.value.score ? {
|
|
|
- G: common_vendor.t(result.value.score)
|
|
|
+ D: common_vendor.t(result.value.score)
|
|
|
} : {}, {
|
|
|
- H: result.value.history && result.value.history.length > 0
|
|
|
+ E: 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) => {
|
|
|
+ F: 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: idx
|
|
|
+ d: index
|
|
|
};
|
|
|
})
|
|
|
} : {}, {
|
|
|
- J: result.value.factors && result.value.factors.length > 0
|
|
|
+ G: 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) => {
|
|
|
+ H: common_vendor.f(result.value.factors, (item, index, i0) => {
|
|
|
return {
|
|
|
a: common_vendor.t(item.name),
|
|
|
b: common_vendor.t(item.value),
|
|
|
- c: idx
|
|
|
+ c: index
|
|
|
};
|
|
|
})
|
|
|
} : {}) : {}, {
|
|
|
- n: errorMsg.value,
|
|
|
- p: result.value
|
|
|
+ k: errorMsg.value,
|
|
|
+ m: 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"]]);
|
|
|
+const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/program/gupiao/gupiao-wx/src/pages/index/index.vue"]]);
|
|
|
wx.createPage(MiniProgramPage);
|