套餐管理添加IP检查状态字段 &修复套餐提取和购买的数量显示问题

This commit is contained in:
Eamon-meng
2026-04-22 10:27:19 +08:00
parent eb4c2d2d5f
commit 7ff42861f1
5 changed files with 28 additions and 19 deletions

View File

@@ -230,6 +230,17 @@ export default function ResourceList({resourceType}: ResourceListProps) {
)
},
},
{
header: 'IP检查状态',
cell: ({row}) => {
const checkip = row.original.checkip
return (
<span className={checkip ? 'text-green-500' : 'text-red-500'}>
{checkip ? '启用IP检查' : '停用IP检查'}
</span>
)
},
},
]
// 短效资源增加到期时间列

View File

@@ -29,36 +29,32 @@ export default function Center({skuData}: {
const currentCountMin = useMemo(() => {
if (!type || !live) return 0
const expireValue = type === '1' ? expire : '0'
return getPurchaseSkuCountMin(skuData, {mode: type, live, expire: expireValue})
const countMin = getPurchaseSkuCountMin(skuData, {
mode: type,
live,
expire: expireValue,
})
return countMin
}, [type, live, expire, skuData])
useEffect(() => {
if (type === '1') {
const current = getValues('daily_limit')
if (current < currentCountMin) {
setValue('daily_limit', currentCountMin)
}
}
else {
const current = getValues('quota')
if (current < currentCountMin) {
setValue('quota', currentCountMin)
}
if (currentCountMin <= 0) return
const targetField = type === '1' ? 'daily_limit' : 'quota'
const currentValue = getValues(targetField)
if (currentValue !== currentCountMin) {
setValue(targetField, currentCountMin, {shouldValidate: true})
}
}, [currentCountMin, type, setValue, getValues])
useEffect(() => {
const nextType = modeList.includes(type) ? type : modeList[0]
if (!nextType) {
return
}
if (nextType !== type) {
setValue('type', nextType)
return
}
const nextLiveList = nextType === '1'
? getAvailablePurchaseLives(skuData, {mode: nextType, expire})
: getAvailablePurchaseLives(skuData, {mode: nextType})

View File

@@ -11,7 +11,7 @@ export function BillingMethodField(props: {
modeList: PurchaseMode[]
timeDailyLimit: number
}) {
const {setValue} = useFormContext<PurchaseFormValues>()
const {setValue, getValues} = useFormContext<PurchaseFormValues>()
return (
<FormField<PurchaseFormValues, 'type'>
@@ -30,8 +30,7 @@ export function BillingMethodField(props: {
setValue('expire', '0')
return
}
setValue('daily_limit', props.timeDailyLimit)
setValue('expire', getValues('expire') || '0')
}}
className="flex gap-4 max-md:flex-col"
>

View File

@@ -36,9 +36,11 @@ export default function Center({
useEffect(() => {
if (currentCountMin <= 0) return
const targetField = type === '1' ? 'daily_limit' : 'quota'
const currentValue = getValues(targetField)
if (currentValue < currentCountMin) {
if (currentValue !== currentCountMin) {
setValue(targetField, currentCountMin, {shouldValidate: true})
}
}, [currentCountMin, type, setValue, getValues])

View File

@@ -29,6 +29,7 @@ export type Resource<T extends 1 | 2 = 1 | 2> = {
active: boolean
created_at: Date
updated_at: Date
checkip: boolean
} & (
T extends 1 ? {
type: 1