@ -1,20 +1,23 @@
@@ -1,20 +1,23 @@
< template >
< div >
< BasicTable @register ="registerTable" @selection-change ="handleSelectionChange" >
< BasicTable @register ="registerTable"
@ fetch - success = "handleSelectionChange"
@ selection - change = "handleSelectionChange"
>
< template # toolbar >
< a -button v -auth = " [ ' role_add ' ] "
type = "primary"
@ click = "handleAdd()"
> 新增角色 < / a - b u t t o n >
< a -button v -auth = " [ ' role_add ' ] "
< a -button v -auth = " [ ' role_edit ' ] "
type = "primary"
: disabled = "state.single"
@ click = "handleAdd ()"
@ click = "handleEdit ()"
> 修改角色 < / a - b u t t o n >
< a -button v -auth = " [ ' role_ad d ' ] "
< a -button v -auth = " [ ' role_del ' ] "
type = "primary"
: disabled = "state.multiple"
@ click = "handleAdd ()"
@ click = "handleDel ()"
> 删除角色 < / a - b u t t o n >
< / template >
< template # action = "{ record }" >
@ -22,18 +25,15 @@
@@ -22,18 +25,15 @@
{
label : '编辑' ,
icon : 'fa6-regular:pen-to-square' ,
auth : [ 'menu _edit' ] ,
auth : [ 'role _edit' ] ,
onClick : handleEdit . bind ( null , record )
} ,
{
label : '删除' ,
icon : 'ant-design:delete-outlined' ,
auth : [ 'menu _del' ] ,
auth : [ 'role _del' ] ,
color : 'error' ,
popConfirm : {
title : '是否确认删除' ,
confirm : handleDel . bind ( null , record ) ,
} ,
onClick : handleDel . bind ( null , record )
} ] "
/ >
< / template >
@ -52,7 +52,10 @@
@@ -52,7 +52,10 @@
import RoleDrawer from './RoleDrawer.vue' ;
import { columns , searchFormSchema } from './role.data' ;
import { useMessage } from '/@/hooks/web/useMessage' ;
import { reactive } from 'vue' ;
import { reactive , toRaw } from 'vue' ;
const { createConfirm } = useMessage ( ) ;
const { createMessage } = useMessage ( ) ;
const state = reactive ( {
/ / 选 中 数 组
@ -62,7 +65,7 @@
@@ -62,7 +65,7 @@
/ / 非 多 个 禁 用
multiple : true
} ) ;
const { createMessage } = useMessage ( ) ;
const [ registerDrawer , { openDrawer } ] = useDrawer ( ) ;
const [ registerTable , { reload } ] = useTable ( {
title : '角色列表' ,
@ -88,27 +91,37 @@
@@ -88,27 +91,37 @@
} ) ;
/** 处理多选框选中数据 */
function handleSelectionChange ( selection ) {
state . ids = selection . map ( item => item . id ) ;
state . single = selection . length != 1 ;
state . multiple = ! selection . length ;
function handleSelectionChange ( selection ? : Recordable ) {
const rawRows = toRaw ( selection ? . rows ) || [ ] ;
state . ids = rawRows . map ( item => item . id ) ;
state . single = rawRows . length != 1 ;
state . multiple = ! rawRows . length ;
}
/** 新增按钮操作,行内新增与工具栏局域新增通用 */
function handleAdd ( record ? : Recordable ) {
openDrawer ( true , { _tag : 'add' , record } ) ;
function handleAdd ( ) {
openDrawer ( true , { _tag : 'add' } ) ;
}
/** 编辑按钮操作,行内编辑 */
function handleEdit ( record : Recordable ) {
function handleEdit ( record ? : Recordable ) {
record = record || { id : toRaw ( state . ids ) } ;
openDrawer ( true , { _tag : 'edit' , record } ) ;
}
/** 删除按钮操作,行内删除 */
async function handleDel ( record : Recordable ) {
await delRole ( { id : record . id } ) ;
createMessage . success ( '删除成功!' ) ;
handleSuccess ( ) ;
async function handleDel ( record ? : Recordable ) {
const ids = record ? . id || toRaw ( state . ids ) ;
createConfirm ( {
iconType : 'warning' ,
title : '警告' ,
content : ` 是否确认删除角色编号为 ${ ids } 角色吗? ` ,
onOk : async ( ) => {
await delRole ( ids ) ;
createMessage . success ( '删除成功!' ) ;
handleSuccess ( ) ;
}
} ) ;
}
/** 处理表单提交成功 */