1
0
forked from dyf/APP

优化首页的下拉刷新、数据排序、绑定后刷新

This commit is contained in:
liub
2025-12-24 10:52:28 +08:00
parent 425b7b9cfd
commit 637658a762
202 changed files with 5432 additions and 301514 deletions

View File

@ -62,6 +62,12 @@ const HttpStatusCode = {
LoopDetected: 508,
NotExtended: 510,
NetworkAuthenticationRequired: 511,
WebServerIsDown: 521,
ConnectionTimedOut: 522,
OriginIsUnreachable: 523,
TimeoutOccurred: 524,
SslHandshakeFailed: 525,
InvalidSslCertificate: 526,
};
Object.entries(HttpStatusCode).forEach(([key, value]) => {

View File

@ -1,5 +1,12 @@
'use strict';
/**
* Create a bound version of a function with a specified `this` context
*
* @param {Function} fn - The function to bind
* @param {*} thisArg - The value to be passed as the `this` parameter
* @returns {Function} A new function that will call the original function with the specified `this` context
*/
export default function bind(fn, thisArg) {
return function wrap() {
return fn.apply(thisArg, arguments);

View File

@ -16,9 +16,7 @@ function encode(val) {
replace(/%3A/gi, ':').
replace(/%24/g, '$').
replace(/%2C/gi, ',').
replace(/%20/g, '+').
replace(/%5B/gi, '[').
replace(/%5D/gi, ']');
replace(/%20/g, '+');
}
/**

View File

@ -5,27 +5,38 @@ export default platform.hasStandardBrowserEnv ?
// Standard browser envs support document.cookie
{
write(name, value, expires, path, domain, secure) {
const cookie = [name + '=' + encodeURIComponent(value)];
write(name, value, expires, path, domain, secure, sameSite) {
if (typeof document === 'undefined') return;
utils.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
const cookie = [`${name}=${encodeURIComponent(value)}`];
utils.isString(path) && cookie.push('path=' + path);
utils.isString(domain) && cookie.push('domain=' + domain);
secure === true && cookie.push('secure');
if (utils.isNumber(expires)) {
cookie.push(`expires=${new Date(expires).toUTCString()}`);
}
if (utils.isString(path)) {
cookie.push(`path=${path}`);
}
if (utils.isString(domain)) {
cookie.push(`domain=${domain}`);
}
if (secure === true) {
cookie.push('secure');
}
if (utils.isString(sameSite)) {
cookie.push(`SameSite=${sameSite}`);
}
document.cookie = cookie.join('; ');
},
read(name) {
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
if (typeof document === 'undefined') return null;
const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
return match ? decodeURIComponent(match[1]) : null;
},
remove(name) {
this.write(name, '', Date.now() - 86400000);
this.write(name, '', Date.now() - 86400000, '/');
}
}

View File

@ -0,0 +1,73 @@
/**
* Estimate decoded byte length of a data:// URL *without* allocating large buffers.
* - For base64: compute exact decoded size using length and padding;
* handle %XX at the character-count level (no string allocation).
* - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
*
* @param {string} url
* @returns {number}
*/
export default function estimateDataURLDecodedBytes(url) {
if (!url || typeof url !== 'string') return 0;
if (!url.startsWith('data:')) return 0;
const comma = url.indexOf(',');
if (comma < 0) return 0;
const meta = url.slice(5, comma);
const body = url.slice(comma + 1);
const isBase64 = /;base64/i.test(meta);
if (isBase64) {
let effectiveLen = body.length;
const len = body.length; // cache length
for (let i = 0; i < len; i++) {
if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
const a = body.charCodeAt(i + 1);
const b = body.charCodeAt(i + 2);
const isHex =
((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
if (isHex) {
effectiveLen -= 2;
i += 2;
}
}
}
let pad = 0;
let idx = len - 1;
const tailIsPct3D = (j) =>
j >= 2 &&
body.charCodeAt(j - 2) === 37 && // '%'
body.charCodeAt(j - 1) === 51 && // '3'
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
if (idx >= 0) {
if (body.charCodeAt(idx) === 61 /* '=' */) {
pad++;
idx--;
} else if (tailIsPct3D(idx)) {
pad++;
idx -= 3;
}
}
if (pad === 1 && idx >= 0) {
if (body.charCodeAt(idx) === 61 /* '=' */) {
pad++;
} else if (tailIsPct3D(idx)) {
pad++;
}
}
const groups = Math.floor(effectiveLen / 4);
const bytes = groups * 3 - (pad || 0);
return bytes > 0 ? bytes : 0;
}
return Buffer.byteLength(body, 'utf8');
}

View File

@ -10,7 +10,7 @@ import buildURL from "./buildURL.js";
export default (config) => {
const newConfig = mergeConfig({}, config);
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
newConfig.headers = headers = AxiosHeaders.from(headers);
@ -23,17 +23,21 @@ export default (config) => {
);
}
let contentType;
if (utils.isFormData(data)) {
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
headers.setContentType(undefined); // Let the browser set it
} else if ((contentType = headers.getContentType()) !== false) {
// fix semicolon duplication issue for ReactNative FormData implementation
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
headers.setContentType(undefined); // browser handles it
} else if (utils.isFunction(data.getHeaders)) {
// Node.js FormData (like form-data package)
const formHeaders = data.getHeaders();
// Only set safe headers to avoid overwriting security headers
const allowedHeaders = ['content-type', 'content-length'];
Object.entries(formHeaders).forEach(([key, val]) => {
if (allowedHeaders.includes(key.toLowerCase())) {
headers.set(key, val);
}
});
}
}
}
// Add xsrf header
// This is only done if running in a standard browser environment.

View File

@ -17,7 +17,7 @@ function throttle(fn, freq) {
clearTimeout(timer);
timer = null;
}
fn.apply(null, args);
fn(...args);
}
const throttled = (...args) => {

View File

@ -120,6 +120,10 @@ function toFormData(obj, formData, options) {
return value.toISOString();
}
if (utils.isBoolean(value)) {
return value.toString();
}
if (!useBlob && utils.isBlob(value)) {
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
}

View File

@ -5,7 +5,7 @@ import toFormData from './toFormData.js';
import platform from '../platform/index.js';
export default function toURLEncodedForm(data, options) {
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
return toFormData(data, new platform.classes.URLSearchParams(), {
visitor: function(value, key, path, helpers) {
if (platform.isNode && utils.isBuffer(value)) {
this.append(key, value.toString('base64'));
@ -13,6 +13,7 @@ export default function toURLEncodedForm(data, options) {
}
return helpers.defaultVisitor.apply(this, arguments);
}
}, options));
},
...options
});
}