Files
kefu/deploy/review-picker-20260918/update_panel.py
T
2026-09-21 10:34:06 +08:00

87 lines
5.1 KiB
Python

from pathlib import Path
import hashlib,json,os
base=Path(__file__).parent
rows=[]
styles='''
/* Explicit review-reminder recipient identity; IDs stay readable at every DPI. */
#stage .assistant-recipient-card {
display:grid; grid-template-columns:40px minmax(0,1fr); gap:12px;
margin:14px 0; padding:16px; border:1px solid #c4d5f0; border-radius:14px;
background:#f5f8ff; color:var(--ink); min-width:0;
}
#stage .assistant-recipient-icon {
display:flex; align-items:center; justify-content:center; width:40px; height:40px;
border-radius:12px; background:#e4edff; color:#355da8;
}
#stage .assistant-recipient-icon svg { width:22px; height:22px; }
#stage .assistant-recipient-copy { min-width:0; }
#stage .assistant-recipient-heading {
display:flex; align-items:center; flex-wrap:wrap; gap:8px 12px; margin-bottom:8px;
}
#stage .assistant-recipient-tag {
display:inline-block; padding:3px 8px; border-radius:6px; background:#e4edff;
color:#35558d; font-size:12px; font-weight:700; line-height:1.5;
}
#stage .assistant-recipient-kind { color:var(--muted); font-size:12px; }
#stage .assistant-recipient-name {
display:block; color:var(--ink); font-size:18px; font-weight:700; line-height:1.5;
white-space:normal; overflow-wrap:anywhere;
}
#stage .assistant-recipient-name.is-unknown { color:#875600; font-size:16px; }
#stage .assistant-recipient-identity {
display:flex; flex-wrap:wrap; align-items:baseline; gap:3px 8px;
margin-top:7px; font-size:13px; line-height:1.6; color:var(--muted); min-width:0;
}
#stage .assistant-recipient-id {
font-family:ui-monospace,Consolas,monospace; font-size:13px; color:#566786;
font-variant-numeric:tabular-nums; white-space:normal; overflow-wrap:anywhere;
word-break:break-word; min-width:0; max-width:100%;
}
#stage .assistant-recipient-card.is-empty { background:#f8f9fc; border-color:#d9e0eb; }
@media (max-width:640px) {
#stage .assistant-recipient-card { grid-template-columns:32px minmax(0,1fr); gap:10px; padding:12px; }
#stage .assistant-recipient-icon { width:32px; height:32px; }
}
'''
for tag,root in [('production',Path('C:/wechat_rpa')),('source',Path('C:/kefu/wechat_rpa'))]:
folder=base/'frontend-before'/tag;folder.mkdir(parents=True,exist_ok=True)
for name in ['console-app.js','console-review.css']:
p=root/'assets/ui'/name
backup=folder/name
if backup.exists():
raise RuntimeError('Backup already exists; refuse to overwrite '+str(backup))
backup.write_bytes(p.read_bytes())
p=root/'assets/ui/console-app.js';text=p.read_text(encoding='utf-8')
start=text.index('function reviewAssistantPanel(a){');end=text.index('\n}\n',start)+2
before=text[start:end];panel=before
marker=' const canToggle = canChoose && (recipient.id || r.enabled);'
assert panel.count(marker)==1
panel=panel.replace(marker,marker+'''
const recipientId = String(recipient.id || "").trim();
const recipientName = String(recipient.displayName || "").trim() || String(recipient.name || "").trim();
const nameKnown = recipient.nameKnown !== false && Boolean(recipientName) && recipientName !== "微信联系人";
const recipientTitle = !recipientId ? "尚未选择助理私人微信" : nameKnown ? recipientName : "昵称未读取,请核对联系编号";
''')
old=' <div class="setting-line"><span>助理私人微信</span><div style="flex:1;text-align:right"><strong>${esc(recipient.name || "尚未选择")}</strong>${recipient.label ? `<div class="tiny">${esc(recipient.label)}</div>` : ""}</div></div>'
new=''' <div class="assistant-recipient-card ${recipientId ? "" : "is-empty"}" role="group" aria-label="${recipientId ? "已配置收件人" : "未配置收件人"}">
<div class="assistant-recipient-icon" aria-hidden="true">${icon("user")}</div>
<div class="assistant-recipient-copy"><div class="assistant-recipient-heading"><span class="assistant-recipient-tag">${recipientId ? "已配置收件人" : "未配置收件人"}</span><span class="assistant-recipient-kind">助理私人微信</span></div>
<strong class="assistant-recipient-name ${recipientId && !nameKnown ? "is-unknown" : ""}">${esc(recipientTitle)}</strong>
${recipientId ? `<div class="assistant-recipient-identity"><span>联系编号</span><span class="assistant-recipient-id">${esc(recipientId)}</span></div>` : ""}
</div>
</div>'''
assert panel.count(old)==1
panel=panel.replace(old,new)
text=text[:start]+panel+text[end:]
temp=p.with_suffix('.review-picker.tmp');temp.write_text(text,encoding='utf-8',newline='\n');os.replace(temp,p)
p=root/'assets/ui/console-review.css';css=p.read_text(encoding='utf-8')
assert '.assistant-recipient-card' not in css
temp=p.with_suffix('.review-picker.tmp');temp.write_text(css.rstrip()+'\n'+styles,encoding='utf-8',newline='\n');os.replace(temp,p)
for name in ['console-app.js','console-review.css']:
p=root/'assets/ui'/name
rows.append({'root':str(root),'file':name,'sha256':hashlib.sha256(p.read_bytes()).hexdigest()})
(base/'frontend-files.json').write_text(json.dumps(rows,ensure_ascii=False,indent=2),encoding='utf-8')
print('Updated only reviewAssistantPanel and dedicated styles in both checkouts')