/** * 目录操作「复制/剪切」持久化:使用 localStorage。 * - 按 scope 分桶:同模块内跨实体粘贴(兼容旧逻辑) * - 全局桶 __global_file__:跨页面/跨模块粘贴(论文↔课题等) */ (function () { if (typeof window === 'undefined') return; var PREFIX = 'IAR_DIR_CLIP:v1:'; var GLOBAL_FILE_SCOPE = '__global_file__'; window.IARDirClipboard = { GLOBAL_FILE_SCOPE: GLOBAL_FILE_SCOPE, _key: function (scope) { return PREFIX + String(scope || 'default'); }, save: function (scope, data) { try { if (!data) { localStorage.removeItem(this._key(scope)); return; } localStorage.setItem(this._key(scope), JSON.stringify(data)); } catch (e) { /* 隐私模式或配额 */ } }, load: function (scope) { try { var raw = localStorage.getItem(this._key(scope)); if (!raw) return null; return JSON.parse(raw); } catch (e) { return null; } }, clear: function (scope) { try { localStorage.removeItem(this._key(scope)); } catch (e) { /* ignore */ } }, /** 写入全局文件剪贴板,并同步到指定模块 scope(兼容同页粘贴) */ saveFileClip: function (scope, data) { this.save(GLOBAL_FILE_SCOPE, data); if (scope) this.save(scope, data); }, /** 优先读全局;无则回退模块 scope */ loadFileClip: function (scope) { var g = this.load(GLOBAL_FILE_SCOPE); if (g && typeof g === 'object') return g; return scope ? this.load(scope) : null; }, clearFileClip: function (scope) { this.clear(GLOBAL_FILE_SCOPE); if (scope) this.clear(scope); } }; })();