/** * WPS 打开路径:浏览 / 自动查找 / 保存(目录操作对话框共用) */ (function (global) { 'use strict'; function saveFromInput(inputId) { const input = document.getElementById(inputId); if (!input || !global.localStorage) return; const val = (input.value || '').trim(); if (val) { localStorage.setItem('wpsCustomExePath', val); alert('WPS 路径已保存'); } else { localStorage.removeItem('wpsCustomExePath'); alert('已清空 WPS 路径,将使用自动查找'); } } async function browseToInput(inputId) { const input = document.getElementById(inputId); if (!input) return; try { const resp = await fetch('/api/system/select-program-path', { method: 'GET' }); const data = await resp.json(); if (data && data.success && data.path) { input.value = data.path; saveFromInput(inputId); } else if (data && data.message) { alert(data.message); } } catch (e) { alert('选择程序路径失败:' + e); } } async function autoFindToInput(inputId) { const input = document.getElementById(inputId); if (!input) return; try { const resp = await fetch('/api/system/auto-find-wps', { method: 'GET' }); const data = await resp.json(); if (data && data.success && data.path) { input.value = data.path; saveFromInput(inputId); } else { alert((data && data.message) ? data.message : '未找到 WPS'); } } catch (e) { alert('自动查找 WPS 失败:' + e); } } global.IARDirOpsWps = { saveFromInput: saveFromInput, browseToInput: browseToInput, autoFindToInput: autoFindToInput, }; // 兼容旧页面内联 onclick global.browseWpsPathToInput = browseToInput; global.autoFindWpsToInput = autoFindToInput; })(typeof window !== 'undefined' ? window : this);