优化:请求接口全局处理loading和错误提示

This commit is contained in:
2025-11-26 16:37:47 +08:00
24 changed files with 568 additions and 771 deletions

View File

@@ -34,7 +34,7 @@ export function responseInterceptor(res: UniApp.RequestSuccessCallbackResult) {
}
// 可能为字符串,尝试解析(原项目也做了类似处理)
let httpData: IApiResponse | string = res.data as any;
let httpData: IApiResponse | string = res.data;
if (typeof httpData === 'string') {
try {
httpData = JSON.parse(httpData);
@@ -44,19 +44,20 @@ export function responseInterceptor(res: UniApp.RequestSuccessCallbackResult) {
}
// 规范化 message 字段
const message = (httpData as any).msg || (httpData as any).message || (httpData as any).errMsg || '';
const message = (httpData as IApiResponse).msg || (httpData as IApiResponse).message || (httpData as IApiResponse).errMsg || '';
// 成功判断:与原项目一致的条件
const successFlag = (httpData as any).success === true || (httpData as any).code === 0;
const code = (httpData as IApiResponse).code;
// 成功判断
const successFlag = (httpData as IApiResponse).success === true || code === 0;
if (successFlag) {
// 返回原始 httpData(与原项目 dataFactory 返回 Promise.resolve(httpData) 保持一致)
// 但大多数调用者更关心 data 字段,这里返回整个 httpData调用者可取 .data
// 返回原始 httpData
// 实际数据每个接口不同,调用者需根据实际情况取 .data 字段
return Promise.resolve(httpData);
}
// 登录失效或需要强制登录的一些 code(与原项目一致)
const code = (httpData as any).code;
// 登录失效或需要强制登录的一些 code
if (code === '401' || code === 401) {
// 触发登出流程
handleAuthExpired();
@@ -64,7 +65,7 @@ export function responseInterceptor(res: UniApp.RequestSuccessCallbackResult) {
}
// 原项目还将 1000,1001,1100,402 等视作需要强制登录
if (code === '1000' || code === '1001' || code === 1000 || code === 1001 || code === 1100 || code === '402' || code === 402) {
if (code == 1000 || code == 1001 || code === 1100 || code === 402) {
handleAuthExpired();
return Promise.reject({ statusCode: 0, errMsg: message || t('global.loginExpired'), data: httpData });
}

View File

@@ -254,3 +254,15 @@ export async function getActivityDescription() {
})
return res
}
/**
* 获取充值列表
*/
export async function getTransactionDetailsList(current: number, limit: number, userId: string,) {
const res = await mainClient.request<IApiResponse>({
url: 'common/transactionDetails/getTransactionDetailsList',
method: 'POST',
data: { current, limit, userId, }
})
return res
}

View File

@@ -8,6 +8,7 @@ import { t } from '@/utils/i18n'
export function createRequestClient(cfg: ICreateClientConfig) {
const baseURL = cfg.baseURL;
const timeout = cfg.timeout ?? REQUEST_TIMEOUT;
let reqCount= 0
async function request<T = any>(options: IRequestOptions): Promise<T> {
// 组装 final options
@@ -23,14 +24,18 @@ export function createRequestClient(cfg: ICreateClientConfig) {
// 全局处理请求 loading
const loading = !cfg.loading ? true : cfg.loading // 接口请求参数不传loading默认显示loading
loading && uni.showLoading()
if (loading) {
uni.showLoading({ mask: true })
reqCount++
}
return new Promise((resolve, reject) => {
uni.request({
...intercepted,
complete() {
// 请求完成关闭 loading
loading && uni.hideLoading()
loading && reqCount--
reqCount <= 0 && uni.hideLoading()
},
success(res: any) {
// 委托给响应拦截器处理

View File

@@ -90,7 +90,7 @@
<text class="label">{{ $t('order.total') }}</text>
<text class="amount">{{ finalAmount }} {{ t('global.coin') }}</text>
</view>
<wd-button type="primary" :loading="submitting" @click="handleSubmit">
<wd-button type="primary" @click="handleSubmit">
{{ $t('order.submit') }}
</wd-button>
</view>
@@ -170,12 +170,7 @@ const getDiscountParams = (goodsList: IGoods[]) => {
}))
}
// 支付相关
// UI状态
const submitting = ref(false)
// 监听商品列表变化,更新价格
watch(() => props.goodsList, () => {
getDiscountParams(props.goodsList)
// 初始化价格
@@ -222,24 +217,16 @@ const calculateTotalPrice = () => {
* 计算VIP优惠
*/
const calculateVipDiscounted = async () => {
try {
const res = await orderApi.getVipDiscountAmount(goodsListParams.value)
vipDiscounted.value = res.discountAmount
} catch (error) {
console.error('获取VIP优惠失败:', error)
}
}
/**
* 计算活动优惠
*/
const calculatePromotionDiscounted = async () => {
try {
const res = await orderApi.getDistrictAmount(goodsListParams.value)
promotionDiscounted.value = res.districtAmount
} catch (error) {
console.error('获取地区优惠失败:', error)
}
}
/**
@@ -364,20 +351,9 @@ const validateOrder = (): boolean => {
* 提交订单
*/
const handleSubmit = async () => {
if (submitting.value) {
uni.showToast({
title: t('order.tooFrequent'),
icon: 'none'
})
return
}
// 验证订单
if (!validateOrder()) return
try {
submitting.value = true
// 创建订单 此app用天医币支付创建订单成功即支付成功
await createOrder()
@@ -385,23 +361,12 @@ const handleSubmit = async () => {
title: t('order.orderSuccess'),
icon: 'success'
})
} catch (error) {
console.error('提交订单失败:', error)
uni.showToast({
title: t('order.orderFailed'),
icon: 'none'
})
} finally {
submitting.value = false
}
}
/**
* 创建订单
*/
const createOrder = async (): Promise<string | null> => {
try {
const orderParams = {
userId: props.userInfo.id,
paymentMethod: 4, // 天医币
@@ -424,10 +389,6 @@ const createOrder = async (): Promise<string | null> => {
return res.orderSn
}
return null
} catch (error) {
console.error('下单失败:', error)
throw error
}
}
</script>

View File

@@ -208,7 +208,8 @@
"seasonCard": "Quarterly",
"yearCard": "Yearly",
"days": "days",
"selectPackage": "Please select a package"
"selectPackage": "Please select a package",
"consumptionRecord": "Consumption record"
},
"book": {
"title": "My Books",
@@ -467,6 +468,11 @@
"couponType0": "All Products",
"couponType1": "Specific Courses",
"couponType2": "Course Categories",
"couponCount": "{count} coupons"
"couponCount": "{count} coupons",
"rechargeConsumptionList": "Recharge and consumption records",
"rechargeAmount": "Recharge amount",
"valueAddedServices": "Value-added services",
"readAgree": "I have read and agreed",
"readAgreeServices": "Please read and agree to the value-added services first"
}
}

View File

@@ -209,7 +209,8 @@
"seasonCard": "季卡",
"yearCard": "年卡",
"days": "天",
"selectPackage": "请选择套餐"
"selectPackage": "请选择套餐",
"consumptionRecord": "消费记录"
},
"book": {
"title": "我的书单",
@@ -468,6 +469,11 @@
"couponType0": "全场通用",
"couponType1": "指定课程可用",
"couponType2": "指定课程品类可用",
"couponCount": "共 {count} 张"
"couponCount": "共 {count} 张",
"rechargeConsumptionList": "充值消费记录",
"rechargeAmount": "充值金额",
"valueAddedServices": "增值服务",
"readAgree": "我已阅读并同意",
"readAgreeServices": "请先阅读并同意增值服务"
}
}

View File

@@ -230,71 +230,44 @@ function initScrollHeight() {
// 加载书籍详情
async function loadBookInfo() {
try {
const res = await bookApi.getBookInfo(bookId.value)
if (res.bookInfo) {
bookInfo.value = res.bookInfo
}
} catch (error) {
console.error('Failed to load book info:', error)
}
}
// 加载购买商品信息
async function loadGoodsInfo() {
try {
const res = await bookApi.getBookGoods(bookId.value)
if (res.code === 0) {
goodsList.value = res.productList || []
}
} catch (error) {
console.error('Failed to load goods info:', error)
}
}
// 加载统计数据
async function loadBookCount() {
try {
const res = await bookApi.getBookReadCount(bookId.value)
if (res.code === 0) {
readCount.value = res.readCount || 0
listenCount.value = res.listenCount || 0
buyCount.value = res.buyCount || 0
}
} catch (error) {
console.error('Failed to load book count:', error)
}
}
// 加载评论
async function loadComments() {
try {
const res = await bookApi.getBookComments(bookId.value, 1, 10)
if (res.commentsTree && res.commentsTree.length > 0) {
commentList.value = res.commentsTree
} else {
nullText.value = t('common.data_null')
}
} catch (error) {
nullText.value = t('common.data_null')
console.error('Failed to load comments:', error)
}
}
// 加载推荐书籍
async function loadRecommendBooks() {
try {
const res = await bookApi.getRecommendBook(bookId.value)
if (res.bookList && res.bookList.length > 0) {
relatedBooks.value = res.bookList
} else {
nullBookText.value = t('common.data_null')
}
} catch (error) {
nullBookText.value = t('common.data_null')
console.error('Failed to load recommend books:', error)
}
}
// 显示购买弹窗

View File

@@ -219,21 +219,16 @@ const vipInfo = ref<IVipInfo | null>(null)
* 获取VIP信息
*/
const getVipInfo = async () => {
try {
const res = await homeApi.getVipInfo()
if (res.vipInfo) {
vipInfo.value = res.vipInfo
}
} catch (error) {
console.error('获取VIP信息失败:', error)
}
}
/**
* 获取我的书单
*/
const getMyBooks = async () => {
try {
const res = await homeApi.getMyBooks(1, 10)
if (res && res.code === 0) {
showMyBooks.value = true
@@ -246,30 +241,22 @@ const getMyBooks = async () => {
url: '/pages/login/login'
})
}
} catch (error) {
console.error('获取我的书单失败:', error)
}
}
/**
* 获取推荐图书
*/
const getRecommendBooks = async () => {
try {
const res = await homeApi.getRecommendBooks()
if (res.books && res.books.length > 0) {
recommendBooksList.value = res.books
}
} catch (error) {
console.error('获取推荐图书失败:', error)
}
}
/**
* 获取活动标签列表
*/
const getActivityLabels = async () => {
try {
const res = await homeApi.getBookLabelList(1)
showActivity.value = true
if (res.lableList && res.lableList.length > 0) {
@@ -277,16 +264,12 @@ const getActivityLabels = async () => {
// 默认加载第一个标签的图书列表
await getBooksByLabel(res.lableList[0].id, 'activity')
}
} catch (error) {
console.error('获取活动标签失败:', error)
}
}
/**
* 获取分类标签列表
*/
const getCategoryLabels = async () => {
try {
const res = await homeApi.getBookLabelList(0)
showCategory.value = true
if (res.lableList && res.lableList.length > 0) {
@@ -294,16 +277,12 @@ const getCategoryLabels = async () => {
// 默认加载第一个标签的二级标签
await getSubLabels(res.lableList[0].id, 0)
}
} catch (error) {
console.error('获取分类标签失败:', error)
}
}
/**
* 获取二级标签列表
*/
const getSubLabels = async (pid: number, index: number) => {
try {
const res = await homeApi.getSubLabelList(pid)
currentLevel1Index.value = index
if (res.lableList && res.lableList.length > 0) {
@@ -316,9 +295,6 @@ const getSubLabels = async (pid: number, index: number) => {
categoryLevel2List.value = []
await getBooksByLabel(pid, 'category')
}
} catch (error) {
console.error('获取二级标签失败:', error)
}
}
/**
@@ -328,7 +304,6 @@ const getBooksByLabel = async (
labelId: number,
type: 'activity' | 'category'
) => {
try {
const res = await homeApi.getBooksByLabel(labelId)
if (type === 'activity') {
if (res.bookList && res.bookList.length > 0) {
@@ -343,9 +318,6 @@ const getBooksByLabel = async (
categoryBookList.value = []
}
}
} catch (error) {
console.error('获取图书列表失败:', error)
}
}
/**

View File

@@ -117,19 +117,12 @@ function initScrollHeight() {
// 加载书籍信息
async function loadBookInfo() {
try {
const res = await bookApi.getBookInfo(bookId.value)
if (res.bookInfo) {
bookInfo.value = res.bookInfo
}
} catch (error) {
console.error('Failed to load book info:', error)
}
}
// 加载章节列表
async function loadChapterList() {
try {
const res = await bookApi.getBookChapter({
bookId: bookId.value
})
@@ -139,10 +132,6 @@ async function loadChapterList() {
} else {
nullText.value = t('common.data_null')
}
} catch (error) {
nullText.value = t('common.data_null')
console.error('Failed to load chapter list:', error)
}
}
// 播放章节

View File

@@ -245,15 +245,9 @@ function initAudioContext() {
// 加载书籍信息
async function loadBookInfo() {
try {
const res = await bookApi.getBookInfo(bookId.value)
if (res.bookInfo) {
bookInfo.value = res.bookInfo
}
} catch (error) {
console.error('Failed to load book info:', error)
}
}
// 加载章节列表
async function loadChapterList() {

View File

@@ -164,14 +164,10 @@ function initScrollHeight() {
// 加载书籍信息
async function loadBookInfo() {
try {
const res = await bookApi.getBookInfo(bookId.value)
if (res.bookInfo) {
bookInfo.value = res.bookInfo
}
} catch (error) {
console.error('Failed to load book info:', error)
}
}
// 加载评论列表
@@ -180,7 +176,6 @@ async function loadComments() {
return
}
try {
const res = await bookApi.getBookComments(bookId.value, page.value.current, page.value.limit)
commentsCount.value = res.commentsCount || 0
@@ -191,10 +186,6 @@ async function loadComments() {
} else if (commentList.value.length === 0) {
nullText.value = t('common.data_null')
}
} catch (error) {
nullText.value = t('common.data_null')
console.error('Failed to load comments:', error)
}
}
// 加载更多
@@ -275,7 +266,6 @@ function handleEmj(i: any) {
// 提交评论
async function submitComment() {
try {
const content = await getEditorContent()
if (!content || content === '<p><br></p>') {
@@ -299,9 +289,6 @@ async function submitComment() {
editorCtx.value?.clear()
resetComments()
}, 500)
} catch (error) {
console.error('Failed to submit comment:', error)
}
}
// 点赞/取消点赞
@@ -314,7 +301,6 @@ async function handleLike(comment: IComment) {
return
}
try {
if (comment.isLike === 0) {
await bookApi.likeComment(comment.id)
uni.showToast({
@@ -334,9 +320,6 @@ async function handleLike(comment: IComment) {
setTimeout(() => {
resetComments()
}, 200)
} catch (error) {
console.error('Failed to like comment:', error)
}
}
// 删除评论
@@ -348,7 +331,6 @@ function handleDelete(comment: IComment) {
confirmText: t('common.confirm_text'),
success: async (res) => {
if (res.confirm) {
try {
await bookApi.deleteComment(comment.id)
uni.showToast({
title: t('bookDetails.deleteSuccess'),
@@ -359,9 +341,6 @@ function handleDelete(comment: IComment) {
setTimeout(() => {
resetComments()
}, 500)
} catch (error) {
console.error('Failed to delete comment:', error)
}
}
}
})

View File

@@ -70,15 +70,9 @@ onLoad((options: any) => {
* 获取VIP信息
*/
const getVipInfo = async () => {
try {
const res = await homeApi.getVipInfo()
if (res.vipInfo) {
vipInfo.value = res.vipInfo
}
} catch (error) {
console.error('获取VIP信息失败:', error)
}
}
/**
* 处理搜索
@@ -91,7 +85,6 @@ const handleSearch = async () => {
loading.value = true
isEmpty.value = false
try {
const res = await homeApi.searchBooks({
title: keyword.value.trim(),
page: 1,
@@ -104,14 +97,8 @@ const handleSearch = async () => {
searchResults.value = []
isEmpty.value = true
}
} catch (error) {
console.error('搜索失败:', error)
searchResults.value = []
isEmpty.value = true
} finally {
loading.value = false
}
}
/**
* 处理清空

View File

@@ -164,7 +164,6 @@ onLoad((options: any) => {
* 加载章节详情
*/
const loadChapterDetail = async () => {
try {
const res = await courseApi.getChapterDetail(chapterId.value)
if (res.code === 0 && res.data) {
chapterDetail.value = res.data.detail
@@ -179,9 +178,6 @@ const loadChapterDetail = async () => {
}
}
}
} catch (error) {
console.error('加载章节详情失败:', error)
}
}
/**

View File

@@ -259,9 +259,6 @@ onLoad(async (options: any) => {
* 加载页面数据
*/
const loadPageData = async () => {
try {
uni.showLoading({ title: '加载中...' })
// 获取课程详情
const res = await courseApi.getCourseDetail(courseId.value)
if (res.code === 0 && res.data) {
@@ -286,19 +283,12 @@ const loadPageData = async () => {
// 加载评论
await loadComments()
} catch (error) {
console.error('加载页面数据失败:', error)
} finally {
uni.hideLoading()
}
}
/**
* 检查VIP状态
*/
const checkVipStatus = async () => {
try {
const res = await courseApi.checkCourseVip(courseId.value)
if (res.code === 0) {
userVip.value = res.userVip || null
@@ -311,9 +301,6 @@ const checkVipStatus = async () => {
}
}
}
} catch (error) {
console.error('检查VIP状态失败:', error)
}
}
/**
@@ -324,7 +311,6 @@ const switchCatalogue = async (index: number) => {
const catalogue = catalogueList.value[index]
// 获取章节列表
try {
const res = await courseApi.getCatalogueChapterList(catalogue.id)
if (res.code === 0) {
chapterList.value = res.chapterList || []
@@ -337,9 +323,6 @@ const switchCatalogue = async (index: number) => {
} else {
showRenewBtn.value = false
}
} catch (error) {
console.error('切换目录失败:', error)
}
}
/**
@@ -366,7 +349,6 @@ const handleChapterClick = (chapter: IChapter) => {
const handleGetFreeCourse = async () => {
if (!currentCatalogue.value) return
try {
uni.showLoading({ title: '领取中...' })
const res = await courseApi.startStudyForMF(currentCatalogue.value.id)
if (res.code === 0) {
@@ -374,11 +356,6 @@ const handleGetFreeCourse = async () => {
// 刷新页面数据
await loadPageData()
}
} catch (error) {
console.error('领取免费课程失败:', error)
} finally {
uni.hideLoading()
}
}
/**
@@ -387,7 +364,6 @@ const handleGetFreeCourse = async () => {
const handlePurchase = async () => {
if (!currentCatalogue.value) return
try {
isFudu.value = false
const res = await courseApi.getProductListForCourse(currentCatalogue.value.id)
if (res.code === 0 && res.productList.length > 0) {
@@ -396,9 +372,6 @@ const handlePurchase = async () => {
} else {
uni.showToast({ title: '此课程暂无购买方式', icon: 'none' })
}
} catch (error) {
console.error('获取商品列表失败:', error)
}
}
/**
@@ -407,7 +380,6 @@ const handlePurchase = async () => {
const handleRenew = async () => {
if (!currentCatalogue.value) return
try {
isFudu.value = true
fuduCatalogueId.value = currentCatalogue.value.id
const res = await courseApi.getRenewProductList(currentCatalogue.value.id)
@@ -417,9 +389,6 @@ const handleRenew = async () => {
} else {
uni.showToast({ title: '暂无复读方案', icon: 'none' })
}
} catch (error) {
console.error('获取复读商品列表失败:', error)
}
}
/**

View File

@@ -257,7 +257,6 @@ const handleFirstLevelClick = (item: string) => {
* 获取课程分类数据
*/
const getMedicalTags = async () => {
try {
const res = await courseSubjectClassificationApi.getCourseMedicalTree()
if (res && res.code === 0) {
if (res.labels && res.labels.length > 0) {
@@ -278,9 +277,6 @@ const getMedicalTags = async () => {
curseTagList.value = []
}
}
} catch (error) {
console.error('获取医学课程分类失败:', error)
}
}
/**
* 医学
@@ -309,14 +305,10 @@ const curseClick = (item: IMedicalTag, index: number) => {
*/
const soulCateList = ref<IMedicalTag[]>([])
const getSoulCateList = async () => {
try {
const res = await courseSubjectClassificationApi.getCourseSoulTree()
if (res.labels&&res.labels.length>0) {
soulCateList.value = res.labels;
}
} catch (error) {
console.error('获取心理学课程分类失败:', error)
}
}
/**
@@ -325,14 +317,10 @@ const getSoulCateList = async () => {
*/
const sociologyCateList = ref<IMedicalTag[]>([])
const getSociologyCateList = async () => {
try {
const res = await courseSubjectClassificationApi.getCourseSociologyTree()
if (res.labels&&res.labels.length>0) {
sociologyCateList.value = res.labels;
}
} catch (error) {
console.error('获取国学课程分类失败:', error)
}
}
/**
@@ -369,7 +357,6 @@ const learnList = ref<ICourse[]>([]) // 观看记录列表
* 获取观看记录
*/
const getLearnCourse = async () => {
try {
const res = await courseApi.getUserLateCourseList()
if (res && res.code === 0) {
if (res.page && res.page.length > 0) {
@@ -378,9 +365,6 @@ const getLearnCourse = async () => {
learnList.value = []
}
}
} catch (error) {
console.error('获取观看记录失败:', error)
}
}
// 新闻播报
@@ -389,7 +373,6 @@ const newsList = ref<INews[]>([]) // 新闻列表
* 获取新闻列表
*/
const getNewsList = async () => {
try {
const res = await commonApi.getMessageList(0, 1, 0)
if (res && res.code === 0) {
if (res.messages && res.messages.length > 0) {
@@ -398,9 +381,6 @@ const getNewsList = async () => {
newsList.value = []
}
}
} catch (error) {
console.error('获取新闻列表失败:', error)
}
}
/**
* 新闻点击处理
@@ -423,7 +403,6 @@ const tryListenList = ref<ICourse[]>([]) // 试听课程列表
* 获取试听课程列表
*/
const getTryListenList = async () => {
try {
const res = await courseApi.getMarketCourseList({
page: 1,
limit: 6,
@@ -436,9 +415,6 @@ const getTryListenList = async () => {
tryListenList.value = []
}
}
} catch (error) {
console.error('获取试听课程失败:', error)
}
}
/**

View File

@@ -52,7 +52,6 @@ const subCategoryList = ref<ICategory[]>([]) // 子级分类列表
* 获取分类下的子级分类
*/
const getSubCategoryList = async () => {
try {
let res: any = null
switch (subject.value) {
case '医学':
@@ -74,9 +73,6 @@ const getSubCategoryList = async () => {
radio_category_id.value = 0
}
}
} catch (error) {
console.error('获取分类下的子级分类失败:', error)
}
}
/**

View File

@@ -191,16 +191,12 @@ const getCode = async () => {
if (!isEmailEmpty()) return
if (!isEmailVerified(email.value)) return
try {
await commonApi.sendMailCaptcha(email.value)
uni.showToast({
title: t('login.sendCodeSuccess'),
icon: 'none'
})
getCodeState()
} catch (error) {
console.error('Send code error:', error)
}
}
/**
@@ -264,7 +260,6 @@ const onSubmit = async () => {
if (!isConfirmPasswordEmpty()) return
if (!isPasswordMatch()) return
try {
await resetPassword(email.value, code.value, password.value)
uni.showModal({
@@ -275,9 +270,6 @@ const onSubmit = async () => {
uni.navigateBack()
}
})
} catch (error) {
console.error('Reset password error:', error)
}
}
</script>

View File

@@ -285,13 +285,8 @@ const verifyCodeLogin = async () => {
if (!isCodeEmpty()) return false
try {
const res = await loginWithCode(email.value, code.value)
return res
} catch (error) {
console.error('验证码登录失败:', error)
return null
}
return res || null
}
// 密码登录
const passwordLogin = async () => {
@@ -301,13 +296,8 @@ const passwordLogin = async () => {
if (!isPasswordEmpty()) return false
try {
const res = await loginWithPassword(phoneEmail.value, password.value)
return res
} catch (error) {
console.error('密码登录失败:', error)
return null
}
return res || null
}
// 提交登录
const onSubmit = async () => {

View File

@@ -61,15 +61,9 @@ import GoodsPrice from '@/components/order/GoodsPrice.vue';
*/
const userInfo = ref({})
const getUserInfo = async () => {
try {
const res = await orderApi.getUserInfo()
if (res.code === 0) {
userInfo.value = res.result || {}
}
} catch (error) {
console.error('获取用户信息失败:', error)
}
}
/**
* 获取商品列表
@@ -77,16 +71,12 @@ const getUserInfo = async () => {
const goodsIds = ref<string>('')
const goodsList = ref<IOrderGoods[]>([])
const getGoodsList = async () => {
try {
// 获取商品详情
const res = await orderApi.getShopProductListByIds(goodsIds.value)
if (res.code === 0 && res.shopProductList?.length > 0) {
if (res.shopProductList?.length > 0) {
goodsList.value = res.shopProductList
}
} catch (error) {
console.error('获取商品列表失败:', error)
}
}
/**

View File

@@ -147,7 +147,6 @@
* 获取数据
*/
const getData = async () => {
try {
// 获取用户信息
const userRes = await getUserInfo()
console.log(userRes);
@@ -160,9 +159,6 @@
if (vipRes.vipInfo) {
vipInfo.value = vipRes.vipInfo
}
} catch (error) {
console.error('获取数据失败:', error)
}
}
/**

View File

@@ -199,15 +199,11 @@ const avatarUrl = ref('')
*/
const userInfo = ref<any>({}) // 用户信息
const getData = async () => {
try {
const res = await getUserInfo()
if (res.result) {
userStore.setUserInfo(res.result)
userInfo.value = res.result
}
} catch (error) {
console.error('获取用户信息失败:', error)
}
}
/**
@@ -324,16 +320,12 @@ const sendCode = async () => {
return
}
try {
await sendEmailCode(editForm.value.email)
uni.showToast({
title: t('user.sendCodeSuccess'),
icon: 'none'
})
startCountdown()
} catch (error) {
console.error('发送验证码失败:', error)
}
}
/**
@@ -398,7 +390,6 @@ const checkPasswordStrength = () => {
const handleSubmit = async () => {
const key = currentField.value?.key
try {
// 构建更新数据对象
let updateData: any = Object.assign({}, userInfo.value)
@@ -481,9 +472,6 @@ const handleSubmit = async () => {
setTimeout(() => {
getData()
}, 500)
} catch (error) {
console.error('更新失败:', error)
}
}
/**

View File

@@ -1,9 +1,9 @@
<template>
<view class="recharge-page">
<!-- 自定义导航栏 -->
<nav-bar :title="$t('user.recharge')"></nav-bar>
<nav-bar :title="$t('order.recharge')"></nav-bar>
<view class="block">
<view class="text">充值金额</view>
<view class="text">{{$t('order.rechargeAmount')}}</view>
<view class="recharge">
<view class="recharge_block" @click="chosPric(item)"
:class="aloneItem.priceTypeId === item.priceTypeId ? 'selected' : ''"
@@ -21,30 +21,30 @@
<view v-html="remark.remark"></view>
</view>
<view class="cha_fangsh">
<view class="cf_title PM_font">支付方式</view>
<view class="cf_title PM_font">{{$t('user.paymentMethod')}}</view>
<view class="cf_radio">
<radio-group v-for="item in iosPaylist" @change="choseType(item.id)">
<radio-group v-for="item in iosPaylist" @click="choseType(item.id)">
<view style="width: 100%">
<view :class="payType == item.id ? 'Tab_xf cf_xuanx' : 'cf_xuanx'">
<!-- <image class="pay_item_img" :src="item.imgUrl" mode="aspectFil">
</image> -->
<text>{{ item.title }}</text>
<radio :checked="payType === item.id" style="float: right"></radio>
<radio :checked="payType === item.id"></radio>
</view>
</view>
</radio-group>
</view>
</view>
<view class="agree_wo flexbox">
<radio-group class="agree" v-for="(item, index) in argee" :key="index" @change="radioCheck">
<radio-group class="agree" v-for="(item, index) in argee" :key="index" @click="radioCheck">
<view>
<radio class="agreeRadio" :value="item.id" :checked="state" color="#007bff"></radio>
</view>
</radio-group>
<view>我已阅读并同意<span class="highlight" @click="showAgreement">增值服务协议</span></view>
<view>{{$t('order.readAgree')}}<span class="highlight" @click="showAgreement">{{$t('order.valueAddedServices')}}</span></view>
</view>
<view class="bottom-button-container">
<button class="recharge-button" @click="handleRecharge">立即充值</button>
<button class="recharge-button" @click="handleRecharge">{{$t('order.recharge')}}</button>
</view>
<wd-popup v-model="agreemenState" position="bottom" :closeable="true">
<view class="agreement">
@@ -61,10 +61,11 @@
<script setup lang="ts">
import { ref, computed, onMounted, toRefs, reactive } from 'vue'
import { useI18n } from 'vue-i18n'
import { useMessage } from '@/uni_modules/wot-design-uni'
import { getBookBuyConfigList, getAgreement, getActivityDescription } from '@/api/modules/user'
const googlePay = uni.requireNativePlugin("sn-googlepay5");
// const googlePay = uni.requireNativePlugin("sn-googlepay5");
const { t } = useI18n()
const message = useMessage()
const payType = ref('1')
const iosPaylist = ref([
@@ -108,9 +109,11 @@
const isConnected = ref(false)
/**
* 获取使用环境
*/
const getDevName = () => {
// 获取使用环境
if (uni.getSystemInfoSync().platform === "android") {
qudao.value = 'Google'
isAndroid.value = true;
@@ -132,8 +135,8 @@
* 勾选协议
*/
const radioCheck = () => {
console.log('点击了', state.value);
state.value = !state.value
console.log('点击了', state.value);
}
/**
@@ -151,7 +154,6 @@
console.log(rechargeList.value.bookBuyConfigList, '充值列表');
// 默认选择第一个金额
aloneItem.value = rechargeList.value.bookBuyConfigList[0]
getGooglePay()
} catch (error) {
console.error('获取订单列表失败:', error)
}
@@ -194,7 +196,16 @@
}
const handleRecharge = () => {
if(!state.value){
uni.showToast({
title: t('order.readAgreeServices'),
icon: 'none'
})
return
}
uni.showLoading({ title: '加载中...' })
console.log('立即充值');
getGooglePay()
}
/**
@@ -202,8 +213,6 @@
*/
const getGooglePay = () => {
googlePay.init({
// autoReconnect: true, // 是否自动重连(插件实现)
// enableAutoServiceReconnection: true, //是否自动重连8.0+支持)
}, (e:any) => {
console.log('init', e);
if (e.code == 0) {
@@ -262,9 +271,6 @@
getDevName();
getActivityDescriptionData()
getAgreementData()
})
</script>
@@ -300,7 +306,7 @@
.recharge_money {
font-size: 30rpx;
margin-bottom: 30rpx;
margin-bottom: 10rpx;
}
@@ -376,9 +382,12 @@
.cf_xuanx {
font-size: 24rpx;
padding: 20rpx 0;
padding: 10rpx 0;
margin-bottom: 20rpx;
border-bottom: 1px solid #ededed;
display: flex;
justify-content: space-between;
align-items:center;
image {
width: 40rpx;

View File

@@ -1,65 +1,46 @@
<template>
<z-paging ref="paging" v-model="bookList" auto-show-back-to-top class="my-book-page" @query="loadBookList">
<z-paging ref="paging" v-model="bookList" auto-show-back-to-top class="my-book-page" @query="rechargeList" :default-page-size="10">
<template #top>
<!-- 自定义导航栏 -->
<nav-bar :title="$t('book.myBook')"></nav-bar>
<nav-bar :title="$t('user.consumptionRecord')"></nav-bar>
</template>
<!-- 充值列表 -->
<!-- <uni-icons fontFamily="CustomFont" :size="26">{{'\uebc6'}}</uni-icons> -->
<view class="recharge-record">
<view><uni-icons type="right" size="30"></uni-icons></view>
<view class="go-gecharge">
立即充值
<uni-icons type="contact" size="30"></uni-icons>
<view class="recharge-record" v-if="(bookList && bookList.length > 0)">
<view class="go-gecharge" @click="goRecharge">
<view>{{$t('order.recharge')}}</view>
<view><wd-icon name="arrow-right" size="16px" color="#fff"/></view>
</view>
<view class="title">充值消费记录</view>
<view class="recharge-record-block" v-for="(item) in 5">
<view class="recharge-record-block-row">购买商品<text class="text">90</text></view>
<view class="time">2025-10-20</view>
<view class="title">{{$t('order.rechargeConsumptionList')}}</view>
<view class="recharge-record-block" v-for="(item, index) in bookList" :key="index">
<view class="recharge-record-block-row">{{item.orderType}}<text class="text">{{item.changeAmount}}</text></view>
<view class="time">{{item.createTime}}</view>
</view>
</view>
<!-- <view v-if="(bookList && bookList.length > 0)" class="book-list">
<BookCard
v-for="item in bookList"
:key="item.id"
:book="item"
/>
</view> -->
<!-- 空状态 -->
<!-- <view v-else-if="!loading && !firstLoad" class="empty-state">
<image src="@/static/null_img.png" mode="aspectFit" />
<text class="empty-text">{{ $t('book.nullText') }}</text>
<wd-button type="primary" @click="goToBuy">
{{ $t('book.choose') }}
</wd-button>
</view> -->
</z-paging>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { bookApi } from '@/api/modules/book'
import type { IBook } from '@/types/book'
import BookCard from '@/components/book/BookCard.vue'
import { useUserStore } from '@/stores/user'
import { getTransactionDetailsList } from '@/api/modules/user'
const { t } = useI18n()
const paging = ref<any>()
const userStore = useUserStore()
// 数据状态
const bookList = ref<IBook[]>([])
const bookList = ref([])
const loading = ref(false)
const firstLoad = ref(true)
// 加载书单列表
async function loadBookList(pageNo : number, pageSize : number) {
// 充值记录列表
async function rechargeList(pageNo : number, pageSize : number) {
const userId = userStore.userInfo.id
loading.value = true
try {
const res = await bookApi.getMyBooks(pageNo, pageSize)
paging.value.complete(res.page.records)
const res = await getTransactionDetailsList(pageNo, pageSize, userId)
console.log(res, 'res');
paging.value.complete(res.transactionDetailsList.records)
} catch (error) {
paging.value.complete(false)
console.error('Failed to load book list:', error)
@@ -68,6 +49,15 @@
loading.value = false
}
}
/**
* 跳转充值页面
*/
const goRecharge = () => {
uni.navigateTo({
url: '/pages/user/recharge/index'
})
}
</script>
<style lang="scss" scoped>
@@ -86,15 +76,16 @@
.go-gecharge{
//height: 100rpx;
background: linear-gradient(to right, #007bff, #17a2b8);
font-size: 40rpx;
font-size: 30rpx;
font-weight: bold;
color: #fff;
padding: 20rpx;
margin-bottom: 20rpx;
display: flex;justify-content:space-between;align-items:center
}
.title {
font-size: 40rpx;
font-size: 30rpx;
padding-left:20rpx;
margin-bottom: 30rpx;
color: #007bff;
@@ -120,6 +111,25 @@
}
}
}
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding-top: 200rpx;
image {
width: 400rpx;
height: 300rpx;
margin-bottom: 40rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
margin-bottom: 50rpx;
}
}
</style>

0
pages/vip/course.vue Normal file
View File