feat: 角色crud对接完成

This commit is contained in:
lilinyuan
2024-03-28 16:41:22 +08:00
parent c412b8652d
commit 51cf038bed
3 changed files with 242 additions and 32 deletions

View File

@@ -6,8 +6,11 @@
<script setup lang="jsx">
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
import Tag from '@/components/Tag.vue'
import { ElMessageBox } from 'element-plus';
import { ElMessageBox, ElNotification } from 'element-plus';
import { deleteRole } from "@/api/role/role";
import { useAuthStore } from '@/stores/userstore.js'
const authStore = useAuthStore()
const router = useRouter()
const shortcuts = [
@@ -87,6 +90,12 @@ const searchConfig = reactive([
const tableIns = ref()
const auths = {
edit: ['admin:role:edit'],
del: ['admin:role:del'],
add: ['admin:role:add'],
}
const tableConfig = reactive({
columns: [
{
@@ -119,18 +128,52 @@ const tableConfig = reactive({
{
prop: 'oper',
label: '操作',
align: 'center',
currentRender: ({row, index}) => (
<div>
<el-button type="primary" link onClick={()=>handleEdit(row)}>修改</el-button>
<el-button type="primary" link onClick={()=>handleAssign(row)}>分配用户</el-button>
<el-button type="danger" link onClick={()=>handleDel(row)}>删除</el-button>
</div>
)
align: 'right',
currentRender: ({row, index}) => {
let btn = [{label: '修改', auth: auths.edit, func: ()=>handleEdit(row) , type: 'primary'}]
row.template ?
btn.push(
{
label: '使用模版',
auth: auths.edit,
func: ()=>handleUseTemp(row),
type: 'primary'
}
) :
btn.push(
{
label: '分配用户',
auth: auths.edit,
func: ()=>handleAssign(row),
type: 'primary'
}
)
if(authStore.roles.includes('superAdmin')) {
btn.push({label: '删除', auth: auths.edit, func: ()=>handleDel(row) , type: 'danger'})
} else if(!row.template) {
btn.push({label: '删除', auth: auths.edit, func: ()=>handleDel(row) , type: 'danger'})
}
return (
<div>
{
btn.map(item=>(
<el-button
type={item.type}
v-perm={item.auth}
onClick={()=>item.func()}
link
>
{item.label}
</el-button>
))
}
</div>
)
},
}
],
api: '/admin/role',
btns: [{name: '新增', key: 'add', auth: ['admin:role:add'], type: 'primary'}],
btns: [{name: '新增', key: 'add', auth: auths.add, type: 'primary'}],
params: {}
})
@@ -170,7 +213,22 @@ const handleAdd = () => {
}
const handleEdit = (row) => {
router.push({
path: '/system/roleedit',
query: {
id: row.roleId
}
})
}
const handleUseTemp = (row) => {
router.push({
path: '/system/roleadd',
query: {
id: row.roleId,
isAdd: 1
}
})
}
const handleAssign = (row) => {
@@ -178,12 +236,27 @@ const handleAssign = (row) => {
}
const handleDel = (row) => {
if (!(row.template && authStore.roles.includes('superAdmin'))) {
ElNotification({
title: '提示',
message: '模版角色只能由超级管理员删除!',
type: 'warning'
})
return
}
ElMessageBox.confirm('确定删除该条数据吗?', '确定删除', {
type: 'warning',
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(async res => {
// const { code } = await
const { code, msg } = await deleteRole(row.roleId)
ElNotification({
title: '删除',
message: msg,
type: code === 1000 ? 'success' : 'error'
})
tableIns.value.refresh()
}).catch(()=>{})
}