fix: wechat account scrape (form-data+dates) + frontend staff page
Backend (scrape_wechat_accounts): - Send wxUser/list as form-urlencoded (not JSON) with the REQUIRED filters isOnJob / departmentId / startdate / enddate + empty userId/salesname/ weChatNickName, matching the live request (empty fails with code -90000). - scrape_wechat_accounts now takes department_id (the company-root dept id) plus optional start/end defaulting to a recent 7-day UTC window. - paginate_by_page gains a form=True mode (data= + form content-type). - Orchestrator sync_wechat_accounts resolves the root dept from the Department table (or accepts one) and skips with a warning when unknown. - seed_accounts.py resolves the root via scrape_departments. Frontend (yunkes): - Add StaffList.vue (/staff) with is_on_job filter + pagination. - Add /staff route and a 员工 nav item between 客户 and 群. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -119,6 +119,10 @@ onMounted(async () => {
|
||||
<el-icon><ChatLineSquare /></el-icon>
|
||||
<span>客户</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/staff">
|
||||
<el-icon><Avatar /></el-icon>
|
||||
<span>员工</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/groups">
|
||||
<el-icon><User /></el-icon>
|
||||
<span>群</span>
|
||||
|
||||
@@ -15,6 +15,12 @@ const routes: RouteRecordRaw[] = [
|
||||
component: () => import('@/views/CustomerList.vue'),
|
||||
meta: { title: '客户列表' },
|
||||
},
|
||||
{
|
||||
path: '/staff',
|
||||
name: 'staff',
|
||||
component: () => import('@/views/StaffList.vue'),
|
||||
meta: { title: '员工列表' },
|
||||
},
|
||||
{
|
||||
path: '/groups',
|
||||
name: 'groups',
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { getStaff } from '@/api'
|
||||
import type { Staff } from '@/api/types'
|
||||
import { useOrgStore } from '@/stores/org'
|
||||
|
||||
const route = useRoute()
|
||||
const org = useOrgStore()
|
||||
|
||||
const staff = ref<Staff[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(20)
|
||||
const loading = ref(false)
|
||||
const errorMsg = ref<string | null>(null)
|
||||
|
||||
// On-job filter: 'all' (no filter) / 'on' (is_on_job=true) / 'off' (false).
|
||||
const onJobFilter = ref<'all' | 'on' | 'off'>('all')
|
||||
|
||||
const departmentId = computed<string | undefined>(() =>
|
||||
route.query.department_id ? String(route.query.department_id) : undefined,
|
||||
)
|
||||
|
||||
const onJobOptions: { value: 'all' | 'on' | 'off'; label: string }[] = [
|
||||
{ value: 'all', label: '全部' },
|
||||
{ value: 'on', label: '在职' },
|
||||
{ value: 'off', label: '离职' },
|
||||
]
|
||||
|
||||
function onJobTagType(onJob?: boolean | null): 'success' | 'info' | '' {
|
||||
if (onJob === true) return 'success'
|
||||
if (onJob === false) return 'info'
|
||||
return ''
|
||||
}
|
||||
|
||||
function onJobLabel(onJob?: boolean | null): string {
|
||||
if (onJob === true) return '在职'
|
||||
if (onJob === false) return '离职'
|
||||
return '--'
|
||||
}
|
||||
|
||||
function deptName(deptId?: string | null): string | null {
|
||||
if (!deptId) return null
|
||||
return org.findNode(deptId)?.label ?? deptId
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
errorMsg.value = null
|
||||
try {
|
||||
const res = await getStaff({
|
||||
department_id: departmentId.value,
|
||||
is_on_job:
|
||||
onJobFilter.value === 'all' ? undefined : onJobFilter.value === 'on',
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
})
|
||||
staff.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
errorMsg.value = (e as Error).message
|
||||
ElMessage.error(`员工列表加载失败:${(e as Error).message}`)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handlePageChange(p: number): void {
|
||||
page.value = p
|
||||
load()
|
||||
}
|
||||
|
||||
function handlePageSizeChange(s: number): void {
|
||||
pageSize.value = s
|
||||
page.value = 1
|
||||
load()
|
||||
}
|
||||
|
||||
// React to the on-job filter + any dept query param.
|
||||
watch(
|
||||
() => [onJobFilter.value, departmentId.value] as const,
|
||||
() => {
|
||||
page.value = 1
|
||||
load()
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
// Dept names come from the org tree; best-effort load so the 部门 column
|
||||
// can render names instead of bare ids. A load failure is non-fatal — the
|
||||
// column falls back to the raw dept_id.
|
||||
try {
|
||||
await org.ensureLoaded()
|
||||
} catch {
|
||||
/* surfaced in the aside placeholder */
|
||||
}
|
||||
await load()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="yk-staff">
|
||||
<div class="yk-staff__header">
|
||||
<div>
|
||||
<h2 style="margin: 0 0 4px; font-size: 16px">员工列表</h2>
|
||||
<span class="yk-staff__sub">共 {{ total }} 条</span>
|
||||
</div>
|
||||
<div class="yk-staff__filters">
|
||||
<el-radio-group v-model="onJobFilter" size="small">
|
||||
<el-radio-button
|
||||
v-for="opt in onJobOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-alert
|
||||
v-if="errorMsg"
|
||||
:title="errorMsg"
|
||||
type="error"
|
||||
show-icon
|
||||
:closable="false"
|
||||
style="margin-bottom: 12px"
|
||||
/>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="staff"
|
||||
stripe
|
||||
border
|
||||
row-key="user_id"
|
||||
style="width: 100%"
|
||||
empty-text="暂无员工数据"
|
||||
>
|
||||
<el-table-column label="姓名" min-width="120">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.name">{{ row.name }}</span>
|
||||
<span v-else style="color: #c0c4cc">--</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="手机" min-width="130">
|
||||
<template #default="{ row }">{{ row.phone || '--' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="sale_phone" min-width="130">
|
||||
<template #default="{ row }">{{ row.sale_phone || '--' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="部门" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<span v-if="deptName(row.dept_id)">{{ deptName(row.dept_id) }}</span>
|
||||
<span v-else style="color: #c0c4cc">--</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="在职" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag
|
||||
:type="onJobTagType(row.is_on_job)"
|
||||
size="small"
|
||||
effect="plain"
|
||||
>
|
||||
{{ onJobLabel(row.is_on_job) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="yk-staff__pager">
|
||||
<el-pagination
|
||||
:current-page="page"
|
||||
:page-size="pageSize"
|
||||
:page-sizes="[20, 50, 100]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
background
|
||||
@current-change="handlePageChange"
|
||||
@size-change="handlePageSizeChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.yk-staff__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.yk-staff__sub {
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.yk-staff__filters {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.yk-staff__pager {
|
||||
margin-top: 12px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user