This commit is contained in:
2026-01-13 09:32:33 +08:00
parent 0f3ee631e3
commit 1755fd2202
20 changed files with 3656 additions and 3385 deletions

View File

@@ -59,48 +59,48 @@ async function loadJournalType() {
let parsedData = null;
if (cachedString) {
try {
// 必须先解析 JSON 字符串
parsedData = JSON.parse(cachedString);
} catch (e) {
console.error("缓存数据解析失败,将重新请求 API:", e);
}
try {
// 必须先解析 JSON 字符串
parsedData = JSON.parse(cachedString);
} catch (e) {
console.error("缓存数据解析失败,将重新请求 API:", e);
}
}
// 2. 检查解析后的数据是否有效(是数组且长度大于 0
if (parsedData && Array.isArray(parsedData) && parsedData.length > 0) {
// 缓存有效,直接返回缓存数据
return parsedData;
// 缓存有效,直接返回缓存数据
return parsedData;
}
// 3. 如果缓存无效或不存在,执行 API 调用
try {
// 第一个 API 调用,使用 await 接收结果
const journalRes = await api.post('api/Articletype/getArticleType', {});
if (journalRes.status === 1) {
// 存储 journal data
localStorage.setItem('journalTypeData', JSON.stringify(journalRes.data.base));
localStorage.setItem('journalTypeDataAll', JSON.stringify([...journalRes.data.base, ...journalRes.data.supplement]));
}
// 第一个 API 调用,使用 await 接收结果
const journalRes = await api.post('api/Articletype/getArticleType', {});
if (journalRes.status === 1) {
// 存储 journal data
localStorage.setItem('journalTypeData', JSON.stringify(journalRes.data.base));
localStorage.setItem('journalTypeDataAll', JSON.stringify([...journalRes.data.base, ...journalRes.data.supplement]));
}
// 第二个 API 调用,串行执行
const medicalRes = await api.post('api/Articletype/getMedicalType', {});
if (medicalRes.status === 1) {
// 存储 medical data
localStorage.setItem('opMedicalListData', JSON.stringify(medicalRes.data));
}
// 4. 返回第一个 API 调用的主要数据
if (journalRes.status === 1) {
return journalRes.data.base;
}
// 第二个 API 调用,串行执行
const medicalRes = await api.post('api/Articletype/getMedicalType', {});
if (medicalRes.status === 1) {
// 存储 medical data
localStorage.setItem('opMedicalListData', JSON.stringify(medicalRes.data));
}
// 4. 返回第一个 API 调用的主要数据
if (journalRes.status === 1) {
return journalRes.data.base;
}
} catch (error) {
// 集中处理 API 调用失败
console.error('Error loading data:', error);
return []; // 失败时返回一个默认的空数组,避免程序崩溃
// 集中处理 API 调用失败
console.error('Error loading data:', error);
return []; // 失败时返回一个默认的空数组,避免程序崩溃
}
// 如果所有流程都没有返回,默认返回空数组
return [];
}
@@ -110,7 +110,7 @@ async function loadJournalType() {
async function loadJournalList() {
try {
const localData = store.state.journalList;
if (localData && Array.isArray(localData) && localData.length > 0) {
return localData;
}
@@ -171,51 +171,36 @@ Vue.filter('jtName', function (value) {
// 使用 ES Module
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts
Vue.prototype.$api = api
Vue.config.productionTip = false;
import Editor from "@tinymce/tinymce-vue"; // 默认导入
Vue.component("Editor", Editor);
//自定义组件
const components = {
'common-table': () => import('@/components/page/components/table/table.vue'),
'common-review-article': () => import('@/components/page/components/reviewArticle/index.vue'),
'common-editor-article': () => import('@/components/page/components/EditorArticle/index.vue'),
'common-editor-article-detail': () => import('@/components/page/components/EditorArticle/detail.vue'),
'common-late-x': () => import('@/components/page/components/table/LateX.vue'),
'common-major': () => import('@/components/page/components/major/index.vue'),
'common-major-list': () => import('@/components/page/components/major/list.vue'),
'common-paypal-button': () => import('@/components/page/components/pendingPayment/PayPalButton.vue'),
'common-tiff': () => import('@/components/page/components/table/tiff.vue'),
'common-content': () => import('@/components/page/components/table/content.vue'),
'common-word': () => import('@/components/page/components/table/word.vue'),
'common-comment': () => import('@/components/page/components/table/comment.vue'),
'common-edit-table': () => import('@/components/page/components/table/editTable.vue'),
'common-annotations': () => import('@/components/page/components/table/annotations.vue'),
'common-word-html': () => import('@/components/page/components/table/wordHtml.vue'),
'common-word-html-type-setting': () => import('@/components/page/components/table/wordHtmlTypesetting.vue'),
'common-drag-word': () => import('@/components/page/components/table/dragWord.vue'),
};
import commonTable from '@/components/page/components/table/table.vue'
Vue.component('common-table', commonTable);
import commonReviewArticle from '@/components/page/components/reviewArticle/index.vue'
Vue.component('common-review-article', commonReviewArticle);
import commonEditorArticle from '@/components/page/components/EditorArticle/index.vue'
Vue.component('common-editor-article', commonEditorArticle);
import commonEditorArticleDetail from '@/components/page/components/EditorArticle/detail.vue'
Vue.component('common-editor-article-detail', commonEditorArticleDetail);
import commonLateX from '@/components/page/components/table/LateX.vue'
Vue.component('common-late-x', commonLateX);
import commonMajor from '@/components/page/components/major/index.vue'
Vue.component('common-major', commonMajor);
import commonMajorList from '@/components/page/components/major/list.vue'
Vue.component('common-major-list', commonMajorList);
import commonPayPalButton from '@/components/page/components/pendingPayment/PayPalButton.vue'
Vue.component('common-paypal-button', commonPayPalButton);
import commonTiff from '@/components/page/components/table/tiff.vue'
Vue.component('common-tiff', commonTiff);
import commonContent from '@/components/page/components/table/content.vue'
Vue.component('common-content', commonContent);
import commonWord from '@/components/page/components/table/word.vue'
Vue.component('common-comment', commonComment);
import commonEditTable from '@/components/page/components/table/editTable.vue'
Vue.component('common-edit-table', commonEditTable);
import commonComment from '@/components/page/components/table/comment.vue'
Vue.component('common-word', commonWord);
import commonAnnotations from '@/components/page/components/table/annotations.vue'
Vue.component('common-annotations', commonAnnotations);
import commonWordHtml from '@/components/page/components/table/wordHtml.vue'
Vue.component('common-word-html', commonWordHtml);
import commonWordHtmlTypesetting from '@/components/page/components/table/wordHtmlTypesetting.vue'
Vue.component('common-word-html-type-setting', commonWordHtmlTypesetting);
Object.keys(components).forEach(key => {
Vue.component(key, components[key]);
});
import commonDragWord from '@/components/page/components/table/dragWord.vue'
Vue.component('common-drag-word', commonDragWord);
Vue.use(VueI18n);
Vue.use(ElementUI, {
size: 'small',
@@ -228,22 +213,22 @@ const i18n = new VueI18n({
//使用钩子函数对路由进行权限跳转
router.beforeEach(async (to, from, next) => {
const currentRoute = to; // 获取当前路由路径,例如 "/home"
console.log('currentRoute at line 211:', currentRoute.meta)
if(currentRoute.meta.hideJournal){
}else{
try {
// 尝试请求接口(即使失败也继续后续逻辑)
await Promise.all([
loadJournalList(),
loadJournalType()
]);
} catch (err) {
// 仅打印错误,不阻断路由
}
if (currentRoute.meta.hideJournal) {
} else {
try {
// 尝试请求接口(即使失败也继续后续逻辑)
await Promise.all([
loadJournalList(),
loadJournalType()
]);
} catch (err) {
// 仅打印错误,不阻断路由
}
}
// 无论接口成功/失败,都执行原有跳转逻辑
document.title = `${to.meta.title} | Traditional Medicine Research`;