Skip to content

Commit

Permalink
feat: empty not_empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Liberty-liu committed May 8, 2023
1 parent f961a08 commit eee3e2b
Show file tree
Hide file tree
Showing 5 changed files with 715 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const handleAction = (type) => {
break
case 2:
if (tabs.value.every(tab => !tab.rules.length)) {
ER.state.logic = {}
closeDialog()
} else {
const data = getData()
Expand Down
45 changes: 29 additions & 16 deletions packages/hooks/use-logic/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, watch } from 'vue'
import _ from 'lodash-es'
import utils from '@ER/utils'
const findValidityRule = (state) => {
const result = {}
for (const logicType in state.logic) {
Expand Down Expand Up @@ -32,19 +33,16 @@ const getDataType = (fieldType) => {
}
return result
}
const equal = (logicValue, value, filedType) => {
const equal = (logicValue, value, fieldType) => {
// console.log(logicValue)
// console.log(value)
if (filedType === 'region') {
if (fieldType === 'region') {
return _.includes(logicValue, value)
}
if (_.isString(value) || _.isNumber(value)) {
return _.isEqual(logicValue, value)
}
if (_.isArray(value)) {
// if (/^(select|checkbox)$/.test(filedType)) {
// return logicValue.length === value.length && _.isEqual(_.chain(logicValue).clone().flattenDeep().sort().value(), _.chain(value).clone().flattenDeep().sort().value())
// }
return _.isEqual(_.chain(logicValue).clone().flattenDeep().sort().value(), _.chain(value).clone().flattenDeep().sort().value())
}
if (_.isBoolean(value)) {
Expand All @@ -54,7 +52,7 @@ const equal = (logicValue, value, filedType) => {
const notEqual = (...e) => {
return !equal(...e)
}
const contains = (logicValue, value, filedType) => {
const contains = (logicValue, value, fieldType) => {
if (_.isString(value)) {
return logicValue.some((v) => _.includes(value, v))
}
Expand All @@ -65,32 +63,44 @@ const contains = (logicValue, value, filedType) => {
const notContains = (...e) => {
return !contains(...e)
}
export const validator = (logic, value, filed) => {
const empty = (logicValue, value, fieldType) => {
if (fieldType === 'rate') {
return value === 0 || utils.isEmpty(value)
}
return utils.isEmpty(value)
}
const notEmpty = (...e) => {
return !empty(...e)
}
export const validator = (logic, value, field) => {
let result = false
// console.log(filed)
// console.log(field)
switch (logic.operator) {
case 'equal':
// result = logic.value === value
result = equal(logic.value, value, filed.type)
result = equal(logic.value, value, field.type)
break
case 'one_of':
break
case 'not_equal':
result = notEqual(logic.value, value, filed.type)
result = notEqual(logic.value, value, field.type)
break
case 'contains':
// console.log(logic.value)
// console.log(`操作符的值:${logic.value} type: ${typeof logic.value}`)
// console.log(value)
// console.log(`field的值:${value} type: ${typeof value}`)
result = contains(logic.value, value, filed.type)
result = contains(logic.value, value, field.type)
break
case 'not_contain':
result = notContains(logic.value, value, filed.type)
result = notContains(logic.value, value, field.type)
break
case 'empty':
// console.log(logic.value)
// console.log(`操作符的值:${logic.value} type: ${typeof logic.value}`)
// console.log(value)
// console.log(`field的值:${value} type: ${typeof value}`)
// console.log(field)
result = empty(logic.value, value, field.type)
break
case 'not_empty':
result = notEmpty(logic.value, value, field.type)
break
case 'greater_than':
break
Expand Down Expand Up @@ -118,6 +128,9 @@ const operatingShowHidden = (fields, rules) => {
// console.log(operator(values.map((value, index) => validator(rule.if.conditions[index], value, getDataType(targetFields[index].type)))))
console.log(operator(values.map((value, index) => validator(rule.if.conditions[index], value, targetFields[index]))))
// console.log(values.map((value, index) => validator(rule.if.conditions[index], value, getDataType(targetFields[index].type))))
}, {
immediate: true,
deep: true
})
// console.log(rule.if.conditions.map(e => e.property))
})
Expand Down
16 changes: 15 additions & 1 deletion packages/utils/generateFilterdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,22 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
}
break
case 'number':
filterNode.renderType = 'NUMBER'
filterNode.operatorKey = 'Number'
break
case 'rate':
filterNode.renderType = 'NUMBER'
filterNode.operatorKey = 'Number'
break
case 'slider':
filterNode.renderType = 'NUMBER'
filterNode.operatorKey = 'Number'
filterNode.excludeOperator = {
operator: [
'not_empty',
'empty'
]
}
break
case 'radio':
filterNode.renderType = 'SELECT'
Expand Down Expand Up @@ -152,7 +164,9 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
filterNode.excludeOperator = {
operator: [
'contains',
'not_contain'
'not_contain',
'not_empty',
'empty'
]
}
break
Expand Down
1 change: 1 addition & 0 deletions packages/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isEmpty = (v) => (v === '' || v === null || v === undefined || (Array.isArray(v) && !v.length))
Loading

0 comments on commit eee3e2b

Please sign in to comment.