Преглед изворни кода

全局参数获取方法默认返回值调整

cfort пре 11 месеци
родитељ
комит
c5a08c7d0c
2 измењених фајлова са 18 додато и 13 уклоњено
  1. 1 1
      src/store/modules/ibps/modules/user.js
  2. 17 12
      src/utils/query.js

+ 1 - 1
src/store/modules/ibps/modules/user.js

@@ -102,7 +102,7 @@ export default {
                         })
                         // 尝试从配置数据中获取 否则使用默认
                         const highRoles = await getSetting('system', 'highRoles')
-                        highRoles && (info.highRoles = highRoles)
+                        Utils.isNotEmpty(highRoles) && (info.highRoles = highRoles)
                         const { role = [] } = info || {}
                         const hasHighRole = role.some(item => info.highRoles.includes(item.alias))
                         // 用于文件预览页判定是否开启下载权限

+ 17 - 12
src/utils/query.js

@@ -135,20 +135,25 @@ export const getSetting = async (module = '', key = '') => {
         const org = store.getters.level.first || ''
         const sql = `select setting from t_ipcc where org_ = '${org}' limit 1`
         const { variables: { data = [] } = {}} = await request('sql', sql)
-        if (data.length > 0 && data[0]?.setting) {
-            const setting = data[0].setting?.replace(/\n/g, '')
-            const res = JSON.parse(setting)
-            // 根据module和key的存在情况返回不同的结果
-            if (module !== '') {
-                if (key !== '') {
-                    return res?.[module]?.[key]
-                }
-                return res?.[module]
-            }
-            return res
+
+        // 如果数据为空或 setting 字段不存在,直接返回空对象
+        if (data.length === 0 || !data[0]?.setting) {
+            return {}
         }
-        return null
+
+        // 解析 JSON 并处理可能的格式错误
+        const setting = data[0].setting?.replace(/\n/g, '')
+        const res = JSON.parse(setting) || {}
+
+        // 根据 module 和 key 返回对应的值
+        if (module) {
+            const moduleSettings = res[module] || {}
+            return key ? moduleSettings[key] : moduleSettings
+        }
+
+        return res || {}
     } catch (error) {
+        console.error('获取配置失败:', error)
         return Message.warning('数据库字段配置错误!')
     }
 }