Skip to content

Commit

Permalink
feat: custom configuration by url params
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyzyykk committed Jan 5, 2025
1 parent 3f26af1 commit 19b44f2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
* 请求重定向
*/
@Controller
public class MyErrorController implements ErrorController {

@GetMapping("/error")
public String handleError() {
return "redirect:/";
public String handleError(HttpServletRequest request) {
System.out.println("aaa");
// 获取原始请求的参数
String queryString = request.getQueryString();

String redirect = "redirect:/";
// 如果有参数,将其附加到重定向路径上
if(queryString != null && !queryString.isEmpty()) redirect += ("?" + queryString);
return redirect;
}
}
2 changes: 1 addition & 1 deletion backend/terminal/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ spring.servlet.multipart.max-file-size=20MB
spring.servlet.multipart.max-request-size=100MB

# PC端启用窗口
kk.pc.window=true
kk.pc.window=false
2 changes: 1 addition & 1 deletion front/terminal/src/components/ConnectSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div style="cursor: pointer; margin-left: 10px;" @click="doCopy(setInfo.server_user)"><el-icon size="15"><DocumentCopy /></el-icon></div>
</div>
<div class="item-class" style="margin-bottom: 5px;">
<el-dropdown class="no-select form-width" hide-timeout="300" >
<el-dropdown :disabled="isForbidInput" class="no-select form-width" hide-timeout="300" >
<span>{{ setInfo.authType == 0 ? $t('密码') : $t('私钥') }}<el-icon class="el-icon--right"><arrow-down style="cursor: pointer;" /></el-icon></span>
<template #dropdown>
<el-dropdown-menu>
Expand Down
16 changes: 8 additions & 8 deletions front/terminal/src/utils/BaseUrl.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// 上线环境
let http_protocol = window.location.protocol;
let ws_protocol = '';
if(http_protocol == 'https:') ws_protocol = 'wss://';
else ws_protocol = 'ws://';
export const ws_base_url = ws_protocol + window.location.host + '/socket/ssh/';
export const http_base_url = http_protocol + '//' + window.location.host + '/api';
// let http_protocol = window.location.protocol;
// let ws_protocol = '';
// if(http_protocol == 'https:') ws_protocol = 'wss://';
// else ws_protocol = 'ws://';
// export const ws_base_url = ws_protocol + window.location.host + '/socket/ssh/';
// export const http_base_url = http_protocol + '//' + window.location.host + '/api';

// 本地开发环境
// export const ws_base_url = 'ws://localhost:3000/socket/ssh/';
// export const http_base_url = 'http://localhost:3000/api';
export const ws_base_url = 'ws://localhost:3000/socket/ssh/';
export const http_base_url = 'http://localhost:3000/api';

// 在线环境
// export const ws_base_url = 'wss://ssh.kkbpro.com/socket/ssh/';
Expand Down
32 changes: 25 additions & 7 deletions front/terminal/src/views/FrameWork.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export default {
// 终端自适应
const fitAddon = new FitAddon();
// 获取url参数
const getUrlParams = (url) => {
const params = {};
const urlParams = new URLSearchParams(url || window.location.search).entries();
for (const [key, value] of urlParams) {
params[key] = value;
}
return params;
};
// 加载环境变量
const osInfo = ref({});
const options = ref({});
Expand All @@ -136,14 +146,22 @@ export default {
loadTCodes();
const env = ref(null);
const loadEnv = () => {
if(localStorage.getItem('env')) {
env.value = JSON.parse(decrypt(localStorage.getItem('env')));
let nowOpInfo = options.value[env.value['option']];
if(nowOpInfo) env.value = {...env.value,...nowOpInfo};
else env.value.option = '';
}
if(localStorage.getItem('env')) env.value = JSON.parse(decrypt(localStorage.getItem('env')));
else env.value = default_env;
// 切换语言
// url参数
const urlParams = getUrlParams();
env.value = {...env.value,...urlParams};
// session参数
let sessionEnv = {};
if(sessionStorage.getItem('env')) sessionEnv = JSON.parse(decrypt(sessionStorage.getItem('env')));
env.value = {...env.value,...sessionEnv};
// option
let nowOpInfo = options.value[env.value['option']];
if(nowOpInfo) env.value = {...env.value,...nowOpInfo};
else env.value.option = '';
// lang
i18n.global.locale = env.value.lang || 'en';
};
loadEnv();
Expand Down

0 comments on commit 19b44f2

Please sign in to comment.