feat: full-field display for message/staff/accounts (raw_json + drawers)
Replicates the Customer all-fields pattern across the remaining three entities. Backend now exposes `raw_json` on MessageOut / StaffOut / AccountOut so the frontend can render every 云客 source field without a second endpoint. Each entity gains a Chinese-label field utility + an el-drawer surfacing all fields (structured-first, raw_json fallback, unknown keys under 其他). Backend: - schemas.py: add `raw_json: dict | None` to MessageOut / StaffOut / AccountOut. MessageOut/StaffOut pick the column up via from_attributes; AccountOut is built explicitly in the router, which now threads `raw_json` through from both WechatAccount and WhatsappAccount rows. - tests: new raw_json serialization tests for messages, staff, accounts (assert populated dict round-trips verbatim + NULL serializes as null). Frontend (yunkes/): - New utils: messageFields.ts, staffFields.ts, accountFields.ts — each with a 中文 label map, ordered groups, structured-column preference, and an 其他 fallback for unknown raw_json keys. - Message: clicking a chat bubble opens an all-fields drawer (referMsg renders as pretty-printed JSON). Image preview + file download links stopPropagation so their own interactions still work. - Staff: row click → drawer; columns relabeled (员工ID, 销售手机). - Accounts: new AccountList.vue at /accounts with a 账号 nav item, unified WeChat/WhatsApp table (渠道/账号ID/昵称/微信号/归属员工/好友数/ 群数/收发/在职/最后更新), channel filter, pagination, row-click drawer. - api: add Account type + getAccounts(); add raw_json to Message/Staff. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -27,12 +27,21 @@ async def _seed(session: AsyncSession) -> None:
|
||||
dept_id="d1",
|
||||
is_on_job=True,
|
||||
phone="111",
|
||||
# Verbatim upstream staff record — the all-fields drawer reads
|
||||
# these camelCase keys off raw_json.
|
||||
raw_json={
|
||||
"userId": "u1",
|
||||
"userName": "Alice",
|
||||
"sale_phone": "111",
|
||||
"deptId": "d1",
|
||||
},
|
||||
),
|
||||
Staff(
|
||||
user_id="u2",
|
||||
name="Bob",
|
||||
dept_id="d2",
|
||||
is_on_job=False,
|
||||
raw_json=None,
|
||||
),
|
||||
Staff(user_id="u3", name="Carol", dept_id="d1", is_on_job=True),
|
||||
WechatAccount(
|
||||
@@ -44,6 +53,15 @@ async def _seed(session: AsyncSession) -> None:
|
||||
contacts_num=10,
|
||||
group_num=2,
|
||||
is_on_job=True,
|
||||
raw_json={
|
||||
"wechatId": "wx_a",
|
||||
"nickName": "WxOne",
|
||||
"alias": "alice_wx",
|
||||
"sendNum": 120,
|
||||
"receiveNum": 80,
|
||||
"dbSize": 2048,
|
||||
"onlineStatus": "online",
|
||||
},
|
||||
),
|
||||
WechatAccount(
|
||||
wx_id="wx_b",
|
||||
@@ -51,6 +69,7 @@ async def _seed(session: AsyncSession) -> None:
|
||||
user_id="u2",
|
||||
contacts_num=5,
|
||||
is_on_job=False,
|
||||
raw_json=None,
|
||||
),
|
||||
WhatsappAccount(
|
||||
uid="wa_c@s.whatsapp.net",
|
||||
@@ -61,6 +80,12 @@ async def _seed(session: AsyncSession) -> None:
|
||||
contacts_num=7,
|
||||
group_num=1,
|
||||
is_on_job=True,
|
||||
raw_json={
|
||||
"uid": "wa_c@s.whatsapp.net",
|
||||
"nickName": "WaOne",
|
||||
"talkerCount": 7,
|
||||
"friendAddNum": 3,
|
||||
},
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -92,10 +117,39 @@ async def test_staff_default_page_returns_all(make_client):
|
||||
assert body["page_size"] == 20
|
||||
assert body["total"] == 3
|
||||
assert len(body["items"]) == 3
|
||||
for key in ("user_id", "name", "phone", "sale_phone", "dept_id", "is_on_job"):
|
||||
for key in (
|
||||
"user_id",
|
||||
"name",
|
||||
"phone",
|
||||
"sale_phone",
|
||||
"dept_id",
|
||||
"is_on_job",
|
||||
"raw_json",
|
||||
):
|
||||
assert key in body["items"][0]
|
||||
|
||||
|
||||
async def test_staff_raw_json_serializes_verbatim(make_client):
|
||||
"""``raw_json`` round-trips the verbatim staff record unmolested.
|
||||
|
||||
Seeded ``u1`` carries a populated blob; ``u2`` has NULL raw_json; ``u3``
|
||||
omits it entirely. All three must serialize (populated dict vs null).
|
||||
"""
|
||||
client = await make_client(_seed)
|
||||
r = await client.get("/api/staff")
|
||||
assert r.status_code == 200
|
||||
by_id = {it["user_id"]: it for it in r.json()["items"]}
|
||||
|
||||
assert by_id["u1"]["raw_json"] == {
|
||||
"userId": "u1",
|
||||
"userName": "Alice",
|
||||
"sale_phone": "111",
|
||||
"deptId": "d1",
|
||||
}
|
||||
assert by_id["u2"]["raw_json"] is None
|
||||
assert by_id["u3"]["raw_json"] is None
|
||||
|
||||
|
||||
async def test_staff_filter_by_department_id(make_client):
|
||||
"""``?department_id=d1`` -> 2 staff (Alice + Carol)."""
|
||||
client = await make_client(_seed)
|
||||
@@ -162,6 +216,7 @@ async def test_accounts_default_returns_both_channels(make_client):
|
||||
"contacts_num",
|
||||
"group_num",
|
||||
"is_on_job",
|
||||
"raw_json",
|
||||
):
|
||||
assert key in item
|
||||
assert item["channel"] == "wechat"
|
||||
@@ -169,6 +224,40 @@ async def test_accounts_default_returns_both_channels(make_client):
|
||||
assert item["user_name"] == "Alice"
|
||||
|
||||
|
||||
async def test_accounts_raw_json_serializes_verbatim(make_client):
|
||||
"""``raw_json`` round-trips the verbatim account record for both channels.
|
||||
|
||||
Seeded ``wx_a`` and the whatsapp account carry populated blobs; ``wx_b``
|
||||
has NULL raw_json. All three must serialize (populated dict vs null).
|
||||
"""
|
||||
client = await make_client(_seed)
|
||||
r = await client.get("/api/accounts")
|
||||
assert r.status_code == 200
|
||||
by_id = {(it["channel"], it["account_id"]): it for it in r.json()["items"]}
|
||||
|
||||
wx_a = by_id[("wechat", "wx_a")]
|
||||
assert wx_a["raw_json"] == {
|
||||
"wechatId": "wx_a",
|
||||
"nickName": "WxOne",
|
||||
"alias": "alice_wx",
|
||||
"sendNum": 120,
|
||||
"receiveNum": 80,
|
||||
"dbSize": 2048,
|
||||
"onlineStatus": "online",
|
||||
}
|
||||
|
||||
wa = by_id[("whatsapp", "wa_c@s.whatsapp.net")]
|
||||
assert wa["raw_json"] == {
|
||||
"uid": "wa_c@s.whatsapp.net",
|
||||
"nickName": "WaOne",
|
||||
"talkerCount": 7,
|
||||
"friendAddNum": 3,
|
||||
}
|
||||
|
||||
# NULL raw_json serializes as JSON null.
|
||||
assert by_id[("wechat", "wx_b")]["raw_json"] is None
|
||||
|
||||
|
||||
async def test_accounts_filter_channel_wechat(make_client):
|
||||
"""``?channel=wechat`` -> only the 2 wechat accounts."""
|
||||
client = await make_client(_seed)
|
||||
|
||||
Reference in New Issue
Block a user