提交 5a3861b9 作者: zuihou

feat(table): 表格的数据列和操作列的字段可以根据权限和业务来控制是否显示

上级 7c41c867
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
import { useTableContext } from '../hooks/useTableContext'; import { useTableContext } from '../hooks/useTableContext';
import { usePermission } from '/@/hooks/web/usePermission'; import { usePermission } from '/@/hooks/web/usePermission';
import { isBoolean, isFunction } from '/@/utils/is';
import { propTypes } from '/@/utils/propTypes'; import { propTypes } from '/@/utils/propTypes';
import { ACTION_COLUMN_FLAG } from '../const'; import { ACTION_COLUMN_FLAG } from '../const';
...@@ -63,10 +64,24 @@ ...@@ -63,10 +64,24 @@
} }
const { hasPermission } = usePermission(); const { hasPermission } = usePermission();
function isIfShow(action: ActionItem): boolean {
const ifShow = action.ifShow;
let isIfShow = true;
if (isBoolean(ifShow)) {
isIfShow = ifShow;
}
if (isFunction(ifShow)) {
isIfShow = ifShow(action);
}
return isIfShow;
}
const getActions = computed(() => { const getActions = computed(() => {
return (toRaw(props.actions) || []) return (toRaw(props.actions) || [])
.filter((action) => { .filter((action) => {
return hasPermission(action.auth); return hasPermission(action.auth) && isIfShow(action);
}) })
.map((action) => { .map((action) => {
const { popConfirm } = action; const { popConfirm } = action;
...@@ -85,7 +100,7 @@ ...@@ -85,7 +100,7 @@
const getDropdownList = computed(() => { const getDropdownList = computed(() => {
return (toRaw(props.dropDownActions) || []) return (toRaw(props.dropDownActions) || [])
.filter((action) => { .filter((action) => {
return hasPermission(action.auth); return hasPermission(action.auth) && isIfShow(action);
}) })
.map((action, index) => { .map((action, index) => {
const { label, popConfirm } = action; const { label, popConfirm } = action;
......
...@@ -6,6 +6,7 @@ import { unref, Ref, computed, watch, ref, toRaw } from 'vue'; ...@@ -6,6 +6,7 @@ import { unref, Ref, computed, watch, ref, toRaw } from 'vue';
import { renderEditCell } from '../components/editable'; import { renderEditCell } from '../components/editable';
import { usePermission } from '/@/hooks/web/usePermission';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { isBoolean, isArray, isString, isObject, isFunction } from '/@/utils/is'; import { isBoolean, isArray, isString, isObject, isFunction } from '/@/utils/is';
...@@ -133,11 +134,30 @@ export function useColumns( ...@@ -133,11 +134,30 @@ export function useColumns(
return cloneColumns; return cloneColumns;
}); });
function isIfShow(column: BasicColumn): boolean {
const ifShow = column.ifShow;
let isIfShow = true;
if (isBoolean(ifShow)) {
isIfShow = ifShow;
}
if (isFunction(ifShow)) {
isIfShow = ifShow(column);
}
return isIfShow;
}
const { hasPermission } = usePermission();
const getViewColumns = computed(() => { const getViewColumns = computed(() => {
const viewColumns = sortFixedColumn(unref(getColumnsRef)); const viewColumns = sortFixedColumn(unref(getColumnsRef));
const columns = cloneDeep(viewColumns); const columns = cloneDeep(viewColumns);
columns.forEach((column) => { return columns
.filter((column) => {
return hasPermission(column.auth) && isIfShow(column);
})
.map((column) => {
const { slots, dataIndex, customRender, format, edit, editRow, flag } = column; const { slots, dataIndex, customRender, format, edit, editRow, flag } = column;
if (!slots || !slots?.title) { if (!slots || !slots?.title) {
...@@ -156,8 +176,8 @@ export function useColumns( ...@@ -156,8 +176,8 @@ export function useColumns(
if ((edit || editRow) && !isDefaultAction) { if ((edit || editRow) && !isDefaultAction) {
column.customRender = renderEditCell(column); column.customRender = renderEditCell(column);
} }
return column;
}); });
return columns;
}); });
watch( watch(
......
...@@ -8,6 +8,7 @@ import type { ...@@ -8,6 +8,7 @@ import type {
import { ComponentType } from './componentType'; import { ComponentType } from './componentType';
import { VueNode } from '/@/utils/propTypes'; import { VueNode } from '/@/utils/propTypes';
import { RoleEnum } from '/@/enums/roleEnum';
export declare type SortOrder = 'ascend' | 'descend'; export declare type SortOrder = 'ascend' | 'descend';
...@@ -421,4 +422,8 @@ export interface BasicColumn extends ColumnProps { ...@@ -421,4 +422,8 @@ export interface BasicColumn extends ColumnProps {
editRule?: boolean | ((text: string, record: Recordable) => Promise<string>); editRule?: boolean | ((text: string, record: Recordable) => Promise<string>);
editValueMap?: (value: any) => string; editValueMap?: (value: any) => string;
onEditRow?: () => void; onEditRow?: () => void;
// 权限编码控制是否显示
auth?: RoleEnum | RoleEnum[] | string | string[];
// 业务控制是否显示
ifShow?: boolean | ((column: BasicColumn) => boolean);
} }
...@@ -8,8 +8,10 @@ export interface ActionItem extends ButtonProps { ...@@ -8,8 +8,10 @@ export interface ActionItem extends ButtonProps {
popConfirm?: PopConfirm; popConfirm?: PopConfirm;
disabled?: boolean; disabled?: boolean;
divider?: boolean; divider?: boolean;
// Permission code // 权限编码控制是否显示
auth?: RoleEnum | RoleEnum[] | string | string[]; auth?: RoleEnum | RoleEnum[] | string | string[];
// 业务控制是否显示
ifShow?: boolean | ((action: ActionItem) => boolean);
} }
export interface PopConfirm { export interface PopConfirm {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论