@@ -6,6 +6,7 @@ import { unref, Ref, computed, watch, ref, toRaw } from 'vue';
66
77import { renderEditCell } from '../components/editable' ;
88
9+ import { usePermission } from '/@/hooks/web/usePermission' ;
910import { useI18n } from '/@/hooks/web/useI18n' ;
1011
1112import { isBoolean , isArray , isString , isObject , isFunction } from '/@/utils/is' ;
@@ -133,31 +134,50 @@ export function useColumns(
133134 return cloneColumns ;
134135 } ) ;
135136
137+ function isIfShow ( column : BasicColumn ) : boolean {
138+ const ifShow = column . ifShow ;
139+
140+ let isIfShow = true ;
141+
142+ if ( isBoolean ( ifShow ) ) {
143+ isIfShow = ifShow ;
144+ }
145+ if ( isFunction ( ifShow ) ) {
146+ isIfShow = ifShow ( column ) ;
147+ }
148+ return isIfShow ;
149+ }
150+ const { hasPermission } = usePermission ( ) ;
151+
136152 const getViewColumns = computed ( ( ) => {
137153 const viewColumns = sortFixedColumn ( unref ( getColumnsRef ) ) ;
138154
139155 const columns = cloneDeep ( viewColumns ) ;
140- columns . forEach ( ( column ) => {
141- const { slots, dataIndex, customRender, format, edit, editRow, flag } = column ;
142-
143- if ( ! slots || ! slots ?. title ) {
144- column . slots = { title : `header-${ dataIndex } ` , ...( slots || { } ) } ;
145- column . customTitle = column . title ;
146- Reflect . deleteProperty ( column , 'title' ) ;
147- }
148- const isDefaultAction = [ INDEX_COLUMN_FLAG , ACTION_COLUMN_FLAG ] . includes ( flag ! ) ;
149- if ( ! customRender && format && ! edit && ! isDefaultAction ) {
150- column . customRender = ( { text, record, index } ) => {
151- return formatCell ( text , format , record , index ) ;
152- } ;
153- }
156+ return columns
157+ . filter ( ( column ) => {
158+ return hasPermission ( column . auth ) && isIfShow ( column ) ;
159+ } )
160+ . map ( ( column ) => {
161+ const { slots, dataIndex, customRender, format, edit, editRow, flag } = column ;
162+
163+ if ( ! slots || ! slots ?. title ) {
164+ column . slots = { title : `header-${ dataIndex } ` , ...( slots || { } ) } ;
165+ column . customTitle = column . title ;
166+ Reflect . deleteProperty ( column , 'title' ) ;
167+ }
168+ const isDefaultAction = [ INDEX_COLUMN_FLAG , ACTION_COLUMN_FLAG ] . includes ( flag ! ) ;
169+ if ( ! customRender && format && ! edit && ! isDefaultAction ) {
170+ column . customRender = ( { text, record, index } ) => {
171+ return formatCell ( text , format , record , index ) ;
172+ } ;
173+ }
154174
155- // edit table
156- if ( ( edit || editRow ) && ! isDefaultAction ) {
157- column . customRender = renderEditCell ( column ) ;
158- }
159- } ) ;
160- return columns ;
175+ // edit table
176+ if ( ( edit || editRow ) && ! isDefaultAction ) {
177+ column . customRender = renderEditCell ( column ) ;
178+ }
179+ return column ;
180+ } ) ;
161181 } ) ;
162182
163183 watch (
0 commit comments