// 处于页é¢é…置时,绑定方法 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')
)
})
// 处于页é¢é…置时,绑定方法 start
if ($isDecorateMode) {
document.addEventListener("diy_banner/1", (event) => {
const { field, value } = event.detail;
console.log(field, value)
let html = ''
value.forEach(e => {
html += `
`
})
$('.' + field).html(html)
})
}
// 页é¢åŸ‹ç‚¹
$('.ys-banner .banner-slide').click(function() {
clickLog({
page_key: 'index',
module_key: 'banner/1'
})
})
// 产å“ä¸å¿ƒ
$('.ys-index__product a').click(function() {
clickLog({
page_key: 'index',
module_key: 'index/product'
})
})
// 处于页é¢é…置时,绑定方法 start
if ($isDecorateMode) {
document.addEventListener("diy_index/1", (event) => {
const { field, value } = event.detail;
console.log(field, value)
let html = ''
if (field === 'strength_title') {
$('.ys-index__strength .ys-index__title').html(value)
} else if (field === 'strength_subtitle') {
$('.ys-index__strength .ys-index__subtitle').html(value)
} else if (field === 'strength_list') {
value.forEach(e => {
html += `
`
})
$('.strength-scroll').html(html)
}
})
}
new Swiper(".ys-banner", {
autoplay: 3000,
loop: true,
paginationClickable :true,
pagination: '.ys-banner__indicator',
nextButton: '.ys-banner #next',
prevButton: '.ys-banner #prev',
})
/* new Swiper(".tab-solution-warp", {
slidesPerView: 4,
spaceBetween: 20,
slidesPerGroup: 4,
pagination: '.swiper-pagination',
paginationClickable :true,
}) */
new Swiper(".ys-index__content--product .content-box", {
autoplay: 3000,
loop: true,
slidesPerView: 3,
spaceBetween: 25,
slidesPerGroup: 1,
roundLengths : true,
prevButton: '.content-product-arrow .arrow-left',
nextButton: '.content-product-arrow .arrow-right',
})
// 页é¢åŸ‹ç‚¹
//内容ä¸å¿ƒ
$('.ys-index__information a').click(function() {
clickLog({
page_key: 'index',
module_key: 'index/content'
})
})
//解决方案
$('.ys-index__content--solution a').click(function() {
clickLog({
page_key: 'index',
module_key: 'index/solution'
})
})
/* æ•°å—æ»šåЍ start */
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() {
$(".ys-index-about .power-item").each(function () {
let val = +$(this).find(".power-num div:first").data("number");
animateNumber($(this).find(".power-num div:first"), val, 800);
});
}
function scrollToPower() {
if ($(window).scrollTop() >= $("#power").offset().top - 300) {
initCounter();
// åˆå§‹åŒ–ä¹‹åŽæ¸…除绑定事件
$(window).off("scroll", scrollToPower);
}
}
$(window).scroll(scrollToPower);
/* æ•°å—æ»šåЍ 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) => `
${e.title}
`
)
.join('')
)
$('.ys-footer__friendly ul').empty()
$('.ys-footer__friendly ul').append(nodes)
} else if (field === 'copyright') {
$('.copyright-wrap span').text(value)
} else if (field === 'beian') {
$('.copyright-wrap a').text(value)
} else if (field === 'footer_logo') {
$('.footer-logo').attr('alt', value.alt)
$('.footer-logo').attr('src', value.src)
} else if (field === 'map_links') {
const nodes = $(
value
.map(
(e) => `
${e.title}
`
)
.join('')
)
$('.ys-footer__end .end-link').empty()
$('.ys-footer__end .end-link').append(nodes)
}
})
}
window.addEventListener('openService', openService) // 监å¬å…¨å±€å®¢æœç‚¹å‡»äº‹ä»¶
$('#backTop').click(function () {
$('html, body').animate({ scrollTop: 0 }, 300)
})
$('.ys-rightNav .online-serve').click(function() {
openService()
})
// 打开客æœå¼¹çª—
function openService() {
if ($('#aff-im-root .embed-icon-pcIcon5').length > 0) {
$('#aff-im-root .embed-icon-pcIcon5').click()
} else {
$('#newBridge .nb-icon-wrap').click()
}
customEventLog("open_server"); // 打点
customEventLog("set", { key:'purchase', value:'service'}, {onlyTrack: ["ClarityTracker"]}); // clarityæ ‡ç¾
}
// 监å¬é¡µé¢æ»šåЍ
$(window).scroll(function () {
$('.ys-rightNav #backTop').css('display', $(document).scrollTop() ? 'block' : 'none')
})