Compare commits
3 Commits
7779eaebcd
...
dcabee0975
| Author | SHA1 | Date |
|---|---|---|
|
|
dcabee0975 | |
|
|
65ccac0240 | |
|
|
d19122f54f |
|
|
@ -69,6 +69,7 @@ declare module '@vue/runtime-core' {
|
||||||
ElTour: typeof import('element-plus/es')['ElTour']
|
ElTour: typeof import('element-plus/es')['ElTour']
|
||||||
ElTourStep: typeof import('element-plus/es')['ElTourStep']
|
ElTourStep: typeof import('element-plus/es')['ElTourStep']
|
||||||
ElTransfer: typeof import('element-plus/es')['ElTransfer']
|
ElTransfer: typeof import('element-plus/es')['ElTransfer']
|
||||||
|
ElTreeV2: typeof import('element-plus/es')['ElTreeV2']
|
||||||
ElUpload: typeof import('element-plus/es')['ElUpload']
|
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||||
ElWatermark: typeof import('element-plus/es')['ElWatermark']
|
ElWatermark: typeof import('element-plus/es')['ElWatermark']
|
||||||
Header: typeof import('./src/components/header.vue')['default']
|
Header: typeof import('./src/components/header.vue')['default']
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
import request from '@/utils/user_center_request';
|
||||||
|
|
||||||
|
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") || "";
|
||||||
|
return request.get(url,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'token': token, //token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const UpdatePermissPolicyService = (Data: any) => {
|
||||||
|
// 将 Data 转换为 JSON 字符串
|
||||||
|
const jsonData = JSON.stringify(Data);
|
||||||
|
const token = localStorage.getItem("token") || "";
|
||||||
|
|
||||||
|
return request.post('/permission/update_policy', jsonData, {
|
||||||
|
headers: {
|
||||||
|
'token': token,
|
||||||
|
'Content-Type': 'application/json' // 必须指定 JSON 格式的 Content-Type
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const AddPermissPolicyService = (Data: any) => {
|
||||||
|
const jsonData = JSON.stringify(Data);
|
||||||
|
const token = localStorage.getItem("token") || "";
|
||||||
|
return request.post('/permission/add_policy', jsonData,{
|
||||||
|
headers: {
|
||||||
|
'token': token, //token
|
||||||
|
'Content-Type': 'application/json' // 必须指定 JSON 格式的 Content-Type
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DelPermissPolicyService = (Data: any) => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
for (let key in Data) {
|
||||||
|
params.append(key, Data[key])
|
||||||
|
}
|
||||||
|
let token = localStorage.getItem("token") || "";
|
||||||
|
return request.post('/permission/del_policy', params,{
|
||||||
|
headers: {
|
||||||
|
'token': token, //token
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -59,6 +59,10 @@ export const getUUIDService = (registerData) => {
|
||||||
return request.post('/user/uuid', params)
|
return request.post('/user/uuid', params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getAllDefaultUsers = () => {
|
||||||
|
return request.get('/user/get_all_default_users')
|
||||||
|
}
|
||||||
|
|
||||||
export const addGroupRequestService = (Data) => {
|
export const addGroupRequestService = (Data) => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
for (let key in Data) {
|
for (let key in Data) {
|
||||||
|
|
@ -66,7 +70,20 @@ export const addGroupRequestService = (Data) => {
|
||||||
}
|
}
|
||||||
return request.post('/im/send_message', params,{
|
return request.post('/im/send_message', params,{
|
||||||
headers: {
|
headers: {
|
||||||
'token': Data.token, // 闂佽绻愭蹇涘箯閿燂拷 token 闂備礁鎼ú锔锯偓绗涘啰鏆﹂柛娆忣槺閳绘棃鏌i幋鐏活亝绂嶉崼鏇熺厽闁靛ǹ鍎遍褔鏌熼煬鎻掆偓婵嬪箖瑜忔禒锔炬喆閿濆懍澹曢梺璺ㄥ櫐閹凤拷
|
'token': Data.token,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AdminAddUserRequestService = (Data) => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
for (let key in Data) {
|
||||||
|
params.append(key, Data[key])
|
||||||
|
}
|
||||||
|
let token = localStorage.getItem("token") || "";
|
||||||
|
return request.post('/user/admin_add_user', params,{
|
||||||
|
headers: {
|
||||||
|
'token': token,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ export const menuData: Menus[] = [
|
||||||
title: '功能管理',
|
title: '功能管理',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: '73',
|
||||||
|
pid: '1',
|
||||||
|
index: '/manage-permiss-policy',
|
||||||
|
title: '权限策略管理',
|
||||||
|
}
|
||||||
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
@ -208,12 +214,12 @@ export const menuData: Menus[] = [
|
||||||
index: '/ucenter',
|
index: '/ucenter',
|
||||||
title: '个人中心',
|
title: '个人中心',
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
id: '9',
|
// id: '9',
|
||||||
icon: 'Files',
|
// icon: 'Files',
|
||||||
index: '/kbase-chat',
|
// index: '/kbase-chat',
|
||||||
title: '知识库交互',
|
// title: '知识库交互',
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
id: '53',
|
id: '53',
|
||||||
icon: 'ChatDotSquare',
|
icon: 'ChatDotSquare',
|
||||||
|
|
@ -226,12 +232,12 @@ export const menuData: Menus[] = [
|
||||||
index: '/gen-prompt',
|
index: '/gen-prompt',
|
||||||
title: '提示词生成',
|
title: '提示词生成',
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
id: '57',
|
// id: '57',
|
||||||
icon: 'ChatDotSquare',
|
// icon: 'ChatDotSquare',
|
||||||
index: '/ai-ppt',
|
// index: '/ai-ppt',
|
||||||
title: '智能PPT生成',
|
// title: '智能PPT生成',
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
id: '59',
|
id: '59',
|
||||||
icon: 'Select',
|
icon: 'Select',
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,23 @@
|
||||||
<el-form-item :label="item.label" :prop="item.prop">
|
<el-form-item :label="item.label" :prop="item.prop">
|
||||||
<!-- 文本框、数字框、下拉框、日期框、开关、上传 -->
|
<!-- 文本框、数字框、下拉框、日期框、开关、上传 -->
|
||||||
<el-input v-if="item.type === 'input'" v-model="form[item.prop]" :disabled="item.disabled"
|
<el-input v-if="item.type === 'input'" v-model="form[item.prop]" :disabled="item.disabled"
|
||||||
:placeholder="item.placeholder" clearable type="textarea" :row="item.rows?item.rows:1"></el-input>
|
:placeholder="item.placeholder" clearable :row="item.rows?item.rows:1"></el-input>
|
||||||
<el-input-number v-else-if="item.type === 'number'" v-model="form[item.prop]"
|
<el-input-number v-else-if="item.type === 'number'" v-model="form[item.prop]"
|
||||||
:disabled="item.disabled" controls-position="right"></el-input-number>
|
:disabled="item.disabled" controls-position="right"></el-input-number>
|
||||||
<el-select v-else-if="item.type === 'select'" v-model="form[item.prop]" :disabled="item.disabled"
|
<el-select v-else-if="item.type === 'select'" v-model="form[item.prop]" :disabled="item.disabled"
|
||||||
: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="1"
|
||||||
|
:inactive-value="-1"
|
||||||
|
></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]"
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,16 @@ const routes: RouteRecordRaw[] = [
|
||||||
},
|
},
|
||||||
component: () => import(/* webpackChunkName: "system-user" */ '../views/system/manage-file.vue'),
|
component: () => import(/* webpackChunkName: "system-user" */ '../views/system/manage-file.vue'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/manage-permiss-policy',
|
||||||
|
name: 'manage-permiss-policy',
|
||||||
|
meta: {
|
||||||
|
title: '权限策略管理',
|
||||||
|
permiss: '73',
|
||||||
|
},
|
||||||
|
component: () => import(/* webpackChunkName: "system-user" */ '../views/system/manage-permiss-policy.vue'),
|
||||||
|
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/manage-session',
|
path: '/manage-session',
|
||||||
name: 'manage-session',
|
name: 'manage-session',
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ export const usePermissStore = defineStore("permiss", {
|
||||||
"58", //知识库管理
|
"58", //知识库管理
|
||||||
"59", //项目选择
|
"59", //项目选择
|
||||||
"71", //用户功能管理
|
"71", //用户功能管理
|
||||||
"72" //数据库管理工具
|
"72", //数据库管理工具
|
||||||
|
"73", //权限策略管理
|
||||||
],
|
],
|
||||||
user: ["0", "8", "7", "9", "51" ,"53","55" ,"56", "57", "58", "59", "61", "71"],
|
user: ["0", "8", "7", "9", "51" ,"53","55" ,"56", "57", "58", "59", "61", "71"],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,5 @@ export interface FormOptionList {
|
||||||
activeText?: string;
|
activeText?: string;
|
||||||
inactiveText?: string;
|
inactiveText?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
is_textarea?: boolean;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
// 策略信息结构体
|
||||||
|
export interface Policy {
|
||||||
|
ID: number;
|
||||||
|
CreatedAt: string; // 日期时间格式,如 "2025-11-03T20:09:59.455+08:00"
|
||||||
|
UpdatedAt: string; // 日期时间格式
|
||||||
|
DeletedAt: null | string; // 可能为 null 或日期时间格式
|
||||||
|
name: string;
|
||||||
|
info: string;
|
||||||
|
redis: number; // 0 表示禁用,推测可能为布尔含义的数字
|
||||||
|
run_shell: number; // 同上
|
||||||
|
upload: number; // 同上
|
||||||
|
cid: number;
|
||||||
|
file: number; // 同上
|
||||||
|
device: number; // 同上
|
||||||
|
upload_size: number; // 上传大小限制
|
||||||
|
upload_max_size: number; // 最大上传大小限制
|
||||||
|
send_mail: number; // 同上
|
||||||
|
}
|
||||||
|
|
||||||
|
// 范围信息结构体
|
||||||
|
export interface Range {
|
||||||
|
id: number;
|
||||||
|
type: number;
|
||||||
|
prev: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 完整响应结构体
|
||||||
|
export interface PermissPolicyResponseData {
|
||||||
|
policy: Policy;
|
||||||
|
range: Range[]; // 范围信息数组
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PolicyUserRange {
|
||||||
|
ID: number;
|
||||||
|
CreatedAt: string; // 日期时间格式,如 "2025-11-03T20:09:59.455+08:00"
|
||||||
|
UpdatedAt: string; // 日期时间格式
|
||||||
|
DeletedAt: null | string; // 可能为 null 或日期时间格式
|
||||||
|
name: string;
|
||||||
|
info: string;
|
||||||
|
redis: number; // 0 表示禁用,推测可能为布尔含义的数字
|
||||||
|
run_shell: number; // 同上
|
||||||
|
upload: number; // 同上
|
||||||
|
cid: number;
|
||||||
|
file: number; // 同上
|
||||||
|
device: number; // 同上
|
||||||
|
upload_size: number; // 上传大小限制
|
||||||
|
upload_max_size: number; // 最大上传大小限制
|
||||||
|
send_mail: number; // 同上
|
||||||
|
range: number[]; // 范围信息数组
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,538 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="GetPermissPolicy" />
|
||||||
|
<div class="container">
|
||||||
|
<div
|
||||||
|
v-loading="loading"
|
||||||
|
loading-text="加载中..."
|
||||||
|
style="min-height: 300px;"
|
||||||
|
>
|
||||||
|
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
||||||
|
:delFunc="handleDelete" :changePage="changePage" :currentPage="page.index" :editFunc="handleEdit" :refresh="GetPermissPolicy">
|
||||||
|
<template #toolbarBtn>
|
||||||
|
<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>
|
||||||
|
</TableCustom>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<el-dialog :title="isEdit ? '编辑': '编辑'" v-model="visible" width="900px" destroy-on-close
|
||||||
|
:close-on-click-modal="false" @close="closeDialog">
|
||||||
|
<TableEdit :form-data="rowData" :options="options_edit" :edit="isEdit" :update="handleUpdatePermissPolicy" />
|
||||||
|
</el-dialog>
|
||||||
|
<el-dialog :title="isAdd ? '新增' : '新增'" v-model="visible_add" width="900px" destroy-on-close
|
||||||
|
:close-on-click-modal="false" @close="closeDialog">
|
||||||
|
<TableEdit :form-data="rowData" :options="options" :edit="isAdd" :update="handleAddPermissPolicy" />
|
||||||
|
</el-dialog>
|
||||||
|
<el-dialog title="查看详情" v-model="visible1" width="700px" destroy-on-close>
|
||||||
|
<TableDetail :data="viewData"></TableDetail>
|
||||||
|
</el-dialog>
|
||||||
|
</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>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
//获取query参数
|
||||||
|
import { onMounted,ref, reactive } from 'vue';
|
||||||
|
import { CirclePlusFilled,Search } from '@element-plus/icons-vue';
|
||||||
|
import {PermissPolicyResponseData, PolicyUserRange} from '@/types/permiss_policy';
|
||||||
|
import {getAllDefaultUsers} from '@/api/user';
|
||||||
|
import {GetPermissPolicyService, DelPermissPolicyService, UpdatePermissPolicyService, AddPermissPolicyService} from '@/api/permiss_policy';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
|
|
||||||
|
const tableData = ref<PolicyUserRange[]>([]);
|
||||||
|
const allData = ref<PolicyUserRange[]>([]);
|
||||||
|
const visible = ref(false);
|
||||||
|
const visible_add = ref(false);
|
||||||
|
const isEdit = ref(false);
|
||||||
|
const isAdd = ref(false);
|
||||||
|
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({
|
||||||
|
name: '',
|
||||||
|
});
|
||||||
|
const page = reactive({
|
||||||
|
index: 1,
|
||||||
|
size: 10,
|
||||||
|
total: 122,
|
||||||
|
});
|
||||||
|
const searchOpt = {};
|
||||||
|
const viewData = ref({
|
||||||
|
row: {},
|
||||||
|
list: [
|
||||||
|
|
||||||
|
]
|
||||||
|
});
|
||||||
|
// 查看详情弹窗相关
|
||||||
|
const visible1 = ref(false);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// 获取query参数
|
||||||
|
GetPermissPolicy();
|
||||||
|
|
||||||
|
});
|
||||||
|
const closeDialog = () => {
|
||||||
|
visible.value = false;
|
||||||
|
visible_add.value = false;
|
||||||
|
isEdit.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleAddPermissPolicy = async (data) => {
|
||||||
|
if (data.upload_size && isNaN(Number(data.upload_size))) {
|
||||||
|
ElMessage.error('单个上传大小必须是数字');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.upload_max_size && isNaN(Number(data.upload_max_size))) {
|
||||||
|
ElMessage.error('总上传大小必须是数字');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 添加权限策略
|
||||||
|
let req = {
|
||||||
|
"policy_name": data.name,
|
||||||
|
"policy_info": data.info,
|
||||||
|
"user_range": [],
|
||||||
|
"redis": data.redis > 0 ? 1 : -1,
|
||||||
|
"run_shell": data.run_shell > 0 ? 1 : -1,
|
||||||
|
"upload": data.upload > 0 ? 1 : -1,
|
||||||
|
"cid": data.cid > 0? 1 : -1,
|
||||||
|
"file": data.file > 0? 1 : -1,
|
||||||
|
"device": data.device > 0 ? 1 : -1,
|
||||||
|
"upload_size": data.upload_size > 0 ? parseInt(data.upload_size) : 0,
|
||||||
|
"upload_max_size": data.upload_max_size > 0 ? parseInt(data.upload_max_size) : 0,
|
||||||
|
"send_mail": data.send_mail > 0 ? 1 : -1,
|
||||||
|
};
|
||||||
|
for(let i=0;i<data.range.length;i++){
|
||||||
|
req.user_range.push({"id":data.range[i]});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await AddPermissPolicyService(req);
|
||||||
|
if (response['code'] !== 0) {
|
||||||
|
ElMessage.error('添加权限策略失败:' + response["message"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ElMessage.success('添加权限策略成功');
|
||||||
|
visible_add.value = false;
|
||||||
|
GetPermissPolicy();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取权限策略失败:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const GetAllDefaultUsers = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getAllDefaultUsers();
|
||||||
|
if (response['code'] !== 0) {
|
||||||
|
console.error('获取默认用户失败:', response["message"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
user_select_opts.value.length = 0;
|
||||||
|
for (let i = 0; i < response.data.length; i++) {
|
||||||
|
let user = response.data[i];
|
||||||
|
console.log("user:", user);
|
||||||
|
user_select_opts.value.push({
|
||||||
|
value: user.id,
|
||||||
|
label: (user.type === 0 ? "user":"group" )+ ":"+user.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.log("user_select_opts:", user_select_opts.value);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取默认用户失败:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GetAllDefaultUsers();
|
||||||
|
|
||||||
|
const handleUpdatePermissPolicy = async (data) => {
|
||||||
|
// 更新权限策略
|
||||||
|
let req = {
|
||||||
|
"id": data.ID,
|
||||||
|
"policy_name": data.name,
|
||||||
|
"policy_info": data.info,
|
||||||
|
"user_range": [],
|
||||||
|
"redis": data.redis > 0 ? 1 : -1,
|
||||||
|
"run_shell": data.run_shell > 0 ? 1 : -1,
|
||||||
|
"upload": data.upload > 0 ? 1 : -1,
|
||||||
|
"cid": data.cid > 0? 1 : -1,
|
||||||
|
"file": data.file > 0? 1 : -1,
|
||||||
|
"device": data.device > 0 ? 1 : -1,
|
||||||
|
"upload_size": 0,
|
||||||
|
"upload_max_size": 0,
|
||||||
|
"send_mail": data.send_mail > 0 ? 1 : -1,
|
||||||
|
};
|
||||||
|
//upload_size和upload_max_size必须是数字
|
||||||
|
if (data.upload_size > 0) {
|
||||||
|
req.upload_size = parseInt(data.upload_size);
|
||||||
|
}
|
||||||
|
if (data.upload_max_size > 0) {
|
||||||
|
req.upload_max_size = parseInt(data.upload_max_size);
|
||||||
|
}
|
||||||
|
for(let i=0;i<data.range.length;i++){
|
||||||
|
req.user_range.push({"id":data.range[i]});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await UpdatePermissPolicyService(req);
|
||||||
|
if (response['code'] !== 0) {
|
||||||
|
ElMessage.error('更新权限策略失败:' + response["message"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ElMessage.success('更新权限策略成功');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新权限策略失败:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
const handleDeletePermissPolicy = async () => {
|
||||||
|
// 删除权限策略
|
||||||
|
let req = {
|
||||||
|
"id": 1,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await DelPermissPolicyService(req);
|
||||||
|
if (response['code'] !== 0) {
|
||||||
|
ElMessage.error('删除权限策略失败:' + response["message"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ElMessage.success('删除权限策略成功');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除权限策略失败:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const GetOnePermissPolicy = async () => {
|
||||||
|
try {
|
||||||
|
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) {
|
||||||
|
console.error('获取权限策略失败:', response["message"]);
|
||||||
|
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.map(item => item.id),
|
||||||
|
};
|
||||||
|
permiss_policy_check_res.value = temp_;
|
||||||
|
|
||||||
|
console.log("alldata 1:", addData[0])
|
||||||
|
|
||||||
|
} 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 = [];
|
||||||
|
for (let i = 0; i < response.data.length; i++) {
|
||||||
|
let temp: PermissPolicyResponseData = response.data[i];
|
||||||
|
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.map(item => item.id),
|
||||||
|
};
|
||||||
|
allData.value.push(temp_);
|
||||||
|
}
|
||||||
|
page.total = allData.value.length;
|
||||||
|
page.index = 1;
|
||||||
|
// 分页
|
||||||
|
let start = (page.index - 1) * page.size;
|
||||||
|
let end = start + page.size;
|
||||||
|
if (end > page.total) {
|
||||||
|
end = page.total;
|
||||||
|
}
|
||||||
|
if (start > page.total) {
|
||||||
|
start = page.total;
|
||||||
|
}
|
||||||
|
tableData.value = allData.value.slice(start, end);
|
||||||
|
console.log("allData:", allData.value);
|
||||||
|
loading.value = false;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取权限策略失败:', error);
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const handleEdit = async (row) => {
|
||||||
|
let data = row;
|
||||||
|
console.log("edit_row_data:", data);
|
||||||
|
rowData.value = data;
|
||||||
|
isEdit.value = true;
|
||||||
|
visible.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const addData = async (data) => {
|
||||||
|
console.log("add_data:", data);
|
||||||
|
let result ={}
|
||||||
|
try{
|
||||||
|
let req={
|
||||||
|
policy_name: data.name,
|
||||||
|
policy_info: data.info
|
||||||
|
}
|
||||||
|
result = await AddPermissPolicyService(req);
|
||||||
|
if (result['code'] === 0) {
|
||||||
|
ElMessage.success("新增成功");
|
||||||
|
} else {
|
||||||
|
ElMessage.error("新增失败:"+result['message']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(e){
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
closeDialog();
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateData = async (data) => {
|
||||||
|
|
||||||
|
let result ={}
|
||||||
|
try{
|
||||||
|
let req={
|
||||||
|
token:localStorage.getItem("token"),
|
||||||
|
id: data.ID,
|
||||||
|
};
|
||||||
|
result = await UpdatePermissPolicyService(req);
|
||||||
|
if (result['code'] === 0) {
|
||||||
|
ElMessage.success("更新成功");
|
||||||
|
} else {
|
||||||
|
ElMessage.error("更新失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(e){
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
closeDialog();
|
||||||
|
};
|
||||||
|
const handleSearch = async () => {
|
||||||
|
// query.name是否是数字
|
||||||
|
if (isNaN(Number(query.name))) {
|
||||||
|
ElMessage.error('请输入数字');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let req={
|
||||||
|
token: localStorage.getItem('token'),
|
||||||
|
type: "ID",
|
||||||
|
id: parseInt(query.name) || 1
|
||||||
|
}
|
||||||
|
await GetPermissPolicy();
|
||||||
|
page.total = allData.value.length;
|
||||||
|
page.index = 1;
|
||||||
|
// 分页
|
||||||
|
let start = (page.index - 1) * page.size;
|
||||||
|
let end = start + page.size;
|
||||||
|
if (end > page.total) {
|
||||||
|
end = page.total;
|
||||||
|
}
|
||||||
|
if (start > page.total) {
|
||||||
|
start = page.total;
|
||||||
|
}
|
||||||
|
tableData.value = allData.value.slice(start, end);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表格相关
|
||||||
|
let columns = ref([
|
||||||
|
// { type: 'index', label: '序号', width: 55, align: 'center' },
|
||||||
|
{ prop: 'ID', label: '权限策略ID' },
|
||||||
|
{prop: 'name', label: '名称'},
|
||||||
|
{ prop: 'info', label: '描述信息' },
|
||||||
|
{ prop: 'CreatedAt', label: '创建时间',type: 'date' },
|
||||||
|
{ prop: 'operator', label: '操作', width: 250 , operate: { view: true, edit: true, delete: true,push: {link: false,label:"继续该会话"},gen: {show: false,label:"下载文件"}, genv2:{type:"", label:"", show:false} }},
|
||||||
|
])
|
||||||
|
|
||||||
|
// 新增弹窗
|
||||||
|
let options = ref<FormOption>({
|
||||||
|
labelWidth: '100px',
|
||||||
|
span: 12,
|
||||||
|
list: [
|
||||||
|
{ type: 'input', label: '名称', prop: 'name', required: true },
|
||||||
|
{ type: 'input', label: '描述', prop: 'info', required: true },
|
||||||
|
{ type: 'input', label: '单个上传大小', prop: 'upload_size', required: true, is_textarea: false },
|
||||||
|
{ type: 'input', label: '总上传大小', prop: 'upload_max_size', required: true, is_textarea: false },
|
||||||
|
{ 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: '关闭' },
|
||||||
|
{ type: 'switch', label: 'CID权限', prop: 'cid', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '文件管理权限', prop: 'file', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
//编辑弹窗
|
||||||
|
let options_edit = ref<FormOption>({
|
||||||
|
labelWidth: '100px',
|
||||||
|
span: 12,
|
||||||
|
list: [
|
||||||
|
{ type: 'input', label: '名称', prop: 'name', required: true },
|
||||||
|
{ type: 'input', label: '描述', prop: 'info', required: true },
|
||||||
|
{ type: 'input', label: '单个上传大小', prop: 'upload_size', required: true },
|
||||||
|
{ type: 'input', label: '总上传大小', prop: 'upload_max_size', 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: '关闭' },
|
||||||
|
{ type: 'switch', label: 'CID权限', prop: 'cid', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
{ type: 'switch', label: '文件管理权限', prop: 'file', required: false, activeText: '开启', inactiveText: '关闭' },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleView =async (row) => {
|
||||||
|
viewData.value.row = row;
|
||||||
|
viewData.value.list = [
|
||||||
|
{
|
||||||
|
prop: 'ID',
|
||||||
|
label: '权限策略ID',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'name',
|
||||||
|
label: '名称',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'info',
|
||||||
|
label: '描述',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'redis',
|
||||||
|
label: 'Redis权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'run_shell',
|
||||||
|
label: '运行Shell权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'upload',
|
||||||
|
label: '上传权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'device',
|
||||||
|
label: '设备权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'send_mail',
|
||||||
|
label: '发送邮件权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'cid',
|
||||||
|
label: 'CID权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'file',
|
||||||
|
label: '文件管理权限',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'CreatedAt',
|
||||||
|
label: '创建时间',
|
||||||
|
type: 'date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'UpdatedAt',
|
||||||
|
label: '更新时间',
|
||||||
|
type: 'date'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
visible1.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 删除相关
|
||||||
|
const handleDelete = async (row) => {
|
||||||
|
let req={
|
||||||
|
id: row.ID,
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
let result = await DelPermissPolicyService(req);
|
||||||
|
if(result['code'] === 0){
|
||||||
|
ElMessage.success("删除成功");
|
||||||
|
GetPermissPolicy();
|
||||||
|
}else{
|
||||||
|
ElMessage.error("删除失败");
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const changePage = (val: number) => {
|
||||||
|
page.index = val;
|
||||||
|
//分页
|
||||||
|
let start = (page.index - 1) * page.size;
|
||||||
|
let end = start + page.size;
|
||||||
|
if (end > page.total) {
|
||||||
|
end = page.total;
|
||||||
|
}
|
||||||
|
if (start > page.total) {
|
||||||
|
start = page.total;
|
||||||
|
}
|
||||||
|
tableData.value = allData.value.slice(start, end);
|
||||||
|
};
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
@ -4,9 +4,10 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<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">
|
:delFunc="handleDelete" :changePage="changePage" :currentPage="page.index" :editFunc="handleEdit">
|
||||||
<!-- <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> -->
|
<el-button type="primary" @click="visible_system = true">查看组织架构</el-button>
|
||||||
|
</template>
|
||||||
</TableCustom>
|
</TableCustom>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -14,13 +15,26 @@
|
||||||
:close-on-click-modal="false" @close="closeDialog">
|
:close-on-click-modal="false" @close="closeDialog">
|
||||||
<TableEdit :form-data="rowData" :options="options_edit" :edit="isEdit" :update="updateData" />
|
<TableEdit :form-data="rowData" :options="options_edit" :edit="isEdit" :update="updateData" />
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
<!-- <el-dialog :title="isAdd ? '新增' : '新增'" v-model="visible_add" width="700px" destroy-on-close
|
<el-dialog :title="isAdd ? '新增' : '新增'" v-model="visible_add" width="700px" destroy-on-close
|
||||||
:close-on-click-modal="false" @close="closeDialog">
|
:close-on-click-modal="false" @close="closeDialog">
|
||||||
<TableEdit :form-data="rowData" :options="options" :edit="isAdd" :update="addData" />
|
<TableEdit :form-data="rowData" :options="options" :edit="isAdd" :update="addData" />
|
||||||
</el-dialog> -->
|
</el-dialog>
|
||||||
<el-dialog title="查看详情" v-model="visible1" width="700px" destroy-on-close>
|
<el-dialog title="查看详情" v-model="visible1" width="700px" destroy-on-close>
|
||||||
<TableDetail :data="viewData"></TableDetail>
|
<TableDetail :data="viewData"></TableDetail>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
||||||
|
<el-dialog title="组织架构" v-model="visible_system" width="700px" destroy-on-close>
|
||||||
|
<div>
|
||||||
|
<el-tree-v2
|
||||||
|
ref="treeRef"
|
||||||
|
style="max-width: 300px"
|
||||||
|
:data="treeData"
|
||||||
|
:props="treeProps"
|
||||||
|
:filter-method="filterMethod"
|
||||||
|
:height="200"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -30,18 +44,71 @@ import { ElMessage } from 'element-plus';
|
||||||
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
||||||
import { UserInfo } from '@/types/user';
|
import { UserInfo } from '@/types/user';
|
||||||
import { fetchUserData } from '@/api';
|
import { fetchUserData } from '@/api';
|
||||||
import { SearchUserService } from "@/api/user";
|
import { SearchUserService,AdminAddUserRequestService } from "@/api/user";
|
||||||
import {GetUserInfoService} from "@/api/user";
|
import {GetUserInfoService} from "@/api/user";
|
||||||
import {updateUserInfoService} from "@/api/user";
|
import {updateUserInfoService} from "@/api/user";
|
||||||
import TableCustom from '@/components/table-custom.vue';
|
import TableCustom from '@/components/table-custom.vue';
|
||||||
import TableDetail from '@/components/table-detail.vue';
|
import TableDetail from '@/components/table-detail.vue';
|
||||||
import TableSearch from '@/components/table-search.vue';
|
import TableSearch from '@/components/table-search.vue';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
|
import {getAllDefaultUsers} from '@/api/user';
|
||||||
|
|
||||||
|
const treeData = ref([]);
|
||||||
|
const treeProps = ref({
|
||||||
|
id: 'id', // 节点唯一标识字段(对应数据中的 id)
|
||||||
|
label: 'name', // 节点显示文本字段(对应数据中的 name)
|
||||||
|
children: 'children' // 子节点数组字段(转换后会添加 children 字段)
|
||||||
|
});
|
||||||
// 查询相关
|
// 查询相关
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const GetAllDefaultUsers = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getAllDefaultUsers();
|
||||||
|
if (response['code'] !== 0) {
|
||||||
|
console.error('获取默认用户失败:', response["message"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buildTree(response['data']);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取默认用户失败:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GetAllDefaultUsers();
|
||||||
|
|
||||||
|
const buildTree = (data) => {
|
||||||
|
// 1. 用 map 存储所有节点(key 为 id,value 为节点对象),方便快速查找父节点
|
||||||
|
const nodeMap = {};
|
||||||
|
data.forEach(node => {
|
||||||
|
// 为每个节点初始化 children 数组(避免后续添加子节点时 undefined 错误)
|
||||||
|
nodeMap[node.id] = { ...node, children: [] };
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. 遍历所有节点,根据 prev 字段找到父节点,添加到父节点的 children 中
|
||||||
|
const tree = [];
|
||||||
|
Object.values(nodeMap).forEach(node => {
|
||||||
|
const parentId = node["prev"];
|
||||||
|
if (parentId === 0) {
|
||||||
|
// prev 为 0 表示根节点,直接加入树形结构的顶层
|
||||||
|
tree.push(node);
|
||||||
|
} else {
|
||||||
|
// 找到父节点,将当前节点添加到父节点的 children 中
|
||||||
|
const parentNode = nodeMap[parentId];
|
||||||
|
if (parentNode) {
|
||||||
|
parentNode.children.push(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
treeData.value = tree;
|
||||||
|
};
|
||||||
|
|
||||||
|
const filterMethod =(node, value) =>{
|
||||||
|
// node 是当前节点对象,value 是过滤输入的值
|
||||||
|
return node.name.toLowerCase().includes(value.toLowerCase());
|
||||||
|
}
|
||||||
const searchOpt = ref<FormOptionList[]>([
|
const searchOpt = ref<FormOptionList[]>([
|
||||||
{ type: 'input', label: '用户名或ID:', prop: 'name' }
|
{ type: 'input', label: '用户名或ID:', prop: 'name' }
|
||||||
])
|
])
|
||||||
|
|
@ -79,6 +146,8 @@ const handleSearch = async () => {
|
||||||
tableData.value = result.data.slice(start, end);
|
tableData.value = result.data.slice(start, end);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const visible_system = ref(false);
|
||||||
|
|
||||||
// 表格相关
|
// 表格相关
|
||||||
let columns = ref([
|
let columns = ref([
|
||||||
{ type: 'index', label: '序号', width: 55, align: 'center' },
|
{ type: 'index', label: '序号', width: 55, align: 'center' },
|
||||||
|
|
@ -120,6 +189,29 @@ const getData = async () => {
|
||||||
};
|
};
|
||||||
getData();
|
getData();
|
||||||
|
|
||||||
|
const addData = async (data) => {
|
||||||
|
let result ={}
|
||||||
|
try{
|
||||||
|
let req={
|
||||||
|
|
||||||
|
name: data.Name,
|
||||||
|
email: data.Email,
|
||||||
|
password: data.Password,
|
||||||
|
}
|
||||||
|
|
||||||
|
result = await AdminAddUserRequestService(req);
|
||||||
|
if (result["code"] === 0) {
|
||||||
|
ElMessage.success("新增成功");
|
||||||
|
closeDialog();
|
||||||
|
} else {
|
||||||
|
ElMessage.error("新增失败:"+result["message"]);
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
getData();
|
||||||
|
};
|
||||||
|
|
||||||
const changePage = (val: number) => {
|
const changePage = (val: number) => {
|
||||||
page.index = val;
|
page.index = val;
|
||||||
//分页
|
//分页
|
||||||
|
|
@ -142,7 +234,6 @@ let options = ref<FormOption>({
|
||||||
{ type: 'input', label: '用户名', prop: 'Name', required: true },
|
{ type: 'input', label: '用户名', prop: 'Name', required: true },
|
||||||
{ type: 'input', label: '密码', prop: 'Password', required: true },
|
{ type: 'input', label: '密码', prop: 'Password', required: true },
|
||||||
{ type: 'input', label: '邮箱', prop: 'Email', required: true },
|
{ type: 'input', label: '邮箱', prop: 'Email', required: true },
|
||||||
{ type: 'input', label: '角色', prop: 'Role', required: true },
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue