first commit

This commit is contained in:
PC-202306242200\Administrator
2026-03-28 23:09:02 +08:00
commit dac42e3b0c
3512 changed files with 181637 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
"use strict";
const common_vendor = require("../../../../../common/vendor.js");
const uni_modules_uviewPlus_libs_luchRequest_helpers_buildURL = require("../helpers/buildURL.js");
const uni_modules_uviewPlus_libs_luchRequest_core_buildFullPath = require("../core/buildFullPath.js");
const uni_modules_uviewPlus_libs_luchRequest_core_settle = require("../core/settle.js");
const uni_modules_uviewPlus_libs_luchRequest_utils = require("../utils.js");
const mergeKeys = (keys, config2) => {
const config = {};
keys.forEach((prop) => {
if (!uni_modules_uviewPlus_libs_luchRequest_utils.isUndefined(config2[prop])) {
config[prop] = config2[prop];
}
});
return config;
};
const adapter = (config) => new Promise((resolve, reject) => {
const fullPath = uni_modules_uviewPlus_libs_luchRequest_helpers_buildURL.buildURL(uni_modules_uviewPlus_libs_luchRequest_core_buildFullPath.buildFullPath(config.baseURL, config.url), config.params);
const _config = {
url: fullPath,
header: config.header,
complete: (response) => {
config.fullPath = fullPath;
response.config = config;
try {
if (typeof response.data === "string") {
response.data = JSON.parse(response.data);
}
} catch (e) {
}
uni_modules_uviewPlus_libs_luchRequest_core_settle.settle(resolve, reject, response);
}
};
let requestTask;
if (config.method === "UPLOAD") {
delete _config.header["content-type"];
delete _config.header["Content-Type"];
const otherConfig = {
filePath: config.filePath,
name: config.name
};
const optionalKeys = [
"formData"
];
requestTask = common_vendor.index.uploadFile({ ..._config, ...otherConfig, ...mergeKeys(optionalKeys, config) });
} else if (config.method === "DOWNLOAD") {
requestTask = common_vendor.index.downloadFile(_config);
} else {
const optionalKeys = [
"data",
"method",
"timeout",
"dataType",
"responseType"
];
requestTask = common_vendor.index.request({ ..._config, ...mergeKeys(optionalKeys, config) });
}
if (config.getTask) {
config.getTask(requestTask, config);
}
});
exports.adapter = adapter;

View File

@@ -0,0 +1,24 @@
"use strict";
function InterceptorManager() {
this.handlers = [];
}
InterceptorManager.prototype.use = function use(fulfilled, rejected) {
this.handlers.push({
fulfilled,
rejected
});
return this.handlers.length - 1;
};
InterceptorManager.prototype.eject = function eject(id) {
if (this.handlers[id]) {
this.handlers[id] = null;
}
};
InterceptorManager.prototype.forEach = function forEach(fn) {
this.handlers.forEach((h) => {
if (h !== null) {
fn(h);
}
});
};
exports.InterceptorManager = InterceptorManager;

View File

@@ -0,0 +1,144 @@
"use strict";
const uni_modules_uviewPlus_libs_luchRequest_core_dispatchRequest = require("./dispatchRequest.js");
const uni_modules_uviewPlus_libs_luchRequest_core_InterceptorManager = require("./InterceptorManager.js");
const uni_modules_uviewPlus_libs_luchRequest_core_mergeConfig = require("./mergeConfig.js");
const uni_modules_uviewPlus_libs_luchRequest_core_defaults = require("./defaults.js");
const uni_modules_uviewPlus_libs_luchRequest_utils = require("../utils.js");
const uni_modules_uviewPlus_libs_luchRequest_utils_clone = require("../utils/clone.js");
class Request {
/**
* @param {Object} arg - 全局配置
* @param {String} arg.baseURL - 全局根路径
* @param {Object} arg.header - 全局header
* @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 全局默认请求方式
* @param {String} arg.dataType = [json] - 全局默认的dataType
* @param {String} arg.responseType = [text|arraybuffer] - 全局默认的responseType。支付宝小程序不支持
* @param {Object} arg.custom - 全局默认的自定义参数
* @param {Number} arg.timeout - 全局默认的超时时间,单位 ms。默认60000。H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序2.10.0)、支付宝小程序
* @param {Boolean} arg.sslVerify - 全局默认的是否验证 ssl 证书。默认true.仅App安卓端支持HBuilderX 2.3.3+
* @param {Boolean} arg.withCredentials - 全局默认的跨域请求时是否携带凭证cookies。默认false。仅H5支持HBuilderX 2.6.15+
* @param {Boolean} arg.firstIpv4 - 全DNS解析时优先使用ipv4。默认false。仅 App-Android 支持 (HBuilderX 2.8.0+)
* @param {Function(statusCode):Boolean} arg.validateStatus - 全局默认的自定义验证器。默认statusCode >= 200 && statusCode < 300
*/
constructor(arg = {}) {
if (!uni_modules_uviewPlus_libs_luchRequest_utils.isPlainObject(arg)) {
arg = {};
console.warn("设置全局参数必须接收一个Object");
}
this.config = uni_modules_uviewPlus_libs_luchRequest_utils_clone.clone({ ...uni_modules_uviewPlus_libs_luchRequest_core_defaults.defaults, ...arg });
this.interceptors = {
request: new uni_modules_uviewPlus_libs_luchRequest_core_InterceptorManager.InterceptorManager(),
response: new uni_modules_uviewPlus_libs_luchRequest_core_InterceptorManager.InterceptorManager()
};
}
/**
* @Function
* @param {Request~setConfigCallback} f - 设置全局默认配置
*/
setConfig(f) {
this.config = f(this.config);
}
middleware(config) {
config = uni_modules_uviewPlus_libs_luchRequest_core_mergeConfig.mergeConfig(this.config, config);
const chain = [uni_modules_uviewPlus_libs_luchRequest_core_dispatchRequest.dispatchRequest, void 0];
let promise = Promise.resolve(config);
this.interceptors.request.forEach((interceptor) => {
chain.unshift(interceptor.fulfilled, interceptor.rejected);
});
this.interceptors.response.forEach((interceptor) => {
chain.push(interceptor.fulfilled, interceptor.rejected);
});
while (chain.length) {
promise = promise.then(chain.shift(), chain.shift());
}
return promise;
}
/**
* @Function
* @param {Object} config - 请求配置项
* @prop {String} options.url - 请求路径
* @prop {Object} options.data - 请求参数
* @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 响应的数据类型
* @prop {Object} [options.dataType = config.dataType] - 如果设为 json会尝试对返回的数据做一次 JSON.parse
* @prop {Object} [options.header = config.header] - 请求header
* @prop {Object} [options.method = config.method] - 请求方法
* @returns {Promise<unknown>}
*/
request(config = {}) {
return this.middleware(config);
}
get(url, options = {}) {
return this.middleware({
url,
method: "GET",
...options
});
}
post(url, data, options = {}) {
return this.middleware({
url,
data,
method: "POST",
...options
});
}
put(url, data, options = {}) {
return this.middleware({
url,
data,
method: "PUT",
...options
});
}
delete(url, data, options = {}) {
return this.middleware({
url,
data,
method: "DELETE",
...options
});
}
connect(url, data, options = {}) {
return this.middleware({
url,
data,
method: "CONNECT",
...options
});
}
head(url, data, options = {}) {
return this.middleware({
url,
data,
method: "HEAD",
...options
});
}
options(url, data, options = {}) {
return this.middleware({
url,
data,
method: "OPTIONS",
...options
});
}
trace(url, data, options = {}) {
return this.middleware({
url,
data,
method: "TRACE",
...options
});
}
upload(url, config = {}) {
config.url = url;
config.method = "UPLOAD";
return this.middleware(config);
}
download(url, config = {}) {
config.url = url;
config.method = "DOWNLOAD";
return this.middleware(config);
}
}
exports.Request = Request;

View File

@@ -0,0 +1,10 @@
"use strict";
const uni_modules_uviewPlus_libs_luchRequest_helpers_isAbsoluteURL = require("../helpers/isAbsoluteURL.js");
const uni_modules_uviewPlus_libs_luchRequest_helpers_combineURLs = require("../helpers/combineURLs.js");
function buildFullPath(baseURL, requestedURL) {
if (baseURL && !uni_modules_uviewPlus_libs_luchRequest_helpers_isAbsoluteURL.isAbsoluteURL(requestedURL)) {
return uni_modules_uviewPlus_libs_luchRequest_helpers_combineURLs.combineURLs(baseURL, requestedURL);
}
return requestedURL;
}
exports.buildFullPath = buildFullPath;

View File

@@ -0,0 +1,14 @@
"use strict";
const defaults = {
baseURL: "",
header: {},
method: "GET",
dataType: "json",
responseType: "text",
custom: {},
timeout: 6e4,
validateStatus: function validateStatus(status) {
return status >= 200 && status < 300;
}
};
exports.defaults = defaults;

View File

@@ -0,0 +1,4 @@
"use strict";
const uni_modules_uviewPlus_libs_luchRequest_adapters_index = require("../adapters/index.js");
const dispatchRequest = (config) => uni_modules_uviewPlus_libs_luchRequest_adapters_index.adapter(config);
exports.dispatchRequest = dispatchRequest;

View File

@@ -0,0 +1,52 @@
"use strict";
const uni_modules_uviewPlus_libs_luchRequest_utils = require("../utils.js");
const mergeKeys = (keys, globalsConfig, config2) => {
const config = {};
keys.forEach((prop) => {
if (!uni_modules_uviewPlus_libs_luchRequest_utils.isUndefined(config2[prop])) {
config[prop] = config2[prop];
} else if (!uni_modules_uviewPlus_libs_luchRequest_utils.isUndefined(globalsConfig[prop])) {
config[prop] = globalsConfig[prop];
}
});
return config;
};
const mergeConfig = (globalsConfig, config2 = {}) => {
const method = config2.method || globalsConfig.method || "GET";
let config = {
baseURL: globalsConfig.baseURL || "",
method,
url: config2.url || "",
params: config2.params || {},
custom: { ...globalsConfig.custom || {}, ...config2.custom || {} },
header: uni_modules_uviewPlus_libs_luchRequest_utils.deepMerge(globalsConfig.header || {}, config2.header || {})
};
const defaultToConfig2Keys = ["getTask", "validateStatus"];
config = { ...config, ...mergeKeys(defaultToConfig2Keys, globalsConfig, config2) };
if (method === "DOWNLOAD")
;
else if (method === "UPLOAD") {
delete config.header["content-type"];
delete config.header["Content-Type"];
const uploadKeys = [
"filePath",
"name",
"formData"
];
uploadKeys.forEach((prop) => {
if (!uni_modules_uviewPlus_libs_luchRequest_utils.isUndefined(config2[prop])) {
config[prop] = config2[prop];
}
});
} else {
const defaultsKeys = [
"data",
"timeout",
"dataType",
"responseType"
];
config = { ...config, ...mergeKeys(defaultsKeys, globalsConfig, config2) };
}
return config;
};
exports.mergeConfig = mergeConfig;

View File

@@ -0,0 +1,11 @@
"use strict";
function settle(resolve, reject, response) {
const { validateStatus } = response.config;
const status = response.statusCode;
if (status && (!validateStatus || validateStatus(status))) {
resolve(response);
} else {
reject(response);
}
}
exports.settle = settle;

View File

@@ -0,0 +1,44 @@
"use strict";
const uni_modules_uviewPlus_libs_luchRequest_utils = require("../utils.js");
function encode(val) {
return encodeURIComponent(val).replace(/%40/gi, "@").replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
}
function buildURL(url, params) {
if (!params) {
return url;
}
let serializedParams;
if (uni_modules_uviewPlus_libs_luchRequest_utils.isURLSearchParams(params)) {
serializedParams = params.toString();
} else {
const parts = [];
uni_modules_uviewPlus_libs_luchRequest_utils.forEach(params, (val, key) => {
if (val === null || typeof val === "undefined") {
return;
}
if (uni_modules_uviewPlus_libs_luchRequest_utils.isArray(val)) {
key = `${key}[]`;
} else {
val = [val];
}
uni_modules_uviewPlus_libs_luchRequest_utils.forEach(val, (v) => {
if (uni_modules_uviewPlus_libs_luchRequest_utils.isDate(v)) {
v = v.toISOString();
} else if (uni_modules_uviewPlus_libs_luchRequest_utils.isObject(v)) {
v = JSON.stringify(v);
}
parts.push(`${encode(key)}=${encode(v)}`);
});
});
serializedParams = parts.join("&");
}
if (serializedParams) {
const hashmarkIndex = url.indexOf("#");
if (hashmarkIndex !== -1) {
url = url.slice(0, hashmarkIndex);
}
url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
}
return url;
}
exports.buildURL = buildURL;

View File

@@ -0,0 +1,5 @@
"use strict";
function combineURLs(baseURL, relativeURL) {
return relativeURL ? `${baseURL.replace(/\/+$/, "")}/${relativeURL.replace(/^\/+/, "")}` : baseURL;
}
exports.combineURLs = combineURLs;

View File

@@ -0,0 +1,5 @@
"use strict";
function isAbsoluteURL(url) {
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
}
exports.isAbsoluteURL = isAbsoluteURL;

View File

@@ -0,0 +1,2 @@
"use strict";
const uni_modules_uviewPlus_libs_luchRequest_core_Request = require("./core/Request.js");

View File

@@ -0,0 +1,63 @@
"use strict";
const { toString } = Object.prototype;
function isArray(val) {
return toString.call(val) === "[object Array]";
}
function isObject(val) {
return val !== null && typeof val === "object";
}
function isDate(val) {
return toString.call(val) === "[object Date]";
}
function isURLSearchParams(val) {
return typeof URLSearchParams !== "undefined" && val instanceof URLSearchParams;
}
function forEach(obj, fn) {
if (obj === null || typeof obj === "undefined") {
return;
}
if (typeof obj !== "object") {
obj = [obj];
}
if (isArray(obj)) {
for (let i = 0, l = obj.length; i < l; i++) {
fn.call(null, obj[i], i, obj);
}
} else {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
fn.call(null, obj[key], key, obj);
}
}
}
}
function isPlainObject(obj) {
return Object.prototype.toString.call(obj) === "[object Object]";
}
function deepMerge() {
const result = {};
function assignValue(val, key) {
if (typeof result[key] === "object" && typeof val === "object") {
result[key] = deepMerge(result[key], val);
} else if (typeof val === "object") {
result[key] = deepMerge({}, val);
} else {
result[key] = val;
}
}
for (let i = 0, l = arguments.length; i < l; i++) {
forEach(arguments[i], assignValue);
}
return result;
}
function isUndefined(val) {
return typeof val === "undefined";
}
exports.deepMerge = deepMerge;
exports.forEach = forEach;
exports.isArray = isArray;
exports.isDate = isDate;
exports.isObject = isObject;
exports.isPlainObject = isPlainObject;
exports.isURLSearchParams = isURLSearchParams;
exports.isUndefined = isUndefined;

View File

@@ -0,0 +1,195 @@
"use strict";
var clone = function() {
function _instanceof(obj, type) {
return type != null && obj instanceof type;
}
var nativeMap;
try {
nativeMap = Map;
} catch (_) {
nativeMap = function() {
};
}
var nativeSet;
try {
nativeSet = Set;
} catch (_) {
nativeSet = function() {
};
}
var nativePromise;
try {
nativePromise = Promise;
} catch (_) {
nativePromise = function() {
};
}
function clone2(parent, circular, depth, prototype, includeNonEnumerable) {
if (typeof circular === "object") {
depth = circular.depth;
prototype = circular.prototype;
includeNonEnumerable = circular.includeNonEnumerable;
circular = circular.circular;
}
var allParents = [];
var allChildren = [];
var useBuffer = typeof Buffer != "undefined";
if (typeof circular == "undefined")
circular = true;
if (typeof depth == "undefined")
depth = Infinity;
function _clone(parent2, depth2) {
if (parent2 === null)
return null;
if (depth2 === 0)
return parent2;
var child;
var proto;
if (typeof parent2 != "object") {
return parent2;
}
if (_instanceof(parent2, nativeMap)) {
child = new nativeMap();
} else if (_instanceof(parent2, nativeSet)) {
child = new nativeSet();
} else if (_instanceof(parent2, nativePromise)) {
child = new nativePromise(function(resolve, reject) {
parent2.then(function(value) {
resolve(_clone(value, depth2 - 1));
}, function(err) {
reject(_clone(err, depth2 - 1));
});
});
} else if (clone2.__isArray(parent2)) {
child = [];
} else if (clone2.__isRegExp(parent2)) {
child = new RegExp(parent2.source, __getRegExpFlags(parent2));
if (parent2.lastIndex)
child.lastIndex = parent2.lastIndex;
} else if (clone2.__isDate(parent2)) {
child = new Date(parent2.getTime());
} else if (useBuffer && Buffer.isBuffer(parent2)) {
if (Buffer.from) {
child = Buffer.from(parent2);
} else {
child = new Buffer(parent2.length);
parent2.copy(child);
}
return child;
} else if (_instanceof(parent2, Error)) {
child = Object.create(parent2);
} else {
if (typeof prototype == "undefined") {
proto = Object.getPrototypeOf(parent2);
child = Object.create(proto);
} else {
child = Object.create(prototype);
proto = prototype;
}
}
if (circular) {
var index = allParents.indexOf(parent2);
if (index != -1) {
return allChildren[index];
}
allParents.push(parent2);
allChildren.push(child);
}
if (_instanceof(parent2, nativeMap)) {
parent2.forEach(function(value, key) {
var keyChild = _clone(key, depth2 - 1);
var valueChild = _clone(value, depth2 - 1);
child.set(keyChild, valueChild);
});
}
if (_instanceof(parent2, nativeSet)) {
parent2.forEach(function(value) {
var entryChild = _clone(value, depth2 - 1);
child.add(entryChild);
});
}
for (var i in parent2) {
var attrs = Object.getOwnPropertyDescriptor(parent2, i);
if (attrs) {
child[i] = _clone(parent2[i], depth2 - 1);
}
try {
var objProperty = Object.getOwnPropertyDescriptor(parent2, i);
if (objProperty.set === "undefined") {
continue;
}
child[i] = _clone(parent2[i], depth2 - 1);
} catch (e) {
if (e instanceof TypeError) {
continue;
} else if (e instanceof ReferenceError) {
continue;
}
}
}
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(parent2);
for (var i = 0; i < symbols.length; i++) {
var symbol = symbols[i];
var descriptor = Object.getOwnPropertyDescriptor(parent2, symbol);
if (descriptor && !descriptor.enumerable && !includeNonEnumerable) {
continue;
}
child[symbol] = _clone(parent2[symbol], depth2 - 1);
Object.defineProperty(child, symbol, descriptor);
}
}
if (includeNonEnumerable) {
var allPropertyNames = Object.getOwnPropertyNames(parent2);
for (var i = 0; i < allPropertyNames.length; i++) {
var propertyName = allPropertyNames[i];
var descriptor = Object.getOwnPropertyDescriptor(parent2, propertyName);
if (descriptor && descriptor.enumerable) {
continue;
}
child[propertyName] = _clone(parent2[propertyName], depth2 - 1);
Object.defineProperty(child, propertyName, descriptor);
}
}
return child;
}
return _clone(parent, depth);
}
clone2.clonePrototype = function clonePrototype(parent) {
if (parent === null)
return null;
var c = function() {
};
c.prototype = parent;
return new c();
};
function __objToStr(o) {
return Object.prototype.toString.call(o);
}
clone2.__objToStr = __objToStr;
function __isDate(o) {
return typeof o === "object" && __objToStr(o) === "[object Date]";
}
clone2.__isDate = __isDate;
function __isArray(o) {
return typeof o === "object" && __objToStr(o) === "[object Array]";
}
clone2.__isArray = __isArray;
function __isRegExp(o) {
return typeof o === "object" && __objToStr(o) === "[object RegExp]";
}
clone2.__isRegExp = __isRegExp;
function __getRegExpFlags(re) {
var flags = "";
if (re.global)
flags += "g";
if (re.ignoreCase)
flags += "i";
if (re.multiline)
flags += "m";
return flags;
}
clone2.__getRegExpFlags = __getRegExpFlags;
return clone2;
}();
exports.clone = clone;