123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="keywords" content="">
- <meta name="description" content="">
- <title text="系统菜单"></title>
- <link rel="stylesheet" href="../../../component/pear/css/pear.css">
- <style>
- .pear-btn-success {background-color: #2d8cf0 !important;}
- </style>
- </head>
- <body>
- <form class="layui-form" lay-filter="edit">
- <input type="hidden" name="id">
- <div class="mainBox">
- <div class="main-container">
- <div class="layui-form-item">
- <label class="layui-form-label layui-required">上级菜单:</label>
- <div class="layui-input-block">
- <div id="tree"></div>
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label layui-required">菜单名称:</label>
- <div class="layui-input-block">
- <input type="text" name="title" placeholder="菜单名称" lay-verify="required"
- autocomplete="off" class="layui-input" value="">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label layui-required">权限类型:</label>
- <div class="layui-input-block">
- <input type="radio" lay-filter="type" name="type" value="0" title="目录">
- <input type="radio" lay-filter="type" name="type" value="1" title="菜单">
- <input type="radio" lay-filter="type" name="type" value="2" title="按钮">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">菜单图标:</label>
- <div class="layui-input-block">
- <input type="text" id="icon" name="icon" lay-filter="icon"
- class="layui-input">
- </div>
- </div>
- <div class="layui-form-item" id="codeItem">
- <label class="layui-form-label">权限标识:</label>
- <div class="layui-input-block">
- <input type="text" id="code" name="code" placeholder="权限标识:sys:menu:main"
- class="layui-input" autocomplete="off">
- </div>
- </div>
- <div class="layui-form-item" id="urlItem">
- <label class="layui-form-label">菜单路径:</label>
- <div class="layui-input-block">
- <input type="text" id="href" name="href" placeholder="菜单路径: /system/menu/main"
- class="layui-input" autocomplete="off">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label layui-required">菜单排序:</label>
- <div class="layui-input-block">
- <input type="text" name="sort" placeholder="请输入排序号"
- class="layui-input" autocomplete="off" lay-verify="required">
- </div>
- </div>
- </div>
- </div>
- <div class="bottom">
- <div class="button-container">
- <button type="submit" class="pear-btn pear-btn-success"
- lay-submit="" lay-filter="save">保 存
- </button>
- <button type="submit" class="pear-btn" id="close">
- 关 闭
- </button>
- </div>
- </div>
- </form>
- <script src="../../../component/layui/layui.js"></script>
- <script src="../../../component/pear/pear.js"></script>
- <script src="../../../component/js/xm-select.js"></script>
- <script>
- layui.use(['request', 'form', 'iconPicker', 'popup'], function () {
- var $ = layui.jquery,
- request = layui.request,
- form = layui.form,
- iconPicker = layui.iconPicker,
- popup = layui.popup;
- var MODULE_PATH = "/system/menu/v1/";
- var menuSelectTree = xmSelect.render({
- el: '#tree',
- name: 'parentId', // 表单提交name
- model: {label: {type: 'text'}},
- layVerify: 'required', // 必填
- clickClose: true, // 点击关闭
- tree: {
- show: true, // 是否显示树状结构
- showLine: false, // 是否显示虚线
- strict: false, // 是否严格遵守父子模式
- expandedKeys: [1], // 默认展开节点的数组, 为 true 时, 展开所有节点
- },
- prop: { // key value 名称修改
- name: 'title',
- value: 'id'
- },
- on: function (data) {
- if (data.isAdd) {
- return data.change.slice(0, 1)
- }
- },
- data: []
- });
- layer.ready(function() {
- request.httpGet(MODULE_PATH + 'selectTree', function(result) {
- if (result.success) {
- menuSelectTree.update({
- data: result.data,
- autoRow: true,
- });
- var id = request.getQueryString("id");
- if (id) {
- request.httpGet(MODULE_PATH + id, function (result) {
- form.val('edit', result.data);
- // xmSelect回显
- menuSelectTree.setValue([result.data.parentId]);
- // 单选框事件回显
- window.init(result.data.type);
- // 图标选择器回显
- iconPicker.checkIcon("icon", result.data.icon);
- });
- }
- }
- });
- });
- // 单选框点击事件
- form.on("radio(type)", function () {
- window.init(this.value);
- });
- window.init = function(type) {
- if (parseInt(type) === 0) {
- $("#urlItem").hide();
- $("#codeItem").hide();
- $("#url").val("");
- $("#code").val("");
- } else if (parseInt(type) === 1) {
- $("#urlItem").show();
- $("#codeItem").show();
- } else if (parseInt(type) === 2) {
- $("#urlItem").hide();
- $("#codeItem").show();
- $("#url").val("");
- }
- };
- // 图标选择器
- iconPicker.render({
- elem: '#icon', // 选择器,推荐使用input
- type: 'fontClass', // 数据类型:fontClass/unicode,推荐使用 fontClass
- search: true, // 是否开启搜索:true/false
- page: true, // 是否开启分页
- limit: 12 // 每页显示数量,默认12
- });
- form.on('submit(save)', function (data) {
- if (data.field.icon.indexOf("layui-icon ") === -1) {
- data.field.icon = "layui-icon " + data.field.icon;
- }
- request.http({
- url: MODULE_PATH,
- type: (data.field.id ? 'put':'post'),
- data: data.field,
- success: function (res) {
- if (res.success) {
- popup.success(res.msg, function () {
- parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
- parent.render();
- })
- } else {
- popup.failure(res.msg);
- }
- }
- });
- return false;
- });
- $('#close').on('click', function () {
- parent.layer.closeAll();
- });
- })
- </script>
- </body>
- </html>
|