20260304临时补救article_list

This commit is contained in:
2026-03-24 09:51:18 +08:00
parent 8da302f382
commit 9dd44cc165
34 changed files with 5827 additions and 2066 deletions

171
js/common/commonJS1.js Normal file
View File

@@ -0,0 +1,171 @@
(function ($) {
// --- 1. 获取 URL 参数的工具函数 ---
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
});
}
// --- 2. 公共方法:主题匹配逻辑 ---
var topicListHandler = function (res, currentCode) {
if (res && res.data && Array.isArray(res.data.topic)) {
var match = res.data.topic.find(function (item) {
var normalizedTitle = (item.title || "").toLowerCase().replace(/[\s-]/g, '');
var normalizedCode = (currentCode || "").toLowerCase().replace(/[\s-]/g, '');
return normalizedTitle === normalizedCode || (normalizedTitle + "1") === normalizedCode;
});
if (match) {
return { id: match.base_topic_id, title: 'TMR' };
}
}
return null;
};
// --- 3. 静态 ID 映射表:解决“一个页面不同 ID”的问题 ---
// 以后增加新页面只需要在这里加一行,不用建文件夹
var footerMap = {
'peer-review-process1': 37,
'editorial-workflow1': 76,
'for-authors1': 74,
'open-access1': 70,
'for-librarians1': 77,
'for-conference-organizers1': 78,
// 如果有更多,继续往这里塞...
};
$(function () {
var path = window.location.pathname;
var segments = path.split('/').filter(Boolean);
var journalCode = null;
var pageKey = null;
var specialJournals = ['bmec', 'tmr', 'cancer', 'hpm', 'ia', 'in', 'lr', 'mdm'];
// 解析当前页面的 journalCode 和 pageKey
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 if (segments.indexOf('collection') !== -1) {
var CIndex = segments.indexOf('collection');
journalCode = segments[CIndex + 1];
pageKey = segments[segments.length - 1];
} else {
pageKey = segments[0];
journalCode = null;
}
// --- 4. 配置表重构 ---
var routeMap = {
// 学科类页面:统统指向 topicListHandler
'covid-191': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'clinical-medicine1': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'oncology1': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'food1': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'nutriology1': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'pharmacology1': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'immunology1': { oldPage: 'artihom_list_baseid.html', apiUrl: '/api/Journal/getAllTopics', dynamicKey: 'base_id', params: { J_num: 1 }, handler: topicListHandler },
'author-guidelines': {
oldPage: 'common_for_author.html',
apiUrl: '/api/Supplementary/getJournalDetail',
dynamicKey: 'J_num',
handler: function (res) {
if (res.data) return { id: res.data.journal_id || res.data.id, title: res.data.title };
return null;
}
},
// 固定结构的静态页面
'online-first1': { oldPage: 'artihom_list_oid.html', params: { J_num: 1, o_id: 1 } },
'top-cited1': { oldPage: 'artihom_list_cite.html', params: { J_num: 1, cite_id: 1 } },
'new-papers1': { oldPage: 'artihom_list_pid.html', params: { J_num: 1, p_id: 1 } },
};
// --- 5. 动态匹配逻辑:自动处理 footer 系列页面 ---
var config = routeMap[pageKey];
if (!config && footerMap[pageKey]) {
// 如果在映射表里找到了,自动指向 afoor_text.html
config = {
oldPage: 'afoor_text.html',
params: { footer_id: footerMap[pageKey] }
};
}
// 终极保底:如果页面以 1 结尾且符合学科逻辑,但没在 map 里(比如新加的学科)
if (!config && pageKey && pageKey.slice(-1) === '1') {
config = {
oldPage: 'artihom_list_baseid.html',
apiUrl: '/api/Journal/getAllTopics',
dynamicKey: 'base_id',
params: { J_num: 1 },
handler: topicListHandler
};
}
if (!config) return;
var $frame = $('frame[name="main"]');
if ($frame.length > 0) {
if (config.apiUrl && journalCode) {
var postData = config.getCustomParams ? config.getCustomParams(journalCode) : { usx: journalCode };
$.ajax({
type: 'post',
url: config.apiUrl,
data: postData,
dataType: 'json',
success: function (res) {
var result = (typeof config.handler === 'function') ? config.handler(res, journalCode) : null;
var finalId = (result && result.id) || (config.params && (config.params.sid || config.params.footer_id || config.params.J_num));
var finalTitle = (result && result.title) || pageKey;
renderFrame(finalId || 1, finalTitle);
},
error: function () {
renderFrame((config.params && (config.params.sid || config.params.J_num)) || 1, pageKey);
}
});
} else {
// 静态模式:直接取 footer_id 等参数
var staticId = config.params.footer_id || config.params.sid || config.params.J_num;
renderFrame(staticId, pageKey);
}
}
function renderFrame(mainId, title) {
if (title) document.title = title;
var url = "/" + config.oldPage + "?";
if (config.dynamicKey && mainId) url += config.dynamicKey + "=" + mainId + "&";
for (var key in config.params) {
if (key === config.dynamicKey) continue;
url += key + "=" + config.params[key] + "&";
}
$frame.attr('src', url + "id_updated=true");
}
// 保持原有的子页面交互逻辑...
$frame.on('load', function () {
try {
var $header = $('#index_top');
$header.find('[onclick*="window.location"]').each(function () {
var cmd = $(this).attr('onclick');
$(this).attr('onclick', cmd.replace('window.location', 'top.location'));
});
var childWin = this.contentWindow;
if (childWin && !childWin.getQueryString) childWin.getQueryString = mySmartGetQuery;
} catch (e) { }
});
});
})(jQuery);