Files
yl/MES_Manage_View_V20/static/pdf-compatibility.js
2026-05-23 14:07:11 +08:00

66 lines
2.1 KiB
JavaScript

// pdf-compatibility.js
(function() {
'use strict';
// 修复 url.parse
if (typeof window.URL === 'undefined' || typeof window.URL.parse !== 'function') {
window.URL = window.URL || {};
window.URL.parse = function(url) {
try {
// 使用 DOM 方式解析 URL
const a = document.createElement('a');
a.href = url;
return {
protocol: a.protocol,
hostname: a.hostname,
port: a.port,
pathname: a.pathname,
search: a.search,
hash: a.hash,
host: a.host,
href: a.href,
origin: a.origin
};
} catch (e) {
// 简单的字符串解析
const match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);
return {
protocol: match[2] || '',
hostname: match[4] || '',
pathname: match[5] || '',
search: match[6] || '',
hash: match[8] || '',
href: url
};
}
};
}
// 修复 Promise.withResolvers
if (typeof Promise.withResolvers !== 'function') {
Promise.withResolvers = function() {
var resolve, reject;
var promise = new Promise(function(res, rej) {
resolve = res;
reject = rej;
});
return { promise: promise, resolve: resolve, reject: reject };
};
}
// 修复 Object.values
if (typeof Object.values !== 'function') {
Object.values = function(obj) {
var values = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
values.push(obj[key]);
}
}
return values;
};
}
console.log('PDF 兼容性修复已加载');
})();