在系统设置页面添加同步钉钉部门按钮

This commit is contained in:
Your Name 2026-01-02 13:51:26 +08:00
parent f0ae3dabdf
commit 9ad09332cb
2 changed files with 41 additions and 1 deletions

View File

@ -65,6 +65,14 @@ export function getDingTalkDepartments(): Promise<any[]> {
.then(res => res.data)
}
/**
* 同步钉钉部门
*/
export function syncDingTalkDepartments(): Promise<number> {
return request.post<Result<number>>('/dingtalk/sync-departments')
.then(res => res.data)
}
/**
* 同步钉钉用户
*/

View File

@ -671,6 +671,21 @@
</a-button>
</a-space>
</a-form-item>
<a-divider orientation="left">部门同步</a-divider>
<a-alert
message="部门同步说明"
description="同步钉钉部门到系统:自动获取所有钉钉部门并设置ding_dept_id。如果钉钉部门在系统中不存在,会自动创建。同步后,用户登录时就能自动匹配到部门了。"
type="info"
show-icon
style="margin-bottom: 16px;"
/>
<a-form-item>
<a-button type="primary" @click="handleSyncDepartments" :loading="syncingDepartments" :disabled="!dingTalkConfig.appKey || !dingTalkConfig.appSecret">
<template #icon><Icon name="sync" size="sm" /></template>
同步钉钉部门
</a-button>
</a-form-item>
</a-form>
</div>
</a-tab-pane>
@ -2281,7 +2296,7 @@ const goToScorePool = () => {
}
// =============== 钉钉集成 ===============
import { getDingTalkConfig, saveDingTalkConfig, testDingTalkConnection, sendTestMessage } from '@/api/dingtalk'
import { getDingTalkConfig, saveDingTalkConfig, testDingTalkConnection, sendTestMessage, syncDingTalkDepartments } from '@/api/dingtalk'
const dingTalkConfig = reactive({
id: undefined as number | undefined,
@ -2403,6 +2418,23 @@ const handleSendTestMessage = async () => {
}
}
const handleSyncDepartments = async () => {
if (!dingTalkConfig.appKey || !dingTalkConfig.appSecret) {
message.warning('请先填写AppKey和AppSecret')
return
}
syncingDepartments.value = true
try {
const count = await syncDingTalkDepartments()
message.success(`同步成功!共处理 ${count} 个部门`)
} catch (error: any) {
message.error(error.message || '同步失败')
} finally {
syncingDepartments.value = false
}
}
// ==================== 导航栏配置 ====================
const navbarConfig = ref<NavbarConfig>({
menuItems: {