From 808690c4866977fbb97fa5c4200353c0e075d630 Mon Sep 17 00:00:00 2001 From: qwqVictor Date: Tue, 21 May 2024 16:59:51 +0800 Subject: [PATCH] feat: jquery-confirm popup --- webrdp/assets/file.js | 93 +++++++++++++++++++++++++++++++----------- webrdp/assets/rdp.css | 6 +-- webrdp/assets/rdp.html | 9 ++-- webrdp/assets/ui.js | 63 +++++++++++++++++++++++++++- 4 files changed, 139 insertions(+), 32 deletions(-) diff --git a/webrdp/assets/file.js b/webrdp/assets/file.js index 7ceb84e..130b7e2 100644 --- a/webrdp/assets/file.js +++ b/webrdp/assets/file.js @@ -1,7 +1,9 @@ window.filegatewayUrl = "/filegw/" function initFile() { window.fileShareName = "drive_c$"; + $('option').val(window.fileShareName).appendTo('#shares'); window.currentPath = []; + updatePathText(); listFile(); setInterval(listFile, 20000); } @@ -44,13 +46,13 @@ function listFile() { cell2.innerHTML = "目录"; } else { - cell1.innerHTML = "" + filename + ""; + cell1.innerHTML = "" + filename + ""; cell2.innerHTML = getSize(data.entries[i].fileSize); } } }, error: function (xhr, status, error) { - alert("文件夹列出失败,可能没有权限或者凭证过期,刷新网页后再试"); + $.alert("文件夹列出失败,可能没有权限或者凭证过期,刷新网页后再试"); } }); @@ -60,8 +62,6 @@ function uploadFile(force) { var file = fileInput.files[0]; var suffix = ""; var blob = new Blob([file], { type: "application/octet-stream" }); - if (force) - suffix="?force=1" $.ajax({ url: getCurrentPath() + encodeURI(file.name) + suffix, method: "POST", @@ -69,35 +69,80 @@ function uploadFile(force) { contentType: false, processData: false, success: function (response) { - if (response.exist && !force) { - if (confirm("文件已存在,是否覆盖?")) { - uploadFile(true); - } + console.log("upload response", response) + if (response.exists && !force) { + $.confirm({ + title: '文件已存在!', + content: '是否替换?', + buttons: { + replace: { + text: '替换', + btnClass: 'btn-red', + keys: ['enter', 'shift'], + action: function () { + uploadFile(true) + } + }, + cancel: { + text: '取消', + action: function () {} + } + } + }); } - else if (!response.exist && !response.error) - alert("上传成功"); + else if (!response.exists && !response.error) + $.alert("上传成功"); }, error: function (xhr, status, error) { - alert("上传失败,可能没有权限访问。") + $.alert("上传失败,可能没有权限访问。") console.error("upload error", xhr, status, error) } }); } function mkdir() { - var dirName = prompt("请输入文件夹名称"); - if (dirName) { - $.ajax({ - url: getCurrentPath() + encodeURI(dirName), - method: "PUT", - success: function (response) { - if (!response.error) - alert("创建成功"); + $.confirm({ + title: "请输入文件夹名称", + content: '' + + '
' + + '
' + + '' + + '' + + '
' + + '
', + buttons: { + formSubmit: { + text: '确定', + btnClass: 'btn-blue', + action: function () { + var dirName = this.$content.find('.name').val(); + $.ajax({ + url: getCurrentPath() + encodeURI(dirName), + method: "PUT", + success: function (response) { + if (!response.error) + $.alert("创建成功"); + }, + error: function (xhr, status, error) { + $.alert("创建文件夹失败,可能是没有权限"); + } + }); + } }, - error: function (xhr, status, error) { - alert("创建文件夹失败,可能是没有权限"); - } - }); - } + cancel: { + text: '取消', + action: function() {} + }, + }, + onContentReady: function () { + // bind to events + var jc = this; + this.$content.find('form').on('submit', function (e) { + // if the user submits the form by pressing enter in the field. + e.preventDefault(); + jc.$$formSubmit.trigger('click'); // reference the button and click it + }); + } + }); } function onClickOpenDir(element) { window.currentPath = window.currentPath.concat(element.innerHTML); diff --git a/webrdp/assets/rdp.css b/webrdp/assets/rdp.css index 89790e6..0146c0f 100644 --- a/webrdp/assets/rdp.css +++ b/webrdp/assets/rdp.css @@ -127,8 +127,8 @@ transform: translateY(-50%); float: left; background: white; - border-bottom-left-radius: 15px; - border-top-left-radius: 15px; + border-bottom-right-radius: 15px; + border-top-right-radius: 15px; } .fileshareback-open { @@ -141,7 +141,7 @@ #filesharelist { width: 295px; - height: 200px; + height: 35vh; border: 1px dotted #000; } diff --git a/webrdp/assets/rdp.html b/webrdp/assets/rdp.html index 9ce9fd0..59ea1e4 100644 --- a/webrdp/assets/rdp.html +++ b/webrdp/assets/rdp.html @@ -7,6 +7,7 @@ 远程桌面 + @@ -49,7 +50,7 @@ } function disconnectedAndRefresh(msg) { - alert(msg ?? "抱歉,与服务器连接断开。"); + $.alert(msg ?? "抱歉,与服务器连接断开。"); window.location.reload(); } @@ -93,9 +94,8 @@
-
当前路径: /drive_c$/
-
分享:
@@ -107,6 +107,7 @@
+ diff --git a/webrdp/assets/ui.js b/webrdp/assets/ui.js index 2f8c0fb..da07d50 100644 --- a/webrdp/assets/ui.js +++ b/webrdp/assets/ui.js @@ -76,4 +76,65 @@ function fileshare_close() { // canvas 防止触屏滑动事件 $("#canvas").on("touchmove", function (e) { e.preventDefault(); -}); \ No newline at end of file +}); + +jconfirm.defaults = { + title: '提示', + titleClass: '', + type: 'default', + typeAnimated: true, + draggable: true, + dragWindowGap: 15, + dragWindowBorder: true, + animateFromElement: true, + smoothContent: true, + content: '你确定要继续吗?', + buttons: {}, + defaultButtons: { + ok: { + text: '确定', + action: function () {} + }, + close: { + text: '关闭', + action: function () {} + }, + }, + contentLoaded: function (data, status, xhr) { + }, + icon: '', + lazyOpen: false, + bgOpacity: null, + theme: 'light', + animation: 'scale', + closeAnimation: 'scale', + animationSpeed: 400, + animationBounce: 1, + rtl: false, + container: 'body', + containerFluid: false, + backgroundDismiss: false, + backgroundDismissAnimation: 'shake', + autoClose: false, + closeIcon: null, + closeIconClass: false, + watchInterval: 100, + columnClass: 'col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1', + boxWidth: '50%', + scrollToPreviousElement: true, + scrollToPreviousElementAnimate: true, + useBootstrap: true, + offsetTop: 40, + offsetBottom: 40, + bootstrapClasses: { + container: 'container', + containerFluid: 'container-fluid', + row: 'row', + }, + onContentReady: function () { }, + onOpenBefore: function () { }, + onOpen: function () { }, + onClose: function () { }, + onDestroy: function () { }, + onAction: function () { } +};