fix(ui): 页内确认框替代阻塞式 window.confirm(设置/备份/诊断 6 处);打包前强制 lint(防未定义变量再溜进包)
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m29s
Verify (Gitea) / gate (build · unit · facts) (push) Successful in 1m29s
This commit is contained in:
1 parent
a625faab17
commit
dd15a7d45f
11 files changed
+108
-18
No files matched your search
+13
-4
@@ -11,6 +11,15 @@
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
function askConfirm (text, opts) {
|
||||
const D = (typeof window !== 'undefined') ? window.IWBDesktop : null
|
||||
const native = !!(D && D.isTauri && D.isTauri())
|
||||
const C = (typeof window !== 'undefined') ? window.IWBUIConfirm : null
|
||||
if (native && C && typeof C.ask === 'function') return C.ask(Object.assign({ text: text }, opts || {}))
|
||||
return Promise.resolve(window.confirm(text))
|
||||
}
|
||||
|
||||
// 存储入口收敛(2026-11-06):统一走 IWBStorageLocal 门面,配额/异常集中处理
|
||||
const _lstore = () => (typeof window !== 'undefined' && window.IWBStorageLocal && typeof window.IWBStorageLocal.getStore === 'function') ? window.IWBStorageLocal.getStore() : null
|
||||
const React = global.React || {}
|
||||
@@ -170,7 +179,7 @@ function BackupModal(props) {
|
||||
const needConfirm = estMB >= 20 || imgMeta.length >= 20
|
||||
const sizeText = estMB >= 1 ? ('约 ' + estMB.toFixed(0) + ' MB') : '未记录(按张数估算偏大)'
|
||||
if (needConfirm && typeof window !== 'undefined' && typeof window.confirm === 'function') {
|
||||
const okGo = window.confirm('本次备份包含 ' + imgMeta.length + ' 张图片,预计体积 ' + sizeText + '。\n导出期间浏览器内存占用会明显上升,图库很大时页面会变慢。\n确定继续导出吗?')
|
||||
const okGo = await askConfirm('本次备份包含 ' + imgMeta.length + ' 张图片,预计体积 ' + sizeText + '。\n导出期间内存占用会明显上升,图库很大时页面会变慢。\n确定继续导出吗?', { title: '导出备份', okText: '继续导出' })
|
||||
if (!okGo) {
|
||||
setBkMsg({ type: 'err', text: '已取消导出(' + imgMeta.length + ' 张图片 / ' + sizeText + ')' })
|
||||
return
|
||||
@@ -322,7 +331,7 @@ function BackupModal(props) {
|
||||
const items = restoreData.items
|
||||
const want = Object.keys(restoreSel).filter((k) => restoreSel[k])
|
||||
if (!want.length) { setRstMsg({ type: 'err', text: '请至少勾选一项要恢复的数据' }); return }
|
||||
if (!window.confirm((restoreMerge ? '将以「合并」方式导入(追加去重,不覆盖已有):' : '将用备份覆盖当前数据:') + want.map((k) => ({ config: '设置', prompts: '提示词库', nodeGroups: '节点组', workspaces: '画布工作台', outputs: '图库(含缩略图+原图)' })[k]).join('、') + '。确定恢复?')) return
|
||||
if (!(await askConfirm((restoreMerge ? '将以「合并」方式导入(追加去重,不覆盖已有):' : '将用备份覆盖当前数据:') + want.map((k) => ({ config: '设置', prompts: '提示词库', nodeGroups: '节点组', workspaces: '画布工作台', outputs: '图库(含缩略图+原图)' })[k]).join('、') + '。确定恢复?', { title: '恢复备份', okText: '开始恢复' }))) return
|
||||
setRstBusy(true); setRstMsg(null)
|
||||
try {
|
||||
props.onSaveNow && props.onSaveNow() // 导入前保存当前画布(避免导入后丢失未保存改动)
|
||||
@@ -398,7 +407,7 @@ function BackupModal(props) {
|
||||
for (const m of keepMiss) { const t = (m && (m.label || m.path)) || '密钥'; if (uniqLabel.indexOf(t) === -1) uniqLabel.push(t) }
|
||||
keepWarn = '⚠︎ 有 ' + keepMiss.length + ' 个密钥字段在备份里是「保留本机原值」(__KEEP__),但本机没有对应值,已保持为空:' + uniqLabel.slice(0, 3).join('、') + (uniqLabel.length > 3 ? ' 等 ' + uniqLabel.length + ' 类' : '') + '。请到「服务与 Key 设置」里补填。'
|
||||
wLog('restore', 'KEEP-MISS:' + keepMiss.map((m) => m && m.path).join(', '))
|
||||
try { window.confirm(keepWarn + '\n\n点「确定」继续(恢复已完成,随后刷新页面生效)。') } catch (e) { /* ignore */ }
|
||||
try { await askConfirm(keepWarn + '\n\n点「确定」继续(恢复已完成,随后刷新页面生效)。', { title: '恢复提示', okText: '知道了', cancelText: '关闭' }) } catch (e) { /* ignore */ }
|
||||
}
|
||||
setRstMsg({
|
||||
type: (imgBad.length || keepWarn) ? 'err' : 'ok',
|
||||
@@ -428,7 +437,7 @@ function BackupModal(props) {
|
||||
)
|
||||
// 清理本地数据:清空 localStorage(iwb_*) + IndexedDB(iwb_web),不可撤销
|
||||
const doClear = async () => {
|
||||
if (!window.confirm('确定清空本机的全部本地数据吗?\n\n将删除:设置、提示词库、节点组、画布工作台、图库索引与本机图片(IndexedDB)。\n此操作不可撤销。\n\n建议先「导出备份」再清理。')) return
|
||||
if (!(await askConfirm('确定清空本机的全部本地数据吗?\n\n将删除:设置、提示词库、节点组、画布工作台、图库索引与本机图片。\n此操作不可撤销。\n\n建议先「导出备份」再清理。', { title: '清空本地数据', okText: '全部清空' }))) return
|
||||
setClearBusy(true); setClearMsg(null)
|
||||
try {
|
||||
const st = _lstore()
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* ui-confirm.js —— 页内确认框(桌面端替代 window.confirm)
|
||||
*
|
||||
* 为什么需要:Tauri(WKWebView)里 window.confirm 会弹 macOS 原生框并**阻塞 WebView 主线程**,
|
||||
* 用户点了按钮界面像死机(实测复现)。这里用 DOM 覆盖层实现同样的"确认/取消",
|
||||
* 用 Promise 返回结果,调用方 await 即可。
|
||||
*
|
||||
* 网页端仍然用 window.confirm(行为零变化)。
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
function ask (opts) {
|
||||
const o = opts || {}
|
||||
if (typeof document === 'undefined' || !document.body) return Promise.resolve(false)
|
||||
return new Promise(function (resolve) {
|
||||
const overlay = document.createElement('div')
|
||||
overlay.className = 'iwb-confirm-overlay'
|
||||
const box = document.createElement('div')
|
||||
box.className = 'iwb-confirm-box'
|
||||
const title = document.createElement('div')
|
||||
title.className = 'iwb-confirm-title'
|
||||
title.textContent = o.title || '确认'
|
||||
const text = document.createElement('div')
|
||||
text.className = 'iwb-confirm-text'
|
||||
text.textContent = String(o.text || '')
|
||||
const row = document.createElement('div')
|
||||
row.className = 'iwb-confirm-actions'
|
||||
const cancel = document.createElement('button')
|
||||
cancel.className = 'iwb-btn iwb-btn-sm'
|
||||
cancel.textContent = o.cancelText || '取消'
|
||||
const ok = document.createElement('button')
|
||||
ok.className = 'iwb-btn iwb-btn-sm iwb-btn-primary'
|
||||
ok.textContent = o.okText || '确定'
|
||||
let settled = false
|
||||
function done (value) {
|
||||
if (settled) return
|
||||
settled = true
|
||||
try { overlay.remove() } catch (e) { /* ignore */ }
|
||||
resolve(value)
|
||||
}
|
||||
cancel.addEventListener('click', function () { done(false) })
|
||||
ok.addEventListener('click', function () { done(true) })
|
||||
overlay.addEventListener('click', function (e) { if (e.target === overlay) done(false) })
|
||||
overlay.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape') done(false)
|
||||
if (e.key === 'Enter') done(true)
|
||||
})
|
||||
row.appendChild(cancel)
|
||||
row.appendChild(ok)
|
||||
box.appendChild(title)
|
||||
box.appendChild(text)
|
||||
box.appendChild(row)
|
||||
overlay.appendChild(box)
|
||||
document.body.appendChild(overlay)
|
||||
setTimeout(function () { try { ok.focus() } catch (e) { /* ignore */ } }, 0)
|
||||
})
|
||||
}
|
||||
|
||||
global.IWBUIConfirm = { ask: ask }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
@@ -101,6 +101,15 @@
|
||||
)
|
||||
}
|
||||
|
||||
// 桌面端用页内确认(window.confirm 会阻塞 WKWebView 主线程 ⇒ 界面像死机)
|
||||
function askConfirm (text, opts) {
|
||||
const D = (typeof window !== 'undefined') ? window.IWBDesktop : null
|
||||
const native = !!(D && D.isTauri && D.isTauri())
|
||||
const C = (typeof window !== 'undefined') ? window.IWBUIConfirm : null
|
||||
if (native && C && typeof C.ask === 'function') return C.ask(Object.assign({ text: text }, opts || {}))
|
||||
return Promise.resolve(window.confirm(text))
|
||||
}
|
||||
|
||||
// 桌面端插件管理(参考 Obsidian):搜索 + 已安装(开关/设置)+ 可安装(市场)
|
||||
function DesktopPluginsTab (props) {
|
||||
const { PluginHost, pluginItems, setPluginsRev, setTab, wRuntimePlugins } = props
|
||||
@@ -351,7 +360,7 @@
|
||||
try {
|
||||
const d = await F.pickDir()
|
||||
if (!d || d === dataDir) return
|
||||
if (!window.confirm('切换资料目录?\n\n当前数据会先保存到当前目录,然后窗口重载并从新目录装载。\n新目录:' + d)) return
|
||||
if (!(await askConfirm('切换资料目录?\n\n当前数据会先保存到当前目录,然后窗口重载并从新目录装载。\n新目录:' + d, { title: '切换资料目录', okText: '切换' }))) return
|
||||
await F.switchTo(d)
|
||||
setDataDir(d); setNote('已切换,正在重载…')
|
||||
} catch (e) { setNote('切换失败:' + String((e && e.message) || e)) }
|
||||
@@ -364,7 +373,7 @@
|
||||
try {
|
||||
const d = await F.pickDir()
|
||||
if (!d || d === dataDir) return
|
||||
if (!window.confirm('把整个数据库复制到:\n' + d + '\n\n复制完成后自动切换并重载;原目录会保留,确认无误后可手动删除。\n(图片较多时会花几十秒)')) return
|
||||
if (!(await askConfirm('把整个数据库复制到:\n' + d + '\n\n复制完成后自动切换并重载;原目录会保留,确认无误后可手动删除。\n(图片较多时会花几十秒)', { title: '转移数据库', okText: '开始复制' }))) return
|
||||
setNote('正在复制,请稍候…')
|
||||
await F.migrateTo(d)
|
||||
} catch (e) { setNote('转移失败:' + String((e && e.message) || e)) }
|
||||
@@ -386,7 +395,7 @@
|
||||
const rDry = await F.gcImages({ dryRun: true })
|
||||
if (!rDry.ok) { setNote('检查失败:' + rDry.error); return }
|
||||
if (!rDry.orphans) { setNote('没有未引用的图片'); return }
|
||||
if (!window.confirm('发现 ' + rDry.orphans + ' 个文件没有被画布/图库引用。移动到 trash/(不直接删除)?')) return
|
||||
if (!(await askConfirm('发现 ' + rDry.orphans + ' 个文件没有被画布/图库引用。移动到 trash/(不直接删除)?', { title: '清理未引用图片', okText: '移动' }))) return
|
||||
const rGo = await F.gcImages({ dryRun: false })
|
||||
setNote(rGo.ok ? ('已移入 trash/:' + rGo.moved + ' 个文件') : ('清理失败:' + rGo.error))
|
||||
} catch (e) { setNote('清理失败:' + String((e && e.message) || e)) }
|
||||
@@ -551,11 +560,12 @@
|
||||
el('div', { className: 'iwb-diag-head' }, new Date(row.at).toLocaleString() + ' · ' + row.keyCount + ' 个键 · ' + Math.round((row.bytes || 0) / 1024) + 'KB'),
|
||||
el('button', {
|
||||
className: 'iwb-btn iwb-btn-sm',
|
||||
onClick: () => {
|
||||
if (!window.confirm('用这份备份覆盖当前本机数据?\n\n覆盖后会' + (isDesk() ? '自动重载窗口' : '立即刷新页面') + '。当前数据不会保留,建议先「导出备份」。')) return
|
||||
onClick: async () => {
|
||||
const okGo = await askConfirm('用这份备份覆盖当前本机数据?\n\n覆盖后会' + (isDesk() ? '自动重载窗口' : '立即刷新页面') + '。当前数据不会保留,建议先「导出备份」。', { title: '还原自动备份', okText: '还原' })
|
||||
if (!okGo) return
|
||||
Promise.resolve(props.autoBackupRestore && props.autoBackupRestore(row.name)).then((r) => {
|
||||
if (r && r.ok) location.reload()
|
||||
else window.alert('还原失败:' + ((r && r.error) || '未知错误'))
|
||||
else askConfirm('还原失败:' + ((r && r.error) || '未知错误'), { title: '还原失败', okText: '知道了', cancelText: '关闭' })
|
||||
})
|
||||
},
|
||||
}, '还原此份'),
|
||||
|
||||
Reference in new issue
Block a user