新增权限配置
This commit is contained in:
parent
f22754edbf
commit
d95678841c
72
src/api/permissionConfig.ts
Normal file
72
src/api/permissionConfig.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { request } from '@/utils/request'
|
||||
|
||||
// 数据权限配置 类型定义
|
||||
export interface PermissionConfig {
|
||||
id?: number
|
||||
|
||||
mapperKey?: string
|
||||
|
||||
controlMethod?: string
|
||||
|
||||
permissionControl?: string
|
||||
|
||||
}
|
||||
|
||||
// 数据权限配置 API
|
||||
export const permissionConfigApi = {
|
||||
// 分页查询
|
||||
page(params: { page: number; pageSize: number; mapperKey?: string; controlMethod?: string }) {
|
||||
return request({ url: '/biz/permissionConfig/page', method: 'get', params })
|
||||
},
|
||||
|
||||
// 新增
|
||||
options() {
|
||||
return request({ url: '/biz/permissionConfig/options', method: 'get' })
|
||||
},
|
||||
|
||||
// 获取详情
|
||||
detail(id: string) {
|
||||
return request({ url: `/biz/permissionConfig/${id}`, method: 'get' })
|
||||
},
|
||||
|
||||
// 新增
|
||||
create(data: PermissionConfig) {
|
||||
return request({ url: '/biz/permissionConfig', method: 'post', data })
|
||||
},
|
||||
|
||||
// 修改
|
||||
update(data: PermissionConfig) {
|
||||
return request({ url: '/biz/permissionConfig', method: 'put', data })
|
||||
},
|
||||
|
||||
// 删除
|
||||
delete(ids: string[]) {
|
||||
return request({ url: `/biz/permissionConfig/${ids.join(',')}`, method: 'delete' })
|
||||
},
|
||||
|
||||
// 导出
|
||||
export(params?: { ids?: string[]; mapperKey?: string; controlMethod?: string }) {
|
||||
const p: Record<string, any> = {}
|
||||
if (params?.ids?.length) p.ids = params.ids.join(',')
|
||||
if (params?.mapperKey !== undefined && params?.mapperKey !== null) p.mapperKey = params.mapperKey
|
||||
if (params?.controlMethod !== undefined && params?.controlMethod !== null) p.controlMethod = params.controlMethod
|
||||
return request({ url: `/biz/permissionConfig/export`, method: 'get', params: p, responseType: 'blob' })
|
||||
},
|
||||
|
||||
// 导入
|
||||
importData(file: File) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return request<{ success: number; fail: number; errors: string[] }>({
|
||||
url: `/biz/permissionConfig/import`,
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
},
|
||||
|
||||
// 下载导入模板
|
||||
downloadTemplate() {
|
||||
return request({ url: `/biz/permissionConfig/template`, method: 'get', responseType: 'blob' })
|
||||
}
|
||||
}
|
||||
@ -216,6 +216,12 @@ const routes: RouteRecordRaw[] = [
|
||||
meta: { title: '设备状态监控', icon: 'PulseOutline' }
|
||||
},
|
||||
// 开发工具
|
||||
{
|
||||
path: 'biz/permissionConfig',
|
||||
name: 'permissionConfig',
|
||||
component: () => import('@/views/biz/permissionConfig/index.vue'),
|
||||
meta: { title: '数据权限配置', icon: 'ListOutline' }
|
||||
},
|
||||
{
|
||||
path: 'tool/gen',
|
||||
name: 'ToolGen',
|
||||
|
||||
452
src/views/biz/permissionConfig/index.vue
Normal file
452
src/views/biz/permissionConfig/index.vue
Normal file
@ -0,0 +1,452 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<n-card>
|
||||
<!-- 搜索表单 -->
|
||||
<div class="search-form">
|
||||
<n-form inline :model="searchForm" label-placement="left">
|
||||
<n-form-item label="mapper">
|
||||
<n-select v-model:value="searchForm.mapperKey" placeholder="请选择mapper" clearable style="width: 300px" :options="mapperOptions"
|
||||
@update:value="mapperSearchUpdate" />
|
||||
</n-form-item>
|
||||
<n-form-item label="控制方法">
|
||||
<n-select v-model:value="searchForm.controlMethod" placeholder="请选择控制方法" clearable style="width: 200px" :options="methodSearchOptions" />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleSearch">
|
||||
<template #icon><n-icon><SearchOutline /></n-icon></template>
|
||||
搜索
|
||||
</n-button>
|
||||
<n-button @click="handleReset">
|
||||
<template #icon><n-icon><RefreshOutline /></n-icon></template>
|
||||
重置
|
||||
</n-button>
|
||||
</n-space>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</div>
|
||||
|
||||
<!-- 工具栏 -->
|
||||
<div class="table-toolbar">
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleAdd">
|
||||
<template #icon><n-icon><AddOutline /></n-icon></template>
|
||||
新增
|
||||
</n-button>
|
||||
<n-button @click="importModalVisible = true">
|
||||
<template #icon><n-icon><CloudUploadOutline /></n-icon></template>
|
||||
导入
|
||||
</n-button>
|
||||
<n-button @click="handleExport">
|
||||
<template #icon><n-icon><DownloadOutline /></n-icon></template>
|
||||
导出{{ selectedIds.length > 0 ? `(${selectedIds.length})` : '' }}
|
||||
</n-button>
|
||||
<n-button type="error" :disabled="selectedIds.length === 0" @click="handleBatchDelete">
|
||||
<template #icon><n-icon><TrashOutline /></n-icon></template>
|
||||
删除
|
||||
</n-button>
|
||||
</n-space>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="tableData"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
:row-key="(row) => row.id"
|
||||
:scroll-x="1200"
|
||||
@update:page="handlePageChange"
|
||||
@update:page-size="handlePageSizeChange"
|
||||
@update:checked-row-keys="handleCheck"
|
||||
/>
|
||||
</n-card>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<n-modal v-model:show="modalVisible" preset="card" :title="modalTitle" style="width: 800px" :mask-closable=false>
|
||||
<n-form ref="formRef" :model="formData" :rules="formRules" label-placement="left" label-width="100px">
|
||||
<n-grid :cols="2" :x-gap="24">
|
||||
<n-form-item-gi label="mapper" path="mapperKey">
|
||||
<n-select v-model:value="formData.mapperKey" placeholder="请选择mapper" :options="mapperOptions" @update:value="mapperUpdate" />
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi label="控制方法" path="controlMethod">
|
||||
<n-select v-model:value="formData.controlMethod" multiple placeholder="请选择控制方法" :options="methodOptions" />
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
<n-grid :cols="1" :x-gap="24">
|
||||
<n-form-item-gi label="权限控制方案" path="permissionControl">
|
||||
<n-dynamic-input
|
||||
v-model:value="permissionControl"
|
||||
key-field="sole"
|
||||
preset="pair"
|
||||
:min="1"
|
||||
:max="5"
|
||||
@create="handleCreate"
|
||||
>
|
||||
<template #default="{ value,index }">
|
||||
<n-space>
|
||||
<n-select
|
||||
v-model:value="value.key"
|
||||
:options="roleOptions"
|
||||
placeholder="请选择角色"
|
||||
style="width: 150px"
|
||||
/>
|
||||
<n-input
|
||||
v-model:value="value.value"
|
||||
placeholder="请输入权限内容"
|
||||
readonly
|
||||
style="width: 400px"
|
||||
@click="clickPermission(index)"
|
||||
/>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-dynamic-input>
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button @click="modalVisible = false">取消</n-button>
|
||||
<n-button type="primary" @click="handleSubmit">确定</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<n-modal v-model:show="updatePermissionModal" :draggable="true" :on-after-leave="closePermission">
|
||||
<n-card style="width: 600px" :bordered="false" size="huge" role="dialog" aria-modal="true" >
|
||||
<n-input v-model:value="updatePermissionContent" placeholder="请输入权限内容" type="textarea" />
|
||||
</n-card>
|
||||
</n-modal>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, h, onMounted } from 'vue'
|
||||
import { NButton, NSpace, NIcon, NUpload, useMessage, useDialog, type DataTableColumns, type UploadCustomRequestOptions } from 'naive-ui'
|
||||
import { SearchOutline, RefreshOutline, AddOutline, TrashOutline, CreateOutline, CloudUploadOutline, DownloadOutline } from '@vicons/ionicons5'
|
||||
import { permissionConfigApi, type PermissionConfig } from '@/api/permissionConfig'
|
||||
import { roleApi, SysRole } from '@/api/system'
|
||||
|
||||
const message = useMessage()
|
||||
const dialog = useDialog()
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
mapperKey: '',
|
||||
controlMethod: '',
|
||||
})
|
||||
|
||||
const permissionControl = ref([
|
||||
{
|
||||
sole:Date.now(),
|
||||
key: '',
|
||||
value: '123'
|
||||
}
|
||||
])
|
||||
|
||||
// 下拉选项
|
||||
const roleOptions = ref<Array<{ label: string; value: number; disabled:false }>>([])
|
||||
|
||||
const handleCreate = () => {
|
||||
return {
|
||||
sole: Date.now() + Math.random(), // key‑field使用的唯一主键
|
||||
key:"",
|
||||
value: null // select绑定的业务字段,不要和key混淆
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 表格数据
|
||||
const tableData = ref<PermissionConfig[]>([])
|
||||
const loading = ref(false)
|
||||
const selectedIds = ref<number[]>([])
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
itemCount: 0,
|
||||
showSizePicker: true,
|
||||
pageSizes: [10, 20, 50]
|
||||
})
|
||||
|
||||
// 弹窗
|
||||
const modalVisible = ref(false)
|
||||
const modalTitle = ref('')
|
||||
const importModalVisible = ref(false)
|
||||
const formRef = ref()
|
||||
const defaultFormData: PermissionConfig = {
|
||||
mapperKey: '',
|
||||
controlMethod: '',
|
||||
permissionControl: '',
|
||||
}
|
||||
const formData = reactive<PermissionConfig>({ ...defaultFormData })
|
||||
|
||||
// 字典选项(下拉框/单选框/复选框关联字典时使用)
|
||||
|
||||
// 表单校验规则
|
||||
const formRules = {
|
||||
}
|
||||
|
||||
// 表格列
|
||||
const columns: DataTableColumns<PermissionConfig> = [
|
||||
{ type: 'selection' },
|
||||
{ title: 'mapper', key: 'mapperKey' },
|
||||
{ title: '控制方法', key: 'controlMethod' },
|
||||
{ title: '权限控制方案', key: 'permissionControl' },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'actions',
|
||||
width: 140,
|
||||
fixed: 'right',
|
||||
render(row) {
|
||||
return h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'nowrap' } }, [
|
||||
h(NButton, { size: 'small', quaternary: true, onClick: () => handleEdit(row) }, {
|
||||
default: () => [h(NIcon, null, { default: () => h(CreateOutline) }), ' 编辑']
|
||||
}),
|
||||
h(NButton, { size: 'small', quaternary: true, type: 'error', onClick: () => handleDelete(row) }, {
|
||||
default: () => [h(NIcon, null, { default: () => h(TrashOutline) }), ' 删除']
|
||||
})
|
||||
])
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
const updatePermissionIndex = ref<number>(-1)
|
||||
const updatePermissionContent = ref<string>('')
|
||||
const updatePermissionModal = ref(false)
|
||||
|
||||
function clickPermission(index:number){
|
||||
updatePermissionIndex.value = index
|
||||
updatePermissionContent.value = permissionControl.value[index].value;
|
||||
updatePermissionModal.value = true
|
||||
}
|
||||
function closePermission(){
|
||||
permissionControl.value[updatePermissionIndex.value].value = updatePermissionContent.value;
|
||||
}
|
||||
|
||||
// 加载数据
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await permissionConfigApi.page({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
mapperKey: searchForm.mapperKey || undefined,
|
||||
controlMethod: searchForm.controlMethod || undefined,
|
||||
})
|
||||
tableData.value = res.list
|
||||
pagination.itemCount = res.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
function handleSearch() {
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// 重置
|
||||
function handleReset() {
|
||||
searchForm.mapperKey = ''
|
||||
|
||||
searchForm.controlMethod = ''
|
||||
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 分页
|
||||
function handlePageChange(page: number) {
|
||||
pagination.page = page
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handlePageSizeChange(pageSize: number) {
|
||||
pagination.pageSize = pageSize
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
// 选择
|
||||
function handleCheck(keys: Array<string | number>) {
|
||||
selectedIds.value = keys as number[]
|
||||
}
|
||||
|
||||
// 新增
|
||||
function handleAdd() {
|
||||
modalTitle.value = '新增数据权限配置'
|
||||
Object.assign(formData, defaultFormData)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑
|
||||
function handleEdit(row: PermissionConfig) {
|
||||
modalTitle.value = '编辑数据权限配置'
|
||||
Object.assign(formData, row)
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
// 提交
|
||||
async function handleSubmit() {
|
||||
await formRef.value?.validate()
|
||||
try {
|
||||
const submitData = { ...formData } as PermissionConfig
|
||||
if (submitData.id) {
|
||||
await permissionConfigApi.update(submitData)
|
||||
message.success('修改成功')
|
||||
} else {
|
||||
await permissionConfigApi.create(submitData)
|
||||
message.success('新增成功')
|
||||
}
|
||||
modalVisible.value = false
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
function handleDelete(row: PermissionConfig) {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: '确定要删除该记录吗?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try {
|
||||
await permissionConfigApi.delete([row.id!])
|
||||
message.success('删除成功')
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
function handleBatchDelete() {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: `确定要删除选中的 ${selectedIds.value.length} 条记录吗?`,
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
try {
|
||||
await permissionConfigApi.delete(selectedIds.value)
|
||||
message.success('删除成功')
|
||||
selectedIds.value = []
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 导出
|
||||
async function handleExport() {
|
||||
try {
|
||||
const params: Record<string, any> = {}
|
||||
if (selectedIds.value.length > 0) params.ids = selectedIds.value
|
||||
if (searchForm.mapperKey) params.mapperKey = searchForm.mapperKey
|
||||
if (searchForm.controlMethod) params.controlMethod = searchForm.controlMethod
|
||||
const blob = await permissionConfigApi.export(params)
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = '数据权限配置数据.xlsx'
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 下载导入模板
|
||||
async function handleDownloadTemplate() {
|
||||
try {
|
||||
const blob = await permissionConfigApi.downloadTemplate()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = '数据权限配置导入模板.xlsx'
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 导入上传
|
||||
async function handleImportUpload({ file }: UploadCustomRequestOptions) {
|
||||
if (!file.file) return
|
||||
try {
|
||||
const result = await permissionConfigApi.importData(file.file)
|
||||
if (result.fail > 0) {
|
||||
dialog.warning({
|
||||
title: '导入结果',
|
||||
content: `成功: ${result.success} 条,失败: ${result.fail} 条\n错误信息: ${(result.errors || []).join('\n') || '无'}`,
|
||||
positiveText: '确定'
|
||||
})
|
||||
} else {
|
||||
message.success(`导入成功,共 ${result.success} 条数据`)
|
||||
importModalVisible.value = false
|
||||
}
|
||||
loadData()
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
const mapperOptions = ref<{ label: string; value: any }[]>([])
|
||||
const methodSearchOptions = ref<{ label: string; value: any }[]>([])
|
||||
const methodOptions = ref<{ label: string; value: any }[]>([])
|
||||
function mapperUpdate(v:any,opt:any) {
|
||||
formData.controlMethod=''
|
||||
methodOptions.value = opt.childList;
|
||||
}
|
||||
|
||||
function mapperSearchUpdate(v:any,opt:any) {
|
||||
searchForm.controlMethod=''
|
||||
methodSearchOptions.value = opt.childList;
|
||||
}
|
||||
|
||||
// 加载字典选项
|
||||
async function loadDictOptions() {
|
||||
try {
|
||||
mapperOptions.value = await permissionConfigApi.options();
|
||||
}catch{}
|
||||
try {
|
||||
const roles = await roleApi.list()
|
||||
roleOptions.value = roles.map((role: SysRole) => ({
|
||||
label: role.name,
|
||||
value: role.id!,
|
||||
disabled:false
|
||||
}))
|
||||
} catch (error) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
loadDictOptions()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-form {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.table-toolbar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user