fix: 身份标签 color 合并进 texiao_json

This commit is contained in:
XingQue
2026-06-26 03:26:34 +08:00
parent 01d73c5fae
commit 141f17859a

View File

@@ -13,22 +13,33 @@ SHENFEN_ZUZHANG = 4
def _tag_texiao(tag):
"""合并 texiao_json 与 color / flash 列,避免空 JSON 导致前端默认金黄。"""
base = {}
if tag.texiao_json:
try:
return json.loads(tag.texiao_json)
parsed = json.loads(tag.texiao_json)
if isinstance(parsed, dict):
base = dict(parsed)
except (TypeError, ValueError, json.JSONDecodeError):
pass
return {
'color': tag.color or '#000000',
'flash': bool(tag.flash_enabled),
}
if not base.get('color') and tag.color:
base['color'] = tag.color
if 'flash' not in base:
base['flash'] = bool(tag.flash_enabled)
# 身份装饰标签固定圆角 pill勿沿用考核称号的 shape
if 'shape' in base and base.get('shape') not in (None, '', 'pill', 'rounded', 'rectangle'):
base.pop('shape', None)
return base
def format_tag_item(tag):
texiao = _tag_texiao(tag)
return {
'id': tag.id,
'mingcheng': tag.name,
'texiao_json': _tag_texiao(tag),
'color': texiao.get('color') or tag.color or '#000000',
'flash_enabled': bool(texiao.get('flash')),
'texiao_json': texiao,
}