feat: 使用json或excel导入导出权限
This commit is contained in:
parent
6d8e3d2cf0
commit
603cdf3285
|
@ -1,85 +0,0 @@
|
|||
/**
|
||||
* * 自动创建权限内容
|
||||
*/
|
||||
(async function requestPath() {
|
||||
// 获取基础paths对象
|
||||
const response = await fetch('http://localhost:7070/v3/api-docs/%E9%BB%98%E8%AE%A4%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3', { method: 'GET' });
|
||||
const json = await response.json();
|
||||
const paths = json.paths;
|
||||
|
||||
// 设置父级id顺序
|
||||
let id = 1;
|
||||
|
||||
// 最后整理的数据内容
|
||||
const data = {};
|
||||
|
||||
// 获取所有键
|
||||
Object.keys(paths)
|
||||
.filter(item => !item.includes('noAuth') && !item.includes('noManage'))
|
||||
.forEach(key => {
|
||||
const pathKey = paths[key];
|
||||
const { tags, description } = pathKey[Object.keys(pathKey)[0]];
|
||||
const tag = tags[0];
|
||||
|
||||
// 父级内容为info信息
|
||||
const path = key.match(/\w+\/\w+/, key)[0];
|
||||
const info = {
|
||||
id: 1,
|
||||
parentId: 0,
|
||||
powerCode: path.replaceAll('/', '::'),
|
||||
powerName: tag,
|
||||
requestUrl: undefined,
|
||||
};
|
||||
|
||||
// 整理子级内容信息
|
||||
const powerCode = key.replace('/api/', '').replace(/\/\{.*?\}/g, '');
|
||||
const item = {
|
||||
parentId: info.id,
|
||||
powerCode: powerCode.replaceAll('/', '::'),
|
||||
powerName: description,
|
||||
requestUrl: key.replace(/\/{.*/, '/.*'),
|
||||
};
|
||||
|
||||
// 向父级内容添加子级Children内容
|
||||
if (!data[tag]) {
|
||||
data[tag] = {
|
||||
info,
|
||||
children: [item],
|
||||
};
|
||||
}
|
||||
data[tag].children.push(item);
|
||||
});
|
||||
|
||||
// 便利整理好的参数data
|
||||
for (const item in data) {
|
||||
// 先添加父级内容
|
||||
const info = data[item].info;
|
||||
info.id = id;
|
||||
await add(info);
|
||||
|
||||
// 遍历子级内容向服务器添加
|
||||
const children = data[item].children;
|
||||
for (const item1 of children) {
|
||||
item1.parentId = id;
|
||||
await add(item1);
|
||||
}
|
||||
|
||||
// 父级添加后id增加
|
||||
id++;
|
||||
}
|
||||
})();
|
||||
|
||||
// 向服务器添加的内容
|
||||
async function add(data) {
|
||||
const response = await fetch('http://localhost:7070/admin/power/addPower', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
token:
|
||||
'eyJhbGciOiJIUzI1NiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAA_yWLywqFIBQA_-WsE_RknWxXuz5DU8EgCx9QXO6_X-HuhmHmA7kamGGtMb7QgXtumAX1KEekQXVQs0ubbe6PUZ-u5Ys9Qwy5JF2u1LajhGaNFoZGLxlKS0xavjPjkbPBKS8Uql3TBN8fHTtSk3MAAAA.u-rDR1a46DoV0X-iQEz0Y9lfUGPm0Nsr2MuD4fvtVMg',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
const json = await response.json();
|
||||
console.log(json);
|
||||
}
|
|
@ -35,7 +35,12 @@ export const importPermission = (data: any) => {
|
|||
|
||||
/** 权限---获取所有权限 */
|
||||
export const getPermissionList = () => {
|
||||
return http.request<BaseResult<any>>('get', `permission/getPermissionList`);
|
||||
return http.request<BaseResult<any>>('get', `permission/private/getPermissionList`);
|
||||
};
|
||||
|
||||
/* 权限---获取系统API信息 */
|
||||
export const getSystemApiInfoList = () => {
|
||||
return http.request<BaseResult<any>>('get', 'permission/private/getSystemApiInfoList');
|
||||
};
|
||||
|
||||
/** 权限---更新权限 */
|
||||
|
|
|
@ -45,4 +45,4 @@ export const tableSelectButtonClass = computed(() => ['!h-[20px]', 'reset-margin
|
|||
export const UserAvatar =
|
||||
'https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoj0hHXhgJNOTSOFsS4uZs8x1ConecaVOB8eIl115xmJZcT4oCicvia7wMEufibKtTLqiaJeanU2Lpg3w/132';
|
||||
|
||||
export const RequestMethod = ['', 'GET', 'PUT', 'POST', 'DELETE', 'HEAD', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'];
|
||||
export const RequestMethod = ['', 'GET', 'PUT', 'POST', 'DELETE', /* 'HEAD', 'CONNECT', 'OPTIONS', 'TRACE', */ 'PATCH'];
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
exportPermission,
|
||||
getPermissionList,
|
||||
getPermissionPage,
|
||||
getSystemApiInfoList,
|
||||
importPermission,
|
||||
updatePermission,
|
||||
updatePermissionListByParentId,
|
||||
|
@ -24,6 +25,8 @@ export const usePermissionStore = defineStore('PermissionStore', {
|
|||
datalist: [],
|
||||
// 权限树形结构
|
||||
allPowerList: [],
|
||||
// 系统api列表
|
||||
systemApiInfoList: [],
|
||||
// 查询表单
|
||||
form: {
|
||||
// 权限编码
|
||||
|
@ -102,6 +105,13 @@ export const usePermissionStore = defineStore('PermissionStore', {
|
|||
this.allPowerList = result.data;
|
||||
},
|
||||
|
||||
/* 获取系统API信息 */
|
||||
async loadSystemApiInfoList() {
|
||||
const result = await getSystemApiInfoList();
|
||||
if (result.code !== 200) return;
|
||||
this.systemApiInfoList = result.data;
|
||||
},
|
||||
|
||||
/** 批量修改权限父级 */
|
||||
async updatePermissionListByParentId(data: any) {
|
||||
const result = await updatePermissionListByParentId(data);
|
||||
|
|
|
@ -4,9 +4,9 @@ export const auth = {
|
|||
// 添加操作
|
||||
add: ['schedulers::add'],
|
||||
// 暂停
|
||||
pause: ['schedulers::pause'],
|
||||
pause: ['schedulers::update'],
|
||||
// 恢复
|
||||
resume: ['schedulers::resume'],
|
||||
resume: ['schedulers::update'],
|
||||
// 删除操作
|
||||
delete: ['schedulers::delete'],
|
||||
};
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import type { TreeInstance } from 'element-plus';
|
||||
import { FormInstance } from 'element-plus';
|
||||
import { FormProps, powerCascadeProps, rules } from '@/views/system/permission/utils';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { handleTree } from '@pureadmin/utils';
|
||||
import { usePermissionStore } from '@/store/system/power';
|
||||
import { RequestMethod } from '@/enums/baseConstant';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
interface Tree {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<FormProps>(), {
|
||||
formInline: () => ({
|
||||
|
@ -23,27 +29,81 @@ const props = withDefaults(defineProps<FormProps>(), {
|
|||
});
|
||||
|
||||
const formRef = ref<FormInstance>();
|
||||
const treeRef = ref<TreeInstance>();
|
||||
const form = ref(props.formInline);
|
||||
const powerStore = usePermissionStore();
|
||||
const { allPowerList, systemApiInfoList } = storeToRefs(powerStore);
|
||||
|
||||
// tab 默认选中项
|
||||
const activeName = ref('system');
|
||||
|
||||
// 过滤搜索
|
||||
const queryText = ref('');
|
||||
|
||||
/* 搜索名称 */
|
||||
const filterMethod = (value: string, data: Tree) => {
|
||||
if (!value) return true;
|
||||
return data.summary.includes(value);
|
||||
};
|
||||
/* 输入时搜索 */
|
||||
const onQueryChange = (val: string) => {
|
||||
treeRef.value!.filter(val);
|
||||
};
|
||||
|
||||
const onNodeClick = (node) => {
|
||||
form.value.powerName = node.summary;
|
||||
form.value.requestMethod = node.httpMethod;
|
||||
form.value.requestUrl = node.path;
|
||||
if (node.powerCodes && node.powerCodes.length > 0) {
|
||||
form.value.powerCode = node.powerCodes[0];
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
powerStore.loadPermissionList();
|
||||
powerStore.loadSystemApiInfoList();
|
||||
});
|
||||
|
||||
defineExpose({ formRef });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="auto">
|
||||
<el-input v-model="queryText" clearable placeholder="搜索名称" @input="onQueryChange" />
|
||||
<el-tree
|
||||
ref="treeRef"
|
||||
:data="systemApiInfoList"
|
||||
:expand-on-click-node="true"
|
||||
:filter-node-method="filterMethod"
|
||||
:props="{ label: 'summary' }"
|
||||
accordion
|
||||
class="my-2 py-1 h-[220px] overflow-y-auto"
|
||||
highlight-current
|
||||
node-key="path"
|
||||
@node-click="onNodeClick"
|
||||
>
|
||||
<template #default="{ node, data }">
|
||||
<el-tooltip :content="data.description">
|
||||
<span>{{ node.label }}</span>
|
||||
</el-tooltip>
|
||||
<div class="custom-tree-node">
|
||||
<el-text type="primary">{{ data.path }}</el-text>
|
||||
<el-text type="danger">{{ data.httpMethod }}</el-text>
|
||||
</div>
|
||||
</template>
|
||||
<template #empty>
|
||||
<ElEmpty />
|
||||
</template>
|
||||
</el-tree>
|
||||
<el-form-item :label="$t('power_parentId')" prop="parentId">
|
||||
<el-cascader
|
||||
v-model="form.parentId"
|
||||
:options="handleTree(powerStore.allPowerList)"
|
||||
:options="handleTree(allPowerList)"
|
||||
:props="powerCascadeProps"
|
||||
class="w-full"
|
||||
clearable
|
||||
filterable
|
||||
show-all-levels
|
||||
style="max-height: 200px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('power_powerCode')" prop="powerCode">
|
||||
|
@ -62,3 +122,13 @@ defineExpose({ formRef });
|
|||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
<style scoped>
|
||||
.custom-tree-node {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export const auth = {
|
||||
// 分页查询
|
||||
query: ['power::query', 'power::queryPage'],
|
||||
// 添加操作
|
||||
// // 添加操作
|
||||
add: ['power::addPower'],
|
||||
// 更新操作
|
||||
update: ['power::updatePower'],
|
||||
|
|
|
@ -7,12 +7,12 @@ export const columns: TableColumnList = [
|
|||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: $t('index'), minWidth: 60 },
|
||||
// 权限编码
|
||||
{ label: $t('power_powerCode'), prop: 'powerCode', minWidth: 350 },
|
||||
{ label: $t('power_powerCode'), prop: 'powerCode', minWidth: 240, align: 'left' },
|
||||
// 权限名称
|
||||
{ label: $t('power_powerName'), prop: 'powerName', minWidth: 320 },
|
||||
{ label: $t('power_powerName'), prop: 'powerName', minWidth: 220 },
|
||||
// 请求路径
|
||||
{ label: $t('power_requestUrl'), prop: 'requestUrl', minWidth: 360 },
|
||||
{ label: $t('requestMethod'), prop: 'requestMethod', minWidth: 360 },
|
||||
{ label: $t('power_requestUrl'), prop: 'requestUrl', minWidth: 360, align: 'left' },
|
||||
{ label: $t('requestMethod'), prop: 'requestMethod', minWidth: 80 },
|
||||
{ label: $t('table.updateTime'), prop: 'updateTime', sortable: true, minWidth: 160 },
|
||||
{ label: $t('table.createTime'), prop: 'createTime', sortable: true, minWidth: 160 },
|
||||
{ label: $t('table.createUser'), prop: 'createUser', slot: 'createUser', minWidth: 130 },
|
||||
|
|
|
@ -75,7 +75,8 @@ export function onUpdate(row: any) {
|
|||
const form = options.props.formInline as FormItemProps;
|
||||
formRef.value.formRef.validate(async (valid: any) => {
|
||||
if (!valid) return;
|
||||
|
||||
// 请求方法是否存在,不存在就为空
|
||||
form.requestMethod = form.requestMethod ? form.requestMethod : '';
|
||||
const result = await powerStore.editPermission({ ...form, id: row.id });
|
||||
if (!result) return;
|
||||
done();
|
||||
|
|
Loading…
Reference in New Issue