import request from "@/sheep/utils/request" import { encryption } from "@/sheep/utils/encryption" // 将 Basic Auth 字符串提取为常量 const BASIC_AUTH = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_APP_CLIENT) // 定义接口类型 interface LoginParams { username: string password: string randomStr: string code: string grant_type: string scope: string } export default { // 获取用户信息 userInfo: (): Promise => request({ url: "/admin/user/info", method: "GET", custom: { showLoading: false, loadingMsg: "登录中", }, }), // 浙政钉授权 auth: (token: string): Promise => request({ url: `/thirdparty/thirdPartyOAth2/zzdsso/${token}`, method: "GET", custom: { showLoading: false, loadingMsg: "授权中", }, }), // 诗画授权 authsh: (params: { accountId: string; sessionId: string }) => request({ url: `/sys/auth/shjnsso`, method: "POST", custom: { showLoading: false, loadingMsg: "授权中", }, data: params, }), // 刷新token refreshToken: (params: { refreshToken: string }) => request({ url: `/sys/auth/refresh-token`, method: "POST", params, custom: { showLoading: false, }, }), // 登录 login: (params: LoginParams) => { const { username, password, randomStr, code, grant_type, scope } = params const encPassword = encryption(password, import.meta.env.VITE_PWD_ENC_KEY) return request({ url: `/auth/oauth2/token`, method: "POST", params: { username, password, randomStr, code, grant_type, scope, }, data: { password }, header: { skipToken: true, Authorization: BASIC_AUTH, "content-type": "application/x-www-form-urlencoded", }, custom: { showLoading: false, }, }) }, }