支持data_filter显式声明op(LIKE),不自动对所有字符串字段模糊匹配
This commit is contained in:
parent
36267a18cc
commit
db5f579464
@ -171,17 +171,21 @@ ori_fields = json.loads(fields_str)
|
||||
if not filterjson:
|
||||
fields = [ f['name'] for f in ori_fields ]
|
||||
filterjson = default_filterjson(fields, ns)
|
||||
# 字符串字段使用LIKE模糊匹配
|
||||
str_fields = {f['name'] for f in ori_fields if f.get('type') in ('str', 'text')}
|
||||
if filterjson and str_fields:
|
||||
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
|
||||
filterjson = {'AND': [filterjson] if filterjson else []}
|
||||
for fj in filterjson['AND']:
|
||||
if fj.get('field') in str_fields and fj.get('op') == '=':
|
||||
var = fj.get('var')
|
||||
if var and var in ns and ns[var]:
|
||||
ns[var] = f'%{ns[var]}%'
|
||||
fj['op'] = 'LIKE'
|
||||
{% if data_filter and data_filter.fields %}
|
||||
# 应用 data_filter 中显式声明的 op(如 LIKE)
|
||||
__df_fields = {{json.dumps(data_filter.fields, ensure_ascii=False)}}
|
||||
__df_ops = {f['field']: f.get('op') for f in __df_fields if f.get('op')}
|
||||
if filterjson and __df_ops:
|
||||
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
|
||||
filterjson = {'AND': [filterjson] if filterjson else []}
|
||||
for fj in filterjson['AND']:
|
||||
if fj.get('field') in __df_ops:
|
||||
fj['op'] = __df_ops[fj['field']]
|
||||
if fj['op'] == 'LIKE':
|
||||
var = fj.get('var')
|
||||
if var and var in ns and ns[var]:
|
||||
ns[var] = f'%{ns[var]}%'
|
||||
{% endif %}
|
||||
{% if logined_userorgid or logined_userid %}
|
||||
# 确保 logined 过滤条件始终生效
|
||||
if filterjson:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user