/* * @Descripttion : 通用js * @Author : liuzhifang * @Date : 2022-06-02 13:42:45 * @LastEditors : Please set LastEditors * @LastEditTime : 2022-12-24 00:18:35 */ // 导航服务和消息 foxui.tooltip({ el: '#barService', content: barServiceHtml(), className: 'bar-service-container', width: '324px', }); foxui.tooltip({ el: '#barBell', content: barBellHtml(), className: 'bar-bell-container', effect: 'light', width: '330px', }); // 导航折叠功能 $('.foxcms-menu-nav-fold').on('click', function () { let $this = $(this), $icon = $this.find('i'), $inner = $('.foxcms-menu-nav-inner'), isRotate = $icon.is('.rotate'); if (isRotate) { $icon.removeClass('rotate'); $inner.animate({ width: '148px' }); } else { $icon.addClass('rotate'); $inner.animate({ width: 0 }); } }); // 根据窗口宽度判断是否折叠 let foldTimer = null; $(window).on('resize', function () { if (foldTimer) { clearTimeout(foldTimer); foldTimer = null; } foldTimer = setTimeout(function () { let width = $(window).width(), $fold = $('.foxcms-menu-nav-fold'), $icon = $fold.find('i'), $inner = $('.foxcms-menu-nav-inner'), isRotate = $icon.is('.rotate'); if (width < 1440) { if (!isRotate) { $icon.addClass('rotate'); $inner.animate({ width: 0 }); } } else { if (isRotate) { $icon.removeClass('rotate'); $inner.animate({ width: '148px' }); } } clearTimeout(foldTimer); foldTimer = null; }, 300); }); // 收起/展开所有导航 $('.foxcms-menu-expand-all i').on('click', function () { let $container = $('.foxui-menu.foxui-type-vertical'), $this = $(this), isActive = $this.is('.is-active'); if (isActive) { let $openHandle = $container.find('.foxui-menu-handle.is-active'); $openHandle.click(); $this.removeClass('is-active'); } else { let $foldHandle = $container.find('.foxui-menu-handle:not(.is-active)'); $foldHandle.click(); $this.addClass('is-active'); } }); // 根据折叠转换全部折叠按钮状态 $(document).on('click', '.foxui-menu.foxui-type-vertical .foxui-menu-handle', function () { let count = $('.foxui-menu.foxui-type-vertical .foxui-menu-handle').length, openLen = $('.foxui-menu.foxui-type-vertical .foxui-menu-handle.is-active').length; if (count === openLen) { $('.foxcms-menu-expand-all i').addClass('is-active'); } else { $('.foxcms-menu-expand-all i').removeClass('is-active'); } }); // 表单字段调用 $(document).on('click', '.call-field .foxui-tag', function () { const text = $(this).text(), el = document.createElement('input'); el.value = text; el.setAttribute('readonly', ''); el.style.position = 'absolute'; el.style.opacity = 0; document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); foxui.message({ text: '已复制到剪贴板' }); }); // 右侧浮动预览模板 $('.web-image-view .content-box .main-part').on('mouseover', function () { const viewHeight = $(this).height(); const imgHeight = $(this).find('img').height(); const mValue = viewHeight - imgHeight; $(this) .find('img') .css('marginTop', mValue + 'px'); }); $('.web-image-view .content-box .main-part').on('mouseout', function () { $(this).find('img').css('marginTop', 0); }); /* bar -> html *****************************************************************************************************/ function barServiceHtml() { return [ '
', '
', '', '
', '
', '
', '
', '
', '', '
', '
', '
', '
', '

扫码联系官方客服

', '

提供线上咨询

', '

400-888-3116

', '
', '
', '
', '
', '
', ].join(''); } function barBellHtml() { return [ '
', '
', '

系统消息

', '
', '
', '', '', '', '', '
', '
', ].join(''); } // 标签调用 html function _callHtml(dataObj) { return [ '
', '
', '', ``, '
', '
', '', ``, '
', '
', '', ``, '
', '
', '

请将相应标签复制并粘贴到对应模板文件中!

', '
', '
', ].join(''); } // 校验颜色值是否合法 function _CheckIsColor(bgVal) { let type = ''; if (/^rgb\(/.test(bgVal)) { //如果是rgb开头,200-249,250-255,0-199 type = '^[rR][gG][Bb][(]([\\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)[\\s]*,){2}[\\s]*(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)[\\s]*[)]{1}$'; } else if (/^rgba\(/.test(bgVal)) { //如果是rgba开头,判断0-255:200-249,250-255,0-199 判断0-1:0 1 1.0 0.0-0.9 type = '^[rR][gG][Bb][Aa][(]([\\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)[\\s]*,){3}[\\s]*(1|1.0|0|0.[0-9])[\\s]*[)]{1}$'; } else if (/^#/.test(bgVal)) { //六位或者三位 type = '^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$'; } else if (/^hsl\(/.test(bgVal)) { //判断0-360 判断0-100%(0可以没有百分号) type = '^[hH][Ss][Ll][(]([\\s]*(2[0-9][0-9]|360|3[0-5][0-9]|[01]?[0-9][0-9]?)[\\s]*,)([\\s]*((100|[0-9][0-9]?)%|0)[\\s]*,)([\\s]*((100|[0-9][0-9]?)%|0)[\\s]*)[)]$'; } else if (/^hsla\(/.test(bgVal)) { type = '^[hH][Ss][Ll][Aa][(]([\\s]*(2[0-9][0-9]|360|3[0-5][0-9]|[01]?[0-9][0-9]?)[\\s]*,)([\\s]*((100|[0-9][0-9]?)%|0)[\\s]*,){2}([\\s]*(1|1.0|0|0.[0-9])[\\s]*)[)]$'; } if (!type || bgVal.match(new RegExp(type)) == null) { return false; } else { return true; } } // 按钮形状单选 $(document).on('click', '.button-radio .button-radio-item', function () { $(this).closest('.button-radio').find('.button-radio-item.is-active').removeClass('is-active'); $(this).addClass('is-active'); });