修复enabledFeatures解析问题:前端将JSON字符串解析为对象
This commit is contained in:
parent
9c71237bdf
commit
0006a0b25e
@ -12,7 +12,8 @@ export interface DingTalkConfig {
|
||||
robotWebhook?: string
|
||||
robotSecret?: string
|
||||
enabled: number
|
||||
enabledFeatures?: {
|
||||
// enabledFeatures在数据库中存储为JSON字符串,但在前端使用时会解析为对象
|
||||
enabledFeatures?: string | {
|
||||
notification?: boolean
|
||||
login?: boolean
|
||||
attendance?: boolean
|
||||
|
||||
@ -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<string, boolean> = {}
|
||||
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<string, boolean>
|
||||
}
|
||||
|
||||
enabledFeaturesList.value = Object.entries(featuresObj)
|
||||
.filter(([, v]) => v)
|
||||
.map(([k]) => k)
|
||||
} else {
|
||||
enabledFeaturesList.value = []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user