Skip to content

Commit 64f80a9

Browse files
authored
feat: 增加系统 IP 设置,实现容器端口跳转功能 (#1479)
1 parent 847c14d commit 64f80a9

File tree

12 files changed

+156
-10
lines changed

12 files changed

+156
-10
lines changed

backend/app/dto/setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "time"
55
type SettingInfo struct {
66
UserName string `json:"userName"`
77
Email string `json:"email"`
8+
SystemIP string `json:"systemIP"`
89
SystemVersion string `json:"systemVersion"`
910

1011
SessionTimeout string `json:"sessionTimeout"`

backend/init/migration/migrations/init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ var AddMfaInterval = &gormigrate.Migration{
407407
if err := tx.Create(&model.Setting{Key: "MFAInterval", Value: "30"}).Error; err != nil {
408408
return err
409409
}
410+
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
411+
return err
412+
}
410413
return nil
411414
},
412415
}

frontend/src/api/interface/setting.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export namespace Setting {
55
userName: string;
66
password: string;
77
email: string;
8+
systemIP: string;
89
systemVersion: string;
910

1011
sessionTimeout: number;

frontend/src/lang/modules/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,8 @@ const message = {
969969
sessionTimeoutError: 'The minimum timeout is 300 seconds',
970970
sessionTimeoutHelper:
971971
'If you do not operate the panel for more than {0} seconds, the panel automatically logs out',
972+
systemIP: 'System IP',
973+
systemIPWarning: 'Please set the system IP in the panel settings first.',
972974
syncTime: 'Server time',
973975
timeZone: 'Time Zone',
974976
timeZoneChangeHelper: 'Changing the time zone requires restarting the service. Do you want to continue?',

frontend/src/lang/modules/zh.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,8 @@ const message = {
949949
sessionTimeout: '超时时间',
950950
sessionTimeoutError: '最小超时时间为 300 秒',
951951
sessionTimeoutHelper: '如果用户超过 {0} 秒未操作面板,面板将自动退出登录',
952+
systemIP: '服务器 IP',
953+
systemIPWarning: '请先在面板设置中设置服务器 IP',
952954
syncTime: '服务器时间',
953955
timeZone: '系统时区',
954956
timeZoneChangeHelper: '系统时区修改需要重启服务,是否继续?',

frontend/src/views/container/container/index.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@
9090
<div v-if="row.ports">
9191
<div v-for="(item, index) in row.ports" :key="index">
9292
<div v-if="row.expand || (!row.expand && index < 3)">
93-
<el-tag class="tagMargin">{{ item }}</el-tag>
93+
<el-button
94+
@click="goDashboard(item)"
95+
class="tagMargin"
96+
icon="Position"
97+
type="primary"
98+
plain
99+
size="small"
100+
>
101+
{{ item }}
102+
</el-button>
94103
</div>
95104
</div>
96105
<div v-if="!row.expand && row.ports.length > 3">
@@ -154,8 +163,9 @@ import { Container } from '@/api/interface/container';
154163
import { ElMessageBox } from 'element-plus';
155164
import i18n from '@/lang';
156165
import router from '@/routers';
157-
import { MsgSuccess } from '@/utils/message';
166+
import { MsgError, MsgSuccess } from '@/utils/message';
158167
import { computeSize } from '@/utils/util';
168+
import { getSettingInfo } from '@/api/modules/setting';
159169
160170
const loading = ref();
161171
const data = ref();
@@ -184,6 +194,20 @@ const loadStatus = async () => {
184194
loading.value = false;
185195
});
186196
};
197+
198+
const goDashboard = async (port: any) => {
199+
if (!port || port.indexOf(':') === -1) {
200+
return;
201+
}
202+
let portEx = port.split(':')[0];
203+
const res = await getSettingInfo();
204+
if (!res.data.systemIP) {
205+
MsgError(i18n.global.t('setting.systemIPWarning'));
206+
return;
207+
}
208+
window.open(`http://${res.data.systemIP}:${portEx}`, '_blank');
209+
};
210+
187211
const goSetting = async () => {
188212
router.push({ name: 'ContainerSetting' });
189213
};

frontend/src/views/container/container/operate/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ const acceptParams = (params: DialogProps): void => {
257257
item.host = item.hostPort;
258258
}
259259
dialogData.value.rowData.volumes = dialogData.value.rowData.volumes || [];
260-
console.log(dialogData.value.rowData.cpuShares);
261260
}
262261
loadLimit();
263262
loadImageOptions();

frontend/src/views/database/mysql/index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ import { GetAppPort } from '@/api/modules/app';
164164
import router from '@/routers';
165165
import { MsgError, MsgSuccess } from '@/utils/message';
166166
import useClipboard from 'vue-clipboard3';
167+
import { getSettingInfo } from '@/api/modules/setting';
167168
const { toClipboard } = useClipboard();
168169
169170
const loading = ref(false);
@@ -261,9 +262,12 @@ const goDashboard = async () => {
261262
phpVisiable.value = true;
262263
return;
263264
}
264-
let href = window.location.href;
265-
let ipLocal = href.split('//')[1].split(':')[0];
266-
window.open(`http://${ipLocal}:${phpadminPort.value}`, '_blank');
265+
const res = await getSettingInfo();
266+
if (!res.data.systemIP) {
267+
MsgError(i18n.global.t('setting.systemIPWarning'));
268+
return;
269+
}
270+
window.open(`http://${res.data.systemIP}:${phpadminPort.value}`, '_blank');
267271
};
268272
const getAppDetail = (key: string) => {
269273
router.push({ name: 'AppDetail', params: { appKey: key } });

frontend/src/views/database/redis/index.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ import { nextTick, onBeforeUnmount, ref } from 'vue';
6565
import { App } from '@/api/interface/app';
6666
import { GetAppPort } from '@/api/modules/app';
6767
import router from '@/routers';
68+
import { MsgError } from '@/utils/message';
69+
import { getSettingInfo } from '@/api/modules/setting';
70+
import i18n from '@/lang';
6871
6972
const loading = ref(false);
7073
const maskShow = ref(true);
@@ -94,9 +97,12 @@ const goDashboard = async () => {
9497
commandVisiable.value = true;
9598
return;
9699
}
97-
let href = window.location.href;
98-
let ipLocal = href.split('//')[1].split(':')[0];
99-
window.open(`http://${ipLocal}:${redisCommandPort.value}`, '_blank');
100+
const res = await getSettingInfo();
101+
if (!res.data.systemIP) {
102+
MsgError(i18n.global.t('setting.systemIPWarning'));
103+
return;
104+
}
105+
window.open(`http://${res.data.systemIP}:${redisCommandPort.value}`, '_blank');
100106
};
101107
const getAppDetail = (key: string) => {
102108
router.push({ name: 'AppDetail', params: { appKey: key } });

frontend/src/views/host/file-management/upload/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ const handleExceed: UploadProps['onExceed'] = (files) => {
8282
};
8383
8484
const hadleSuccess: UploadProps['onSuccess'] = (res, file) => {
85-
console.log(file.name);
8685
file.status = 'success';
8786
};
8887

0 commit comments

Comments
 (0)