dzzoffice/static/lyear/js/main.min.js
2025-03-27 09:05:55 +08:00

462 lines
13 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

jQuery(document).ready( function() {
// 关闭页面loading
setTimeout(function () {
$('#lyear-preloader').fadeOut(500, function () {
$('#lyear-preloader').removeClass('loading');
});
}, 500);
jQuery('.js-popbox').each(function(){
jQuery(this).popbox();
});
$(document).on('click', '.modal-fullscreen-btn', function(){
$(this).closest('.modal-dialog').toggleClass('modal-fullscreen');
});
$("button:submit,input:submit,.nav-stacked a,.nav-pills .nav-link,.lyearloading,.btn").click(function(){
$(this).attr('disable', 'true');
var l = $(this).lyearloading({
opacity: 0.2,
spinnerSize: 'nm',
});
l.addClass('disabled');
setTimeout(function() {
$(this).prop('disable', 'false');
l.destroy(); // 可以使用hide页面中如果有多个loading最好用destroy避免后面的loading设置不生效
l.removeClass('disabled');
}, 1e3);
});
$(".bodyloading").click(function(){
$(this).attr('disable', 'true');
var l = $('body').lyearloading({
opacity: 0.2,
spinnerSize: 'lg',
spinnerText: '后台处理中,请稍后...',
textColorClass: 'text-info',
spinnerColorClass: 'text-info'
});
l.addClass('disabled');
setTimeout(function() {
$(this).prop('disable', 'false');
l.destroy(); // 可以使用hide页面中如果有多个loading最好用destroy避免后面的loading设置不生效
l.removeClass('disabled');
}, 1e3);
});
// 停止
$("body").on('click','[data-stopPropagation]',function (e) {
e.stopPropagation();
});
// 侧边栏
$(document).on('click', '.lyear-aside-toggler', function() {
$('.bs-left-container').toggleClass('lyear-aside-open');
$("body").toggleClass('bs-left-container-close');
if ($('.lyear-mask-modal').length == 0) {
$('<div class="lyear-mask-modal"></div>').prependTo('body');
} else {
$( '.lyear-mask-modal' ).remove();
}
});
// 遮罩层
$(document).on('click', '.lyear-mask-modal', function() {
$( this ).remove();
$('.bs-left-container').toggleClass('lyear-aside-open');
$('body').toggleClass('bs-left-container-close');
});
// 侧边栏导航
$(document).on('click', '.nav-item-has-subnav > a', function() {
$subnavToggle = jQuery( this );
$navHasSubnav = $subnavToggle.parent();
$topHasSubNav = $subnavToggle.parents('.nav-item-has-subnav').last();
$subnav = $navHasSubnav.find('.nav-subnav').first();
$viSubHeight = $navHasSubnav.siblings().find('.nav-subnav:visible').outerHeight();
$navHasSubnav.siblings().find('.nav-subnav:visible').slideUp(500).parent().removeClass('open');
$subnav.stop().slideToggle( 300, function() {
$navHasSubnav.toggleClass( 'open' );
});
});
// 工具提示
if ($('[data-bs-toggle="tooltip"]')[0]) {
$('[data-bs-toggle="tooltip"]').tooltip({
"container" : 'body',
});
}
// pop提示
if ($('[data-bs-toggle="popover"]')[0]) {
$('[data-bs-toggle="popover"]').popover({
container: 'body'
});
}
// Card最大化
$(document).on('click', '.card-btn-fullscreen', function(){
$(this).closest('.card').toggleClass('card-fullscreen');
});
// Card收缩/展开
$(document).on('click', '.card-btn-slide', function(){
$(this).toggleClass('rotate-180').closest('.card').find('.card-body').slideToggle();
});
// Card刷新
$(document).on('click', '.card-btn-reload', function(e) {
e.preventDefault();
var url = $(this).attr('href');
var $card = $(this).closest('.card');
if (url == "#" | url == "#!") {
return;
}
var l = $card.lyearloading({
opacity: 0.1,
spinnerSize: 'nm'
});
$card.find('.card-body').load(url, function(){
l.destroy();
});
});
// Card关闭
$(document).on('click', '.card-btn-close', function() {
$(this).closest('.card').fadeOut(600, function() {
if ($(this).parent().children().length == 1) {
$(this).parent().remove();
} else {
$(this).remove();
}
});
});
/**
* 滚动条
*/
if($('.lyear-scroll')[0]) {
$('.lyear-scroll').each(function(){
new PerfectScrollbar(this, {
swipeEasing: false,
suppressScrollX: true
});
});
}
// 颜色选取
jQuery('.js-colorpicker').each(function() {
var $colorpicker = jQuery(this);
$colorpicker.colorpicker({
'format': $colorpicker.data('colorpicker-mode') ? $colorpicker.data('colorpicker-mode') : 'auto',
'horizontal' : $colorpicker.data('colorpicker-horizontal') ? $colorpicker.data('colorpicker-horizontal') : false
});
});
// 日期选择器
jQuery("[data-provide = 'datepicker']").each(function() {
var options = {
language: 'zh-CN', // 默认简体中文
multidateSeparator: ', ' // 默认多个日期用,分隔
}
options = $.extend( options, getDataOptions( $(this) ));
if ( $(this).prop("tagName") != 'INPUT' ) {
options.inputs = [$(this).find('input:first'), $(this).find('input:last')];
}
$(this).datepicker(options);
});
// 时间日期选择器
jQuery("[data-provide = 'datetimepicker']").each(function() {
var options = {
locale: moment.locale(),
}
options = $.extend( options, getDataOptions( $(this) ));
if ( $(this).prop("tagName") != 'INPUT' ) {
options.inputs = [$(this).find('input:first'), $(this).find('input:last')];
}
console.log(options);
$(this).datetimepicker(options);
});
// 标签
$('.js-tags-input').each(function() {
var $this = $(this);
$this.tagsInput({
height: $this.data('height') ? $this.data('height') : '100%',
width: '100%',
defaultText: $this.attr("placeholder"),
removeWithBackspace: true,
delimiter: [',']
});
});
// 复选框全选
$(document).on('change', '#check-all', function () {
if ($boxname = $(this).data('name')) {
$(this).closest('table').find("input[name='" + $boxname + "']").prop('checked', $(this).prop("checked"));
} else {
$(this).closest('table').find(".form-check input[type='checkbox']").prop('checked', $(this).prop("checked"));
}
});
// 设置主题配色
$(".theme-toggle-btn").click(function(){
var currentTheme = $('body').attr('data-theme') || 'default';
var newTheme;
var newIconClass;
var oldIconClass;
if (currentTheme === 'dark') {
newTheme = 'default'; // 切换到明亮主题
newIconClass = 'mdi-white-balance-sunny';
oldIconClass = 'mdi-power-sleep';
} else {
newTheme = 'dark'; // 切换到黑暗主题
newIconClass = 'mdi-power-sleep';
oldIconClass = 'mdi-white-balance-sunny';
}
$(this).removeClass(oldIconClass).addClass(newIconClass);
$('body').attr('data-theme', newTheme);
setcookie('the_site_theme', newTheme);
});
// $("input[name='site_theme']").click(function(){
// var check_theme = $(this).val();
// $('body').attr('data-theme', check_theme);
// setcookie('the_site_theme', check_theme);
// });
});
// 参考国外模板的写法获取当前的配置以data-**指插件原有的配置名)
getDataOptions = function(el, castList) {
var options = {};
$.each( $(el).data(), function(key, value){
key = dataToOption(key);
if ( key == 'provide' ) {
return;
}
options[key] = value;
});
return options;
}
dataToOption = function(name) {
return name.replace(/-([a-z])/g, function(x){return x[1].toUpperCase();});
}
function popbox() {
$(".popover")
.css({
display: "none"
})
}
(function($) {
$.fn.popbox = function(options) {
var box = $('.popover');
if(!box.length) {
box = $(' <div class="popover fade clearfix">' +
' <div class="popover-arrow">' +
' </div>' +
' <div class="popover-container">' +
' <div class="mdi mdi-36px mdi-spin mdi-loading"></div>' +
' </div>' +
'</div>'
).appendTo('body');
}
var me = $(this);
var dataurl = [];
var current = 0;
var open = function(event) {
if(event) event.preventDefault();
if(me.data('href')) {
getdata(me.data('data-bs-href'));
}
$('.js-popbox').removeClass('openpop');
show();
if(me.data('closest')) {
me.closest(me.data('closest')).find('.dropdown-toggle').dropdown('toggle');
}
return false;
}
var show = function() {
var clientWidth = document.documentElement.clientWidth;
var clientHeight = document.documentElement.clientHeight;
if(me.data('closest')) var target = me.closest(me.data('closest'));
else var target = me;
me.addClass('openpop');
var p = target.offset();
var bw = box.outerWidth(true);
var bh = box.outerHeight(true);
var w = target.outerWidth(true);
var h = target.outerHeight(true);
var left = 0,
top = 0;
box.attr('class', 'popover fade show bs-popover-' + me.data('bs-placement'));
switch(me.data('bs-placement')) {
case 'cover':
left = p.left;
top = p.top;
break;
case 'right':
left = p.left + w + 10;
top = p.top + h / 2 - bh / 2;
break;
case 'top':
top = p.top - bh - 10;
left = p.left + w / 2 - bw / 2;
break;
case 'bottom':
top = p.top + h + 10;
left = p.left + w / 2 - bw / 2;
break;
case 'left':
left = p.left - bw - 10;
top = p.top + h / 2 - bh / 2;
break;
default:
left = p.left + w + 10;
top = p.top + h / 2 - bh / 2;
break;
}
//判断是否超出屏幕
if(me.data('auto-adapt')) {
switch(me.data('bs-placement')) {
case 'right':
case 'left':
if(left + bw > clientWidth) left = clientWidth - bw - 10;
if(left < 0) left = 10;
if(top + bh > (clientHeight + jQuery(window).scrollTop())) top = clientHeight + jQuery(window).scrollTop() - bh - 10;
if(top < 0) top = 10;
break;
case 'top':
case 'bottom':
if(top + bh > (clientHeight + jQuery(window).scrollTop()) && (me.data('bs-placement') != 'bottom' && me.data('bs-placement') != 'cover')) top = clientHeight - bh - 10 + jQuery(window).scrollTop();
if(top < 0) top = 10;
if(left + bw > clientWidth) left = clientWidth - bw - 10;
if(left < 0) left = 10;
break;
case 'cover':
if(left + bw > clientWidth) left = clientWidth - bw - 10;
if(left < 0) left = 10;
break;
}
}
box.css({
'display': 'block',
'left': left,
'top': top /*,'min-width':w*/
});
switch(me.data('bs-placement')) {
case 'right':
case 'left':
var top = p.top - top + h / 2 - 10;
if(top + 25 > bh) top = bh - 25;
else if(top < 5) top = 5;
box.find('.popover-arrow').attr('style', 'top:' + (top) + 'px');
break;
case 'top':
case 'bottom':
var left = p.left - left + w / 2 - 10;
if(left + 25 > bw) left = bw - 25;
else if(left < 5) left = 5;
box.find('.popover-arrow').attr('style', 'left:' + left + 'px');
break;
}
$(document).off('click.popover').on('click.popover',function(event){
if( !$(event.target).closest('.popover,.ui-icon,.dzzdate,.ui-corner-all', '#jquery-color-picker').length) {
close();
$('.openpop').removeClass('openpop');
}
});
}
var getdata = function(url) {
if(!url) url = me.data('href');
if(url == '#'){
var html = me.siblings('.popover-html').html();
data_operate(html);
}else{
var s=(url.indexOf('?') != -1) ? '&' :'?';
url+=s+'t='+new Date().getTime();
current = dataurl.push(url);
$.get(url, function(html) {
data_operate(html);
});
}
}
var data_operate = function(html){
box.find('.popover-container').html(html);
box.find('.js-popbox').on('click', function() {
getdata($(this).data('href'));
return false;
});
box.find('.js-popbox-prev').on('click', function() {
goto_prev()
return false;
});
box.find('.close,.cancel').on('click', function(event) {
event.preventDefault();
close();
});
box.find('.btn-close,.cancel').on('click', function(event) {
event.preventDefault();
close();
});
show();
}
var goto_prev = function() {
if(current > 1) {
current -= 1;
} else {
current = 0;
}
url = dataurl[current - 1];
dataurl.splice(current - 1, dataurl.length - current + 1);
getdata(url);
}
var close = function() {
current = 0;
dataurl = [];
box.data('prevel', null);
box.fadeOut("fast", function() {
box.find('.popover-container').html('<div class="mdi mdi-36px mdi-spin mdi-loading"></div>');
});
me.removeClass('openpop');
$(document).off('click.popover');
}
if(options == 'update') {
window.setTimeout(function() {
show();
});
} else if(options == 'open') {
window.setTimeout(function() {
open();
});
} else if(options == 'close') {
close();
} else if(options == 'getdata') {
getdata();
} else {
$(this).off('click.popover').on('click.popover', open);
}
}
})(jQuery);