feat: 查积分、支付、拆弹、取消订单

This commit is contained in:
2026-07-28 18:39:34 +08:00
parent 53305757f8
commit c443109869
40 changed files with 1814 additions and 163 deletions
+36 -7
View File
@@ -3,6 +3,7 @@ import { postFunction } from '@/api/supplied-service'
const USER_KEY = 'joyful-selection-user'
const DEFAULT_SUPPLIER_IDENTIFICATION = (process.env.VUE_APP_SUPPLIER_IDENTIFICATION || '').toLowerCase()
let bridgeTokenPromise = null
const readUser = () => {
try {
@@ -22,10 +23,10 @@ export const useUserStore = defineStore('joyfulSelectionUser', {
supplierIdentification: '',
supplierId: '',
supplierName: '',
clientId: '',
token: '',
refreshToken: '',
tokenExpiresAt: 0,
pointsBalance: 0,
loaded: false,
loadingToken: false
}),
@@ -42,10 +43,10 @@ export const useUserStore = defineStore('joyfulSelectionUser', {
this.supplierIdentification = supplierIdentification
this.supplierId = supplierChanged ? '' : data.supplierId || ''
this.supplierName = supplierChanged ? '' : data.supplierName || ''
this.clientId = supplierChanged ? '' : data.clientId || ''
this.token = supplierChanged ? '' : data.token || ''
this.refreshToken = supplierChanged ? '' : data.refreshToken || ''
this.tokenExpiresAt = supplierChanged ? 0 : Number(data.tokenExpiresAt || 0)
this.pointsBalance = supplierChanged ? 0 : Number(data.pointsBalance || 0)
this.loaded = true
},
persistUser() {
@@ -54,10 +55,10 @@ export const useUserStore = defineStore('joyfulSelectionUser', {
supplierIdentification: this.supplierIdentification,
supplierId: this.supplierId,
supplierName: this.supplierName,
clientId: this.clientId,
token: this.token,
refreshToken: this.refreshToken,
tokenExpiresAt: this.tokenExpiresAt
tokenExpiresAt: this.tokenExpiresAt,
pointsBalance: this.pointsBalance
})
this.loaded = true
},
@@ -73,6 +74,7 @@ export const useUserStore = defineStore('joyfulSelectionUser', {
this.token = ''
this.refreshToken = ''
this.tokenExpiresAt = 0
this.pointsBalance = 0
}
if (!this.supplierIdentification) {
this.supplierIdentification = DEFAULT_SUPPLIER_IDENTIFICATION
@@ -100,19 +102,21 @@ export const useUserStore = defineStore('joyfulSelectionUser', {
this.supplierId = data?.supplierId || ''
this.supplierName = data?.supplierName || ''
this.clientId = data?.clientId || ''
this.persistUser()
},
async fetchBridgeToken() {
if (!this.loaded) {
this.loadUser()
}
if (!this.userId || !this.supplierIdentification || this.loadingToken || this.hasToken) {
if (!this.userId || !this.supplierIdentification || this.hasToken) {
return
}
if (this.loadingToken && bridgeTokenPromise) {
return bridgeTokenPromise
}
this.loadingToken = true
try {
bridgeTokenPromise = (async () => {
if (!this.supplierId) {
await this.fetchSupplierInfo()
}
@@ -129,9 +133,34 @@ export const useUserStore = defineStore('joyfulSelectionUser', {
const expiresIn = Number(data?.expiresIn || 0)
this.tokenExpiresAt = this.token && expiresIn > 0 ? Date.now() + expiresIn * 1000 : 0
this.persistUser()
})()
try {
await bridgeTokenPromise
} finally {
this.loadingToken = false
bridgeTokenPromise = null
}
},
async fetchUserPoints() {
if (!this.loaded) {
this.loadUser()
}
await this.fetchBridgeToken()
if (!this.userId || !this.supplierId || !this.token) {
return this.pointsBalance
}
const data = await postFunction('supplier-points', {
userId: this.userId,
supplierId: this.supplierId,
token: this.token
})
this.pointsBalance = Number(data?.userPoints || 0)
this.persistUser()
return this.pointsBalance
}
}
})