This commit is contained in:
2025-09-04 09:03:42 +08:00
parent d26db2d321
commit 9b06c042ef
5 changed files with 512 additions and 25 deletions

View File

@ -71,7 +71,7 @@ export function getRoleList(deptId?: number | string): AxiosPromise<any[]> {
url: '/system/role/listNoPage', url: '/system/role/listNoPage',
method: 'get', method: 'get',
params: { params: {
deptId deptId,
} }
}); });
} }

View File

@ -16,7 +16,7 @@
<!-- 表单区域 --> <!-- 表单区域 -->
<el-card class="rounded-lg shadow-sm bg-white border border-gray-100 transition-all hover:shadow-md overflow-hidden"> <el-card class="rounded-lg shadow-sm bg-white border border-gray-100 transition-all hover:shadow-md overflow-hidden">
<div class="p-4 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-gray-100"> <div class="p-4 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-gray-100">
<h3 class="text-lg font-semibold text-gray-800">标工程清单</h3> <h3 class="text-lg font-semibold text-gray-800">标工程清单</h3>
</div> </div>
<div class="p-6"> <div class="p-6">
<el-form <el-form

View File

@ -75,10 +75,10 @@
</el-col> </el-col>
</el-row> </el-row>
</el-form> </el-form>
<div class="box_submit"> <!-- <div class="box_submit">
<el-button type="primary" @click="submitForm"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel()"> </el-button> <el-button @click="cancel()"> </el-button>
</div> </div> -->
</div> </div>
</template> </template>
@ -105,7 +105,7 @@ const initFormData = {
sex: undefined, sex: undefined,
projectRoles: [ projectRoles: [
{ {
projectId: [], projectId: '',
roleIds: [] roleIds: []
} }
], ],
@ -178,6 +178,7 @@ const filterDisabledDept = (deptList) => {
}); });
}; };
async function handleDeptChange(value: number | string) { async function handleDeptChange(value: number | string) {
proxy?.$emit('setDeptId', value);
const response = await optionselect(value); const response = await optionselect(value);
const roleList = await getRoleList(value); const roleList = await getRoleList(value);
roleOptions.value = roleList.data; roleOptions.value = roleList.data;
@ -185,7 +186,7 @@ async function handleDeptChange(value: number | string) {
form.value.postIds = []; form.value.postIds = [];
form.value.projectRoles = [ form.value.projectRoles = [
{ {
projectId: [], projectId: '',
roleIds: [] roleIds: []
} }
]; ];
@ -209,7 +210,7 @@ const reset = () => {
form.value = { ...initFormData }; form.value = { ...initFormData };
form.value.projectRoles = [ form.value.projectRoles = [
{ {
projectId: [], projectId: '',
roleIds: [] roleIds: []
} }
]; ];
@ -236,10 +237,13 @@ const open = async (row?: any) => {
postOptions.value = data.posts; postOptions.value = data.posts;
} }
}; };
const getInfoForm = () => {
return form.value;
};
onMounted(() => { onMounted(() => {
getDeptTree(); getDeptTree();
}); });
defineExpose({ open }); defineExpose({ open, getInfoForm });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.editInfo { .editInfo {

View File

@ -0,0 +1,477 @@
<template>
<div class="roleInfo">
<div class="title_detail">
<span>当前选定角色信息预览</span>
<div style="margin-top: 10px">
<el-table :data="roleList" border height="150">
<el-table-column label="所属部门" align="center" prop="deptName" />
<el-table-column label="关联项目" align="center" prop="projectName" />
<el-table-column label="web端担任角色" align="center" prop="webRoles" />
<el-table-column label="APP端担任角色" align="center" prop="appRoles" />
</el-table>
</div>
</div>
<div class="title_detail" style="margin-top: 20px">
<span>选择或修改当前角色信息</span>
<div style="margin-top: 10px" class="box_detail">
<!-- 项目列表选择区 -->
<div class="project_list">
<span>关联项目模块</span>
<div class="project-items">
<div
v-for="item in projectOptions"
:key="item.id"
class="project-item"
:class="{ 'project-item-selected': isProjectSelected(item.id) }"
@click="toggleProjectSelection(item)"
>
<div class="project-item-content">
<el-checkbox v-model="item.checked" :value="item.id" class="project-checkbox" @change="handleProjectCheck(item, $event)" />
<span class="project-name">{{ item.projectName }}</span>
</div>
</div>
</div>
</div>
<!-- 角色分配区 -->
<div class="post_list">
<span>关联项目角色分配</span>
<div v-if="selectedProjects.length === 0" class="no-selection">请从左侧选择项目进行角色分配</div>
<div v-for="(project, index) in selectedProjects" :key="project.id" class="project-role-container">
<div class="project-header">
<span class="project-title">{{ project.projectName }}</span>
<el-button type="text" class="remove-project" @click="removeProject(project.id)"> 移除 </el-button>
</div>
<div class="role-assignment">
<div class="role-group">
<label class="role-label">web端角色</label>
<el-checkbox-group v-model="project.webRoles" @change="updateRoleList">
<el-checkbox v-for="role in allRoles" :key="role.roleId" :value="role.roleId">
{{ role.roleName }}
</el-checkbox>
</el-checkbox-group>
</div>
<div class="role-group">
<label class="role-label">APP端角色</label>
<el-checkbox-group v-model="project.appRoles" @change="updateRoleList">
<el-checkbox v-for="role in AppRoles" :key="role.roleId" :value="role.roleId">
{{ role.roleName }}
</el-checkbox>
</el-checkbox-group>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="box_submit">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel()"> </el-button>
</div>
</div>
</template>
<script setup name="RoleProjectManagement" lang="ts">
import { ref, reactive, toRefs, getCurrentInstance, ComponentInternalInstance, defineExpose, watch } from 'vue';
import { ElFormInstance } from 'element-plus';
import api from '@/api/system/user';
import { listProject } from '@/api/project/project';
import { getRoleList } from '@/api/system/post';
// 类型定义
interface Project {
id: number | string;
projectName: string;
checked: boolean;
webRoles: string[];
appRoles: string[];
}
interface Role {
roleId: number | string;
roleName: string;
roleSort?: number;
}
interface RoleInfo {
userNick: string;
deptName: string;
postName: string;
projectName: string;
webRoles: string;
appRoles: string;
}
// 组件实例
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
// 响应式数据
const projectOptions = ref<Project[]>([]);
const selectedProjects = ref<Project[]>([]);
const allRoles = ref<Role[]>([]); // web端角色
const AppRoles = ref<Role[]>([]); // APP端角色
const roleList = ref<RoleInfo[]>([]);
// 表单初始数据
const initFormData = {
userId: undefined,
deptId: undefined,
userName: '',
nickName: undefined,
password: '',
phonenumber: undefined,
email: undefined,
sex: undefined,
projectRoles: [] as Array<{ projectId: number | string; webRoles: string[]; appRoles: string[] }>,
status: '0',
remark: '',
postIds: [],
filePath: undefined,
deptName: '' // 新增部门名称字段
};
const data = reactive({
form: { ...initFormData }
});
const deptName = ref('');
const { form } = toRefs(data);
// 核心方法:更新预览列表
const updateRoleList = () => {
if (selectedProjects.value.length === 0) {
roleList.value = [];
return;
}
roleList.value = selectedProjects.value.map((project) => {
// 处理web端角色名称
var webRoleNames = project.webRoles
.map((roleId) => {
const role = allRoles.value.find((r) => r.roleId === roleId);
return role ? role.roleName : '';
})
.filter(Boolean);
// 处理APP端角色名称
var appRoleNames = project.appRoles
.map((roleId) => {
const role = AppRoles.value.find((r) => r.roleId === roleId);
return role ? role.roleName : '';
})
.filter(Boolean);
webRoleNames = [...new Set(webRoleNames)];
appRoleNames = [...new Set(appRoleNames)];
return {
deptName: deptName.value,
projectName: project.projectName,
webRoles: webRoleNames.length > 0 ? webRoleNames.join('') : '无',
appRoles: appRoleNames.length > 0 ? appRoleNames.join('') : '无'
};
});
};
// 监听已选项目变化,自动更新预览列表
watch(
selectedProjects,
() => {
updateRoleList();
},
{ deep: true }
);
// 检查项目是否被选中
const isProjectSelected = (projectId: number | string) => {
return selectedProjects.value.some((p) => p.id === projectId);
};
// 切换项目选择状态
const toggleProjectSelection = (project: Project) => {
// handleProjectCheck(project, !project.checked);
};
// 处理项目勾选状态变化
const handleProjectCheck = (project: Project, checked: boolean) => {
// project.checked = checked;
const index = selectedProjects.value.findIndex((p) => p.id === project.id);
if (checked && index === -1) {
// 添加选中的项目
selectedProjects.value.push({
...project,
webRoles: [],
appRoles: []
});
} else if (!checked && index !== -1) {
// 移除取消选中的项目
selectedProjects.value.splice(index, 1);
}
};
// 移除项目
const removeProject = (projectId: number | string) => {
// 更新选中项目列表
selectedProjects.value = selectedProjects.value.filter((p) => p.id !== projectId);
// 更新项目选项的勾选状态
const project = projectOptions.value.find((p) => p.id === projectId);
if (project) {
project.checked = false;
}
};
// 提交表单
const submitForm = async () => {
// 整理项目角色数据
form.value.projectRoles = selectedProjects.value.map((project) => ({
projectId: project.id,
roleIds: [...new Set(project.webRoles), ...new Set(project.appRoles)]
}));
// 提交数据
try {
if (form.value.userId) {
await api.updateUser(form.value);
} else {
await api.addUser(form.value);
}
proxy?.$modal.msgSuccess('操作成功');
proxy?.$emit('submit', form.value);
cancel();
} catch (error) {
proxy?.$modal.msgError('操作失败,请重试');
console.error('提交失败:', error);
}
};
// 取消操作
const cancel = () => {
resetForm();
proxy?.$emit('close');
};
// 重置表单
const resetForm = () => {
data.form = { ...initFormData };
projectOptions.value.forEach((p) => (p.checked = false));
selectedProjects.value = [];
roleList.value = [];
};
// 初始化数据
const initData = async () => {
try {
// 获取项目列表
const projectRes = await listProject();
projectOptions.value = projectRes.rows.map((item: any) => ({
id: item.id,
projectName: item.projectName,
checked: false
}));
} catch (error) {
proxy?.$modal.msgError('数据加载失败');
console.error('初始化数据失败:', error);
}
};
// 打开弹窗时调用
const open = async (row?: any, deptId?: any) => {
resetForm();
await initData();
deptName.value = row.deptName;
console.log(row);
if (row) {
try {
if (!row.createTime) {
form.value = { ...row };
// 获取角色列表
if (form.value.deptId) {
deptId = form.value.deptId;
}
const roleRes = await getRoleList(deptId);
allRoles.value = roleRes.data.filter((item: Role) => item.roleSort === 1);
AppRoles.value = roleRes.data.filter((item: Role) => item.roleSort !== 1);
} else {
const { data } = await api.getUser(row.userId);
Object.assign(form.value, data.user);
// 获取角色列表
if (form.value.deptId) {
deptId = form.value.deptId;
}
const roleRes = await getRoleList(deptId);
// 区分web端和app端角色
allRoles.value = roleRes.data.filter((item: Role) => item.roleSort === 1);
AppRoles.value = roleRes.data.filter((item: Role) => item.roleSort !== 1);
// 加载项目角色数据
if (data.projectRoles && data.projectRoles.length) {
data.projectRoles.forEach((pr: any) => {
const project = projectOptions.value.find((p) => p.id === pr.projectId);
if (project) {
project.checked = true;
selectedProjects.value.push({
...project,
webRoles: pr.roleIds || [],
appRoles: pr.roleIds || []
});
}
});
}
}
} catch (error) {
proxy?.$modal.msgError('加载用户数据失败');
console.error('加载用户数据失败:', error);
}
}
};
// 暴露方法
defineExpose({ open });
</script>
<style lang="scss">
.roleInfo {
position: relative;
height: 100%;
padding-bottom: 60px;
box-sizing: border-box;
.title_detail {
> span {
font-size: 16px;
font-weight: 600;
color: #333;
display: inline-block;
padding-bottom: 5px;
border-bottom: 2px solid #409eff;
}
.box_detail {
display: flex;
gap: 15px;
margin-top: 15px;
> div {
height: 350px;
padding: 15px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
overflow-y: auto;
box-sizing: border-box;
}
.project_list {
width: 320px;
background-color: #fff;
.project-items {
margin-top: 10px;
}
.project-item {
padding: 10px 12px;
margin-bottom: 8px;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
border: 1px solid #eee;
&:hover {
background-color: #f5f7fa;
border-color: #e4e7ed;
}
.project-item-content {
display: flex;
align-items: center;
}
.project-checkbox {
margin-right: 8px;
}
.project-name {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
.project-item-selected {
background-color: #ecf5ff;
border-color: #c6e2ff;
}
}
.post_list {
flex: 1;
background-color: #fff;
.no-selection {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #909399;
font-size: 14px;
}
.project-role-container {
padding: 15px;
margin-bottom: 15px;
background-color: #f9f9f9;
border-radius: 4px;
border: 1px solid #f0f0f0;
.project-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
.project-title {
font-weight: 500;
color: #333;
font-size: 14px;
}
.remove-project {
color: #f56c6c;
padding: 0 5px;
&:hover {
color: #e4393c;
}
}
}
.role-assignment {
.role-group {
margin-bottom: 15px;
.role-label {
display: inline-block;
width: 110px;
color: #606266;
font-size: 14px;
}
.el-checkbox-group {
display: inline-block;
margin-left: 10px;
.el-checkbox {
margin-right: 15px;
margin-bottom: 8px;
}
}
}
}
}
}
}
}
.box_submit {
position: absolute;
right: 20px;
bottom: 0px;
display: flex;
gap: 10px;
}
}
</style>

View File

@ -154,16 +154,18 @@
</el-row> </el-row>
<!-- 添加或修改用户配置对话框 --> <!-- 添加或修改用户配置对话框 -->
<el-dialog draggable ref="formDialogRef" v-model="dialog.visible" :title="dialog.title" width="1200px" append-to-body @close="closeDialog"> <el-dialog draggable ref="formDialogRef" v-model="dialog.visible" :title="dialog.title" width="1300px" append-to-body @close="closeDialog">
<div class="boxDetial"> <div class="boxDetial">
<div class="tab_info"> <div class="tab_info">
<span @click="onTab(1)" :class="{ active: type == 1 }">基本资料</span> <span @click="onTab(1)" :class="{ active: type == 1 }">基本资料</span>
<span @click="onTab(2)" :class="{ active: type == 2 }">角色信息</span> <span @click="onTab(2)" :class="{ active: type == 2 }">角色信息</span>
</div> </div>
<div class="tab_content" v-if="type == 1"> <div class="tab_content" v-show="type == 1">
<editInfo ref="editInfoRef" @close="dialog.visible = false" @submit="getList"></editInfo> <editInfo ref="editInfoRef" @close="dialog.visible = false" @submit="getList" @setDeptId="setDeptId"></editInfo>
</div>
<div class="tab_content" v-show="type == 2">
<roleInfo ref="roleInfoRef" @close="dialog.visible = false" @submit="getList"></roleInfo>
</div> </div>
<div class="tab_content" v-if="type == 2"></div>
</div> </div>
</el-dialog> </el-dialog>
@ -229,6 +231,7 @@ import { getProjectByDeptId, getRoleList, optionselect } from '@/api/system/post
import ShuttleFrame from '../../project/projectRelevancy/component/ShuttleFrame.vue'; import ShuttleFrame from '../../project/projectRelevancy/component/ShuttleFrame.vue';
import { listProject } from '@/api/project/project'; import { listProject } from '@/api/project/project';
import editInfo from './comm/editInfo.vue'; import editInfo from './comm/editInfo.vue';
import roleInfo from './comm/roleInfo.vue';
const router = useRouter(); const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_normal_disable, sys_user_sex } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'sys_user_sex')); const { sys_normal_disable, sys_user_sex } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'sys_user_sex'));
@ -248,6 +251,7 @@ const postOptions = ref<PostVO[]>([]);
const roleOptions = ref<RoleVO[]>([]); const roleOptions = ref<RoleVO[]>([]);
const projectOptions = ref<any[]>([]); const projectOptions = ref<any[]>([]);
const editInfoRef = ref<InstanceType<typeof editInfo> | null>(null); const editInfoRef = ref<InstanceType<typeof editInfo> | null>(null);
const roleInfoRef = ref<InstanceType<typeof roleInfo> | null>(null);
/*** 用户导入参数 */ /*** 用户导入参数 */
const upload = reactive<ImportOption>({ const upload = reactive<ImportOption>({
// 是否显示弹出层(用户导入) // 是否显示弹出层(用户导入)
@ -279,6 +283,7 @@ const queryFormRef = ref<ElFormInstance>();
const userFormRef = ref<ElFormInstance>(); const userFormRef = ref<ElFormInstance>();
const uploadRef = ref<ElUploadInstance>(); const uploadRef = ref<ElUploadInstance>();
const formDialogRef = ref<ElDialogInstance>(); const formDialogRef = ref<ElDialogInstance>();
const deptIdRole = ref<number>();
const type = ref(1); const type = ref(1);
const dialog = reactive<DialogOption>({ const dialog = reactive<DialogOption>({
visible: false, visible: false,
@ -373,7 +378,9 @@ watchEffect(
flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发此属性控制在DOM元素更新后运行 flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发此属性控制在DOM元素更新后运行
} }
); );
const setDeptId = (deptId: number) => {
deptIdRole.value = deptId;
};
/** 查询用户列表 */ /** 查询用户列表 */
const getList = async () => { const getList = async () => {
loading.value = true; loading.value = true;
@ -558,6 +565,7 @@ const cancel = () => {
const handleAdd = async () => { const handleAdd = async () => {
reset(); reset();
const { data } = await api.getUser(); const { data } = await api.getUser();
type.value = 1;
dialog.visible = true; dialog.visible = true;
dialog.title = '新增用户'; dialog.title = '新增用户';
nextTick(() => { nextTick(() => {
@ -570,22 +578,13 @@ const handleAdd = async () => {
/** 修改按钮操作 */ /** 修改按钮操作 */
const handleUpdate = async (row?: UserForm) => { const handleUpdate = async (row?: UserForm) => {
reset(); reset();
const userId = row?.userId || ids.value[0];
const { data } = await api.getUser(userId);
dialog.visible = true; dialog.visible = true;
dialog.title = '修改用户'; dialog.title = '修改用户';
type.value = 1;
form.value = row;
nextTick(() => { nextTick(() => {
editInfoRef.value?.open(row); editInfoRef.value?.open(row);
}); });
Object.assign(form.value, data.user);
postOptions.value = data.posts;
roleOptions.value = data.roles;
form.value.postIds = data.postIds;
form.value.projectRoles = data.projectRoles;
form.value.password = '';
const roleList = await getRoleList(form.value.deptId);
roleOptions.value = roleList.data;
}; };
const validate = () => { const validate = () => {
@ -693,6 +692,13 @@ const uploadCert = async () => {
}; };
const onTab = (val) => { const onTab = (val) => {
type.value = val; type.value = val;
if (val == 2) {
let obj = editInfoRef.value?.getInfoForm();
form.value = obj;
nextTick(() => {
roleInfoRef.value?.open(form.value, deptIdRole.value);
});
}
}; };
</script> </script>
@ -701,7 +707,7 @@ const onTab = (val) => {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
height: 600px; height: 680px;
.tab_info { .tab_info {
height: 100%; height: 100%;
width: 200px; width: 200px;