// 处于页面配置时,绑定方法 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')
)
})
$(function () {
if (!solutionType || solutionType == 1) {
// banner 轮播
const bannerSwiper = new Swiper(".swiper", {
autoplay: false,
loop: true,
effect: "fade",
onlyExternal: true,
});
// banner 轮播切换
$(".solution-banner__tabs").on("click", ".banner-tabs__item", function () {
$(".banner-tabs__item.active").removeClass("active");
const index = $(this).addClass("active").index();
bannerSwiper.slideTo(index + 1, 1000, false);
});
/* tab start */
// tab 滚动监听
const fixedHeight = 107 + 56 + 5; // 导航栏 + tab栏高度 + 容错
let tabContentItemTopList = [];
function getTabContentItemTop() {
tabContentItemTopList = [];
$(".solution-content__item").each(function () {
tabContentItemTopList.push(
Math.ceil($(this).offset().top - fixedHeight)
);
});
}
const handleScroll = throttle(
function () {
if (
!Array.isArray(tabContentItemTopList) ||
!tabContentItemTopList.length
)
return;
const scrollTop = $(window).scrollTop();
if (scrollTop <= tabContentItemTopList[0]) {
changeTabActive(0);
return;
}
for (let i = 0; i < tabContentItemTopList.length; i++) {
const itemTop = tabContentItemTopList[i];
if (scrollTop >= itemTop) {
changeTabActive(i);
}
}
},
400,
{ leading: false }
);
function initScrollTab() {
getTabContentItemTop();
handleScroll();
$(window).on("resize", function () {
getTabContentItemTop();
});
$(window).on("scroll", handleScroll);
}
initScrollTab();
// tab 切换
let tabTimer;
$(".solution-tabs__list").on("click", "a", function () {
$(window).off("scroll", handleScroll);
const top = $($(this).attr("href")).offset().top - fixedHeight + 1;
changeTabActive($(this).parent().index());
$("html, body")
.stop()
.animate(
{
scrollTop: top,
},
300,
function () {
clearTimeout(tabTimer);
tabTimer = setTimeout(() => {
clearTimeout(tabTimer);
$(window).on("scroll", handleScroll);
}, 300);
}
);
return false;
});
function changeTabActive(index) {
$(".solution-tabs__item.active").removeClass("active");
$(".solution-tabs__item").eq(index).addClass("active");
}
/* tab end */
// 客服
$(".server-button").click(function () {
window.dispatchEvent(new CustomEvent("openService"));
});
}
});
$(function () {
if (solutionType == 2) {
/* tab start */
// tab 滚动监听
const fixedHeight = 107 + 56 + 20; // 导航栏 + tab栏高度 + 容错
let tabContentItemTopList = [];
function getTabContentItemTop() {
tabContentItemTopList = [];
$(".solution-content__item").each(function () {
tabContentItemTopList.push(
Math.ceil($(this).offset().top - fixedHeight)
);
});
}
const handleScroll = throttle(
function () {
if (
!Array.isArray(tabContentItemTopList) ||
!tabContentItemTopList.length
)
return;
const scrollTop = $(window).scrollTop();
if (scrollTop <= tabContentItemTopList[0]) {
changeTabActive(0);
return;
}
for (let i = 0; i < tabContentItemTopList.length; i++) {
const itemTop = tabContentItemTopList[i];
if (scrollTop >= itemTop) {
changeTabActive(i);
}
}
},
400,
{ leading: false }
);
function initScrollTab() {
getTabContentItemTop();
handleScroll();
$(window).on("resize", function () {
getTabContentItemTop();
});
$(window).on("scroll", handleScroll);
}
initScrollTab();
// tab 切换
let tabTimer;
$(".solution-tabs__list").on("click", "a", function () {
$(window).off("scroll", handleScroll);
const top = $($(this).attr("href")).offset().top - fixedHeight + 1;
changeTabActive($(this).parent().index());
$("html, body")
.stop()
.animate(
{
scrollTop: top,
},
300,
function () {
clearTimeout(tabTimer);
tabTimer = setTimeout(() => {
clearTimeout(tabTimer);
$(window).on("scroll", handleScroll);
}, 300);
}
);
return false;
});
function changeTabActive(index) {
$(".solution-tabs__item.active").removeClass("active");
$(".solution-tabs__item").eq(index).addClass("active");
}
/* tab end */
// 客服
$(".server-button").click(function () {
window.dispatchEvent(new CustomEvent("openService"));
});
}
});
$(function () {
if (solutionType == 3) {
/* tab start */
// tab 滚动监听
const fixedHeight = 107 + 56 + 20; // 导航栏 + tab栏高度 + 容错
let tabContentItemTopList = [];
function getTabContentItemTop() {
tabContentItemTopList = [];
$(".solution-content__item").each(function () {
tabContentItemTopList.push(
Math.ceil($(this).offset().top - fixedHeight)
);
});
}
const handleScroll = throttle(
function () {
if (
!Array.isArray(tabContentItemTopList) ||
!tabContentItemTopList.length
)
return;
const scrollTop = $(window).scrollTop();
if (scrollTop <= tabContentItemTopList[0]) {
changeTabActive(0);
return;
}
for (let i = 0; i < tabContentItemTopList.length; i++) {
const itemTop = tabContentItemTopList[i];
if (scrollTop >= itemTop) {
changeTabActive(i);
}
}
},
400,
{ leading: false }
);
function initScrollTab() {
getTabContentItemTop();
handleScroll();
$(window).on("resize", function () {
getTabContentItemTop();
});
$(window).on("scroll", handleScroll);
}
initScrollTab();
// tab 切换
let tabTimer;
$(".solution-tabs__list").on("click", "a", function () {
$(window).off("scroll", handleScroll);
const top = $($(this).attr("href")).offset().top - fixedHeight + 1;
changeTabActive($(this).parent().index());
$("html, body")
.stop()
.animate(
{
scrollTop: top,
},
300,
function () {
clearTimeout(tabTimer);
tabTimer = setTimeout(() => {
clearTimeout(tabTimer);
$(window).on("scroll", handleScroll);
}, 300);
}
);
return false;
});
function changeTabActive(index) {
$(".solution-tabs__item.active").removeClass("active");
$(".solution-tabs__item").eq(index).addClass("active");
}
/* tab end */
// 客服
$(".server-button").click(function () {
window.dispatchEvent(new CustomEvent("openService"));
});
}
});
$(function () {
if (solutionType == 4) {
new Swiper(".solution-detail--4 .solution-relation__box", {
autoplay: 3000,
loop: true,
slidesPerView: 3,
spaceBetween: 25,
slidesPerGroup: 1,
roundLengths: true,
prevButton: ".solution-detail--4 .solution-relation__arrow .arrow-left",
nextButton: ".solution-detail--4 .solution-relation__arrow .arrow-right",
breakpoints: {
1280: {
spaceBetween: 10,
},
},
});
}
});
// 处于页面配置时,绑定方法
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) => `