refactor: 员工同步复用钉钉免密登录配置
Some checks failed
continuous-integration/drone/push Build is failing

- 移除员工同步独立的 API 凭证配置
- 复用 dingtalk 配置组的 CorpId、AppKey、AppSecret
- 简化前端界面,只保留开关和测试连接
This commit is contained in:
yuliang_guo
2026-01-31 17:29:10 +08:00
parent 7be1ac1787
commit 18d6d5aff3
3 changed files with 40 additions and 108 deletions

View File

@@ -105,13 +105,13 @@
<template #default>
<p>通过钉钉开放 API 自动同步组织架构和员工信息姓名手机号部门岗位等</p>
<p style="margin-top: 8px;">同步的员工将自动创建系统账号初始密码为 123456</p>
<p style="margin-top: 8px; color: #E6A23C;">注意员工同步复用钉钉免密登录 API 凭证配置</p>
</template>
</el-alert>
<el-form
ref="syncFormRef"
:model="syncForm"
:rules="syncRules"
label-width="140px"
v-loading="syncLoading"
>
@@ -124,50 +124,20 @@
<span class="form-tip">启用后将每日自动从钉钉同步员工数据</span>
</el-form-item>
<el-divider content-position="left">钉钉应用配置</el-divider>
<el-form-item label="企业 CorpId" prop="corp_id">
<el-input
v-model="syncForm.corp_id"
placeholder="请输入钉钉企业 CorpId"
style="width: 350px;"
/>
<span class="form-tip">在钉钉管理后台-设置中查看</span>
</el-form-item>
<el-form-item label="应用 ClientId" prop="client_id">
<el-input
v-model="syncForm.client_id"
placeholder="请输入应用 ClientId (AppKey)"
style="width: 350px;"
/>
<span class="form-tip">钉钉开发者后台-应用凭证</span>
</el-form-item>
<el-form-item label="应用 ClientSecret" prop="client_secret">
<el-input
v-model="syncForm.client_secret"
type="password"
show-password
:placeholder="syncForm.client_secret_masked || '请输入应用 ClientSecret'"
style="width: 350px;"
/>
<span class="form-tip" v-if="syncForm.client_secret_masked && !syncForm.client_secret">
当前值: {{ syncForm.client_secret_masked }}
</span>
</el-form-item>
<el-form-item label="配置状态">
<el-form-item label="钉钉 API 状态">
<el-tag :type="syncForm.configured ? 'success' : 'warning'">
{{ syncForm.configured ? '已配置' : '未配置' }}
</el-tag>
<span class="form-tip" v-if="!syncForm.configured">
请先在钉钉免密登录页签配置 API 凭证
</span>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="saveSyncConfig" :loading="syncSaving">
保存配置
</el-button>
<el-button @click="testSyncConnection" :loading="syncTesting">
<el-button @click="testSyncConnection" :loading="syncTesting" :disabled="!syncForm.configured">
测试连接
</el-button>
</el-form-item>
@@ -206,14 +176,10 @@ const dingtalkForm = reactive({
corp_id: '',
})
// 员工同步配置表单(钉钉 API 方式
// 员工同步配置表单(复用钉钉免密登录配置
const syncForm = reactive({
enabled: false,
corp_id: '',
client_id: '',
client_secret: '',
client_secret_masked: '',
configured: false,
configured: false, // 钉钉 API 是否已配置
})
// 表单验证规则
@@ -229,14 +195,7 @@ const dingtalkRules = reactive<FormRules>({
]
})
const syncRules = reactive<FormRules>({
corp_id: [
{ required: false, message: '请输入企业 CorpId', trigger: 'blur' }
],
client_id: [
{ required: false, message: '请输入应用 ClientId', trigger: 'blur' }
]
})
const syncRules = reactive<FormRules>({})
/**
* 加载钉钉配置
@@ -308,7 +267,7 @@ const saveDingtalkConfig = async () => {
}
/**
* 加载员工同步配置(钉钉 API 方式
* 加载员工同步配置(复用钉钉免密登录配置
*/
const loadSyncConfig = async () => {
syncLoading.value = true
@@ -316,10 +275,6 @@ const loadSyncConfig = async () => {
const response = await request.get('/api/v1/settings/employee-sync')
if (response.code === 200 && response.data) {
syncForm.enabled = response.data.enabled || false
syncForm.corp_id = response.data.corp_id || ''
syncForm.client_id = response.data.client_id || ''
syncForm.client_secret = ''
syncForm.client_secret_masked = response.data.client_secret_masked || ''
syncForm.configured = response.data.configured || false
}
} catch (error: any) {
@@ -330,23 +285,14 @@ const loadSyncConfig = async () => {
}
/**
* 保存员工同步配置(钉钉 API 方式
* 保存员工同步配置(仅开关
*/
const saveSyncConfig = async () => {
syncSaving.value = true
try {
const updateData: any = {
const response = await request.put('/api/v1/settings/employee-sync', {
enabled: syncForm.enabled,
corp_id: syncForm.corp_id,
client_id: syncForm.client_id,
}
// 只有输入了新密码才传递
if (syncForm.client_secret) {
updateData.client_secret = syncForm.client_secret
}
const response = await request.put('/api/v1/settings/employee-sync', updateData)
})
if (response.code === 200) {
ElMessage.success('配置保存成功')
await loadSyncConfig()