Skip to content

Commit

Permalink
feat: operator equal not_equal contains check logic end
Browse files Browse the repository at this point in the history
  • Loading branch information
Liberty-liu committed May 8, 2023
1 parent 9ac7698 commit 822f48b
Show file tree
Hide file tree
Showing 6 changed files with 1,247 additions and 25 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"lint": "eslint . --ext .js,.jsx,.vue",
"lint-fix": "eslint --fix . --ext .js,.jsx,.vue",
"prepare": "husky install",
"init": "node ./server/db/generateDatabase.js && mkdir uploads"
"init": "node ./server/db/generateDatabase.js && mkdir uploads",
"test": "vitest",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@vant/area-data": "^1.4.0",
Expand Down Expand Up @@ -88,6 +90,7 @@
"sass": "^1.58.3",
"vite": "^3.2.5",
"vite-plugin-eslint": "^1.8.1",
"vitest": "^0.31.0",
"vue-router": "^4.1.6"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/formEditor/preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ provide('Everright', {
getData,
props
})
window.state = state
const setData2 = (data, value) => {
const newData = _.cloneDeep(data)
layout.pc = newData.layout.pc
Expand Down
26 changes: 21 additions & 5 deletions packages/hooks/use-logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const getDataType = (fieldType) => {
const equal = (logicValue, value, filedType) => {
// console.log(logicValue)
// console.log(value)
if (filedType === 'region') {
return _.includes(logicValue, value)
}
if (_.isString(value) || _.isNumber(value)) {
return _.isEqual(logicValue, value)
}
Expand All @@ -48,23 +51,36 @@ const equal = (logicValue, value, filedType) => {
return !!logicValue === value
}
}
const validator = (logic, value, filed) => {
const notEqual = (...e) => {
return !equal(...e)
}
const contains = (logicValue, value, filedType) => {
if (_.isString(value)) {
return logicValue.some((v) => _.includes(value, v))
}
if (_.isArray(value)) {
return !!_.intersection(logicValue, value).length
}
}
export const validator = (logic, value, filed) => {
let result = false
// console.log(filed)
switch (logic.operator) {
case 'equal':
// console.log(logic.value)
// console.log(`操作符的值:${logic.value} type: ${typeof logic.value}`)
// console.log(value)
// console.log(`field的值:${value} type: ${typeof value}`)
// result = logic.value === value
result = equal(logic.value, value, filed.type)
break
case 'one_of':
break
case 'not_equal':
result = notEqual(logic.value, value, filed.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)
break
case 'not_contain':
break
Expand Down
44 changes: 25 additions & 19 deletions packages/utils/generateFilterdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
value: 'equal',
style: 'noop'
},
{
label: '等于其中之一',
value: 'one_of',
style: 'tags'
},
// {
// label: '等于其中之一',
// value: 'one_of',
// style: 'tags'
// },
{
label: '不等于',
value: 'not_equal',
Expand All @@ -23,12 +23,12 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
{
label: '包含',
value: 'contains',
style: 'noop'
style: 'tags'
},
{
label: '不包含',
value: 'not_contain',
style: 'noop'
style: 'tags'
},
{
label: '为空',
Expand Down Expand Up @@ -128,23 +128,23 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
filterNode.renderType = 'SELECT'
filterNode.operatorKey = 'Text'
filterNode.multiple = true
filterNode.excludeOperator = {
operator: [
'contains',
'not_contain'
]
}
// filterNode.excludeOperator = {
// operator: [
// 'contains',
// 'not_contain'
// ]
// }
break
case 'select':
filterNode.renderType = 'SELECT'
filterNode.operatorKey = 'Text'
filterNode.multiple = node.options.multiple
filterNode.excludeOperator = {
operator: [
'contains',
'not_contain'
]
}
// filterNode.excludeOperator = {
// operator: [
// 'contains',
// 'not_contain'
// ]
// }
break
case 'switch':
filterNode.renderType = 'SELECT'
Expand All @@ -169,6 +169,12 @@ const generateIfFilterOptionsData = (activeTab, fields) => {
disabled: 'disabled'
}
}
filterNode.excludeOperator = {
operator: [
'contains',
'not_contain'
]
}
break
case 'time':
filterNode.renderType = 'TIME'
Expand Down
Loading

0 comments on commit 822f48b

Please sign in to comment.