| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /**
- * components/kf-score-panel.js —— <kf-score-panel> 多人评分面板。
- *
- * 显示:平均分(大字)、评分人数、人工平均 / Agent 平均、每一条评分(谁、几分、评语、什么时候)。
- * 输入:用户 + 0–100 分 + 评语 → 派发 score-submit { user, score, comment };业务(去重、平均)在 core。
- */
- import { LitElement, html, css } from 'lit';
- import { useTokens, define } from './base.js';
- import './kf-viz.js';
- import './kf-stat.js';
- import { fmtAgo, fmtDate } from '../core/index.js';
- import { t } from './cjk.js';
- export class KfScorePanel extends LitElement {
- static properties = {
- stats: { type: Object },
- user: { type: String },
- busy: { type: Boolean },
- _score: { state: true },
- _comment: { state: true },
- _err: { state: true },
- };
- constructor() {
- super();
- this.stats = { n: 0, avg: null, scores: [] };
- this.user = '';
- this.busy = false;
- this._score = '';
- this._comment = '';
- this._err = '';
- }
- connectedCallback() {
- super.connectedCallback();
- useTokens(this);
- }
- static styles = css`
- :host { display: block; }
- /* 平均分:大数字(1.1 行盒修剪)+ 进度环(板块二:弧长表达平均在 100 里的位置),环心印数字 */
- .head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
- .avgwrap { display: flex; align-items: center; gap: 12px; }
- .avg { font-size: 32px; font-weight: 600; color: var(--kf-ink); line-height: 1; font-variant-numeric: tabular-nums; text-box-trim: trim-both; text-box-edge: cap alphabetic;
- font-family: var(--kf-font-num); letter-spacing: var(--ls-cn-display); display: block; height: max-content; } /* v11b:flex 容器不修剪 */
- .avg small { font: 500 11px var(--kf-font); color: var(--kf-ink-3); margin-left: 0.12em; letter-spacing: 0; }
- .meta { display: grid; gap: 2px; font-size: 13px; color: var(--kf-ink-3); }
- .meta b { color: var(--kf-ink); font-weight: 600; font-variant-numeric: tabular-nums; }
- .none { color: var(--kf-ink-3); font-size: 14px; font-weight: 600; }
- ul { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
- li { display: grid; grid-template-columns: 88px 48px 1fr; gap: 8px; align-items: baseline; padding: 8px 12px; border-radius: 8px; background: rgba(255,255,255,0.4); border: 1px solid var(--kf-line); }
- /* Agent 评分:6% 染色 + 1px 同色半透明描边(不是整块紫底) */
- li.agent { background: color-mix(in srgb, var(--kf-accent) 6%, rgba(255,255,255,0.4)); border-color: color-mix(in srgb, var(--kf-accent) 18%, transparent); }
- .who { color: var(--kf-ink); font-weight: 600; font-size: 13px; }
- .s { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--kf-accent-ink); font-size: 14px; }
- /* 行内只用 kf-stat 的数字槽(数字滚动 + 单位分层都复用它),不渲染标签 / 注脚 */
- .s kf-stat { display: inline-block; }
- .c .t { color: var(--kf-ink-3); font-size: 11px; margin-left: 6px; }
- form { margin-top: 16px; padding: 12px; border-radius: 8px; border: 1px dashed var(--kf-line-strong); display: grid; gap: 8px; }
- .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
- input[type="number"], input[type="text"] { height: 32px; border-radius: 8px; border: 1px solid var(--kf-line-strong); background: rgba(255,255,255,0.6); transition: var(--kf-t); }
- input:focus { outline: none; border-color: var(--kf-focus); box-shadow: 0 0 0 2px rgba(91, 91, 214, 0.22); background: #fff; }
- input[type="number"] { width: 88px; padding: 0 8px; font: 600 14px var(--kf-font-num); font-variant-numeric: tabular-nums; }
- input[type="text"] { flex: 1; min-width: 160px; padding: 0 12px; font: 13px var(--kf-font); }
- .err { color: var(--kf-danger); font-size: 11px; }
- .hint { font-size: 11px; color: var(--kf-ink-3); }
- `;
- #submit(e) {
- e.preventDefault();
- this._err = '';
- const score = Number(this._score);
- if (!this.user) { this._err = '先选「我是谁」(右上角),再评分'; return; }
- if (!(score >= 0 && score <= 100) || this._score === '') { this._err = t('分数必须在 0–100 之间'); return; }
- this.dispatchEvent(new CustomEvent('score-submit', {
- detail: { user: this.user, score, comment: this._comment.trim() },
- bubbles: true, composed: true,
- }));
- this._score = '';
- this._comment = '';
- }
- render() {
- const s = this.stats || { n: 0, avg: null, scores: [] };
- return html`
- <div class="head">
- ${s.avg == null
- ? html`<div class="none">暂无评分</div>`
- : html`<div class="avgwrap"><kf-ring size=${44} .pct=${Math.round(s.avg)} label=${String(s.avg)}></kf-ring><div class="avg kf-num">${s.avg}<small>平均</small></div></div>`}
- <div class="meta">
- <span>${t(`${s.n || 0} 人评分`)}${s.n > 1 ? '(同一人多次取最后一次)' : ''}</span>
- <span>${t(`人工平均 ${s.humanAvg ?? '—'} · Agent 平均 ${s.agentAvg ?? '—'}`)}</span>
- ${s.max != null ? html`<span>${t(`最高 ${s.max} · 最低 ${s.min} · 分歧 ${s.max - s.min} 分`)}</span>` : ''}
- </div>
- </div>
- ${s.scores?.length ? html`
- <ul aria-label="评分明细">
- ${s.scores.map((x) => html`
- <li class=${x.source === 'agent' ? 'agent' : ''}>
- <span class="who">${x.user}</span>
- <span class="s kf-num"><kf-stat inline value=${String(x.score)}></kf-stat></span>
- <span class="c">${x.comment || html`<span class="kf-muted">(无评语)</span>`}<span class="t">${x.at ? fmtAgo(x.at) : ''}${x.source === 'agent' ? t(' · Agent') : ''}</span></span>
- </li>`)}
- </ul>` : ''}
- <form @submit=${this.#submit} data-no-activate>
- <div class="row">
- <strong>我来评分</strong>
- <span class="hint">${this.user ? html`评分人:<b>${this.user}</b>` : '未选择「我是谁」'}</span>
- </div>
- <div class="row">
- <input type="number" min="0" max="100" placeholder="0–100" .value=${this._score}
- @input=${(e) => { this._score = e.target.value; }} aria-label="分数" />
- <input type="text" placeholder="一句评语(可选)" .value=${this._comment}
- @input=${(e) => { this._comment = e.target.value; }} aria-label="评语" />
- <button class="kf-btn primary" type="submit" ?disabled=${this.busy}>${this.busy ? '提交中…' : '提交评分'}</button>
- </div>
- ${this._err ? html`<div class="err" role="alert">${this._err}</div>` : ''}
- ${s.latest ? html`<div class="hint">${t(`最近一次:${s.latest.user} ${s.latest.score} 分 · ${fmtDate(s.latest.at, true)}`)}</div>` : ''}
- </form>
- `;
- }
- }
- define('kf-score-panel', KfScorePanel);
|