From c1d364b786936e5643ca6bdde67387ee6a8252a8 Mon Sep 17 00:00:00 2001 From: DXC Date: Fri, 29 May 2026 10:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E9=A1=B5?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=A2=9E=E5=88=97=E5=B1=95=E7=A4=BA=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E7=BC=93=E5=AD=98=20+=20=E5=85=A8=E9=80=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventory-web/src/views/material/list.vue | 110 +++++++++++++++++----- 1 file changed, 87 insertions(+), 23 deletions(-) diff --git a/inventory-web/src/views/material/list.vue b/inventory-web/src/views/material/list.vue index 4b7a830..6d29e54 100644 --- a/inventory-web/src/views/material/list.vue +++ b/inventory-web/src/views/material/list.vue @@ -171,21 +171,30 @@
-
- 列展示设置 +
+ 列展示设置 + + 全选 +
- - - - - - - - - - - - + + + + + + + + + + + + + +
@@ -904,19 +913,74 @@ const permissionMap: Record = { isInspectionRequired: 'material_list:operation' }; -// 根据用户权限初始化列显示状态 +// ================= 全选与本地缓存逻辑 ================= + +// 获取唯一缓存 Key (加上用户名,防止同一个浏览器切换账号时设置错乱) +const getStorageKey = () => `MOM_BASIC_INFO_COLS_${userStore.username || 'DEFAULT'}`; + +// 辅助方法:判断当前用户是否有某列的权限 +const hasColPermission = (key: string) => { + if (userStore.role === 'SUPER_ADMIN' || userStore.username === 'IRIS') return true; + const code = permissionMap[key]; + return code ? !!userStore.hasPermission(code) : true; +}; + +// 计算属性:判断是否"全选"了所有【有权限】的列 +const isAllSelected = computed(() => { + const allowedKeys = Object.keys(columns).filter(k => hasColPermission(k)); + return allowedKeys.length > 0 && allowedKeys.every(k => columns[k as keyof typeof columns].visible); +}); + +// 计算属性:判断是否"半选" (Element UI 中 checkbox 的 indeterminate 状态) +const isIndeterminate = computed(() => { + const allowedKeys = Object.keys(columns).filter(k => hasColPermission(k)); + const checkedCount = allowedKeys.filter(k => columns[k as keyof typeof columns].visible).length; + return checkedCount > 0 && checkedCount < allowedKeys.length; +}); + +// 事件:点击"全选"复选框时触发 +const handleCheckAllChange = (val: boolean) => { + Object.keys(columns).forEach(key => { + // 只有用户有权限的列,才会被全选/全不选操作控制 + if (hasColPermission(key)) { + columns[key as keyof typeof columns].visible = val; + } + }); +}; + +// 监听:只要列展示状态发生变化,就自动保存到浏览器本地 +watch(columns, (newVal) => { + localStorage.setItem(getStorageKey(), JSON.stringify(newVal)); +}, { deep: true }); + +// ================= 修改:权限初始化与读取缓存 ================= + +// 修改你原有的 initColumnPermissions 函数 const initColumnPermissions = () => { - // 超级管理员跳过权限检查,显示所有列 - if (userStore.role === 'SUPER_ADMIN' || userStore.username === 'IRIS') { - return; + // 1. 尝试从本地缓存读取用户上次的设置 + const cachedData = localStorage.getItem(getStorageKey()); + let parsedCache: Record | null = null; + if (cachedData) { + try { + parsedCache = JSON.parse(cachedData); + } catch (e) { + console.error('解析列缓存失败', e); + } } - // 普通用户:严格执行列级权限控制,没有权限的列必须隐藏 + // 2. 遍历列进行权限判断与缓存赋值 Object.keys(columns).forEach(key => { - const code = permissionMap[key]; - if (code) { - // 如果不具备该权限,必须设为 false - columns[key].visible = !!userStore.hasPermission(code); + const colKey = key as keyof typeof columns; + const hasPerm = hasColPermission(colKey); + + if (!hasPerm) { + // 【权限最高】如果没有权限,强制隐藏,无视任何缓存 + columns[colKey].visible = false; + } else { + // 如果有权限,且存在本地缓存,则使用本地缓存的值 + if (parsedCache && parsedCache[colKey] !== undefined) { + columns[colKey].visible = parsedCache[colKey].visible; + } } }); };