3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
$(function() {
    cheackForm("from");
    $("title").text("菜单管理 - " + systemTitle);
});
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};
var ztree;
var local = window.location.href;
var menuId = local.substring(local.lastIndexOf('=') + 1, local.length);
 
var vm = new Vue({
    el:'#rapp',
    data:{
        title: null,
        menu:{
            parentName:null,
            parentId:0,
            type:1
        }
 
    },
    methods: {
        getMenu: function(){
            //加载菜单树
            $.get(restServerBaseURL + "sys/menu/select", function(r){
                ztree = $.fn.zTree.init($("#menuTree"), setting, r.menuList);
                var node = ztree.getNodeByParam("id", vm.menu.parentId);
                ztree.selectNode(node);
 
                vm.menu.parentName = node.name;
            })
        },
        saveOrUpdate: function () {
            var url = vm.menu.id == null ? "sys/menu/save" : "sys/menu/update";
            vm.menu.isshow = $("#isshow")[0].checked==true ? 1 : 0;
            vm.menu.target = $("#target")[0].checked==true ? 1 : 0;
            if ($("#from").valid()) {
                $.ajax({
                    type: "POST",
                    url: restServerBaseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.menu),
                    success: function (r) {
                        if (r.code === 0) {
                            alert('操作成功', function () {
                                if (vm.title == "新增") {
                                    window.location.href = window.location.href + "?menuId=" + r.id;
                                } else {
                                    window.location.reload();
                                }
                                if (parent.opener.vm && parent.opener.vm.reload) {
                                    parent.opener.vm.reload();
                                }
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }
        },
        menuTree: function(){
            openLayerOfBtn("300px", "450px", "选择菜单", "menuLayer", vm.menuTreeCallback);
        },
        menuTreeCallback: function () {
            var node = ztree.getSelectedNodes();
            //选择上级菜单
            vm.menu.parentId = node[0].id;
            vm.menu.parentName = node[0].name;
        },
        reload: function () {
            Menu.table.refresh();
        },
        refresh: function () {
            window.location.reload();
        }
    },
    created: function(){
        var search = window.location.search;
        var menuId = "";
        if(search.indexOf("?") > -1){
            search = search.replace("?", "");
            menuId = search.split('=')[1];
        }
        if(menuId == ""){
            this.title = "新增";
            this.menu = {parentName:null,parentId:0,type:1};
            this.getMenu();
        } else {
            this.title = "编辑";
            update1(menuId);
        }
    }
});
 
var Menu = {
    id: "menuTable",
    table: null,
    layerIndex: -1
};
 
   function update1(){
       $.get(restServerBaseURL + "sys/menu/info/"+menuId, function(r){
           $.get(restServerBaseURL + "sys/menu/info/"+menuId, function(r){
               vm.title = "修改";
               vm.menu = r.menu;
               if (r.code == 0 && vm.menu.isshow != null && vm.menu.isshow == 1) {
                    $("#isshow").prop("checked",true);
               }else{
                    $("#isshow").prop("checked",false);
               }
               if (r.code == 0 && vm.menu.target != null && vm.menu.target ==1) {
                    $("#target").prop("checked",true);
               }else{
                    $("#target").prop("checked",false);
               }
               vm.getMenu();
           });
       });
   }
 
    
function getMenuId () {
    var selected = $('#menuTable').bootstrapTreeTable('getSelections');
    var update = arguments[0] ? arguments[0] : false;
    if (selected.length == 0) {
        // update第一步GET的时候,为防止弹窗,不判断选择记录与否
        if (!update) {
            alert("请选择一条记录");
        }
        return;
    } else {
        return selected[0].id;
    }
}
 
function clearForm(){
    $(".panel-body input").each(function(){
        $(this).val("");
    })
    $("#type").val("");
}