20260304临时补救article_list
This commit is contained in:
147
js/common/commonJS.js
Normal file
147
js/common/commonJS.js
Normal file
@@ -0,0 +1,147 @@
|
||||
(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);
|
||||
171
js/common/commonJS1.js
Normal file
171
js/common/commonJS1.js
Normal 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);
|
||||
Reference in New Issue
Block a user