提交
This commit is contained in:
1 parent
3520f9ce90
commit
0e60b88cba
104 files changed
+344311
-250708
No files matched your search
@@ -18,6 +18,7 @@ export async function fetchLogin(params: { username: string; password: string })
|
||||
realName: string
|
||||
phone: string
|
||||
role: string
|
||||
roles?: string[]
|
||||
regionId: string
|
||||
regionName: string
|
||||
avatarUrl?: string | null
|
||||
@@ -39,6 +40,7 @@ export function fetchGetUserInfo() {
|
||||
realName: string
|
||||
phone: string
|
||||
role: string
|
||||
roles?: string[]
|
||||
regionId: string
|
||||
regionName: string
|
||||
regionIds?: string[]
|
||||
|
||||
@@ -72,13 +72,37 @@ export class MenuProcessor {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 Web 端角色(优先使用后端 current-user/login 的 role 字段)。
|
||||
* 避免 Pinia 持久化的旧 roles(模板/demo 遗留)覆盖真实 role 导致菜单被滤空。
|
||||
*/
|
||||
private resolveWebRoles(info: Api.Auth.UserInfo | Record<string, any> | undefined): string[] | undefined {
|
||||
const webRole = String(info?.role ?? '').trim()
|
||||
if (webRole) {
|
||||
return [webRole]
|
||||
}
|
||||
if (info?.roles?.length) {
|
||||
return info.roles
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否超级管理员(跳过后端 menuCodes 过滤)
|
||||
*/
|
||||
private isSuperAdminRole(info: Api.Auth.UserInfo | Record<string, any> | undefined): boolean {
|
||||
const webRole = String(info?.role ?? '').trim()
|
||||
if (webRole === 'super_admin') return true
|
||||
return Array.isArray(info?.roles) && info.roles.includes('super_admin')
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理前端控制模式的菜单
|
||||
*/
|
||||
private async processFrontendMenu(): Promise<AppRouteRecord[]> {
|
||||
const userStore = useUserStore()
|
||||
const info = userStore.info
|
||||
const roles = info?.roles?.length ? info.roles : info?.role ? [info.role] : undefined
|
||||
const roles = this.resolveWebRoles(info)
|
||||
|
||||
let menuList = [...asyncRoutes]
|
||||
|
||||
@@ -90,14 +114,23 @@ export class MenuProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
// 静态菜单模式下,admin 按后端返回的 menuCodes 过滤菜单
|
||||
if (info?.role === 'admin') {
|
||||
// 静态菜单模式下,非 super_admin 按后端返回的 menuCodes 过滤菜单
|
||||
if (!this.isSuperAdminRole(info)) {
|
||||
const perm = await fetchGetMenuCodes()
|
||||
const codeSet = new Set(
|
||||
(perm?.menuCodes || []).map((x) => this.normalizeMenuCode(x)).filter(Boolean)
|
||||
)
|
||||
if (!perm?.all) {
|
||||
menuList = this.filterMenuByCodes(menuList, codeSet)
|
||||
const filtered = this.filterMenuByCodes(menuList, codeSet)
|
||||
// 有 menuCodes 但过滤后为空,多为 roles/menuCode 配置异常,保留角色过滤结果便于排查
|
||||
if (filtered.length > 0 || codeSet.size === 0) {
|
||||
menuList = filtered
|
||||
} else {
|
||||
console.warn(
|
||||
'[MenuProcessor] menuCodes 非空但过滤后菜单为空,保留角色过滤后的菜单树',
|
||||
codeSet.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,9 +212,9 @@ export class MenuProcessor {
|
||||
return item
|
||||
})
|
||||
.filter((item) => {
|
||||
// 如果定义了 children 属性(即使是空数组),说明这是一个目录菜单,应该保留
|
||||
if ('children' in item) {
|
||||
return true
|
||||
// 仅当 children 为数组时视为目录;勿用 `'children' in item`(spread 后叶子常为 children: undefined)
|
||||
if (Array.isArray(item.children)) {
|
||||
return item.children.length > 0
|
||||
}
|
||||
|
||||
// 如果有外链或 iframe,保留
|
||||
|
||||
@@ -98,6 +98,9 @@ export function getRouteInitFailed(): boolean {
|
||||
export function resetRouteInitState(): void {
|
||||
routeInitFailed = false
|
||||
routeInitInProgress = false
|
||||
routeRegistry?.unregister()
|
||||
useMenuStore().removeAllDynamicRoutes()
|
||||
useMenuStore().setMenuList([])
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,12 +58,20 @@ export const useUserStore = defineStore(
|
||||
* @param newInfo 新的用户信息
|
||||
*/
|
||||
const setUserInfo = (newInfo: Partial<Api.Auth.UserInfo> & Record<string, any>) => {
|
||||
const webRole = String(newInfo?.role ?? '').trim()
|
||||
info.value = {
|
||||
...(info.value || {}),
|
||||
...(newInfo || {}),
|
||||
buttons: newInfo?.buttons ?? info.value?.buttons ?? [],
|
||||
userName: newInfo?.userName ?? newInfo?.username ?? info.value?.userName ?? ''
|
||||
} as Api.Auth.UserInfo
|
||||
// 后端 role(admin/super_admin)为权威来源,同步到 roles,避免持久化旧 demo roles 导致菜单被滤空
|
||||
if (webRole) {
|
||||
info.value.role = webRole
|
||||
info.value.roles = [webRole]
|
||||
} else if (Array.isArray(newInfo?.roles)) {
|
||||
info.value.roles = newInfo.roles
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -326,18 +326,18 @@
|
||||
}
|
||||
|
||||
/* 列表合计:金额列等 footer 单元格样式(如有需要可在此扩展) */
|
||||
.table-scroll.table-page-summary .el-table__footer-wrapper td:nth-child(4) .cell {
|
||||
:is(.table-scroll, .list-body).table-page-summary .el-table__footer-wrapper td:nth-child(4) .cell {
|
||||
font-weight: 600;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.table-scroll.table-page-summary .el-table__footer-wrapper td.col-apply-code .cell {
|
||||
:is(.table-scroll, .list-body).table-page-summary .el-table__footer-wrapper td.col-apply-code .cell {
|
||||
font-weight: 600;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
/* 合并申请单列表:金额合计按备用金 / 报销单分列展示 */
|
||||
.table-scroll.table-page-summary-biz-split .el-table__footer-wrapper td.col-money .cell {
|
||||
:is(.table-scroll, .list-body).table-page-summary-biz-split .el-table__footer-wrapper td.col-money .cell {
|
||||
white-space: normal;
|
||||
line-height: 1.45;
|
||||
font-size: 13px;
|
||||
|
||||
@@ -88,19 +88,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-body list-wrap">
|
||||
<div class="table-scroll table-page-summary table-page-summary-biz-split">
|
||||
<el-table
|
||||
class="list-table"
|
||||
:data="pager.pagedRows.value"
|
||||
v-loading="loading"
|
||||
stripe
|
||||
show-summary
|
||||
:summary-method="summaryMethod"
|
||||
:max-height="'min(520px, calc(100vh - 300px))'"
|
||||
@row-dblclick="openViewDetail"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<div class="list-body list-wrap table-page-summary table-page-summary-biz-split">
|
||||
<el-table
|
||||
class="list-table"
|
||||
:data="pager.pagedRows.value"
|
||||
v-loading="loading"
|
||||
stripe
|
||||
show-summary
|
||||
:summary-method="summaryMethod"
|
||||
@row-dblclick="openViewDetail"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" min-width="55" align="center" header-align="center" />
|
||||
<el-table-column type="index" label="序号" min-width="68" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
@@ -199,8 +197,7 @@
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination list-pager-bar">
|
||||
<span class="list-range">{{ pager.rangeText.value }}</span>
|
||||
@@ -209,7 +206,7 @@
|
||||
v-model:page-size="pager.pageSize.value"
|
||||
:total="pager.total.value"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
:page-sizes="[10, 20, 30]"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@size-change="pager.onSizeChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user