动态生成购买套餐 & 取消初次进后台修改密码的弹窗 & 添加总折扣字段 & 发布v1.5.0版本
This commit is contained in:
@@ -5,28 +5,52 @@ import Right from '@/components/composites/purchase/short/right'
|
||||
import {Form} from '@/components/ui/form'
|
||||
import * as z from 'zod'
|
||||
import {zodResolver} from '@hookform/resolvers/zod'
|
||||
import {ProductItem} from '@/actions/product'
|
||||
|
||||
// 定义表单验证架构
|
||||
const schema = z.object({
|
||||
type: z.enum(['1', '2']).default('2'),
|
||||
live: z.enum(['3', '5', '10', '15', '30']),
|
||||
quota: z.number().min(10000, '购买数量不能少于10000个'),
|
||||
expire: z.enum(['7', '15', '30', '90', '180', '365']),
|
||||
daily_limit: z.number().min(2000, '每日限额不能少于2000个'),
|
||||
pay_type: z.enum(['wechat', 'alipay', 'balance']),
|
||||
live: z.string(),
|
||||
quota: z.number().min(10000, '购买数量不能少于 10000 个'),
|
||||
expire: z.string(),
|
||||
daily_limit: z.number().min(2000, '每日限额不能少于 2000 个'),
|
||||
pay_type: z.enum(['wechat', 'alipay', 'balance']).default('balance'),
|
||||
})
|
||||
|
||||
// 从架构中推断类型
|
||||
export type Schema = z.infer<typeof schema>
|
||||
|
||||
export default function ShortForm() {
|
||||
export default function ShortForm({skuList}: {skuList: ProductItem['skus']}) {
|
||||
if (!skuList?.length) throw new Error('没有套餐数据')
|
||||
|
||||
const priceMap = new Map<string, string>()
|
||||
const _liveList = new Set<number>()
|
||||
const _expireList = new Set<number>()
|
||||
|
||||
for (const sku of skuList) {
|
||||
const params = new URLSearchParams(sku.code)
|
||||
const mode = params.get('mode')
|
||||
const live = params.get('live')
|
||||
const expire = params.get('expire')
|
||||
|
||||
if (live && live !== '0') {
|
||||
_liveList.add(Number(live))
|
||||
}
|
||||
if (mode === 'time' && expire && expire !== '0') {
|
||||
_expireList.add(Number(expire))
|
||||
}
|
||||
priceMap.set(sku.code, sku.price)
|
||||
}
|
||||
|
||||
const liveList = Array.from(_liveList).filter(Boolean).map(String)
|
||||
const expireList = Array.from(_expireList).filter(Boolean).map(String)
|
||||
|
||||
const form = useForm<Schema>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
type: '2', // 默认为包量套餐
|
||||
live: '3', // 分钟
|
||||
quota: 10_000, // >= 10000
|
||||
expire: '30', // 天
|
||||
live: liveList[0] || '',
|
||||
expire: '0', // 包量模式下无效
|
||||
quota: 10_000, // >= 10000,
|
||||
daily_limit: 2_000, // >= 2000
|
||||
pay_type: 'balance', // 余额支付
|
||||
},
|
||||
@@ -34,8 +58,8 @@ export default function ShortForm() {
|
||||
|
||||
return (
|
||||
<Form form={form} className="flex flex-col lg:flex-row gap-4">
|
||||
<Center/>
|
||||
<Right/>
|
||||
<Center {...{priceMap, liveList, expireList}}/>
|
||||
<Right {...{skuList, priceMap}}/>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user