complex-data
Advanced tools
+4
-0
@@ -29,2 +29,6 @@ | ||
| ### `4.10.7` | ||
| - feat(SimpleDateEdit): `rangeLimit`配置扩展,添加相等判断和信息提示,并优化修正相关功能。 | ||
| - feat(DefaultEdit): 添加`ruleMessage`配置项以及相关的默认值,实现快速定义ruleMessage的功能。 | ||
| ### `4.10.6` | ||
@@ -31,0 +35,0 @@ - feat(SimpleDateEdit): 添加`complexDisabledDate`配置项,协调`rangeLimit`一起,存在其中一个参数时`disabledDate`禁用时间判断函数将额外传递参数实现复杂判断。 |
+1
-1
| { | ||
| "name": "complex-data", | ||
| "version": "4.10.6", | ||
| "version": "4.10.7", | ||
| "description": "a complex data", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -14,2 +14,3 @@ import SimpleDateEdit, { SimpleDateEditInitOption } from "./SimpleDateEdit" | ||
| static $range = true | ||
| static $defaultRuleMessage = '请正确选择开始结束时间' | ||
| static $defaultPlaceholder = function (_name: string) { | ||
@@ -16,0 +17,0 @@ return `开始日期` |
@@ -29,2 +29,3 @@ import { deepCloneData, hasProp, isArray, isComplex } from "complex-utils" | ||
| placeholder?: false | string | ||
| ruleMessage?: string | ||
| value?: { | ||
@@ -49,3 +50,5 @@ default?: any | ||
| static $defaultPlaceholder = (name: string) => `请输入${name}` | ||
| static $defaultRuleMessage = '' | ||
| static $parseRuleList = function($constructor: typeof DefaultEdit<boolean>, target: DefaultEdit<boolean>, formData: Record<PropertyKey, any>, _type?: string) { | ||
| const ruleMessage = target.ruleMessage || target.placeholder | ||
| if (target.$rules) { | ||
@@ -57,4 +60,4 @@ return target.$rules.map(rule => { | ||
| } | ||
| if (ruleValue.message == undefined && target.placeholder) { | ||
| ruleValue.message = target.placeholder | ||
| if (ruleValue.message == undefined && ruleMessage) { | ||
| ruleValue.message = ruleMessage | ||
| } | ||
@@ -70,3 +73,3 @@ return $constructor.$parseRule(ruleValue, formData) | ||
| type: 'array', | ||
| message: target.placeholder, | ||
| message: ruleMessage, | ||
| validator(value) { | ||
@@ -94,2 +97,3 @@ return isArray(value) && value.length > 0 | ||
| placeholder?: string | ||
| ruleMessage?: string | ||
| $rules?: ruleOption[] | ||
@@ -129,5 +133,11 @@ $value: { | ||
| } | ||
| if (this.simple.rules !== true && initOption.rules) { | ||
| if (this.simple.rules !== true) { | ||
| // rule | ||
| this.$rules = initOption.rules | ||
| if (initOption.rules) { | ||
| this.$rules = initOption.rules | ||
| } | ||
| const ruleMessage = initOption.ruleMessage || $constructor.$defaultRuleMessage | ||
| if (ruleMessage) { | ||
| this.ruleMessage = ruleMessage | ||
| } | ||
| } | ||
@@ -134,0 +144,0 @@ if (initOption.deepClone && this.parse === undefined) { |
@@ -11,2 +11,8 @@ import { isArray } from 'complex-utils' | ||
| export type rangeLimitType = { | ||
| value: number | ||
| eq?: boolean | ||
| message?: (offset: number, payload: editPayloadType) => undefined | string | ||
| } | ||
| export type dateConfig = { start?: dateConfigValue, end?: dateConfigValue } | ||
@@ -19,3 +25,3 @@ | ||
| complexDisabledDate: boolean | ||
| disabledDate?: (value: any, payload?: editPayloadType, rangeLimit?: number) => boolean | ||
| disabledDate?: (value: any, payload?: editPayloadType, rangeLimit?: rangeLimitType) => boolean | ||
| time?: { | ||
@@ -33,3 +39,3 @@ format: string | ||
| complexDisabledDate?: boolean | ||
| disabledDate?: dateConfig | ((value: any, payload?: editPayloadType, rangeLimit?: number) => boolean) | ||
| disabledDate?: dateConfig | ((value: any, payload?: editPayloadType, rangeLimit?: rangeLimitType) => boolean) | ||
| time?: { | ||
@@ -44,3 +50,3 @@ format?: string | ||
| separator?: string | ||
| rangeLimit?: number // 时间范围时间间隔字段,仅range模式下生效,按照秒限制时间范围选择 | ||
| rangeLimit?: rangeLimitType // 时间范围时间间隔字段,仅range模式下生效,按照秒限制时间范围选择 | ||
| endProp?: string // 结束时间字段,存在则将数组解析,仅range模式下生效 | ||
@@ -116,3 +122,20 @@ time?: { | ||
| static $compareDate = (target: any, other: any) => (other as Date).getTime() - (target as Date).getTime() | ||
| static $disabledDate = (option: dateConfig) => (value: unknown, payload?: editPayloadType, rangeLimit?: number) => { | ||
| static $parseDisabledDateByRangeLimit = function(disable: boolean, value: unknown, payload?: editPayloadType, rangeLimit?: rangeLimitType) { | ||
| if (payload && rangeLimit) { | ||
| // 时间范围选择器 | ||
| const currentRangeValue = payload.targetData[payload.prop] | ||
| if (currentRangeValue) { | ||
| const [startValue, endValue] = currentRangeValue | ||
| const targetValue = startValue && endValue ? undefined : (startValue || endValue) | ||
| if (targetValue) { | ||
| const offset = Math.abs(SimpleDateEdit.$compareDate(targetValue, value)) | ||
| if (!rangeLimit.eq ? offset >= (rangeLimit.value * 1000) : offset > (rangeLimit.value * 1000)) { | ||
| disable = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return disable | ||
| } | ||
| static $disabledDate = (option: dateConfig) => (value: unknown, payload?: editPayloadType, rangeLimit?: rangeLimitType) => { | ||
| const start = option.start | ||
@@ -133,21 +156,13 @@ const end = option.end | ||
| } | ||
| if (!disable && payload && rangeLimit) { | ||
| // 时间范围选择器 | ||
| const currentRangeValue = payload.targetData[payload.prop] | ||
| if (currentRangeValue) { | ||
| const [startValue, endValue] = currentRangeValue | ||
| const targetValue = startValue && endValue ? undefined : (startValue || endValue) | ||
| if (targetValue) { | ||
| const offset = Math.abs(SimpleDateEdit.$compareDate(targetValue, value)) | ||
| if (offset > rangeLimit * 1000) { | ||
| disable = true | ||
| } | ||
| } | ||
| } | ||
| if (!disable) { | ||
| disable = SimpleDateEdit.$parseDisabledDateByRangeLimit(disable, value, payload, rangeLimit) | ||
| } | ||
| return disable | ||
| } | ||
| static $rangeLimitDisabledDate = (value: unknown, payload?: editPayloadType, rangeLimit?: rangeLimitType) => { | ||
| return SimpleDateEdit.$parseDisabledDateByRangeLimit(false, value, payload, rangeLimit) | ||
| } | ||
| static $parseRuleList = function($constructor: typeof DefaultEdit<boolean>, target: DefaultEdit<boolean>, formData: Record<PropertyKey, any>, _type?: string) { | ||
| let ruleList = DefaultEdit.$parseRuleList($constructor, target, formData, _type) | ||
| if (!ruleList && ($constructor as typeof SimpleDateEdit<boolean>).$range) { | ||
| if (!ruleList && ($constructor as typeof SimpleDateEdit<boolean>).$range && target.required) { | ||
| // 时间范围选择器 | ||
@@ -158,5 +173,5 @@ ruleList = [ | ||
| type: 'array', | ||
| message: target.placeholder, | ||
| message: target.ruleMessage, | ||
| validator(value) { | ||
| return isArray(value) && !!value[0] && !!value[1] | ||
| return isArray(value) | ||
| } | ||
@@ -215,2 +230,4 @@ }, formData) | ||
| this.$option.disabledDate = typeof option.disabledDate === 'object' ? $constructor.$disabledDate(option.disabledDate) : option.disabledDate | ||
| } else if((this.$option as SimpleDateEditOption<true>).rangeLimit) { | ||
| this.$option.disabledDate = $constructor.$rangeLimitDisabledDate | ||
| } | ||
@@ -217,0 +234,0 @@ this.parse = this.parse ?? ($constructor.$range ? defaultRangeParse : defaultParse) as functionType<any> |
287526
0.53%7071
0.38%