|
@@ -1,4 +1,5 @@
|
|
|
|
|
|
+
|
|
|
$(function () {
|
|
|
//计算元素集合的总宽度
|
|
|
function calSumWidth(elements) {
|
|
@@ -8,6 +9,7 @@ $(function () {
|
|
|
});
|
|
|
return width;
|
|
|
}
|
|
|
+
|
|
|
//滚动到指定选项卡
|
|
|
function scrollToTab(element) {
|
|
|
var marginLeftVal = calSumWidth($(element).prevAll()), marginRightVal = calSumWidth($(element).nextAll());
|
|
@@ -35,6 +37,7 @@ $(function () {
|
|
|
marginLeft: 0 - scrollVal + 'px'
|
|
|
}, "fast");
|
|
|
}
|
|
|
+
|
|
|
//查看左侧隐藏的选项卡
|
|
|
function scrollTabLeft() {
|
|
|
var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
|
|
@@ -66,6 +69,7 @@ $(function () {
|
|
|
marginLeft: 0 - scrollVal + 'px'
|
|
|
}, "fast");
|
|
|
}
|
|
|
+
|
|
|
//查看右侧隐藏的选项卡
|
|
|
function scrollTabRight() {
|
|
|
var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
|
|
@@ -105,45 +109,74 @@ $(function () {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+
|
|
|
function menuItem() {
|
|
|
// 获取标识数据
|
|
|
+ var dataIndex = $(this).data('index');
|
|
|
var dataUrl = $(this).attr('href'),
|
|
|
- dataIndex = $(this).data('index'),
|
|
|
menuName = $.trim($(this).text()),
|
|
|
flag = true;
|
|
|
- if (dataUrl == undefined || $.trim(dataUrl).length == 0)return false;
|
|
|
+ if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false;
|
|
|
|
|
|
// 微信公众号菜单时,初始化选择公众号
|
|
|
var currentMp = $('.currentMp');
|
|
|
- if(dataUrl.indexOf('/wxmp/') != -1){
|
|
|
+ if (dataUrl.indexOf('/wxmp/') != -1) {
|
|
|
+ console.log('公众号菜单. URL:' + dataUrl);
|
|
|
currentMp.removeClass('hidden');
|
|
|
- }else {
|
|
|
- if(!currentMp.hasClass('hidden')){
|
|
|
+ } else {
|
|
|
+ console.log('非公众号菜单. URL:' + dataUrl);
|
|
|
+ if (!currentMp.hasClass('hidden')) {
|
|
|
currentMp.addClass('hidden');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 选项卡菜单已存在
|
|
|
+ console.log('选项卡菜单已存在');
|
|
|
$('.J_menuTab').each(function () {
|
|
|
+ console.log('当前 - ' + $(this).data('id') + ' - ' + dataUrl)
|
|
|
if ($(this).data('id') == dataUrl) {
|
|
|
+ console.log('处理 - ' + dataUrl);
|
|
|
+ console.log($(this));
|
|
|
+
|
|
|
if (!$(this).hasClass('active')) {
|
|
|
$(this).addClass('active').siblings('.J_menuTab').removeClass('active');
|
|
|
scrollToTab(this);
|
|
|
// 显示tab对应的内容区
|
|
|
$('.J_mainContent .J_iframe').each(function () {
|
|
|
+ console.log('当前 iframe - ' + $(this).data('id') + ' - ' + dataUrl)
|
|
|
if ($(this).data('id') == dataUrl) {
|
|
|
+ console.log('处理 iframe - ' + dataUrl);
|
|
|
$(this).show().siblings('.J_iframe').hide();
|
|
|
+
|
|
|
+
|
|
|
+ console.log($(this));
|
|
|
+ console.log('src:' + $(this).attr('src'))
|
|
|
+
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ console.log('TODO 如果是公众号tab && 公众号已经切换,reload');
|
|
|
+ if (isWxMpUrl(dataUrl) && wxMpHasChange) {
|
|
|
+
|
|
|
+ $('.J_mainContent .J_iframe').each(function () {
|
|
|
+ if ($(this).data('id') == dataUrl) {
|
|
|
+ $(this).show().siblings('.J_iframe').hide();
|
|
|
+ $(this).attr('src', $(this).attr('src'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ setCurrentWxMpInfo2Last();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
flag = false;
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 选项卡菜单不存在
|
|
|
if (flag) {
|
|
|
+ console.log('选项卡菜单不存在')
|
|
|
var str = '<a href="javascript:;" class="active J_menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
|
|
|
$('.J_menuTab').removeClass('active');
|
|
|
|
|
@@ -168,6 +201,83 @@ $(function () {
|
|
|
|
|
|
$('.J_menuItem').on('click', menuItem);
|
|
|
|
|
|
+ /**
|
|
|
+ * 是否为公众号URL
|
|
|
+ * @param url
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+ function isWxMpUrl(url) {
|
|
|
+ return url.indexOf('/wxmp/') != -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公众号是否切换
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+ function wxMpHasChange() {
|
|
|
+ var currentMpInfo = $('.currentMpInfo');
|
|
|
+ var lastMpInfo = $('.lastMpInfo');
|
|
|
+ console.log('wxMpHasChange: ' + currentMpInfo.attr('data-appid') + ' - ' + lastMpInfo.attr('data-appid'));
|
|
|
+ var hasChange = currentMpInfo.attr('data-appid') != lastMpInfo.attr('data-appid');
|
|
|
+ console.log('hasChange:' + hasChange);
|
|
|
+ return hasChange;
|
|
|
+ }
|
|
|
+
|
|
|
+ function setCurrentWxMpInfo2Last() {
|
|
|
+ var currentMpInfo = $('.currentMpInfo');
|
|
|
+ var lastMpInfo = $('.lastMpInfo');
|
|
|
+
|
|
|
+ lastMpInfo.text(currentMpInfo.text());
|
|
|
+ lastMpInfo.attr('data-appid', currentMpInfo.attr('data-appid'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切换公众号
|
|
|
+ */
|
|
|
+ $('.dropdown-menu.mpList li a').on('click', function () {
|
|
|
+ var that = $(this);
|
|
|
+ var appId = that.attr('lang');
|
|
|
+ var mpName = that.text();
|
|
|
+
|
|
|
+ console.log('当前appId:' + appId);
|
|
|
+ console.log('当前公众号名称:' + mpName);
|
|
|
+
|
|
|
+ var currentMpInfo = $('.currentMpInfo');
|
|
|
+ var lastMpInfo = $('.lastMpInfo');
|
|
|
+
|
|
|
+ lastMpInfo.text(currentMpInfo.text());
|
|
|
+ lastMpInfo.attr('data-appid', currentMpInfo.attr('data-appid'));
|
|
|
+
|
|
|
+ currentMpInfo.text(mpName);
|
|
|
+ currentMpInfo.attr('data-appid', appId);
|
|
|
+
|
|
|
+ console.log(currentMpInfo);
|
|
|
+
|
|
|
+ // 获取当前激活的选项卡,如果为公众号菜单,则reload
|
|
|
+ var $JMenuItem = $('.J_menuTab.active');
|
|
|
+ console.log($JMenuItem);
|
|
|
+ var dataUrl = $JMenuItem.attr('data-id');
|
|
|
+ if (isWxMpUrl(dataUrl)) {
|
|
|
+ console.log('当前激活的tab为公众号菜单,reload');
|
|
|
+ if (wxMpHasChange()) {
|
|
|
+ $('.J_mainContent .J_iframe').each(function () {
|
|
|
+ if ($(this).data('id') == dataUrl) {
|
|
|
+ $(this).show().siblings('.J_iframe').hide();
|
|
|
+ $(this).attr('src', $(this).attr('src'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.log('wxMpHasChange: false')
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log('当前激活的tab非公众号菜单,无需reload');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
// 关闭选项卡菜单
|
|
|
function closeTab() {
|
|
|
var closeTabId = $(this).parents('.J_menuTab').data('id');
|
|
@@ -251,26 +361,45 @@ $(function () {
|
|
|
$('.J_menuTabs').on('click', '.J_menuTab i', closeTab);
|
|
|
|
|
|
//关闭其他选项卡
|
|
|
- function closeOtherTabs(){
|
|
|
+ function closeOtherTabs() {
|
|
|
$('.page-tabs-content').children("[data-id]").not(":first").not(".active").each(function () {
|
|
|
$('.J_iframe[data-id="' + $(this).data('id') + '"]').remove();
|
|
|
$(this).remove();
|
|
|
});
|
|
|
$('.page-tabs-content').css("margin-left", "0");
|
|
|
}
|
|
|
+
|
|
|
$('.J_tabCloseOther').on('click', closeOtherTabs);
|
|
|
|
|
|
//滚动到已激活的选项卡
|
|
|
- function showActiveTab(){
|
|
|
+ function showActiveTab() {
|
|
|
scrollToTab($('.J_menuTab.active'));
|
|
|
}
|
|
|
+
|
|
|
$('.J_tabShowActive').on('click', showActiveTab);
|
|
|
|
|
|
|
|
|
// 点击选项卡菜单
|
|
|
function activeTab() {
|
|
|
+
|
|
|
+ console.log('tab click.')
|
|
|
+ var dataUrl = $(this).data('id');
|
|
|
+ if (isWxMpUrl(dataUrl) && wxMpHasChange()) {
|
|
|
+ console.log('公众号已经切换 && 为公众号tab,数据需要reload')
|
|
|
+ $('.J_mainContent .J_iframe').each(function () {
|
|
|
+ if ($(this).data('id') == dataUrl) {
|
|
|
+ $(this).show().siblings('.J_iframe').hide();
|
|
|
+ $(this).attr('src', $(this).attr('src'));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置上个公众号信息,防止下次再刷新
|
|
|
+ setCurrentWxMpInfo2Last();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
if (!$(this).hasClass('active')) {
|
|
|
- var currentId = $(this).data('id');
|
|
|
+ var currentId = dataUrl;
|
|
|
// 显示tab对应的内容区
|
|
|
$('.J_mainContent .J_iframe').each(function () {
|
|
|
if ($(this).data('id') == currentId) {
|