6 changed files with 106 additions and 13 deletions
-
80src/utils/subSiteAuth.js
-
10src/views/modules/other-transaction/inventory-move.vue
-
6src/views/modules/production-inbound/inboundRegister.vue
-
8src/views/modules/production-withdrawal/order-list.vue
-
7src/views/modules/recv/qualifiedStorage.vue
-
8src/views/modules/recv/recv.vue
@ -0,0 +1,80 @@ |
|||||
|
/** |
||||
|
* 统一格式化站点编码,避免大小写和空白导致匹配失败 |
||||
|
* @param {*} siteCode |
||||
|
* @returns {string} |
||||
|
*/ |
||||
|
function normalizeSiteCode(siteCode) { |
||||
|
return String(siteCode || '') |
||||
|
.replace(/%/g, '') |
||||
|
.trim() |
||||
|
.toUpperCase(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 站点编码去重并清理空值 |
||||
|
* @param {Array} siteCodeList |
||||
|
* @returns {Array<string>} |
||||
|
*/ |
||||
|
function normalizeSiteCodeList(siteCodeList) { |
||||
|
if (!Array.isArray(siteCodeList)) { |
||||
|
return []; |
||||
|
} |
||||
|
return Array.from( |
||||
|
new Set( |
||||
|
siteCodeList |
||||
|
.map(code => normalizeSiteCode(code)) |
||||
|
.filter(code => !!code) |
||||
|
) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取当前用户授权子site编码列表 |
||||
|
* 优先读取Vuex,若为空再回退localStorage,避免页面刷新后Vuex丢失 |
||||
|
* @param {Array} storeSubSiteCodeList |
||||
|
* @returns {Array<string>} |
||||
|
*/ |
||||
|
export function getAuthorizedSubSiteCodeList(storeSubSiteCodeList) { |
||||
|
const subSiteCodeListFromStore = normalizeSiteCodeList(storeSubSiteCodeList); |
||||
|
if (subSiteCodeListFromStore.length > 0) { |
||||
|
return subSiteCodeListFromStore; |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
const localSubSiteCodeList = JSON.parse(localStorage.getItem('userSubSiteCodeList') || '[]'); |
||||
|
return normalizeSiteCodeList(localSubSiteCodeList); |
||||
|
} catch (error) { |
||||
|
console.error('解析userSubSiteCodeList失败:', error); |
||||
|
return []; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 按授权子site过滤列表数据,避免接口按site前缀查询后返回越权数据 |
||||
|
* @param {Array} rows 列表原始数据 |
||||
|
* @param {Array} authorizedSubSiteCodeList 用户授权子site编码列表 |
||||
|
* @param {Array} siteFieldList 数据中可能存放站点编码的字段 |
||||
|
* @returns {Array} |
||||
|
*/ |
||||
|
export function filterRowsByAuthorizedSubSite(rows, authorizedSubSiteCodeList, siteFieldList = ['contract']) { |
||||
|
const sourceRows = Array.isArray(rows) ? rows : []; |
||||
|
const normalizedAuthorizedList = normalizeSiteCodeList(authorizedSubSiteCodeList); |
||||
|
|
||||
|
// 未拿到授权子site时,返回空列表,避免放行越权数据
|
||||
|
if (normalizedAuthorizedList.length === 0) { |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
const authorizedSiteSet = new Set(normalizedAuthorizedList); |
||||
|
const validSiteFieldList = Array.isArray(siteFieldList) && siteFieldList.length > 0 ? siteFieldList : ['contract']; |
||||
|
|
||||
|
return sourceRows.filter(row => { |
||||
|
if (!row || typeof row !== 'object') { |
||||
|
return false; |
||||
|
} |
||||
|
return validSiteFieldList.some(field => { |
||||
|
const rowSiteCode = normalizeSiteCode(row[field]); |
||||
|
return rowSiteCode && authorizedSiteSet.has(rowSiteCode); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue