个人中心:优化登录后的数据读取

pull/34/MERGE
YunaiV 2023-12-28 22:00:07 +08:00
parent 1a07dc4a40
commit c3cc5d653d
12 changed files with 125 additions and 171 deletions

View File

@ -38,7 +38,7 @@
</view>
<view class="check-box ss-flex ss-col-center ss-p-l-10">
<view class="userInfo-money ss-m-r-10" v-if="item.value === 'wallet'">
余额: {{ fen2yuan(userInfo.money) }}
余额: {{ fen2yuan(userWallet.money) }}
</view>
<radio
:value="item.value"
@ -83,7 +83,7 @@
import PayChannelApi from '@/sheep/api/pay/channel';
import { getPayMethods } from '@/sheep/platform/pay';
const userInfo = computed(() => sheep.$store('user').userInfo);
const userWallet = computed(() => sheep.$store('user').userWallet);
//
const state = reactive({
@ -189,6 +189,8 @@
state.orderType = options.orderType;
}
setOrder(id);
//
sheep.$store('user').getWallet();
});
</script>

View File

@ -9,7 +9,7 @@
]">
<view class="">
<view class="num-title">当前余额</view>
<view class="wallet-num">{{ fen2yuan(userInfo.money) }}</view>
<view class="wallet-num">{{ fen2yuan(userWallet.balance) }}</view>
</view>
<button class="ss-reset-button log-btn" @tap="sheep.$router.go('/pages/pay/recharge-log')">
充值记录
@ -48,7 +48,7 @@
import { fen2yuan } from '@/sheep/hooks/useGoods';
import PayWalletApi from '@/sheep/api/pay/wallet';
const userInfo = computed(() => sheep.$store('user').userInfo);
const userWallet = computed(() => sheep.$store('user').userWallet);
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');

View File

@ -13,7 +13,7 @@
/>
</view>
<view class="ss-flex ss-row-between ss-col-center ss-m-t-64">
<view class="money-num">{{ state.showMoney ? fen2yuan(userInfo.money) : '*****' }}</view>
<view class="money-num">{{ state.showMoney ? fen2yuan(userWallet.balance) : '*****' }}</view>
<button class="ss-reset-button topup-btn" @tap="sheep.$router.go('/pages/pay/recharge')">
充值
</button>
@ -122,7 +122,8 @@
value: '2',
},
];
const userInfo = computed(() => sheep.$store('user').userInfo);
const userWallet = computed(() => sheep.$store('user').userWallet);
//
const dateFilterText = computed(() => {
@ -167,6 +168,8 @@
state.date = [state.today, state.today];
getLogList();
getSummary();
//
sheep.$store('user').getWallet();
});
// tab

View File

@ -1,6 +1,17 @@
import request from '@/sheep/request';
const UserApi = {
// 获得基本信息
getUserInfo: () => {
return request({
url: '/app-api/member/user/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
},
// 修改基本信息
updateUser: (data) => {
return request({

View File

@ -1,6 +1,17 @@
import request from '@/sheep/request';
const PayWalletApi = {
// 获取钱包
getPayWallet() {
return request({
url: '/app-api/pay/wallet/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
},
// 获得钱包流水分页
getWalletTransactionPage: (params) => {
const queryString = Object.keys(params)

View File

@ -57,6 +57,17 @@ const CouponApi = {
params: { id },
});
},
// 获得未使用的优惠劵数量
getUnusedCouponCount: () => {
return request({
url: '/app-api/promotion/coupon/get-unused-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
}
};
export default CouponApi;

View File

@ -90,6 +90,17 @@ const OrderApi = {
},
});
},
// 获得交易订单数量
getOrderCount: () => {
return request2({
url: '/app-api/trade/order/get-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
},
// 创建单个评论
createOrderItemComment: (data) => {
return request2({

View File

@ -12,24 +12,6 @@ export default {
auth: true,
},
}),
profile: () =>
request2({
url: 'member/user/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
balance: () =>
request2({
url: '/app-api/pay/wallet/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
// 账号登录
accountLogin: (data) =>
request({
@ -41,28 +23,6 @@ export default {
loadingMsg: '登录中',
},
}),
// 短信登录
smsLogin: (data) =>
request({
url: '/user/api/user/smsLogin',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登录中',
},
}),
// 短信注册
smsRegister: (data) =>
request({
url: '/user/api/user/smsRegister',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '正在注册',
},
}),
// 绑定、更换手机号
changeMobile: (data) =>
@ -76,28 +36,6 @@ export default {
},
}),
// 更新小程序信息
updateMpUserInfo: (data) =>
request({
url: '/user/api/user/updateMpUserInfo',
method: 'POST',
data,
}),
// 第三方授权信息
thirdOauthInfo: () =>
request({
url: '/user/api/user/thirdOauth',
method: 'GET',
params: {
provider: $platform.provider,
platform: $platform.platform,
},
custom: {
showLoading: false,
},
}),
// 添加分享记录
addShareLog: (data) =>
request({
@ -132,14 +70,6 @@ export default {
}),
address: {
// default: () =>
// request({
// url: 'user/address/default',
// method: 'GET',
// custom: {
// showError: false,
// },
// }),
default: () =>
request2({
url: 'member/address/get-default',
@ -278,33 +208,5 @@ export default {
auth: true,
},
}),
},
//数量接口
// data: () =>
// request({
// url: 'user/user/data',
// method: 'GET',
// custom: {
// showLoading: false,
// auth: true,
// },
// }),
data: () =>
request2({
url: 'trade/order/get-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
data2: () =>
request2({
url: 'trade/after-sale/get-applying-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
}
};

View File

@ -9,11 +9,11 @@
>
<uni-badge
class="uni-badge-left-margin"
:text="numData.order_num[item.type]"
:text="numData.orderCount[item.count]"
absolute="rightTop"
size="small"
>
<image class="item-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit"></image>
<image class="item-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit" />
</uni-badge>
<view class="menu-title ss-m-t-28">{{ item.title }}</view>
</view>
@ -34,6 +34,7 @@
icon: '/static/img/shop/order/no_pay.png',
path: '/pages/order/list',
type: 'unpaid',
count: 'unpaidCount',
},
{
title: '待收货',
@ -41,6 +42,7 @@
icon: '/static/img/shop/order/no_take.png',
path: '/pages/order/list',
type: 'noget',
count: 'deliveredCount',
},
{
title: '待评价',
@ -48,6 +50,7 @@
icon: '/static/img/shop/order/no_comment.png',
path: '/pages/order/list',
type: 'nocomment',
count: 'uncommentedCount',
},
{
title: '售后单',
@ -55,6 +58,7 @@
icon: '/static/img/shop/order/change_order.png',
path: '/pages/order/aftersale/list',
type: 'aftersale',
count: 'afterSaleCount',
},
{
title: '全部订单',
@ -65,7 +69,6 @@
];
const numData = computed(() => sheep.$store('user').numData);
console.log('更换后的yuda订单数量',numData)
</script>
<style lang="scss" scoped>

View File

@ -4,7 +4,7 @@
<view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/money')">
<view class="value-box ss-flex ss-col-bottom">
<view class="value-text ss-line-1">{{ fen2yuan(userInfo.money) || '0.00' }}</view>
<view class="value-text ss-line-1">{{ fen2yuan(userWallet.balance) || '0.00' }}</view>
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">账户余额</view>
@ -23,15 +23,14 @@
})
">
<view class="value-box ss-flex ss-col-bottom">
<view class="value-text">{{ numData.coupons_num || '0.00' }}</view>
<view class="value-text">{{ numData.unusedCouponCount }}</view>
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">优惠券</view>
</view>
<view class="menu-item ss-flex-col ss-row-center ss-col-center menu-wallet"
@tap="sheep.$router.go('/pages/user/wallet/money')">
<image class="item-icon" :src="sheep.$url.static('/static/img/shop/user/wallet_icon.png')" mode="aspectFit">
</image>
@tap="sheep.$router.go('/pages/user/wallet/money')">
<image class="item-icon" :src="sheep.$url.static('/static/img/shop/user/wallet_icon.png')" mode="aspectFit" />
<view class="menu-title ss-m-t-30">我的钱包</view>
</view>
</view>
@ -41,13 +40,11 @@
/**
* 装修组件 - 订单菜单组
*/
import {
computed,
ref
} from 'vue';
import { computed } from 'vue';
import sheep from '@/sheep';
import { fen2yuan } from '../../hooks/useGoods';
const userWallet = computed(() => sheep.$store('user').userWallet);
const userInfo = computed(() => sheep.$store('user').userInfo);
const numData = computed(() => sheep.$store('user').numData);
</script>

View File

@ -3,14 +3,13 @@ import { defineStore } from 'pinia';
const modal = defineStore({
id: 'modal',
state: () => ({
auth: '', // 授权弹框 accountLogin|smsLogin|smsRegister|resetPassword|changeMobile|changePassword|changeUsername
auth: '', // 授权弹框 accountLogin|smsLogin|resetPassword|changeMobile|changePassword|changeUsername
share: false, // 分享弹框
menu: false, // 快捷菜单弹框
advHistory: [], // 广告弹框记录
lastTimer: {
// 短信验证码计时器,为了防止刷新请求做了持久化
smsLogin: 0,
smsRegister: 0,
changeMobile: 0,
resetPassword: 0,
changePassword: 0,

View File

@ -15,6 +15,10 @@ import {
} from '@/sheep/hooks/useModal';
import AuthUtil from '@/sheep/api/member/auth';
import BrokerageApi from '@/sheep/api/trade/brokerage';
import UserApi from '@/sheep/api/member/user';
import PayWalletApi from '@/sheep/api/pay/wallet';
import OrderApi from '@/sheep/api/trade/order';
import CouponApi from '@/sheep/api/promotion/coupon';
// 默认用户信息
const defaultUserInfo = {
@ -22,20 +26,26 @@ const defaultUserInfo = {
nickname: '', // 昵称
gender: 0, // 性别
mobile: '', // 手机号
money: '--', // 余额
score: '--', // 积分 TODO 芋艿:改成 point
point: 0, // 积分
money: 0, // 余额
verification: {}, // 认证字段
};
// 默认钱包信息
const defaultUserWallet = {
balance: 0, // 余额
}
// 默认订单、优惠券等其他资产信息
const defaultNumData = {
coupons_num: '--',
order_num: {
aftersale: 0,
nocomment: 0,
noget: 0,
nosend: 0,
unpaid: 0,
unusedCouponCount: 0,
orderCount: {
allCount: 0,
unpaidCount: 0,
undeliveredCount: 0,
deliveredCount: 0,
uncommentedCount: 0,
afterSaleCount: 0,
},
};
@ -43,55 +53,44 @@ const user = defineStore({
id: 'user',
state: () => ({
userInfo: clone(defaultUserInfo), // 用户信息
userWallet: clone(defaultUserWallet), // 用户钱包信息
isLogin: !!uni.getStorageSync('token'), // 登录状态
numData: cloneDeep(defaultNumData), // 用户其他数据
lastUpdateTime: 0, // 上次更新时间
}),
actions: {
// 获取个人信息
// TODO 芋艿:整理下;
// 获取用户信息
async getInfo() {
const {
code,
data
} = await userApi.profile();
// 为了兼容 获取用户余额 可能还会用到其他参数
// 优惠券数量,积分数量 应该在这里
const {
code: code2,
data: data2
} = await userApi.balance();
if (code !== 0 || code2 != 0) return;
data.money = data2.balance;
this.userInfo = data;
// console.log(data2, '信息')
const { code, data } = await UserApi.getUserInfo();
if (code !== 0) {
return;
}
this.userInfo = data;
return Promise.resolve(data);
},
// 获得用户钱包
async getWallet() {
const { code, data } = await PayWalletApi.getPayWallet();
if (code !== 0) {
return;
}
this.userWallet = data;
},
// 获取订单、优惠券等其他资产信息
// TODO 芋艿:整理下;
async getNumData() {
const {
code,
data
} = await userApi.data();
const data2 = await userApi.data2();
let data3 = await userApi.getUnused();
// console.log(data3.data, '优惠券')
if (code === 0 && data2.code === 0) {
// console.log('订单数据', data);
this.numData = {
coupons_num: data3.data,
order_num: {
noget: data.deliveredCount,
unpaid: data.unpaidCount,
nocomment: data.uncommentedCount,
aftersale: data2.data
}
};
}
getNumData() {
OrderApi.getOrderCount().then(res => {
if (res.code === 0) {
this.numData.orderCount = res.data;
}
});
CouponApi.getUnusedCouponCount().then(res => {
if (res.code === 0) {
this.numData.unusedCouponCount = res.data;
}
});
},
// 添加分享记录
@ -117,18 +116,23 @@ const user = defineStore({
return this.isLogin;
},
// 更新用户相关信息 (手动限流 5秒之内不刷新)
// TODO 芋艿:整理下;
// 更新用户相关信息 (手动限流5 秒之内不刷新)
async updateUserData() {
if (!this.isLogin) {
this.resetUserData();
return;
}
// 防抖5 秒之内不刷新
const nowTime = new Date().getTime();
if (this.lastUpdateTime + 5000 > nowTime) return;
if (this.lastUpdateTime + 5000 > nowTime) {
return;
}
this.lastUpdateTime = nowTime;
// 获取最新信息
await this.getInfo();
this.getWallet();
this.getNumData();
this.lastUpdateTime = nowTime;
return this.userInfo;
},
@ -137,8 +141,8 @@ const user = defineStore({
resetUserData() {
this.setToken();
this.userInfo = clone(defaultUserInfo);
this.userWallet = clone(defaultUserWallet);
this.numData = cloneDeep(defaultNumData);
this.agentInfo = {};
cart().emptyList();
},