123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- -- 动作转化
- local root = {}
- function root:initFuncMap()
- self.operateFunMap = {
- ["kv"] = self.isTableMatch,
- ["=="] = self.isConditionEqual,
- [">"] = self.isConditionGreater,
- [">="] = self.isConditionEqualGreater,
- ["<"] = self.isConditionLess,
- ["<="] = self.isConditionEqualLess,
- ["="] = self.isConditionEqual,
- ["~="] = self.isConditionNotEqual,
- ["!="] = self.isConditionNotEqual,
- ["sam"] = self.isConditionSameMember,
- ["unsam"] = self.isConditionNotSameMember,
- ["!sam"] = self.isConditionNotSameMember,
- [">inc"] = self.isConditionLinclude,
- ["<inc"] = self.isConditionRinclude,
- [">uninc"] = self.isConditionNotLinclude,
- ["<uninc"] = self.isConditionNotRinclude,
- ["!>inc"] = self.isConditionNotLinclude,
- ["!<inc"] = self.isConditionNotRinclude,
- ["range"] = self.isConditionRange,
- ["unrange"] = self.isConditionNotRange,
- ["!range"] = self.isConditionNotRange,
- -- 支持中文
- ["等于"] = self.isConditionEqual,
- ["大于"] = self.isConditionGreater,
- ["大于等于"] = self.isConditionEqualGreater,
- ["等于大于"] = self.isConditionEqualGreater,
- ["小于"] = self.isConditionLess,
- ["小于等于"] = self.isConditionEqualLess,
- ["等于小于"] = self.isConditionEqualLess,
- ["不等于"] = self.isConditionNotEqual,
- ["包含范围"] = self.isConditionRange,
- ["不包含范围"] = self.isConditionNotRange,
- ["相同成员"] = self.isConditionSameMember,
- ["无相同成员"] = self.isConditionNotSameMember
- }
- end
- -- 操作条件
- function root:isActionCondition(val, operate, ...)
- if val == nil or operate == nil then
- return false
- end
- if self.operateFunMap == nil then
- self:initFuncMap()
- end
- if self.operateFunMap then
- for k, fun in pairs(self.operateFunMap) do
- if k == operate then
- return fun(self, val, ...)
- end
- end
- end
- return false
- end
- -- table 匹配
- function root:isTableMatch(val, tabKey, tabVal)
- if type(val) ~= "table" then
- return false
- end
- if not tabKey or not tabVal then
- return true
- end
- for key, value in ipairs(val) do
- if key == tabKey and tabVal >= value then
- return true
- end
- end
- return false
- end
- -- 等于
- function root:isConditionEqual(val, condValue)
- return val and val == condValue
- end
- -- 不等于
- function root:isConditionNotEqual(val, condValue)
- return val and val ~= condValue
- end
- -- 大于
- function root:isConditionGreater(val, condValue)
- return val and condValue and val > condValue
- end
- -- 大于等于
- function root:isConditionEqualGreater(val, condValue)
- return val and condValue and val >= condValue
- end
- -- 小于
- function root:isConditionLess(val, condValue)
- return val and condValue and val < condValue
- end
- -- 小于等于
- function root:isConditionEqualLess(val, condValue)
- return val and condValue and val <= condValue
- end
- -- 是否范围值
- function root:isRangeValue(v, range)
- if type(range) ~= "table" or #range ~= 2 then
- return false
- end
- local isMinLimit = false
- local isMaxLimit = false
- if string.lower(range[1]) == "z" then
- isMinLimit = true
- end
- if range[2] == -1 or string.lower(range[2]) == "z" then
- isMaxLimit = true
- end
- if not isMinLimit and not isMaxLimit then
- if v >= range[1] and v <= range[2] then
- return true
- end
- else
- if not isMinLimit then
- if v < range[1] then
- return false
- end
- end
- if not isMaxLimit then
- if v > range[2] then
- return false
- end
- end
- return true
- end
- return false
- end
- -- 包含范围
- function root:isConditionRange(val, condValue)
- if val == nil or condValue == nil then
- return false
- end
- if type(condValue) ~= "table" then
- return false
- end
- return root:isRangeValue(val, condValue)
- end
- -- 有共同项
- function root:isConditionSameMember(val, condValue)
- local valTable = type(val) == "table" and val or {val}
- local condTable = type(condValue) == "table" and condValue or {condValue}
- for k, v in ipairs(condTable) do
- if table.include(valTable, v) then
- return true
- end
- end
- return false
- end
- -- 无共同项
- function root:isConditionNotSameMember(val, condValue)
- return not self:isConditionSameMember(val, condValue)
- end
- -- 不包含范围
- function root:isConditionNotRange(val, condValue)
- if val == nil or condValue == nil then
- return false
- end
- if type(condValue) ~= "table" then
- return false
- end
- return not root:isRangeValue(val, condValue)
- end
- -- 左被包含
- function root:isConditionLinclude(val, condValue)
- if val == nil or condValue == nil then
- return false
- end
- -- 配置参数必须为table
- local tbConf = nil
- if type(condValue) == "table" then
- tbConf = condValue
- else
- tbConf = {condValue}
- end
- if type(val) ~= "table" then
- return table.include(tbConf, val)
- end
- for k, v in ipairs(val) do
- if not table.include(tbConf, v) then
- return false
- end
- end
- return true
- end
- -- 右被包含
- function root:isConditionRinclude(val, condValue)
- if val == nil or condValue == nil then
- return false
- end
- -- 入参必须为table
- local tbConf = nil
- if type(val) == "table" then
- tbConf = val
- else
- tbConf = {val}
- end
- if type(condValue) ~= "table" then
- return table.include(tbConf, condValue)
- end
- for k, v in ipairs(condValue) do
- if not table.include(tbConf, v) then
- return false
- end
- end
- return true
- end
- -- 左被不包含
- function root:isConditionNotLinclude(val, condValue)
- if val == nil or condValue == nil then
- return false
- end
- -- 入参必须为table
- local tbConf = nil
- if type(condValue) == "table" then
- tbConf = condValue
- else
- tbConf = {condValue}
- end
- if type(val) ~= "table" then
- return not table.include(tbConf, val)
- end
- for k, v in ipairs(val) do
- if table.include(tbConf, v) then
- return false
- end
- end
- return true
- end
- -- 右被不包含
- function root:isConditionNotRinclude(val, condValue)
- if val == nil or condValue == nil then
- return false
- end
- -- 配置参数必须为table
- local tbConf = nil
- if type(val) == "table" then
- tbConf = val
- else
- tbConf = {val}
- end
- if type(condValue) ~= "table" then
- return not table.include(tbConf, condValue)
- end
- for k, v in ipairs(condValue) do
- if table.include(tbConf, v) then
- return false
- end
- end
- return true
- end
- return root
|