优化完善套餐购买页面
This commit is contained in:
38
src/components/composites/purchase/shared/resource.ts
Normal file
38
src/components/composites/purchase/shared/resource.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {CreateResourceReq} from '@/actions/resource'
|
||||
|
||||
export type PurchaseKind = 'short' | 'long'
|
||||
export type PurchaseMode = '1' | '2'
|
||||
|
||||
export type PurchaseSelection = {
|
||||
kind: PurchaseKind
|
||||
mode: PurchaseMode
|
||||
live: string
|
||||
quota: number
|
||||
expire: string
|
||||
dailyLimit: number
|
||||
}
|
||||
|
||||
function getPurchasePayload(selection: PurchaseSelection) {
|
||||
return {
|
||||
mode: Number(selection.mode),
|
||||
live: Number(selection.live),
|
||||
expire: selection.mode === '1' ? Number(selection.expire) : undefined,
|
||||
quota: selection.mode === '1' ? Number(selection.dailyLimit) : Number(selection.quota),
|
||||
}
|
||||
}
|
||||
|
||||
export function buildPurchaseResource(selection: PurchaseSelection): CreateResourceReq {
|
||||
const payload = getPurchasePayload(selection)
|
||||
|
||||
if (selection.kind === 'short') {
|
||||
return {
|
||||
type: 1,
|
||||
short: payload,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: 2,
|
||||
long: payload,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user