|
"use strict";
|
|
const common_vendor = require("../common/vendor.js");
|
|
const api_model_address = require("./model/address.js");
|
|
const api_model_index = require("./model/index.js");
|
|
const api_model_info = require("./model/info.js");
|
|
const api_model_login = require("./model/login.js");
|
|
const api_model_vip = require("./model/vip.js");
|
|
const api_http = require("./http.js");
|
|
const api_config = require("./config.js");
|
|
const limit = /* @__PURE__ */ new Map();
|
|
const debounce = /* @__PURE__ */ new Map();
|
|
const modules = /* @__PURE__ */ Object.assign({ "./model/address.js": api_model_address.__vite_glob_0_0, "./model/index.js": api_model_index.__vite_glob_0_1, "./model/info.js": api_model_info.__vite_glob_0_2, "./model/login.js": api_model_login.__vite_glob_0_3, "./model/vip.js": api_model_vip.__vite_glob_0_4 });
|
|
Object.entries(modules).forEach(([path, mod]) => {
|
|
const model = mod.default || mod;
|
|
const key = path.match(/\/([^/]+)\.js$/)[1];
|
|
for (const k in model) {
|
|
if (api_config.config[k]) {
|
|
common_vendor.index.__f__("error", "at api/api.js:18", `重名api------model=${key},key=${k}`);
|
|
continue;
|
|
}
|
|
api_config.config[k] = model[k];
|
|
}
|
|
});
|
|
function api(key, data = {}, callback, loadingTitle) {
|
|
const req = api_config.config[key];
|
|
if (!req) {
|
|
common_vendor.index.__f__("error", "at api/api.js:38", "无效key: " + key);
|
|
return Promise.reject(new Error("无效key"));
|
|
}
|
|
if (typeof callback === "string") {
|
|
loadingTitle = callback;
|
|
callback = void 0;
|
|
}
|
|
if (typeof data === "function") {
|
|
callback = data;
|
|
data = {};
|
|
}
|
|
if (req.limit) {
|
|
const last = limit.get(req.url);
|
|
if (last && Date.now() - last < req.limit) {
|
|
return Promise.reject(new Error("请求过于频繁"));
|
|
}
|
|
limit.set(req.url, Date.now());
|
|
}
|
|
if (req.auth && !common_vendor.index.getStorageSync("token")) {
|
|
return Promise.reject(new Error("需要登录"));
|
|
}
|
|
if (req.debounce) {
|
|
const prev = debounce.get(req.url);
|
|
if (prev)
|
|
clearTimeout(prev);
|
|
debounce.set(
|
|
req.url,
|
|
setTimeout(() => {
|
|
debounce.delete(req.url);
|
|
api_http.http.http(
|
|
req.url,
|
|
data,
|
|
callback,
|
|
req.method,
|
|
loadingTitle || req.showLoading,
|
|
loadingTitle || req.loadingTitle
|
|
);
|
|
}, req.debounce)
|
|
);
|
|
return Promise.reject(new Error("请求防抖中"));
|
|
}
|
|
return api_http.http.http(
|
|
req.url,
|
|
data,
|
|
callback,
|
|
req.method,
|
|
loadingTitle || req.showLoading,
|
|
loadingTitle || req.loadingTitle
|
|
);
|
|
}
|
|
exports.api = api;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/api/api.js.map
|