From 141f17859a168a8f52561e2c05366cf0b6cc2041 Mon Sep 17 00:00:00 2001 From: XingQue Date: Fri, 26 Jun 2026 03:26:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BA=AB=E4=BB=BD=E6=A0=87=E7=AD=BE=20c?= =?UTF-8?q?olor=20=E5=90=88=E5=B9=B6=E8=BF=9B=20texiao=5Fjson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jituan/services/identity_tag.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) 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, }