Commit 11caae4f by qinjianhui

fix: 修改 CLODOP 打不开问题

parent f84c5115
...@@ -30,7 +30,7 @@ declare global { ...@@ -30,7 +30,7 @@ declare global {
interface Window { interface Window {
LODOP: new () => LODOPObject; LODOP: new () => LODOPObject;
_lodop:LODOPObject | null; _lodop:LODOPObject | null;
_lodopCallback:{ [key: string]: Function }; _lodopCallback:{ [key: string]: (value: string) => void };
CLODOP: CLodopObject; CLODOP: CLodopObject;
getCLodop: () => LODOPObject; getCLodop: () => LODOPObject;
} }
...@@ -99,12 +99,43 @@ export default function useLodop() { ...@@ -99,12 +99,43 @@ export default function useLodop() {
JS1.src = 'http://localhost:8000/CLodopfuncs.js' JS1.src = 'http://localhost:8000/CLodopfuncs.js'
JS2.src = 'http://localhost:18000/CLodopfuncs.js' JS2.src = 'http://localhost:18000/CLodopfuncs.js'
} }
JS1.onload = JS2.onload = function () {
CLodopJsState = 'complete' let loadedCount = 0
let errorCount = 0
const totalScripts = 2
const checkComplete = () => {
if (loadedCount + errorCount >= totalScripts) {
CLodopJsState = 'complete'
// 检查是否成功加载了 getCLodop 函数
if (typeof window.getCLodop !== 'function') {
console.warn('Lodop JS文件加载完成,但 window.getCLodop 未定义')
} else {
console.log('Lodop JS文件加载成功')
}
}
}
JS1.onload = function () {
loadedCount++
checkComplete()
}
JS1.onerror = function () {
errorCount++
console.warn('加载 CLodop JS1 失败:', JS1.src)
checkComplete()
} }
JS1.onerror = JS2.onerror = function () {
CLodopJsState = 'complete' JS2.onload = function () {
loadedCount++
checkComplete()
} }
JS2.onerror = function () {
errorCount++
console.warn('加载 CLodop JS2 失败:', JS2.src)
checkComplete()
}
head.insertBefore(JS1, head.firstChild) head.insertBefore(JS1, head.firstChild)
head.insertBefore(JS2, head.firstChild) head.insertBefore(JS2, head.firstChild)
CLodopIsLocal = !!(JS1.src + JS2.src).match(/\/\/localho|\/\/127.0.0./i) CLodopIsLocal = !!(JS1.src + JS2.src).match(/\/\/localho|\/\/127.0.0./i)
...@@ -162,11 +193,41 @@ export default function useLodop() { ...@@ -162,11 +193,41 @@ export default function useLodop() {
/Linux/i.test(navigator.userAgent) && /aarch64/i.test(navigator.userAgent) /Linux/i.test(navigator.userAgent) && /aarch64/i.test(navigator.userAgent)
if (needCLodop || isLinuxX86 || isLinuxARM) { if (needCLodop || isLinuxX86 || isLinuxARM) {
// 检查 window.getCLodop 是否存在
if (typeof window.getCLodop !== 'function') {
// 如果 JS 文件还在加载中,等待一段时间后重试
if (CLodopJsState === 'loading') {
console.log('Lodop JS文件正在加载中,请稍候...')
return null
}
// 如果 JS 文件加载完成但 getCLodop 不存在,可能是加载失败
if (CLodopJsState === 'complete') {
console.warn('Lodop JS文件加载完成,但 window.getCLodop 未定义,可能是加载失败')
// 尝试重新初始化(最多重试一次,避免无限循环)
const retryKey = '__lodop_retry_count__'
const retryCount = (window as unknown as Record<string, number>)[retryKey] || 0
if (retryCount < 1) {
(window as unknown as Record<string, number>)[retryKey] = retryCount + 1
CLodopJsState = null
initLodop()
} else {
console.error('Lodop JS文件加载失败,已重试一次,请检查CLodop服务是否正常运行')
}
return null
}
// 如果从未加载过,先初始化
if (CLodopJsState === null) {
initLodop()
return null
}
}
try { try {
LODOP = window.getCLodop() LODOP = window.getCLodop()
} catch (err) { } catch (err) {
console.error(err) console.error('调用 window.getCLodop() 出错:', err)
} }
if (!LODOP && CLodopJsState !== 'complete') { if (!LODOP && CLodopJsState !== 'complete') {
if (CLodopJsState == 'loading'){ if (CLodopJsState == 'loading'){
console.log('网页还没下载完毕,请稍等一下再操作.') console.log('网页还没下载完毕,请稍等一下再操作.')
...@@ -189,7 +250,7 @@ export default function useLodop() { ...@@ -189,7 +250,7 @@ export default function useLodop() {
strAlertMessage = strLodop7Update_X86 strAlertMessage = strLodop7Update_X86
else if (isLinuxARM && LODOP.CVERSION < '7.0.4.3') else if (isLinuxARM && LODOP.CVERSION < '7.0.4.3')
strAlertMessage = strLodop7Update_ARM strAlertMessage = strLodop7Update_ARM
else if (window.CLODOP.CVERSION < '4.1.6.1') else if (window.CLODOP && window.CLODOP.CVERSION < '4.1.6.1')
strAlertMessage = strCLodopUpdate strAlertMessage = strCLodopUpdate
if (strAlertMessage) showMsg(strAlertMessage + strInstallOK) if (strAlertMessage) showMsg(strAlertMessage + strInstallOK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment