1.完成新版列字段授权
This commit is contained in:
@@ -33,14 +33,10 @@ class ColumnViewSet(CustomModelViewSet):
|
|||||||
app_name = request.query_params.get('app')
|
app_name = request.query_params.get('app')
|
||||||
model_name = request.query_params.get('model')
|
model_name = request.query_params.get('model')
|
||||||
if not role_id or not model_name or not app_name:
|
if not role_id or not model_name or not app_name:
|
||||||
return SuccessResponse([])
|
return ErrorResponse(msg="参数错误")
|
||||||
queryset = self.filter_queryset(self.get_queryset().filter(role_id=role_id, model=model_name, app=app_name))
|
queryset = Columns.objects.filter(role_id=role_id, model=model_name, app=app_name)
|
||||||
page = self.paginate_queryset(queryset)
|
serializer = ColumnSerializer(queryset, many=True, request=request)
|
||||||
if page is not None:
|
return DetailResponse(data=serializer.data, msg="获取成功")
|
||||||
serializer = self.get_serializer(page, many=True, request=request)
|
|
||||||
return self.get_paginated_response(serializer.data)
|
|
||||||
serializer = self.get_serializer(queryset, many=True, request=request)
|
|
||||||
return SuccessResponse(data=serializer.data, msg="获取成功")
|
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
payload = request.data
|
payload = request.data
|
||||||
@@ -94,4 +90,4 @@ class ColumnViewSet(CustomModelViewSet):
|
|||||||
serializer = self.get_serializer(data=data, request=request)
|
serializer = self.get_serializer(data=data, request=request)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return SuccessResponse(msg='匹配成功')
|
return DetailResponse(msg='匹配成功')
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class MenuViewSet(CustomModelViewSet):
|
|||||||
"""用于前端获取当前角色的路由"""
|
"""用于前端获取当前角色的路由"""
|
||||||
user = request.user
|
user = request.user
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
queryset = self.queryset.filter(status=1)
|
queryset = self.queryset.filter(status=1,menu_type__in=[0,1])
|
||||||
else:
|
else:
|
||||||
role_list = user.role.values_list('id', flat=True)
|
role_list = user.role.values_list('id', flat=True)
|
||||||
menu_list = RoleMenuPermission.objects.filter(role__in=role_list).values_list('menu_id', flat=True)
|
menu_list = RoleMenuPermission.objects.filter(role__in=role_list).values_list('menu_id', flat=True)
|
||||||
|
|||||||
65
web/src/views/system/role/components/FieldPermission/api.ts
Normal file
65
web/src/views/system/role/components/FieldPermission/api.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { request } from '/@/utils/service';
|
||||||
|
import { UserPageQuery, AddReq, DelReq, EditReq, InfoReq } from '@fast-crud/fast-crud';
|
||||||
|
import XEUtils from "xe-utils";
|
||||||
|
import {CurrentInfoType} from "/@/views/system/columns/types";
|
||||||
|
|
||||||
|
export const apiPrefix = '/api/system/column/';
|
||||||
|
export function GetList(query: UserPageQuery) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix,
|
||||||
|
method: 'get',
|
||||||
|
params: query,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function GetObj(id: InfoReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + id,
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddObj(obj: AddReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix,
|
||||||
|
method: 'post',
|
||||||
|
data: obj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UpdateObj(obj: EditReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + obj.id + '/',
|
||||||
|
method: 'put',
|
||||||
|
data: obj,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DelObj(id: DelReq) {
|
||||||
|
return request({
|
||||||
|
url: apiPrefix + id + '/',
|
||||||
|
method: 'delete',
|
||||||
|
data: { id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有model
|
||||||
|
*/
|
||||||
|
export function getModelList() {
|
||||||
|
return request({
|
||||||
|
url: '/api/system/column/get_models/',
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动匹配field
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export function automatchColumnsData(data: CurrentInfoType) {
|
||||||
|
return request({
|
||||||
|
url: '/api/system/column/auto_match_fields/',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
208
web/src/views/system/role/components/FieldPermission/crud.tsx
Normal file
208
web/src/views/system/role/components/FieldPermission/crud.tsx
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
import * as api from './api';
|
||||||
|
import { dict, UserPageQuery, AddReq, DelReq, EditReq, compute, CreateCrudOptionsProps, CreateCrudOptionsRet } from '@fast-crud/fast-crud';
|
||||||
|
import { request } from '/@/utils/service';
|
||||||
|
import { dictionary } from '/@/utils/dictionary';
|
||||||
|
import { successMessage, successNotification, warningNotification } from '/@/utils/message';
|
||||||
|
import { inject } from 'vue';
|
||||||
|
import { automatchColumnsData } from '/@/views/system/columns/components/ColumnsTableCom/api';
|
||||||
|
|
||||||
|
export const createCrudOptions = function ({ crudExpose, props }: CreateCrudOptionsProps): CreateCrudOptionsRet {
|
||||||
|
const pageRequest = async (query: UserPageQuery) => {
|
||||||
|
return await api.GetList(query);
|
||||||
|
};
|
||||||
|
const editRequest = async ({ form, row }: EditReq) => {
|
||||||
|
form.id = row.id;
|
||||||
|
return await api.UpdateObj(form);
|
||||||
|
};
|
||||||
|
const delRequest = async ({ row }: DelReq) => {
|
||||||
|
return await api.DelObj(row.id);
|
||||||
|
};
|
||||||
|
const addRequest = async ({ form }: AddReq) => {
|
||||||
|
form.role = props.role;
|
||||||
|
form.model = props.model;
|
||||||
|
form.model = props.app;
|
||||||
|
return await api.AddObj(form);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动匹配列
|
||||||
|
*/
|
||||||
|
const handleAutomatch = async () => {
|
||||||
|
if (props.role && props.model && props.app) {
|
||||||
|
const res = await automatchColumnsData(props);
|
||||||
|
if (res?.code === 2000) {
|
||||||
|
successNotification('匹配成功');
|
||||||
|
}
|
||||||
|
crudExpose.doSearch({ form: { role: props.role, model: props.model, app: props.app } });
|
||||||
|
}
|
||||||
|
warningNotification('请选择角色和模型表!');
|
||||||
|
};
|
||||||
|
|
||||||
|
//权限判定
|
||||||
|
const hasPermissions = inject('$hasPermissions');
|
||||||
|
|
||||||
|
return {
|
||||||
|
crudOptions: {
|
||||||
|
request: {
|
||||||
|
pageRequest,
|
||||||
|
addRequest,
|
||||||
|
editRequest,
|
||||||
|
delRequest,
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
show: false,
|
||||||
|
},
|
||||||
|
actionbar: {
|
||||||
|
buttons: {
|
||||||
|
auto: {
|
||||||
|
text: '自动匹配',
|
||||||
|
type: 'success',
|
||||||
|
click: () => {
|
||||||
|
return handleAutomatch();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rowHandle: {
|
||||||
|
//固定右侧
|
||||||
|
fixed: 'right',
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
col: { span: 24 },
|
||||||
|
labelWidth: '110px',
|
||||||
|
wrapper: {
|
||||||
|
is: 'el-dialog',
|
||||||
|
width: '600px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
columns: {
|
||||||
|
_index: {
|
||||||
|
title: '序号',
|
||||||
|
form: { show: false },
|
||||||
|
column: {
|
||||||
|
//type: 'index',
|
||||||
|
align: 'center',
|
||||||
|
width: '70px',
|
||||||
|
columnSetDisabled: true, //禁止在列设置中选择
|
||||||
|
//@ts-ignore
|
||||||
|
formatter: (context) => {
|
||||||
|
//计算序号,你可以自定义计算规则,此处为翻页累加
|
||||||
|
let index = context.index ?? 1;
|
||||||
|
let pagination: any = crudExpose!.crudBinding.value.pagination;
|
||||||
|
return ((pagination.currentPage ?? 1) - 1) * pagination.pageSize + index + 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
field_name: {
|
||||||
|
title: '字段名',
|
||||||
|
type: 'text',
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
title: '中文名',
|
||||||
|
sortable: 'custom',
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
type: 'text',
|
||||||
|
column: {
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
rules: [
|
||||||
|
// 表单校验规则
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '必填项',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
component: {
|
||||||
|
span: 12,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
is_create: {
|
||||||
|
title: '创建时显示',
|
||||||
|
sortable: 'custom',
|
||||||
|
search: {
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
|
type: 'dict-switch',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{ value: true, label: '启用' },
|
||||||
|
{ value: false, label: '禁用' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
valueChange(context){
|
||||||
|
return api.UpdateObj(context.row)
|
||||||
|
},
|
||||||
|
component: {
|
||||||
|
name: 'fs-dict-switch',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
is_update: {
|
||||||
|
title: '编辑时显示',
|
||||||
|
search: {
|
||||||
|
show: true,
|
||||||
|
},
|
||||||
|
type: 'dict-switch',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{ value: true, label: '启用' },
|
||||||
|
{ value: false, label: '禁用' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
component: {
|
||||||
|
name: 'fs-dict-switch',
|
||||||
|
onChange: compute((context) => {
|
||||||
|
//动态onChange方法测试
|
||||||
|
return () => {
|
||||||
|
console.log('onChange', context.row.switch);
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
is_query: {
|
||||||
|
title: '列表中显示',
|
||||||
|
type: 'dict-switch',
|
||||||
|
dict: dict({
|
||||||
|
data: [
|
||||||
|
{ value: true, label: '启用' },
|
||||||
|
{ value: false, label: '禁用' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
form: {
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
column: {
|
||||||
|
component: {
|
||||||
|
name: 'fs-dict-switch',
|
||||||
|
onChange: compute((context) => {
|
||||||
|
//动态onChange方法测试
|
||||||
|
return () => {
|
||||||
|
console.log('onChange', context.row.switch);
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<el-divider>模型表</el-divider>
|
||||||
|
<div class="model-card">
|
||||||
|
<div v-for="(item,index) in allModelData" :key="index">
|
||||||
|
<el-text @click="onModelChecked(item,index)" :type="modelCheckIndex===index?'primary':''">{{item.app + '--'+item.title + '('+item.key+')' }}</el-text>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-divider>字段权限</el-divider>
|
||||||
|
<div style="height: 50vh">
|
||||||
|
<fs-crud ref="crudRef" v-bind="crudBinding">
|
||||||
|
</fs-crud>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import {ref, onMounted, reactive} from 'vue';
|
||||||
|
import {useFs} from '@fast-crud/fast-crud';
|
||||||
|
import {createCrudOptions} from './crud';
|
||||||
|
import {getModelList} from './api'
|
||||||
|
const propsContext = defineProps({
|
||||||
|
roleId:{
|
||||||
|
type:String||Number,
|
||||||
|
required:true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const props = reactive({
|
||||||
|
role: '',
|
||||||
|
model: '',
|
||||||
|
app: '',
|
||||||
|
menu:''
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 获取所有model
|
||||||
|
const allModelData = ref<any[]>([]);
|
||||||
|
const modelCheckIndex=ref(-1)
|
||||||
|
const onModelChecked = (row,index)=>{
|
||||||
|
modelCheckIndex.value = index
|
||||||
|
props.model = row.key
|
||||||
|
props.app = row.app
|
||||||
|
props.role=propsContext.roleId
|
||||||
|
crudExpose.setTableData([])
|
||||||
|
crudExpose.doSearch({form:{role:propsContext.roleId,model:row.key,app:row.app}})
|
||||||
|
}
|
||||||
|
|
||||||
|
const {crudBinding, crudRef, crudExpose} = useFs({createCrudOptions,props});
|
||||||
|
onMounted(async () => {
|
||||||
|
const res = await getModelList();
|
||||||
|
allModelData.value = res.data;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.model-card{
|
||||||
|
height: 20vh;
|
||||||
|
overflow-y: scroll;
|
||||||
|
div{
|
||||||
|
margin: 15px 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user