🚑️ hotfix: 修复红包组件校验bug

This commit is contained in:
wangsongsole 2023-06-27 09:50:18 +08:00
parent 6ae2d4ae52
commit 61bd2d0e9c
1 changed files with 13 additions and 25 deletions

View File

@ -1,6 +1,6 @@
import { Notify } from "zent"
import isArray from "lodash/isArray"
import uniq from "lodash/uniq"
import cloneDeep from "lodash/cloneDeep"
const fP = /^\d+(\.\d{1,2})?$/
const regObj = {
type: "regExp",
@ -44,7 +44,15 @@ export default {
}
/* 额外验证规则 */
export function additionalRules({ model, computeMax }) {
export function additionalRules(params) {
const model = cloneDeep(params.model)
model.all_budget = Number(model.all_budget)
model.day_budget = Number(model.day_budget)
model.receive_num = Number(model.receive_num)
model.num = Number(model.num)
model.min_denomination = Number(model.min_denomination)
model.max_denomination = Number(model.max_denomination)
model.denomination = Number(model.denomination)
/* 验证每日可领 */
if (model.receive_type === 3) {
if (model.receive_day.length < 1) {
@ -141,11 +149,6 @@ export function additionalRules({ model, computeMax }) {
return false
}
if (model.all_budget - 0 < model.day_budget - 0) {
Notify.error("单天预算发放上限不允许大于总预算")
return false
}
/* 预警人数 */
if (model.early_notifier.length > 14) {
Notify.error("目前仅支持新增10个预警通知人")
@ -163,17 +166,17 @@ export function additionalRules({ model, computeMax }) {
return rulesRandom(model, 0.01)
}
if (model.all_budget < model.min_denomination * model.num) {
if (Number(model.all_budget) < model.min_denomination * model.num) {
Notify.error("总预算不得小于(最小面额 x 红包个数)")
return false
}
if (model.max_denomination < model.min_denomination) {
if (Number(model.max_denomination) < model.min_denomination) {
Notify.error("随机最小面额不允许大于随机计算最大面额")
return false
}
if (model.all_budget < model.all_budget / model.num) {
if (Number(model.all_budget) < model.all_budget / model.num) {
Notify.error("最大面额不得小于最大面额中的最小值")
return false
}
@ -233,21 +236,6 @@ function rulesFixed(model, num) {
}
}
function testDateFunction(arr) {
return arr.map((item) => setTime(item)).filter((item) => item)
}
//限制时间
function setTime(data) {
if (!isArray(data) || data?.length === 0) return true
const newData = data.map((item) => Boolean(item))
let blr = null
newData.map((item) => {
if (!item) blr = true
})
return blr
}
/* 处理时间交集 */
function detectTimeConflict(arr) {
for (var i = 0; i < arr.length; i++) {