添加权限策略
This commit is contained in:
parent
d19122f54f
commit
65ccac0240
|
|
@ -1,8 +1,20 @@
|
||||||
import request from '@/utils/user_center_request';
|
import request from '@/utils/user_center_request';
|
||||||
|
|
||||||
export const GetPermissPolicyService = () =>{
|
export const GetPermissPolicyService = (req) =>{
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
for (const key in req) {
|
||||||
|
// 处理值为数组的情况(如多选参数)
|
||||||
|
if (Array.isArray(req[key])) {
|
||||||
|
req[key].forEach(value => {
|
||||||
|
params.append(key, value); // 数组参数会以 key=val1&key=val2 形式拼接
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
params.append(key, req[key]); // 普通键值对
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let url = `/permission/get_policy?${params.toString()}`;
|
||||||
let token = localStorage.getItem("token") || "";
|
let token = localStorage.getItem("token") || "";
|
||||||
return request.get('/permission/get_policy',
|
return request.get(url,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'token': token, //token
|
'token': token, //token
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,16 @@
|
||||||
:placeholder="item.placeholder" clearable :multiple="item.multiple?true:false" filterable :allow-create="item.allowcreate?true:false" >
|
:placeholder="item.placeholder" clearable :multiple="item.multiple?true:false" filterable :allow-create="item.allowcreate?true:false" >
|
||||||
<el-option v-for="opt in item.opts" :label="opt.label" :value="opt.value"></el-option>
|
<el-option v-for="opt in item.opts" :label="opt.label" :value="opt.value"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
|
|
||||||
|
<el-switch
|
||||||
|
v-else-if="item.type === 'switch'"
|
||||||
|
v-model="form[item.prop]"
|
||||||
|
:disabled="item.disabled"
|
||||||
|
:active-text="item.activeText"
|
||||||
|
:inactive-text="item.inactiveText"
|
||||||
|
:active-value="item.activeValue ?? true"
|
||||||
|
:inactive-value="item.inactiveValue ?? false"
|
||||||
|
></el-switch>
|
||||||
<el-date-picker v-else-if="item.type === 'date'" type="date" v-model="form[item.prop]"
|
<el-date-picker v-else-if="item.type === 'date'" type="date" v-model="form[item.prop]"
|
||||||
:value-format="item.format"></el-date-picker>
|
:value-format="item.format"></el-date-picker>
|
||||||
<el-switch v-else-if="item.type === 'switch'" v-model="form[item.prop]"
|
<el-switch v-else-if="item.type === 'switch'" v-model="form[item.prop]"
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,18 @@
|
||||||
<div>
|
<div>
|
||||||
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="getData" />
|
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="getData" />
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div
|
||||||
|
v-loading="loading"
|
||||||
|
loading-text="加载中..."
|
||||||
|
style="min-height: 300px;"
|
||||||
|
>
|
||||||
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
||||||
:delFunc="handleDelete" :changePage="changePage" :currentPage="page.index" :editFunc="handleEdit" :refresh="getData">
|
:delFunc="handleDelete" :changePage="changePage" :currentPage="page.index" :editFunc="handleEdit" :refresh="getData">
|
||||||
<template #toolbarBtn>
|
<template #toolbarBtn>
|
||||||
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true">新增</el-button>
|
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true">新增</el-button>
|
||||||
</template>
|
</template>
|
||||||
</TableCustom>
|
</TableCustom>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<el-dialog :title="isEdit ? '编辑': '编辑'" v-model="visible" width="700px" destroy-on-close
|
<el-dialog :title="isEdit ? '编辑': '编辑'" v-model="visible" width="700px" destroy-on-close
|
||||||
|
|
@ -105,7 +111,9 @@ const getData = async () => {
|
||||||
value: modelResult.data[i].ID
|
value: modelResult.data[i].ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
loading.value = true;
|
||||||
let result = await FindFunctionService(req);
|
let result = await FindFunctionService(req);
|
||||||
|
loading.value = false;
|
||||||
page.total = result.data.length;
|
page.total = result.data.length;
|
||||||
page.index = 1;
|
page.index = 1;
|
||||||
allData.value = result.data;
|
allData.value = result.data;
|
||||||
|
|
@ -121,6 +129,7 @@ const getData = async () => {
|
||||||
tableData.value = result.data.slice(start, end);
|
tableData.value = result.data.slice(start, end);
|
||||||
};
|
};
|
||||||
getData();
|
getData();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
const changePage = (val: number) => {
|
const changePage = (val: number) => {
|
||||||
page.index = val;
|
page.index = val;
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,19 @@
|
||||||
<div>
|
<div>
|
||||||
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="GetPermissPolicy" />
|
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="GetPermissPolicy" />
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div
|
||||||
|
v-loading="loading"
|
||||||
|
loading-text="加载中..."
|
||||||
|
style="min-height: 300px;"
|
||||||
|
>
|
||||||
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
||||||
:delFunc="handleDelete" :changePage="changePage" :currentPage="page.index" :editFunc="handleEdit" :refresh="GetPermissPolicy">
|
:delFunc="handleDelete" :changePage="changePage" :currentPage="page.index" :editFunc="handleEdit" :refresh="GetPermissPolicy">
|
||||||
<template #toolbarBtn>
|
<template #toolbarBtn>
|
||||||
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true">新增</el-button>
|
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true">新增</el-button>
|
||||||
|
<el-button type="primary" :icon="Search" @click="get_user_permission_policy_visible = true">权限策略检测</el-button>
|
||||||
</template>
|
</template>
|
||||||
</TableCustom>
|
</TableCustom>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<el-dialog :title="isEdit ? '编辑': '编辑'" v-model="visible" width="700px" destroy-on-close
|
<el-dialog :title="isEdit ? '编辑': '编辑'" v-model="visible" width="700px" destroy-on-close
|
||||||
|
|
@ -22,17 +29,29 @@
|
||||||
<TableDetail :data="viewData"></TableDetail>
|
<TableDetail :data="viewData"></TableDetail>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<el-dialog title="策略匹配检测" v-model="get_user_permission_policy_visible" width="700px" destroy-on-close>
|
||||||
|
<el-input v-model="permiss_policy_check_req" placeholder="请输入用户ID或用户名" style="width: 50%;"></el-input>
|
||||||
|
<el-button type="warning" :icon="Search" @click="GetOnePermissPolicy">权限策略检测</el-button>
|
||||||
|
<div>
|
||||||
|
<!-- 显示检测结果 -->
|
||||||
|
<div v-if="permiss_policy_check_res.ID">
|
||||||
|
<p>匹配到的权限策略:{{ permiss_policy_check_res.name }}</p>
|
||||||
|
<p>描述信息:{{ permiss_policy_check_res.info }}</p>
|
||||||
|
<p>Redis权限:{{ permiss_policy_check_res.redis>0 ? '有' : '无' }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
//获取query参数
|
//获取query参数
|
||||||
import { onMounted,ref, reactive } from 'vue';
|
import { onMounted,ref, reactive } from 'vue';
|
||||||
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
import { CirclePlusFilled,Search } from '@element-plus/icons-vue';
|
||||||
import {PermissPolicyResponseData, PolicyUserRange} from '@/types/permiss_policy';
|
import {PermissPolicyResponseData, PolicyUserRange} from '@/types/permiss_policy';
|
||||||
import {GetPermissPolicyService, DelPermissPolicyService, UpdatePermissPolicyService, AddPermissPolicyService} from '@/api/permiss_policy';
|
import {GetPermissPolicyService, DelPermissPolicyService, UpdatePermissPolicyService, AddPermissPolicyService} from '@/api/permiss_policy';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
import { all } from 'axios';
|
|
||||||
import { t } from '@wangeditor/editor';
|
|
||||||
|
|
||||||
const tableData = ref<PolicyUserRange[]>([]);
|
const tableData = ref<PolicyUserRange[]>([]);
|
||||||
const allData = ref<PolicyUserRange[]>([]);
|
const allData = ref<PolicyUserRange[]>([]);
|
||||||
|
|
@ -41,6 +60,11 @@ const visible_add = ref(false);
|
||||||
const isEdit = ref(false);
|
const isEdit = ref(false);
|
||||||
const isAdd = ref(false);
|
const isAdd = ref(false);
|
||||||
const rowData = ref<PolicyUserRange>({} as PolicyUserRange);
|
const rowData = ref<PolicyUserRange>({} as PolicyUserRange);
|
||||||
|
const user_select_opts = ref([]);
|
||||||
|
const get_user_permission_policy_visible = ref(false);
|
||||||
|
const permiss_policy_check_req = ref("");
|
||||||
|
const permiss_policy_check_res = ref<PolicyUserRange>({} as PolicyUserRange);
|
||||||
|
const loading = ref(false);
|
||||||
// 查询相关
|
// 查询相关
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
|
|
@ -125,13 +149,65 @@ const handleDeletePermissPolicy = async () => {
|
||||||
console.error('删除权限策略失败:', error);
|
console.error('删除权限策略失败:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const GetPermissPolicy = async () => {
|
const GetOnePermissPolicy = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await GetPermissPolicyService();
|
let req={
|
||||||
|
type: 1,
|
||||||
|
user_id: 0,
|
||||||
|
user_name: ""
|
||||||
|
}
|
||||||
|
if (isNaN(Number(permiss_policy_check_req.value))) {
|
||||||
|
req.user_name = permiss_policy_check_req.value;
|
||||||
|
} else {
|
||||||
|
req.user_id = parseInt(permiss_policy_check_req.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await GetPermissPolicyService(req);
|
||||||
if (response['code'] !== 0) {
|
if (response['code'] !== 0) {
|
||||||
console.error('获取权限策略失败:', response["message"]);
|
console.error('获取权限策略失败:', response["message"]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// allData.value = response.data;
|
||||||
|
let temp: PermissPolicyResponseData = response.data;
|
||||||
|
let temp_ :PolicyUserRange = {
|
||||||
|
ID: temp.policy.ID,
|
||||||
|
CreatedAt: temp.policy.CreatedAt,
|
||||||
|
UpdatedAt: temp.policy.UpdatedAt,
|
||||||
|
DeletedAt: temp.policy.DeletedAt,
|
||||||
|
name: temp.policy.name,
|
||||||
|
info: temp.policy.info,
|
||||||
|
redis: temp.policy.redis, // Redis 相关权限
|
||||||
|
run_shell: temp.policy.run_shell, // 运行 Shell 相关权限
|
||||||
|
upload: temp.policy.upload, // 上传相关权限
|
||||||
|
cid: temp.policy.cid, // 同上
|
||||||
|
file: temp.policy.file, // 同上
|
||||||
|
device: temp.policy.device, // 设备相关权限
|
||||||
|
upload_size: temp.policy.upload_size, // 同上
|
||||||
|
upload_max_size: temp.policy.upload_max_size, // 同上
|
||||||
|
send_mail: temp.policy.send_mail, // 发送邮件相关权限
|
||||||
|
range: temp.range,
|
||||||
|
};
|
||||||
|
permiss_policy_check_res.value = temp_;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取权限策略失败:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const sleep = (ms: number): Promise<void> => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, ms);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const GetPermissPolicy = async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
const response = await GetPermissPolicyService({});
|
||||||
|
if (response['code'] !== 0) {
|
||||||
|
console.error('获取权限策略失败:', response["message"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await sleep(100);
|
||||||
|
|
||||||
// allData.value = response.data;
|
// allData.value = response.data;
|
||||||
allData.value = [];
|
allData.value = [];
|
||||||
for (let i = 0; i < response.data.length; i++) {
|
for (let i = 0; i < response.data.length; i++) {
|
||||||
|
|
@ -169,8 +245,10 @@ const GetPermissPolicy = async () => {
|
||||||
}
|
}
|
||||||
tableData.value = allData.value.slice(start, end);
|
tableData.value = allData.value.slice(start, end);
|
||||||
console.log("allData:", allData.value);
|
console.log("allData:", allData.value);
|
||||||
|
loading.value = false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取权限策略失败:', error);
|
console.error('获取权限策略失败:', error);
|
||||||
|
loading.value = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleEdit = async (row: PolicyUserRange) => {
|
const handleEdit = async (row: PolicyUserRange) => {
|
||||||
|
|
@ -182,28 +260,18 @@ const handleEdit = async (row: PolicyUserRange) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const addData = async (data) => {
|
const addData = async (data) => {
|
||||||
let model_id =[]
|
console.log("add_data:", data);
|
||||||
console.log("model update:",data)
|
|
||||||
let model_id_list= data["ModelIDS"]
|
|
||||||
for (let i = 0; i < model_id_list.length; i++) {
|
|
||||||
model_id.push({"id":model_id_list[i]})
|
|
||||||
}
|
|
||||||
let model_ids = JSON.stringify(model_id)
|
|
||||||
let result ={}
|
let result ={}
|
||||||
try{
|
try{
|
||||||
let req={
|
let req={
|
||||||
token:localStorage.getItem("token"),
|
policy_name: data.name,
|
||||||
name: data.Name,
|
policy_info: data.info
|
||||||
model_id: model_id_list[0],
|
|
||||||
model_ids: model_ids,
|
|
||||||
function: data.Function,
|
|
||||||
info: data.Info
|
|
||||||
}
|
}
|
||||||
result = await AddPermissPolicyService(req);
|
result = await AddPermissPolicyService(req);
|
||||||
if (result['code'] === 0) {
|
if (result['code'] === 0) {
|
||||||
ElMessage.success("新增成功");
|
ElMessage.success("新增成功");
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error("新增失败");
|
ElMessage.error("新增失败:"+result['message']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(e){
|
}catch(e){
|
||||||
|
|
@ -273,8 +341,14 @@ let options = ref<FormOption>({
|
||||||
labelWidth: '100px',
|
labelWidth: '100px',
|
||||||
span: 12,
|
span: 12,
|
||||||
list: [
|
list: [
|
||||||
{ type: 'input', label: '名称', prop: 'Name', required: true },
|
{ type: 'input', label: '名称', prop: 'name', required: true },
|
||||||
{ type: 'input', label: '描述', prop: 'Info', required: true },
|
{ type: 'input', label: '描述', prop: 'info', required: true },
|
||||||
|
{ type: 'select', label: '生效范围', prop: 'range', required: true, opts:user_select_opts.value ,multiple: true},
|
||||||
|
{ type: 'switch', label: 'Redis权限', prop: 'redis', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '运行Shell权限', prop: 'run_shell', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '上传权限', prop: 'upload', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '设备权限', prop: 'device', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '发送邮件权限', prop: 'send_mail', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -283,8 +357,14 @@ let options_edit = ref<FormOption>({
|
||||||
labelWidth: '100px',
|
labelWidth: '100px',
|
||||||
span: 12,
|
span: 12,
|
||||||
list: [
|
list: [
|
||||||
{ type: 'input', label: '名称', prop: 'Name', required: true },
|
{ type: 'input', label: '名称', prop: 'name', required: true },
|
||||||
{ type: 'input', label: '描述', prop: 'Info', required: true },
|
{ type: 'input', label: '描述', prop: 'info', required: true },
|
||||||
|
{ type: 'select', label: '生效范围', prop: 'range', required: true, opts:user_select_opts.value ,multiple: true},
|
||||||
|
{ type: 'switch', label: 'Redis权限', prop: 'redis', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '运行Shell权限', prop: 'run_shell', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '上传权限', prop: 'upload', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '设备权限', prop: 'device', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '发送邮件权限', prop: 'send_mail', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -296,11 +376,11 @@ const handleView =async (row: Function) => {
|
||||||
label: '权限策略ID',
|
label: '权限策略ID',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'Name',
|
prop: 'name',
|
||||||
label: '名称',
|
label: '名称',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'Info',
|
prop: 'info',
|
||||||
label: '描述',
|
label: '描述',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue