Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
球球不吃虾
vue-vben-admin
提交
5a3861b9
V
vue-vben-admin
项目概览
球球不吃虾
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5a3861b9
编写于
4月 27, 2021
作者:
Z
zuihou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(table): 表格的数据列和操作列的字段可以根据权限和业务来控制是否显示
上级
7c41c867
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
23 deletion
+65
-23
src/components/Table/src/components/TableAction.vue
src/components/Table/src/components/TableAction.vue
+17
-2
src/components/Table/src/hooks/useColumns.ts
src/components/Table/src/hooks/useColumns.ts
+40
-20
src/components/Table/src/types/table.ts
src/components/Table/src/types/table.ts
+5
-0
src/components/Table/src/types/tableAction.ts
src/components/Table/src/types/tableAction.ts
+3
-1
未找到文件。
src/components/Table/src/components/TableAction.vue
浏览文件 @
5a3861b9
...
...
@@ -37,6 +37,7 @@
import
{
useTableContext
}
from
'
../hooks/useTableContext
'
;
import
{
usePermission
}
from
'
/@/hooks/web/usePermission
'
;
import
{
isBoolean
,
isFunction
}
from
'
/@/utils/is
'
;
import
{
propTypes
}
from
'
/@/utils/propTypes
'
;
import
{
ACTION_COLUMN_FLAG
}
from
'
../const
'
;
...
...
@@ -63,10 +64,24 @@
}
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
(()
=>
{
return
(
toRaw
(
props
.
actions
)
||
[])
.
filter
((
action
)
=>
{
return
hasPermission
(
action
.
auth
);
return
hasPermission
(
action
.
auth
)
&&
isIfShow
(
action
)
;
})
.
map
((
action
)
=>
{
const
{
popConfirm
}
=
action
;
...
...
@@ -85,7 +100,7 @@
const
getDropdownList
=
computed
(()
=>
{
return
(
toRaw
(
props
.
dropDownActions
)
||
[])
.
filter
((
action
)
=>
{
return
hasPermission
(
action
.
auth
);
return
hasPermission
(
action
.
auth
)
&&
isIfShow
(
action
)
;
})
.
map
((
action
,
index
)
=>
{
const
{
label
,
popConfirm
}
=
action
;
...
...
src/components/Table/src/hooks/useColumns.ts
浏览文件 @
5a3861b9
...
...
@@ -6,6 +6,7 @@ import { unref, Ref, computed, watch, ref, toRaw } from 'vue';
import
{
renderEditCell
}
from
'
../components/editable
'
;
import
{
usePermission
}
from
'
/@/hooks/web/usePermission
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
isBoolean
,
isArray
,
isString
,
isObject
,
isFunction
}
from
'
/@/utils/is
'
;
...
...
@@ -133,31 +134,50 @@ export function useColumns(
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
viewColumns
=
sortFixedColumn
(
unref
(
getColumnsRef
));
const
columns
=
cloneDeep
(
viewColumns
);
columns
.
forEach
((
column
)
=>
{
const
{
slots
,
dataIndex
,
customRender
,
format
,
edit
,
editRow
,
flag
}
=
column
;
if
(
!
slots
||
!
slots
?.
title
)
{
column
.
slots
=
{
title
:
`header-
${
dataIndex
}
`
,
...(
slots
||
{})
};
column
.
customTitle
=
column
.
title
;
Reflect
.
deleteProperty
(
column
,
'
title
'
);
}
const
isDefaultAction
=
[
INDEX_COLUMN_FLAG
,
ACTION_COLUMN_FLAG
].
includes
(
flag
!
);
if
(
!
customRender
&&
format
&&
!
edit
&&
!
isDefaultAction
)
{
column
.
customRender
=
({
text
,
record
,
index
})
=>
{
return
formatCell
(
text
,
format
,
record
,
index
);
};
}
return
columns
.
filter
((
column
)
=>
{
return
hasPermission
(
column
.
auth
)
&&
isIfShow
(
column
);
})
.
map
((
column
)
=>
{
const
{
slots
,
dataIndex
,
customRender
,
format
,
edit
,
editRow
,
flag
}
=
column
;
if
(
!
slots
||
!
slots
?.
title
)
{
column
.
slots
=
{
title
:
`header-
${
dataIndex
}
`
,
...(
slots
||
{})
};
column
.
customTitle
=
column
.
title
;
Reflect
.
deleteProperty
(
column
,
'
title
'
);
}
const
isDefaultAction
=
[
INDEX_COLUMN_FLAG
,
ACTION_COLUMN_FLAG
].
includes
(
flag
!
);
if
(
!
customRender
&&
format
&&
!
edit
&&
!
isDefaultAction
)
{
column
.
customRender
=
({
text
,
record
,
index
})
=>
{
return
formatCell
(
text
,
format
,
record
,
index
);
};
}
// edit table
if
((
edit
||
editRow
)
&&
!
isDefaultAction
)
{
column
.
customRender
=
renderEditCell
(
column
);
}
})
;
return
columns
;
// edit table
if
((
edit
||
editRow
)
&&
!
isDefaultAction
)
{
column
.
customRender
=
renderEditCell
(
column
);
}
return
column
;
})
;
});
watch
(
...
...
src/components/Table/src/types/table.ts
浏览文件 @
5a3861b9
...
...
@@ -8,6 +8,7 @@ import type {
import
{
ComponentType
}
from
'
./componentType
'
;
import
{
VueNode
}
from
'
/@/utils/propTypes
'
;
import
{
RoleEnum
}
from
'
/@/enums/roleEnum
'
;
export
declare
type
SortOrder
=
'
ascend
'
|
'
descend
'
;
...
...
@@ -421,4 +422,8 @@ export interface BasicColumn extends ColumnProps {
editRule
?:
boolean
|
((
text
:
string
,
record
:
Recordable
)
=>
Promise
<
string
>
);
editValueMap
?:
(
value
:
any
)
=>
string
;
onEditRow
?:
()
=>
void
;
// 权限编码控制是否显示
auth
?:
RoleEnum
|
RoleEnum
[]
|
string
|
string
[];
// 业务控制是否显示
ifShow
?:
boolean
|
((
column
:
BasicColumn
)
=>
boolean
);
}
src/components/Table/src/types/tableAction.ts
浏览文件 @
5a3861b9
...
...
@@ -8,8 +8,10 @@ export interface ActionItem extends ButtonProps {
popConfirm
?:
PopConfirm
;
disabled
?:
boolean
;
divider
?:
boolean
;
//
Permission code
//
权限编码控制是否显示
auth
?:
RoleEnum
|
RoleEnum
[]
|
string
|
string
[];
// 业务控制是否显示
ifShow
?:
boolean
|
((
action
:
ActionItem
)
=>
boolean
);
}
export
interface
PopConfirm
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录