增加菜单权限接口批量创建功能
This commit is contained in:
@@ -80,4 +80,29 @@ class MenuButtonViewSet(CustomModelViewSet):
|
|||||||
else:
|
else:
|
||||||
role_id = request.user.role.values_list('id', flat=True)
|
role_id = request.user.role.values_list('id', flat=True)
|
||||||
queryset = RoleMenuButtonPermission.objects.filter(role__in=role_id).values_list('menu_button__value',flat=True).distinct()
|
queryset = RoleMenuButtonPermission.objects.filter(role__in=role_id).values_list('menu_button__value',flat=True).distinct()
|
||||||
return DetailResponse(data=queryset)
|
return DetailResponse(data=queryset)
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=False, permission_classes=[IsAuthenticated])
|
||||||
|
def batch_create(self, request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
批量创建菜单“增删改查查”权限
|
||||||
|
创建的数据来源于菜单,需要规范创建菜单参数
|
||||||
|
value:菜单的component_name:method
|
||||||
|
api:菜单的web_path增加'/api/'前缀,并根据method增加{id}
|
||||||
|
"""
|
||||||
|
menu_obj = Menu.objects.filter(id=request.data['menu']).first()
|
||||||
|
result_list = [
|
||||||
|
{'menu': menu_obj.id, 'name': '新增', 'value': f'{menu_obj.component_name}:Create', 'api': f'/api/{menu_obj.web_path}/',
|
||||||
|
'method': 0},
|
||||||
|
{'menu': menu_obj.id, 'name': '删除', 'value': f'{menu_obj.component_name}:Delete', 'api': f'/api/{menu_obj.web_path}/{{id}}/',
|
||||||
|
'method': 3},
|
||||||
|
{'menu': menu_obj.id, 'name': '修改', 'value': f'{menu_obj.component_name}:Update', 'api': f'/api/{menu_obj.web_path}/{{id}}/',
|
||||||
|
'method': 2},
|
||||||
|
{'menu': menu_obj.id, 'name': '查询', 'value': f'{menu_obj.component_name}:Search', 'api': f'/api/{menu_obj.web_path}/',
|
||||||
|
'method': 0},
|
||||||
|
{'menu': menu_obj.id, 'name': '详情', 'value': f'{menu_obj.component_name}:Retrieve', 'api': f'/api/{menu_obj.web_path}/{{id}}/',
|
||||||
|
'method': 0}]
|
||||||
|
serializer = self.get_serializer(data=result_list, many=True)
|
||||||
|
serializer.is_valid(raise_exception=True)
|
||||||
|
serializer.save()
|
||||||
|
return SuccessResponse(serializer.data, msg="批量创建成功")
|
||||||
|
|||||||
@@ -39,3 +39,12 @@ export function DelObj(id: DelReq) {
|
|||||||
data: { id },
|
data: { id },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function BatchAdd(obj: AddReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + 'batch_create/',
|
||||||
|
method: 'post',
|
||||||
|
data: obj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import {AddReq, DelReq, EditReq, dict, CreateCrudOptionsRet, CreateCrudOptionsPr
|
|||||||
import * as api from './api';
|
import * as api from './api';
|
||||||
import {auth} from '/@/utils/authFunction'
|
import {auth} from '/@/utils/authFunction'
|
||||||
import {request} from '/@/utils/service';
|
import {request} from '/@/utils/service';
|
||||||
|
import { successNotification } from '/@/utils/message';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
//此处为crudOptions配置
|
//此处为crudOptions配置
|
||||||
export const createCrudOptions = function ({crudExpose, context}: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
export const createCrudOptions = function ({crudExpose, context}: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||||
const pageRequest = async () => {
|
const pageRequest = async () => {
|
||||||
@@ -40,6 +42,22 @@ export const createCrudOptions = function ({crudExpose, context}: CreateCrudOpti
|
|||||||
add: {
|
add: {
|
||||||
show: auth('btn:Create')
|
show: auth('btn:Create')
|
||||||
},
|
},
|
||||||
|
batchAdd: {
|
||||||
|
show: true,
|
||||||
|
type: 'primary',
|
||||||
|
text: '批量生成',
|
||||||
|
click: async () => {
|
||||||
|
if (context!.selectOptions.value.id == undefined) {
|
||||||
|
ElMessage.error('请选择菜单');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await api.BatchAdd({ menu: context!.selectOptions.value.id });
|
||||||
|
if (result.code == 2000) {
|
||||||
|
successNotification(result.msg);
|
||||||
|
crudExpose.doRefresh();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rowHandle: {
|
rowHandle: {
|
||||||
|
|||||||
Reference in New Issue
Block a user