// 处于页面配置时,绑定方法 start
if ($isDecorateMode) {
document.addEventListener("diy_header/1", (event) => {
const { field, value } = event.detail;
console.log(field, value)
if (field === 'hots') {
let html = ''
value.forEach(e => {
html += `${e.name}`
})
$('.' + field).html(html)
}
});
}
// 处于页面配置时,绑定方法 end
$(function () {
$("#logout").click(function () {
$request
.post("/api/user/logout")
.then((res) => {
// 跳转页面
location.href = "/";
});
})
// 防止一开始进入页面在底部不显示
setHeaderSticky()
$(window).scroll(setHeaderSticky)
function setHeaderSticky(){
let offset = $("html,body").scrollTop()
if (offset) {
$('.ys-header').addClass('is-sticky')
} else {
$('.ys-header').removeClass('is-sticky')
}
}
// 导航栏悬停
$('.ys-header__nav .nav-item').hover(function () {
$(this).find('.ys-header__card').addClass('show')
if(!$(this).hasClass('ignore'))
$('.ys-header__cover').removeClass('display-none')
}, function () {
$(this).find('.ys-header__card').removeClass('show')
$('.ys-header__cover').addClass('display-none')
})
// 产品中心悬停
$('.ys-header__nav .product-item').hover(function () {
$('.ys-header__nav .product-child').addClass('display-none')
$('.ys-header__nav .product-item').removeClass('active')
$(this).addClass('active')
$(this).next().removeClass('display-none')
})
// 搜索框悬停事件
$('.ys-header__search').focus(function () {
$('.ys-header__nav').addClass('display-none')
$('.ys-header__right').addClass('open')
}, function() {
if (!$('.ys-header__search-card').hasClass('show')) {
$('.ys-header__nav').removeClass('display-none')
$('.ys-header__right').removeClass('open')
}
})
// 搜索框聚焦事件
$('.ys-header__search input').focus(function () {
openSearchCard()
})
$('.ys-header__search-card .icon-close').click(function () {
closeSearchCard()
})
$(document).on('click', function (e) {
if (!$('.ys-header__search-card')[0].contains(e.target) && !$('.ys-header__search input').is(':focus')) {
closeSearchCard()
}
})
// 搜索
$('.ys-header__search input').keyup(function (e) {
if (e.keyCode === 13) {
search()
}
})
$('.ys-header__search .search-btn').click(function () {
search()
})
// 清空历史记录
$('.ys-header__search-card .search-history span').click(function () {
localStorage.removeItem('searchHistory')
setHistory()
})
// 展开搜索卡片
function openSearchCard() {
$('.ys-header__nav').addClass('display-none')
$('.ys-header__search-card').addClass('show')
$('.ys-header__cover').removeClass('display-none')
$('.ys-header__right').addClass('open')
}
// 收起搜索卡片
function closeSearchCard() {
$('.ys-header__nav').removeClass('display-none')
$('.ys-header__search-card').removeClass('show')
$('.ys-header__cover').addClass('display-none')
$('.ys-header__right').removeClass('open')
}
// 搜索事件
function search() {
let val = $('.ys-header__search input').val()
if (!val) return $message.warning('请输入搜索关键词')
let history = JSON.parse(localStorage.getItem('searchHistory')) || []
history.unshift(val)
history = [...new Set(history)]
localStorage.setItem('searchHistory', JSON.stringify(history.slice(0, 10)))
window.open('/search_result.html?keyword=' + val)
closeSearchCard()
setHistory()
}
// 设置搜索历史
function setHistory() {
let history = JSON.parse(localStorage.getItem('searchHistory')) || []
let html = ''
history.forEach(e => {
html += `${e}`
})
$('.ys-header__search-card .search-history .search-words').html(html)
}
setHistory()
})
// 客服
$('.ys-header-shortcut__server span').click(function(){
window.dispatchEvent(
new CustomEvent('openService')
)
})
/******** 数字滚动 begin *********/
function animateNumber(element, targetNumber, duration) {
var counterElement = typeof element === "string" ? $(element) : element;
var currentValue = parseFloat(counterElement.text());
if (currentValue >= targetNumber) return;
var step = (targetNumber - currentValue) / (duration / 50);
var interval = setInterval(function () {
currentValue += step;
counterElement.text(Math.round(currentValue));
if (currentValue >= targetNumber) {
clearInterval(interval);
counterElement.text(targetNumber);
}
}, 50);
}
function initCounter() {
const counterDoms = $(".about-counter__num");
counterDoms.each(function () {
const num = $(this).data("number");
animateNumber($(this), num, 800);
});
}
function scrollToCounter(){
if ($(window).scrollTop() >= $('#about-intro').offset().top - 150) {
initCounter()
// 初始化之后清除绑定事件
$(window).off('scroll', scrollToCounter)
}
}
$(window).scroll(scrollToCounter)
/******** 数字滚动 end *********/
/******** 里程碑 begin *********/
const milestoneList = $(".milestone-tab__list");
const maxMilestoneLength = milestoneList.children(".tab-item").length;
const milestoneLastIndex = maxMilestoneLength - 1;
const milestoneItem = $(".milestone-tab__list")
.children(".tab-item")
.not(".active")
.eq(0);
let milestoneActiveIndex = 0;
const milestoneInfo = {
icon: "/asset/img/about/circle.svg",
activeIcon: "/asset/img/about/circle-active.svg",
};
// 左箭头
$(".milestone-tab .left").on("click", function () {
if (milestoneActiveIndex <= 0) return;
milestoneActiveIndex--;
combineMilestoneActive(milestoneActiveIndex);
});
// 右箭头
$(".milestone-tab .right").on("click", function () {
if (milestoneActiveIndex >= maxMilestoneLength - 1) return;
milestoneActiveIndex++;
combineMilestoneActive(milestoneActiveIndex);
});
// 点击年份处理
$(".milestone-tab__list").on("click", ".tab-item", function (e, i) {
const index = $(this).index();
if (milestoneActiveIndex === index) return;
milestoneActiveIndex = index;
combineMilestoneActive(index);
});
function combineMilestoneActive(index) {
changeMilestoneActive(index);
changeMilestoneInfoActive(index);
moveMilestone();
}
function moveMilestone() {
if (maxMilestoneLength <= 1) return;
const milestoneItemWidth =
milestoneItem.width() + parseFloat(milestoneItem.css("marginLeft"));
const boxWidth = $(".milestone-tab__box").width();
const listWidth = maxMilestoneLength * milestoneItemWidth;
if (boxWidth > listWidth) {
return;
}
const isLastItem = milestoneActiveIndex == milestoneLastIndex;
if (isLastItem) return;
// 最大显示数量
const maxShowMilestoneItem = parseInt(boxWidth / milestoneItemWidth) + 1;
const isRoll =
milestoneActiveIndex + maxShowMilestoneItem > maxMilestoneLength;
let roll;
if (isRoll) {
roll = -((maxMilestoneLength - maxShowMilestoneItem) * milestoneItemWidth);
} else {
roll = -(milestoneActiveIndex * milestoneItemWidth);
}
$(".milestone-tab__list").css({
transform: `translateX(${roll}px)`,
});
}
// 修改里程碑节点 active class
function changeMilestoneActive(index) {
$(".tab-item.active")
.removeClass("active")
.children(".tab-item__icon")
.attr("src", milestoneInfo.icon);
$(".tab-item")
.eq(index)
.addClass("active")
.children(".tab-item__icon")
.attr("src", milestoneInfo.activeIcon);
}
// 修改里程碑信息 active
function changeMilestoneInfoActive(index) {
$(".about-milestone__info.active").hide().removeClass("active");
$(".about-milestone__info").eq(index).fadeIn(500).addClass("active");
}
/******** 里程碑 end *********/
/******** 客户说 begin *********/
new Swiper(".say-banner", {
autoplay: 3000,
loop: true,
nextButton: ".say-wrap .arrow-right",
prevButton: ".say-wrap .arrow-left",
});
/******** 客户说 end *********/
/******** 证书 begin *********/
new Swiper(".about-certificate__box", {
autoplay: 3000,
speed: 1000,
loop: true,
autoplayDisableOnInteraction: false,
centeredSlides: true,
watchSlidesProgress: true,
slidesPerView: 4,
slideToClickedSlide: true,
roundLengths : true,
prevButton: ".about-certificate-arrow .arrow-left",
nextButton: ".about-certificate-arrow .arrow-right",
breakpoints: {
1280: {
slidesPerView: 3.5,
}
},
onSetTranslate: function (swiper) {
let slides = swiper.slides;
for (i = 0; i < slides.length; i++) {
slide = slides.eq(i);
progress = slides[i].progress;
slide.css({ opacity: "", background: "" });
slide.transform(""); //清除样式
slide.transform("scale(" + (1 - Math.abs(progress) / 8) + ")");
}
},
onSetTransition: function (swiper, transition) {
let slides = swiper.slides;
for (var i = 0; i < slides.length; i++) {
var slide = slides.eq(i);
slide.transition(transition);
}
},
});
/******** 证书 end *********/
// 处于页面配置时,绑定方法
if ($isDecorateMode) {
document.addEventListener('diy_footer/1', (event) => {
const { field, value } = event.detail
console.log(field, value)
if (field === 'footer_ad') {
const nodes = $(
value
.map((item) => ``)
.join('')
)
$('.ys-footer__ad').empty()
$('.ys-footer__ad').append(nodes)
} else if (field === 'contact_phone') {
$('.footer_phone').text(value)
} else if (field === 'work_time') {
$('.footer_work_time').text(value)
} else if (field === 'contact_email') {
$('.footer_email').text(value)
} else if (field === 'footer_nav') {
const nodes = $(
value
.map(
(c) => `
`
)
.join('')
)
$('.ys-footer__content .center-part').empty()
$('.ys-footer__content .center-part').append(nodes)
} else if (field === 'right_part') {
const nodes = $(
value
.map((item) => `
`)
.join('')
)
$('.ys-footer__content .right-part').empty()
$('.ys-footer__content .right-part').append(nodes)
} else if (field === 'friendly_links') {
const nodes = $(
value
.map(
(e) => `