Ver código fonte

部门选择器预设值优先为主部门

cfort 2 anos atrás
pai
commit
39abce492c
1 arquivos alterados com 19 adições e 11 exclusões
  1. 19 11
      src/business/platform/form/utils/formUtil.js

+ 19 - 11
src/business/platform/form/utils/formUtil.js

@@ -351,7 +351,7 @@ const FormUtil = {
         }
     },
     getCurrentDataValue ({ selectorType, bindId, fieldName, storeType }) {
-        const userInfo = store.getters.userInfo
+        const { userInfo } = store.getters || {}
         const { level = {} } = store.getters
         // 缓存用户
         if (userInfo.employee && userInfo.employee.id) {
@@ -377,16 +377,24 @@ const FormUtil = {
         }
         // 岗位
         if (Utils.isNotEmpty(userInfo.positions)) {
-            const selectors = []
-            userInfo.positions.forEach((item) => {
-                if (Utils.isNotEmpty(item) && Utils.isNotEmpty(item.id)) {
-                    selectors.push({
-                        'id': item.id,
-                        'name': item.name
-                    })
-                }
-            })
-            this.CACHE_CURRENT_USER_DATA['position'] = selectors
+            const { mainPosition } = userInfo || {}
+            if (Utils.isNotEmpty(mainPosition)) {
+                this.CACHE_CURRENT_USER_DATA['position'] = [{
+                    id: mainPosition.id,
+                    name: mainPosition.name
+                }]
+            } else {
+                const selectors = []
+                userInfo.positions.forEach((item) => {
+                    if (Utils.isNotEmpty(item) && Utils.isNotEmpty(item.id)) {
+                        selectors.push({
+                            'id': item.id,
+                            'name': item.name
+                        })
+                    }
+                })
+                this.CACHE_CURRENT_USER_DATA['position'] = selectors
+            }
         }
         // 角色
         if (Utils.isNotEmpty(userInfo.role)) {