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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,24 +12,6 @@ export default {
auth: true, 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) => accountLogin: (data) =>
request({ request({
@ -41,28 +23,6 @@ export default {
loadingMsg: '登录中', 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) => 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) => addShareLog: (data) =>
request({ request({
@ -132,14 +70,6 @@ export default {
}), }),
address: { address: {
// default: () =>
// request({
// url: 'user/address/default',
// method: 'GET',
// custom: {
// showError: false,
// },
// }),
default: () => default: () =>
request2({ request2({
url: 'member/address/get-default', url: 'member/address/get-default',
@ -278,33 +208,5 @@ export default {
auth: true, 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 <uni-badge
class="uni-badge-left-margin" class="uni-badge-left-margin"
:text="numData.order_num[item.type]" :text="numData.orderCount[item.count]"
absolute="rightTop" absolute="rightTop"
size="small" 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> </uni-badge>
<view class="menu-title ss-m-t-28">{{ item.title }}</view> <view class="menu-title ss-m-t-28">{{ item.title }}</view>
</view> </view>
@ -34,6 +34,7 @@
icon: '/static/img/shop/order/no_pay.png', icon: '/static/img/shop/order/no_pay.png',
path: '/pages/order/list', path: '/pages/order/list',
type: 'unpaid', type: 'unpaid',
count: 'unpaidCount',
}, },
{ {
title: '待收货', title: '待收货',
@ -41,6 +42,7 @@
icon: '/static/img/shop/order/no_take.png', icon: '/static/img/shop/order/no_take.png',
path: '/pages/order/list', path: '/pages/order/list',
type: 'noget', type: 'noget',
count: 'deliveredCount',
}, },
{ {
title: '待评价', title: '待评价',
@ -48,6 +50,7 @@
icon: '/static/img/shop/order/no_comment.png', icon: '/static/img/shop/order/no_comment.png',
path: '/pages/order/list', path: '/pages/order/list',
type: 'nocomment', type: 'nocomment',
count: 'uncommentedCount',
}, },
{ {
title: '售后单', title: '售后单',
@ -55,6 +58,7 @@
icon: '/static/img/shop/order/change_order.png', icon: '/static/img/shop/order/change_order.png',
path: '/pages/order/aftersale/list', path: '/pages/order/aftersale/list',
type: 'aftersale', type: 'aftersale',
count: 'afterSaleCount',
}, },
{ {
title: '全部订单', title: '全部订单',
@ -65,7 +69,6 @@
]; ];
const numData = computed(() => sheep.$store('user').numData); const numData = computed(() => sheep.$store('user').numData);
console.log('更换后的yuda订单数量',numData)
</script> </script>
<style lang="scss" scoped> <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" <view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/money')"> @tap="sheep.$router.go('/pages/user/wallet/money')">
<view class="value-box ss-flex ss-col-bottom"> <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 class="unit-text ss-m-l-6"></view>
</view> </view>
<view class="menu-title ss-m-t-28">账户余额</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-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 class="unit-text ss-m-l-6"></view>
</view> </view>
<view class="menu-title ss-m-t-28">优惠券</view> <view class="menu-title ss-m-t-28">优惠券</view>
</view> </view>
<view class="menu-item ss-flex-col ss-row-center ss-col-center menu-wallet" <view class="menu-item ss-flex-col ss-row-center ss-col-center menu-wallet"
@tap="sheep.$router.go('/pages/user/wallet/money')"> @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 class="item-icon" :src="sheep.$url.static('/static/img/shop/user/wallet_icon.png')" mode="aspectFit" />
</image>
<view class="menu-title ss-m-t-30">我的钱包</view> <view class="menu-title ss-m-t-30">我的钱包</view>
</view> </view>
</view> </view>
@ -41,13 +40,11 @@
/** /**
* 装修组件 - 订单菜单组 * 装修组件 - 订单菜单组
*/ */
import { import { computed } from 'vue';
computed,
ref
} from 'vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { fen2yuan } from '../../hooks/useGoods'; import { fen2yuan } from '../../hooks/useGoods';
const userWallet = computed(() => sheep.$store('user').userWallet);
const userInfo = computed(() => sheep.$store('user').userInfo); const userInfo = computed(() => sheep.$store('user').userInfo);
const numData = computed(() => sheep.$store('user').numData); const numData = computed(() => sheep.$store('user').numData);
</script> </script>

View File

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

View File

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