import request from '@/utils/request' // Java 后台接口 const javaApi = { // 小说相关接口 getNovelList: (params) => request({ url: '/java-api/novel/list', params }), getChapterContent: (chapterId) => request({ url: `/java-api/novel/chapter/${chapterId}` }), // 作家申请 applyAuthor: (data) => request({ url: '/java-api/author/apply', method: 'post', data }) } // PHP 后台接口 (预留) const phpApi = { getNovelList: (params) => request({ url: '/php-api/novel/list', params }), getChapterContent: (chapterId) => request({ url: `/php-api/novel/chapter/${chapterId}` }) } // 根据配置切换数据源 const usePhpApi = false; // 默认使用Java后台 export default { // 分类相关 getCategories() { return request({ url: '/api/novel/categories' }) }, // 小说相关 getHotNovels() { return request({ url: '/api/novel/hot' }) }, getNovelsByCategory(categoryId = 0) { return request({ url: '/api/novel/list', params: { categoryId } }) }, getChapters(novelId) { return request({ url: `/api/novel/${novelId}/chapters` }) }, getChapterContent(chapterId) { return request({ url: `/api/novel/chapter/${chapterId}` }) }, // 作家申请 applyAuthor(data) { return request({ url: '/api/author/apply', method: 'post', data }) }, // 上传相关(需要管理员权限) uploadNovel(file, title, authorId) { const formData = new FormData(); formData.append('file', file); formData.append('title', title); formData.append('authorId', authorId); return request({ url: '/admin/novel/upload', method: 'post', data: formData, headers: { 'Content-Type': 'multipart/form-data' } }) }, uploadChapter(file, novelId, chapterOrder) { const formData = new FormData(); formData.append('file', file); formData.append('novelId', novelId); if (chapterOrder) formData.append('chapterOrder', chapterOrder); return request({ url: '/admin/novel/chapter/upload', method: 'post', data: formData, headers: { 'Content-Type': 'multipart/form-data' } }) } getNovelList: usePhpApi ? phpApi.getNovelList : javaApi.getNovelList, getChapterContent: usePhpApi ? phpApi.getChapterContent : javaApi.getChapterContent, // 其他接口... applyAuthor: javaApi.applyAuthor, // 保存阅读进度 saveReadingProgress(chapter) { return request({ url: '/java-api/reading/progress', method: 'post', data: { chapter } }) }, // 获取阅读进度 getReadingProgress() { return request({ url: '/java-api/reading/progress', method: 'get' }) } }