完成一键登录和支付功能
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { formatMemberCenterPhone, normalizePhoneForStore } from './format.js'
|
||||
import {
|
||||
getDefaultBodyTestState,
|
||||
mergeBodyTestState,
|
||||
@@ -10,14 +9,36 @@ import {
|
||||
mergeModuleState,
|
||||
finalizeModules
|
||||
} from './moduleStore.js'
|
||||
import {
|
||||
getDefaultCourseCatalog,
|
||||
import { getDefaultCourseCatalog,
|
||||
mergeCourseCatalog,
|
||||
canCancelBooking
|
||||
} from './bookingStore.js'
|
||||
import { getMemberId as requestGetMemberId } from '@/utils/request.js'
|
||||
|
||||
const STORAGE_KEY = 'gym_member_info_v1'
|
||||
|
||||
/**
|
||||
* 获取当前登录会员ID
|
||||
* @deprecated 请使用 @/utils/request.js 中的 getMemberId
|
||||
*/
|
||||
export function getCurrentMemberId() {
|
||||
return requestGetMemberId()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录信息
|
||||
*/
|
||||
export function getLoginMemberInfo() {
|
||||
return uni.getStorageSync('loginMemberInfo') || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
export function getToken() {
|
||||
return uni.getStorageSync('token') || null
|
||||
}
|
||||
|
||||
export function buildCardTip(remainingDays) {
|
||||
return `距离下次到期还有${remainingDays}天,请及时续费`
|
||||
}
|
||||
@@ -41,12 +62,6 @@ export function syncStats(store) {
|
||||
function finalizeStore(store) {
|
||||
syncStats(store)
|
||||
applyCardInfo(store)
|
||||
if (store.profile?.avatar) {
|
||||
store.memberProfile.avatar = store.profile.avatar
|
||||
}
|
||||
if (store.profile?.phone) {
|
||||
store.memberProfile.phone = formatMemberCenterPhone(store.profile.phone)
|
||||
}
|
||||
const latestBodyTest = getLatestBodyTestRecord(store)
|
||||
if (latestBodyTest) {
|
||||
const previous = store.bodyTest.records[1]
|
||||
@@ -60,11 +75,10 @@ function finalizeStore(store) {
|
||||
|
||||
function getDefaultStore() {
|
||||
return finalizeStore({
|
||||
profile: {},
|
||||
memberProfile: {},
|
||||
stats: {},
|
||||
cardInfo: {},
|
||||
card: {},
|
||||
cards: [],
|
||||
records: [],
|
||||
ongoingBookings: [],
|
||||
historyBookings: [],
|
||||
@@ -74,7 +88,11 @@ function getDefaultStore() {
|
||||
modules: getDefaultModuleState(),
|
||||
courseCatalog: getDefaultCourseCatalog(),
|
||||
couponPoints: {},
|
||||
referral: {}
|
||||
referral: {},
|
||||
storedCard: {
|
||||
balance: 0,
|
||||
zeroVerified: false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,11 +101,10 @@ export { getDefaultStore }
|
||||
function mergeDefaults(saved) {
|
||||
const defaults = getDefaultStore()
|
||||
return finalizeStore({
|
||||
profile: { ...defaults.profile, ...(saved.profile || {}) },
|
||||
memberProfile: { ...defaults.memberProfile, ...(saved.memberProfile || {}) },
|
||||
stats: { ...defaults.stats, ...(saved.stats || {}) },
|
||||
cardInfo: { ...defaults.cardInfo, ...(saved.cardInfo || {}) },
|
||||
card: { ...defaults.card, ...(saved.card || {}) },
|
||||
cards: saved.cards?.length ? saved.cards : defaults.cards,
|
||||
records: saved.records?.length ? saved.records : defaults.records,
|
||||
ongoingBookings: saved.ongoingBookings ?? defaults.ongoingBookings,
|
||||
historyBookings: saved.historyBookings ?? defaults.historyBookings,
|
||||
@@ -97,7 +114,8 @@ function mergeDefaults(saved) {
|
||||
modules: mergeModuleState(saved.modules),
|
||||
courseCatalog: mergeCourseCatalog(saved.courseCatalog),
|
||||
couponPoints: { ...defaults.couponPoints, ...(saved.couponPoints || {}) },
|
||||
referral: { ...defaults.referral, ...(saved.referral || {}) }
|
||||
referral: { ...defaults.referral, ...(saved.referral || {}) },
|
||||
storedCard: { ...defaults.storedCard, ...(saved.storedCard || {}) }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -193,21 +211,33 @@ export function getBookingPreview(store, limit = 2) {
|
||||
return store.ongoingBookings.slice(0, limit).map(toBookingPreviewItem)
|
||||
}
|
||||
|
||||
export function getExpiringCards(store, daysThreshold = 30) {
|
||||
if (!store.cards || store.cards.length === 0) {
|
||||
return []
|
||||
}
|
||||
return store.cards.filter(card => {
|
||||
const remainingDays = computeRemainingDays(card.validityEnd || card.expireTime)
|
||||
return remainingDays > 0 && remainingDays <= daysThreshold
|
||||
}).sort((a, b) => {
|
||||
const daysA = computeRemainingDays(a.validityEnd || a.expireTime)
|
||||
const daysB = computeRemainingDays(b.validityEnd || b.expireTime)
|
||||
return daysA - daysB
|
||||
})
|
||||
}
|
||||
|
||||
export function getCenterPageData(store) {
|
||||
const expiringCards = getExpiringCards(store, 30)
|
||||
return {
|
||||
userInfo: { ...store.memberProfile },
|
||||
stats: {
|
||||
checkInCount: store.stats?.checkInCount ?? 0,
|
||||
trainingHours: store.stats?.trainingHours ?? 0,
|
||||
pointsBalance: store.stats?.pointsBalance ?? 0
|
||||
},
|
||||
cardInfo: { ...store.cardInfo },
|
||||
expiringCards: expiringCards,
|
||||
bookingPreview: getBookingPreview(store),
|
||||
checkIns: store.checkIns.map((item) => ({ ...item })),
|
||||
bodyReport: {
|
||||
...store.bodyReport,
|
||||
weight: store.profile.weight || store.bodyReport.weight
|
||||
},
|
||||
bodyReport: { ...store.bodyReport },
|
||||
couponPoints: {
|
||||
...store.couponPoints,
|
||||
points: store.stats.pointsBalance
|
||||
@@ -290,16 +320,9 @@ export function renewMemberCard(store, addDays = 90) {
|
||||
}
|
||||
|
||||
export function saveUserProfile(store, profile) {
|
||||
const phone = normalizePhoneForStore(profile.phone ?? store.profile.phone)
|
||||
store.profile = { ...store.profile, ...profile, phone }
|
||||
store.memberProfile = {
|
||||
...store.memberProfile,
|
||||
name: store.profile.name,
|
||||
phone: formatMemberCenterPhone(store.profile.phone),
|
||||
avatar: store.profile.avatar || store.memberProfile.avatar
|
||||
}
|
||||
if (store.profile.weight) {
|
||||
store.bodyReport.weight = store.profile.weight
|
||||
// 不再保存profile到store,用户信息从loginMemberInfo获取
|
||||
if (profile.weight) {
|
||||
store.bodyReport.weight = profile.weight
|
||||
}
|
||||
finalizeStore(store)
|
||||
saveMemberStore(store)
|
||||
@@ -311,3 +334,17 @@ export function persistMemberStore(store) {
|
||||
saveMemberStore(store)
|
||||
return store
|
||||
}
|
||||
|
||||
export function getStoredCardBalance() {
|
||||
console.log('[storedCard] 余额不使用缓存,每次从后端读取')
|
||||
return null
|
||||
}
|
||||
|
||||
export function saveStoredCardBalance(balance) {
|
||||
console.log('[storedCard] 余额不使用缓存,跳过保存')
|
||||
return Number(balance) || 0
|
||||
}
|
||||
|
||||
export function clearStoredCardCache() {
|
||||
console.log('[storedCard] 余额不使用缓存,无需清除')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user