| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import request from '@/utils/request'
- // Java 后台接口
- const javaApi = {
- // 小说相关接口
- getNovelList: (params) => request({ url: '/novel/list', params }),
- getChapterContent: (chapterId) => request({ url: `/novel/chapter/${chapterId}` }),
-
- // 作家申请
- applyAuthor: (data) => request({ url: '/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: '/reading/progress',
- method: 'post',
- data: { chapter }
- })
- },
-
- // 获取阅读进度
- getReadingProgress() {
- return request({
- url: '/reading/progress',
- method: 'get'
- })
- }
- }
|