Add all dashboard projects
This commit is contained in:
66
MES_Manage_View_V20/static/pdf-compatibility.js
Normal file
66
MES_Manage_View_V20/static/pdf-compatibility.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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 兼容性修复已加载');
|
||||
})();
|
||||
Reference in New Issue
Block a user