Browse Source

feat(api): 新增fetch.js并更新api.js以支持统一请求处理

新增fetch.js用于统一处理API请求,支持数据转换和加载提示。更新api.js,添加新的模型和配置,优化登录和书架相关接口。同时更新config.js以引入fetch.js,并调整环境配置的baseUrl。
master
前端-胡立永 3 weeks ago
parent
commit
fc6210fb64
8 changed files with 259 additions and 187 deletions
  1. +6
    -2
      api/api.js
  2. +20
    -0
      api/fetch.js
  3. +44
    -0
      api/model/bookshelf.js
  4. +112
    -0
      api/model/index.js
  5. +17
    -19
      api/model/login.js
  6. +4
    -2
      config.js
  7. +26
    -106
      pages/index/category.vue
  8. +30
    -58
      pages/index/index.vue

+ 6
- 2
api/api.js View File

@ -5,7 +5,7 @@ import utils from '../utils/utils.js'
let limit = {} let limit = {}
let debounce = {} let debounce = {}
const models = ['login']
const models = ['login', 'index', 'bookshelf']
const config = { const config = {
// 示例 // 示例
@ -14,7 +14,11 @@ const config = {
// limit : 1000 // limit : 1000
// }, // },
getConfig : {url : '/config_common/getConfig', method : 'GET', limit : 500},
// 获取平台基础配置信息
getConfig: {
url: '/all_login/getConfig',
method: 'GET',
},
} }


+ 20
- 0
api/fetch.js View File

@ -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

+ 44
- 0
api/model/bookshelf.js View File

@ -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

+ 112
- 0
api/model/index.js View File

@ -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

+ 17
- 19
api/model/login.js View File

@ -1,35 +1,33 @@
// 登录相关接口 // 登录相关接口
const api = { const api = {
// 微信登录接口
// 微信小程序授权登录
wxLogin: { wxLogin: {
url: '/login_common/appletLogin',
url: '/all_login/appletLogin',
method: 'GET', method: 'GET',
limit : 500,
showLoading : true,
limit: 500,
showLoading: true,
}, },
// 获取绑定手机号码
// 绑定手机号码
bindPhone: { bindPhone: {
url: '/login_common/bindPhone',
url: '/all_login/bindPhone',
method: 'GET', method: 'GET',
auth: true, 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', method: 'GET',
auth: true, auth: true,
}, },
// 更新用户信息
updateUserInfo: {
url: '/all_login/updateUserInfo',
method: 'POST',
auth: true,
limit: 500,
showLoading: true,
},
} }
export default api export default api

+ 4
- 2
config.js View File

@ -1,6 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import api from '@/api/api.js' import api from '@/api/api.js'
import fetch from '@/api/fetch.js'
import utils from './utils/utils.js' import utils from './utils/utils.js'
import uvUI from '@/uni_modules/uv-ui-tools' import uvUI from '@/uni_modules/uv-ui-tools'
@ -13,10 +14,10 @@ const type = 'dev'
// 环境配置 // 环境配置
const config = { const config = {
dev : { dev : {
baseUrl : 'http://www.gcosc.fun:82',
baseUrl : 'http://h5.xzaiyp.top/novel-admin',
}, },
prod : { 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.$config = utils.deepMergeObject(defaultConfig, config[type])
Vue.prototype.$api = api Vue.prototype.$api = api
Vue.prototype.$fetch = fetch
export default Vue.prototype.$config export default Vue.prototype.$config

+ 26
- 106
pages/index/category.vue View File

@ -4,8 +4,7 @@
<navbar title="书城" <navbar title="书城"
leftClick leftClick
@leftClick="$utils.navigateBack" @leftClick="$utils.navigateBack"
bgColor="#E3441A"
color="#fff" />
/>
<!-- 分类商品列表 --> <!-- 分类商品列表 -->
<view class="category" <view class="category"
@ -14,20 +13,23 @@
<view class="tabs"> <view class="tabs">
<uv-tabs <uv-tabs
:list="category" :list="category"
:activeStyle="{color : '#f00', fontWeight : 600}"
lineColor="#f00"
:activeStyle="{color : '#0A2463', fontWeight : 600}"
lineColor="#0A2463"
:inactiveStyle="{color: 'rgba(0,0,0,.8)'}" :inactiveStyle="{color: 'rgba(0,0,0,.8)'}"
lineHeight="8rpx" lineHeight="8rpx"
lineWidth="50rpx" lineWidth="50rpx"
:current="current" :current="current"
keyName="title"
@click="clickTabs"></uv-tabs> @click="clickTabs"></uv-tabs>
</view> </view>
<uv-vtabs <uv-vtabs
:list="category[current].children"
:list="categoryList"
:current="currentChildren" :current="currentChildren"
keyName="name"
keyName="title"
:chain="false" :chain="false"
:barItemActiveLineStyle="{background : '#0A2463'}"
:barItemActiveStyle="{color : '#0A2463', fontWeight : 600}"
@change="change"> @change="change">
<uv-vtabs-item> <uv-vtabs-item>
<view class="category-item"> <view class="category-item">
@ -55,8 +57,9 @@
} from 'vuex' } from 'vuex'
import tabber from '@/components/base/tabbar.vue' import tabber from '@/components/base/tabbar.vue'
import novelItem from '@/components/novel/novelItem.vue' import novelItem from '@/components/novel/novelItem.vue'
import mixinsList from '@/mixins/list.js'
export default { export default {
// mixins: [mixinsList],
mixins: [mixinsList],
components: { components: {
tabber, tabber,
novelItem novelItem
@ -66,76 +69,8 @@
mixinsListApi: '', mixinsListApi: '',
current : 0, current : 0,
currentChildren : 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: { computed: {
@ -184,49 +119,34 @@
// // this.queryParams.classId = this.category[0].id // // this.queryParams.classId = this.category[0].id
// } // }
}, },
onShow() {
this.getCategoryList()
this.getBookAreaList()
},
methods: { methods: {
change(e) { change(e) {
// this.queryParams.classId = this.category[e].id // this.queryParams.classId = this.category[e].id
this.currentChildren = e this.currentChildren = e
// //
this.updateBookList(this.category[this.current].children[e].id)
this.getData(this.category[this.current].children[e].id)
}, },
clickTabs({index}){ clickTabs({index}){
this.current = index this.current = index
this.currentChildren = 0 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(){ search(){
for(let i = 0;i < 10;i++){
delete this.queryParams[i]
}
this.queryParams.pageSize = 10
this.getData() this.getData()
}, },
async getCategoryList() {
const data = await this.$fetch('getCategoryList')
this.category = data
},
async getBookAreaList() {
const data = await this.$fetch('getBookAreaList')
this.categoryList = data
},
} }
} }
</script> </script>


+ 30
- 58
pages/index/index.vue View File

@ -61,9 +61,9 @@
</view> </view>
</view> </view>
<view class="notice-center"> <view class="notice-center">
<view class="notice-tag">通讯</view>
<view class="notice-tag">{{noticeList.title}}</view>
<view class="notice-text" @click="viewNotice"> <view class="notice-text" @click="viewNotice">
2025年2月平台福利活动截稿作品公示
{{ noticeList.titleText }}
</view> </view>
</view> </view>
<view class="notice-right"> <view class="notice-right">
@ -114,6 +114,7 @@
import PrivacyAgreementPoup from '@/components/config/PrivacyAgreementPoup.vue' import PrivacyAgreementPoup from '@/components/config/PrivacyAgreementPoup.vue'
import tabber from '@/components/base/tabbar.vue' import tabber from '@/components/base/tabbar.vue'
import novelItem from '@/components/novel/novelItem.vue' import novelItem from '@/components/novel/novelItem.vue'
import mixinsList from '@/mixins/list.js'
import { import {
mapGetters mapGetters
} from 'vuex' } from 'vuex'
@ -123,68 +124,25 @@
PrivacyAgreementPoup, PrivacyAgreementPoup,
novelItem, novelItem,
}, },
mixins: [mixinsList],
data() { data() {
return { 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: {}, computed: {},
onShow() {
this.getBanner()
this.getNotice()
this.getNewList()
},
methods: { methods: {
// //
toSearch() { toSearch() {
@ -213,6 +171,20 @@
// //
this.$utils.navigateTo(`/pages_order/novel/novelDetail?id=${id}`) 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
},
} }
} }
</script> </script>


Loading…
Cancel
Save