过鱼设施权限-页面逻辑样式更改,接口更改,完善字典数据

This commit is contained in:
王兴凯 2026-04-22 18:04:51 +08:00
parent 6e9b4a4d5b
commit f01e6d926f
4 changed files with 397 additions and 184 deletions

View File

@ -101,6 +101,14 @@ export function changeItemOrder(params:any) {
params: params
});
}
//根据字典编号查询字典项列表
export function getDictItemsByCode(params:any) {
return request({
url: '/system/dictionary/getDictItemsByCode',
method: 'get',
params: params
});
}
/**
*
*

View File

@ -102,6 +102,30 @@ export function updatePassword (queryParams:any) {
params: queryParams,
});
}
//获取过鱼设施权限树
export function getFishtree(queryParams:any) {
return request({
url: '/env/tree/rvcdEng',
method: 'get',
params: queryParams
});
}
//保存权限
export function saveFishqvan(queryParams:any) {
return request({
url: '/data/userDataScope/batchAdd',
method: 'post',
data: queryParams
});
}
//查询用户有效权限
export function getuserdata(queryParams:any) {
return request({
url: '/data/userDataScope/getValidPermissions',
method: 'get',
params: queryParams
});
}
/**
*

View File

@ -15,8 +15,14 @@ import {
addUsers,
updataUser,
setpass,
delChoise
delChoise,
getFishtree,
saveFishqvan,
getuserdata
} from "@/api/user";
import {
getDictItemsByCode
} from "@/api/dict";
import { ElMessageBox, ElMessage } from "element-plus";
import { useAppStore } from '@/store/modules/app';
import Page from '@/components/Pagination/page.vue'
@ -267,6 +273,7 @@ function setpassword(row: any) {
})
})
userid.value = row.id
}
//
@ -281,6 +288,28 @@ function openFishway(row: any) {
//
getFishTree()
// watch
fishhui.value = []
tableDatafish.value = []
getuserdata({ userId: userId.value }).then((res: any) => {
console.log(res)
if (res.code == 0) {
res.data.forEach((item: any) => {
fishhui.value.push(item.orgId)
tableDatafish.value.push({
name: item.orgName,
type: item.orgType, // ''
id: item.orgId.toString(), // 使codeid
code: item.orgId,
path: item.path,
userId: item.userId,
parentId: item.parentId,
orgLevel: item.orgLevel,
permissionType: item.permissionType //
})
})
}
})
}
@ -299,14 +328,28 @@ watch(fishway, (newVal) => {
// ,
setTimeout(() => {
fishTreeRef.value.setCheckedKeys(fishhui.value, false);
//
const checkedKeys = fishTreeRef.value.getCheckedKeys();
const halfCheckedKeys = fishTreeRef.value.getHalfCheckedKeys();
console.log('回显完成 - 全选节点:', checkedKeys);
console.log('回显完成 - 半选节点:', halfCheckedKeys);
}, 100);
} else if (fishTreeRef.value) {
// fishhui.value
setTimeout(() => {
fishTreeRef.value.setCheckedKeys([], false);
fishTableData.value = [];
}, 100);
}
fishTableData.value = tableDatafish.value
// if (fishhui.value.length > 0 && activeName.value == '1') {
// isCompanyDisabled.value = true
// } else if (fishhui.value.length > 0 && activeName.value == '2') {
// isBaseDisabled.value = true
// } else {
// isCompanyDisabled.value = false
// isBaseDisabled.value = false
// }
}, 500);
} else {
//
@ -317,105 +360,65 @@ watch(fishway, (newVal) => {
if (fishTreeRef.value) {
fishTreeRef.value.setCheckedKeys([], false);
}
fishTableData.value = [];
}, 300);
}
});
function fishHandleClose() {
fishway.value = false
fishTableData.value = []
fishData.value = []
}
//type
const activeName = ref('1')
// const activeName = ref('1')
//
const isBaseDisabled = ref(false) //
const isCompanyDisabled = ref(false) //
// const isBaseDisabled = ref(false) //
// const isCompanyDisabled = ref(false) //
const handleClick = (tab: any, event: any) => {
// tab.props.name
console.log(tab.props.name, event)
activeName.value = tab.props.name
treeInput.value = ''
getFishTree()
}
// const handleClick = (tab: any, event: any) => {
// ElMessageBox.confirm(",", "", {
// confirmButtonText: "",
// cancelButtonText: "",
// type: "warning",
// })
// .then(() => {
// fishhui.value = []
// fishTreeDialog.value = true
// console.log(tab.props.name, event)
// activeName.value = tab.props.name
// treeInput.value = ''
// getFishTree()
// })
// .catch(() => {
// //
// });
// }
//
const treeInput = ref('')
const fishProps = {
children: 'children',
label: 'label',
label: 'name',
}
const fishData: Tree[] = [
{
id: 1,
label: 'Level one 1',
children: [
{
id: 4,
label: 'Level two 1-1',
children: [
{
id: 9,
label: 'Level three 1-1-1',
},
{
id: 10,
label: 'Level three 1-1-2',
},
],
},
],
},
{
id: 2,
label: 'Level one 2',
children: [
{
id: 5,
label: 'Level two 2-1',
},
{
id: 6,
label: 'Level two 2-2',
},
],
},
{
id: 3,
label: 'Level one 3',
children: [
{
id: 7,
label: 'Level two 3-1',
},
{
id: 8,
label: 'Level two 3-2',
},
],
},
]
const fishData: any = ref([])
//
// const huixiandata = ref([])
let tableDatafish: any = []
function getFishTree() {
fishTreeDialog.value = true
const params = {
type: activeName.value,
name: treeInput.value
// type:'1',
engName: treeInput.value
}
getFishtree(params).then((res: any) => {
if (res.code == 0) {
fishData.value = res.data
}
})
fishTreeDialog.value = false
// fishhui.value = [1, 5];
if (fishhui.value.length > 0 && activeName.value == '1') {
isCompanyDisabled.value = true
} else if (fishhui.value.length > 0 && activeName.value == '2') {
isBaseDisabled.value = true
} else {
isCompanyDisabled.value = false
isBaseDisabled.value = false
}
// console.log('ID:', fishhui.value);
console.log(params)
// getFishTreeData().then((res) => {
// fishData.value = res.data.data
// })
}
// - ID
@ -423,7 +426,7 @@ function getAllChildrenIds(node: any): number[] {
const ids: number[] = [];
if (node.children && node.children.length > 0) {
node.children.forEach((child: any) => {
ids.push(child.id);
ids.push(child.code);
if (child.children && child.children.length > 0) {
ids.push(...getAllChildrenIds(child));
}
@ -439,14 +442,14 @@ function areAllChildrenChecked(parentNode: any, checkedKeysArray: any[]): boolea
return false;
}
// IDkeys
return allChildrenIds.every(id => checkedKeysArray.includes(id));
return allChildrenIds.every(code => checkedKeysArray.includes(code));
}
// -
function isNodeContainedByOtherParent(nodeId: number, parentIds: number[], allCheckedNodes: any[]): boolean {
// ""
for (const parentId of parentIds) {
const parentNode = allCheckedNodes.find((n: any) => n.id === parentId);
const parentNode = allCheckedNodes.find((n: any) => n.code === parentId);
if (parentNode) {
const childrenIds = getAllChildrenIds(parentNode);
// ,true
@ -458,38 +461,17 @@ function isNodeContainedByOtherParent(nodeId: number, parentIds: number[], allCh
return false;
}
// -
function handleFishCheckChange(checkedNode: any, checkedInfo: any) {
console.log('当前操作的节点:', checkedNode);
console.log('选中的info:', checkedInfo);
const treeInstance = treeRef.value;
if (!treeInstance) return;
// checkedInfo keys
const checkedKeysArray = checkedInfo.checkedKeys || [];
const allCheckedNodes = checkedInfo.checkedNodes || [];
console.log('选中的keys数组:', checkedKeysArray);
console.log('选中的节点数组:', allCheckedNodes);
// ID
// IDsID
function filterSelectedIds(checkedKeysArray: number[], allCheckedNodes: any[]): number[] {
const resultIds: number[] = [];
// :""
const fullySelectedParentIds: number[] = [];
const filteredNodeIds = new Set<number>();
// :""
allCheckedNodes.forEach((node: any) => {
// ()
if (node.children && node.children.length > 0) {
//
if (areAllChildrenChecked(node, checkedKeysArray)) {
//
fullySelectedParentIds.push(node.id);
// ""
fullySelectedParentIds.push(node.code);
const childrenIds = getAllChildrenIds(node);
childrenIds.forEach(childId => {
filteredNodeIds.add(childId);
@ -498,13 +480,9 @@ function handleFishCheckChange(checkedNode: any, checkedInfo: any) {
}
});
console.log('全选父节点IDs:', fullySelectedParentIds);
console.log('应过滤的子节点IDs:', Array.from(filteredNodeIds));
// :
// 1. ""()
fullySelectedParentIds.forEach(parentId => {
//
if (!isNodeContainedByOtherParent(parentId, fullySelectedParentIds, allCheckedNodes)) {
resultIds.push(parentId);
}
@ -512,69 +490,80 @@ function handleFishCheckChange(checkedNode: any, checkedInfo: any) {
// 2. ()
allCheckedNodes.forEach((node: any) => {
// ,resultIds
if (!filteredNodeIds.has(node.id) && !resultIds.includes(node.id)) {
// :,
if (!isNodeContainedByOtherParent(node.id, fullySelectedParentIds, allCheckedNodes)) {
resultIds.push(node.id);
if (!filteredNodeIds.has(node.code) && !resultIds.includes(node.code)) {
if (!isNodeContainedByOtherParent(node.code, fullySelectedParentIds, allCheckedNodes)) {
resultIds.push(node.code);
}
}
});
console.log('过滤后的IDs:', resultIds);
return resultIds;
}
// -
function handleFishCheckChange(checkedNode: any, checkedInfo: any) {
const treeInstance = fishTreeRef.value;
if (!treeInstance) return;
// checkedInfo keys
const checkedKeysArray = checkedInfo.checkedKeys || [];
const allCheckedNodes = checkedInfo.checkedNodes || [];
// 使IDs
const resultIds = filterSelectedIds(checkedKeysArray, allCheckedNodes);
console.log('最终获取的IDs:', resultIds);
if (resultIds.length > 0 && activeName.value == '1') {
isCompanyDisabled.value = true
} else if (resultIds.length > 0 && activeName.value == '2') {
isBaseDisabled.value = true
} else {
isCompanyDisabled.value = false
isBaseDisabled.value = false
}
// 使resultIds,
// saveFishPermissions(resultIds);
getFishTableData()
tableids.value = resultIds
//
getFishTableData(resultIds);
tableids.value = resultIds;
}
//
const fishTableData = ref([
{
name: '过鱼设施权限1',
type: '站点',
id: 'fish_along_point1',
radio: '1'
},
{
name: '过鱼设施权限2',
type: '站点',
id: 'fish_along_point2',
radio: '2'
}, {
name: '过鱼设施权限3',
type: '站点',
id: 'fish_along_point3',
radio: '1'
},
])
const fishTableData: any = ref([])
const fishDialog = ref(false)
const fishTableSelection = ref([])
//
function getFishTableData() {
fishDialog.value = true
fishDialog.value = false;
//
// getFishPermissions().then((res: any) => {
// fishTableData.value = res.data
// })
function getFishTableData(ids: any[]) {
// fishData.valuecodeids
const extractedData: any[] = [];
function extractMatchingNodes(nodes: any[]) {
for (const node of nodes) {
if (ids.includes(node.code)) {
// codeids
extractedData.push({
name: node.name,
type: node.type, // ''
id: node.code.toString(), // 使codeid
code: node.code,
path: node.path,
userId: userId.value,
parentId: node.parentId,
orgLevel: node.orgLevel,
permissionType: 'READ' //
});
}
//
if (node.children && node.children.length > 0) {
extractMatchingNodes(node.children);
}
}
}
extractMatchingNodes(fishData.value);
fishTableData.value = extractedData;
}
//
const tableids:any = ref([])
const tableids: any = ref([])
//
function fishDataHandleSelectionChange(val: any) {
console.log('选中的行数据:', val);
fishTableSelection.value = val
}
//
function delFishTable() {
ElMessageBox.confirm("确定移除选中权限吗?", "删除提示", {
@ -591,6 +580,27 @@ function delFishTable() {
return !selectedIds.includes(item.id);
});
//
if (fishTreeRef.value) {
//
const treeData = fishData.value;
//
const nodesToUncheck = new Set<any>();
// ID
selectedIds.forEach((id: any) => {
nodesToUncheck.add(id);
//
findAllChildNodes(treeData, id, nodesToUncheck);
});
//
nodesToUncheck.forEach((nodeId: any) => {
fishTreeRef.value.setChecked(nodeId, false, false);
});
}
ElMessage({
type: "success",
message: "删除成功",
@ -603,15 +613,51 @@ function delFishTable() {
//
});
}
//
function findAllChildNodes(nodes: any[], targetNodeId: any, result: Set<any>) {
for (const node of nodes) {
if (node.code == targetNodeId) {
//
if (node.children && node.children.length > 0) {
for (const child of node.children) {
result.add(child.code);
//
findAllChildNodes([child], child.code, result);
}
}
break; //
} else if (node.children && node.children.length > 0) {
//
findAllChildNodes(node.children, targetNodeId, result);
}
}
}
//
function fishSure() {
// fishTableDataID
const ids = fishTableData.value.map((item: any) => item.id);
// userId.value //id
console.log('fishTableData中的所有ID:', ids);
// 使ids
// saveFishPermissions(ids);
let params: any = []
fishTableData.value.forEach((item: any) => {
params.push({
engName: item.name,
userId: item.userId,
orgType: item.type,
orgId: item.code,
parentId: item.parentId,
orgLevel: item.orgLevel,
path: item.path,
permissionType: item.permissionType,
})
})
saveFishqvan({ userId: userId.value, dataScopeList: params }).then((res: any) => {
console.log(res);
if (res.code == 0) {
ElMessage({
message: '保存成功',
type: 'success',
})
fishHandleClose()
}
})
}
//
function delclick(row: any) {
@ -690,10 +736,26 @@ function dateFormat(row: any) {
}
//
//
function getName(arr: any[], type: any): string {
if (!arr || !Array.isArray(arr) || type === undefined || type === null) {
return ''
}
const item = arr.find((item: any) => item?.itemCode === type)
return item?.dictName || ''
}
onMounted(() => {
getTree();
getdictdata()
});
const dictData = ref([])
function getdictdata(){
getDictItemsByCode({dictCode:'resourceType'}).then(res=>{
dictData.value = res.data
})
}
const vMove = {
mounted(el: any) {
el.onmousedown = function (e: any) {
@ -711,6 +773,114 @@ const vMove = {
};
}
}
// code
function getAllNodeCodes(nodes: any[]): number[] {
const codes: number[] = [];
nodes.forEach((node: any) => {
codes.push(node.code);
if (node.children && node.children.length > 0) {
codes.push(...getAllNodeCodes(node.children));
}
});
return codes;
}
//
function handleSelectAll() {
if (!fishTreeRef.value || !fishData.value || fishData.value.length === 0) {
ElMessage.warning('暂无数据可全选');
return;
}
const allCodes = getAllNodeCodes(fishData.value);
console.log('全选 - 所有节点codes:', allCodes);
fishTreeRef.value.setCheckedKeys(allCodes, true);
// 使
setTimeout(() => {
//
const checkedKeys = fishTreeRef.value.getCheckedKeys();
const checkedNodes = fishTreeRef.value.getCheckedNodes(false, false); //
// 使
const filteredIds = filterSelectedIds(checkedKeys, checkedNodes);
getFishTableData(filteredIds);
tableids.value = filteredIds;
console.log('全选 - 表格数据已更新过滤后IDs:', filteredIds);
}, 100);
ElMessage.success('已全选所有节点');
}
//
function handleInvertSelection() {
if (!fishTreeRef.value || !fishData.value || fishData.value.length === 0) {
ElMessage.warning('暂无数据可操作');
return;
}
// keys
const checkedKeys = fishTreeRef.value.getCheckedKeys();
// keys
const halfCheckedKeys = fishTreeRef.value.getHalfCheckedKeys();
console.log('反选前 - 已选中codes:', checkedKeys);
console.log('反选前 - 半选codes:', halfCheckedKeys);
//
const currentSelectedKeys = [...new Set([...checkedKeys, ...halfCheckedKeys])];
console.log('反选前 - 当前有效选中状态:', currentSelectedKeys);
// codes
const allCodes = getAllNodeCodes(fishData.value);
// -
const invertedCodes = allCodes.filter(code => !currentSelectedKeys.includes(code));
console.log('反选后 - 新的选中codes:', invertedCodes);
//
fishTreeRef.value.setCheckedKeys([], false);
//
setTimeout(() => {
fishTreeRef.value.setCheckedKeys(invertedCodes, true);
// 使
setTimeout(() => {
//
const newCheckedKeys = fishTreeRef.value.getCheckedKeys();
const newCheckedNodes = fishTreeRef.value.getCheckedNodes(false, false);
// 使
const filteredIds = filterSelectedIds(newCheckedKeys, newCheckedNodes);
getFishTableData(filteredIds);
tableids.value = filteredIds;
console.log('反选 - 表格数据已更新过滤后IDs:', filteredIds);
}, 100);
}, 50);
ElMessage.success('已反选操作');
}
//
function handleClearSelection() {
if (!fishTreeRef.value) {
return;
}
console.log('取消选中 - 清空所有选中');
fishTreeRef.value.setCheckedKeys([], true);
//
setTimeout(() => {
getFishTableData([]);
tableids.value = [];
console.log('取消选中 - 表格数据已清空');
}, 100);
ElMessage.success('已取消所有选中');
}
</script>
<template>
@ -830,11 +1000,11 @@ const vMove = {
<!-- 过鱼设施权限维护 -->
<el-dialog v-model="fishway" :close-on-click-modal="false" :before-close="fishHandleClose" title="过鱼设施权限维护"
append-to-body width="1600px" draggable>
<el-scrollbar height="628px">
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
<el-scrollbar height="610px">
<!-- <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
<el-tab-pane label="基地" name="1" :disabled="isBaseDisabled"></el-tab-pane>
<el-tab-pane label="公司" name="2" :disabled="isCompanyDisabled"></el-tab-pane>
</el-tabs>
</el-tabs> -->
<div class="fishBody">
<div class="fishTree">
<div style="width: 100%;padding: 0px 10px; box-sizing: border-box;">
@ -844,11 +1014,16 @@ const vMove = {
<el-button :icon="Search" @click="getFishTree()" />
</template>
</el-input>
<div class="button_div">
<el-button type="primary" @click="handleSelectAll">全选</el-button>
<el-button type="primary" @click="handleInvertSelection">反选</el-button>
<el-button type="primary" @click="handleClearSelection">取消选中</el-button>
</div>
</div>
<el-scrollbar height="500px">
<el-scrollbar height="460px">
<el-tree ref="fishTreeRef" style="max-width: 300px" :data="fishData" show-checkbox default-expand-all
:v-loading="fishTreeDialog" node-key="id" highlight-current :props="fishProps"
:v-loading="fishTreeDialog" node-key="code" highlight-current :props="fishProps"
@check="handleFishCheckChange" />
</el-scrollbar>
</div>
@ -857,21 +1032,21 @@ const vMove = {
<el-button type="danger" :disabled="fishTableSelection.length == 0" @click="delFishTable">移除权限</el-button>
</div>
<el-table :data="fishTableData" style="width: 100%;" row-key="id" border default-expand-all
:v-loading="fishDialog" @selection-change="fishDataHandleSelectionChange" max-height="500"
:v-loading="fishDialog" @selection-change="fishDataHandleSelectionChange" max-height="600"
:header-cell-style="{ background: 'rgb(250 250 250)', color: ' #383838', height: '50px' }">
<el-table-column type="selection" width="50" align="center" />
<el-table-column type="index" label="序号" width="70" align="center" />
<el-table-column prop="name" label="名称"></el-table-column>
<el-table-column prop="type" label="类型" width="200" align="center">
<template #default="scope">
<span>{{ scope.row.type }}</span>
<span>{{ getName(dictData,scope.row.type) }}</span>
</template>
</el-table-column>
<el-table-column prop="id" label="权限" align="center" width="200">
<template #default="scope">
<el-radio-group v-model="scope.row.radio" >
<el-radio value="1" size="large"></el-radio>
<el-radio value="2" size="large"></el-radio>
<el-radio-group v-model="scope.row.permissionType">
<el-radio value="READ" size="large"></el-radio>
<el-radio value="WRITE" size="large"></el-radio>
</el-radio-group>
</template>
</el-table-column>
@ -890,7 +1065,7 @@ const vMove = {
<style scoped lang="scss">
.fishBody {
height: 500px;
// height: 620px;
width: 100%;
display: flex;
// align-items: center;
@ -898,9 +1073,17 @@ const vMove = {
.fishTree {
width: 300px;
height: 542px;
// height: 620px;
margin-right: 10px;
border-right: #409eff 1px solid;
.button_div {
// width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 10px;
}
}
.fishTable {

View File

@ -25,10 +25,8 @@ export default ({ mode }: ConfigEnv): UserConfig => {
proxy: {
[env.VITE_APP_BASE_API]: {
// 线上API地址
// target: 'http://10.84.121.4:8093/',
// target: 'http://localhost:8093/',
// 本地API地址
// target: 'http://localhost:8093',
// 汤伟
target: 'http://10.84.121.21:8093',
changeOrigin: true,
rewrite: path =>