Ship feedback identity limits, admin visitor dossiers, and a cleaner hiring board.
Cap feedback at 10 per user with clustered admin views, and redesign /social/team as a denser job board. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
35e5f863fe
commit
985ecf5e77
@ -2,7 +2,7 @@
|
||||
* 游民社区 · UGC 数据台
|
||||
* 前端提交数据可视化:加入线索 / 消息 / 花名册 / 评价 / 技能 / 核验 / 预约 / 行程 / 举报 …
|
||||
*/
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { api } from '../api'
|
||||
import { WxEmpty, WxHead, WxTabs, WxToast } from '../components/wxUi'
|
||||
@ -120,12 +120,32 @@ function joinLiveCell(it: Record<string, unknown>): string {
|
||||
return '未核验'
|
||||
}
|
||||
|
||||
function feedbackPersonLabel(it: Record<string, unknown>): string {
|
||||
const meta =
|
||||
it.meta && typeof it.meta === 'object' && !Array.isArray(it.meta)
|
||||
? (it.meta as Record<string, unknown>)
|
||||
: {}
|
||||
const email = String(meta.email || '').trim()
|
||||
const contact = String(it.contact || '').trim()
|
||||
const name = String(meta.name || '').trim()
|
||||
const key = String(it.userKey || '')
|
||||
if (email) return email
|
||||
if (contact) return contact
|
||||
if (name) return name
|
||||
if (key.startsWith('email:')) return key.slice(6)
|
||||
if (key.startsWith('contact:')) return key.slice(8)
|
||||
if (key.startsWith('guest:')) return `访客 ${key.slice(6, 18)}`
|
||||
if (key.startsWith('weak:')) return `未登录 · ${key.slice(5, 13)}`
|
||||
return key || String(it.guestId || '未知访客')
|
||||
}
|
||||
|
||||
export default function SocialData() {
|
||||
const [tab, setTab] = useState<Tab>('joins')
|
||||
const [overview, setOverview] = useState<Overview | null>(null)
|
||||
const [items, setItems] = useState<any[]>([])
|
||||
const [total, setTotal] = useState(0)
|
||||
const [q, setQ] = useState('')
|
||||
const [personKey, setPersonKey] = useState('')
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [err, setErr] = useState('')
|
||||
@ -153,7 +173,14 @@ export default function SocialData() {
|
||||
}
|
||||
const qs = new URLSearchParams()
|
||||
if (q.trim()) qs.set('q', q.trim())
|
||||
qs.set('limit', '100')
|
||||
if (tab === 'feedback' && personKey) {
|
||||
qs.set('userKey', personKey)
|
||||
qs.set('limit', '100')
|
||||
} else if (tab === 'feedback') {
|
||||
qs.set('limit', '200')
|
||||
} else {
|
||||
qs.set('limit', '100')
|
||||
}
|
||||
const data = await api<ListResp>(`${ENDPOINTS[tab]}?${qs}`)
|
||||
setItems(data.items || [])
|
||||
setTotal(data.total || 0)
|
||||
@ -164,7 +191,7 @@ export default function SocialData() {
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [tab, q])
|
||||
}, [tab, q, personKey])
|
||||
|
||||
useEffect(() => {
|
||||
loadOverview().catch((e) => setErr(e.message || '概览失败'))
|
||||
@ -174,6 +201,34 @@ export default function SocialData() {
|
||||
void loadList()
|
||||
}, [loadList])
|
||||
|
||||
useEffect(() => {
|
||||
setPersonKey('')
|
||||
}, [tab])
|
||||
|
||||
const feedbackPeople = useMemo(() => {
|
||||
if (tab !== 'feedback' || personKey) return []
|
||||
const map = new Map<string, any>()
|
||||
for (const row of items) {
|
||||
const key = String(row.userKey || '').trim()
|
||||
if (!key) continue
|
||||
const prev = map.get(key)
|
||||
if (!prev || row.isGroupHead) {
|
||||
map.set(key, {
|
||||
...row,
|
||||
userCount: Number(row.userCount || prev?.userCount || 1) || 1,
|
||||
})
|
||||
} else if (prev) {
|
||||
const n = Math.max(
|
||||
Number(prev.userCount || 1),
|
||||
Number(row.userCount || 1),
|
||||
Number(row.userIndex || 1),
|
||||
)
|
||||
map.set(key, { ...prev, userCount: n })
|
||||
}
|
||||
}
|
||||
return [...map.values()]
|
||||
}, [tab, personKey, items])
|
||||
|
||||
async function remove(kind: Tab, id: string) {
|
||||
if (!DELETABLE.has(kind)) return
|
||||
if (!confirm('软删除?内容会写入存档(social_archives),不会物理抹除。')) return
|
||||
@ -345,12 +400,103 @@ export default function SocialData() {
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
if (tab === 'feedback' && !personKey) {
|
||||
return (
|
||||
<tr
|
||||
key={String(it.userKey || it.id)}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => setPersonKey(String(it.userKey || ''))}
|
||||
>
|
||||
<td>
|
||||
<strong>{feedbackPersonLabel(it)}</strong>
|
||||
<div className="wx-mono" style={{ fontSize: 11, opacity: 0.65, marginTop: 4 }}>
|
||||
{cell(it.userKey, 40)}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span>{it.kind}</span> · {cell(it.text, 80)}
|
||||
</td>
|
||||
<td>{it.contact || '—'}</td>
|
||||
<td>
|
||||
<strong>
|
||||
{String(it.userCount || 1)}/{String(it.userMax || 10)}
|
||||
</strong>
|
||||
</td>
|
||||
<td>{it.at}</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
className="wx-btn-sm"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setPersonKey(String(it.userKey || ''))
|
||||
}}
|
||||
>
|
||||
全部反馈
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
if (tab === 'feedback') {
|
||||
const imgs = Array.isArray(it.images) ? (it.images as string[]) : []
|
||||
const meta = it.meta && typeof it.meta === 'object' ? (it.meta as Record<string, unknown>) : {}
|
||||
const userKey = String(it.userKey || '')
|
||||
const userCount = Number(it.userCount || 0) || 0
|
||||
const userIndex = Number(it.userIndex || 0) || 0
|
||||
const userMax = Number(it.userMax || 10) || 10
|
||||
const metaBits = [
|
||||
meta.email ? `邮箱 ${String(meta.email)}` : '',
|
||||
meta.name ? `昵称 ${String(meta.name)}` : '',
|
||||
it.guestId ? `guest ${String(it.guestId)}` : '',
|
||||
meta.href ? String(meta.href) : '',
|
||||
meta.userAgent ? String(meta.userAgent).slice(0, 80) : '',
|
||||
meta.timezone ? `时区 ${String(meta.timezone)}` : '',
|
||||
meta.serverIp ? `IP ${String(meta.serverIp)}` : '',
|
||||
].filter(Boolean)
|
||||
return (
|
||||
<tr key={it.id}>
|
||||
<td>{it.kind}</td>
|
||||
<td>{cell(it.text, 140)}</td>
|
||||
<td>
|
||||
<div>{it.kind}</div>
|
||||
<div className="wx-mono" style={{ fontSize: 11, opacity: 0.7, marginTop: 4 }}>
|
||||
{userIndex}/{userCount || '?'} · 上限 {userMax}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>{cell(it.text, 140)}</div>
|
||||
{imgs.length ? (
|
||||
<div style={{ display: 'flex', gap: 6, marginTop: 6, flexWrap: 'wrap' }}>
|
||||
{imgs.slice(0, 4).map((url) => (
|
||||
<a key={url} href={url} target="_blank" rel="noreferrer">
|
||||
<img
|
||||
src={url}
|
||||
alt=""
|
||||
style={{ width: 48, height: 48, objectFit: 'cover', borderRadius: 8 }}
|
||||
/>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</td>
|
||||
<td>{it.contact || '—'}</td>
|
||||
<td>
|
||||
<div style={{ fontSize: 12, lineHeight: 1.45, maxWidth: 280, wordBreak: 'break-all' }}>
|
||||
{userKey ? (
|
||||
<div style={{ marginBottom: 4 }}>
|
||||
<span className="wx-mono">user {cell(userKey, 36)}</span>
|
||||
</div>
|
||||
) : null}
|
||||
{metaBits.length ? metaBits.map((b) => <div key={b}>{b}</div>) : '—'}
|
||||
{Object.keys(meta).length ? (
|
||||
<details style={{ marginTop: 4 }}>
|
||||
<summary>全部详情</summary>
|
||||
<pre style={{ whiteSpace: 'pre-wrap', fontSize: 11, margin: '6px 0 0' }}>
|
||||
{JSON.stringify(meta, null, 2)}
|
||||
</pre>
|
||||
</details>
|
||||
) : null}
|
||||
</div>
|
||||
</td>
|
||||
<td>{it.at}</td>
|
||||
<td>
|
||||
<button
|
||||
@ -491,7 +637,9 @@ export default function SocialData() {
|
||||
reports: ['被举报', '原因', '状态', '举报人', '时间'],
|
||||
blocks: ['拉黑人', '被拉黑', '原因', '时间', ''],
|
||||
files: ['文件名', '类型', '频道', '访客', '时间'],
|
||||
feedback: ['类型', '内容', '联系', '时间', '操作'],
|
||||
feedback: personKey
|
||||
? ['类型', '内容 / 图', '联系', '用户详情', '时间', '操作']
|
||||
: ['访客', '最近一条', '联系', '条数', '最近时间', '操作'],
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -215,10 +215,13 @@ async def del_gig_app(app_id: str, _: str = Depends(require_admin)) -> dict[str,
|
||||
async def get_feedback(
|
||||
limit: int = Query(100, ge=1, le=500),
|
||||
offset: int = Query(0, ge=0),
|
||||
userKey: str = Query(""),
|
||||
_: str = Depends(require_admin),
|
||||
) -> dict[str, Any]:
|
||||
try:
|
||||
return ugc.list_feedback(limit=limit, offset=offset)
|
||||
return ugc.list_feedback(
|
||||
limit=limit, offset=offset, user_key=userKey
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(503, f"social db unavailable: {e}") from e
|
||||
|
||||
|
||||
@ -114,8 +114,15 @@ def delete_gig_app(app_id: str) -> bool:
|
||||
return _pb().admin_delete_gig_app(app_id)
|
||||
|
||||
|
||||
def list_feedback(*, limit: int = 100, offset: int = 0) -> dict[str, Any]:
|
||||
return _pb().admin_list_feedback(limit=limit, offset=offset)
|
||||
def list_feedback(
|
||||
*,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
user_key: str = "",
|
||||
) -> dict[str, Any]:
|
||||
return _pb().admin_list_feedback(
|
||||
limit=limit, offset=offset, user_key=user_key
|
||||
)
|
||||
|
||||
|
||||
def delete_feedback(fid: str) -> bool:
|
||||
|
||||
@ -264,11 +264,18 @@ SOCIAL_FEEDBACK = _base(
|
||||
"social_feedback",
|
||||
[
|
||||
_text("guest_id"),
|
||||
_text("user_key"),
|
||||
_text("kind"),
|
||||
_text("text"),
|
||||
_text("contact"),
|
||||
_json("images"),
|
||||
_json("meta"),
|
||||
_text("created_at", True),
|
||||
],
|
||||
indexes=[
|
||||
"CREATE INDEX idx_social_feedback_user ON social_feedback (user_key)",
|
||||
"CREATE INDEX idx_social_feedback_guest ON social_feedback (guest_id)",
|
||||
],
|
||||
)
|
||||
|
||||
# Join funnel leads — email click onwards (test-phase archive for admin)
|
||||
|
||||
@ -1154,13 +1154,103 @@ def _feedback_local_list() -> list[dict[str, Any]]:
|
||||
return []
|
||||
|
||||
|
||||
def add_feedback(kind: str, text: str, contact: str, guest_id: str) -> dict[str, Any]:
|
||||
FEEDBACK_MAX_PER_USER = 10
|
||||
|
||||
|
||||
def feedback_user_key(
|
||||
*,
|
||||
guest_id: str = "",
|
||||
contact: str = "",
|
||||
meta: dict[str, Any] | None = None,
|
||||
) -> str:
|
||||
meta_obj = meta if isinstance(meta, dict) else {}
|
||||
email = str(meta_obj.get("email") or "").strip().lower()
|
||||
if "@" in email:
|
||||
return f"email:{email[:160]}"
|
||||
contact_n = str(contact or "").strip().lower()[:120]
|
||||
if "@" in contact_n:
|
||||
return f"email:{contact_n}"
|
||||
if contact_n:
|
||||
return f"contact:{contact_n}"
|
||||
gid = str(guest_id or meta_obj.get("guestId") or "").strip()[:120]
|
||||
if gid:
|
||||
return f"guest:{gid}"
|
||||
ua = str(meta_obj.get("userAgent") or meta_obj.get("serverUserAgent") or "")[:96]
|
||||
tz = str(meta_obj.get("timezone") or "")
|
||||
weak = f"{ua}|{tz}|{meta_obj.get('platform') or ''}"
|
||||
return f"weak:{hashlib.sha256(weak.encode()).hexdigest()[:16]}"
|
||||
|
||||
|
||||
def _feedback_count_for_user(user_key: str) -> int:
|
||||
"""Count existing feedback for the same person in PB + social local (id-deduped).
|
||||
|
||||
Do NOT scan portal data/feedback.json: portal writes locally then forwards here,
|
||||
so counting that file would reject the same submission on the forward hop.
|
||||
"""
|
||||
if not user_key:
|
||||
return 0
|
||||
seen: set[str] = set()
|
||||
|
||||
def _take(r: dict[str, Any]) -> None:
|
||||
key = str(r.get("userKey") or r.get("user_key") or "")
|
||||
if not key:
|
||||
key = feedback_user_key(
|
||||
guest_id=str(r.get("guestId") or r.get("guest_id") or ""),
|
||||
contact=str(r.get("contact") or ""),
|
||||
meta=r.get("meta") if isinstance(r.get("meta"), dict) else {},
|
||||
)
|
||||
if key != user_key:
|
||||
return
|
||||
rid = str(r.get("id") or "")
|
||||
text = str(r.get("text") or "")[:80]
|
||||
at = str(r.get("at") or r.get("created_at") or "")[:16]
|
||||
seen.add(rid or f"{text}|{at}")
|
||||
|
||||
try:
|
||||
init_pb()
|
||||
rows = get_pb().list_all(
|
||||
C_FEEDBACK,
|
||||
filter=f"user_key={pb_quote(user_key)}",
|
||||
hard_limit=50,
|
||||
)
|
||||
for r in rows:
|
||||
if isinstance(r, dict):
|
||||
_take(r)
|
||||
except Exception:
|
||||
pass
|
||||
for r in _feedback_local_list():
|
||||
if isinstance(r, dict):
|
||||
_take(r)
|
||||
return len(seen)
|
||||
|
||||
|
||||
def add_feedback(
|
||||
kind: str,
|
||||
text: str,
|
||||
contact: str,
|
||||
guest_id: str,
|
||||
*,
|
||||
images: list[str] | None = None,
|
||||
meta: dict | None = None,
|
||||
) -> dict[str, Any]:
|
||||
now = _now()
|
||||
imgs = [
|
||||
str(u).strip()[:500]
|
||||
for u in (images or [])
|
||||
if isinstance(u, str) and str(u).strip().startswith(("http://", "https://"))
|
||||
][:8]
|
||||
meta_obj = meta if isinstance(meta, dict) else {}
|
||||
user_key = feedback_user_key(guest_id=guest_id, contact=contact, meta=meta_obj)
|
||||
if _feedback_count_for_user(user_key) >= FEEDBACK_MAX_PER_USER:
|
||||
raise ValueError(f"每人最多提交 {FEEDBACK_MAX_PER_USER} 条反馈")
|
||||
body = {
|
||||
"guest_id": guest_id,
|
||||
"user_key": user_key,
|
||||
"kind": kind if kind in {"反馈", "建议"} else "建议",
|
||||
"text": (text or "").strip()[:4000],
|
||||
"contact": (contact or "").strip()[:120],
|
||||
"images": imgs,
|
||||
"meta": meta_obj,
|
||||
"created_at": now,
|
||||
}
|
||||
if not body["text"]:
|
||||
@ -1173,10 +1263,16 @@ def add_feedback(kind: str, text: str, contact: str, guest_id: str) -> dict[str,
|
||||
"kind": body["kind"],
|
||||
"text": body["text"],
|
||||
"contact": body["contact"],
|
||||
"images": imgs,
|
||||
"meta": meta_obj,
|
||||
"userKey": user_key,
|
||||
"guestId": guest_id,
|
||||
"at": now,
|
||||
"stored": "pocketbase",
|
||||
"remaining": max(0, FEEDBACK_MAX_PER_USER - _feedback_count_for_user(user_key)),
|
||||
}
|
||||
except ValueError:
|
||||
raise
|
||||
except Exception:
|
||||
# PB 挂了仍要接住反馈(本地 / 离线)
|
||||
fid = f"fb_local_{uuid.uuid4().hex[:12]}"
|
||||
@ -1185,12 +1281,19 @@ def add_feedback(kind: str, text: str, contact: str, guest_id: str) -> dict[str,
|
||||
"kind": body["kind"],
|
||||
"text": body["text"],
|
||||
"contact": body["contact"],
|
||||
"images": imgs,
|
||||
"meta": meta_obj,
|
||||
"userKey": user_key,
|
||||
"guestId": guest_id,
|
||||
"at": now,
|
||||
"source": "api-local",
|
||||
}
|
||||
_feedback_local_append(row)
|
||||
return {**row, "stored": "local"}
|
||||
return {
|
||||
**row,
|
||||
"stored": "local",
|
||||
"remaining": max(0, FEEDBACK_MAX_PER_USER - _feedback_count_for_user(user_key)),
|
||||
}
|
||||
|
||||
|
||||
_JOIN_FACE_STAGES = frozenset(
|
||||
@ -1999,45 +2102,59 @@ def admin_delete_gig_app(app_id: str) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def admin_list_feedback(*, limit: int = 100, offset: int = 0) -> dict[str, Any]:
|
||||
def admin_list_feedback(
|
||||
*,
|
||||
limit: int = 100,
|
||||
offset: int = 0,
|
||||
user_key: str = "",
|
||||
) -> dict[str, Any]:
|
||||
lim = max(1, min(int(limit or 100), 500))
|
||||
off = max(0, int(offset or 0))
|
||||
want_key = (user_key or "").strip()[:200]
|
||||
items: list[dict[str, Any]] = []
|
||||
|
||||
def _row(r: dict[str, Any]) -> dict[str, Any]:
|
||||
meta = r.get("meta") if isinstance(r.get("meta"), dict) else {}
|
||||
guest = r.get("guestId") or r.get("guest_id") or ""
|
||||
contact = r.get("contact") or ""
|
||||
user_key = str(r.get("userKey") or r.get("user_key") or "") or feedback_user_key(
|
||||
guest_id=str(guest),
|
||||
contact=str(contact),
|
||||
meta=meta,
|
||||
)
|
||||
return {
|
||||
"id": r.get("id"),
|
||||
"kind": r.get("kind"),
|
||||
"text": r.get("text"),
|
||||
"contact": contact,
|
||||
"images": r.get("images") if isinstance(r.get("images"), list) else [],
|
||||
"meta": meta,
|
||||
"userKey": user_key,
|
||||
"guestId": guest,
|
||||
"at": r.get("at") or r.get("created_at") or "",
|
||||
}
|
||||
|
||||
try:
|
||||
init_pb()
|
||||
rows = get_pb().list_all(C_FEEDBACK, sort="-created_at", hard_limit=5000)
|
||||
items = [
|
||||
{
|
||||
"id": r.get("id"),
|
||||
"kind": r.get("kind"),
|
||||
"text": r.get("text"),
|
||||
"contact": r.get("contact") or "",
|
||||
"guestId": r.get("guest_id"),
|
||||
"at": r.get("created_at"),
|
||||
}
|
||||
for r in rows
|
||||
]
|
||||
items = [_row(r) for r in rows]
|
||||
except Exception:
|
||||
items = []
|
||||
# Merge API-local + portal-local offline files
|
||||
seen = {str(x.get("id") or "") for x in items}
|
||||
|
||||
def _append(r: dict[str, Any]) -> None:
|
||||
rid = str(r.get("id") or "")
|
||||
if rid and rid in seen:
|
||||
return
|
||||
if rid:
|
||||
seen.add(rid)
|
||||
items.append(_row(r))
|
||||
|
||||
for src in (_feedback_local_list(),):
|
||||
for r in src:
|
||||
rid = str(r.get("id") or "")
|
||||
if rid and rid in seen:
|
||||
continue
|
||||
if rid:
|
||||
seen.add(rid)
|
||||
items.append(
|
||||
{
|
||||
"id": r.get("id"),
|
||||
"kind": r.get("kind"),
|
||||
"text": r.get("text"),
|
||||
"contact": r.get("contact") or "",
|
||||
"guestId": r.get("guestId") or r.get("guest_id") or "",
|
||||
"at": r.get("at") or r.get("created_at") or "",
|
||||
}
|
||||
)
|
||||
if isinstance(r, dict):
|
||||
_append(r)
|
||||
# Also portal data/feedback.json
|
||||
try:
|
||||
portal_fb = Path.cwd() / "data" / "feedback.json"
|
||||
@ -2050,28 +2167,67 @@ def admin_list_feedback(*, limit: int = 100, offset: int = 0) -> dict[str, Any]:
|
||||
if not isinstance(rows, list):
|
||||
continue
|
||||
for r in rows:
|
||||
if not isinstance(r, dict):
|
||||
continue
|
||||
rid = str(r.get("id") or "")
|
||||
if rid and rid in seen:
|
||||
continue
|
||||
if rid:
|
||||
seen.add(rid)
|
||||
items.append(
|
||||
{
|
||||
"id": r.get("id"),
|
||||
"kind": r.get("kind"),
|
||||
"text": r.get("text"),
|
||||
"contact": r.get("contact") or "",
|
||||
"guestId": r.get("guestId") or "",
|
||||
"at": r.get("at") or "",
|
||||
}
|
||||
)
|
||||
if isinstance(r, dict):
|
||||
_append(r)
|
||||
except Exception:
|
||||
pass
|
||||
items.sort(key=lambda r: str(r.get("at") or ""), reverse=True)
|
||||
total = len(items)
|
||||
return {"ok": True, "total": total, "items": items[off : off + lim]}
|
||||
# Collapse portal-local + PB copies of the same submit (different ids).
|
||||
deduped: list[dict[str, Any]] = []
|
||||
seen_fp: set[str] = set()
|
||||
for it in items:
|
||||
fp = "|".join(
|
||||
[
|
||||
str(it.get("userKey") or ""),
|
||||
str(it.get("text") or "")[:120],
|
||||
str(it.get("at") or "")[:16],
|
||||
]
|
||||
)
|
||||
if fp in seen_fp:
|
||||
continue
|
||||
seen_fp.add(fp)
|
||||
deduped.append(it)
|
||||
items = deduped
|
||||
if want_key:
|
||||
items = [it for it in items if str(it.get("userKey") or "") == want_key]
|
||||
# Cluster same person for admin: newest first within each userKey group.
|
||||
groups: dict[str, list[dict[str, Any]]] = {}
|
||||
for it in items:
|
||||
key = str(it.get("userKey") or "unknown")
|
||||
groups.setdefault(key, []).append(it)
|
||||
clustered: list[dict[str, Any]] = []
|
||||
for key, rows in sorted(
|
||||
groups.items(),
|
||||
key=lambda kv: str(kv[1][0].get("at") or ""),
|
||||
reverse=True,
|
||||
):
|
||||
for i, row in enumerate(rows):
|
||||
clustered.append(
|
||||
{
|
||||
**row,
|
||||
"userCount": len(rows),
|
||||
"userIndex": i + 1,
|
||||
"userMax": FEEDBACK_MAX_PER_USER,
|
||||
"isGroupHead": i == 0,
|
||||
}
|
||||
)
|
||||
# Person dossier: return full timeline for one userKey (no pagination cut).
|
||||
if want_key:
|
||||
return {
|
||||
"ok": True,
|
||||
"total": len(clustered),
|
||||
"maxPerUser": FEEDBACK_MAX_PER_USER,
|
||||
"userKey": want_key,
|
||||
"personView": True,
|
||||
"items": clustered,
|
||||
}
|
||||
total = len(clustered)
|
||||
return {
|
||||
"ok": True,
|
||||
"total": total,
|
||||
"maxPerUser": FEEDBACK_MAX_PER_USER,
|
||||
"items": clustered[off : off + lim],
|
||||
}
|
||||
|
||||
|
||||
def admin_delete_feedback(fid: str) -> bool:
|
||||
@ -3457,6 +3613,16 @@ def admin_get_detail(entity: str, entity_id: str) -> dict[str, Any] | None:
|
||||
)
|
||||
except Exception:
|
||||
rec = None
|
||||
# Feedback may only exist in portal/local offline files.
|
||||
if not rec and entity == "feedback":
|
||||
try:
|
||||
listed = admin_list_feedback(limit=500, offset=0)
|
||||
for it in listed.get("items") or []:
|
||||
if str(it.get("id") or "") == str(entity_id):
|
||||
rec = dict(it)
|
||||
break
|
||||
except Exception:
|
||||
rec = None
|
||||
if not rec:
|
||||
return None
|
||||
# files / 语音厅录像:补可播 URL(S3 直链优先)
|
||||
@ -3471,6 +3637,24 @@ def admin_get_detail(entity: str, entity_id: str) -> dict[str, Any] | None:
|
||||
or _is_room_archive_row(rec)
|
||||
else rec.get("videoUrl") or "",
|
||||
}
|
||||
if entity == "feedback" and isinstance(rec, dict):
|
||||
meta = rec.get("meta") if isinstance(rec.get("meta"), dict) else {}
|
||||
guest = rec.get("guestId") or rec.get("guest_id") or ""
|
||||
contact = rec.get("contact") or ""
|
||||
user_key = str(rec.get("userKey") or rec.get("user_key") or "") or feedback_user_key(
|
||||
guest_id=str(guest),
|
||||
contact=str(contact),
|
||||
meta=meta,
|
||||
)
|
||||
rec = {
|
||||
**rec,
|
||||
"userKey": user_key,
|
||||
"guestId": guest,
|
||||
"contact": contact,
|
||||
"images": rec.get("images") if isinstance(rec.get("images"), list) else [],
|
||||
"meta": meta,
|
||||
"at": rec.get("at") or rec.get("created_at") or "",
|
||||
}
|
||||
hist = pb.list_all(
|
||||
C_ARCHIVES,
|
||||
filter=f"entity={pb_quote(entity)} && entity_id={pb_quote(entity_id)}",
|
||||
|
||||
@ -126,6 +126,8 @@ class FeedbackIn(BaseModel):
|
||||
kind: str = Field(default="建议", max_length=8)
|
||||
text: str = Field(min_length=1, max_length=4000)
|
||||
contact: str = Field(default="", max_length=120)
|
||||
images: list[str] = Field(default_factory=list)
|
||||
meta: dict | None = None
|
||||
|
||||
|
||||
class JoinLeadIn(BaseModel):
|
||||
@ -460,15 +462,16 @@ async def upload_media(
|
||||
max_size=max_avatar,
|
||||
)
|
||||
has_face = bool(face_meta and face_meta.ok)
|
||||
# Roster write must not fail the upload — file is already persisted.
|
||||
try:
|
||||
store.mark_face_photo(peer, uploaded.url, face_ok=has_face)
|
||||
except Exception as roster_exc: # pragma: no cover
|
||||
import logging
|
||||
# Only avatar/roster/profile photos belong on the face roster.
|
||||
if purpose_norm in {"avatar", "roster", "profile"}:
|
||||
try:
|
||||
store.mark_face_photo(peer, uploaded.url, face_ok=has_face)
|
||||
except Exception as roster_exc: # pragma: no cover
|
||||
import logging
|
||||
|
||||
logging.getLogger("social_svc.upload").warning(
|
||||
"mark_face_photo failed for %s: %s", peer, roster_exc
|
||||
)
|
||||
logging.getLogger("social_svc.upload").warning(
|
||||
"mark_face_photo failed for %s: %s", peer, roster_exc
|
||||
)
|
||||
return uploaded, face_meta, gate_on, has_face
|
||||
|
||||
try:
|
||||
@ -1033,10 +1036,30 @@ def put_my_roster(
|
||||
def post_feedback(
|
||||
body: FeedbackIn,
|
||||
x_social_guest_id: str | None = Header(default=None),
|
||||
x_social_email: str | None = Header(default=None),
|
||||
user_agent: str | None = Header(default=None, alias="User-Agent"),
|
||||
):
|
||||
guest = _guest(x_social_guest_id)
|
||||
store.init_db()
|
||||
return store.add_feedback(body.kind, body.text, body.contact, guest)
|
||||
meta = dict(body.meta) if isinstance(body.meta, dict) else {}
|
||||
email = (x_social_email or "").strip()[:160]
|
||||
if email and not meta.get("email"):
|
||||
meta["email"] = email
|
||||
if user_agent and "serverUserAgent" not in meta:
|
||||
meta["serverUserAgent"] = (user_agent or "")[:400]
|
||||
try:
|
||||
return store.add_feedback(
|
||||
body.kind,
|
||||
body.text,
|
||||
body.contact,
|
||||
guest,
|
||||
images=list(body.images or []),
|
||||
meta=meta,
|
||||
)
|
||||
except ValueError as exc:
|
||||
detail = str(exc)
|
||||
code = 429 if "最多" in detail else 400
|
||||
raise HTTPException(status_code=code, detail=detail) from exc
|
||||
|
||||
|
||||
@router.post("/join/leads")
|
||||
|
||||
@ -944,10 +944,25 @@ def list_liveness_audits(*, status: str = "", limit: int = 50) -> list[dict[str,
|
||||
return pb_data.list_liveness_audits(status=status, limit=limit)
|
||||
|
||||
|
||||
def add_feedback(kind: str, text: str, contact: str, guest_id: str) -> dict[str, Any]:
|
||||
def add_feedback(
|
||||
kind: str,
|
||||
text: str,
|
||||
contact: str,
|
||||
guest_id: str,
|
||||
*,
|
||||
images: list[str] | None = None,
|
||||
meta: dict | None = None,
|
||||
) -> dict[str, Any]:
|
||||
from social_svc import pb_data
|
||||
|
||||
return pb_data.add_feedback(kind, text, contact, guest_id)
|
||||
return pb_data.add_feedback(
|
||||
kind,
|
||||
text,
|
||||
contact,
|
||||
guest_id,
|
||||
images=images,
|
||||
meta=meta,
|
||||
)
|
||||
|
||||
|
||||
def upsert_join_lead(
|
||||
|
||||
@ -3,7 +3,14 @@
|
||||
* 整行可进详情;分页;软删除进存档。
|
||||
*/
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { Link, Navigate, useLocation, useNavigate, useParams } from 'react-router-dom'
|
||||
import {
|
||||
Link,
|
||||
Navigate,
|
||||
useLocation,
|
||||
useNavigate,
|
||||
useParams,
|
||||
useSearchParams,
|
||||
} from 'react-router-dom'
|
||||
import { api } from '../api/client'
|
||||
import {
|
||||
useSharedSocialPresence,
|
||||
@ -176,15 +183,37 @@ function Donut({
|
||||
)
|
||||
}
|
||||
|
||||
function feedbackPersonLabel(row: Record<string, unknown>): string {
|
||||
const meta =
|
||||
row.meta && typeof row.meta === 'object' && !Array.isArray(row.meta)
|
||||
? (row.meta as Record<string, unknown>)
|
||||
: {}
|
||||
const email = String(meta.email || '').trim()
|
||||
const contact = String(row.contact || '').trim()
|
||||
const name = String(meta.name || '').trim()
|
||||
const key = String(row.userKey || '')
|
||||
if (email) return email
|
||||
if (contact) return contact
|
||||
if (name) return name
|
||||
if (key.startsWith('email:')) return key.slice(6)
|
||||
if (key.startsWith('contact:')) return key.slice(8)
|
||||
if (key.startsWith('guest:')) return `访客 ${key.slice(6, 18)}`
|
||||
if (key.startsWith('weak:')) return `未登录 · ${key.slice(5, 13)}`
|
||||
return key || String(row.guestId || row.guest_id || '未知访客')
|
||||
}
|
||||
|
||||
export default function Social() {
|
||||
const { lane = 'intl', section: sectionParam } = useParams()
|
||||
const { pathname } = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const base = `/${lane}/social`
|
||||
const fromPath = pathname.split('/').filter(Boolean)[2] || 'overview'
|
||||
const sectionRaw = (sectionParam || fromPath || 'overview') as SectionKey
|
||||
const sectionValid = SECTIONS.includes(sectionRaw)
|
||||
const section: SectionKey = sectionValid ? sectionRaw : 'overview'
|
||||
const personKey =
|
||||
section === 'feedback' ? (searchParams.get('person') || '').trim() : ''
|
||||
|
||||
const [overview, setOverview] = useState<Overview | null>(null)
|
||||
const [stats, setStats] = useState<Stats | null>(null)
|
||||
@ -234,8 +263,18 @@ export default function Social() {
|
||||
return
|
||||
}
|
||||
const qs = new URLSearchParams()
|
||||
qs.set('limit', String(PAGE))
|
||||
qs.set('offset', String(offset))
|
||||
if (section === 'feedback' && personKey) {
|
||||
qs.set('userKey', personKey)
|
||||
qs.set('limit', '100')
|
||||
qs.set('offset', '0')
|
||||
} else if (section === 'feedback') {
|
||||
// Pull a wide window so we can fold into per-person rows.
|
||||
qs.set('limit', '200')
|
||||
qs.set('offset', '0')
|
||||
} else {
|
||||
qs.set('limit', String(PAGE))
|
||||
qs.set('offset', String(offset))
|
||||
}
|
||||
if (q.trim()) qs.set('q', q.trim())
|
||||
const apiSeg = SECTION_API[section]
|
||||
if (!apiSeg) {
|
||||
@ -271,7 +310,7 @@ export default function Social() {
|
||||
} finally {
|
||||
if (!silent) setLoading(false)
|
||||
}
|
||||
}, [section, q, offset])
|
||||
}, [section, q, offset, personKey])
|
||||
|
||||
useEffect(() => {
|
||||
setQ('')
|
||||
@ -282,6 +321,24 @@ export default function Social() {
|
||||
setEditRoster(null)
|
||||
}, [section])
|
||||
|
||||
useEffect(() => {
|
||||
setOffset(0)
|
||||
}, [personKey])
|
||||
|
||||
function openFeedbackPerson(key: string) {
|
||||
const k = key.trim()
|
||||
if (!k) return
|
||||
const next = new URLSearchParams(searchParams)
|
||||
next.set('person', k)
|
||||
setSearchParams(next, { replace: false })
|
||||
}
|
||||
|
||||
function clearFeedbackPerson() {
|
||||
const next = new URLSearchParams(searchParams)
|
||||
next.delete('person')
|
||||
setSearchParams(next, { replace: false })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadOverview().catch((e: Error) => setErr(e.message || '概览失败'))
|
||||
loadStats().catch(() => undefined)
|
||||
@ -445,6 +502,22 @@ export default function Social() {
|
||||
<span className="com-chip">活跃成员 {stats?.activeRoster ?? '—'}</span>
|
||||
<span className="com-chip">存档 {counts.archives ?? '—'}</span>
|
||||
</div>
|
||||
) : section === 'feedback' && personKey ? (
|
||||
<div className="com-chip-row">
|
||||
<button type="button" className="com-chip" onClick={clearFeedbackPerson}>
|
||||
← 全部访客
|
||||
</button>
|
||||
<span className="com-chip com-chip-ok">
|
||||
{feedbackPersonLabel(items[0] || { userKey: personKey })}
|
||||
</span>
|
||||
<span className="com-chip">共 {items.length} 条反馈</span>
|
||||
<span className="com-chip">上限 10</span>
|
||||
</div>
|
||||
) : section === 'feedback' ? (
|
||||
<div className="com-chip-row">
|
||||
<span className="com-chip">点「访客」看全部归类</span>
|
||||
<span className="com-chip">共 {total} 条</span>
|
||||
</div>
|
||||
) : section !== 'catalog' ? (
|
||||
<div className="com-chip-row">
|
||||
<span className="com-chip">共 {total} 条</span>
|
||||
@ -626,29 +699,59 @@ export default function Social() {
|
||||
</>
|
||||
)}
|
||||
<span className="com-muted" style={{ marginLeft: 'auto' }}>
|
||||
{loading ? '加载中…' : `第 ${pageFrom || 0}–${pageTo} / ${total}`}
|
||||
{loading
|
||||
? '加载中…'
|
||||
: section === 'feedback' && personKey
|
||||
? `该访客 ${items.length} 条`
|
||||
: section === 'feedback'
|
||||
? `共 ${total} 条 · 点访客看归类`
|
||||
: `第 ${pageFrom || 0}–${pageTo} / ${total}`}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost"
|
||||
disabled={!canPrev || loading}
|
||||
onClick={() => setOffset((o) => Math.max(0, o - PAGE))}
|
||||
>
|
||||
上一页
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost"
|
||||
disabled={!canNext || loading}
|
||||
onClick={() => setOffset((o) => o + PAGE)}
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
{section === 'feedback' && personKey ? (
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost"
|
||||
onClick={clearFeedbackPerson}
|
||||
>
|
||||
返回访客列表
|
||||
</button>
|
||||
) : null}
|
||||
{section !== 'feedback' ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost"
|
||||
disabled={!canPrev || loading}
|
||||
onClick={() => setOffset((o) => Math.max(0, o - PAGE))}
|
||||
>
|
||||
上一页
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost"
|
||||
disabled={!canNext || loading}
|
||||
onClick={() => setOffset((o) => o + PAGE)}
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<section className="com-panel com-table-wrap">
|
||||
{loading && !items.length ? (
|
||||
<p className="com-muted">加载中…</p>
|
||||
) : section === 'feedback' && personKey && !items.length ? (
|
||||
<div className="com-empty">
|
||||
<p className="com-muted">该访客暂无反馈</p>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost"
|
||||
onClick={clearFeedbackPerson}
|
||||
>
|
||||
返回列表
|
||||
</button>
|
||||
</div>
|
||||
) : !items.length ? (
|
||||
<div className="com-empty">
|
||||
<p className="com-muted">本列表暂无数据</p>
|
||||
@ -657,6 +760,77 @@ export default function Social() {
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{section === 'feedback' && personKey && items[0] ? (
|
||||
<div
|
||||
className="com-panel"
|
||||
style={{ marginBottom: 12, padding: 14 }}
|
||||
>
|
||||
<div className="com-chip-row" style={{ marginBottom: 8 }}>
|
||||
<strong>{feedbackPersonLabel(items[0])}</strong>
|
||||
<span className="com-chip">
|
||||
{items.length}/{String(items[0].userMax || 10)} 条
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost com-btn-sm"
|
||||
onClick={clearFeedbackPerson}
|
||||
>
|
||||
← 返回
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className="com-muted"
|
||||
style={{ fontSize: 12, lineHeight: 1.55, wordBreak: 'break-all' }}
|
||||
>
|
||||
<div>
|
||||
userKey <code>{personKey}</code>
|
||||
</div>
|
||||
<div>
|
||||
guestId{' '}
|
||||
<code>
|
||||
{String(items[0].guestId || items[0].guest_id || '—')}
|
||||
</code>
|
||||
</div>
|
||||
<div>联系 {String(items[0].contact || '—')}</div>
|
||||
{(() => {
|
||||
const meta =
|
||||
items[0].meta &&
|
||||
typeof items[0].meta === 'object' &&
|
||||
!Array.isArray(items[0].meta)
|
||||
? (items[0].meta as Record<string, unknown>)
|
||||
: {}
|
||||
const bits = [
|
||||
meta.email ? `邮箱 ${meta.email}` : '',
|
||||
meta.name ? `昵称 ${meta.name}` : '',
|
||||
meta.href ? `页面 ${meta.href}` : '',
|
||||
meta.timezone ? `时区 ${meta.timezone}` : '',
|
||||
meta.platform ? `平台 ${meta.platform}` : '',
|
||||
meta.serverIp ? `IP ${meta.serverIp}` : '',
|
||||
meta.userAgent
|
||||
? `UA ${String(meta.userAgent).slice(0, 100)}`
|
||||
: '',
|
||||
].filter(Boolean)
|
||||
return bits.length ? (
|
||||
<div style={{ marginTop: 6 }}>
|
||||
{bits.map((b) => (
|
||||
<div key={String(b)}>{String(b)}</div>
|
||||
))}
|
||||
<details style={{ marginTop: 6 }}>
|
||||
<summary>全部 meta</summary>
|
||||
<pre
|
||||
className="com-pre com-pre-sm"
|
||||
style={{ marginTop: 6 }}
|
||||
>
|
||||
{JSON.stringify(meta, null, 2)}
|
||||
</pre>
|
||||
</details>
|
||||
</div>
|
||||
) : null
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
<table className="com-table com-table-click">
|
||||
<thead>
|
||||
{section === 'messages' ? (
|
||||
@ -701,10 +875,10 @@ export default function Social() {
|
||||
) : null}
|
||||
{section === 'feedback' ? (
|
||||
<tr>
|
||||
<th>类型</th>
|
||||
<th>内容</th>
|
||||
<th>联系</th>
|
||||
<th>访客</th>
|
||||
<th>{personKey ? '#' : '类型'}</th>
|
||||
<th>{personKey ? '类型' : '内容'}</th>
|
||||
<th>{personKey ? '内容 / 截图' : '联系'}</th>
|
||||
<th>{personKey ? '联系' : '访客'}</th>
|
||||
<th>时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
@ -821,10 +995,15 @@ export default function Social() {
|
||||
section === 'joins' || section === 'roster'
|
||||
? Boolean(rowLivePeer(row, presence.peers))
|
||||
: false
|
||||
const feedbackPersonMode = section === 'feedback' && !!personKey
|
||||
const feedbackFlatMode = section === 'feedback' && !personKey
|
||||
const visitorKey = String(row.userKey || '')
|
||||
return (
|
||||
<tr
|
||||
key={id || JSON.stringify(row).slice(0, 40)}
|
||||
className={`com-tr-link${live ? ' is-live-row' : ''}`}
|
||||
className={`com-tr-link${live ? ' is-live-row' : ''}${
|
||||
feedbackPersonMode && row.isGroupHead ? ' is-group-head' : ''
|
||||
}`}
|
||||
onClick={() => openDetail(row)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
@ -895,19 +1074,89 @@ export default function Social() {
|
||||
<td>{fmtTime(row.at || row.created_at)}</td>
|
||||
</>
|
||||
) : null}
|
||||
{section === 'feedback' ? (
|
||||
{feedbackFlatMode ? (
|
||||
<>
|
||||
<td>
|
||||
<span className="com-badge tone-info">{String(row.kind || '—')}</span>
|
||||
{Number(row.userCount || 0) > 1 ? (
|
||||
<div className="com-muted" style={{ fontSize: 11, marginTop: 4 }}>
|
||||
同人 {String(row.userIndex)}/{String(row.userCount)}
|
||||
</div>
|
||||
) : null}
|
||||
</td>
|
||||
<td>{short(row.text, 56)}</td>
|
||||
<td>{short(row.contact, 24)}</td>
|
||||
<td>
|
||||
<code className="com-id">{short(row.guestId || row.guest_id, 14)}</code>
|
||||
<td>{short(row.contact, 24) || '—'}</td>
|
||||
<td
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (visitorKey) openFeedbackPerson(visitorKey)
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost com-btn-sm"
|
||||
title="查看该访客全部反馈与归类信息"
|
||||
disabled={!visitorKey}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (visitorKey) openFeedbackPerson(visitorKey)
|
||||
}}
|
||||
>
|
||||
{feedbackPersonLabel(row)}
|
||||
</button>
|
||||
<div className="com-muted" style={{ fontSize: 11, marginTop: 4 }}>
|
||||
{Number(row.userCount || 1)} 条 · 点访客看全部
|
||||
</div>
|
||||
</td>
|
||||
<td>{fmtTime(row.created_at || row.createdAt || row.at)}</td>
|
||||
</>
|
||||
) : null}
|
||||
{feedbackPersonMode ? (
|
||||
<>
|
||||
<td>
|
||||
<span className="com-muted">
|
||||
{String(row.userIndex || '—')}/{String(row.userCount || items.length)}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className="com-badge tone-info">{String(row.kind || '—')}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div>{short(row.text, 72)}</div>
|
||||
{Array.isArray(row.images) && row.images.length ? (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: 6,
|
||||
marginTop: 6,
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{(row.images as unknown[])
|
||||
.filter((u): u is string => typeof u === 'string')
|
||||
.slice(0, 4)
|
||||
.map((url) => (
|
||||
<a key={url} href={url} target="_blank" rel="noreferrer">
|
||||
<img
|
||||
src={url}
|
||||
alt=""
|
||||
style={{
|
||||
width: 44,
|
||||
height: 44,
|
||||
objectFit: 'cover',
|
||||
borderRadius: 8,
|
||||
}}
|
||||
/>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</td>
|
||||
<td>{short(row.contact, 24) || '—'}</td>
|
||||
<td>{fmtTime(row.created_at || row.createdAt || row.at)}</td>
|
||||
</>
|
||||
) : null}
|
||||
{section === 'joins' ? (
|
||||
<>
|
||||
<td>
|
||||
@ -1181,6 +1430,15 @@ export default function Social() {
|
||||
) : null}
|
||||
<td onClick={(e) => e.stopPropagation()}>
|
||||
<div className="com-row-actions">
|
||||
{feedbackFlatMode && visitorKey ? (
|
||||
<button
|
||||
type="button"
|
||||
className="com-btn com-btn-ghost com-btn-sm"
|
||||
onClick={() => openFeedbackPerson(visitorKey)}
|
||||
>
|
||||
该访客全部
|
||||
</button>
|
||||
) : null}
|
||||
{href ? (
|
||||
<Link className="com-btn com-btn-ghost com-btn-sm" to={href}>
|
||||
详情
|
||||
@ -1217,6 +1475,7 @@ export default function Social() {
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
</>
|
||||
|
||||
@ -263,11 +263,13 @@ function PrimaryFields({
|
||||
item,
|
||||
media,
|
||||
roster,
|
||||
lane = 'cn',
|
||||
}: {
|
||||
entity: string
|
||||
item: Record<string, unknown>
|
||||
media?: Record<string, unknown>
|
||||
roster?: Record<string, unknown>
|
||||
lane?: string
|
||||
}) {
|
||||
if (entity === 'joinLeads') {
|
||||
return <JoinPrimary item={item} media={media} roster={roster} />
|
||||
@ -387,6 +389,10 @@ function PrimaryFields({
|
||||
)
|
||||
}
|
||||
if (entity === 'feedback') {
|
||||
const userKey = String(val(item, 'userKey', 'user_key') || '')
|
||||
const imgs = Array.isArray(item.images)
|
||||
? (item.images as unknown[]).filter((u): u is string => typeof u === 'string')
|
||||
: []
|
||||
return (
|
||||
<div className="com-detail-hero">
|
||||
<div className="com-detail-name-row">
|
||||
@ -394,13 +400,35 @@ function PrimaryFields({
|
||||
<span className="com-badge tone-info">{String(val(item, 'kind') ?? '—')}</span>
|
||||
</div>
|
||||
<blockquote className="com-detail-quote">{String(val(item, 'text') ?? '—')}</blockquote>
|
||||
{imgs.length ? (
|
||||
<MediaGallery
|
||||
items={imgs.map((url, i) => ({
|
||||
key: `img-${i}`,
|
||||
label: `截图 ${i + 1}`,
|
||||
value: url,
|
||||
}))}
|
||||
/>
|
||||
) : null}
|
||||
<div className="com-detail-meta">
|
||||
<span>联系 {String(val(item, 'contact') ?? '—')}</span>
|
||||
<span>
|
||||
身份 <code>{userKey || '—'}</code>
|
||||
</span>
|
||||
<span>
|
||||
访客 <code>{String(val(item, 'guestId', 'guest_id') ?? '—')}</code>
|
||||
</span>
|
||||
<span>{fmtTime(val(item, 'at', 'created_at', 'createdAt'))}</span>
|
||||
</div>
|
||||
{userKey ? (
|
||||
<p style={{ margin: '10px 0 0' }}>
|
||||
<Link
|
||||
className="com-btn com-btn-ghost com-btn-sm"
|
||||
to={`/${lane}/social/feedback?person=${encodeURIComponent(userKey)}`}
|
||||
>
|
||||
查看该访客全部反馈
|
||||
</Link>
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@ -470,6 +498,7 @@ export default function SocialDetail() {
|
||||
const nav = useNavigate()
|
||||
const base = `/${lane}/social`
|
||||
const [data, setData] = useState<Detail | null>(null)
|
||||
const [siblings, setSiblings] = useState<Record<string, unknown>[]>([])
|
||||
const [err, setErr] = useState('')
|
||||
const [msg, setMsg] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
@ -517,6 +546,23 @@ export default function SocialDetail() {
|
||||
bio: String(item.bio || ''),
|
||||
})
|
||||
}
|
||||
if (entity === 'feedback') {
|
||||
const uk = String(item.userKey || item.user_key || '').trim()
|
||||
if (uk) {
|
||||
try {
|
||||
const sib = await api<{ items?: Record<string, unknown>[] }>(
|
||||
`/api/admin/social/ugc/feedback?userKey=${encodeURIComponent(uk)}&limit=100`,
|
||||
)
|
||||
setSiblings(Array.isArray(sib.items) ? sib.items : [])
|
||||
} catch {
|
||||
setSiblings([])
|
||||
}
|
||||
} else {
|
||||
setSiblings([])
|
||||
}
|
||||
} else {
|
||||
setSiblings([])
|
||||
}
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
@ -685,10 +731,55 @@ export default function SocialDetail() {
|
||||
item={item}
|
||||
media={data.media}
|
||||
roster={data.roster}
|
||||
lane={lane}
|
||||
/>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{!loading && !err && entity === 'feedback' && siblings.length > 0 ? (
|
||||
<section className="com-panel">
|
||||
<h2>该访客全部反馈({siblings.length})</h2>
|
||||
<div className="com-table-wrap">
|
||||
<table className="com-table com-table-click">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>类型</th>
|
||||
<th>内容</th>
|
||||
<th>时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{siblings.map((row) => {
|
||||
const rid = String(row.id || '')
|
||||
const active = rid === id
|
||||
return (
|
||||
<tr
|
||||
key={rid}
|
||||
className={active ? 'is-live-row' : 'com-tr-link'}
|
||||
onClick={() => {
|
||||
if (!rid || active) return
|
||||
nav(`${base}/feedback/${encodeURIComponent(rid)}`)
|
||||
}}
|
||||
>
|
||||
<td>
|
||||
{String(row.userIndex || '—')}/{String(row.userCount || siblings.length)}
|
||||
{active ? ' · 当前' : ''}
|
||||
</td>
|
||||
<td>
|
||||
<span className="com-badge tone-info">{String(row.kind || '—')}</span>
|
||||
</td>
|
||||
<td>{short(row.text, 72)}</td>
|
||||
<td>{fmtTime(row.at || row.created_at || row.createdAt)}</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{edit && entity === 'roster' ? (
|
||||
<section className="com-panel">
|
||||
<h2>编辑资料</h2>
|
||||
|
||||
@ -80,7 +80,7 @@ export const SECTION_DESC: Record<SectionKey, string> = {
|
||||
reports: '用户举报,优先处理。',
|
||||
blocks: '拉黑记录。',
|
||||
files: '聊天与资料里上传的文件。',
|
||||
feedback: '用户反馈。',
|
||||
feedback: '按访客整理;点访客看全部反馈。',
|
||||
archives: '已移入存档的记录(加入细节在「加入线索」里看)。',
|
||||
catalog: '社区目录内容配置。',
|
||||
}
|
||||
|
||||
@ -2,6 +2,11 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { requireAdminSession } from "~/lib/admin-auth";
|
||||
import {
|
||||
FEEDBACK_MAX_PER_USER,
|
||||
feedbackUserKey,
|
||||
rowMatchesFeedbackUser,
|
||||
} from "~/lib/feedback-identity";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
@ -14,6 +19,9 @@ type Item = {
|
||||
text: string;
|
||||
contact: string;
|
||||
guestId: string;
|
||||
userKey: string;
|
||||
images: string[];
|
||||
meta: Record<string, unknown>;
|
||||
at: string;
|
||||
source: string;
|
||||
};
|
||||
@ -54,6 +62,30 @@ function uid(): string {
|
||||
return `fb_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
|
||||
function normalizeImages(raw: unknown): string[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
return raw
|
||||
.filter((u): u is string => typeof u === "string")
|
||||
.map((u) => u.trim())
|
||||
.filter((u) => /^https?:\/\//i.test(u))
|
||||
.slice(0, 8)
|
||||
.map((u) => u.slice(0, 500));
|
||||
}
|
||||
|
||||
function countForUser(store: Store, userKey: string): number {
|
||||
return store.items.filter((row) =>
|
||||
rowMatchesFeedbackUser(
|
||||
{
|
||||
userKey: row.userKey,
|
||||
guestId: row.guestId,
|
||||
contact: row.contact,
|
||||
meta: row.meta,
|
||||
},
|
||||
userKey,
|
||||
),
|
||||
).length;
|
||||
}
|
||||
|
||||
/** Admin / debug list — local offline seed. */
|
||||
export async function GET(req: NextRequest) {
|
||||
if (!(await requireAdminSession())) {
|
||||
@ -78,6 +110,7 @@ export async function GET(req: NextRequest) {
|
||||
{
|
||||
ok: true,
|
||||
total: rows.length,
|
||||
maxPerUser: FEEDBACK_MAX_PER_USER,
|
||||
items: rows.slice(offset, offset + limit),
|
||||
},
|
||||
{ headers: { "Cache-Control": "no-store" } },
|
||||
@ -106,6 +139,33 @@ export async function POST(req: NextRequest) {
|
||||
const guestId = String(
|
||||
body.guestId || req.headers.get("x-social-guest-id") || "",
|
||||
).slice(0, 120);
|
||||
const images = normalizeImages(body.images);
|
||||
const meta =
|
||||
body.meta && typeof body.meta === "object" && !Array.isArray(body.meta)
|
||||
? { ...(body.meta as Record<string, unknown>) }
|
||||
: {};
|
||||
const headerEmail = (req.headers.get("x-social-email") || "").trim().slice(0, 160);
|
||||
if (headerEmail && !meta.email) meta.email = headerEmail;
|
||||
meta.serverUserAgent = (req.headers.get("user-agent") || "").slice(0, 400);
|
||||
meta.serverIp =
|
||||
req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ||
|
||||
req.headers.get("x-real-ip") ||
|
||||
"";
|
||||
const userKey = feedbackUserKey({ guestId, contact, meta });
|
||||
const store = await readStore();
|
||||
const used = countForUser(store, userKey);
|
||||
if (used >= FEEDBACK_MAX_PER_USER) {
|
||||
return withCors(
|
||||
NextResponse.json(
|
||||
{
|
||||
detail: `每人最多提交 ${FEEDBACK_MAX_PER_USER} 条反馈`,
|
||||
used,
|
||||
max: FEEDBACK_MAX_PER_USER,
|
||||
},
|
||||
{ status: 429 },
|
||||
),
|
||||
);
|
||||
}
|
||||
const now = new Date().toISOString();
|
||||
const item: Item = {
|
||||
id: uid(),
|
||||
@ -113,31 +173,30 @@ export async function POST(req: NextRequest) {
|
||||
text,
|
||||
contact,
|
||||
guestId,
|
||||
userKey,
|
||||
images,
|
||||
meta,
|
||||
at: now,
|
||||
source: "portal-local",
|
||||
};
|
||||
const store = await readStore();
|
||||
store.items.unshift(item);
|
||||
store.items = store.items.slice(0, 2000);
|
||||
await writeStore(store);
|
||||
|
||||
// Best-effort forward to social_svc (PB) — failure does not fail the request
|
||||
const payload = JSON.stringify({ kind, text, contact });
|
||||
const payload = JSON.stringify({ kind, text, contact, images, meta });
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Social-Guest-Id": guestId || "portal",
|
||||
};
|
||||
for (const raw of [
|
||||
process.env.SOCIAL_API_URL,
|
||||
process.env.API_URL,
|
||||
"http://127.0.0.1:8080",
|
||||
]) {
|
||||
for (const raw of [process.env.SOCIAL_API_URL, process.env.API_URL]) {
|
||||
const base = (raw || "").replace(/\/$/, "");
|
||||
if (!base) continue;
|
||||
if (!base || /127\.0\.0\.1|localhost/i.test(base)) continue;
|
||||
void fetch(`${base}/api/social/v1/feedback`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: payload,
|
||||
signal: AbortSignal.timeout(4000),
|
||||
}).catch(() => undefined);
|
||||
}
|
||||
|
||||
@ -148,9 +207,13 @@ export async function POST(req: NextRequest) {
|
||||
kind: item.kind,
|
||||
text: item.text,
|
||||
contact: item.contact,
|
||||
images: item.images,
|
||||
userKey: item.userKey,
|
||||
guestId: item.guestId,
|
||||
at: item.at,
|
||||
stored: "local",
|
||||
remaining: Math.max(0, FEEDBACK_MAX_PER_USER - used - 1),
|
||||
max: FEEDBACK_MAX_PER_USER,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
53
src/lib/feedback-identity.ts
Normal file
53
src/lib/feedback-identity.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/** Stable identity for feedback rate-limit + admin clustering. */
|
||||
|
||||
export const FEEDBACK_MAX_PER_USER = 10;
|
||||
|
||||
export function feedbackUserKey(input: {
|
||||
guestId?: string;
|
||||
contact?: string;
|
||||
meta?: Record<string, unknown> | null;
|
||||
}): string {
|
||||
const meta = input.meta && typeof input.meta === "object" ? input.meta : {};
|
||||
const email = String(meta.email || "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (email.includes("@")) return `email:${email.slice(0, 160)}`;
|
||||
|
||||
const contact = String(input.contact || "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.slice(0, 120);
|
||||
if (contact.includes("@")) return `email:${contact}`;
|
||||
if (contact) return `contact:${contact}`;
|
||||
|
||||
const guest = String(input.guestId || meta.guestId || "")
|
||||
.trim()
|
||||
.slice(0, 120);
|
||||
if (guest) return `guest:${guest}`;
|
||||
|
||||
const ua = String(meta.userAgent || meta.serverUserAgent || "").slice(0, 96);
|
||||
const tz = String(meta.timezone || "");
|
||||
const weak = `${ua}|${tz}|${String(meta.platform || "")}`;
|
||||
let h = 0;
|
||||
for (let i = 0; i < weak.length; i++) h = (h * 31 + weak.charCodeAt(i)) >>> 0;
|
||||
return `weak:${h.toString(16)}`;
|
||||
}
|
||||
|
||||
export function rowMatchesFeedbackUser(
|
||||
row: {
|
||||
userKey?: string;
|
||||
guestId?: string;
|
||||
contact?: string;
|
||||
meta?: Record<string, unknown> | null;
|
||||
},
|
||||
key: string,
|
||||
): boolean {
|
||||
if (row.userKey && row.userKey === key) return true;
|
||||
return (
|
||||
feedbackUserKey({
|
||||
guestId: row.guestId,
|
||||
contact: row.contact,
|
||||
meta: row.meta,
|
||||
}) === key
|
||||
);
|
||||
}
|
||||
@ -675,11 +675,11 @@ export const DEFAULT_REMOTE_CONFIG: NomadroRemoteConfig = {
|
||||
"先选城市,再挑适合见面的咖啡馆。看完介绍、聊过天之后,出来见一面会更自然。",
|
||||
},
|
||||
team: {
|
||||
eyebrow: "不只好玩,也能做事",
|
||||
title: "一起,做点事",
|
||||
accent: "招聘",
|
||||
eyebrow: "一起做事",
|
||||
title: "招聘",
|
||||
accent: "帮手 · 兼职 · 全职",
|
||||
description:
|
||||
"有人在招帮手、兼职伙伴;也有人一起做共创(小册与视频)。点卡片看看详情。",
|
||||
"帮手、兼职、全职都在这里。点一条看看详情,感兴趣就留个联系方式。",
|
||||
},
|
||||
gigs: {
|
||||
eyebrow: "帮得上忙的机会",
|
||||
|
||||
@ -749,3 +749,329 @@
|
||||
min-height: 42px;
|
||||
}
|
||||
}
|
||||
|
||||
/* —— 招聘看板(/social/team)—— */
|
||||
.social-hire {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
.social-hire-hero {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 8px 0 4px;
|
||||
}
|
||||
.social-hire-eyebrow {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.12em;
|
||||
color: var(--sx-mint, #4ecdc4);
|
||||
}
|
||||
.social-hire-hero h1 {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: 10px 14px;
|
||||
font-family: var(--font-display, inherit);
|
||||
line-height: 1.1;
|
||||
}
|
||||
.social-hire-title {
|
||||
font-size: clamp(34px, 7vw, 56px);
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.05em;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.social-hire-accent {
|
||||
font-size: clamp(14px, 2.2vw, 18px);
|
||||
font-weight: 550;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.social-hire-desc {
|
||||
margin: 0;
|
||||
max-width: 36rem;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.social-hire-switch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--sx-line, rgba(255, 255, 255, 0.1));
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
.social-hire-switch-on,
|
||||
.social-hire-switch-off {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
min-height: 40px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
color: var(--text-secondary);
|
||||
transition:
|
||||
background 0.25s ease,
|
||||
color 0.25s ease,
|
||||
transform 0.25s ease;
|
||||
}
|
||||
.social-hire-switch-on {
|
||||
color: #0a0e17;
|
||||
background: var(--sx-mint, #4ecdc4);
|
||||
}
|
||||
.social-hire-switch-off:hover {
|
||||
color: var(--text-primary);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
.social-hire-rail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
border-radius: 18px;
|
||||
border: 1px solid var(--sx-line, rgba(255, 255, 255, 0.08));
|
||||
background:
|
||||
linear-gradient(180deg, rgba(78, 205, 196, 0.06), transparent 60%),
|
||||
rgba(17, 24, 39, 0.55);
|
||||
}
|
||||
.social-hire-kinds {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.social-hire-kinds > button {
|
||||
min-height: 40px;
|
||||
padding: 0 14px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
font-weight: 550;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
background 0.2s ease,
|
||||
border-color 0.2s ease,
|
||||
color 0.2s ease,
|
||||
transform 0.2s ease;
|
||||
}
|
||||
.social-hire-kinds > button.is-on,
|
||||
.social-hire-saved.is-on {
|
||||
color: #0a0e17;
|
||||
background: var(--sx-mint, #4ecdc4);
|
||||
border-color: transparent;
|
||||
}
|
||||
.social-hire-kinds > button:hover:not(.is-on) {
|
||||
color: var(--text-primary);
|
||||
border-color: rgba(78, 205, 196, 0.35);
|
||||
}
|
||||
.social-hire-saved {
|
||||
margin-left: auto;
|
||||
}
|
||||
.social-hire-count {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.social-hire-count strong {
|
||||
font-family: var(--font-display, inherit);
|
||||
font-size: 28px;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.04em;
|
||||
color: var(--text-primary);
|
||||
line-height: 1;
|
||||
}
|
||||
.social-hire-reset {
|
||||
margin-left: auto;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--sx-mint, #4ecdc4);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
min-height: 36px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
.social-hire-board {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
.social-hire-row {
|
||||
display: grid;
|
||||
grid-template-columns: 48px minmax(0, 1fr) auto;
|
||||
gap: 12px 14px;
|
||||
align-items: start;
|
||||
padding: 14px 16px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
background: rgba(17, 24, 39, 0.72);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition:
|
||||
border-color 0.25s ease,
|
||||
transform 0.25s ease,
|
||||
background 0.25s ease,
|
||||
box-shadow 0.25s ease;
|
||||
}
|
||||
.social-hire-row::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0 auto 0 0;
|
||||
width: 3px;
|
||||
background: var(--sx-mint, #4ecdc4);
|
||||
opacity: 0.85;
|
||||
}
|
||||
.social-hire-row.tone-volunteer::before {
|
||||
background: var(--sx-coral, #ff6b6b);
|
||||
}
|
||||
.social-hire-row.tone-fulltime::before {
|
||||
background: var(--sx-gold, #ffe66d);
|
||||
}
|
||||
.social-hire-row:hover {
|
||||
border-color: rgba(78, 205, 196, 0.28);
|
||||
background: rgba(22, 32, 48, 0.92);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
|
||||
}
|
||||
.social-hire-row-mark {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid rgba(78, 205, 196, 0.22);
|
||||
color: var(--sx-mint, #4ecdc4);
|
||||
background: rgba(78, 205, 196, 0.08);
|
||||
}
|
||||
.social-hire-row.tone-volunteer .social-hire-row-mark {
|
||||
color: var(--sx-coral, #ff6b6b);
|
||||
border-color: rgba(255, 107, 107, 0.25);
|
||||
background: rgba(255, 107, 107, 0.08);
|
||||
}
|
||||
.social-hire-row.tone-fulltime .social-hire-row-mark {
|
||||
color: var(--sx-gold, #ffe66d);
|
||||
border-color: rgba(255, 230, 109, 0.28);
|
||||
background: rgba(255, 230, 109, 0.08);
|
||||
}
|
||||
.social-hire-row-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
}
|
||||
.social-hire-row-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
}
|
||||
.social-hire-kind {
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--sx-mint, #4ecdc4);
|
||||
text-transform: none;
|
||||
}
|
||||
.social-hire-row.tone-volunteer .social-hire-kind {
|
||||
color: var(--sx-coral, #ff6b6b);
|
||||
}
|
||||
.social-hire-row.tone-fulltime .social-hire-kind {
|
||||
color: var(--sx-gold, #ffe66d);
|
||||
}
|
||||
.social-hire-row-body h2 {
|
||||
margin: 0;
|
||||
font-family: var(--font-display, inherit);
|
||||
font-size: clamp(17px, 2.4vw, 22px);
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.03em;
|
||||
line-height: 1.25;
|
||||
}
|
||||
.social-hire-row-body > p {
|
||||
margin: 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
}
|
||||
.social-hire-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px 16px;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.social-hire-meta > span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.social-hire-pay {
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
.social-hire-tags {
|
||||
margin: 2px 0 0;
|
||||
}
|
||||
.social-hire-row-cta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-self: center;
|
||||
}
|
||||
.social-hire-row-cta .social-btn {
|
||||
white-space: nowrap;
|
||||
}
|
||||
.social-apply-hero.tone-volunteer {
|
||||
border-color: rgba(255, 107, 107, 0.28);
|
||||
}
|
||||
.social-apply-hero.tone-fulltime {
|
||||
border-color: rgba(255, 230, 109, 0.28);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.social-hire-row {
|
||||
grid-template-columns: 44px minmax(0, 1fr);
|
||||
}
|
||||
.social-hire-row-mark {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 14px;
|
||||
}
|
||||
.social-hire-row-cta {
|
||||
grid-column: 1 / -1;
|
||||
width: 100%;
|
||||
}
|
||||
.social-hire-row-cta .social-btn {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
min-height: 44px;
|
||||
}
|
||||
.social-hire-saved {
|
||||
margin-left: 0;
|
||||
}
|
||||
.social-hire-rail {
|
||||
padding: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 960px) {
|
||||
.social-hire-rail {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
.social-hire-rail .social-search {
|
||||
flex: 1;
|
||||
min-width: 220px;
|
||||
}
|
||||
.social-hire-kinds {
|
||||
flex: 1.2;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,10 +85,14 @@ export function CommunityFeedback() {
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
try {
|
||||
const { collectFeedbackClientMeta } = await import(
|
||||
"@social/lib/feedbackMeta"
|
||||
);
|
||||
await socialApi.postFeedback({
|
||||
...draft,
|
||||
text: draft.text.trim(),
|
||||
contact: draft.contact.trim(),
|
||||
meta: collectFeedbackClientMeta({ ui: "feedback-page" }),
|
||||
});
|
||||
setDelivery("sent");
|
||||
setStatus(socialTx("已提交,感谢反馈。"));
|
||||
@ -141,19 +145,6 @@ export function CommunityFeedback() {
|
||||
) : (
|
||||
<form className="social-form" onSubmit={(event) => void submit(event)}>
|
||||
<fieldset disabled={busy} className="social-fieldset">
|
||||
<div className="social-filters">
|
||||
{(["建议", "反馈"] as const).map((kind) => (
|
||||
<button
|
||||
type="button"
|
||||
key={kind}
|
||||
className={draft.kind === kind ? "active" : ""}
|
||||
aria-pressed={draft.kind === kind}
|
||||
onClick={() => update("kind", kind)}
|
||||
>
|
||||
{socialTx(kind)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label>
|
||||
{socialTx("内容")}
|
||||
<textarea
|
||||
|
||||
@ -9,17 +9,15 @@ import {
|
||||
Check,
|
||||
Globe2,
|
||||
HeartHandshake,
|
||||
MapPin,
|
||||
Send,
|
||||
Sparkles,
|
||||
} from "lucide-react";
|
||||
import SiteShell from "./SiteShell";
|
||||
import {
|
||||
BookmarkButton,
|
||||
DemoBadge,
|
||||
EmptyState,
|
||||
PageIntro,
|
||||
SearchField,
|
||||
ResultSummary,
|
||||
SocialDialog,
|
||||
} from "./SocialUI";
|
||||
import { TEAM_KIND_LABEL } from "@social/lib/seed";
|
||||
@ -40,6 +38,12 @@ const NOTE_PROMPTS = [
|
||||
"想一起做成…",
|
||||
] as const;
|
||||
|
||||
function kindTone(kind?: string) {
|
||||
if (kind === "volunteer") return "volunteer";
|
||||
if (kind === "fulltime") return "fulltime";
|
||||
return "parttime";
|
||||
}
|
||||
|
||||
function ApplicationForm({ gig }: { gig: SocialGig }) {
|
||||
const [draft, setDraft] = useLocalState(`gig-draft:${gig.id}`, {
|
||||
name: "",
|
||||
@ -127,7 +131,7 @@ function ApplicationForm({ gig }: { gig: SocialGig }) {
|
||||
|
||||
return (
|
||||
<div className="social-apply">
|
||||
<div className="social-apply-hero">
|
||||
<div className={`social-apply-hero tone-${kindTone(gig.kind)}`}>
|
||||
<span className="social-apply-kind">
|
||||
{socialTx(TEAM_KIND_LABEL[gig.kind || "parttime"])}
|
||||
</span>
|
||||
@ -158,7 +162,10 @@ function ApplicationForm({ gig }: { gig: SocialGig }) {
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<form className="social-form social-apply-form" onSubmit={(e) => void submit(e)}>
|
||||
<form
|
||||
className="social-form social-apply-form"
|
||||
onSubmit={(e) => void submit(e)}
|
||||
>
|
||||
<fieldset disabled={busy} className="social-fieldset">
|
||||
<label>
|
||||
{socialTx("怎么称呼你")}
|
||||
@ -219,9 +226,7 @@ function ApplicationForm({ gig }: { gig: SocialGig }) {
|
||||
<button
|
||||
type="submit"
|
||||
className="social-btn primary"
|
||||
disabled={
|
||||
busy || !draft.name.trim() || !draft.contact.trim()
|
||||
}
|
||||
disabled={busy || !draft.name.trim() || !draft.contact.trim()}
|
||||
>
|
||||
<Send size={14} />
|
||||
{busy
|
||||
@ -240,7 +245,9 @@ function ApplicationForm({ gig }: { gig: SocialGig }) {
|
||||
</p>
|
||||
) : null}
|
||||
<small className="social-muted">
|
||||
{socialTx("草稿会先留在你这边。提交只是表达兴趣,不代表已经被录用。")}
|
||||
{socialTx(
|
||||
"草稿会先留在你这边。提交只是表达兴趣,不代表已经被录用。",
|
||||
)}
|
||||
</small>
|
||||
</form>
|
||||
</div>
|
||||
@ -271,142 +278,190 @@ export default function RoleBoard({
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase().trim()),
|
||||
);
|
||||
const filtered = Boolean(query || kind !== "all" || savedOnly);
|
||||
|
||||
return (
|
||||
<SiteShell title={socialTx("一起做事")}>
|
||||
<PageIntro title={socialTx("一起,做点事")} accent="招聘">
|
||||
<div className="social-actions social-cocreate-switch">
|
||||
<span className="social-btn primary" aria-current="page">
|
||||
{socialTx("招聘")}
|
||||
</span>
|
||||
<Link className="social-btn" href={socialPath("/ebook")}>
|
||||
<BookOpen size={14} />
|
||||
{socialTx("共创")}
|
||||
</Link>
|
||||
<DemoBadge>
|
||||
{catalog.source === "remote" ? "最新机会" : "先看看这些机会"}
|
||||
</DemoBadge>
|
||||
<span className="social-muted">{roles.length} 个机会</span>
|
||||
</div>
|
||||
</PageIntro>
|
||||
<p className="social-muted social-event-lead reveal">
|
||||
{socialTx("远程也能一起推进:认领角色、写申请,草稿会先留在本机。")}
|
||||
</p>
|
||||
<div className="social-toolbar reveal">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder={socialTx("角色 / 技能 / 关键词")}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className={`social-save${savedOnly ? " selected" : ""}`}
|
||||
aria-pressed={savedOnly}
|
||||
onClick={() => setSavedOnly(!savedOnly)}
|
||||
>
|
||||
{socialTx("收藏 · ")}
|
||||
{saved.length}
|
||||
</button>
|
||||
</div>
|
||||
<div className="social-filters reveal">
|
||||
{([["all", "全部"], ...Object.entries(TEAM_KIND_LABEL)] as [string, string][]).map(
|
||||
([id, label]) => (
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
className={id === kind ? "active" : ""}
|
||||
aria-pressed={id === kind}
|
||||
onClick={() => setKind(id)}
|
||||
>
|
||||
{socialTx(label)}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
<ResultSummary count={roles.length} unit={socialTx("个机会")} filtered={Boolean(query || kind !== "all" || savedOnly)} onReset={() => { setQuery(""); setKind("all"); setSavedOnly(false); }} />
|
||||
<div className="social-grid social-role-grid">
|
||||
{roles.map((gig, index) => {
|
||||
const d = txGig(gig);
|
||||
return (
|
||||
<article
|
||||
className="social-card social-role-card social-panel-fx reveal"
|
||||
key={gig.id}
|
||||
style={{ ["--stagger" as string]: `${index * 70}ms` }}
|
||||
>
|
||||
<div className="social-role-art" aria-hidden="true">
|
||||
<span>{String(index + 1).padStart(2, "0")}</span>
|
||||
<i />
|
||||
<i />
|
||||
{gig.kind === "volunteer" ? (
|
||||
<HeartHandshake size={28} strokeWidth={1.2} />
|
||||
) : (
|
||||
<BriefcaseBusiness size={28} strokeWidth={1.2} />
|
||||
)}
|
||||
</div>
|
||||
<div className="social-card-top">
|
||||
<div className={`social-role-symbol tone-${index % 3}`}>
|
||||
{gig.kind === "volunteer" ? (
|
||||
<HeartHandshake size={27} />
|
||||
) : (
|
||||
<BriefcaseBusiness size={27} />
|
||||
)}
|
||||
</div>
|
||||
<BookmarkButton id={gig.id} collection="saved-roles" />
|
||||
</div>
|
||||
<span className="social-role-type">
|
||||
{socialTx(TEAM_KIND_LABEL[gig.kind || "parttime"])}
|
||||
<SiteShell title={socialTx("招聘")}>
|
||||
<div className="social-hire">
|
||||
<header className="social-hire-hero">
|
||||
<p className="social-hire-eyebrow">{socialTx("一起做事")}</p>
|
||||
<h1>
|
||||
<span className="social-hire-title">{socialTx("招聘")}</span>
|
||||
<span className="social-hire-accent">
|
||||
{socialTx("帮手 · 兼职 · 全职")}
|
||||
</span>
|
||||
<h2>{d.title}</h2>
|
||||
<p>{d.role}</p>
|
||||
<div className="social-role-meta">
|
||||
<span>
|
||||
<Globe2 size={13} />
|
||||
{socialTx(gig.remote ? "线上也能做" : "可以见面做")}
|
||||
</span>
|
||||
<span>{d.pay}</span>
|
||||
</div>
|
||||
<div className="social-tags">
|
||||
{d.tags.map((tag) => (
|
||||
<span key={tag}>{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
</h1>
|
||||
<p className="social-hire-desc">
|
||||
{socialTx(
|
||||
"点一条看看详情,感兴趣就留个联系方式。草稿会先留在本机。",
|
||||
)}
|
||||
</p>
|
||||
<div className="social-hire-switch">
|
||||
<span className="social-hire-switch-on" aria-current="page">
|
||||
<BriefcaseBusiness size={14} />
|
||||
{socialTx("招聘")}
|
||||
</span>
|
||||
<Link className="social-hire-switch-off" href={socialPath("/ebook")}>
|
||||
<BookOpen size={14} />
|
||||
{socialTx("共创")}
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="social-hire-rail reveal">
|
||||
<SearchField
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
placeholder={socialTx("角色 / 技能 / 关键词")}
|
||||
/>
|
||||
<div className="social-hire-kinds" role="tablist" aria-label={socialTx("类型")}>
|
||||
{(
|
||||
[["all", "全部"], ...Object.entries(TEAM_KIND_LABEL)] as [
|
||||
string,
|
||||
string,
|
||||
][]
|
||||
).map(([id, label]) => (
|
||||
<button
|
||||
key={id}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={id === kind}
|
||||
className={id === kind ? "is-on" : ""}
|
||||
onClick={() => setKind(id)}
|
||||
>
|
||||
{socialTx(label)}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
onClick={() => setActive(gig)}
|
||||
className={`social-hire-saved${savedOnly ? " is-on" : ""}`}
|
||||
aria-pressed={savedOnly}
|
||||
onClick={() => setSavedOnly(!savedOnly)}
|
||||
>
|
||||
{socialTx("我想参与")} <ArrowUpRight size={14} />
|
||||
{socialTx("收藏")} · {saved.length}
|
||||
</button>
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
{!roles.length && (
|
||||
<EmptyState
|
||||
title={socialTx("暂时没有合适的机会")}
|
||||
description={socialTx("换个词试试,或者看看共创内容找灵感。")}
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="social-hire-count" role="status">
|
||||
<strong>{roles.length}</strong>
|
||||
<span>{socialTx("个机会")}</span>
|
||||
{filtered ? (
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
className="social-hire-reset"
|
||||
onClick={() => {
|
||||
setQuery("");
|
||||
setKind("all");
|
||||
setSavedOnly(false);
|
||||
}}
|
||||
>
|
||||
{socialTx("重新看看")}
|
||||
{socialTx("清除筛选")}
|
||||
</button>
|
||||
<Link className="social-btn" href={socialPath("/ebook")}>
|
||||
<Sparkles size={14} />
|
||||
{socialTx("去共创逛逛")}
|
||||
</Link>
|
||||
</EmptyState>
|
||||
)}
|
||||
) : (
|
||||
<span className="social-muted">
|
||||
{catalog.source === "remote"
|
||||
? socialTx("最新机会")
|
||||
: socialTx("本地机会")}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="social-hire-board">
|
||||
{roles.map((gig, index) => {
|
||||
const d = txGig(gig);
|
||||
const tone = kindTone(gig.kind);
|
||||
return (
|
||||
<article
|
||||
key={gig.id}
|
||||
className={`social-hire-row tone-${tone} reveal`}
|
||||
style={{ ["--stagger" as string]: `${index * 45}ms` }}
|
||||
>
|
||||
<div className="social-hire-row-mark" aria-hidden>
|
||||
{gig.kind === "volunteer" ? (
|
||||
<HeartHandshake size={20} strokeWidth={1.6} />
|
||||
) : (
|
||||
<BriefcaseBusiness size={20} strokeWidth={1.6} />
|
||||
)}
|
||||
</div>
|
||||
<div className="social-hire-row-body">
|
||||
<div className="social-hire-row-top">
|
||||
<span className="social-hire-kind">
|
||||
{socialTx(TEAM_KIND_LABEL[gig.kind || "parttime"])}
|
||||
</span>
|
||||
<BookmarkButton id={gig.id} collection="saved-roles" />
|
||||
</div>
|
||||
<h2>{d.title}</h2>
|
||||
{d.role &&
|
||||
d.role !== d.title &&
|
||||
d.role !== TEAM_KIND_LABEL[gig.kind || "parttime"] ? (
|
||||
<p>{d.role}</p>
|
||||
) : null}
|
||||
<div className="social-hire-meta">
|
||||
<span>
|
||||
{gig.remote ? (
|
||||
<Globe2 size={13} />
|
||||
) : (
|
||||
<MapPin size={13} />
|
||||
)}
|
||||
{socialTx(gig.remote ? "线上也能做" : "可以见面做")}
|
||||
</span>
|
||||
<span className="social-hire-pay">{d.pay}</span>
|
||||
</div>
|
||||
{d.tags.length ? (
|
||||
<div className="social-tags social-hire-tags">
|
||||
{d.tags.slice(0, 5).map((tag) => (
|
||||
<span key={tag}>{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="social-hire-row-cta">
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn primary"
|
||||
onClick={() => setActive(gig)}
|
||||
>
|
||||
{socialTx("我想参与")}
|
||||
<ArrowUpRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
})}
|
||||
{!roles.length ? (
|
||||
<EmptyState
|
||||
title={socialTx("暂时没有合适的机会")}
|
||||
description={socialTx("换个词试试,或者看看共创内容找灵感。")}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="social-btn"
|
||||
onClick={() => {
|
||||
setQuery("");
|
||||
setKind("all");
|
||||
setSavedOnly(false);
|
||||
}}
|
||||
>
|
||||
{socialTx("重新看看")}
|
||||
</button>
|
||||
<Link className="social-btn" href={socialPath("/ebook")}>
|
||||
<Sparkles size={14} />
|
||||
{socialTx("去共创逛逛")}
|
||||
</Link>
|
||||
</EmptyState>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{active && (
|
||||
<SocialDialog title={socialTx("表达兴趣")} onClose={() => setActive(null)}>
|
||||
|
||||
{active ? (
|
||||
<SocialDialog
|
||||
title={socialTx("表达兴趣")}
|
||||
onClose={() => setActive(null)}
|
||||
>
|
||||
<ApplicationForm gig={active} />
|
||||
</SocialDialog>
|
||||
)}
|
||||
) : null}
|
||||
</SiteShell>
|
||||
);
|
||||
}
|
||||
|
||||
@ -229,6 +229,76 @@
|
||||
box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.16);
|
||||
}
|
||||
|
||||
.sfm-images {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.sfm-images-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
font-size: 0.82rem;
|
||||
color: color-mix(in srgb, #f5f0e8 70%, transparent);
|
||||
}
|
||||
|
||||
.sfm-thumbs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.sfm-thumb {
|
||||
position: relative;
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
background: rgba(0, 0, 0, 0.28);
|
||||
}
|
||||
|
||||
.sfm-thumb img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sfm-thumb button {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
cursor: pointer;
|
||||
color: #0c0c0f;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.sfm-add-image {
|
||||
width: 72px;
|
||||
height: 72px;
|
||||
border-radius: 12px;
|
||||
border: 1px dashed color-mix(in srgb, #f59e0b 45%, rgba(255, 255, 255, 0.2));
|
||||
background: rgba(245, 158, 11, 0.06);
|
||||
color: #fbbf24;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
gap: 2px;
|
||||
font-size: 11px;
|
||||
font-weight: 650;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.sfm-add-image:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.sfm-submit {
|
||||
width: 100%;
|
||||
min-height: 46px;
|
||||
|
||||
@ -2,8 +2,9 @@
|
||||
|
||||
import { FormEvent, useEffect, useId, useRef, useState } from "react";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Send, X } from "lucide-react";
|
||||
import { ImagePlus, Send, X } from "lucide-react";
|
||||
import { socialApi } from "@social/lib/api";
|
||||
import { collectFeedbackClientMeta } from "@social/lib/feedbackMeta";
|
||||
import { socialPath } from "@social/lib/socialPath";
|
||||
import { socialTx } from "@social/lib/socialTx";
|
||||
import { useLocalState } from "@social/lib/useLocalState";
|
||||
@ -17,16 +18,21 @@ export function openSocialFeedbackMate() {
|
||||
window.dispatchEvent(new CustomEvent(SOCIAL_FEEDBACK_OPEN));
|
||||
}
|
||||
|
||||
type DraftImage = { url: string; preview?: string };
|
||||
|
||||
export default function SocialFeedbackMate() {
|
||||
const { locale } = useSocialI18n();
|
||||
const zh = locale === "zh";
|
||||
const pathname = usePathname() || "";
|
||||
const panelId = useId();
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [hint, setHint] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [status, setStatus] = useState("");
|
||||
const [images, setImages] = useState<DraftImage[]>([]);
|
||||
const [delivery, setDelivery] = useLocalState<"draft" | "sent" | "local">(
|
||||
"feedback-mate-delivery",
|
||||
"draft",
|
||||
@ -82,31 +88,82 @@ export default function SocialFeedbackMate() {
|
||||
|
||||
const reset = () => {
|
||||
setDraft({ kind: "建议", text: "", contact: "" });
|
||||
setImages([]);
|
||||
setDelivery("draft");
|
||||
setStatus("");
|
||||
};
|
||||
|
||||
const onPickImages = async (files: FileList | null) => {
|
||||
if (!files?.length || uploading) return;
|
||||
const room = Math.max(0, 4 - images.length);
|
||||
const batch = Array.from(files)
|
||||
.filter((f) => f.type.startsWith("image/"))
|
||||
.slice(0, room);
|
||||
if (!batch.length) return;
|
||||
setUploading(true);
|
||||
setStatus("");
|
||||
try {
|
||||
for (const file of batch) {
|
||||
if (file.size > 8 * 1024 * 1024) {
|
||||
throw new Error(zh ? "单张图片请小于 8MB" : "Each image must be under 8MB");
|
||||
}
|
||||
const uploaded = await socialApi.uploadAvatar(file, "feedback");
|
||||
if (!uploaded?.url) throw new Error(zh ? "上传失败" : "Upload failed");
|
||||
setImages((cur) => [...cur, { url: uploaded.url }].slice(0, 4));
|
||||
}
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : String(e);
|
||||
setStatus(
|
||||
msg && msg.length < 120
|
||||
? socialTx(`图片上传失败:${msg}`)
|
||||
: socialTx("图片上传失败,请重试"),
|
||||
);
|
||||
} finally {
|
||||
setUploading(false);
|
||||
if (fileRef.current) fileRef.current.value = "";
|
||||
}
|
||||
};
|
||||
|
||||
const submit = async (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (!draft.text.trim() || lock.current || delivery === "sent") return;
|
||||
if (!draft.text.trim() || lock.current || delivery === "sent" || uploading)
|
||||
return;
|
||||
lock.current = true;
|
||||
setBusy(true);
|
||||
try {
|
||||
// meta is silent admin telemetry — never rendered to the user.
|
||||
await socialApi.postFeedback({
|
||||
...draft,
|
||||
kind: draft.kind || "建议",
|
||||
text: draft.text.trim(),
|
||||
contact: draft.contact.trim(),
|
||||
images: images.map((i) => i.url),
|
||||
meta: collectFeedbackClientMeta({
|
||||
imageCount: images.length,
|
||||
ui: "feedback-mate",
|
||||
}),
|
||||
});
|
||||
setDelivery("sent");
|
||||
setStatus(socialTx("已提交,感谢反馈。"));
|
||||
setImages([]);
|
||||
} catch (e) {
|
||||
setDelivery("local");
|
||||
const msg = e instanceof Error ? e.message : "";
|
||||
setStatus(
|
||||
msg && msg.length < 120
|
||||
? socialTx(`提交失败:${msg}。内容还在表单里,修好后点重试。`)
|
||||
: socialTx("提交失败。内容还在表单里,请稍后点重试。"),
|
||||
);
|
||||
if (/最多提交|429/.test(msg)) {
|
||||
setDelivery("draft");
|
||||
setStatus(
|
||||
socialTx(
|
||||
msg.includes("最多")
|
||||
? msg
|
||||
: "每人最多提交 10 条反馈,已达上限。",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
setDelivery("local");
|
||||
setStatus(
|
||||
msg && msg.length < 120
|
||||
? socialTx(`提交失败:${msg}。内容还在表单里,修好后点重试。`)
|
||||
: socialTx("提交失败。内容还在表单里,请稍后点重试。"),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
lock.current = false;
|
||||
setBusy(false);
|
||||
@ -201,7 +258,6 @@ export default function SocialFeedbackMate() {
|
||||
>
|
||||
<header className="sfm-head">
|
||||
<div>
|
||||
<p className="sfm-kicker">{zh ? "看板娘在听" : "Listening"}</p>
|
||||
<h2>{socialTx("说说想法")}</h2>
|
||||
</div>
|
||||
<button
|
||||
@ -226,19 +282,6 @@ export default function SocialFeedbackMate() {
|
||||
</div>
|
||||
) : (
|
||||
<form className="sfm-form" onSubmit={(e) => void submit(e)}>
|
||||
<div className="sfm-kinds" role="group">
|
||||
{(["建议", "反馈"] as const).map((kind) => (
|
||||
<button
|
||||
type="button"
|
||||
key={kind}
|
||||
className={draft.kind === kind ? "is-on" : ""}
|
||||
aria-pressed={draft.kind === kind}
|
||||
onClick={() => update("kind", kind)}
|
||||
>
|
||||
{socialTx(kind)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className="sfm-field">
|
||||
<span>{socialTx("内容")}</span>
|
||||
<textarea
|
||||
@ -259,10 +302,54 @@ export default function SocialFeedbackMate() {
|
||||
placeholder={socialTx("邮箱 / 微信")}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="sfm-images">
|
||||
<div className="sfm-images-head">
|
||||
<span>{zh ? "截图(选填)" : "Screenshots (optional)"}</span>
|
||||
<span>{images.length}/4</span>
|
||||
</div>
|
||||
<div className="sfm-thumbs">
|
||||
{images.map((img) => (
|
||||
<div key={img.url} className="sfm-thumb">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={img.url} alt="" />
|
||||
<button
|
||||
type="button"
|
||||
aria-label={zh ? "移除图片" : "Remove image"}
|
||||
onClick={() =>
|
||||
setImages((cur) => cur.filter((x) => x.url !== img.url))
|
||||
}
|
||||
>
|
||||
<X size={12} />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
{images.length < 4 ? (
|
||||
<button
|
||||
type="button"
|
||||
className="sfm-add-image"
|
||||
disabled={uploading || busy}
|
||||
onClick={() => fileRef.current?.click()}
|
||||
>
|
||||
<ImagePlus size={18} />
|
||||
<span>{uploading ? (zh ? "上传中…" : "Uploading…") : zh ? "加图" : "Add"}</span>
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
<input
|
||||
ref={fileRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
hidden
|
||||
onChange={(e) => void onPickImages(e.target.files)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="sfm-submit"
|
||||
disabled={busy || !draft.text.trim()}
|
||||
disabled={busy || uploading || !draft.text.trim()}
|
||||
>
|
||||
<Send size={15} />
|
||||
{busy
|
||||
|
||||
@ -528,18 +528,36 @@ export const socialApi = {
|
||||
};
|
||||
},
|
||||
|
||||
/** Prefer portal local store (PB 挂了也能落盘);再打 social API。 */
|
||||
/**
|
||||
* Feedback: local portal first, then online .com portal, then social API.
|
||||
* `meta` is silent admin telemetry — never rendered in user UI.
|
||||
*/
|
||||
postFeedback: async (payload: {
|
||||
kind: string;
|
||||
text: string;
|
||||
contact?: string;
|
||||
images?: string[];
|
||||
meta?: Record<string, unknown>;
|
||||
}) => {
|
||||
const body = { ...payload, guestId: getGuestId() };
|
||||
const body = {
|
||||
kind: payload.kind,
|
||||
text: payload.text,
|
||||
contact: payload.contact || "",
|
||||
images: Array.isArray(payload.images) ? payload.images.slice(0, 8) : [],
|
||||
meta: payload.meta && typeof payload.meta === "object" ? payload.meta : {},
|
||||
guestId: getGuestId(),
|
||||
};
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Social-Guest-Id": getGuestId(),
|
||||
};
|
||||
const urls = ["/api/portal/feedback", `${BASE}/feedback`];
|
||||
const email = socialEmail();
|
||||
if (email) headers["X-Social-Email"] = email;
|
||||
const urls = [
|
||||
"/api/portal/feedback",
|
||||
"https://nomadro.com/api/portal/feedback",
|
||||
`${BASE}/feedback`,
|
||||
];
|
||||
let lastErr = "";
|
||||
for (const url of urls) {
|
||||
try {
|
||||
@ -548,19 +566,39 @@ export const socialApi = {
|
||||
headers,
|
||||
body: JSON.stringify(body),
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(8000),
|
||||
signal: AbortSignal.timeout(url.startsWith("http") ? 12000 : 4000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
lastErr = await res.text().catch(() => `HTTP ${res.status}`);
|
||||
const raw = await res.text().catch(() => `HTTP ${res.status}`);
|
||||
let detail = raw;
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as { detail?: unknown };
|
||||
if (typeof parsed.detail === "string" && parsed.detail.trim()) {
|
||||
detail = parsed.detail.trim();
|
||||
}
|
||||
} catch {
|
||||
/* plain text */
|
||||
}
|
||||
// Hard stop on rate limit — do not fall through to other endpoints.
|
||||
if (res.status === 429 || /最多提交/.test(detail)) {
|
||||
throw new Error(detail || "每人最多提交 10 条反馈");
|
||||
}
|
||||
lastErr = detail.slice(0, 200);
|
||||
continue;
|
||||
}
|
||||
return (await res.json()) as {
|
||||
ok?: boolean;
|
||||
id?: string;
|
||||
stored?: string;
|
||||
remaining?: number;
|
||||
max?: number;
|
||||
};
|
||||
} catch (e) {
|
||||
lastErr = e instanceof Error ? e.message : String(e);
|
||||
if (e instanceof Error && /最多提交/.test(e.message)) throw e;
|
||||
const raw = e instanceof Error ? e.message : String(e);
|
||||
lastErr = /abort|timed?\s*out|timeout/i.test(raw)
|
||||
? "提交超时,请再试一次"
|
||||
: raw;
|
||||
}
|
||||
}
|
||||
throw new Error(lastErr || "反馈提交失败");
|
||||
|
||||
93
src/modules/social/lib/feedbackMeta.ts
Normal file
93
src/modules/social/lib/feedbackMeta.ts
Normal file
@ -0,0 +1,93 @@
|
||||
/** Silent client telemetry for feedback — admin-only; never shown in UI. */
|
||||
|
||||
import { getGuestId } from "./api";
|
||||
import { getSocialSession } from "./socialSession";
|
||||
|
||||
export type FeedbackClientMeta = Record<string, unknown>;
|
||||
|
||||
function safeLocal(key: string): string {
|
||||
try {
|
||||
return (localStorage.getItem(key) || "").trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export function collectFeedbackClientMeta(
|
||||
extra?: Record<string, unknown>,
|
||||
): FeedbackClientMeta {
|
||||
if (typeof window === "undefined") {
|
||||
return { ...(extra || {}), collectedAt: new Date().toISOString() };
|
||||
}
|
||||
const session = getSocialSession();
|
||||
const nav = window.navigator;
|
||||
const conn =
|
||||
(nav as Navigator & { connection?: Record<string, unknown> }).connection ||
|
||||
null;
|
||||
const screen = window.screen;
|
||||
return {
|
||||
collectedAt: new Date().toISOString(),
|
||||
guestId: getGuestId(),
|
||||
email: session?.email || "",
|
||||
name: session?.name || "",
|
||||
href: window.location.href,
|
||||
pathname: window.location.pathname,
|
||||
search: window.location.search,
|
||||
hash: window.location.hash,
|
||||
referrer: document.referrer || "",
|
||||
title: document.title || "",
|
||||
locale: document.documentElement.lang || "",
|
||||
language: nav.language || "",
|
||||
languages: Array.from(nav.languages || []),
|
||||
userAgent: nav.userAgent || "",
|
||||
platform: nav.platform || "",
|
||||
vendor: nav.vendor || "",
|
||||
cookieEnabled: nav.cookieEnabled,
|
||||
onLine: nav.onLine,
|
||||
maxTouchPoints: nav.maxTouchPoints || 0,
|
||||
hardwareConcurrency: nav.hardwareConcurrency || 0,
|
||||
deviceMemory:
|
||||
(nav as Navigator & { deviceMemory?: number }).deviceMemory || null,
|
||||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "",
|
||||
timezoneOffsetMin: new Date().getTimezoneOffset(),
|
||||
screen: {
|
||||
width: screen.width,
|
||||
height: screen.height,
|
||||
availWidth: screen.availWidth,
|
||||
availHeight: screen.availHeight,
|
||||
colorDepth: screen.colorDepth,
|
||||
pixelDepth: screen.pixelDepth,
|
||||
orientation: screen.orientation?.type || "",
|
||||
},
|
||||
viewport: {
|
||||
innerWidth: window.innerWidth,
|
||||
innerHeight: window.innerHeight,
|
||||
outerWidth: window.outerWidth,
|
||||
outerHeight: window.outerHeight,
|
||||
devicePixelRatio: window.devicePixelRatio || 1,
|
||||
},
|
||||
connection: conn
|
||||
? {
|
||||
type: conn.type ?? null,
|
||||
effectiveType: conn.effectiveType ?? null,
|
||||
downlink: conn.downlink ?? null,
|
||||
rtt: conn.rtt ?? null,
|
||||
saveData: conn.saveData ?? null,
|
||||
}
|
||||
: null,
|
||||
accountFlags: {
|
||||
paidType: safeLocal("paidType"),
|
||||
joinPaid:
|
||||
safeLocal("social-join-paid") ||
|
||||
(() => {
|
||||
try {
|
||||
return sessionStorage.getItem("social-join-paid") || "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
})(),
|
||||
profileDone: safeLocal("social-join-profile-done"),
|
||||
},
|
||||
...(extra || {}),
|
||||
};
|
||||
}
|
||||
@ -43,11 +43,11 @@ export const SOCIAL_PAGES_EN: Record<string, SocialPageCopy> = {
|
||||
"Pick a city, then a café that works for meeting. After chatting online, meeting in person feels more natural.",
|
||||
},
|
||||
team: {
|
||||
eyebrow: "Not only fun — also build",
|
||||
title: "Together · make something",
|
||||
accent: "Hiring",
|
||||
eyebrow: "Build with people",
|
||||
title: "Hiring",
|
||||
accent: "Work together",
|
||||
description:
|
||||
"People post hiring / helper / part-time roles, and co-create projects (guides & videos). Open a card for details.",
|
||||
"Helpers, part-time, and full-time roles live here. Open one, then leave a note if it fits.",
|
||||
},
|
||||
gigs: {
|
||||
eyebrow: "Ways to help",
|
||||
|
||||
@ -231,6 +231,7 @@ export const SOCIAL_PHRASES_EN: Record<string, string> = {
|
||||
"去招聘": "Browse hiring",
|
||||
"看看招聘": "Browse hiring",
|
||||
"说说想法": "Share feedback",
|
||||
"图片上传失败,请重试": "Image upload failed. Please try again.",
|
||||
"认识人": "Meet people",
|
||||
"游民社区 · 约会": "Nomad Social · Dating",
|
||||
"找搭子做事": "Find buddies",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user