"use strict"; const common_vendor = require("../common/vendor.js"); const BASE_URL = "https://api.assetmanager.com"; const TIMEOUT = 1e4; const request = (url, method = "GET", data = {}, headers = {}) => { const token = common_vendor.index.getStorageSync("token"); return new Promise((resolve, reject) => { common_vendor.index.request({ url: BASE_URL + url, method, data, header: { "Content-Type": "application/json", "Authorization": token ? `Bearer ${token}` : "", ...headers }, timeout: TIMEOUT, success: (res) => { if (res.statusCode === 200) { resolve(res.data); } else if (res.statusCode === 401) { common_vendor.index.removeStorageSync("token"); common_vendor.index.removeStorageSync("userInfo"); common_vendor.index.__f__("log", "at utils/api.js:40", "登录已过期,请重新登录"); reject(new Error("登录已过期")); } else { reject(new Error(`请求失败: ${res.statusCode}`)); } }, fail: (err) => { common_vendor.index.__f__("log", "at utils/api.js:48", "API请求失败,使用模拟数据:", err); resolve(getMockData(url)); } }); }); }; const get = (url, params = {}, headers = {}) => { const queryString = Object.keys(params).map((key) => `${key}=${encodeURIComponent(params[key])}`).join("&"); const fullUrl = queryString ? `${url}?${queryString}` : url; return request(fullUrl, "GET", {}, headers); }; const post = (url, data = {}, headers = {}) => { return request(url, "POST", data, headers); }; const put = (url, data = {}, headers = {}) => { return request(url, "PUT", data, headers); }; const del = (url, params = {}, headers = {}) => { const queryString = Object.keys(params).map((key) => `${key}=${encodeURIComponent(params[key])}`).join("&"); const fullUrl = queryString ? `${url}?${queryString}` : url; return request(fullUrl, "DELETE", {}, headers); }; const getMockData = (url, method, data) => { return new Promise((resolve) => { setTimeout(() => { if (url.includes("/assets")) { resolve({ code: 200, data: { totalValue: 12845924e-1, currency: "CNY", todayProfit: 12482, todayProfitCurrency: "CNY", totalReturnRate: 24.82 }, message: "success" }); } if (url.includes("/holdings")) { resolve({ code: 200, data: [ { id: "hfea-001", name: "美股全天候杠杆", tags: "HFEA · 季度调仓", status: "监控中", statusType: "green", iconChar: "H", iconBgClass: "bg-green-100", iconTextClass: "text-green-700", value: 156240, currency: "USD", returnRate: 42.82, returnType: "positive" }, { id: "ma-002", name: "纳指双均线趋势", tags: "趋势跟踪 · 日线", status: "等待信号", statusType: "gray", iconChar: "T", iconBgClass: "bg-blue-100", iconTextClass: "text-blue-700", value: 412500, currency: "USD", returnRate: -1.79, returnType: "negative" }, { id: "hk-003", name: "港股价值投资", tags: "价值投资 · 蓝筹", status: "持有中", statusType: "green", iconChar: "H", iconBgClass: "bg-green-100", iconTextClass: "text-green-700", value: 896e3, currency: "HKD", returnRate: 12.56, returnType: "positive" } ], message: "success" }); } if (url.includes("/strategies")) { resolve({ code: 200, data: [ { id: "hfea", iconChar: "H", title: "HFEA 风险平价逻辑", tag: "高风险 · 高预期收益", desc: "针对杠杆ETF平衡的对冲策略,核心逻辑为 TMF (3x长债) 与 UPRO (3x标普) 的季度平衡。", bgClass: "bg-emerald-900", tagClass: "text-emerald-700", tags: ["季调", "止损机制"], btnText: "配置参数", btnClass: "btn-primary" }, { id: "ma", iconChar: "T", title: "双均线趋势跟随", tag: "中风险 · 低回撤要求", desc: "利用快线(EMA10)上穿慢线(EMA60)捕捉强势波段,金叉买入,死叉离场。", bgClass: "bg-blue-600", tagClass: "text-blue-700", tags: ["日线", "左侧止盈"], btnText: "预览模型", btnClass: "btn-secondary" }, { id: "chandelier", iconChar: "S", title: "吊灯止损策略", tag: "风险控制 · 辅助", desc: "基于 ATR 波动率计算的动态止损线,锁住利润,防止回撤过大。", bgClass: "bg-orange-500", tagClass: "text-orange-700", tags: ["ATR", "动态止盈"], btnText: "配置参数", btnClass: "btn-secondary" } ], message: "success" }); } if (url.includes("/user/info")) { resolve({ code: 200, data: { userName: "首席策略员 0x42", memberLevel: "全球实验室 Pro", runningDays: 412 }, message: "success" }); } if (url.includes("/user/stats")) { resolve({ code: 200, data: { signalsCaptured: 1248, winRate: 58.4 }, message: "success" }); } if (url.includes("/app/info")) { resolve({ code: 200, data: { version: "v2.4.0", currentDate: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] }, message: "success" }); } if (url.includes("/api/auth/wechat/login")) { resolve({ code: 200, data: { token: "mock-wechat-token-123456", userInfo: { id: "user-001", openid: "mock-openid-123456", nickname: "微信用户", avatar: "https://via.placeholder.com/100", memberLevel: "全球实验室 Pro", runningDays: 412 } }, message: "success" }); } if (url.includes("/api/auth/wechat/bind")) { resolve({ code: 200, data: { token: "mock-wechat-token-789012", userInfo: { id: "user-001", openid: "mock-openid-123456", email: "user@example.com", nickname: "微信用户", avatar: "https://via.placeholder.com/100", memberLevel: "全球实验室 Pro", runningDays: 412 } }, message: "success" }); } resolve({ code: 200, data: null, message: "success" }); }, 500); }); }; const api = { // 资产相关API assets: { // 获取总资产数据 getAssetData: () => get("/assets"), // 获取持仓组合数据 getHoldings: () => get("/holdings") }, // 策略相关API strategies: { // 获取策略列表 getStrategies: () => get("/strategies"), // 获取单个策略详情 getStrategyDetail: (id) => get(`/strategies/${id}`), // 创建新策略 createStrategy: (data) => post("/strategies", data), // 更新策略 updateStrategy: (id, data) => put(`/strategies/${id}`, data), // 删除策略 deleteStrategy: (id) => del(`/strategies/${id}`) }, // 用户相关API user: { // 获取用户信息 getUserInfo: () => get("/user/info"), // 获取用户统计数据 getUserStats: () => get("/user/stats"), // 更新用户信息 updateUserInfo: (data) => put("/user/info", data) }, // 认证相关API auth: { // 微信登录 wechatLogin: (code) => post("/api/auth/wechat/login", { code }), // 微信绑定 wechatBind: (data) => post("/api/auth/wechat/bind", data) }, // 应用相关API app: { // 获取应用信息 getAppInfo: () => get("/app/info") } }; exports.api = api; //# sourceMappingURL=../../.sourcemap/mp-weixin/utils/api.js.map