筛选高级权限修改,基础信息启用禁用修改
This commit is contained in:
@ -104,7 +104,7 @@
|
||||
<template #reference><el-button :icon="Setting" class="action-btn">表头</el-button></template>
|
||||
<el-checkbox-group v-model="visibleColumnProps" class="column-selector">
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="8" v-for="c in allColumns" :key="c.prop"><el-checkbox :label="c.prop" :disabled="!hasColumnPermission(c.prop)">{{ c.label }}</el-checkbox></el-col>
|
||||
<el-col :span="8" v-for="c in allColumns" :key="c.prop"><el-checkbox :label="c.prop">{{ c.label }}</el-checkbox></el-col>
|
||||
</el-row>
|
||||
</el-checkbox-group>
|
||||
</el-popover>
|
||||
@ -691,46 +691,53 @@ const permissionMap: Record<string, string> = {
|
||||
}
|
||||
|
||||
// 根据用户权限初始化列显示状态
|
||||
// 初始化列显示状态(移除权限限制,添加 localStorage 支持)
|
||||
const initColumnPermissions = () => {
|
||||
// 超级管理员跳过权限检查,显示所有列
|
||||
if (userStore.role === 'SUPER_ADMIN' || userStore.username === 'IRIS') {
|
||||
return
|
||||
}
|
||||
|
||||
// 普通用户:严格执行列级权限控制,没有权限的列必须隐藏
|
||||
// 遍历 allColumns,将没有权限的列从 visibleColumnProps 中移除
|
||||
const allowedColumns = allColumns.filter(col => {
|
||||
const code = permissionMap[col.prop]
|
||||
if (code) {
|
||||
return userStore.hasPermission(code)
|
||||
// 生成存储键:使用用户ID或用户名,如果没有则使用浏览器唯一标识
|
||||
const userId = userStore.user?.id || userStore.username || 'anonymous'
|
||||
const storageKey = `inbound_product_columns_${userId}`
|
||||
|
||||
// 尝试从 localStorage 读取保存的列配置
|
||||
const savedColumns = localStorage.getItem(storageKey)
|
||||
if (savedColumns) {
|
||||
try {
|
||||
const parsed = JSON.parse(savedColumns)
|
||||
// 验证保存的列是否有效(存在于 allColumns 中)
|
||||
const validColumns = parsed.filter((prop: string) =>
|
||||
allColumns.some(col => col.prop === prop)
|
||||
)
|
||||
if (validColumns.length > 0) {
|
||||
visibleColumnProps.value = validColumns
|
||||
return
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to parse saved columns:', e)
|
||||
}
|
||||
// 如果没有映射,默认隐藏
|
||||
return false
|
||||
}).map(col => col.prop)
|
||||
|
||||
// 更新 visibleColumnProps,只保留有权限的列
|
||||
// 同时保持用户之前已经选择的有权限的列
|
||||
const currentVisible = visibleColumnProps.value.filter(prop => allowedColumns.includes(prop))
|
||||
// 如果当前没有可见列,则使用 allowedColumns 作为默认
|
||||
if (currentVisible.length === 0) {
|
||||
visibleColumnProps.value = allowedColumns
|
||||
} else {
|
||||
visibleColumnProps.value = currentVisible
|
||||
}
|
||||
|
||||
// 如果没有保存的配置,使用默认列
|
||||
visibleColumnProps.value = defaultColumns
|
||||
}
|
||||
|
||||
// 检查列权限
|
||||
// 检查列权限(移除权限限制,始终返回 true)
|
||||
const hasColumnPermission = (prop: string) => {
|
||||
if (userStore.role === 'SUPER_ADMIN' || userStore.username === 'IRIS') {
|
||||
return true
|
||||
}
|
||||
const code = permissionMap[prop]
|
||||
return code ? userStore.hasPermission(code) : false
|
||||
return true
|
||||
}
|
||||
|
||||
const defaultVisibleCols = ['company_name', 'material_name', 'sku', 'serial_number', 'qty_stock', 'status', 'quality_status', 'product_photo', 'sale_price', 'order_id']
|
||||
const visibleColumnProps = ref(defaultVisibleCols)
|
||||
|
||||
// 监听列配置变化并保存到 localStorage
|
||||
watch(visibleColumnProps, (newVal) => {
|
||||
const userId = userStore.user?.id || userStore.username || 'anonymous'
|
||||
const storageKey = `inbound_product_columns_${userId}`
|
||||
try {
|
||||
localStorage.setItem(storageKey, JSON.stringify(newVal))
|
||||
} catch (e) {
|
||||
console.warn('Failed to save columns to localStorage:', e)
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
const form = reactive({
|
||||
id: undefined, base_id: undefined as number | undefined,
|
||||
company_name: '', // [新增]
|
||||
|
||||
Reference in New Issue
Block a user