diff --git a/extend/base/admin/controller/system/MenuBase.php b/extend/base/admin/controller/system/MenuBase.php index 177d1b9..a4709f9 100644 --- a/extend/base/admin/controller/system/MenuBase.php +++ b/extend/base/admin/controller/system/MenuBase.php @@ -10,6 +10,7 @@ use app\admin\service\TriggerService; use app\common\constants\MenuConstant; use app\common\controller\AdminController; use think\App; +use think\facade\Db; /** * Class Menu. @@ -216,4 +217,68 @@ class MenuBase extends AdminController 'type' => 'success', ]); } + + /** + * @NodeAnotation(title="导出") + */ + public function export() + { + $list_menu_json = SystemMenu::select()->hidden([ + 'create_time', + 'update_time', + 'delete_time', + ])->toJson(); + + $download = $this->request->param('download'); + if ($download == 1) { + $file_name = 'admin_menu.json'; + $file_name = $this->request->host() . '_' . $file_name; + + return download($list_menu_json, $file_name, true, 0); + } + + $this->assign('list_menu_json', $list_menu_json); + + return $this->fetch(); + } + + /** + * @NodeAnotation(title="import") + */ + public function import() + { + if ($this->request->isPost()) { + $data = $this->request->post('data'); + $data_arr = json_decode($data, true); + + $rule = [ + 'pid|上级菜单' => 'require', + 'title|菜单名称' => 'require', + 'icon|菜单图标' => 'require', + ]; + foreach ($data_arr as $data_item) { + $this->validate($data_item, $rule); + } + + Db::startTrans(); + try { + $list_old_menu = SystemMenu::withTrashed()->select(); + foreach ($list_old_menu as $menu) { + $menu->force()->delete(); + } + + foreach ($data_arr as $data_item) { + $menu = new SystemMenu(); + $menu->save($data_item); + } + Db::commit(); + } catch (\Throwable $th) { + Db::rollback(); + $this->error('导入失败:' . $th->getMessage()); + } + $this->success('导入成功'); + } + + return $this->fetch(); + } } diff --git a/extend/base/admin/view/system/menu/export.html b/extend/base/admin/view/system/menu/export.html new file mode 100644 index 0000000..ad68428 --- /dev/null +++ b/extend/base/admin/view/system/menu/export.html @@ -0,0 +1,15 @@ +
+
+
+ +
+ +
+
复制
+ 下载 +
+ 可以通过复制或下载的方式导出配置,然后在另一个系统中导入。 +
+
+
+
\ No newline at end of file diff --git a/extend/base/admin/view/system/menu/export.js b/extend/base/admin/view/system/menu/export.js new file mode 100644 index 0000000..4d2e0be --- /dev/null +++ b/extend/base/admin/view/system/menu/export.js @@ -0,0 +1,3 @@ +$(function () { + ua.listen(); +}); \ No newline at end of file diff --git a/extend/base/admin/view/system/menu/import.html b/extend/base/admin/view/system/menu/import.html new file mode 100644 index 0000000..4880ae1 --- /dev/null +++ b/extend/base/admin/view/system/menu/import.html @@ -0,0 +1,22 @@ +
+
+
+ +
+ +
+
复制
+
上传
+ +
+ 从另一个系统中复制或下载,导出配置文件,在本页面导入或上传即可。请不要随意编辑内容,否则可能导致出错。 + 注意:这将覆盖当前系统的配置文件,请注意导出备份。 +
+
+
+
+ + +
+
+
\ No newline at end of file diff --git a/extend/base/admin/view/system/menu/import.js b/extend/base/admin/view/system/menu/import.js new file mode 100644 index 0000000..6b63064 --- /dev/null +++ b/extend/base/admin/view/system/menu/import.js @@ -0,0 +1,38 @@ +$(function () { + var fileInput = document.getElementById('json-file-input'); + fileInput.addEventListener('change', function (e) { + var files = e.target.files; + if (files.length > 0) { + var file = files[0]; + var reader = new FileReader(); + reader.onload = function (e) { + var jsonStr = e.target.result; + // 解析json字符串,判断是否出错 + try { + var jsonData = JSON.parse(jsonStr); + + } catch (error) { + layer.msg('JSON 解析出错,请检查 JSON 格式是否正确。'); + return; + } + $('#data').val(jsonStr); + }; + reader.readAsText(file); + } + }); + $('#process-json-file').click(function () { + + + fileInput.click(); + }); + + ua.listen(function (data) { + return data; + }, function (res) { + ua.msg.success(res.msg, function () { + var index = parent.layer.getFrameIndex(window.name); + parent.layer.close(index); + parent.$('[data-treetable-refresh]').trigger("click"); + }); + }); +}); \ No newline at end of file diff --git a/extend/base/admin/view/system/menu/index.html b/extend/base/admin/view/system/menu/index.html index 3d7c9a7..8b164c8 100644 --- a/extend/base/admin/view/system/menu/index.html +++ b/extend/base/admin/view/system/menu/index.html @@ -21,4 +21,6 @@ + + diff --git a/extend/base/common/command/admin/VersionBase.php b/extend/base/common/command/admin/VersionBase.php index a73d01d..5ebd284 100644 --- a/extend/base/common/command/admin/VersionBase.php +++ b/extend/base/common/command/admin/VersionBase.php @@ -12,14 +12,16 @@ use think\console\Output; class VersionBase extends Command { - public const VERSION = 'v2.0.108'; + public const VERSION = 'v2.0.109'; public const PRODUCT_VERSION = ''; public const LAYUI_VERSION = '2.8.17'; public const COMMENT = [ - '生成数据库迁移文件支持生成更新的迁移文件', + '增加菜单到导出和导入', + '增加粘贴全局操作', + '优化表单错误表现', '发布新版本', ]; diff --git a/public/static/plugs/ulthon-admin/ulthon-admin.js b/public/static/plugs/ulthon-admin/ulthon-admin.js index 9462612..232ced4 100644 --- a/public/static/plugs/ulthon-admin/ulthon-admin.js +++ b/public/static/plugs/ulthon-admin/ulthon-admin.js @@ -171,7 +171,12 @@ } }, error: function (xhr, textstatus, thrown) { - admin.msg.error('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!', function () { + var errorMsg = ''; + if(xhr.responseJSON.message){ + errorMsg = xhr.responseJSON.message; + } + loading.hide(); + admin.msg.error('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!
'+errorMsg, function () { ex(this); }); return false; @@ -1570,6 +1575,9 @@ // 监听点击复制 admin.api.copyText(); + // 监听点击粘贴 + admin.api.pasteText(); + // 监听tab操作 miniTab.listen(); @@ -2414,6 +2422,33 @@ }); }); + }, + pasteText(elem) { + if (elem == undefined) { + elem = 'body'; + } + var list = $(elem).find('[data-toggle="paste-text"]'); + + $.each(list, function (i, v) { + + if ($(v).hasClass('paste-rendered')) { + return false; + } + $(v).addClass('paste-rendered'); + + var targetElemName = $(v).data('paste-target'); + $(v).on('click', function () { + navigator.clipboard.readText() + .then(text => { + $(targetElemName).val(text); + layer.msg('粘贴成功'); + }) + .catch(err => { + console.error('Failed to read clipboard contents: ', err); + layer.msg('粘贴失败,请手动粘贴'); + }); + }); + }); } }, getQueryVariable(variable, defaultValue) {