From 853ad5e11ac93ed3203a4130ff7fb6f6a5146d5a Mon Sep 17 00:00:00 2001 From: hyunfa <1598047833@qq.com> Date: Mon, 22 Apr 2024 17:20:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=BC=B9=E7=AA=97=20#=20Reviewed,=20transact?= =?UTF-8?q?ion=20id:=208151?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/build/webpack.base.conf.ts | 6 ++++ frontend/build/webpack.dev.conf.ts | 6 ++++ frontend/login_success.html | 13 ++++++++ frontend/package.json | 1 + frontend/src/App.vue | 33 +++++++++---------- frontend/src/components/common/navigation.vue | 7 +++- static/login_success.html | 13 ++++++++ 7 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 frontend/login_success.html create mode 100644 static/login_success.html diff --git a/frontend/build/webpack.base.conf.ts b/frontend/build/webpack.base.conf.ts index 3ccf7b8ad..ce44e6227 100644 --- a/frontend/build/webpack.base.conf.ts +++ b/frontend/build/webpack.base.conf.ts @@ -179,6 +179,12 @@ const baseConfig: webpack.Configuration = { from: resolve('static/images'), to: resolve('dist/static/images'), toType: 'dir' + }, + // 成功登录页面构建 + { + from: resolve('./login_success.html'), + to: `${config.build.assetsRoot}/login_success.html`, + toType: 'file' }] }), new ProgressBarPlugin({ diff --git a/frontend/build/webpack.dev.conf.ts b/frontend/build/webpack.dev.conf.ts index 59d5f1796..4d66dff44 100644 --- a/frontend/build/webpack.dev.conf.ts +++ b/frontend/build/webpack.dev.conf.ts @@ -177,6 +177,12 @@ const webpackConfig = merge(baseConf, { inject: true }), + new HtmlWebpackPlugin({ + filename: 'login_success.html', + template: 'login_success.html', + inject: true + }), + // new AnalyzerPlugin.BundleAnalyzerPlugin() // new FriendlyErrorsPlugin() ] diff --git a/frontend/login_success.html b/frontend/login_success.html new file mode 100644 index 000000000..9b3ee2b9d --- /dev/null +++ b/frontend/login_success.html @@ -0,0 +1,13 @@ + + + + + 登录成功 + + + + + \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index ba5214b76..30b75c744 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -44,6 +44,7 @@ "dependencies": { "@blueking/crypto-js-sdk": "0.0.4", "@blueking/ip-selector": "0.2.0-beta", + "@blueking/login-modal": "^1.0.1", "@blueking/notice-component-vue2": "~2.0.1", "@blueking/paas-login": "0.0.9", "@icon-cool/bk-icon-node-manager": "latest", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 71f8f57eb..c4a8236ef 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -24,6 +24,7 @@ import { IAuthApply, IBkBiz } from '@/types/index'; import BkPaasLogin from '@blueking/paas-login/dist/paas-login.umd'; import NoticeComponent from '@blueking/notice-component-vue2'; import '@blueking/notice-component-vue2/dist/style.css'; +import { showLoginModal } from '@blueking/login-modal'; @Component({ name: 'app', @@ -96,30 +97,28 @@ export default class App extends Vue { private mounted() { window.LoginModal = this.$refs.login; bus.$on('show-login-modal', () => { + // static_url: '/static/' or '/' + const static_url = window.PROJECT_CONFIG?.STATIC_URL ? window.PROJECT_CONFIG.STATIC_URL : '/'; + // 登录成功之后的回调地址,用于执行关闭登录窗口或刷新父窗口页面等动作 + const successUrl = `${window.location.origin}${static_url}login_success.html`; const { href, protocol } = window.location; + let loginUrl = ''; if (process.env.NODE_ENV === 'development') { - window.location.href = LOGIN_DEV_URL + href; + // 本地登录地址不需要bknodeman前缀 + loginUrl = LOGIN_DEV_URL.replace('bknodeman.','') + encodeURIComponent(successUrl); } else { - // 目前仅ieod取消登录弹框 - // if (window.PROJECT_CONFIG.RUN_VER === 'ieod') { - let loginUrl = window.PROJECT_CONFIG.LOGIN_URL; + loginUrl = window.PROJECT_CONFIG.LOGIN_URL; if (!/http(s)?:\/\//.test(loginUrl)) { loginUrl = `${protocol}//${loginUrl}`; } - if (!loginUrl.includes('?')) { - loginUrl += '?'; - } - window.location.href = `${loginUrl}&c_url=${encodeURIComponent(href)}`; - // } else { - // const res = data?.data || {}; - // if (res.has_plain) { - // MainStore.setLoginUrl(res.login_url); - // window.LoginModal && window.LoginModal.show(); - // } else { - // window.location.href = res.login_url ? res.login_url : (LOGIN_DEV_URL + href); - // } - // } } + // 处理登录地址为登录小窗需要的格式,主要是设置c_url参数 + const loginURL = new URL(loginUrl); + loginURL.searchParams.set('c_url', successUrl); + const pathname = loginURL.pathname.endsWith('/') ? loginURL.pathname : `${loginURL.pathname}/`; + loginUrl = `${loginURL.origin}${pathname}plain/${loginURL.search}`; + // 使用登录弹框登录 + showLoginModal({ loginUrl }); }); bus.$on('show-permission-modal', (data: { trigger: 'request' | 'click', params: IAuthApply }) => { this.permissionModal.show(data); diff --git a/frontend/src/components/common/navigation.vue b/frontend/src/components/common/navigation.vue index 5bffe0c31..1c29956dd 100644 --- a/frontend/src/components/common/navigation.vue +++ b/frontend/src/components/common/navigation.vue @@ -132,6 +132,7 @@ import ExceptionPage from '@/components/exception/exception-page.vue'; import routerBackMixin from '@/common/router-back-mixin'; import { bus } from '@/common/bus'; import { INavConfig } from '@/types'; +import { showLoginModal } from '@blueking/login-modal'; interface IUserItem { id: string @@ -369,7 +370,11 @@ export default class NodemanNavigation extends Mixins(routerBackMixin) { private async handleUser(userItem: IUserItem) { if (userItem.id === 'LOGOUT') { if (NODE_ENV === 'development') { - window.location.href = LOGIN_DEV_URL + window.location.href; + const successUrl = `${window.location.origin}/login_success.html`; + // 不需要bknodeman前缀 + const loginUrl = LOGIN_DEV_URL.replace('bknodeman.','') + encodeURIComponent(successUrl); + // 使用登录弹框登录 + showLoginModal({ loginUrl }); } else { this.$http.get?.(`${window.PROJECT_CONFIG.SITE_URL}logout/`); // window.location.href = `${window.PROJECT_CONFIG.BK_PAAS_HOST}/console/accounts/logout/`; diff --git a/static/login_success.html b/static/login_success.html new file mode 100644 index 000000000..9b3ee2b9d --- /dev/null +++ b/static/login_success.html @@ -0,0 +1,13 @@ + + + + + 登录成功 + + + + + \ No newline at end of file