| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_auth = require("../../utils/auth.js");
- const utils_api = require("../../utils/api.js");
- const _sfc_main = {
- __name: "shortPool",
- setup(__props) {
- const searchKeyword = common_vendor.ref("");
- const suggestions = common_vendor.ref([]);
- const showSuggestions = common_vendor.ref(false);
- const searching = common_vendor.ref(false);
- const stockList = common_vendor.ref([]);
- const loading = common_vendor.ref(false);
- const poolType = 1;
- let searchTimer = null;
- let refreshTimer = null;
- const getToken = () => common_vendor.index.getStorageSync("user_token") || null;
- const request = (options) => {
- return new Promise((resolve, reject) => {
- const token = getToken();
- const header = options.header || {};
- if (token)
- header["Authorization"] = `Bearer ${token}`;
- common_vendor.index.request({
- url: `${utils_api.BASE_URL}${options.url}`,
- method: options.method || "GET",
- data: options.data || {},
- header,
- success: (res) => {
- var _a;
- return res.statusCode === 200 ? resolve(res.data) : reject(new Error(((_a = res.data) == null ? void 0 : _a.message) || "请求失败"));
- },
- fail: () => reject(new Error("网络异常"))
- });
- });
- };
- const handleBack = () => {
- const pages = getCurrentPages();
- pages.length > 1 ? common_vendor.index.navigateBack() : common_vendor.index.switchTab({ url: "/pages/mine/mine" });
- };
- common_vendor.onShow(() => {
- checkAdminPermission();
- loadStockList();
- startAutoRefresh();
- });
- common_vendor.onHide(() => stopAutoRefresh());
- common_vendor.onUnmounted(() => stopAutoRefresh());
- const startAutoRefresh = () => {
- stopAutoRefresh();
- refreshTimer = setInterval(() => loadStockList(true), 5e3);
- };
- const stopAutoRefresh = () => {
- if (refreshTimer) {
- clearInterval(refreshTimer);
- refreshTimer = null;
- }
- };
- const checkAdminPermission = async () => {
- const userInfo = await utils_auth.refreshUserInfo();
- if (!userInfo || userInfo.status !== 2) {
- common_vendor.index.showToast({ title: "无权限访问", icon: "none" });
- setTimeout(() => {
- const pages = getCurrentPages();
- pages.length > 1 ? common_vendor.index.navigateBack() : common_vendor.index.switchTab({ url: "/pages/mine/mine" });
- }, 1500);
- }
- };
- const loadStockList = async (silent = false) => {
- if (!silent)
- loading.value = true;
- try {
- const res = await request({ url: "/v1/stock/pool/admin/list", data: { poolType } });
- if (res.code === 200)
- stockList.value = res.data || [];
- } catch (e) {
- console.error("加载失败", e);
- } finally {
- if (!silent)
- loading.value = false;
- }
- };
- const getChangeClass = (changePercent) => {
- if (!changePercent || changePercent === "-")
- return "";
- return changePercent.startsWith("+") ? "up" : changePercent.startsWith("-") ? "down" : "";
- };
- const handleSearchInput = () => {
- if (searchTimer)
- clearTimeout(searchTimer);
- if (!searchKeyword.value.trim()) {
- suggestions.value = [];
- showSuggestions.value = false;
- return;
- }
- searching.value = true;
- showSuggestions.value = true;
- searchTimer = setTimeout(async () => {
- try {
- const res = await utils_api.getSuggestions(searchKeyword.value.trim());
- suggestions.value = res.code === 200 && res.data ? res.data : [];
- } catch (e) {
- suggestions.value = [];
- } finally {
- searching.value = false;
- }
- }, 300);
- };
- const clearSearch = () => {
- searchKeyword.value = "";
- suggestions.value = [];
- showSuggestions.value = false;
- };
- const closeSuggestions = () => showSuggestions.value = false;
- const handleAddFromSuggestion = async (item) => {
- if (stockList.value.some((s) => s.code === item.code)) {
- common_vendor.index.showToast({ title: "该股票已在超短池中", icon: "none" });
- return;
- }
- try {
- const res = await request({
- url: "/v1/stock/pool/admin/add",
- method: "POST",
- header: { "content-type": "application/json" },
- data: { stockCode: item.code, poolType }
- });
- if (res.code === 200) {
- common_vendor.index.showToast({ title: "添加成功", icon: "success" });
- clearSearch();
- loadStockList();
- } else {
- common_vendor.index.showToast({ title: res.message || "添加失败", icon: "none" });
- }
- } catch (e) {
- common_vendor.index.showToast({ title: "添加失败", icon: "none" });
- }
- };
- const handleDeleteStock = (item) => {
- common_vendor.index.showModal({
- title: "确认撤出",
- content: `确定要将 ${item.name} 从超短池撤出吗?`,
- success: async (res) => {
- if (res.confirm) {
- try {
- const result = await request({
- url: "/v1/stock/pool/admin/delete",
- method: "POST",
- header: { "content-type": "application/json" },
- data: { stockCode: item.code, poolType }
- });
- if (result.code === 200) {
- common_vendor.index.showToast({ title: "撤出成功", icon: "success" });
- loadStockList();
- } else {
- common_vendor.index.showToast({ title: result.message || "撤出失败", icon: "none" });
- }
- } catch (e) {
- common_vendor.index.showToast({ title: "撤出失败", icon: "none" });
- }
- }
- }
- });
- };
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: common_vendor.o(handleBack),
- b: common_vendor.o([($event) => searchKeyword.value = $event.detail.value, handleSearchInput]),
- c: common_vendor.o(($event) => showSuggestions.value = true),
- d: searchKeyword.value,
- e: searchKeyword.value
- }, searchKeyword.value ? {
- f: common_vendor.o(clearSearch)
- } : {}, {
- g: showSuggestions.value && suggestions.value.length > 0
- }, showSuggestions.value && suggestions.value.length > 0 ? {
- h: 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) => handleAddFromSuggestion(item), index)
- };
- })
- } : {}, {
- i: showSuggestions.value && searching.value
- }, showSuggestions.value && searching.value ? {} : {}, {
- j: showSuggestions.value && !searching.value && searchKeyword.value && suggestions.value.length === 0
- }, showSuggestions.value && !searching.value && searchKeyword.value && suggestions.value.length === 0 ? {} : {}, {
- k: showSuggestions.value && suggestions.value.length > 0
- }, showSuggestions.value && suggestions.value.length > 0 ? {
- l: common_vendor.o(closeSuggestions)
- } : {}, {
- m: common_vendor.t(stockList.value.length),
- n: loading.value && stockList.value.length === 0
- }, loading.value && stockList.value.length === 0 ? {} : stockList.value.length === 0 ? {} : {
- p: common_vendor.f(stockList.value, (item, index, i0) => {
- return {
- a: common_vendor.t(item.name),
- b: common_vendor.t(item.code),
- c: common_vendor.t(item.currentPrice || "-"),
- d: common_vendor.t(item.changePercent || "-"),
- e: common_vendor.n(getChangeClass(item.changePercent)),
- f: common_vendor.o(($event) => handleDeleteStock(item), item.code),
- g: item.code
- };
- })
- }, {
- o: stockList.value.length === 0
- });
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-98720f9d"], ["__file", "D:/program/gupiao/gupiao-wx/src/pages/admin/shortPool.vue"]]);
- wx.createPage(MiniProgramPage);
|