Przeglądaj źródła

解决csrf_token缺失报错问题

jqh 4 lat temu
rodzic
commit
cb2df2314e

+ 90 - 82
resources/assets/dcat/js/bootstrappers/Menu.js

@@ -1,82 +1,90 @@
-
-export default class Menu {
-    constructor(Dcat) {
-        this.init();
-        this.initHorizontal();
-    }
-
-    // 菜单点击选中效果
-    init() {
-        if (! $('.main-sidebar .sidebar').length) {
-            return;
-        }
-
-        // 滚动条优化
-        new PerfectScrollbar('.main-sidebar .sidebar');
-
-        let $content = $('.main-menu-content'),
-            $items = $content.find('li'),
-            $hasSubItems = $content.find('li.has-treeview');
-
-        $items.find('a').click(function () {
-            let href = $(this).attr('href');
-            if (! href || href === '#') {
-                return;
-            }
-
-            $items.find('.nav-link').removeClass('active');
-            // $hasSubItems.removeClass('menu-open');
-
-            $(this).addClass('active')
-        });
-    }
-
-    initHorizontal() {
-        let selectors = {
-            item: '.horizontal-menu .main-menu-content li.nav-item',
-            link: '.horizontal-menu .main-menu-content li.nav-item .nav-link',
-        };
-
-        $(selectors.item).on('mouseover', function () {
-            $(this).addClass('open')
-        }).on('mouseout', function () {
-            $(this).removeClass('open')
-        });
-
-        $(selectors.link).on('click', function () {
-            let $this = $(this);
-
-            $(selectors.link).removeClass('active');
-
-            $this.addClass('active');
-
-            $this.parents('.dropdown').find('.nav-link').eq(0).addClass('active');
-            $this.parents('.dropdown-submenu').find('.nav-link').eq(0).addClass('active')
-        });
-
-        // 自动计算高度
-        let $horizontalMenu = $('.horizontal-menu .main-horizontal-sidebar'),
-            defaultHorizontalMenuHeight = $horizontalMenu.height(),
-            horizontalMenuTop = $horizontalMenu.offset().top + 15;
-
-        // 重新计算高度
-        let resize = function () {
-            if (! $('.horizontal-menu').length) {
-                return;
-            }
-
-            let height = $horizontalMenu.height(),
-                diff = height - defaultHorizontalMenuHeight,
-                $wrapper = $('.horizontal-menu.navbar-fixed-top .content-wrapper');
-
-            if (height <= defaultHorizontalMenuHeight) {
-                return $wrapper.css({'padding-top': horizontalMenuTop + 'px'});
-            }
-
-            $wrapper.css({'padding-top': (horizontalMenuTop + diff) + 'px'});
-        };
-        window.onresize = resize;
-
-        resize();
-    }
-}
+
+export default class Menu {
+    constructor(Dcat) {
+        this.init();
+        this.initHorizontal();
+    }
+
+    // 菜单点击选中效果
+    init() {
+        if (! $('.main-sidebar .sidebar').length) {
+            return;
+        }
+
+        // 滚动条优化
+        new PerfectScrollbar('.main-sidebar .sidebar');
+
+        let $content = $('.main-menu-content'),
+            $items = $content.find('li'),
+            $hasSubItems = $content.find('li.has-treeview');
+
+        $items.find('a').click(function () {
+            let href = $(this).attr('href');
+            if (! href || href === '#') {
+                return;
+            }
+
+            $items.find('.nav-link').removeClass('active');
+            // $hasSubItems.removeClass('menu-open');
+
+            $(this).addClass('active')
+        });
+    }
+
+    initHorizontal() {
+        let selectors = {
+            item: '.horizontal-menu .main-menu-content li.nav-item',
+            link: '.horizontal-menu .main-menu-content li.nav-item .nav-link',
+        };
+
+        $(selectors.item).on('mouseover', function () {
+            $(this).addClass('open')
+        }).on('mouseout', function () {
+            $(this).removeClass('open')
+        });
+
+        $(selectors.link).on('click', function () {
+            let $this = $(this);
+
+            $(selectors.link).removeClass('active');
+
+            $this.addClass('active');
+
+            $this.parents('.dropdown').find('.nav-link').eq(0).addClass('active');
+            $this.parents('.dropdown-submenu').find('.nav-link').eq(0).addClass('active')
+        });
+
+        // 自动计算高度
+        let $horizontalMenu = $('.horizontal-menu .main-horizontal-sidebar'),
+            defaultHorizontalMenuHeight = 0,
+            horizontalMenuTop = 0;
+
+        // 重新计算高度
+        let resize = function () {
+            if (! $('.horizontal-menu').length) {
+                return;
+            }
+
+            if (! defaultHorizontalMenuHeight) {
+                defaultHorizontalMenuHeight = $horizontalMenu.height()
+            }
+
+            if (! horizontalMenuTop) {
+                horizontalMenuTop = $horizontalMenu.offset().top + 15;
+            }
+
+            let height = $horizontalMenu.height(),
+                diff = height - defaultHorizontalMenuHeight,
+                $wrapper = $('.horizontal-menu.navbar-fixed-top .content-wrapper');
+
+            if (height <= defaultHorizontalMenuHeight) {
+                return $wrapper.css({'padding-top': horizontalMenuTop + 'px'});
+            }
+
+            $wrapper.css({'padding-top': (horizontalMenuTop + diff) + 'px'});
+        };
+        window.onresize = resize;
+
+        resize();
+    }
+}

+ 169 - 168
resources/assets/dcat/js/extensions/Ajax.js

@@ -1,168 +1,169 @@
-
-export default class Ajax {
-    constructor(Dcat) {
-        this.dcat = Dcat;
-
-        Dcat.handleAjaxError = this.handleAjaxError.bind(this);
-        Dcat.handleJsonResponse = this.handleJsonResponse.bind(this);
-
-        this.init(Dcat)
-    }
-
-    init(Dcat) {
-        $.get = function (url, data, success, dataType) {
-            let options = {
-                type: 'GET',
-                url: url,
-            };
-
-            if (typeof data === 'function') {
-                dataType = success;
-                success = data;
-                data = null
-            }
-
-            if (typeof success === 'function') {
-                options.success = success;
-            }
-
-            if (typeof data === 'object') {
-                options.data = data
-            }
-
-            if (dataType) {
-                options.dataType = dataType;
-            }
-
-            return $.ajax(options)
-        };
-
-        $.post = function (options) {
-            options.type = 'POST';
-
-            return $.ajax(options);
-        };
-
-        $.delete = function (options) {
-            options.type = 'POST';
-            options.data = {_method: 'DELETE'};
-
-            return $.ajax(options);
-        };
-
-        $.put = function (options) {
-            options.type = 'POST';
-            Object.assign(options.data, {_method: 'PUT'});
-
-            return $.ajax(options);
-        };
-    }
-
-    handleAjaxError(xhr, text, msg) {
-        let Dcat = this.dcat,
-            json = xhr.responseJSON || {},
-            _msg = json.message;
-
-        Dcat.NP.done();
-        Dcat.loading(false);// 关闭所有loading效果
-        $('.btn-loading').buttonLoading(false);
-
-        switch (xhr.status) {
-            case 500:
-                return Dcat.error(_msg || (Dcat.lang['500'] || 'Server internal error.'));
-            case 403:
-                return Dcat.error(_msg || (Dcat.lang['403'] || 'Permission deny!'));
-            case 401:
-                if (json.login) {
-                    return location.href = json.login;
-                }
-                return Dcat.error(Dcat.lang['401'] || 'Unauthorized.');
-            case 419:
-                return Dcat.error(Dcat.lang['419'] || 'Sorry, your page has expired.');
-
-            case 422:
-                if (json.errors) {
-                    try {
-                        var err = [], i;
-                        for (i in json.errors) {
-                            err.push(json.errors[i].join('<br/>'));
-                        }
-                        Dcat.error(err.join('<br/>'));
-                    } catch (e) {}
-                    return;
-                }
-        }
-
-        Dcat.error(_msg || (xhr.status + ' ' + msg));
-    }
-
-    // 处理接口返回数据
-    handleJsonResponse(response, options) {
-        let Dcat = this.dcat,
-            data = response.data;
-
-        if (! response) {
-            return;
-        }
-
-        if (typeof response !== 'object') {
-            return Dcat.error('error', 'Oops!');
-        }
-
-        var then = function (then) {
-            switch (then.action) {
-                case 'refresh':
-                    Dcat.reload();
-                    break;
-                case 'download':
-                    window.open(then.value, '_blank');
-                    break;
-                case 'redirect':
-                    Dcat.reload(then.value || null);
-                    break;
-                case 'location':
-                    setTimeout(function () {
-                        if (then.value) {
-                            window.location = then.value;
-                        } else {
-                            window.location.reload();
-                        }
-                    }, 1000);
-                    break;
-                case 'script':
-                    (function () {
-                        eval(then.value);
-                    })();
-                    break;
-            }
-        };
-
-        if (typeof response.html === 'string' && response.html && options.target) {
-            if (typeof options.html === 'function') {
-                // 处理api返回的HTML代码
-                options.html(options.target, response.html, response);
-            } else {
-                $(target).html(response.html);
-            }
-        }
-
-        let message = data.message || response.message;
-
-        // 判断默认弹窗类型.
-        if (! data.type) {
-            data.type = response.status ? 'success' : 'error';
-        }
-
-        if (typeof message === 'string' && data.type && message) {
-            if (data.alert) {
-                Dcat.swal[data.type](message, data.detail);
-            } else {
-                Dcat[data.type](message, null, data.timeout ? {timeOut: data.timeout*1000} : {});
-            }
-        }
-
-        if (data.then) {
-            then(data.then);
-        }
-    }
-}
+
+export default class Ajax {
+    constructor(Dcat) {
+        this.dcat = Dcat;
+
+        Dcat.handleAjaxError = this.handleAjaxError.bind(this);
+        Dcat.handleJsonResponse = this.handleJsonResponse.bind(this);
+
+        this.init(Dcat)
+    }
+
+    init(Dcat) {
+        $.get = function (url, data, success, dataType) {
+            let options = {
+                type: 'GET',
+                url: url,
+            };
+
+            if (typeof data === 'function') {
+                dataType = success;
+                success = data;
+                data = null
+            }
+
+            if (typeof success === 'function') {
+                options.success = success;
+            }
+
+            if (typeof data === 'object') {
+                options.data = data
+            }
+
+            if (dataType) {
+                options.dataType = dataType;
+            }
+
+            return $.ajax(options)
+        };
+
+        $.post = function (options) {
+            options.type = 'POST';
+            Object.assign(options.data, {_token: Dcat.token});
+
+            return $.ajax(options);
+        };
+
+        $.delete = function (options) {
+            options.type = 'POST';
+            options.data = {_method: 'DELETE', _token: Dcat.token};
+
+            return $.ajax(options);
+        };
+
+        $.put = function (options) {
+            options.type = 'POST';
+            Object.assign(options.data, {_method: 'PUT', _token: Dcat.token});
+
+            return $.ajax(options);
+        };
+    }
+
+    handleAjaxError(xhr, text, msg) {
+        let Dcat = this.dcat,
+            json = xhr.responseJSON || {},
+            _msg = json.message;
+
+        Dcat.NP.done();
+        Dcat.loading(false);// 关闭所有loading效果
+        $('.btn-loading').buttonLoading(false);
+
+        switch (xhr.status) {
+            case 500:
+                return Dcat.error(_msg || (Dcat.lang['500'] || 'Server internal error.'));
+            case 403:
+                return Dcat.error(_msg || (Dcat.lang['403'] || 'Permission deny!'));
+            case 401:
+                if (json.login) {
+                    return location.href = json.login;
+                }
+                return Dcat.error(Dcat.lang['401'] || 'Unauthorized.');
+            case 419:
+                return Dcat.error(Dcat.lang['419'] || 'Sorry, your page has expired.');
+
+            case 422:
+                if (json.errors) {
+                    try {
+                        var err = [], i;
+                        for (i in json.errors) {
+                            err.push(json.errors[i].join('<br/>'));
+                        }
+                        Dcat.error(err.join('<br/>'));
+                    } catch (e) {}
+                    return;
+                }
+        }
+
+        Dcat.error(_msg || (xhr.status + ' ' + msg));
+    }
+
+    // 处理接口返回数据
+    handleJsonResponse(response, options) {
+        let Dcat = this.dcat,
+            data = response.data;
+
+        if (! response) {
+            return;
+        }
+
+        if (typeof response !== 'object') {
+            return Dcat.error('error', 'Oops!');
+        }
+
+        var then = function (then) {
+            switch (then.action) {
+                case 'refresh':
+                    Dcat.reload();
+                    break;
+                case 'download':
+                    window.open(then.value, '_blank');
+                    break;
+                case 'redirect':
+                    Dcat.reload(then.value || null);
+                    break;
+                case 'location':
+                    setTimeout(function () {
+                        if (then.value) {
+                            window.location = then.value;
+                        } else {
+                            window.location.reload();
+                        }
+                    }, 1000);
+                    break;
+                case 'script':
+                    (function () {
+                        eval(then.value);
+                    })();
+                    break;
+            }
+        };
+
+        if (typeof response.html === 'string' && response.html && options.target) {
+            if (typeof options.html === 'function') {
+                // 处理api返回的HTML代码
+                options.html(options.target, response.html, response);
+            } else {
+                $(target).html(response.html);
+            }
+        }
+
+        let message = data.message || response.message;
+
+        // 判断默认弹窗类型.
+        if (! data.type) {
+            data.type = response.status ? 'success' : 'error';
+        }
+
+        if (typeof message === 'string' && data.type && message) {
+            if (data.alert) {
+                Dcat.swal[data.type](message, data.detail);
+            } else {
+                Dcat[data.type](message, null, data.timeout ? {timeOut: data.timeout*1000} : {});
+            }
+        }
+
+        if (data.then) {
+            then(data.then);
+        }
+    }
+}

Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


Plik diff jest za duży
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików