//////////////////////////////////////////////////////////////////////////// // System Pre-define Functions // 95099372-ef3e-11ea-9c81-bf848405c62e //Callback of data preparation stage before UI is fully loaded. function OnInitializeData() { // 注册保存请求的回调函数,当网页请求保存时会触发此逻辑 model.OnMonacoSaveRequest = function (content, cb) { // 弹出“保存文件”对话框,初始目录为 D:/,允许保存为 .txt 文件 const filepath = ui.SaveFileDialog("保存文件", "D:/", "*.txt"); // 如果用户选择了文件路径 if (filepath) { cb(filepath); // 调用回调函数,把选定路径传给 model 层保存文件内容 const filename = filepath.split(/[/\\]/).pop(); // 提取不带路径的文件名 ui.MessageBox("提示", `成功保存‘${filename}’到‘${filepath}’`, MessageBox.Icon.Information, MessageBox.Button.Ok); // 弹出成功提示 } else { // 用户取消保存操作 ui.MessageBox("提示", "取消", MessageBox.Icon.Warning, MessageBox.Button.Ok); } }; // 注册打开请求的回调函数,当网页请求打开文件时会触发此逻辑 model.OnMonacoOpenRequest = function (cb) { // 弹出“打开文件”对话框,初始目录为 D:/,仅显示 .txt 文件 const filepath = ui.OpenFileDialog("打开文件", "D:/", "*.txt"); // 对于用户选择的文件 if (filepath) { cb(filepath); // 调用回调函数,把选定路径传给 model 层读取文件内容 const filename = filepath.split(/[/\\]/).pop(); // 提取文件名 ui.MessageBox("提示", `成功打开‘${filename}’`, MessageBox.Icon.Information, MessageBox.Button.Ok); // 弹出成功提示 } else { // 用户取消打开操作 ui.MessageBox("提示", "取消", MessageBox.Icon.Warning, MessageBox.Button.Ok); } }; } //Callback after UI is fully loaded and displayed. function OnReady(reload, preview) { model.StartupMonacoEdit(()=>{ ui.url.value = "http://localhost:3000"; }); } function OnCloseForm() { } function OnException(err) { //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok); } ////////////////////////////////////////////////////////////////////////// // Callback Functions. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7 function OnPageLoadOkay(){ ui.page.index = 1; } function OnPageLoadFail(){ ui.url.value = "http://localhost:3000"; } //The message corresponding callback executed by the main form // when calling pui.fireEvent(type,para) in the Docker subform. ////////////////////////////////////////////////////////////////////////// // Utils Functions. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe function onDragFile(filepath) { } /*Usage of BLOCK_EVENT BLOCK_EVENT(()=>{ ui.[name].[var] = ...; }); */ function BLOCK_EVENT(cb) { ui.block_event = true; cb(); ui.block_event = false; }