From e9283ffe6822b12ec5dd2ccf4dc13a369b227a61 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期一, 30 三月 2026 08:32:06 +0800
Subject: [PATCH] chore: sync rsf-design from isolated worktree

---
 rsf-design/src/api/auth.js |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 104 insertions(+), 12 deletions(-)

diff --git a/rsf-design/src/api/auth.js b/rsf-design/src/api/auth.js
index b7c9fbb..c420267 100644
--- a/rsf-design/src/api/auth.js
+++ b/rsf-design/src/api/auth.js
@@ -1,19 +1,111 @@
 import request from '@/utils/http'
+
+function buildLoginPayload({ username, password }) {
+  return { username, password }
+}
+
+function normalizeLoginParams(params) {
+  return {
+    username: params?.username || params?.userName || '',
+    password: params?.password
+  }
+}
+
+function normalizeLoginResponse(payload) {
+  const data = payload?.data || payload || {}
+  return {
+    accessToken: data.accessToken || '',
+    refreshToken: data.refreshToken || '',
+    user: data.user || {}
+  }
+}
+
+function normalizeUserInfo(data) {
+  const normalizedRoles = normalizeRoleCodes(data?.roles)
+  const normalizedButtons = normalizeButtonMarks(data)
+  return {
+    ...data,
+    roles: normalizedRoles,
+    buttons: normalizedButtons
+  }
+}
+
+function normalizeRoleCodes(roles) {
+  if (!Array.isArray(roles)) {
+    return []
+  }
+
+  return Array.from(
+    new Set(
+      roles
+        .map((item) => {
+          if (typeof item === 'string') {
+            return item.trim()
+          }
+          if (item && typeof item === 'object') {
+            return item.code || item.name || ''
+          }
+          return ''
+        })
+        .filter(Boolean)
+    )
+  )
+}
+
+function normalizeButtonMarks(data) {
+  const directButtons = Array.isArray(data?.buttons) ? data.buttons : []
+  const authorityButtons = Array.isArray(data?.authorities)
+    ? data.authorities.map((item) => item?.authority || item?.authMark || '')
+    : []
+
+  return Array.from(
+    new Set(
+      [...directButtons, ...authorityButtons]
+        .map((item) => (typeof item === 'string' ? item.trim() : ''))
+        .filter(Boolean)
+    )
+  )
+}
+
 function fetchLogin(params) {
-  return request.post({
-    url: '/api/auth/login',
-    params
-    // showSuccessMessage: true // 鏄剧ず鎴愬姛娑堟伅
-    // showErrorMessage: false // 涓嶆樉绀洪敊璇秷鎭�
-  })
+  return request
+    .post({
+      url: '/login',
+      params: buildLoginPayload(normalizeLoginParams(params))
+      // showSuccessMessage: true // 鏄剧ず鎴愬姛娑堟伅
+      // showErrorMessage: false // 涓嶆樉绀洪敊璇秷鎭�
+    })
+    .then((response) => {
+      const normalized = normalizeLoginResponse(response)
+      return {
+        token: normalized.accessToken,
+        accessToken: normalized.accessToken,
+        refreshToken: normalized.refreshToken,
+        user: normalized.user
+      }
+    })
 }
 function fetchGetUserInfo() {
+  return request
+    .get({
+      url: '/auth/user'
+      // 鑷畾涔夎姹傚ご
+      // headers: {
+      //   'X-Custom-Header': 'your-custom-value'
+      // }
+    })
+    .then((response) => normalizeUserInfo(response))
+}
+function fetchGetMenuList() {
   return request.get({
-    url: '/api/user/info'
-    // 鑷畾涔夎姹傚ご
-    // headers: {
-    //   'X-Custom-Header': 'your-custom-value'
-    // }
+    url: '/auth/menu'
   })
 }
-export { fetchGetUserInfo, fetchLogin }
+export {
+  buildLoginPayload,
+  fetchGetMenuList,
+  fetchGetUserInfo,
+  fetchLogin,
+  normalizeLoginResponse,
+  normalizeUserInfo
+}

--
Gitblit v1.9.1