From 40905cbd04c2e332cd4bc2b9e0c5b3e1da9cccfa Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期一, 30 三月 2026 08:17:32 +0800
Subject: [PATCH] feat: complete rsf-design phase 1 integration

---
 rsf-design/src/api/system-manage.js |  391 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 374 insertions(+), 17 deletions(-)

diff --git a/rsf-design/src/api/system-manage.js b/rsf-design/src/api/system-manage.js
index 1c9f35a..f28243d 100644
--- a/rsf-design/src/api/system-manage.js
+++ b/rsf-design/src/api/system-manage.js
@@ -4,11 +4,12 @@
   return {
     current: params.current || 1,
     pageSize: params.pageSize || params.size || 20,
-    username: params.username,
-    nickname: params.nickname,
-    phone: params.phone,
-    status: params.status,
-    deptId: params.deptId
+    ...(params.username !== undefined ? { username: params.username } : {}),
+    ...(params.nickname !== undefined ? { nickname: params.nickname } : {}),
+    ...(params.phone !== undefined ? { phone: params.phone } : {}),
+    ...(params.email !== undefined ? { email: params.email } : {}),
+    ...(params.status !== undefined ? { status: params.status } : {}),
+    ...(params.deptId !== undefined ? { deptId: params.deptId } : {})
   }
 }
 
@@ -16,10 +17,10 @@
   return {
     current: params.current || 1,
     pageSize: params.pageSize || params.size || 20,
-    name: params.name,
-    code: params.code,
-    memo: params.memo,
-    status: params.status
+    ...(params.name !== undefined ? { name: params.name } : {}),
+    ...(params.code !== undefined ? { code: params.code } : {}),
+    ...(params.memo !== undefined ? { memo: params.memo } : {}),
+    ...(params.status !== undefined ? { status: params.status } : {})
   }
 }
 
@@ -40,7 +41,8 @@
 }
 
 function fetchResetUserPassword(params) {
-  return request.post({ url: '/auth/reset/password', params })
+  const normalizedParams = normalizeAdminPasswordUpdateParams(params)
+  return request.post({ url: '/user/update', params: normalizedParams })
 }
 
 function fetchUpdateUserStatus(params) {
@@ -71,32 +73,145 @@
   return request.post({ url: '/role/list', params })
 }
 
+function buildRolePageParams(params = {}) {
+  return {
+    current: params.current || 1,
+    pageSize: params.pageSize || params.size || 20,
+    ...(params.name !== undefined ? { name: params.name } : {}),
+    ...(params.code !== undefined ? { code: params.code } : {}),
+    ...(params.memo !== undefined ? { memo: params.memo } : {}),
+    ...(params.status !== undefined ? { status: params.status } : {}),
+    ...(params.condition !== undefined ? { condition: params.condition } : {})
+  }
+}
+
+function fetchRolePage(params = {}) {
+  return request.post({ url: '/role/page', params: buildRolePageParams(params) })
+}
+
+const fetchRolePrintPage = fetchRolePage
+
+function normalizeRoleManyIds(ids) {
+  if (Array.isArray(ids)) {
+    return ids
+      .map((id) => normalizeLegacyId(id))
+      .filter((id) => id !== '')
+      .join(',')
+  }
+  return normalizeLegacyId(ids)
+}
+
+function fetchGetRoleMany(ids) {
+  const normalizedIds = normalizeRoleManyIds(ids)
+  return request.post({ url: `/role/many/${normalizedIds}` })
+}
+
+async function fetchExportRoleReport(payload = {}, options = {}) {
+  return fetch(`${import.meta.env.VITE_API_URL}/role/export`, {
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+      ...(options.headers || {})
+    },
+    body: JSON.stringify(payload)
+  })
+}
+
 function fetchGetDeptTree(params) {
   return request.post({ url: '/dept/tree', params })
 }
 
-function fetchGetMenuTree(params) {
+function fetchGetMenuTree(params = {}) {
   return request.post({ url: '/menu/tree', params })
 }
 
-function fetchGetRoleScopeList(scopeType, roleId) {
+function fetchSaveMenu(params) {
+  return request.post({ url: '/menu/save', params })
+}
+
+function fetchUpdateMenu(params) {
+  return request.post({ url: '/menu/update', params })
+}
+
+function fetchDeleteMenu(id) {
+  return request.post({ url: `/menu/remove/${id}` })
+}
+
+function assertAdminPasswordUpdatePayload(params) {
+  if (!isPlainObject(params)) {
+    throw new Error('fetchResetUserPassword requires an object payload')
+  }
+  if (params.id === undefined || params.id === null || params.id === '') {
+    throw new Error('fetchResetUserPassword requires a user id')
+  }
+}
+
+function normalizeAdminPasswordUpdateParams(params) {
+  assertAdminPasswordUpdatePayload(params)
+  if (params.password !== undefined) {
+    return params
+  }
+  if (params.newPassword !== undefined) {
+    return {
+      ...params,
+      password: params.newPassword
+    }
+  }
+  throw new Error('fetchResetUserPassword requires a password payload')
+}
+
+function getScopeListUrl(scopeType) {
   const urlMap = {
     menu: '/role/scope/list',
     pda: '/rolePda/scope/list',
     matnr: '/roleMatnr/scope/list',
     warehouse: '/roleWarehouse/scope/list'
   }
-  return request.get({ url: urlMap[scopeType], params: { roleId } })
+  const url = urlMap[scopeType]
+  if (!url) {
+    throw new Error(`Unsupported scope type: ${scopeType}`)
+  }
+  return url
 }
 
-function fetchUpdateRoleScope(scopeType, params) {
+function getScopeUpdateUrl(scopeType) {
   const urlMap = {
     menu: '/role/scope/update',
     pda: '/rolePda/scope/update',
     matnr: '/roleMatnr/scope/update',
     warehouse: '/roleWarehouse/scope/update'
   }
-  return request.post({ url: urlMap[scopeType], params })
+  const url = urlMap[scopeType]
+  if (!url) {
+    throw new Error(`Unsupported scope type: ${scopeType}`)
+  }
+  return url
+}
+
+function getScopeTreeUrl(scopeType) {
+  const urlMap = {
+    menu: '/menu/tree',
+    pda: '/menuPda/tree',
+    matnr: '/menuMatnrGroup/tree',
+    warehouse: '/menuWarehouse/tree'
+  }
+  const url = urlMap[scopeType]
+  if (!url) {
+    throw new Error(`Unsupported scope type: ${scopeType}`)
+  }
+  return url
+}
+
+function fetchGetRoleScopeList(scopeType, roleId) {
+  return request.get({ url: getScopeListUrl(scopeType), params: { roleId } })
+}
+
+function fetchUpdateRoleScope(scopeType, params) {
+  return request.post({ url: getScopeUpdateUrl(scopeType), params })
+}
+
+function fetchGetRoleScopeTree(scopeType, params = {}) {
+  return request.post({ url: getScopeTreeUrl(scopeType), params })
 }
 
 function fetchGetUserLoginList(params) {
@@ -106,8 +221,242 @@
   })
 }
 
-function fetchGetMenuList(params) {
-  return fetchGetMenuTree(params)
+function fetchGetMenuList(params = {}) {
+  return request.post({ url: '/menu/list', params }).then((menuList) => adaptLegacyMenuTree(buildLegacyMenuTree(menuList)))
+}
+
+function adaptLegacyMenuTree(menuTree) {
+  if (!Array.isArray(menuTree)) {
+    return []
+  }
+
+  return menuTree
+    .map((node) => adaptLegacyMenuNode(node))
+    .filter(Boolean)
+}
+
+function buildLegacyMenuTree(menuList) {
+  if (!Array.isArray(menuList)) {
+    return []
+  }
+
+  const nodeMap = new Map()
+  const roots = []
+
+  menuList.forEach((node) => {
+    if (!node || typeof node !== 'object') {
+      return
+    }
+    nodeMap.set(normalizeLegacyId(node.id), {
+      ...node,
+      children: []
+    })
+  })
+
+  nodeMap.forEach((node) => {
+    const parentId = normalizeLegacyId(node.parentId ?? 0)
+    if (parentId && parentId !== '0' && nodeMap.has(parentId)) {
+      nodeMap.get(parentId).children.push(node)
+      return
+    }
+    roots.push(node)
+  })
+
+  return sortLegacyMenuTree(roots)
+}
+
+function sortLegacyMenuTree(nodes) {
+  return nodes
+    .sort((left, right) => {
+      const leftSort = Number(left?.sort ?? 0)
+      const rightSort = Number(right?.sort ?? 0)
+      if (leftSort !== rightSort) {
+        return leftSort - rightSort
+      }
+      return normalizeLegacyId(left?.id).localeCompare(normalizeLegacyId(right?.id))
+    })
+    .map((node) => ({
+      ...node,
+      children: Array.isArray(node.children) ? sortLegacyMenuTree(node.children) : []
+    }))
+}
+
+function adaptLegacyMenuNode(node) {
+  if (!node || typeof node !== 'object' || node.type === 1) {
+    return null
+  }
+
+  const menuChildren = []
+  const authList = []
+  const rawChildren = Array.isArray(node.children) ? node.children : []
+
+  rawChildren.forEach((child) => {
+    if (!child || typeof child !== 'object') {
+      return
+    }
+    if (child.type === 1) {
+      authList.push(buildLegacyAuthItem(child))
+      return
+    }
+    const adaptedChild = adaptLegacyMenuNode(child)
+    if (adaptedChild) {
+      menuChildren.push(adaptedChild)
+    }
+  })
+
+  const adapted = {
+    id: normalizeLegacyId(node.id),
+    parentId: normalizeLegacyId(node.parentId ?? 0),
+    parentName: node.parentName || '',
+    name: buildLegacyRouteName(node),
+    route: typeof node.route === 'string' ? node.route : '',
+    path: buildLegacyMenuPath(node),
+    component: buildLegacyMenuComponent(node),
+    authority: node.authority || '',
+    icon: node.icon || '',
+    sort: node.sort ?? 0,
+    status: node.status ?? 1,
+    memo: node.memo || '',
+    type: node.type ?? 0,
+    meta: buildLegacyMenuMeta(node),
+    children: menuChildren
+  }
+  if (authList.length > 0) {
+    adapted.meta.authList = authList
+  }
+
+  return adapted
+}
+
+function buildLegacyMenuMeta(node) {
+  const metaSource = node.meta && typeof node.meta === 'object' ? node.meta : node
+  const meta = {
+    title: normalizeLegacyTitle(node.name || metaSource.title || '')
+  }
+
+  const supportedKeys = [
+    'icon',
+    'sort',
+    'keepAlive',
+    'isHide',
+    'isHideTab',
+    'fixedTab',
+    'link',
+    'isIframe',
+    'roles',
+    'showBadge',
+    'showTextBadge',
+    'activePath',
+    'isFullPage'
+  ]
+
+  supportedKeys.forEach((key) => {
+    if (metaSource[key] !== undefined) {
+      meta[key] = metaSource[key]
+    }
+  })
+  meta.isEnable = normalizeLegacyEnableState(metaSource)
+
+  return meta
+}
+
+function buildLegacyAuthItem(node) {
+  const metaSource = node.meta && typeof node.meta === 'object' ? node.meta : node
+  return {
+    id: normalizeLegacyId(node.id),
+    parentId: normalizeLegacyId(node.parentId ?? 0),
+    parentName: node.parentName || '',
+    name: node.name || metaSource.title || '',
+    title: normalizeLegacyTitle(node.name || metaSource.title || ''),
+    route: typeof node.route === 'string' ? node.route : '',
+    component: buildLegacyMenuComponent(node),
+    authMark: metaSource.authMark || metaSource.authority || metaSource.code || '',
+    authority: metaSource.authority || metaSource.authMark || metaSource.code || '',
+    icon: metaSource.icon || '',
+    sort: metaSource.sort ?? 0,
+    status: metaSource.status ?? 1,
+    memo: metaSource.memo || '',
+    type: node.type ?? 1
+  }
+}
+
+function buildLegacyMenuPath(node) {
+  const rawPath = typeof node.route === 'string' && node.route.trim()
+    ? node.route
+    : typeof node.path === 'string'
+      ? node.path
+      : ''
+  return normalizeLegacyPath(rawPath)
+}
+
+function buildLegacyMenuComponent(node) {
+  if (typeof node.component === 'string') {
+    return node.component
+  }
+  return ''
+}
+
+function buildLegacyRouteName(node) {
+  if (typeof node.name === 'string' && node.name.trim()) {
+    return node.name.trim()
+  }
+  if (typeof node.component === 'string' && node.component.trim()) {
+    return node.component.trim()
+  }
+  const path = buildLegacyMenuPath(node)
+  if (path) {
+    return path
+      .split('/')
+      .filter(Boolean)
+      .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
+      .join('')
+  }
+  return `Menu${normalizeLegacyId(node.id)}`
+}
+
+function normalizeLegacyTitle(title) {
+  if (typeof title !== 'string') {
+    return ''
+  }
+  const trimmedTitle = title.trim()
+  if (trimmedTitle.startsWith('menu.')) {
+    return `menus.${trimmedTitle.slice('menu.'.length)}`
+  }
+  return trimmedTitle
+}
+
+function normalizeLegacyPath(path) {
+  if (typeof path !== 'string') {
+    return ''
+  }
+  return path.replace(/^\/+/, '').replace(/\/+$/, '')
+}
+
+function normalizeLegacyId(id) {
+  if (id === null || id === undefined || id === '') {
+    return ''
+  }
+  return String(id)
+}
+
+function normalizeLegacyEnableState(metaSource) {
+  if (metaSource.isEnable !== undefined) {
+    return Boolean(metaSource.isEnable)
+  }
+  if (metaSource.enabled !== undefined) {
+    return Boolean(metaSource.enabled)
+  }
+  if (metaSource.statusBool !== undefined) {
+    return Boolean(metaSource.statusBool)
+  }
+  if (metaSource.status !== undefined) {
+    return Number(metaSource.status) === 1
+  }
+  return true
+}
+
+function isPlainObject(value) {
+  return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
 }
 
 export {
@@ -123,9 +472,17 @@
   fetchUpdateRole,
   fetchDeleteRole,
   fetchGetRoleOptions,
+  fetchRolePrintPage,
+  fetchRolePage,
+  fetchExportRoleReport,
+  fetchGetRoleMany,
   fetchGetDeptTree,
   fetchGetMenuTree,
+  fetchSaveMenu,
+  fetchUpdateMenu,
+  fetchDeleteMenu,
   fetchGetRoleScopeList,
+  fetchGetRoleScopeTree,
   fetchUpdateRoleScope,
   fetchGetUserLoginList,
   fetchGetMenuList

--
Gitblit v1.9.1