优化:请求接口全局处理loading和错误提示
This commit is contained in:
@@ -147,21 +147,17 @@
|
||||
* 获取数据
|
||||
*/
|
||||
const getData = async () => {
|
||||
try {
|
||||
// 获取用户信息
|
||||
const userRes = await getUserInfo()
|
||||
console.log(userRes);
|
||||
if (userRes.user) {
|
||||
userStore.setUserInfo(userRes.user)
|
||||
}
|
||||
// 获取用户信息
|
||||
const userRes = await getUserInfo()
|
||||
console.log(userRes);
|
||||
if (userRes.user) {
|
||||
userStore.setUserInfo(userRes.user)
|
||||
}
|
||||
|
||||
// 获取VIP信息
|
||||
const vipRes = await getVipInfo()
|
||||
if (vipRes.vipInfo) {
|
||||
vipInfo.value = vipRes.vipInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取数据失败:', error)
|
||||
// 获取VIP信息
|
||||
const vipRes = await getVipInfo()
|
||||
if (vipRes.vipInfo) {
|
||||
vipInfo.value = vipRes.vipInfo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -199,14 +199,10 @@ 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)
|
||||
const res = await getUserInfo()
|
||||
if (res.result) {
|
||||
userStore.setUserInfo(res.result)
|
||||
userInfo.value = res.result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
await sendEmailCode(editForm.value.email)
|
||||
uni.showToast({
|
||||
title: t('user.sendCodeSuccess'),
|
||||
icon: 'none'
|
||||
})
|
||||
startCountdown()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,92 +390,88 @@ const checkPasswordStrength = () => {
|
||||
const handleSubmit = async () => {
|
||||
const key = currentField.value?.key
|
||||
|
||||
try {
|
||||
// 构建更新数据对象
|
||||
let updateData: any = Object.assign({}, userInfo.value)
|
||||
// 构建更新数据对象
|
||||
let updateData: any = Object.assign({}, userInfo.value)
|
||||
|
||||
switch (key) {
|
||||
case 'email':
|
||||
// 更新邮箱
|
||||
if (!editForm.value.email || !editForm.value.code) {
|
||||
uni.showToast({
|
||||
title: t('user.pleaseInputCode'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
await updateEmail(userInfo.value.id, editForm.value.email, editForm.value.code)
|
||||
break
|
||||
|
||||
case 'password':
|
||||
// 更新密码
|
||||
if (!passwordOk.value) {
|
||||
uni.showToast({
|
||||
title: passwordNote.value,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (editForm.value.password !== editForm.value.confirmPassword) {
|
||||
uni.showToast({
|
||||
title: t('user.passwordNotMatch'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
await updatePassword(userInfo.value.id, editForm.value.password)
|
||||
break
|
||||
|
||||
case 'avatar':
|
||||
// 更新头像
|
||||
console.log('avatarUrl.value:', avatarUrl.value)
|
||||
if (!avatarUrl.value) {
|
||||
uni.showToast({
|
||||
title: t('common.pleaseSelect') + t('user.avatar'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 如果是新上传的图片,需要先上传
|
||||
updateData.avatar = avatarUrl.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
|
||||
case 'sex':
|
||||
// 更新性别
|
||||
updateData.sex = editValue.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
|
||||
default:
|
||||
// 更新其他字段
|
||||
if (!editValue.value) {
|
||||
uni.showToast({
|
||||
title: getPlaceholder(key),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
updateData[key] = editValue.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: t('user.updateSuccess'),
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
closeModal()
|
||||
|
||||
// 刷新数据
|
||||
setTimeout(() => {
|
||||
getData()
|
||||
}, 500)
|
||||
} catch (error) {
|
||||
console.error('更新失败:', error)
|
||||
switch (key) {
|
||||
case 'email':
|
||||
// 更新邮箱
|
||||
if (!editForm.value.email || !editForm.value.code) {
|
||||
uni.showToast({
|
||||
title: t('user.pleaseInputCode'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
await updateEmail(userInfo.value.id, editForm.value.email, editForm.value.code)
|
||||
break
|
||||
|
||||
case 'password':
|
||||
// 更新密码
|
||||
if (!passwordOk.value) {
|
||||
uni.showToast({
|
||||
title: passwordNote.value,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (editForm.value.password !== editForm.value.confirmPassword) {
|
||||
uni.showToast({
|
||||
title: t('user.passwordNotMatch'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
await updatePassword(userInfo.value.id, editForm.value.password)
|
||||
break
|
||||
|
||||
case 'avatar':
|
||||
// 更新头像
|
||||
console.log('avatarUrl.value:', avatarUrl.value)
|
||||
if (!avatarUrl.value) {
|
||||
uni.showToast({
|
||||
title: t('common.pleaseSelect') + t('user.avatar'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 如果是新上传的图片,需要先上传
|
||||
updateData.avatar = avatarUrl.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
|
||||
case 'sex':
|
||||
// 更新性别
|
||||
updateData.sex = editValue.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
|
||||
default:
|
||||
// 更新其他字段
|
||||
if (!editValue.value) {
|
||||
uni.showToast({
|
||||
title: getPlaceholder(key),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
updateData[key] = editValue.value
|
||||
await updateUserInfo(updateData)
|
||||
break
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: t('user.updateSuccess'),
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
closeModal()
|
||||
|
||||
// 刷新数据
|
||||
setTimeout(() => {
|
||||
getData()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user