From fc6210fb643cb199d9e58128d7cadb9e62983276 Mon Sep 17 00:00:00 2001
From: huliyong <2783385703@qq.com>
Date: Sat, 17 May 2025 11:09:50 +0800
Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=96=B0=E5=A2=9Efetch.js?=
=?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0api.js=E4=BB=A5=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=AF=B7=E6=B1=82=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
新增fetch.js用于统一处理API请求,支持数据转换和加载提示。更新api.js,添加新的模型和配置,优化登录和书架相关接口。同时更新config.js以引入fetch.js,并调整环境配置的baseUrl。
---
api/api.js | 8 ++-
api/fetch.js | 20 +++++++
api/model/bookshelf.js | 44 ++++++++++++++++
api/model/index.js | 112 ++++++++++++++++++++++++++++++++++++++++
api/model/login.js | 36 ++++++-------
config.js | 6 ++-
pages/index/category.vue | 132 ++++++++++-------------------------------------
pages/index/index.vue | 88 +++++++++++--------------------
8 files changed, 259 insertions(+), 187 deletions(-)
create mode 100644 api/fetch.js
create mode 100644 api/model/bookshelf.js
create mode 100644 api/model/index.js
diff --git a/api/api.js b/api/api.js
index 9c0590e..b293594 100644
--- a/api/api.js
+++ b/api/api.js
@@ -5,7 +5,7 @@ import utils from '../utils/utils.js'
let limit = {}
let debounce = {}
-const models = ['login']
+const models = ['login', 'index', 'bookshelf']
const config = {
// 示例
@@ -14,7 +14,11 @@ const config = {
// limit : 1000
// },
- getConfig : {url : '/config_common/getConfig', method : 'GET', limit : 500},
+ // 获取平台基础配置信息
+ getConfig: {
+ url: '/all_login/getConfig',
+ method: 'GET',
+ },
}
diff --git a/api/fetch.js b/api/fetch.js
new file mode 100644
index 0000000..6443777
--- /dev/null
+++ b/api/fetch.js
@@ -0,0 +1,20 @@
+import api from './api.js'
+
+const fetch = (key, data = {}, transform = true, loadingTitle) => {
+ return new Promise(resolve => {
+
+ const callback = (res) => {
+ if (!transform) {
+ resolve(res)
+ return
+ }
+ if (res.code == 200) {
+ resolve(res.result)
+ }
+ }
+
+ api(key, data, callback, loadingTitle)
+ })
+}
+
+export default fetch
diff --git a/api/model/bookshelf.js b/api/model/bookshelf.js
new file mode 100644
index 0000000..3e39305
--- /dev/null
+++ b/api/model/bookshelf.js
@@ -0,0 +1,44 @@
+// 书架相关接口
+
+const api = {
+ // 批量移除我阅读过的数据根据书籍标识
+ batchRemoveReadBook: {
+ url: '/all_book/batchRemoveReadBook',
+ method: 'GET',
+ auth: true,
+ },
+ // 获取我的作品带分页
+ getMyBookPage: {
+ url: '/all_book/getMyBookPage',
+ method: 'GET',
+ auth: true,
+ },
+ // 获取我阅读过的书籍列表带分页
+ getReadBookPage: {
+ url: '/all_book/getReadBookPage',
+ method: 'GET',
+ auth: true,
+ },
+ // 移除我阅读过的书籍根据书籍标识
+ removeReadBook: {
+ url: '/all_book/removeReadBook',
+ method: 'GET',
+ auth: true,
+ },
+ // 添加作品或者修改作品
+ saveOrUpdateBook: {
+ url: '/all_book/saveOrUpdateBook',
+ method: 'POST',
+ auth: true,
+ limit: 500,
+ showLoading: true,
+ },
+ // 增加或修改作品章节
+ saveOrUpdateCatalog: {
+ url: '/all_book/saveOrUpdateCatalog',
+ method: 'GET',
+ auth: true,
+ },
+}
+
+export default api
\ No newline at end of file
diff --git a/api/model/index.js b/api/model/index.js
new file mode 100644
index 0000000..3df5fb7
--- /dev/null
+++ b/api/model/index.js
@@ -0,0 +1,112 @@
+// 首页相关接口
+
+const api = {
+ // 批量订阅章节
+ batchSubscribeBookCatalog: {
+ url: '/all_index/batchSubscribeBookCatalog',
+ method: 'GET',
+ auth: true,
+ },
+ // 根据用户标识和书籍标识查询该用户的成就等级
+ getAchievement: {
+ url: '/all_index/getAchievement',
+ method: 'GET',
+ auth: true,
+ },
+ // 获取读者成就列表
+ getAchievementList: {
+ url: '/all_index/getAchievementList',
+ method: 'GET',
+ },
+ // 获取首页banner
+ getBanner: {
+ url: '/all_index/getBanner',
+ method: 'GET',
+ },
+ // 获取书城区域列表
+ getBookAreaList: {
+ url: '/all_index/getBookAreaList',
+ method: 'GET',
+ },
+ // 根据目录查询章节小说信息明细
+ getBookCatalogDetail: {
+ url: '/all_index/getBookCatalogDetail',
+ method: 'GET',
+ },
+ // 根据书本标识获取书本目录列表
+ getBookCatalogList: {
+ url: '/all_index/getBookCatalogList',
+ method: 'GET',
+ },
+ // 根据书本标识获取书本评论列表
+ getBookCommentList: {
+ url: '/all_index/getBookCommentList',
+ method: 'GET',
+ },
+ // 根据书本标识获取书本详细信息
+ getBookDetail: {
+ url: '/all_index/getBookDetail',
+ method: 'GET',
+ },
+ // 获取书城分类列表
+ getCategoryList: {
+ url: '/all_index/getCategoryList',
+ method: 'GET',
+ },
+ // 获取亲密度排行版
+ getIntimacyRankList: {
+ url: '/all_index/getIntimacyRankList',
+ method: 'GET',
+ },
+ // 获取首页最新小说列表带分页
+ getNewList: {
+ url: '/all_index/getNewList',
+ method: 'GET',
+ },
+ // 获取首页公告
+ getNotice: {
+ url: '/all_index/getNotice',
+ method: 'GET',
+ },
+ // 获取公告详情
+ getNoticeById: {
+ url: '/all_index/getNoticeById',
+ method: 'GET',
+ },
+ // 获取公告列表带分页
+ getNoticePage: {
+ url: '/all_index/getNoticePage',
+ method: 'GET',
+ },
+ // 获取首页精品推荐小说列表带分页
+ getRecommendList: {
+ url: '/all_index/getRecommendList',
+ method: 'GET',
+ },
+ // 观看视频之后开启章节
+ openBookCatalog: {
+ url: '/all_index/openBookCatalog',
+ method: 'GET',
+ auth: true,
+ },
+ // 设置读者成就等级名称
+ setAchievementName: {
+ url: '/all_index/setAchievementName',
+ method: 'GET',
+ auth: true,
+ },
+ // 订阅章节
+ subscribeBook: {
+ url: '/all_index/subscribeBook',
+ method: 'GET',
+ auth: true,
+ },
+ // 根据书本标识进行投票
+ vote: {
+ url: '/all_index/vote',
+ method: 'GET',
+ auth: true,
+ },
+}
+
+export default api
\ No newline at end of file
diff --git a/api/model/login.js b/api/model/login.js
index c818a04..7ea631c 100644
--- a/api/model/login.js
+++ b/api/model/login.js
@@ -1,35 +1,33 @@
-
-
// 登录相关接口
const api = {
- // 微信登录接口
+ // 微信小程序授权登录
wxLogin: {
- url: '/login_common/appletLogin',
+ url: '/all_login/appletLogin',
method: 'GET',
- limit : 500,
- showLoading : true,
+ limit: 500,
+ showLoading: true,
},
- // 获取绑定手机号码
+ // 绑定手机号码
bindPhone: {
- url: '/login_common/bindPhone',
+ url: '/all_login/bindPhone',
method: 'GET',
auth: true,
},
- // 修改个人信息接口
- updateInfo: {
- url: '/info_common/updateInfo',
- method: 'POST',
- auth: true,
- limit : 500,
- showLoading : true,
- },
- // 获取个人信息
- getInfo: {
- url: '/info_common/getInfo',
+ // 获取用户信息
+ getUserInfo: {
+ url: '/all_login/getUserByToken',
method: 'GET',
auth: true,
},
+ // 更新用户信息
+ updateUserInfo: {
+ url: '/all_login/updateUserInfo',
+ method: 'POST',
+ auth: true,
+ limit: 500,
+ showLoading: true,
+ },
}
export default api
\ No newline at end of file
diff --git a/config.js b/config.js
index 4175d2b..b7ab4a5 100644
--- a/config.js
+++ b/config.js
@@ -1,6 +1,7 @@
import Vue from 'vue'
import api from '@/api/api.js'
+import fetch from '@/api/fetch.js'
import utils from './utils/utils.js'
import uvUI from '@/uni_modules/uv-ui-tools'
@@ -13,10 +14,10 @@ const type = 'dev'
// 环境配置
const config = {
dev : {
- baseUrl : 'http://www.gcosc.fun:82',
+ baseUrl : 'http://h5.xzaiyp.top/novel-admin',
},
prod : {
- baseUrl : 'http://xxx.xxx.xxx/xxx',
+ baseUrl : 'https://prod-api.budingxiaoshuo.com/novel-admin',
}
}
@@ -52,5 +53,6 @@ uni.$uv.setConfig({
Vue.prototype.$config = utils.deepMergeObject(defaultConfig, config[type])
Vue.prototype.$api = api
+Vue.prototype.$fetch = fetch
export default Vue.prototype.$config
\ No newline at end of file
diff --git a/pages/index/category.vue b/pages/index/category.vue
index 8c80794..2d9ed6c 100644
--- a/pages/index/category.vue
+++ b/pages/index/category.vue
@@ -4,8 +4,7 @@
+ />
@@ -55,8 +57,9 @@
} from 'vuex'
import tabber from '@/components/base/tabbar.vue'
import novelItem from '@/components/novel/novelItem.vue'
+ import mixinsList from '@/mixins/list.js'
export default {
- // mixins: [mixinsList],
+ mixins: [mixinsList],
components: {
tabber,
novelItem
@@ -66,76 +69,8 @@
mixinsListApi: '',
current : 0,
currentChildren : 0,
- categoryList: {
- shopList: [
- {
- id: '1',
- title: '我是半妖',
- cover: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=facearea&w=400&h=400',
- author: '东方不败',
- desc: '这是一部关于半妖少年成长的玄幻小说,讲述了主角在人妖两界的冒险故事。',
- tags: ['玄幻', '冒险', '热血'],
- status: '连载中'
- },
- {
- id: '2',
- title: '兽王进化',
- cover: 'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?auto=format&fit=facearea&w=400&h=400',
- author: '天下霸唱',
- desc: '一场意外让主角获得兽王血脉,开始了进化之路...',
- tags: ['奇幻', '冒险'],
- status: '连载中'
- },
- {
- id: '3',
- title: '魔法少女纯爷们',
- cover: 'https://images.unsplash.com/photo-1465101046530-73398c7f28ca?auto=format&fit=facearea&w=400&h=400',
- author: '南派三叔',
- desc: '一个普通男孩意外获得魔法少女的力量,开始了奇妙冒险...',
- tags: ['搞笑', '奇幻'],
- status: '已完结'
- }
- ]
- },
- category: [
- {
- id: '1',
- name: '男生',
- children: [
- { id: '101', name: '玄幻' },
- { id: '102', name: '奇幻' },
- { id: '103', name: '武侠' },
- { id: '104', name: '仙侠' },
- { id: '105', name: '都市' },
- { id: '106', name: '历史' },
- { id: '107', name: '军事' },
- { id: '108', name: '游戏' },
- { id: '109', name: '体育' }
- ]
- },
- {
- id: '2',
- name: '女生',
- children: [
- { id: '201', name: '古代言情' },
- { id: '202', name: '现代言情' },
- { id: '203', name: '幻想言情' },
- { id: '204', name: '青春校园' },
- { id: '205', name: '纯爱' }
- ]
- },
- {
- id: '3',
- name: '出版',
- children: [
- { id: '301', name: '文学' },
- { id: '302', name: '传记' },
- { id: '303', name: '励志' },
- { id: '304', name: '名著' },
- { id: '305', name: '经管' }
- ]
- }
- ]
+ categoryList: [],
+ category: [],
}
},
computed: {
@@ -184,49 +119,34 @@
// // this.queryParams.classId = this.category[0].id
// }
},
+ onShow() {
+ this.getCategoryList()
+ this.getBookAreaList()
+ },
methods: {
change(e) {
// this.queryParams.classId = this.category[e].id
this.currentChildren = e
// 更新对应分类的书籍列表
- this.updateBookList(this.category[this.current].children[e].id)
+ this.getData(this.category[this.current].children[e].id)
},
clickTabs({index}){
this.current = index
this.currentChildren = 0
// 更新对应分类的书籍列表
- this.updateBookList(this.category[index].children[0].id)
- },
- updateBookList(categoryId) {
- // 模拟获取不同分类的书籍数据
- // 实际项目中应该调用API获取数据
- console.log('获取分类ID为: ' + categoryId + ' 的书籍')
-
- // 这里只是简单模拟不同分类有不同数量的书
- const bookCount = Math.floor(Math.random() * 3) + 1
- const tempList = []
-
- for (let i = 0; i < bookCount; i++) {
- tempList.push({
- id: categoryId + '-' + i,
- title: '分类' + categoryId + '的书' + i,
- cover: 'https://images.unsplash.com/photo-1506744038136-46273834b3fb?auto=format&fit=facearea&w=400&h=400',
- author: '作者' + categoryId,
- desc: '这是分类' + categoryId + '的第' + i + '本书...',
- tags: ['分类' + categoryId, '热门'],
- status: i % 2 === 0 ? '连载中' : '已完结'
- })
- }
-
- this.categoryList.shopList = tempList
+ this.getData(this.category[index].children[0].id)
},
search(){
- for(let i = 0;i < 10;i++){
- delete this.queryParams[i]
- }
- this.queryParams.pageSize = 10
this.getData()
},
+ async getCategoryList() {
+ const data = await this.$fetch('getCategoryList')
+ this.category = data
+ },
+ async getBookAreaList() {
+ const data = await this.$fetch('getBookAreaList')
+ this.categoryList = data
+ },
}
}
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 12750bd..a8833bd 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -61,9 +61,9 @@
- 通讯
+ {{noticeList.title}}
- 2025年2月平台福利活动截稿作品公示
+ {{ noticeList.titleText }}
@@ -114,6 +114,7 @@
import PrivacyAgreementPoup from '@/components/config/PrivacyAgreementPoup.vue'
import tabber from '@/components/base/tabbar.vue'
import novelItem from '@/components/novel/novelItem.vue'
+ import mixinsList from '@/mixins/list.js'
import {
mapGetters
} from 'vuex'
@@ -123,68 +124,25 @@
PrivacyAgreementPoup,
novelItem,
},
+ mixins: [mixinsList],
data() {
return {
// 轮播图数据
- bannerList: [
- {
- id: '3',
- image: 'https://img95.699pic.com/photo/50055/5909.jpg_wh300.jpg',
- title: '我有一座妖怪城',
- desc: '妖怪横行,一座神秘古城,藏着千年秘密'
- }
- ],
- // 小说列表数据
- novelList: [
- {
- id: '1',
- title: '我是半妖',
- cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
- author: '东方不败',
- desc: '都市玄幻小说,主角获得半妖化能力,通过吸收妖气不断变强...',
- tags: ['玄幻', '都市', '热血'],
- status: '连载中'
- },
- {
- id: '2',
- title: '兽王进化',
- cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
- author: '天下霸唱',
- desc: '一场意外让主角获得兽王血脉,开始了进化之路...',
- tags: ['奇幻', '冒险'],
- status: '连载中'
- },
- {
- id: '3',
- title: '魔法少女纯爷们',
- cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
- author: '南派三叔',
- desc: '一个普通男孩意外获得魔法少女的力量,开始了奇妙冒险...',
- tags: ['搞笑', '奇幻'],
- status: '已完结'
- },
- {
- id: '4',
- title: '我是一条小青龙',
- cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
- author: '辰东',
- desc: '重生为一条小青龙,主角在修仙世界中成长的故事...',
- tags: ['仙侠', '修真'],
- status: '连载中'
- },
- {
- id: '5',
- title: '女帝归来',
- cover: 'https://tse4-mm.cn.bing.net/th/id/OIP-C.iUyxJ_fxLjjX3kEBjteXWwAAAA?rs=1&pid=ImgDetMain',
- author: '猫腻',
- desc: '曾经的女帝重生归来,开始了复仇之路...',
- tags: ['古代', '女强'],
- status: '连载中'
- }
- ]
+ bannerList: [],
+ // 最近更新小说列表数据
+ novelList: [],
+ // 公告数据
+ noticeList: {},
+ // 精品小说列表
+ mixinsListApi : 'getRecommendList',
}
},
computed: {},
+ onShow() {
+ this.getBanner()
+ this.getNotice()
+ this.getNewList()
+ },
methods: {
// 跳转到搜索页面
toSearch() {
@@ -213,6 +171,20 @@
// 跳转到小说详情页
this.$utils.navigateTo(`/pages_order/novel/novelDetail?id=${id}`)
},
+ async getBanner() {
+ const data = await this.$fetch('getBanner')
+ this.bannerList = data
+ },
+ // 获取公告列表
+ async getNotice() {
+ const data = await this.$fetch('getNotice')
+ this.noticeList = data
+ },
+ // 获取最近更新小说列表
+ async getNewList() {
+ const data = await this.$fetch('getNewList')
+ this.novelList = data
+ },
}
}