feat: customer full-field display (raw_json + cloud-matching list + all-fields drawer)
Backend: - CustomerOut now exposes raw_json (verbatim upstream friend record) so the frontend can render every 云客 field without per-field structured columns. - The verbatim blob round-trips via from_attributes; no model change needed. Frontend: - CustomerList table mirrors the 云客 客户列表 column set (头像/微信昵称/微信号/ 备注/真实姓名/手机/性别/地区/描述/销售员工/部门/来源/添加方式/添加时间/最近 聊天/消息数/渠道). A readField helper reads the structured column first and falls back to raw_json.<camelCase>. - Row click opens an all-fields drawer (right side) rendering EVERY field of the record with Chinese labels, grouped (基本信息/联系方式/归属员工与部门/时间 与来源/消息统计/好友状态/其他). Timestamps format to local datetime, flags render 是/否, image URLs render as el-image thumbnails, empty values show —. - New src/utils/customerFields.ts holds the camelCase→中文 label map, the structured-column alias map, group definitions, and value-type formatters; unknown raw_json keys auto-flow into an 其他 section so new upstream fields surface without code changes. - Drawer 查看聊天记录 action navigates to /chat/:channel/:ownerId/:talkerId (owner_account_id + friend_id + channel), preserving the existing path. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,16 @@ async def client():
|
||||
last_chat_time=2000,
|
||||
message_count=10,
|
||||
version="v1",
|
||||
# Verbatim upstream record — the all-fields drawer reads
|
||||
# these camelCase keys off raw_json.
|
||||
raw_json={
|
||||
"friendWxId": "wx_a",
|
||||
"friendWxAlias": "alice_wx",
|
||||
"friendWxNickname": "Alice",
|
||||
"saleName": "Tom",
|
||||
"addTime": 1690000000000,
|
||||
"fromType": "qrcode",
|
||||
},
|
||||
),
|
||||
Customer(
|
||||
friend_id="wx_b",
|
||||
@@ -65,6 +75,7 @@ async def client():
|
||||
friend_nickname="Bob",
|
||||
last_chat_time=1000,
|
||||
version="v1",
|
||||
raw_json=None,
|
||||
),
|
||||
Customer(
|
||||
friend_id="wa_c",
|
||||
@@ -112,7 +123,8 @@ async def test_list_default_page_returns_all(client: AsyncClient):
|
||||
assert body["page_size"] == 20
|
||||
assert body["total"] == 3
|
||||
assert len(body["items"]) == 3
|
||||
# Shape: every documented CustomerOut field is present.
|
||||
# Shape: every documented CustomerOut field is present, including the
|
||||
# verbatim upstream record exposed for the all-fields drawer.
|
||||
item = body["items"][0]
|
||||
for key in (
|
||||
"friend_id",
|
||||
@@ -129,10 +141,37 @@ async def test_list_default_page_returns_all(client: AsyncClient):
|
||||
"last_chat_time",
|
||||
"message_count",
|
||||
"version",
|
||||
"raw_json",
|
||||
):
|
||||
assert key in item
|
||||
|
||||
|
||||
async def test_raw_json_serializes_verbatim(client: AsyncClient):
|
||||
"""``raw_json`` round-trips the verbatim upstream record unmolested.
|
||||
|
||||
Seeded ``wx_a`` carries a populated blob; ``wx_b``/``wa_c`` have NULL
|
||||
raw_json (omitted on the model). Both must serialize: present dict vs null.
|
||||
"""
|
||||
r = await client.get("/api/customers", params={"channel": "wechat"})
|
||||
assert r.status_code == 200
|
||||
by_id = {it["friend_id"]: it for it in r.json()["items"]}
|
||||
|
||||
# Populated blob: every camelCase key preserved verbatim.
|
||||
alice = by_id["wx_a"]
|
||||
assert alice["raw_json"] == {
|
||||
"friendWxId": "wx_a",
|
||||
"friendWxAlias": "alice_wx",
|
||||
"friendWxNickname": "Alice",
|
||||
"saleName": "Tom",
|
||||
"addTime": 1690000000000,
|
||||
"fromType": "qrcode",
|
||||
}
|
||||
|
||||
# NULL raw_json serializes as JSON null (not omitted, not an error).
|
||||
bob = by_id["wx_b"]
|
||||
assert bob["raw_json"] is None
|
||||
|
||||
|
||||
async def test_list_filters_by_channel_wechat(client: AsyncClient):
|
||||
"""``?channel=wechat`` -> total 2, both wechat rows."""
|
||||
r = await client.get(
|
||||
|
||||
Reference in New Issue
Block a user