diff --git a/jituan/services/identity_tag.py b/jituan/services/identity_tag.py index 3e0ccd3..b5f7501 100644 --- a/jituan/services/identity_tag.py +++ b/jituan/services/identity_tag.py @@ -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, }