xiaohaizhao 3 месяцев назад
Родитель
Сommit
2cef4f236f
4 измененных файлов с 50 добавлено и 68 удалено
  1. 1 1
      project.private.config.json
  2. 40 25
      utils/queryPermissions.js
  3. 7 35
      utils/work/apps.js
  4. 2 7
      utils/work/work.js

+ 1 - 1
project.private.config.json

@@ -6,7 +6,7 @@
         "compileHotReLoad": true,
         "bigPackageSizeSupport": false
     },
-    "libVersion": "3.11.2",
+    "libVersion": "3.13.0",
     "condition": {
         "miniprogram": {
             "list": [

+ 40 - 25
utils/queryPermissions.js

@@ -1,30 +1,45 @@
-/* 
-    list = 查询的数组
-    tier = 层级
-    need = 需要查询的数据
-*/
-let getObjectKey = (object, value) => {
-    return Object.keys(object).find(key => object[key] == value);
-};
-
-let name = ['modules', 'apps'];
+/**
+ * 优化后的查询函数
+ * @param {Array|Object} list - 查询的数据源
+ * @param {Array} tier - 路径层级数组 (例如: ['systemA', 'moduleB'])
+ * @param {Array} need - 需要匹配的 systemmodulename 集合
+ */
+const nameKeys = ['modules', 'apps'];
 
 function query(list, tier, need) {
-    if (!list.some(v => v.systemname == tier[0])) return [];
-    // if (!list) return;
-    if (list.length == 0) return;
-    //排除不是数组 在深入查找一级
-    if (list.constructor !== Array) return query(list[Object.keys(list).filter((key) => name.includes(key))], tier, need);
-    //拿到当前层的数组 如果不是最后一层 继续查找
-    let arr = list.find(v => getObjectKey(v, tier[0]));
-    if (tier.length > 1) return query(arr, tier.splice(1, 1), need);
-    // 到达最后一层查询需要查询的权限
-    if (arr.constructor !== Array) arr = arr[Object.keys(arr).filter((key) => name.includes(key))]
-    let perArr = [];
-    for (let i = 0; i < arr.length; i++) {
-        if (need.includes(arr[i].systemmodulename)) perArr.push(arr[i])
+    // 1. 边界检查
+    if (!list || (Array.isArray(list) && list.length === 0)) return [];
+    
+    // 2. 统一处理:如果是对象,则提取出 modules 或 apps 对应的数组
+    if (!Array.isArray(list)) {
+        const key = Object.keys(list).find(k => nameKeys.includes(k));
+        return key ? query(list[key], tier, need) : [];
+    }
+
+    const [currentLevel, ...restLevels] = tier;
+
+    // 3. 在当前层级寻找匹配 systemname 的节点
+    const target = list.find(item => item.systemname === currentLevel);
+    if (!target) return [];
+
+    // 4. 判断是否到达路径最后一层
+    if (restLevels.length > 0) {
+        // 还没到最后一层,递归进入下一级
+        return query(target, restLevels, need);
+    }
+
+    // 5. 到达最后一层,执行筛选逻辑
+    // 先获取最后一层实际的数据数组(考虑嵌套在 modules/apps 里的情况)
+    let finalArr = target;
+    if (!Array.isArray(finalArr)) {
+        const key = Object.keys(finalArr).find(k => nameKeys.includes(k));
+        finalArr = key ? finalArr[key] : [];
     }
-    return perArr;
-};
+
+    // 确保 finalArr 是数组后进行过滤
+    return Array.isArray(finalArr) 
+        ? finalArr.filter(item => need.includes(item.systemmodulename))
+        : [];
+}
 
 module.exports.query = query;

+ 7 - 35
utils/work/apps.js

@@ -56,7 +56,7 @@ function getcrm() {
     path: "/prsx/calendar/index",
     icon: "work-shichanghuodong",
     objectname: ""
-  },{
+  }, {
     name: "市场活动",
     path: "/prsx/activity/index",
     icon: "work-shichanghuodong",
@@ -107,8 +107,13 @@ function getcrm() {
     icon: "work-xiaochengxu_xiaoshoumubiao",
     objectname: "sa_salestarget"
   }];
-  let crm = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['CRM'], ['业务管理', '销售管理', '营销目标']),
+  let crm = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['CRM'], ['业务管理', '销售管理', '营销目标', '行事历']),
     list = [];
+  try {
+    crm.push(getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['行事历'], ['行事历'])[0])
+  } catch (error) {
+
+  }
   crm.forEach(v => {
     v.apps.forEach(s => {
       authList[s.name] = {
@@ -131,38 +136,6 @@ function getcrm() {
   });
   return dye(list.sort((a, b) => a.index - b.index))
 };
-//行事历
-function getxsl() {
-  const paths = [{
-    name: "行事历",
-    path: "/prsx/calendar/index",
-    icon: "work-shichanghuodong",
-    objectname: ""
-  }];
-  let xsl = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['行事历'], ['行事历']),
-    list = [];
-  xsl.forEach(v => {
-    v.apps.forEach(s => {
-      authList[s.name] = {
-        options: s.meta.auth.map(a => a.option),
-        optionnames: s.meta.auth.map(a => a.optionname),
-        istask: s.istask == 1,
-        isdatafollowup: s.isdatafollowup == 1,
-        isdatatag: s.isdatatag == 1,
-        isdatateam: s.isdatateam == 1,
-      }
-      if (authList[s.name].options.some(s => s == "read")) {
-        let i = paths.findIndex(k => k.name == s.meta.title);
-        if (i != -1) {
-          paths[i].index = i;
-          paths[i].appName = s.name;
-          list.push(paths[i])
-        }
-      }
-    })
-  });
-  return dye(list.sort((a, b) => a.index - b.index))
-};
 //染色
 function dye(list) {
   let colorList = [{
@@ -227,6 +200,5 @@ function dye(list) {
 module.exports = {
   getapps,
   getcrm,
-  getxsl,
   authList
 };

+ 2 - 7
utils/work/work.js

@@ -6,13 +6,8 @@ async function initWorkbench(that) {
         icon: "work-tongyong",
         appid: "wx197f219a82a89d7b",
         list: apps.getapps()
-    }, {
-      label: "行事历",
-      appid: "wx197f219a82a89d7b",
-      icon: "work-CRM",
-      list: apps.getxsl()
-  },{
-        label: "CRM",
+    },{
+        label: "应用",
         appid: "wx197f219a82a89d7b",
         icon: "work-CRM",
         list: apps.getcrm()