zhanghaijun пре 1 година
родитељ
комит
4d544e25d1

+ 1 - 2
.env.development

@@ -10,5 +10,4 @@ VITE_API_URL = /api
 VITE_DROP_CONSOLE = false
 VITE_DROP_CONSOLE = false
 
 
 # 本地开发代理的目标后端地址(仅开发环境生效,用于解决跨域)
 # 本地开发代理的目标后端地址(仅开发环境生效,用于解决跨域)
-# VITE_API_PROXY_URL = https://m1.apifoxmock.com/m1/7156555-6880574-default
-VITE_API_PROXY_URL = http://haijunit.icu/teacher/api
+VITE_API_PROXY_URL = http://haijunit.icu/course/api

+ 1 - 1
.env.mock

@@ -7,7 +7,7 @@ VITE_BASE_URL = ./
 VITE_API_URL = https://m1.apifoxmock.com/m1/7156555-6880574-default
 VITE_API_URL = https://m1.apifoxmock.com/m1/7156555-6880574-default
 
 
 # 权限模式( frontend | backend )
 # 权限模式( frontend | backend )
-VITE_ACCESS_MODE = backend
+VITE_ACCESS_MODE = frontend
 
 
 # Delete console
 # Delete console
 VITE_DROP_CONSOLE = true
 VITE_DROP_CONSOLE = true

+ 1 - 1
.env.production

@@ -4,7 +4,7 @@
 VITE_BASE_URL = ./
 VITE_BASE_URL = ./
 
 
 # API 地址前缀
 # API 地址前缀
-VITE_API_URL = /teacher/api
+VITE_API_URL = /course/api
 
 
 # Delete console
 # Delete console
 VITE_DROP_CONSOLE = true
 VITE_DROP_CONSOLE = true

+ 1 - 0
src/api/auth.api.ts

@@ -13,6 +13,7 @@ export interface UserItem {
   userName: string /** 用户名 */
   userName: string /** 用户名 */
   UserType: number /** 用户类型 */
   UserType: number /** 用户类型 */
   roleCodes: string[] /** 用户角色编码 */
   roleCodes: string[] /** 用户角色编码 */
+  buttons: string[] /** 用户按钮编码 */
 }
 }
 
 
 export class AuthService {
 export class AuthService {

+ 11 - 15
src/router/guards/beforeEach.ts

@@ -15,7 +15,6 @@ import { asyncRoutes } from '../routes/asyncRoutes'
 import { loadingService } from '@/utils/ui'
 import { loadingService } from '@/utils/ui'
 import { useCommon } from '@/composables/useCommon'
 import { useCommon } from '@/composables/useCommon'
 import { useWorktabStore } from '@/store/modules/worktab'
 import { useWorktabStore } from '@/store/modules/worktab'
-import { UserService } from '@/api/sys/user'
 
 
 // 前端权限模式 loading 关闭延时,提升用户体验
 // 前端权限模式 loading 关闭延时,提升用户体验
 const LOADING_DELAY = 50
 const LOADING_DELAY = 50
@@ -135,20 +134,17 @@ async function handleDynamicRoutes(to: RouteLocationNormalized, from: RouteLocat
     loadingService.showLoading()
     loadingService.showLoading()
 
 
     // 获取用户信息
     // 获取用户信息
-    const userStore = useUserStore()
-    try {
-      const data = await UserService.getUserInfo()
-      let permCode = data.buttons
-      if (useCommon().isFrontendMode.value && !permCode) {
-        permCode = await UserService.getPermCode()
-      }
-      userStore.setUserInfo({
-        ...data,
-        buttons: permCode
-      })
-    } catch (error) {
-      console.error('获取用户信息失败', error)
-    }
+    // const userStore = useUserStore()
+    // try {
+    // const data = await UserService.getUserInfo()
+    // const permCode = data.buttons
+    // if (useCommon().isFrontendMode.value && !permCode) {
+    //   permCode = await UserService.getPermCode()
+    // }
+    // userStore.setUserInfo({ ...data, buttons: permCode })
+    // } catch (error) {
+    //   console.error('获取用户信息失败', error)
+    // }
 
 
     await getMenuData(router)
     await getMenuData(router)
 
 

+ 12 - 9
src/utils/http/server.axios.ts

@@ -41,8 +41,10 @@ export class RequestHttp {
      *  服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
      *  服务器换返回信息 -> [拦截统一处理] -> 客户端JS获取到信息
      */
      */
     this.service.interceptors.response.use(
     this.service.interceptors.response.use(
-      (response: AxiosResponse<Http.BaseResponse>) => {
-        const { code, msg } = response.data
+      async (response: AxiosResponse<ApiResponse>) => {
+        const res = response.data as ApiResponse
+        const { code, msg } = res
+        console.log('response', response)
         if (code === ApiStatus.success) return response
         if (code === ApiStatus.success) return response
         if (code === ApiStatus.unauthorized) handleUnauthorizedError(msg)
         if (code === ApiStatus.unauthorized) handleUnauthorizedError(msg)
         throw new Error(msg || $t('httpMsg.requestFailed'))
         throw new Error(msg || $t('httpMsg.requestFailed'))
@@ -54,22 +56,23 @@ export class RequestHttp {
     )
     )
   }
   }
 
 
-  public request<T = any>(config: ExtendedAxiosRequestConfig): Promise<T> {
+  public async request<T = unknown>(config: ExtendedAxiosRequestConfig): Promise<ApiResponse<T>> {
     if (['POST', 'PUT'].includes(config.method?.toUpperCase() || '') && config.params && !config.data) {
     if (['POST', 'PUT'].includes(config.method?.toUpperCase() || '') && config.params && !config.data) {
       config.data = config.params
       config.data = config.params
       config.params = undefined
       config.params = undefined
     }
     }
-    return this.service.request(config)
+    const { data } = await this.service.request(config)
+    return data as ApiResponse<T>
   }
   }
   /**
   /**
    * @description 常用请求方法封装
    * @description 常用请求方法封装
    */
    */
   public get<T>(url: string, params?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
   public get<T>(url: string, params?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
-    return this.service.get(url, { params, ..._object })
+    return this.request({ url, params, ..._object })
   }
   }
 
 
   public post<T>(url: string, data?: object | string, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
   public post<T>(url: string, data?: object | string, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
-    return this.service.post(url, data, _object)
+    return this.request({ url, method: 'POST', data, ..._object })
   }
   }
 
 
   public postPage<T>(url: string, data?: object | string, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<ApiResponsePage<T>>> {
   public postPage<T>(url: string, data?: object | string, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<ApiResponsePage<T>>> {
@@ -77,11 +80,11 @@ export class RequestHttp {
   }
   }
 
 
   public put<T>(url: string, data?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
   public put<T>(url: string, data?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
-    return this.service.put(url, data, _object)
+    return this.request({ url, method: 'PUT', data, ..._object })
   }
   }
 
 
   public delete<T>(url: string, params?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
   public delete<T>(url: string, params?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<ApiResponse<T>> {
-    return this.service.delete(url, { params, ..._object })
+    return this.request({ url, method: 'DELETE', params, ..._object })
   }
   }
 
 
   public download(url: string, params?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<BlobPart> {
   public download(url: string, params?: object, _object: ExtendedAxiosRequestConfig = {}): Promise<BlobPart> {
@@ -103,6 +106,6 @@ export class RequestHttp {
       ..._object,
       ..._object,
       headers: { 'Content-Type': 'multipart/form-data', ..._object?.headers }
       headers: { 'Content-Type': 'multipart/form-data', ..._object?.headers }
     }
     }
-    return this.service.post(url, formData, finalConfig)
+    return this.post(url, formData, finalConfig)
   }
   }
 }
 }

+ 1 - 1
src/utils/http/server.type.ts

@@ -11,7 +11,7 @@ export interface ApiResponsePage<T = unknown> {
 }
 }
 
 
 export enum ApiStatus {
 export enum ApiStatus {
-  success = 0, // 成功
+  success = 200, // 成功
   error = 400, // 错误
   error = 400, // 错误
   unauthorized = 401, // 未授权
   unauthorized = 401, // 未授权
   forbidden = 403, // 禁止访问
   forbidden = 403, // 禁止访问

+ 0 - 1
src/views/auth/login/index.vue

@@ -138,7 +138,6 @@
       const { username, password } = formData
       const { username, password } = formData
       const { data } = await AuthService.login({ userName: username, password })
       const { data } = await AuthService.login({ userName: username, password })
       const { token } = data!
       const { token } = data!
-
       // 验证token
       // 验证token
       if (!token) {
       if (!token) {
         throw new Error('Login failed - no token received')
         throw new Error('Login failed - no token received')