From a637cdb04ab7e0954196ad0d8e7cc24ae22ee93a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 10 三月 2026 13:22:22 +0800
Subject: [PATCH] #

---
 src/main/webapp/static/js/resource/resource.js |  825 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 454 insertions(+), 371 deletions(-)

diff --git a/src/main/webapp/static/js/resource/resource.js b/src/main/webapp/static/js/resource/resource.js
index 5b5610d..1f3502c 100644
--- a/src/main/webapp/static/js/resource/resource.js
+++ b/src/main/webapp/static/js/resource/resource.js
@@ -1,382 +1,465 @@
-var pageCurr;
-layui.use(['table','laydate', 'form'], function(){
-    var table = layui.table;
-    var $ = layui.jquery;
-    var layer = layui.layer;
-    var layDate = layui.laydate;
-    var form = layui.form;
-
-    // 鏁版嵁娓叉煋
-    tableIns = table.render({
-        elem: '#resource',
-        headers: {token: localStorage.getItem('token')},
-        url: baseUrl+'/resource/list/auth',
-        page: true,
-        limit: 16,
-        limits: [16, 30, 50, 100, 200, 500],
-        toolbar: '#toolbar',
-        cellMinWidth: 50,
-        cols: [[
-            {type: 'checkbox', fixed: 'left'}
-            ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
-            ,{field: 'code', align: 'center',title: '鑿滃崟缂栫爜'}
-            ,{field: 'name', align: 'center',title: '鑿滃崟鍚嶇О'}
-            ,{field: 'resourceName', align: 'center',title: '鐖剁骇鑿滃崟'}
-            ,{field: 'level$', align: 'center',title: '鑿滃崟绛夌骇'}
-            ,{field: 'sort', align: 'center',title: '鎺掑簭'}
-            // ,{field: 'status$', align: 'center',title: '鐘舵��'}
-
-            ,{fixed: 'right', title:'鎿嶄綔', align: 'center', toolbar: '#operate', width:150}
-        ]],
-        request: {
-            pageName: 'curr',
-            pageSize: 'limit'
-        },
-        parseData: function (res) {
-            return {
-                'code': res.code,
-                'msg': res.msg,
-                'count': res.data.total,
-                'data': res.data.records
-            }
-        },
-        response: {
-            statusCode: 200
-        },
-        done: function(res, curr, count) {
-            if (res.code === 403) {
-                top.location.href = baseUrl+"/";
-            }
-            pageCurr=curr;
-            limit();
-        }
-    });
-
-    // 鐩戝惉鎺掑簭浜嬩欢
-    table.on('sort(resource)', function (obj) {
-        var searchData = {};
-        $.each($('#search-box [name]').serializeArray(), function() {
-            searchData[this.name] = this.value;
-        });
-        searchData['orderByField'] = obj.field;
-        searchData['orderByType'] = obj.type;
-        tableIns.reload({
-            where: searchData,
-            page: {
-                curr: 1
-            },
-            done: function (res, curr, count) {
-                if (res.code === 403) {
-                    top.location.href = baseUrl+"/";
-                }
-                pageCurr=curr;
-                limit();
-            }
-        });
-    });
-
-    // 鐩戝惉澶村伐鍏锋爮浜嬩欢
-    table.on('toolbar(resource)', function (obj) {
-        var checkStatus = table.checkStatus(obj.config.id);
-        switch(obj.event) {
-            case 'addData':
-                layer.open({
-                    type: 2,
-                    title: '鏂板',
-                    maxmin: true,
-                    area: [top.detailWidth, top.detailHeight],
-                    shadeClose: false,
-                    content: 'resource_detail.html',
-                    success: function(layero, index){
-                    	clearFormVal(layer.getChildFrame('#detail', index));
-                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
-                    }
-                });
-                break;
-            case 'refreshData':
-                tableIns.reload({
-                    page: {
-                        curr: pageCurr
-                    }
-                });
-                limit();
-                break;
-            case 'deleteData':
-                var data = checkStatus.data;
-                var ids=[];
-                data.map(function (track) {
-                    ids.push(track.id);
-                });
-                if (ids.length === 0){
-                    layer.msg('璇烽�夋嫨鏁版嵁');
-                } else {
-                    layer.confirm('纭畾鍒犻櫎'+(ids.length===1?'姝�':ids.length)+'鏉℃暟鎹悧', function(){
-                        $.ajax({
-                            url: baseUrl+"/resource/delete/auth",
-                            headers: {'token': localStorage.getItem('token')},
-                            data: {ids: ids},
-                            method: 'POST',
-                            traditional:true,
-                            success: function (res) {
-                                if (res.code === 200){
-                                    layer.closeAll();
-                                    tableReload(false);
-                                } else if (res.code === 403){
-                                    top.location.href = baseUrl+"/";
-                                } else {
-                                    layer.msg(res.msg)
-                                }
-                            }
-                        })
-                    });
-                }
-                break;
-            case 'exportData':
-                layer.confirm('纭畾瀵煎嚭Excel鍚�', {shadeClose: true}, function(){
-                    var titles=[];
-                    var fields=[];
-                    obj.config.cols[0].map(function (col) {
-                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
-                            titles.push(col.title);
-                            fields.push(col.field);
-                        }
-                    });
-                    var exportData = {};
-                    $.each($('#search-box [name]').serializeArray(), function() {
-                        exportData[this.name] = this.value;
-                    });
-                    var param = {
-                        'resource': exportData,
-                        'fields': fields
-                    };
-                    $.ajax({
-                        url: baseUrl+"/resource/export/auth",
-                        headers: {'token': localStorage.getItem('token')},
-                        data: JSON.stringify(param),
-                        dataType:'json',
-                        contentType:'application/json;charset=UTF-8',
-                        method: 'POST',
-                        success: function (res) {
-                            layer.closeAll();
-                            if (res.code === 200) {
-                                table.exportFile(titles,res.data,'xls');
-                            } else if (res.code === 403) {
-                                top.location.href = baseUrl+"/";
-                            } else {
-                                layer.msg(res.msg)
-                            }
-                        }
-                    });
-                });
-                break;
-        }
-    });
-
-    // 鐩戝惉琛屽伐鍏蜂簨浠�
-    table.on('tool(resource)', function(obj){
-        var data = obj.data;
-        switch (obj.event) {
-            // 璇︽儏
-            case 'detail':
-                layer.open({
-                    type: 2,
-                    title: '璇︽儏',
-                    maxmin: true,
-                    area: [top.detailWidth, top.detailHeight],
-                    shadeClose: false,
-                    content: 'resource_detail.html',
-                    success: function(layero, index){
-                        setFormVal(layer.getChildFrame('#detail', index), data, true);
-                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
-                        layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
-                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
-                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
-                    }
-                });
-                break;
-            // 缂栬緫
-            case 'edit':
-                layer.open({
-                    type: 2,
-                    title: '淇敼',
-                    maxmin: true,
-                    area: [top.detailWidth, top.detailHeight],
-                    shadeClose: false,
-                    content: 'resource_detail.html',
-                    success: function(layero, index){
-                        setFormVal(layer.getChildFrame('#detail', index), data, false);
-                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
-                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
-                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
-                    }
-                });
-                break;
-            case 'Resource':
-                var param = top.reObject(data).resourceId;
-                if (param === undefined) {
-                    layer.msg("鏃犳暟鎹�");
-                } else {
-                   layer.open({
-                       type: 2,
-                       title: '鐖剁骇璇︽儏',
-                       maxmin: true,
-                       area: [top.detailHeight, top.detailWidth],
-                       shadeClose: false,
-                       content: '../resource/resource_detail.html',
-                       success: function(layero, index){
-                           $.ajax({
-                               url: baseUrl+"/resource/"+ param +"/auth",
-                               headers: {'token': localStorage.getItem('token')},
-                               method: 'GET',
-                               success: function (res) {
-                                   if (res.code === 200){
-                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
-                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
-                                       layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
-                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
-                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
-                                   } else if (res.code === 403){
-                                       parent.location.href = "/";
-                                   }else {
-                                       layer.msg(res.msg)
-                                   }
-                               }
-                           })
-                       }
-                   });
-                }
-                break;
-
-        }
-    });
-
-    // 鏁版嵁淇敼鍔ㄤ綔
-    form.on('submit(edit)', function () {
-        var index = layer.load(1, {
-            shade: [0.5,'#000'] //0.1閫忔槑搴︾殑鑳屾櫙
-        });
-        var data = {
-            id: $('#id').val(),
-            code: $('#code').val(),
-            name: $('#name').val(),
-            resourceId: $('#resourceId').val(),
-            level: $('#level').val(),
-            sort: $('#sort').val(),
-            status: $('#status').val(),
-
+(function () {
+    function authHeaders() {
+        return {
+            token: localStorage.getItem('token') || ''
         };
-        $.ajax({
-            url: baseUrl+"/resource/edit/auth",
-            headers: {'token': localStorage.getItem('token')},
-            data: top.reObject(data),
-            method: 'POST',
-            success: function (res) {
-                if (res.code === 200){
-                    parent.layer.closeAll();
-                    tableReload(true);
-                    $("#data-detail :input").each(function () {
-                        $(this).val("");
-                    });
-                } else if (res.code === 403){
-                    top.location.href = baseUrl+"/";
-                }else {
-                    layer.msg(res.msg)
+    }
+
+    function isForbidden(res) {
+        return res && Number(res.code) === 403;
+    }
+
+    function isOk(res) {
+        return res && (Number(res.code) === 200 || Number(res.code) === 0);
+    }
+
+    function normalizeId(value) {
+        if (value === null || value === undefined || value === '') {
+            return null;
+        }
+        var numberValue = Number(value);
+        return isNaN(numberValue) ? value : numberValue;
+    }
+
+    function normalizeNumber(value, fallback) {
+        if (value === null || value === undefined || value === '') {
+            return fallback;
+        }
+        var numberValue = Number(value);
+        return isNaN(numberValue) ? fallback : numberValue;
+    }
+
+    function cloneRow(row) {
+        return {
+            id: normalizeId(row.id),
+            code: row.code || '',
+            name: row.name || '',
+            resourceId: normalizeId(row.resourceId),
+            level: normalizeNumber(row.level, 1),
+            sort: normalizeNumber(row.sort, 999),
+            status: normalizeNumber(row.status, 1)
+        };
+    }
+
+    function createDefaultForm() {
+        return {
+            id: null,
+            resourceId: null,
+            code: '',
+            level: 1,
+            name: '',
+            sort: 999,
+            status: 1
+        };
+    }
+
+    function sortNodes(nodes) {
+        nodes.sort(function (left, right) {
+            var sortDiff = normalizeNumber(left.sort, 999) - normalizeNumber(right.sort, 999);
+            if (sortDiff !== 0) {
+                return sortDiff;
+            }
+            return String(left.id).localeCompare(String(right.id), 'zh-Hans-CN', {numeric: true});
+        });
+        nodes.forEach(function (node) {
+            if (node.children && node.children.length > 0) {
+                sortNodes(node.children);
+            }
+        });
+        return nodes;
+    }
+
+    function buildTree(rows) {
+        var nodeMap = {};
+        var roots = [];
+
+        rows.forEach(function (item) {
+            var node = cloneRow(item);
+            node.children = [];
+            nodeMap[node.id] = node;
+        });
+
+        Object.keys(nodeMap).forEach(function (key) {
+            var current = nodeMap[key];
+            if (current.resourceId !== null && nodeMap[current.resourceId] && current.resourceId !== current.id) {
+                nodeMap[current.resourceId].children.push(current);
+            } else {
+                roots.push(current);
+            }
+        });
+
+        return sortNodes(roots);
+    }
+
+    new Vue({
+        el: '#app',
+        data: function () {
+            var vm = this;
+            return {
+                loading: false,
+                tableData: [],
+                tableKey: 0,
+                tableHeight: Math.max(window.innerHeight - 198, 360),
+                expandAll: false,
+                selection: [],
+                flatRows: [],
+                resourceLookup: {},
+                childrenLookup: {},
+                editingId: null,
+                dialog: {
+                    visible: false,
+                    mode: 'create',
+                    submitting: false
+                },
+                dialogForm: createDefaultForm(),
+                parentCascaderProps: {
+                    checkStrictly: true,
+                    emitPath: false,
+                    value: 'id',
+                    label: 'name',
+                    children: 'children'
+                },
+                dialogRules: {
+                    code: [
+                        {required: true, message: '璇疯緭鍏ヨ彍鍗曠紪鐮�', trigger: 'blur'}
+                    ],
+                    name: [
+                        {required: true, message: '璇疯緭鍏ヨ彍鍗曞悕绉�', trigger: 'blur'}
+                    ],
+                    level: [
+                        {required: true, message: '璇烽�夋嫨绫诲瀷', trigger: 'change'}
+                    ],
+                    resourceId: [
+                        {
+                            validator: function (rule, value, callback) {
+                                if (Number(vm.dialogForm.level) > 1 && (value === null || value === undefined || value === '')) {
+                                    callback(new Error('璇烽�夋嫨涓婄骇鑿滃崟'));
+                                    return;
+                                }
+                                callback();
+                            },
+                            trigger: 'change'
+                        }
+                    ],
+                    sort: [
+                        {type: 'number', message: '鎺掑簭蹇呴』涓烘暟瀛�', trigger: 'blur'}
+                    ],
+                    status: [
+                        {required: true, message: '璇烽�夋嫨鐘舵��', trigger: 'change'}
+                    ]
                 }
-                layer.close(index);
-            }
-        })
-    });
-
-    // 鎼滅储鏍忔悳绱簨浠�
-    form.on('submit(search)', function (data) {
-        pageCurr = 1;
-        tableReload(false);
-    });
-
-    // 鎼滅储鏍忛噸缃簨浠�
-    form.on('submit(reset)', function (data) {
-        pageCurr = 1;
-        clearFormVal($('#search-box'));
-        tableReload(false);
-    });
-
-    // 鏃堕棿閫夋嫨鍣�
-
-});
-
-// 鍏抽棴鍔ㄤ綔
-$(document).on('click','#data-detail-close', function () {
-    parent.layer.closeAll();
-});
-
-function tableReload(child) {
-    var searchData = {};
-    $.each($('#search-box [name]').serializeArray(), function() {
-        searchData[this.name] = this.value;
-    });
-    (child ? parent.tableIns : tableIns).reload({
-        where: searchData,
-        page: {
-            curr: pageCurr
+            };
         },
-        done: function (res, curr, count) {
-            if (res.code === 403) {
-                top.location.href = baseUrl+"/";
+        computed: {
+            parentOptions: function () {
+                var blocked = {};
+                if (this.editingId !== null) {
+                    blocked = this.collectDescendantIds(this.editingId);
+                }
+                return this.buildParentOptions(this.tableData, blocked);
             }
-            pageCurr=curr;
-            if (res.data.length === 0 && count !== 0) {
-                tableIns.reload({
-                    where: searchData,
-                    page: {
-                        curr: pageCurr-1
+        },
+        created: function () {
+            this.loadTree();
+        },
+        mounted: function () {
+            window.addEventListener('resize', this.handleResize);
+        },
+        beforeDestroy: function () {
+            window.removeEventListener('resize', this.handleResize);
+        },
+        methods: {
+            createDefaultForm: function () {
+                return createDefaultForm();
+            },
+            handleResize: function () {
+                this.tableHeight = Math.max(window.innerHeight - 198, 360);
+                this.refreshTableLayout();
+            },
+            handleForbidden: function (res) {
+                if (isForbidden(res)) {
+                    top.location.href = baseUrl + '/';
+                    return true;
+                }
+                return false;
+            },
+            refreshTableLayout: function () {
+                var vm = this;
+                this.$nextTick(function () {
+                    if (vm.$refs.treeTable && vm.$refs.treeTable.doLayout) {
+                        vm.$refs.treeTable.doLayout();
                     }
                 });
-                pageCurr -= 1;
-            }
-            limit(child);
-        }
-    });
-}
+            },
+            rebuildIndexes: function (rows) {
+                var lookup = {};
+                var childrenLookup = {};
 
-function setFormVal(el, data, showImg) {
-    for (var val in data) {
-        var find = el.find(":input[id='" + val + "']");
-        find.val(data[val]);
-        if (showImg){
-            var next = find.next();
-            if (next.get(0)){
-                if (next.get(0).localName === "img") {
-                    find.hide();
-                    next.attr("src", data[val]);
-                    next.show();
+                rows.forEach(function (item) {
+                    var normalized = cloneRow(item);
+                    lookup[normalized.id] = normalized;
+                    if (normalized.resourceId !== null) {
+                        if (!childrenLookup[normalized.resourceId]) {
+                            childrenLookup[normalized.resourceId] = [];
+                        }
+                        childrenLookup[normalized.resourceId].push(normalized.id);
+                    }
+                });
+
+                this.flatRows = rows.map(function (item) {
+                    return cloneRow(item);
+                });
+                this.resourceLookup = lookup;
+                this.childrenLookup = childrenLookup;
+            },
+            loadTree: function () {
+                var vm = this;
+                vm.loading = true;
+                $.ajax({
+                    url: baseUrl + '/resource/tree/auth',
+                    method: 'GET',
+                    headers: authHeaders(),
+                    success: function (res) {
+                        vm.loading = false;
+                        if (vm.handleForbidden(res)) {
+                            return;
+                        }
+                        if (!isOk(res)) {
+                            vm.$message.error(res && res.msg ? res.msg : '鑿滃崟鍔犺浇澶辫触');
+                            return;
+                        }
+                        var rows = Array.isArray(res.data) ? res.data : [];
+                        vm.rebuildIndexes(rows);
+                        vm.tableData = buildTree(rows);
+                        vm.selection = [];
+                        vm.tableKey += 1;
+                        vm.refreshTableLayout();
+                    },
+                    error: function () {
+                        vm.loading = false;
+                        vm.$message.error('鑿滃崟鍔犺浇澶辫触');
+                    }
+                });
+            },
+            handleSelectionChange: function (rows) {
+                this.selection = rows || [];
+            },
+            toggleExpandAll: function () {
+                this.expandAll = !this.expandAll;
+                this.tableKey += 1;
+                this.refreshTableLayout();
+            },
+            levelText: function (level) {
+                var currentLevel = Number(level);
+                if (currentLevel === 1) {
+                    return '涓�绾ц彍鍗�';
+                }
+                if (currentLevel === 2) {
+                    return '浜岀骇鑿滃崟';
+                }
+                if (currentLevel === 3) {
+                    return '鎸夐挳';
+                }
+                return '--';
+            },
+            levelTagType: function (level) {
+                var currentLevel = Number(level);
+                if (currentLevel === 3) {
+                    return 'info';
+                }
+                if (currentLevel === 2) {
+                    return '';
+                }
+                return 'success';
+            },
+            parentName: function (resourceId) {
+                if (resourceId === null || resourceId === undefined || resourceId === '') {
+                    return '';
+                }
+                var parent = this.resourceLookup[normalizeId(resourceId)];
+                return parent ? parent.name : '';
+            },
+            collectDescendantIds: function (resourceId) {
+                var blocked = {};
+                var stack = [normalizeId(resourceId)];
+                while (stack.length > 0) {
+                    var currentId = stack.pop();
+                    if (currentId === null || blocked[currentId]) {
+                        continue;
+                    }
+                    blocked[currentId] = true;
+                    var childIds = this.childrenLookup[currentId] || [];
+                    childIds.forEach(function (childId) {
+                        stack.push(childId);
+                    });
+                }
+                return blocked;
+            },
+            buildParentOptions: function (nodes, blocked) {
+                var vm = this;
+                return (nodes || []).reduce(function (result, node) {
+                    if (blocked[node.id]) {
+                        return result;
+                    }
+                    var option = {
+                        id: node.id,
+                        name: node.name,
+                        children: vm.buildParentOptions(node.children || [], blocked)
+                    };
+                    if (option.children.length === 0) {
+                        delete option.children;
+                    }
+                    result.push(option);
+                    return result;
+                }, []);
+            },
+            resetDialogForm: function () {
+                this.editingId = null;
+                this.dialogForm = this.createDefaultForm();
+                var vm = this;
+                this.$nextTick(function () {
+                    if (vm.$refs.dialogForm) {
+                        vm.$refs.dialogForm.clearValidate();
+                    }
+                });
+            },
+            openCreateDialog: function () {
+                this.dialog.mode = 'create';
+                this.dialog.visible = true;
+                this.resetDialogForm();
+            },
+            openEditDialog: function (row) {
+                this.dialog.mode = 'edit';
+                this.dialog.visible = true;
+                this.editingId = normalizeId(row.id);
+                this.dialogForm = {
+                    id: normalizeId(row.id),
+                    resourceId: normalizeId(row.resourceId),
+                    code: row.code || '',
+                    level: normalizeNumber(row.level, 1),
+                    name: row.name || '',
+                    sort: normalizeNumber(row.sort, 999),
+                    status: normalizeNumber(row.status, 1)
+                };
+                var vm = this;
+                this.$nextTick(function () {
+                    if (vm.$refs.dialogForm) {
+                        vm.$refs.dialogForm.clearValidate();
+                    }
+                });
+            },
+            removeSelection: function () {
+                if (!this.selection.length) {
+                    this.$message.warning('璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁');
+                    return;
+                }
+                var ids = this.selection.map(function (row) {
+                    return normalizeId(row.id);
+                }).filter(function (id) {
+                    return id !== null;
+                });
+                this.removeRows(ids);
+            },
+            removeRows: function (ids) {
+                var vm = this;
+                var uniqueIds = Array.from(new Set((ids || []).map(function (id) {
+                    return normalizeId(id);
+                }).filter(function (id) {
+                    return id !== null;
+                })));
+                if (!uniqueIds.length) {
+                    vm.$message.warning('璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁');
+                    return;
+                }
+                vm.$confirm('纭畾瑕佸垹闄ら�変腑鏁版嵁鍚楋紵', '鎻愮ず', {
+                    confirmButtonText: '纭畾',
+                    cancelButtonText: '鍙栨秷',
+                    type: 'warning'
+                }).then(function () {
+                    $.ajax({
+                        url: baseUrl + '/resource/delete/auth',
+                        method: 'POST',
+                        headers: authHeaders(),
+                        traditional: true,
+                        data: {
+                            ids: uniqueIds
+                        },
+                        success: function (res) {
+                            if (vm.handleForbidden(res)) {
+                                return;
+                            }
+                            if (!isOk(res)) {
+                                vm.$message.error(res && res.msg ? res.msg : '鍒犻櫎澶辫触');
+                                return;
+                            }
+                            vm.$message.success(res.msg || '鍒犻櫎鎴愬姛');
+                            vm.loadTree();
+                        },
+                        error: function () {
+                            vm.$message.error('鍒犻櫎澶辫触');
+                        }
+                    });
+                }).catch(function () {
+                });
+            },
+            submitDialog: function () {
+                var vm = this;
+                if (!vm.$refs.dialogForm) {
+                    return;
+                }
+                vm.$refs.dialogForm.validate(function (valid) {
+                    if (!valid) {
+                        return false;
+                    }
+                    var payload = {
+                        id: vm.dialog.mode === 'edit' ? normalizeId(vm.dialogForm.id) : null,
+                        resourceId: Number(vm.dialogForm.level) === 1 ? null : normalizeId(vm.dialogForm.resourceId),
+                        code: $.trim(vm.dialogForm.code),
+                        level: normalizeNumber(vm.dialogForm.level, 1),
+                        name: $.trim(vm.dialogForm.name),
+                        sort: normalizeNumber(vm.dialogForm.sort, 999),
+                        status: normalizeNumber(vm.dialogForm.status, 1)
+                    };
+                    vm.dialog.submitting = true;
+                    $.ajax({
+                        url: baseUrl + '/resource/' + (vm.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
+                        method: 'POST',
+                        headers: authHeaders(),
+                        data: payload,
+                        success: function (res) {
+                            vm.dialog.submitting = false;
+                            if (vm.handleForbidden(res)) {
+                                return;
+                            }
+                            if (!isOk(res)) {
+                                vm.$message.error(res && res.msg ? res.msg : '淇濆瓨澶辫触');
+                                return;
+                            }
+                            vm.$message.success(res.msg || '淇濆瓨鎴愬姛');
+                            vm.dialog.visible = false;
+                            vm.loadTree();
+                        },
+                        error: function () {
+                            vm.dialog.submitting = false;
+                            vm.$message.error('淇濆瓨澶辫触');
+                        }
+                    });
+                    return true;
+                });
+            }
+        },
+        watch: {
+            'dialogForm.level': function (value) {
+                if (Number(value) === 1) {
+                    this.dialogForm.resourceId = null;
+                }
+            },
+            'dialog.visible': function (visible) {
+                if (!visible) {
+                    this.resetDialogForm();
+                    this.dialog.submitting = false;
                 }
             }
         }
-    }
-}
-
-function clearFormVal(el) {
-    $(':input', el)
-        .val('')
-        .removeAttr('checked')
-        .removeAttr('selected');
-}
-
-function detailScreen(index) {
-    var detail = layer.getChildFrame('#data-detail', index);
-    var height = detail.height()+60;
-    if (height > ($(window).height()*0.9)) {
-        height = ($(window).height()*0.9);
-    }
-    layer.style(index, {
-        top: (($(window).height()-height)/3)+"px",
-        height: height+'px'
     });
-    $(".layui-layer-shade").remove();
-}
-
-$('body').keydown(function () {
-    if (event.keyCode === 13) {
-        $("#search").click();
-    }
-});
+})();

--
Gitblit v1.9.1