diff --git a/.env.dev b/.env.dev index 3b85e481..a52eec30 100644 --- a/.env.dev +++ b/.env.dev @@ -16,7 +16,7 @@ VITE_API_BASEPATH=/dev-api VITE_API_URL=/admin-api # 打包路径 -VITE_BASE_PATH=/dist-dev/ +VITE_BASE_PATH=/ # 是否删除debugger VITE_DROP_DEBUGGER=false diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 2255e3cf..24f356ed 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -1,16 +1,19 @@ import request from '@/config/axios' import { getRefreshToken } from '@/utils/auth' import type { UserLoginVO } from './types' +import { service } from '@/config/axios/service' export interface CodeImgResult { captchaOnOff: boolean img: string uuid: string } + export interface SmsCodeVO { mobile: string scene: number } + export interface SmsLoginVO { mobile: string code: string @@ -71,3 +74,51 @@ export const getCode = (data) => { export const reqCheck = (data) => { return request.postOriginal({ url: 'system/captcha/check', data }) } + +// ========== OAUTH 2.0 相关 ========== +export type scopesType = string[] +export interface paramsType { + responseType: string + clientId: string + redirectUri: string + state: string + scopes: scopesType +} +export const getAuthorize = (clientId) => { + return request.get({ url: '/system/oauth2/authorize?clientId=' + clientId }) +} + +export function authorize( + responseType: string, + clientId: string, + redirectUri: string, + state: string, + autoApprove: boolean, + checkedScopes: scopesType, + uncheckedScopes: scopesType +) { + // 构建 scopes + const scopes = {} + for (const scope of checkedScopes) { + scopes[scope] = true + } + for (const scope of uncheckedScopes) { + scopes[scope] = false + } + // 发起请求 + return service({ + url: '/system/oauth2/authorize', + headers: { + 'Content-type': 'application/x-www-form-urlencoded' + }, + params: { + response_type: responseType, + client_id: clientId, + redirect_uri: redirectUri, + state: state, + auto_approve: autoApprove, + scope: JSON.stringify(scopes) + }, + method: 'post' + }) +} diff --git a/src/config/axios/service.ts b/src/config/axios/service.ts index fb205a6b..d37dfb06 100644 --- a/src/config/axios/service.ts +++ b/src/config/axios/service.ts @@ -1,8 +1,8 @@ import axios, { + AxiosError, AxiosInstance, AxiosRequestHeaders, AxiosResponse, - AxiosError, InternalAxiosRequestConfig } from 'axios' @@ -230,7 +230,7 @@ const handleAuthorized = () => { wsCache.clear() removeToken() isRelogin.show = false - window.location.href = import.meta.env.VITE_BASE_PATH + window.location.href = '/login?redirect=/sso?' + window.location.href.split('?')[1] }) } return Promise.reject(t('sys.api.timeoutMessage')) diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 7c5742c4..da706bb3 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -129,6 +129,12 @@ export default { btnMobile: '手机登录', btnQRCode: '二维码登录', qrcode: '扫描二维码登录', + sso: { + user: { + read: '访问你的个人信息', + write: '修改你的个人信息' + } + }, btnRegister: '注册', SmsSendMsg: '验证码已发送' }, @@ -352,6 +358,7 @@ export default { login: { backSignIn: '返回', signInFormTitle: '登录', + ssoFormTitle: '三方授权', mobileSignInFormTitle: '手机登录', qrSignInFormTitle: '二维码登录', signUpFormTitle: '注册', diff --git a/src/router/index.ts b/src/router/index.ts index 02d913f8..8f66ca31 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,11 +1,11 @@ import type { App } from 'vue' import type { RouteRecordRaw } from 'vue-router' -import { createRouter, createWebHashHistory } from 'vue-router' +import { createRouter, createWebHistory } from 'vue-router' import remainingRouter from './modules/remaining' // 创建路由实例 const router = createRouter({ - history: createWebHashHistory(), // createWebHashHistory URL带#,createWebHistory URL不带# + history: createWebHistory(), // createWebHashHistory URL带#,createWebHistory URL不带# strict: true, routes: remainingRouter as RouteRecordRaw[], scrollBehavior: () => ({ left: 0, top: 0 }) diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 11420a07..8886e388 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -185,6 +185,16 @@ const remainingRouter: AppRouteRecordRaw[] = [ noTagsView: true } }, + { + path: '/sso', + component: () => import('@/views/Login/Login.vue'), + name: 'SSOLogin', + meta: { + hidden: true, + title: t('router.login'), + noTagsView: true + } + }, { path: '/403', component: () => import('@/views/Error/403.vue'), diff --git a/src/types/auto-components.d.ts b/src/types/auto-components.d.ts index 2d620925..431f086f 100644 --- a/src/types/auto-components.d.ts +++ b/src/types/auto-components.d.ts @@ -21,15 +21,14 @@ declare module '@vue/runtime-core' { Descriptions: typeof import('./../components/Descriptions/src/Descriptions.vue')['default'] Dialog: typeof import('./../components/Dialog/src/Dialog.vue')['default'] DictTag: typeof import('./../components/DictTag/src/DictTag.vue')['default'] - DocAlert: typeof import('./../components/DocAlert/index.vue')['default'] Echart: typeof import('./../components/Echart/src/Echart.vue')['default'] Editor: typeof import('./../components/Editor/src/Editor.vue')['default'] - ElAlert: typeof import('element-plus/es')['ElAlert'] ElBadge: typeof import('element-plus/es')['ElBadge'] ElButton: typeof import('element-plus/es')['ElButton'] ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup'] ElCard: typeof import('element-plus/es')['ElCard'] ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] + ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup'] ElCol: typeof import('element-plus/es')['ElCol'] ElCollapse: typeof import('element-plus/es')['ElCollapse'] ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem'] @@ -74,12 +73,8 @@ declare module '@vue/runtime-core' { ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabs: typeof import('element-plus/es')['ElTabs'] - ElTag: typeof import('element-plus/es')['ElTag'] - ElTimeline: typeof import('element-plus/es')['ElTimeline'] - ElTimelineItem: typeof import('element-plus/es')['ElTimelineItem'] ElTooltip: typeof import('element-plus/es')['ElTooltip'] ElTree: typeof import('element-plus/es')['ElTree'] - ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect'] ElUpload: typeof import('element-plus/es')['ElUpload'] Error: typeof import('./../components/Error/src/Error.vue')['default'] FlowCondition: typeof import('./../components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue')['default'] diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue index a513b0ca..a0186ab7 100644 --- a/src/views/Login/Login.vue +++ b/src/views/Login/Login.vue @@ -9,19 +9,19 @@ >