From 0006a0b25e9c1d5840a318309755445c281f8e40 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 Jan 2026 12:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DenabledFeatures=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98=EF=BC=9A=E5=89=8D=E7=AB=AF=E5=B0=86?= =?UTF-8?q?JSON=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=A7=A3=E6=9E=90=E4=B8=BA?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/dingtalk.ts | 3 ++- frontend/src/views/Settings.vue | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/frontend/src/api/dingtalk.ts b/frontend/src/api/dingtalk.ts index d968839..4bd53a7 100644 --- a/frontend/src/api/dingtalk.ts +++ b/frontend/src/api/dingtalk.ts @@ -12,7 +12,8 @@ export interface DingTalkConfig { robotWebhook?: string robotSecret?: string enabled: number - enabledFeatures?: { + // enabledFeatures在数据库中存储为JSON字符串,但在前端使用时会解析为对象 + enabledFeatures?: string | { notification?: boolean login?: boolean attendance?: boolean diff --git a/frontend/src/views/Settings.vue b/frontend/src/views/Settings.vue index 474827d..c170e6f 100644 --- a/frontend/src/views/Settings.vue +++ b/frontend/src/views/Settings.vue @@ -2307,10 +2307,27 @@ const loadDingTalkConfig = async () => { if (config) { Object.assign(dingTalkConfig, config) // 解析启用的功能 + // enabledFeatures在数据库中存储为JSON字符串,需要解析 if (config.enabledFeatures) { - enabledFeaturesList.value = Object.entries(config.enabledFeatures) + let featuresObj: Record = {} + if (typeof config.enabledFeatures === 'string') { + // 如果是字符串,需要解析为对象 + try { + featuresObj = JSON.parse(config.enabledFeatures) + } catch (e) { + console.error('解析enabledFeatures JSON失败:', e) + featuresObj = {} + } + } else { + // 如果已经是对象,直接使用 + featuresObj = config.enabledFeatures as Record + } + + enabledFeaturesList.value = Object.entries(featuresObj) .filter(([, v]) => v) .map(([k]) => k) + } else { + enabledFeaturesList.value = [] } } } catch (error) {