123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- /*全局自适应高度*/
- function autoFlashHeight(){
- var cHeader = $(".c-header").height();
- $(".sjs-height-1").height($(window).height()-cHeader-160);
- $(".sjs-height-2").height($(window).height()-cHeader-191);
- };
- $(window).resize(autoFlashHeight);
- /*全局自适应高度结束*/
- $(function(){
- /*侧滑*/
- $(".open-sidebar").click(function(){
- $(".slide-sidebar").animate({width:"800"}).addClass("open");
- });
- $("body").click(function(event){
- var e = event || window.event; //浏览器兼容性
- if(!$(event.target).is('a')) {
- var elem = event.target || e.srcElement;
- while (elem) { //循环判断至跟节点,防止点击的是div子元素
- if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
- return false;
- }
- elem = elem.parentNode;
- }
- $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
- }
- });
- /*侧滑*/
- /*工具提示*/
- $(function () {
- $('[data-toggle="tooltip"]').tooltip()
- });
- /*侧栏菜单*/
- $(".bg-nav > li > a").click(function() {
- var self = $(this);
- var subMenu = $(this).siblings('ul.sub-menu');
- if(subMenu.length > 0) {
- if(subMenu.is(":visible")) {
- self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
- subMenu.slideUp('fast');
- self.parent().removeClass('active');
- }else{
- self.parent().addClass('active');
- self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
- subMenu.slideDown('fast');
- }
- }
- });
- // 数据提交
- $("#submit-form").click(function() {
- $("#save-form").submit();
- });
- });
- /**
- * 提示框
- *
- * @param string message
- * @param string type
- * @param string icon
- * @return void
- */
- function toast(message, type, icon)
- {
- var toast = $(".toast");
- toast.addClass(type);
- toast.children('.message').html(message);
- var iconClass = 'fa-' + icon;
- toast.children('.icon').addClass(iconClass);
- toast.fadeIn(500);
- setTimeout(function() {
- toast.fadeOut('fast');
- toast.children('.message').text('');
- toast.children('.icon').removeClass(iconClass);
- }, 3000);
- }
- /**
- * 动态请求数据
- * @param {String} url - 请求链接
- * @param data - 提交数据
- * @param {function} successCallback - 返回成功回调
- * @param {function} errorCallBack - 返回失败回调
- */
- const postData = function (url, data, successCallback, errorCallBack) {
- $.ajax({
- type:"POST",
- url: url,
- data: {'data': JSON.stringify(data)},
- dataType: 'json',
- cache: false,
- timeout: 5000,
- beforeSend: function(xhr) {
- let csrfToken = Cookies.get('csrfToken');
- xhr.setRequestHeader('x-csrf-token', csrfToken);
- },
- success: function(result){
- if (result.err === 0) {
- if (successCallback) {
- successCallback(result.data);
- }
- } else {
- toast('error: ' + result.message, 'error', 'exclamation-circle');
- if (errorCallBack) {
- errorCallBack();
- }
- }
- },
- error: function(jqXHR, textStatus, errorThrown){
- toast('error ' + textStatus + " " + errorThrown, 'error', 'exclamation-circle');
- if (errorCallBack) {
- errorCallBack();
- }
- }
- });
- };
|