feat(staff): action buttons → filtered customer/group list
Adds groups.user_id filter; viewCustomers/viewGroups push owner_account_id query; CustomerList/GroupList read it. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
"""GET /api/groups, /api/groups/{room_id}/members — chat-group browse endpoints.
|
"""GET /api/groups, /api/groups/{room_id}/members — chat-group browse endpoints.
|
||||||
|
|
||||||
* ``GET /api/groups`` -> ``Page[GroupOut]`` filtered by ``channel`` /
|
* ``GET /api/groups`` -> ``Page[GroupOut]`` filtered by ``channel`` /
|
||||||
``owner_account_id``, ordered by ``last_chat_time desc`` (nulls last) so
|
``owner_account_id`` / ``user_id`` (the latter mapping to the
|
||||||
recently-active groups surface first.
|
``owner_user_id`` column), ordered by ``last_chat_time desc`` (nulls last)
|
||||||
|
so recently-active groups surface first.
|
||||||
* ``GET /api/groups/{room_id}/members`` -> ``list[GroupMemberOut]`` — the
|
* ``GET /api/groups/{room_id}/members`` -> ``list[GroupMemberOut]`` — the
|
||||||
members of a single group (small set, no pagination needed).
|
members of a single group (small set, no pagination needed).
|
||||||
"""
|
"""
|
||||||
@@ -33,13 +34,22 @@ async def list_groups(
|
|||||||
page_size: PageSizeParam = 20,
|
page_size: PageSizeParam = 20,
|
||||||
channel: Annotated[str | None, Query()] = None,
|
channel: Annotated[str | None, Query()] = None,
|
||||||
owner_account_id: Annotated[str | None, Query()] = None,
|
owner_account_id: Annotated[str | None, Query()] = None,
|
||||||
|
user_id: Annotated[str | None, Query()] = None,
|
||||||
) -> Page[GroupOut]:
|
) -> Page[GroupOut]:
|
||||||
"""List chat groups with optional ``channel`` / ``owner_account_id`` filters."""
|
"""List chat groups with optional ``channel`` / ``owner_account_id`` /
|
||||||
|
``user_id`` filters.
|
||||||
|
|
||||||
|
``user_id`` maps to the ``ChatGroup.owner_user_id`` column (the staff
|
||||||
|
``userId`` who owns the chatroom account), mirroring the ``user_id``
|
||||||
|
filter on ``GET /api/customers``.
|
||||||
|
"""
|
||||||
conditions = []
|
conditions = []
|
||||||
if channel is not None:
|
if channel is not None:
|
||||||
conditions.append(ChatGroup.channel == channel)
|
conditions.append(ChatGroup.channel == channel)
|
||||||
if owner_account_id is not None:
|
if owner_account_id is not None:
|
||||||
conditions.append(ChatGroup.owner_account_id == owner_account_id)
|
conditions.append(ChatGroup.owner_account_id == owner_account_id)
|
||||||
|
if user_id is not None:
|
||||||
|
conditions.append(ChatGroup.owner_user_id == user_id)
|
||||||
|
|
||||||
total_stmt = sa.select(sa.func.count()).select_from(ChatGroup)
|
total_stmt = sa.select(sa.func.count()).select_from(ChatGroup)
|
||||||
if conditions:
|
if conditions:
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ async def _seed(session: AsyncSession) -> None:
|
|||||||
room_name="Team A",
|
room_name="Team A",
|
||||||
owner_account_id="wx_owner_1",
|
owner_account_id="wx_owner_1",
|
||||||
owner_account_nickname="WxOne",
|
owner_account_nickname="WxOne",
|
||||||
|
owner_user_id="u_wx_1",
|
||||||
member_count=2,
|
member_count=2,
|
||||||
message_count=10,
|
message_count=10,
|
||||||
last_chat_time=2000,
|
last_chat_time=2000,
|
||||||
@@ -30,6 +31,7 @@ async def _seed(session: AsyncSession) -> None:
|
|||||||
channel="wechat",
|
channel="wechat",
|
||||||
room_name="Team B",
|
room_name="Team B",
|
||||||
owner_account_id="wx_owner_2",
|
owner_account_id="wx_owner_2",
|
||||||
|
owner_user_id="u_wx_2",
|
||||||
member_count=1,
|
member_count=1,
|
||||||
last_chat_time=1000,
|
last_chat_time=1000,
|
||||||
),
|
),
|
||||||
@@ -38,6 +40,7 @@ async def _seed(session: AsyncSession) -> None:
|
|||||||
channel="whatsapp",
|
channel="whatsapp",
|
||||||
room_name="WA Team",
|
room_name="WA Team",
|
||||||
owner_account_id="wa_owner_1",
|
owner_account_id="wa_owner_1",
|
||||||
|
owner_user_id="u_wa_1",
|
||||||
member_count=3,
|
member_count=3,
|
||||||
last_chat_time=None,
|
last_chat_time=None,
|
||||||
),
|
),
|
||||||
@@ -176,6 +179,26 @@ async def test_filter_by_owner_account_id(make_client):
|
|||||||
assert body["items"][0]["room_id"] == "room_a@chatroom"
|
assert body["items"][0]["room_id"] == "room_a@chatroom"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_filter_by_user_id(make_client):
|
||||||
|
"""``?user_id=u_wx_1`` -> only Team A (param maps to owner_user_id column)."""
|
||||||
|
client = await make_client(_seed)
|
||||||
|
r = await client.get("/api/groups", params={"user_id": "u_wx_1"})
|
||||||
|
assert r.status_code == 200
|
||||||
|
body = r.json()
|
||||||
|
assert body["total"] == 1
|
||||||
|
assert body["items"][0]["room_id"] == "room_a@chatroom"
|
||||||
|
# Sanity: a different user_id matches a different single group.
|
||||||
|
r2 = await client.get("/api/groups", params={"user_id": "u_wa_1"})
|
||||||
|
assert r2.status_code == 200
|
||||||
|
body2 = r2.json()
|
||||||
|
assert body2["total"] == 1
|
||||||
|
assert body2["items"][0]["room_id"] == "wa_room_x@s.whatsapp.net"
|
||||||
|
# Sanity: an unknown user_id matches nothing.
|
||||||
|
r3 = await client.get("/api/groups", params={"user_id": "nobody"})
|
||||||
|
assert r3.status_code == 200
|
||||||
|
assert r3.json()["total"] == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_pagination(make_client):
|
async def test_pagination(make_client):
|
||||||
"""``page_size=1`` -> 1 item, total 3."""
|
"""``page_size=1`` -> 1 item, total 3."""
|
||||||
client = await make_client(_seed)
|
client = await make_client(_seed)
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ export function getAccounts(query: AccountQuery = {}): Promise<Page<Account>> {
|
|||||||
export interface GroupQuery {
|
export interface GroupQuery {
|
||||||
channel?: Channel | 'all'
|
channel?: Channel | 'all'
|
||||||
owner_account_id?: string
|
owner_account_id?: string
|
||||||
|
user_id?: string
|
||||||
page?: number
|
page?: number
|
||||||
page_size?: number
|
page_size?: number
|
||||||
}
|
}
|
||||||
@@ -144,6 +145,7 @@ export function getGroups(query: GroupQuery = {}): Promise<Page<Group>> {
|
|||||||
clean({
|
clean({
|
||||||
channel: query.channel === 'all' ? undefined : query.channel,
|
channel: query.channel === 'all' ? undefined : query.channel,
|
||||||
owner_account_id: query.owner_account_id,
|
owner_account_id: query.owner_account_id,
|
||||||
|
user_id: query.user_id,
|
||||||
page: query.page ?? 1,
|
page: query.page ?? 1,
|
||||||
page_size: query.page_size ?? 20,
|
page_size: query.page_size ?? 20,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ const departmentId = computed<string | null>(() =>
|
|||||||
route.query.department_id ? String(route.query.department_id) : null,
|
route.query.department_id ? String(route.query.department_id) : null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ownerId = computed<string | null>(() =>
|
||||||
|
route.query.owner_account_id ? String(route.query.owner_account_id) : null,
|
||||||
|
)
|
||||||
|
|
||||||
const departmentName = computed(() => {
|
const departmentName = computed(() => {
|
||||||
if (!departmentId.value) return null
|
if (!departmentId.value) return null
|
||||||
return org.findNode(departmentId.value)?.label ?? departmentId.value
|
return org.findNode(departmentId.value)?.label ?? departmentId.value
|
||||||
@@ -96,6 +100,7 @@ async function load(): Promise<void> {
|
|||||||
page: page.value,
|
page: page.value,
|
||||||
page_size: pageSize.value,
|
page_size: pageSize.value,
|
||||||
department_id: departmentId.value ?? undefined,
|
department_id: departmentId.value ?? undefined,
|
||||||
|
owner_account_id: ownerId.value ?? undefined,
|
||||||
})
|
})
|
||||||
customers.value = res.items
|
customers.value = res.items
|
||||||
total.value = res.total
|
total.value = res.total
|
||||||
@@ -118,9 +123,16 @@ function handlePageSizeChange(s: number): void {
|
|||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// React to top-bar channel + dept tree selection.
|
/** Drop the ``owner_account_id`` query param while preserving any others. */
|
||||||
|
function clearOwnerFilter(): void {
|
||||||
|
const { owner_account_id: _drop, ...rest } = route.query
|
||||||
|
void _drop
|
||||||
|
router.replace({ query: rest })
|
||||||
|
}
|
||||||
|
|
||||||
|
// React to top-bar channel + dept tree selection + owner_account_id query.
|
||||||
watch(
|
watch(
|
||||||
() => [channelStore.channel, departmentId.value] as const,
|
() => [channelStore.channel, departmentId.value, ownerId.value] as const,
|
||||||
() => {
|
() => {
|
||||||
page.value = 1
|
page.value = 1
|
||||||
load()
|
load()
|
||||||
@@ -174,6 +186,7 @@ onMounted(load)
|
|||||||
<span class="yk-customers__sub">
|
<span class="yk-customers__sub">
|
||||||
共 {{ total }} 条
|
共 {{ total }} 条
|
||||||
<template v-if="departmentName"> · 部门:{{ departmentName }}</template>
|
<template v-if="departmentName"> · 部门:{{ departmentName }}</template>
|
||||||
|
<template v-if="ownerId"> · 员工账号:{{ ownerId }}</template>
|
||||||
· 渠道:{{ channelLabelCurrent }}
|
· 渠道:{{ channelLabelCurrent }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -200,6 +213,15 @@ onMounted(load)
|
|||||||
>
|
>
|
||||||
清除部门筛选
|
清除部门筛选
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="ownerId"
|
||||||
|
size="small"
|
||||||
|
type="info"
|
||||||
|
plain
|
||||||
|
@click="clearOwnerFilter"
|
||||||
|
>
|
||||||
|
清除员工筛选
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onMounted, ref, watch } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { getGroups } from '@/api'
|
import { getGroups } from '@/api'
|
||||||
import type { Channel, Group } from '@/api/types'
|
import type { Channel, Group } from '@/api/types'
|
||||||
@@ -8,9 +8,14 @@ import { useChannelStore } from '@/stores/channel'
|
|||||||
import { channelLabel, formatTime } from '@/utils/format'
|
import { channelLabel, formatTime } from '@/utils/format'
|
||||||
import { buildGroupSections, readField } from '@/utils/groupFields'
|
import { buildGroupSections, readField } from '@/utils/groupFields'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const channelStore = useChannelStore()
|
const channelStore = useChannelStore()
|
||||||
|
|
||||||
|
const ownerId = computed<string | null>(() =>
|
||||||
|
route.query.owner_account_id ? String(route.query.owner_account_id) : null,
|
||||||
|
)
|
||||||
|
|
||||||
const groups = ref<Group[]>([])
|
const groups = ref<Group[]>([])
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const page = ref(1)
|
const page = ref(1)
|
||||||
@@ -48,6 +53,7 @@ async function load(): Promise<void> {
|
|||||||
channel: channelStore.channel,
|
channel: channelStore.channel,
|
||||||
page: page.value,
|
page: page.value,
|
||||||
page_size: pageSize.value,
|
page_size: pageSize.value,
|
||||||
|
owner_account_id: ownerId.value ?? undefined,
|
||||||
})
|
})
|
||||||
groups.value = res.items
|
groups.value = res.items
|
||||||
total.value = res.total
|
total.value = res.total
|
||||||
@@ -70,15 +76,22 @@ function handlePageSizeChange(s: number): void {
|
|||||||
load()
|
load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// React to the top-bar channel filter.
|
// React to the top-bar channel filter + owner_account_id query.
|
||||||
watch(
|
watch(
|
||||||
() => channelStore.channel,
|
() => [channelStore.channel, ownerId.value] as const,
|
||||||
() => {
|
() => {
|
||||||
page.value = 1
|
page.value = 1
|
||||||
load()
|
load()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** Drop the ``owner_account_id`` query param while preserving any others. */
|
||||||
|
function clearOwnerFilter(): void {
|
||||||
|
const { owner_account_id: _drop, ...rest } = route.query
|
||||||
|
void _drop
|
||||||
|
router.replace({ query: rest })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a raw_json camelCase key off a group, preferring the structured
|
* Read a raw_json camelCase key off a group, preferring the structured
|
||||||
* snake_case column when it is populated. The first argument is the row so the
|
* snake_case column when it is populated. The first argument is the row so the
|
||||||
@@ -148,7 +161,9 @@ onMounted(load)
|
|||||||
<div>
|
<div>
|
||||||
<h2 style="margin: 0 0 4px; font-size: 16px">群列表</h2>
|
<h2 style="margin: 0 0 4px; font-size: 16px">群列表</h2>
|
||||||
<span class="yk-groups__sub">
|
<span class="yk-groups__sub">
|
||||||
共 {{ total }} 条 · 渠道:{{ channelLabelCurrent }}
|
共 {{ total }} 条
|
||||||
|
<template v-if="ownerId"> · 员工账号:{{ ownerId }}</template>
|
||||||
|
· 渠道:{{ channelLabelCurrent }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="yk-groups__filters">
|
<div class="yk-groups__filters">
|
||||||
@@ -165,6 +180,15 @@ onMounted(load)
|
|||||||
{{ opt.label }}
|
{{ opt.label }}
|
||||||
</el-radio-button>
|
</el-radio-button>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
|
<el-button
|
||||||
|
v-if="ownerId"
|
||||||
|
size="small"
|
||||||
|
type="info"
|
||||||
|
plain
|
||||||
|
@click="clearOwnerFilter"
|
||||||
|
>
|
||||||
|
清除员工筛选
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -171,19 +171,26 @@ function waSerial(index: number): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Action buttons (WhatsApp 操作 column) — jump to the corresponding list and
|
// Action buttons (操作 column) — jump to the corresponding list scoped to the
|
||||||
// preset the global channel filter to WhatsApp. Per-staff filtering is not yet
|
// row's account, presetting the global channel filter to the row's channel.
|
||||||
// supported by CustomerList/GroupList, so we land on the channel-wide list.
|
// owner_account_id is the staff's account_id (wxId for WeChat, uid for WA),
|
||||||
|
// which both CustomerList and GroupList already filter on server-side.
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function viewCustomers(): void {
|
function viewCustomers(row: Account): void {
|
||||||
channelStore.setChannel('whatsapp')
|
channelStore.setChannel(row.channel)
|
||||||
router.push('/customers')
|
router.push({
|
||||||
|
path: '/customers',
|
||||||
|
query: { owner_account_id: row.account_id },
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewGroups(): void {
|
function viewGroups(row: Account): void {
|
||||||
channelStore.setChannel('whatsapp')
|
channelStore.setChannel(row.channel)
|
||||||
router.push('/groups')
|
router.push({
|
||||||
|
path: '/groups',
|
||||||
|
query: { owner_account_id: row.account_id },
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -607,11 +614,11 @@ onMounted(() => {
|
|||||||
|
|
||||||
<!-- 操作 -->
|
<!-- 操作 -->
|
||||||
<el-table-column label="操作" width="150" fixed="right" align="center">
|
<el-table-column label="操作" width="150" fixed="right" align="center">
|
||||||
<template #default>
|
<template #default="{ row }">
|
||||||
<el-button link type="primary" size="small" @click.stop="viewCustomers">
|
<el-button link type="primary" size="small" @click.stop="viewCustomers(row)">
|
||||||
好友列表
|
好友列表
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button link type="primary" size="small" @click.stop="viewGroups">
|
<el-button link type="primary" size="small" @click.stop="viewGroups(row)">
|
||||||
群聊
|
群聊
|
||||||
</el-button>
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user