class Base {
constructor() { }
load() {
this.footer();
this.header();
if ($('.counter').length) {
$('.counter').countUp();
}
}
header() {
layui.use(['form', 'layer'], function () {
$('#headSearchBtn').click(function () {
var form = layui.form;
var layer = layui.layer;
layer.open({
maxWidth: 1000,
type: 1,
zIndex: 9999,
title: false,
content: $('#headSearch')
})
})
})
headToggle();
mobileMenuToggle()
scroll()
$(window).scroll(function () {
scroll()
})
$(".head-drop").hover(function () {
let h = $(this).find(".inner").outerHeight();
if ($(this).find(".head-dropinfo").hasClass("_product")) {
h = $(window).height() - 140;
}
$(this).find(".head-dropinfo").height(h)
$("#dropCover").addClass("on")
}, function () {
$("#dropCover").removeClass("on")
$(this).find(".head-dropinfo").height(0)
})
function scroll() {
var st = $(window).scrollTop();
if (st >= 70) {
$('header').addClass('fixed');
} else {
$('header').removeClass('fixed');
if (!$("header").hasClass("substation")) {
}
}
}
function headToggle() {
$('#menuBtn').click(function () {
var flag = $(this).hasClass('on');
if (!flag) {
$(this).addClass("on");
$('#nav').addClass("active");
$('header').addClass("active");
} else {
$(this).removeClass("on");
$('#nav').removeClass("active");
$('header').removeClass("active");
}
})
}
function mobileMenuToggle() {
$('#menus .xsdrop .tit').click(function () {
let parent = $(this).parent();
if (parent.hasClass('open')) {
parent.removeClass('open')
$(this).siblings('.xs-menu').slideUp()
} else {
parent.siblings().removeClass("open")
parent.siblings().find('.xs-menu').slideUp();
parent.addClass('open')
$(this).siblings('.xs-menu').eq(0).slideDown()
}
})
// $('#menus .xsdrop .arr').click(function () {
// let parent = $(this).parent().parent();
// if(!$(this).siblings("tit").attr("href")){
// return false;
// }
// if (parent.hasClass('open')) {
// parent.removeClass('open')
// $(this).parent().siblings('.xs-menu').slideUp()
// } else {
// parent.siblings().removeClass("open")
// parent.siblings().find('.xs-menu').slideUp();
// parent.addClass('open')
// $(this).parent().siblings('.xs-menu').slideDown()
// }
// })
}
}
footer() {
fn();
$(window).resize(fn)
function fn() {
$('#ftNavs').off('click', '.navitem h4');
var flag = $('#ftNavs .icon-jia').eq(0).css('display') == 'block';
if (flag) {
$('#ftNavs .navitem .info').hide()
$('#ftNavs').on('click', '.navitem h4', toggle);
} else {
$('#ftNavs .navitem .info').show()
}
}
function toggle() {
var item = $(this).parent('.navitem');
item.toggleClass('active')
$(this).siblings('.info').slideToggle(100);
item.siblings('.navitem').removeClass('active').each(function () {
$(this).find('.icon-jia').removeClass('active')
$(this).find('.info').slideUp(100)
})
}
}
tab() {
$('.tabNav >*').click(function () {
var index = $(this).index();
var content = $(this).addClass('on').siblings().removeClass('on').parents('.tabJs').find('.tabInfo');
var contentItem = content.find('.cItem');
contentItem.eq(index).addClass('on').siblings().removeClass('on');
return false;
})
$('.tabNavHv >*').mouseover(function () {
if ($(this).hasClass("on")) {
return false
}
let index = $(this).index();
$(this).addClass('on').siblings().removeClass('on');
var tabInfo = $(this).parents('.tabWrap').find('.tabInfo');
var tabItems = tabInfo.find('.cItem');
tabInfo.find('.on').removeClass('on');
tabItems.eq(index).addClass('on').css("opacity", 0);
setTimeout(function () {
tabItems.eq(index).css("opacity", 1);
}, 100)
})
}
wow() {
var wow = new WOW({
boxClass: 'wow',
animateClass: 'animated',
offset: 0,
mobile: false,
live: true
});
new WOW().init();
}
totop() {
$('.totop').on('click', function () {
$('html,body').animate({
scrollTop: 0
}, 300)
})
// $(window).scroll(function () {
// var st = $(window).scrollTop();
// if (st >= $(window).height() / 2) {
// $('#top').addClass('show');
// } else {
// $('#top').removeClass('show');
// }
// })
}
mobileUrl() {
$('.mobileUrl').click(function () {
let url = $(this).attr('data-url');
if ($(window).width() <= 768) {
location.href = url;
}
})
}
/**
* 跨页面跳转
*/
navLink(obj) {
obj.on('click', function () {
var id = $(this).attr('data-id');
var link = $(this).attr('href');
if (id) {
localStorage.setItem('__todom__', id);
}
location.href = link;
return false;
})
window.onload = function () {
var getobj = localStorage.getItem('__todom__');
setTimeout(function () {
if (getobj) {
var obj = $('#' + getobj);
var headheight = $('header').height();
headheight = Math.max(60, headheight);
var top = obj.offset().top - headheight;
$('html,body').scrollTop(top);
localStorage.removeItem('__todom__');
}
});
}
}
// 二级固定分类
secondFixedNav() {
if ($(".fixed_nav_box").length) {
let objT = $(".fixed_nav_box").offset().top;
let domItem = $(".fixed_nav_box .pageToDom");
let arr = [];
let current = 0;
let headerHeight = $('header').height();
let wh = $(window).height();
domItem.each(function () {
let id = $(this).attr("href");
if (id.substring(0, 1) == '#') {
arr.push(parseInt($(id).offset().top));
}
})
$(window).scroll(fn)
fn()
function fn() {
let st = $(window).scrollTop();
if (st > objT - headerHeight) {
$(".fixed_nav_box").addClass("fixed")
} else {
$(".fixed_nav_box").removeClass("fixed")
}
if (arr) {
arr.map((item, index) => {
if (st + wh / 2 > item && index != current) {
current = index;
domItem.eq(index).addClass("on").siblings().removeClass("on")
}
})
}
}
}
}
/**
* 在本页面页跳转
* */
pageToDom(obj) {
obj.click(function () {
var href = $(this).attr('href');
var dom = $(href);
var headheight = $('header').height() >= 60 ? $('header').height() : 70;
var top = dom.offset().top - headheight;
$('html,body').animate({
scrollTop: top
}, 300);
return false;
})
}
// 产品栏目
productMenu() {
$("#productMenuBtn").click(function () {
$(".menu_top").toggleClass("open");
$(".menu_list").slideToggle()
})
$(".productMenu .arr").click(function () {
let parent = $(this).parent().parent();
parent.siblings().removeClass("open");
parent.siblings().find("dd").slideUp()
parent.find("dd").slideToggle();
parent.toggleClass('open');
})
}
layerScale() {
if ($("#layer-photos").length) {
layui.use(['layer'], function () {
var layer = layui.layer;
layer.photos({
photos: '#layer-photos'
, anim: 5
})
});
}
$(".scaleImg").click(function () {
let src = $(this).attr("src");
layer.photos({
photos: {
"data": [
{
src
}
]
}
, anim: 5
});
})
}
index_banner() {
var bannerSwiper = new Swiper('.index_banner', {
loop: true,
autoplay: true,
effect: "fade",
centeredSlides: true,
navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', },
pagination: {
el: '.swiper-pagination',
clickable: true,
renderBullet: function (index, className) {
return '' + (index + 1) + '';
},
},
on:{
slideChange: function(){
if($('.index_banner').find('video').length){
$('.index_banner').find('video').remove();
$(".index_banner .ic-play").show();
bannerSwiper.autoplay.start();
}
},
},
})
$(".index_banner .ic-play").click(function () {
bannerSwiper.autoplay.stop();
let url = $(this).attr("video");
if($(this).hasClass("lg")){
layer.open({
type: 2,
title: false,
// closeBtn: 0,
skin:"layer-banner-video",
maxWidth:"1200px",
maxHeight:"800px",
shade: 0.8,
shadeClose: true,
// content: $("#bannerVideo"),
// success:function(){
// $(".bannerVideo").attr("autoplay",true)
// },
content: url,
cancel:function(){
// canplay = true;
bannerSwiper.slideNext();
}
})
}else{
let str = ``;
$(this).parent().append(str);
$(this).hide()
}
})
}
}
$(function () {
let doc = new Base();
doc.load();
doc.tab();
doc.totop();
doc.wow()
doc.index_banner()
doc.productMenu()
doc.mobileUrl()
doc.layerScale()
doc.navLink($(".navLink"))
doc.pageToDom($(".pageToDom"))
doc.secondFixedNav()
$(".toTop").click(function () {
$('html,body').animate({
scrollTop: 0
}, 300)
return false;
})
})
function submit(name = '*') {
layui.use(['layer', 'form', 'upload', 'element'], function () {
var form = layui.form;
var layer = layui.layer;
var upload = layui.upload;
var element = layui.element;
let loadindex = null;
var uploadInst = upload.render({
elem: ".uploadbtn"
// , url: '/addons/qiniu/index/upload'
, url: '/api/common/upload'
, accept: 'file'
, size: 20 * 1024
, exts: 'jpg|png|bmp|jpeg|gif|zip|rar|xls|xlsx|pdf|docx|mp4|doc|ppt|pptx'
, progress: function (n, elem, res, index) {
loadindex = layer.load(2);
n = n < 100 ? n : 99;
var percent = n + '%' //获取进度百分比
element.progress('step', percent); //可配合 layui 进度条元素使用
$("#progressStep").text(percent)
$(".filebox").addClass("uploading");
}
, done: function (res) {
console.log(res);
let percent = "100%";
if (res.code != 1) {
percent = "0%";
}
element.progress('step', percent);
$("#progressStep").text(percent)
$(".filebox").removeClass("uploading");
if (res.code != 1) {
layer.msg(res.msg);
return false;
}
let url = res.data.fullurl;
let src = url;
if (url.split(".png").length == 1 && url.split(".jpg").length == 1) {
src = "/assets/addons/cms/obj/images/file.png";
}
$(".file-input").val(url);
$(".filebox .imgbox img").attr("src", src);
$(".filebox .imgbox a").attr("href", url);
$(".filebox").addClass("uploadok").removeClass("uploading");
layer.close(loadindex)
}
, error: function (res) {
layer.msg("error");
layer.msg(res);
}
});
$(".fileClose").click(function () {
$(".file-input").val("");
$(".filebox").removeClass("uploadok");
})
form.on("submit(" + name + ")", function (data) {
let params = data.field;
if (params.file) {
params["row[file]"] = params.file;
delete params.file;
}
loadindex = layer.load(2);
$.post("/addons/cms/diyform/post", params, function (res) {
layer.close(loadindex);
if (res.code == 1) {
layer.closeAll()
location.href = '/thanks'
// layer.alert(res.msg, { title: false, closeBtn: false, skin: "popup-layer" }, function () {
// });
} else {
layer.msg(res.msg)
$("input[name=__token__").val(res.data.__token__)
}
})
})
})
}
function httpUrl(url, method, params, async, joinUrl) {
var result = { 'code': '0', 'msg': '请求错误' };
$.ajax({
type: method,
async: Boolean(async),
headers: {
"token": localStorage.getItem("token"),
"jigou": localStorage.getItem("jigou")
},
data: params,
url: url,
dataType: "json",
success: function (res) {
if (res.code == 401) {
location.href = '/login.html';
} else {
result = res;
}
console.log(url);
console.log(res);
},
error: function () {
console.log(params)
},
});
return result;
}
$(function () {
if ($('.videosbox')) {
$(".videosbox").each(function () {
let obj = $(this);
let videoJq = $(this).find("video");
let video = videoJq[0];
$(this).find(".icplay").click(function () {
if (!videoJq.attr("src")) {
video.src = videoJq.attr("url");
}
video.play()
obj.addClass("play").removeClass("pause");
})
// video.addEventListener('pause', function () {
// obj.removeClass("play").addClass("pause");
// });
})
}
if ($('.swiper_partner')) {
$('.swiper_partner').each(function () {
let speed = Number($(this).attr("speed"));
var mySwiper = new Swiper($(this), {
loop: true,
slidesPerView: 'auto',
speed,
freeMode: true,
autoplayDisableOnInteraction: false,
noSwiping: true,
noSwipingClass: 'swiper-slide',
autoplay: {
delay: 0,
stopOnLastSlide: false,
disableOnInteraction: false,
},
})
})
}
var mySwiper = new Swiper('.swiper_product_sub', {
loop: true,
autoplay: true,
pagination: { el: '.swiper-pagination', clickable: true, },
centeredSlides: true,
navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', },
})
$(function () {
var mySwiper = new Swiper('.news-rec', {
loop: true,
autoplay: true,
pagination: { el: '.swiper-pagination', clickable: true, },
})
})
var swiper = new Swiper('.swiper_news', {
slidesPerView: 1,
spaceBetween: 14,
observer: true, //开启动态检查器,监测swiper和slide
observeParents: true, //监测Swiper 的祖/父元素
breakpointsInverse: true,
pagination: { el: '.swiper-pagination', clickable: true, },
breakpoints: {
//当宽度大于等于640
640: {
slidesPerView: 2,
spaceBetween: 14
},
992: {
slidesPerView: 3,
spaceBetween: 20
},
1360: {
slidesPerView: 4,
spaceBetween: 27
}
}
})
var swiper = new Swiper('.swiper_application', {
slidesPerView: 1,
spaceBetween: 10,
loop:true,
observer: true, //开启动态检查器,监测swiper和slide
observeParents: true, //监测Swiper 的祖/父元素
breakpointsInverse: true,
pagination: { el: '.swiper-pagination', clickable: true, },
navigation: {
nextEl: '.solubox-product .swiper-button-next',
prevEl: '.solubox-product .swiper-button-prev',
},
breakpoints: {
//当宽度大于等于640
640: {
slidesPerView: 2,
},
992: {
slidesPerView: 3,
spaceBetween: 20
},
1360: {
slidesPerView: 3,
spaceBetween: 38
},
}
})
})
$(function () {
if ($('.swiper-center').length) {
var currentSwiper = new Swiper('.swiper-center', {
loop: true,
spaceBetween: 0,
});
currentSwiper.$el.parent().find('.swiper-button-next').on('click', function () {
currentSwiper.slideNext();
})
currentSwiper.$el.parent().find('.swiper-button-prev').on('click', function () {
currentSwiper.slidePrev();
})
var leftSwiper = new Swiper('.swiper-left', {
loop: true,
spaceBetween: 0,
simulateTouch: false,
});
var rightSwiper = new Swiper('.swiper-right', {
loop: true,
spaceBetween: 0,
simulateTouch: false,
});
currentSwiper.controller.control = [leftSwiper, rightSwiper];
}
})
//获取网页参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
//解决办法:将解码方式unscape换为decodeURI
//原因:浏览器会将url中的中文参数进行encodeURI编码,所以要通过js使用decodeURI进行解码
if (r != null) return decodeURI(r[2]); return null; //返回参数值
}
function getUrlParamByStr(str, name) {
var index = str.indexOf("?");
str = str.slice(index);
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = str.substr(1).match(reg); //匹配目标参数
//解决办法:将解码方式unscape换为decodeURI
//原因:浏览器会将url中的中文参数进行encodeURI编码,所以要通过js使用decodeURI进行解码
if (r != null) return decodeURI(r[2]); return null; //返回参数值
}