| | |
| | | |
| | | <el-form label-width="100px" class="main-form"> |
| | | <el-form-item label="角色名称" required> |
| | | <el-input v-model="form.roleName" placeholder="请输入" maxlength="128" show-word-limit style="max-width: 480px" /> |
| | | <el-input v-model="form.roleName" placeholder="请输入" maxlength="128" style="max-width: 480px" /> |
| | | </el-form-item> |
| | | <el-form-item label="备注"> |
| | | <el-input |
| | |
| | | :rows="2" |
| | | placeholder="请输入" |
| | | maxlength="512" |
| | | show-word-limit |
| | | style="max-width: 480px" |
| | | /> |
| | | </el-form-item> |
| | |
| | | import RolePermissionMatrix from "../components/RolePermissionMatrix.vue"; |
| | | import type { MenuNode } from "../types/sysMenu"; |
| | | import http from "../api/http"; |
| | | import { normalizeFormData } from "../utils/formHelper"; |
| | | |
| | | const route = useRoute(); |
| | | const router = useRouter(); |
| | |
| | | roleName: "", |
| | | remark: "", |
| | | }); |
| | | |
| | | function resolveSubmitMenuIds() { |
| | | const selected = new Set(menuIds.value || []); |
| | | const merged = new Set<number>(selected); |
| | | |
| | | const walk = (node: MenuNode): boolean => { |
| | | const selfChecked = selected.has(node.id); |
| | | const children = node.children || []; |
| | | if (children.length === 0) { |
| | | return selfChecked; |
| | | } |
| | | let hasCheckedInDescendants = false; |
| | | for (const child of children) { |
| | | if (walk(child)) { |
| | | hasCheckedInDescendants = true; |
| | | } |
| | | } |
| | | if (hasCheckedInDescendants) { |
| | | merged.add(node.id); |
| | | } |
| | | return selfChecked || hasCheckedInDescendants; |
| | | }; |
| | | |
| | | for (const root of menuTree.value || []) { |
| | | walk(root); |
| | | } |
| | | |
| | | return [...merged]; |
| | | } |
| | | |
| | | async function loadTree() { |
| | | const { data } = await http.get("/sys/menus/tree"); |
| | |
| | | ElMessage.warning("请至少选择一项操作权限"); |
| | | return; |
| | | } |
| | | const submitMenuIds = resolveSubmitMenuIds(); |
| | | saving.value = true; |
| | | try { |
| | | if (isCreate.value) { |
| | | await http.post("/sys/role-manage", { |
| | | const payload = normalizeFormData({ |
| | | roleName: form.roleName.trim(), |
| | | remark: form.remark.trim() || undefined, |
| | | menuIds: menuIds.value, |
| | | remark: form.remark.trim(), |
| | | menuIds: submitMenuIds, |
| | | }); |
| | | await http.post("/sys/role-manage", payload); |
| | | ElMessage.success("已创建"); |
| | | } else { |
| | | const uuid = route.query.uuid as string; |
| | | await http.put(`/sys/role-manage/${roleId.value}`, { |
| | | const payload = normalizeFormData({ |
| | | uuid, |
| | | roleName: form.roleName.trim(), |
| | | remark: form.remark.trim() || undefined, |
| | | menuIds: menuIds.value, |
| | | remark: form.remark.trim(), |
| | | menuIds: submitMenuIds, |
| | | }); |
| | | await http.put(`/sys/role-manage/${roleId.value}`, payload); |
| | | ElMessage.success("已保存"); |
| | | } |
| | | router.push("/roles"); |