Files
DzzOffice/static/js/main.min.js

216 lines
6.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

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.

$(document).ready( function() {
$("button:submit,input:submit, .nav-link, .btn,a").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);
});
// 停止
$("body").on('click','[data-stopPropagation]',function (e) {
e.stopPropagation();
});
// 遮罩层
$(document).on('click', '.lyear-mask-modal', function() {
$( this ).remove();
$('.lyear-layout-sidebar').toggleClass('lyear-aside-open');
$('body').toggleClass('lyear-layout-sidebar-close');
});
// 工具提示
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"));
}
});
/*
* 提取通用的通知消息方法
* 这里只采用简单的用法如果想要使用回调或者更多的用法请查看lyear_js_notify.html页面
* @param $msg 提示信息
* @param $type 提示类型:'info', 'success', 'warning', 'danger'
* @param $delay 毫秒数例如1000
* @param $icon 图标,例如:'fa fa-user' 或 'mdi mdi-alert'
* @param $from 'top' 或 'bottom' 消息出现的位置
* @param $align 'left', 'right', 'center' 消息出现的位置
* @param $url 跳转链接,$delay毫秒后跳转 例如: https://www.xxxx.com
*/
showNotify = function ($msg, $type, $delay, $icon, $from, $align, $url) {
$type = $type || 'info';
$delay = $delay || 1000;
$from = $from || 'top';
$align = $align || 'right';
$enter = $type == 'danger' ? 'animate__animated animate__shakeX' : 'animate__animated animate__fadeInUp';
$url = $url || '';
jQuery.notify({
icon: $icon,
message: $msg
},
{
element: 'body',
type: $type,
allow_dismiss: true,
newest_on_top: true,
showProgressbar: false,
placement: {
from: $from,
align: $align
},
offset: 20,
spacing: 10,
z_index: 10800,
delay: $delay,
animate: {
enter: $enter,
exit: 'animate__animated animate__fadeOutDown'
}
});
if ($url != '') {
setTimeout(function() {
window.location.href = $url;
}, $delay);
}
}
});
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();});
}