/** * 右侧浮窗组件 — float-widget.js * 根据后台配置数据动态渲染浮窗按钮 */ (function () { 'use strict'; // SVG 图标定义 var ICONS = { qq: '', service: '', group: '', wechat: '', arrowUp: '' }; /** * 从后台注入的数据或默认 demo 数据 * window.__FLOAT_WIDGET_DATA__ 可被后台模板覆盖 */ var defaultData = [ { type: 'qq', label: 'QQ客服', items: [ { qq: '10001', time: '09:00 - 22:00' }, { qq: '10002', time: '09:00 - 18:00' } ] }, { type: 'service', label: '在线客服', url: 'javascript:;' }, { type: 'group', label: '交流群', qrcode: '/web/BlackFruit-web/assets/img/index/qrcode-placeholder.png' }, { type: 'wechat', label: '公众号', qrcode: '/web/BlackFruit-web/assets/img/index/qrcode-placeholder.png' } ]; function getData() { return window.__FLOAT_WIDGET_DATA__ || defaultData; } function buildQQPopup(item) { var html = '
QQ客服
'; for (var i = 0; i < item.items.length; i++) { var entry = item.items[i]; html += '
' + '
' + ICONS.qq + '
' + '
' + '' + entry.qq + '' + '' + entry.time + '' + '
' + '
点击复制
' + '
'; } html += '
'; return html; } function buildServicePopup(item) { return '
点击跳转在线客服
'; } function buildQRPopup(item) { return '
' + item.label + '
' + '
' + '' + item.label + '' + '
扫码' + (item.type === 'group' ? '加群' : '关注') + '
' + '
'; } function render() { var data = getData(); var container = document.querySelector('.float-widget'); if (!container) return; var html = ''; for (var i = 0; i < data.length; i++) { var item = data[i]; var icon = ICONS[item.type] || ''; var popupContent = ''; if (item.type === 'qq') { popupContent = buildQQPopup(item); } else if (item.type === 'service') { popupContent = buildServicePopup(item); } else if (item.type === 'group' || item.type === 'wechat') { popupContent = buildQRPopup(item); } if (item.type === 'service') { html += '' + icon + '
' + popupContent + '
' + '
'; } else { html += '
' + icon + '
' + popupContent + '
' + '
'; } } // 回到顶部按钮 html += '
' + ICONS.arrowUp + '
'; container.innerHTML = html; // 回到顶部逻辑 var backTopBtn = document.getElementById('fwBackTop'); if (backTopBtn) { window.addEventListener('scroll', function () { if (window.scrollY > 300) { backTopBtn.classList.add('show'); } else { backTopBtn.classList.remove('show'); } }); backTopBtn.addEventListener('click', function () { window.scrollTo({ top: 0, behavior: 'smooth' }); }); } } // DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', render); } else { render(); } })();