添加钉钉登录按钮:在登录页面显示钉钉登录按钮(仅在启用时显示),增强后端isFeatureEnabled方法检查配置启用状态
This commit is contained in:
parent
3d52a3ac4d
commit
ad343c357e
@ -526,7 +526,9 @@ public class DingTalkService {
|
||||
*/
|
||||
public boolean isFeatureEnabled(String feature) {
|
||||
DingTalkConfig config = getConfig();
|
||||
if (config == null || config.getEnabledFeatures() == null) {
|
||||
// 检查配置是否存在、已启用,并且enabledFeatures不为空
|
||||
if (config == null || config.getEnabled() == null || config.getEnabled() != 1
|
||||
|| config.getEnabledFeatures() == null || config.getEnabledFeatures().trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -535,6 +537,7 @@ public class DingTalkService {
|
||||
config.getEnabledFeatures(), new TypeReference<Map<String, Boolean>>() {});
|
||||
return features.getOrDefault(feature, false);
|
||||
} catch (Exception e) {
|
||||
log.warn("解析enabledFeatures失败: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,10 +190,16 @@
|
||||
</a-form>
|
||||
|
||||
<!-- 其他登录方式 -->
|
||||
<div class="alternative-login">
|
||||
<a-button block class="alt-login-button" disabled>
|
||||
<Icon name="lock" size="sm" style="margin-right: 8px;" />
|
||||
企业用户登录
|
||||
<div v-if="activeTab === 'login'" class="alternative-login">
|
||||
<a-button
|
||||
v-if="dingTalkLoginEnabled"
|
||||
block
|
||||
class="alt-login-button"
|
||||
@click="handleDingTalkLogin"
|
||||
:loading="dingTalkLoginLoading"
|
||||
>
|
||||
<Icon name="share" size="sm" style="margin-right: 8px;" />
|
||||
钉钉登录
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
@ -211,6 +217,9 @@ import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { register as registerApi } from '@/api/auth'
|
||||
import * as departmentApi from '@/api/department'
|
||||
import { isDingTalkFeatureEnabled } from '@/api/dingtalk'
|
||||
import request from '@/utils/request'
|
||||
import type { Result } from '@/api/types'
|
||||
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
@ -238,6 +247,10 @@ const registerForm = reactive({
|
||||
phone: ''
|
||||
})
|
||||
|
||||
// 钉钉登录
|
||||
const dingTalkLoginEnabled = ref(false)
|
||||
const dingTalkLoginLoading = ref(false)
|
||||
|
||||
// 部门列表
|
||||
const departments = ref<any[]>([])
|
||||
const filteredDepartments = computed(() => {
|
||||
@ -363,6 +376,42 @@ const loadDepartments = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 检查钉钉登录是否启用
|
||||
const checkDingTalkLogin = async () => {
|
||||
try {
|
||||
dingTalkLoginEnabled.value = await isDingTalkFeatureEnabled('login')
|
||||
console.log('钉钉登录状态:', dingTalkLoginEnabled.value)
|
||||
} catch (error) {
|
||||
console.error('检查钉钉登录状态失败:', error)
|
||||
dingTalkLoginEnabled.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理钉钉登录
|
||||
const handleDingTalkLogin = async () => {
|
||||
dingTalkLoginLoading.value = true
|
||||
try {
|
||||
// 获取钉钉登录URL
|
||||
const response = await request.get<Result<{ authUrl: string; appKey: string }>>('/dingtalk/oauth/login', {
|
||||
params: {
|
||||
redirectUrl: `${window.location.origin}/auth/dingtalk/callback`
|
||||
}
|
||||
})
|
||||
|
||||
if (response.data.code === 200 && response.data.data) {
|
||||
// 跳转到钉钉登录页面
|
||||
window.location.href = response.data.data.authUrl
|
||||
} else {
|
||||
message.error(response.data.message || '获取钉钉登录地址失败')
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('钉钉登录失败:', error)
|
||||
message.error(error.response?.data?.message || '钉钉登录失败,请稍后重试')
|
||||
} finally {
|
||||
dingTalkLoginLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 加载网站设置
|
||||
siteSettingsStore.loadSiteSettings()
|
||||
@ -370,6 +419,9 @@ onMounted(() => {
|
||||
// 加载部门列表
|
||||
loadDepartments()
|
||||
|
||||
// 检查钉钉登录是否启用
|
||||
checkDingTalkLogin()
|
||||
|
||||
// 监听网站设置更新事件(在加载后监听,确保能接收到事件)
|
||||
window.addEventListener('siteSettingsUpdated', handleSiteSettingsUpdate)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user