sugangqiang 2 gadi atpakaļ
vecāks
revīzija
af0d53bb37

+ 62 - 3
app/admin/controller/Menu.php

@@ -3,6 +3,7 @@
 namespace app\admin\controller;
 
 use app\admin\common\AdminController;
+use app\common\api\MenuApi;
 
 /**
  * Description of Menu
@@ -11,28 +12,86 @@ use app\admin\common\AdminController;
  */
 class Menu extends AdminController {
 
+    /**
+     * @auth {{/menu}}
+     * @return type
+     */
     function index() {
         return view();
     }
 
+    /**
+     * @auth {{/menu/list}}
+     * @return type
+     */
+    function list() {
+        if ($this->request->isPost()) {
+
+            return json([]);
+        }
+    }
+
+    /**
+     * @auth {{/menu/add}}
+     * @return type
+     */
     function add() {
         if ($this->request->isPost()) {
-            
+            try {
+                $params = $this->request->param();
+                validate(\app\admin\validate\Menu::class)->check($params);
+                if (MenuApi::save($this->request->param())) {
+                    return json(["msg" => "添加成功"]);
+                }
+                return json(["msg" => "添加失败"]);
+            } catch (\think\Exception $e) {
+                return json(["msg" => $e->getMessage()]);
+            }
         }
         return view();
     }
 
+    /**
+     * @auth {{/menu/edit}}
+     * @return type
+     */
     function edit() {
         if ($this->request->isPost()) {
-            
+            try {
+                $params = $this->request->param();
+                if (!$params["id"])
+                    return json(["msg" => "没有选择菜单"]);
+                validate(\app\admin\validate\Menu::class)->check($params);
+                if (MenuApi::save($this->request->param())) {
+                    return json(["msg" => "修改成功"]);
+                }
+                return json(["msg" => "修改失败"]);
+            } catch (\think\Exception $e) {
+                return json(["msg" => $e->getMessage()]);
+            }
         }
         return view();
     }
 
+    /**
+     * @auth {{/menu/remove}}
+     * @return type
+     */
     function delete() {
         if ($this->request->isPost()) {
-            
+            return json([]);
+        }
+    }
+
+    function selectMenuTreeList() {
+        $list = \app\common\api\MenuApi::getAllMenus("id,code,pcode,name,num,levels,ismenu");
+        foreach ($list as $key => $item) {
+            if ($item["pcode"] == "0") {
+                $list[$key]["open"] = true;
+            }
         }
+        $format_list[] = ["code" => 0, "pcode" => "", "name" => "顶级", "open" => true, "children" => $list];
+        return $format_list;
     }
 
     /**

+ 39 - 0
app/admin/validate/Menu.php

@@ -0,0 +1,39 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace app\admin\validate;
+
+use think\Validate;
+
+/**
+ * Description of Menu
+ *
+ * @author sgq
+ */
+class Menu extends Validate {
+
+    protected $rule = [
+        'name' => 'require|max:255',
+        'url' => 'require|max:255',
+        'code' => 'require|max:255',
+        'pcode' => 'require|max:255',
+        'num' => 'require'
+    ];
+    protected $message = [
+        'name.require' => '请填写菜单名称!',
+        'name.max' => '菜单名称最多255个字符!',
+        'url.require' => '请填写请求地址!',
+        'url.max' => '请求地址最多255个字符!',
+        'code.require' => '请填写菜单编号!',
+        'code.max' => '菜单编号最多255个字符!',
+        'pcode.require' => '请填写父级编号!',
+        'pcode.max' => '父级编号最多255个字符!',
+        'num.require' => '请填写菜单排序!',
+    ];
+
+}

+ 6 - 6
app/admin/view/menu/add.html

@@ -20,14 +20,14 @@
                             <input class="form-control" id="code" name="code" type="text">
                         </div>
                     </div>
-                    <div class="form-group">
+                    <div class="form-group has-feedback">
                         <label class="col-sm-3 control-label">父级编号</label>
                         <div class="col-sm-9">
-                            <input class="form-control" id="pcodeName" name="pcodeName" type="text" readonly="readonly" onclick="MenuInfoDlg.showMenuSelectTree(); return false;" style="background-color: #ffffff !important;">
-                        </div>
-                        <input class="form-control" type="hidden" id="pcode" value="">
-                        <div id="pcodeTreeDiv" style="display: none; position: absolute; z-index: 200;">
-                            <ul id="pcodeTree" class="ztree tree-box" style="width:244px !important;"></ul>
+                            <input class="form-control" id="pcodeName" name="pcodeName" type="text" readonly="readonly" onclick="MenuInfoDlg.showMenuSelectTree(); return false;" style="background-color: #ffffff !important;">                            
+                            <input class="form-control" type="hidden" id="pcode" value="">
+                            <div id="pcodeTreeDiv" style="display: none; position: absolute; z-index: 200;">
+                                <ul id="pcodeTree" class="ztree tree-box" style="width:244px !important;"></ul>
+                            </div>
                         </div>
                     </div>
                     <div class="form-group">

+ 42 - 14
app/admin/view/menu/index.html

@@ -11,32 +11,60 @@
                     <div class="col-sm-12">
                         <div class="row">
                             <div class="col-sm-3">
-                                <#NameCon id="menuName" name="菜单名称" />
+                                <div class="input-group input-group-sm">
+                                    <div class="input-group-btn">
+                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">
+                                            菜单名称
+                                        </button>
+                                    </div>
+                                    <input type="text" class="form-control" id="menuName"/>
+                                </div>
                             </div>
                             <div class="col-sm-3">
-                                <#NameCon id="level" name="层级" />
+                                <div class="input-group input-group-sm">
+                                    <div class="input-group-btn">
+                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">
+                                            层级
+                                        </button>
+                                    </div>
+                                    <input type="text" class="form-control" id="level"/>
+                                </div>
                             </div>
                             <div class="col-sm-3">
-                                <#button name="搜索" icon="fa-search" clickFun="Menu.search()"/>
+                                <button type="button" class="btn btn-sm btn-primary" onclick="Menu.search()">
+                                    <i class="fa fa-search"></i>&nbsp;搜索
+                                </button>
                             </div>
                         </div>
                         <div class="hidden-xs" id="menuTableToolbar" role="group">
-                            @if(shiro.hasPermission("/menu/add")){
-                                <#button name="添加" icon="fa-plus" clickFun="Menu.openAddMenu()"/>
-                            @}
-                            @if(shiro.hasPermission("/menu/edit")){
-                                <#button name="修改" icon="fa-edit" clickFun="Menu.openChangeMenu()" space="true"/>
-                            @}
-                            @if(shiro.hasPermission("/menu/remove")){
-                                <#button name="删除" icon="fa-remove" clickFun="Menu.delMenu()" space="true"/>
-                            @}
+                            {if condition="chkCommission('/admin/user/add','/menu/add')"}
+                            <button type="button" class="btn btn-sm btn-primary" onclick="Menu.openAddMenu()">
+                                <i class="fa fa-plus"></i>&nbsp;添加
+                            </button>
+                            {/if}
+                            {if condition="chkCommission('/admin/menu/edit','/menu/edit')"}
+                            <button type="button" class="btn btn-sm btn-primary button-margin" onclick="Menu.openChangeMenu()">
+                                <i class="fa fa-edit"></i>&nbsp;修改
+                            </button>
+                            {/if}
+                            {if condition="chkCommission('/admin/menu/delete','/menu/remove')"}
+                            <button type="button" class="btn btn-sm btn-primary button-margin" onclick="Menu.delMenu()">
+                                <i class="fa fa-remove"></i>&nbsp;删除
+                            </button>
+                            {/if}
                         </div>
-                        <#table id="menuTable"/>
+                        <table id="menuTable" class="table-condensed" style="font-size: 10px;table-layout: fixed!important;" data-mobile-responsive="true" data-click-to-select="true">
+                            <thead>
+                                <tr>
+                                    <th data-field="selectItem" data-checkbox="true"></th>
+                                </tr>
+                            </thead>
+                        </table>
                     </div>
                 </div>
             </div>
         </div>
     </div>
 </div>
-<script src="${ctxPath}/static/modular/system/menu/menu.js"></script>
+<script src="/static/modular/system/menu/menu.js"></script>
 {/block}

+ 28 - 0
app/common/api/MenuApi.php

@@ -21,6 +21,34 @@ class MenuApi {
         return Menu::where($where)->column("id");
     }
 
+    public static function save($params) {
+        $data["name"] = $params["name"];
+        $data["new_url"] = $params["url"];
+        $data["code"] = $params["code"];
+        $data["pcode"] = $params["pcode"];
+        $data["num"] = $params["num"];
+        $data["icon"] = $params["icon"];
+        $data["ismenu"] = $params["ismenu"];
+        $pcode =  $params["pcode"];
+        $tmp = [];
+        while($pcode != "0"){
+            
+        }
+        if ($params["id"]) {
+            $data["id"] = $params["id"];
+            return Menu::update($data);
+        }
+        return Menu::insert($data);
+    }
+
+    public static function getAllMenus($fields = "*") {
+        $where[] = ["status", "=", 1];
+        $where[] = ["delete", "=", 0];
+        $menus = Menu::where($where)->field($fields)->order("levels asc,num asc")->select()->toArray();
+        $menus = self::buildMenu($menus);
+        return $menus;
+    }
+
     public static function getMenuListByRoleid($roleid) {
         $role = Role::find($roleid);
         $tmp = [];

+ 6 - 6
public/static/modular/system/menu/menu.js

@@ -2,8 +2,8 @@
  * 角色管理的单例
  */
 var Menu = {
-    id: "menuTable",	//表格id
-    seItem: null,		//选中的条目
+    id: "menuTable", //表格id
+    seItem: null, //选中的条目
     table: null,
     layerIndex: -1
 };
@@ -51,7 +51,7 @@ Menu.openAddMenu = function () {
         area: ['830px', '450px'], //宽高
         fix: false, //不固定
         maxmin: true,
-        content: Feng.ctxPath + '/menu/menu_add'
+        content: Feng.ctxPath + '/admin/menu/add'
     });
     this.layerIndex = index;
 };
@@ -67,7 +67,7 @@ Menu.openChangeMenu = function () {
             area: ['800px', '450px'], //宽高
             fix: false, //不固定
             maxmin: true,
-            content: Feng.ctxPath + '/menu/menu_edit/' + this.seItem.id
+            content: Feng.ctxPath + '/admin/menu/edit/id/' + this.seItem.id
         });
         this.layerIndex = index;
     }
@@ -80,7 +80,7 @@ Menu.delMenu = function () {
     if (this.check()) {
 
         var operation = function () {
-            var ajax = new $ax(Feng.ctxPath + "/menu/remove", function (data) {
+            var ajax = new $ax(Feng.ctxPath + "/admin/menu/delete", function (data) {
                 Feng.success("删除成功!");
                 Menu.table.refresh();
             }, function (data) {
@@ -108,7 +108,7 @@ Menu.search = function () {
 
 $(function () {
     var defaultColunms = Menu.initColumn();
-    var table = new BSTreeTable(Menu.id, "/menu/list", defaultColunms);
+    var table = new BSTreeTable(Menu.id, "/admin/menu/list", defaultColunms);
     table.setExpandColumn(2);
     table.setIdField("id");
     table.setCodeField("code");

+ 5 - 5
public/static/modular/system/menu/menu_info.js

@@ -107,7 +107,7 @@ MenuInfoDlg.addSubmit = function () {
     }
 
     //提交信息
-    var ajax = new $ax(Feng.ctxPath + "/menu/add", function (data) {
+    var ajax = new $ax(Feng.ctxPath + "/admin/menu/add", function (data) {
         Feng.success("添加成功!");
         window.parent.Menu.table.refresh();
         MenuInfoDlg.close();
@@ -131,7 +131,7 @@ MenuInfoDlg.editSubmit = function () {
     }
 
     //提交信息
-    var ajax = new $ax(Feng.ctxPath + "/menu/edit", function (data) {
+    var ajax = new $ax(Feng.ctxPath + "/admin/menu/edit", function (data) {
         Feng.success("修改成功!");
         window.parent.Menu.table.refresh();
         MenuInfoDlg.close();
@@ -161,15 +161,15 @@ MenuInfoDlg.showMenuSelectTree = function () {
 $(function () {
     Feng.initValidator("menuInfoForm", MenuInfoDlg.validateFields);
 
-    var ztree = new $ZTree("pcodeTree", "/menu/selectMenuTreeList");
+    var ztree = new $ZTree("pcodeTree", "/admin/menu/selectMenuTreeList");
     ztree.bindOnClick(MenuInfoDlg.onClickDept);
     ztree.init();
     MenuInfoDlg.ztreeInstance = ztree;
 
     //初始化是否是菜单
-    if($("#ismenuValue").val() == undefined){
+    if ($("#ismenuValue").val() == undefined) {
         $("#ismenu").val(0);
-    }else{
+    } else {
         $("#ismenu").val($("#ismenuValue").val());
     }
 });