refactor: 员工同步数据库配置改为环境变量
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- 前端隐藏数据库连接配置输入 - 只保留"启用开关"和"表名"配置 - 数据库连接从 EMPLOYEE_SYNC_DB_URL 环境变量读取 - 显示数据源配置状态 - 保留默认值用于向后兼容
This commit is contained in:
@@ -103,7 +103,7 @@
|
||||
style="margin-bottom: 20px;"
|
||||
>
|
||||
<template #default>
|
||||
<p>配置外部数据源,系统将自动同步员工信息(姓名、手机号、部门、岗位等)。</p>
|
||||
<p>系统将从钉钉员工数据源自动同步员工信息(姓名、手机号、部门、岗位等)。</p>
|
||||
<p style="margin-top: 8px;">同步的员工将自动创建系统账号,初始密码为 123456。</p>
|
||||
</template>
|
||||
</el-alert>
|
||||
@@ -111,7 +111,6 @@
|
||||
<el-form
|
||||
ref="syncFormRef"
|
||||
:model="syncForm"
|
||||
:rules="syncRules"
|
||||
label-width="140px"
|
||||
v-loading="syncLoading"
|
||||
>
|
||||
@@ -124,72 +123,29 @@
|
||||
<span class="form-tip">启用后将每日自动同步员工数据</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">数据库连接配置</el-divider>
|
||||
|
||||
<el-form-item label="数据库主机" prop="db_host">
|
||||
<el-input
|
||||
v-model="syncForm.db_host"
|
||||
placeholder="如:192.168.1.100"
|
||||
style="width: 300px;"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="端口" prop="db_port">
|
||||
<el-input-number
|
||||
v-model="syncForm.db_port"
|
||||
:min="1"
|
||||
:max="65535"
|
||||
placeholder="3306"
|
||||
style="width: 150px;"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据库名" prop="db_name">
|
||||
<el-input
|
||||
v-model="syncForm.db_name"
|
||||
placeholder="请输入数据库名称"
|
||||
style="width: 300px;"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="用户名" prop="db_user">
|
||||
<el-input
|
||||
v-model="syncForm.db_user"
|
||||
placeholder="请输入数据库用户名"
|
||||
style="width: 300px;"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="密码" prop="db_password">
|
||||
<el-input
|
||||
v-model="syncForm.db_password"
|
||||
type="password"
|
||||
show-password
|
||||
:placeholder="syncForm.db_password_masked || '请输入数据库密码'"
|
||||
style="width: 300px;"
|
||||
/>
|
||||
<span class="form-tip" v-if="syncForm.db_password_masked && !syncForm.db_password">
|
||||
当前值: {{ syncForm.db_password_masked }}
|
||||
</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="员工表名" prop="table_name">
|
||||
<el-input
|
||||
v-model="syncForm.table_name"
|
||||
placeholder="v_钉钉员工表"
|
||||
style="width: 300px;"
|
||||
/>
|
||||
<span class="form-tip">表或视图需包含:员工姓名、手机号、所属部门、职位等字段</span>
|
||||
<span class="form-tip">视图需包含:员工姓名、手机号、所属部门、职位、钉钉用户ID等字段</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="数据源状态">
|
||||
<el-tag :type="syncForm.configured ? 'success' : 'warning'">
|
||||
{{ syncForm.configured ? '已配置' : '未配置' }}
|
||||
</el-tag>
|
||||
<span class="form-tip">数据源由系统管理员在后台配置</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-button @click="loadSyncConfig">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
@@ -229,13 +185,8 @@ const dingtalkForm = reactive({
|
||||
// 员工同步配置表单
|
||||
const syncForm = reactive({
|
||||
enabled: false,
|
||||
db_host: '',
|
||||
db_port: 3306,
|
||||
db_name: '',
|
||||
db_user: '',
|
||||
db_password: '',
|
||||
db_password_masked: '',
|
||||
table_name: 'v_钉钉员工表',
|
||||
configured: false, // 数据源是否已配置
|
||||
})
|
||||
|
||||
// 表单验证规则
|
||||
@@ -251,17 +202,7 @@ const dingtalkRules = reactive<FormRules>({
|
||||
]
|
||||
})
|
||||
|
||||
const syncRules = reactive<FormRules>({
|
||||
db_host: [
|
||||
{ required: false, message: '请输入数据库主机', trigger: 'blur' }
|
||||
],
|
||||
db_name: [
|
||||
{ required: false, message: '请输入数据库名', trigger: 'blur' }
|
||||
],
|
||||
db_user: [
|
||||
{ required: false, message: '请输入用户名', trigger: 'blur' }
|
||||
]
|
||||
})
|
||||
const syncRules = reactive<FormRules>({})
|
||||
|
||||
/**
|
||||
* 加载钉钉配置
|
||||
@@ -341,17 +282,11 @@ 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.db_host = response.data.db_host || ''
|
||||
syncForm.db_port = response.data.db_port || 3306
|
||||
syncForm.db_name = response.data.db_name || ''
|
||||
syncForm.db_user = response.data.db_user || ''
|
||||
syncForm.db_password = ''
|
||||
syncForm.db_password_masked = response.data.db_password_masked || ''
|
||||
syncForm.table_name = response.data.table_name || 'v_钉钉员工表'
|
||||
syncForm.configured = response.data.configured || false
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('加载员工同步配置失败:', error)
|
||||
// 不显示错误提示,可能是表不存在
|
||||
} finally {
|
||||
syncLoading.value = false
|
||||
}
|
||||
@@ -363,19 +298,11 @@ const loadSyncConfig = async () => {
|
||||
const saveSyncConfig = async () => {
|
||||
syncSaving.value = true
|
||||
try {
|
||||
const updateData: any = {
|
||||
const updateData = {
|
||||
enabled: syncForm.enabled,
|
||||
db_host: syncForm.db_host,
|
||||
db_port: syncForm.db_port,
|
||||
db_name: syncForm.db_name,
|
||||
db_user: syncForm.db_user,
|
||||
table_name: syncForm.table_name,
|
||||
}
|
||||
|
||||
if (syncForm.db_password) {
|
||||
updateData.db_password = syncForm.db_password
|
||||
}
|
||||
|
||||
const response = await request.put('/api/v1/settings/employee-sync', updateData)
|
||||
if (response.code === 200) {
|
||||
ElMessage.success('配置保存成功')
|
||||
|
||||
Reference in New Issue
Block a user