Files
journal_com/js/common/commonJS.js

147 lines
5.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(function($) {
// --- 1. 万能参数获取函数 ---
var mySmartGetQuery = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
};
if (!window.getQueryString) {
Object.defineProperty(window, 'getQueryString', {
value: mySmartGetQuery,
writable: false,
configurable: false
});
}
$(function() {
var path = window.location.pathname;
var segments = path.split('/').filter(Boolean);
// --- 2. 识别逻辑 ---
var journalCode = null;
var pageKey = null;
var specialJournals = ['bmec', 'tmr', 'cancer', 'hpm', 'ia', 'in', 'lr', 'mdm'];
if (segments.indexOf('journals') !== -1) {
var jIndex = segments.indexOf('journals');
journalCode = segments[jIndex + 1];
pageKey = segments[segments.length - 1];
} else if (specialJournals.includes(segments[0])) {
journalCode = segments[0];
pageKey = segments[segments.length - 1];
} else {
pageKey = segments[0];
journalCode = null;
}
// --- 3. 增强版映射表 (支持多参数 + 多接口) ---
var routeMap = {
// 模式 A纯静态页面多参数传递
'peer-review-process1': {
oldPage: 'afoor_text.html',
params: { footer_id: 37, sid: 37 }
},
'editorial-workflow1': {
oldPage: 'afoor_text.html',
params: { footer_id: 76, sid: 76 }
},
'for-authors1': {
oldPage: 'afoor_text.html',
params: { footer_id: 74, sid: 74 }
},
'open-access1': {
oldPage: 'afoor_text.html',
params: { footer_id: 70, sid: 70 }
},
'for-librarians1': {
oldPage: 'afoor_text.html',
params: { footer_id: 77, sid: 77 }
},
'for-conference-organizers1': {
oldPage: 'afoor_text.html',
params: { footer_id: 78, sid: 78 }
},
// 模式 B动态页面指定不同接口
'author-guidelines': {
oldPage: 'common_for_author.html',
apiUrl: '/api/Supplementary/getJournalDetail', // 指定接口A
dynamicKey: 'J_num', // 接口返回的ID对应的URL参数名
params: { sid: 1, } // 其他固定携带参数
},
'editorial-board': {
oldPage: 'journal_members.html',
apiUrl: '/api/Journal/getMembers', // 指定接口B
dynamicKey: 'j_id',
params: { sid: 0, view: 'list' }
}
};
var config = routeMap[pageKey];
if (!config) return;
var $frame = $('frame[name="main"]');
if ($frame.length > 0) {
// 如果配置了 apiUrl 且有期刊代码,则发起 Ajax
if (config.apiUrl && journalCode) {
$.ajax({
type: 'post',
url: config.apiUrl,
data: { usx: journalCode },
dataType: 'json',
success: function(res) {
// 尝试从返回数据中获取 ID (假设字段为 journal_id 或 id)
var remoteId = res.data ? (res.data.journal_id || res.data.id) : null;
var finalId = remoteId || config.params.sid;
var title = (res.data && res.data.title) || pageKey;
renderFrame(finalId, title);
},
error: function() {
renderFrame(config.params.sid, pageKey);
}
});
} else {
// 静态模式:直接取参数中的第一个或特定 ID
var staticId = config.params.footer_id || config.params.sid;
renderFrame(staticId, pageKey);
}
}
/**
* 渲染函数:拼装所有参数
*/
function renderFrame(mainId, title) {
if (title) document.title = title;
var url = "/" + config.oldPage + "?";
// 1. 处理动态 ID (如果有)
if (config.dynamicKey) {
url += config.dynamicKey + "=" + mainId + "&";
}
// 2. 遍历 params 对象,拼入所有参数
for (var key in config.params) {
// 如果这个 key 已经在 dynamicKey 里处理过了,可以视情况跳过或覆盖
if (key === config.dynamicKey) continue;
url += key + "=" + config.params[key] + "&";
}
var finalSrc = url + "id_updated=true";
$frame.attr('src', finalSrc);
console.log("🚀 跳转路径:", finalSrc);
}
// --- 子页面注入 ---
$frame.on('load', function() {
try {
var childWin = this.contentWindow;
if (childWin && !childWin.getQueryString) {
childWin.getQueryString = mySmartGetQuery;
}
} catch (e) {}
});
});
})(jQuery);