fix: 增加数据库 dashboard 工具跳转

This commit is contained in:
ssongliu
2022-12-04 19:20:36 +08:00
committed by ssongliu
parent 1c4da6d88b
commit c1b7e5edd7
15 changed files with 121 additions and 37 deletions

View File

@@ -53,6 +53,20 @@ func (b *BaseApi) CheckAppInstalled(c *gin.Context) {
helper.SuccessWithData(c, checkData) helper.SuccessWithData(c, checkData)
} }
func (b *BaseApi) LoadPort(c *gin.Context) {
key, ok := c.Params.Get("key")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path"))
return
}
port, err := appInstallService.LoadPort(key)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, port)
}
func (b *BaseApi) DeleteCheck(c *gin.Context) { func (b *BaseApi) DeleteCheck(c *gin.Context) {
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId") appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")

View File

@@ -79,6 +79,14 @@ func (a AppInstallService) CheckExist(key string) (*dto.CheckInstalled, error) {
return res, nil return res, nil
} }
func (a AppInstallService) LoadPort(key string) (int64, error) {
app, err := appInstallRepo.LoadBaseInfoByKey(key)
if err != nil {
return int64(0), nil
}
return app.Port, nil
}
func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstalled, error) { func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstalled, error) {
var installs []model.AppInstall var installs []model.AppInstall
var err error var err error

View File

@@ -240,7 +240,7 @@ func (u *MysqlService) DeleteCheck(id uint) ([]string, error) {
apps, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithResourceId(app.ID), appInstallResourceRepo.WithLinkId(db.ID)) apps, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithResourceId(app.ID), appInstallResourceRepo.WithLinkId(db.ID))
for _, app := range apps { for _, app := range apps {
appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.ID)) appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId))
if appInstall.ID != 0 { if appInstall.ID != 0 {
appInUsed = append(appInUsed, appInstall.Name) appInUsed = append(appInUsed, appInstall.Name)
} }

View File

@@ -22,6 +22,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) {
appRouter.POST("/install", baseApi.InstallApp) appRouter.POST("/install", baseApi.InstallApp)
appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions) appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions)
appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled) appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled)
appRouter.GET("/installed/loadport/:key", baseApi.LoadPort)
appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck) appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck)
appRouter.POST("/installed", baseApi.SearchAppInstalled) appRouter.POST("/installed", baseApi.SearchAppInstalled)
appRouter.POST("/installed/op", baseApi.OperateInstalled) appRouter.POST("/installed/op", baseApi.OperateInstalled)

View File

@@ -30,6 +30,10 @@ export const SearchAppInstalled = (search: App.AppInstallSearch) => {
return http.post<ResPage<App.AppInstalled>>('apps/installed', search); return http.post<ResPage<App.AppInstalled>>('apps/installed', search);
}; };
export const GetAppPort = (key: string) => {
return http.get<number>(`apps/installed/loadport/${key}`);
};
export const CheckAppInstalled = (key: string) => { export const CheckAppInstalled = (key: string) => {
return http.get<App.CheckInstalled>(`apps/installed/check/${key}`); return http.get<App.CheckInstalled>(`apps/installed/check/${key}`);
}; };

View File

@@ -184,7 +184,7 @@ export default {
jsInfo: 'The popular Open source fortress machine', jsInfo: 'The popular Open source fortress machine',
msInfo: 'One-stop open source continuous testing platform', msInfo: 'One-stop open source continuous testing platform',
koInfo: 'Open source lightweight Kubernetes distribution', koInfo: 'Open source lightweight Kubernetes distribution',
kubepiInfo: 'Modern open source K8s panel', kubepiInfo: 'Modern open source Kubernetes panel',
goInstall: 'Go install', goInstall: 'Go install',
}, },
tabs: { tabs: {
@@ -276,6 +276,9 @@ export default {
maxConnectionsHelper: 'Max connections', maxConnectionsHelper: 'Max connections',
restart: 'Restart', restart: 'Restart',
log: 'Logs',
slowLog: 'Slowlogs',
isOn: 'Is on', isOn: 'Is on',
longQueryTime: 'Slow query threshold', longQueryTime: 'Slow query threshold',

View File

@@ -190,7 +190,7 @@ export default {
jsInfo: '广受欢迎的开源堡垒机', jsInfo: '广受欢迎的开源堡垒机',
msInfo: '一站式开源持续测试平台', msInfo: '一站式开源持续测试平台',
koInfo: '开源的轻量级 Kubernetes 发行版', koInfo: '开源的轻量级 Kubernetes 发行版',
kubepiInfo: '现代化的开源 K8s 面板', kubepiInfo: '现代化的开源 Kubernetes 面板',
goInstall: '去安装', goInstall: '去安装',
}, },
tabs: { tabs: {
@@ -279,6 +279,9 @@ export default {
maxConnectionsHelper: '最大连接数', maxConnectionsHelper: '最大连接数',
restart: '重启数据库', restart: '重启数据库',
log: '日志',
slowLog: '慢日志',
isOn: '是否开启', isOn: '是否开启',
longQueryTime: '慢查询阈值', longQueryTime: '慢查询阈值',
@@ -751,7 +754,7 @@ export default {
gotoInstalled: '去安装', gotoInstalled: '去安装',
search: '搜索', search: '搜索',
limitHelper: '该应用已安装不支持重复安装', limitHelper: '该应用已安装不支持重复安装',
deleteHelper: '应用已经关联以下资源无法删除', deleteHelper: '{0}已经关联以下资源无法删除',
checkTitle: '提示', checkTitle: '提示',
website: '网站', website: '网站',
database: '数据库', database: '数据库',

View File

@@ -7,7 +7,13 @@
:destroy-on-close="true" :destroy-on-close="true"
> >
<el-row> <el-row>
<el-alert type="warning" :description="$t('app.deleteHelper')" center show-icon :closable="false" /> <el-alert
type="warning"
:description="$t('app.deleteHelper', [$t('app.app')])"
center
show-icon
:closable="false"
/>
<el-col :span="12" :offset="6"> <el-col :span="12" :offset="6">
<br /> <br />
<el-descriptions border :column="1"> <el-descriptions border :column="1">

View File

@@ -7,7 +7,13 @@
:destroy-on-close="true" :destroy-on-close="true"
> >
<el-row> <el-row>
<el-alert type="warning" :description="$t('app.deleteHelper')" center show-icon :closable="false" /> <el-alert
type="warning"
:description="$t('app.deleteHelper', [$t('app.database')])"
center
show-icon
:closable="false"
/>
<el-col :span="12" :offset="6"> <el-col :span="12" :offset="6">
<br /> <br />
<el-descriptions border :column="1"> <el-descriptions border :column="1">

View File

@@ -16,7 +16,7 @@
<el-button type="primary" icon="Plus" @click="onOpenDialog()"> <el-button type="primary" icon="Plus" @click="onOpenDialog()">
{{ $t('commons.button.create') }} {{ $t('commons.button.create') }}
</el-button> </el-button>
<el-button>phpMyAdmin</el-button> <el-button @click="goDashboard" icon="Position">phpMyAdmin</el-button>
</template> </template>
<el-table-column type="selection" fix /> <el-table-column type="selection" fix />
<el-table-column :label="$t('commons.table.name')" prop="name" /> <el-table-column :label="$t('commons.table.name')" prop="name" />
@@ -132,12 +132,14 @@ import { ElForm, ElMessage } from 'element-plus';
import { Database } from '@/api/interface/database'; import { Database } from '@/api/interface/database';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import { App } from '@/api/interface/app'; import { App } from '@/api/interface/app';
import { GetAppPort } from '@/api/modules/app';
const selects = ref<any>([]); const selects = ref<any>([]);
const mysqlName = ref(); const mysqlName = ref();
const isOnSetting = ref<boolean>(); const isOnSetting = ref<boolean>();
const checkRef = ref(); const checkRef = ref();
const phpadminPort = ref();
const data = ref(); const data = ref();
const paginationConfig = reactive({ const paginationConfig = reactive({
@@ -212,11 +214,21 @@ const search = async () => {
paginationConfig.total = res.data.total; paginationConfig.total = res.data.total;
}; };
const goDashboard = async () => {
window.open('http://localhost:' + phpadminPort.value, '_blank');
};
const loadDashboardPort = async () => {
const res = await GetAppPort('phpmyadmin');
phpadminPort.value = res.data;
};
const checkExist = (data: App.CheckInstalled) => { const checkExist = (data: App.CheckInstalled) => {
mysqlIsExist.value = data.isExist; mysqlIsExist.value = data.isExist;
mysqlName.value = data.name; mysqlName.value = data.name;
if (mysqlIsExist.value) { if (mysqlIsExist.value) {
search(); search();
loadDashboardPort();
} }
}; };

View File

@@ -66,7 +66,7 @@
v-model="mysqlConf" v-model="mysqlConf"
:readOnly="true" :readOnly="true"
/> />
<el-button type="primary" style="width: 120px; margin-top: 10px" @click="onSaveFile()"> <el-button type="primary" style="margin-top: 10px" @click="onSaveFile()">
{{ $t('commons.button.save') }} {{ $t('commons.button.save') }}
</el-button> </el-button>
</el-collapse-item> </el-collapse-item>
@@ -76,11 +76,11 @@
<el-collapse-item :title="$t('database.performanceTuning')" name="4"> <el-collapse-item :title="$t('database.performanceTuning')" name="4">
<Variables ref="variablesRef" /> <Variables ref="variablesRef" />
</el-collapse-item> </el-collapse-item>
<el-collapse-item title="日志" name="5"> <el-collapse-item :title="$t('database.log')" name="5">
<ContainerLog ref="dialogContainerLogRef" /> <ContainerLog ref="dialogContainerLogRef" />
</el-collapse-item> </el-collapse-item>
<el-collapse-item title="慢日志" name="6"> <el-collapse-item :title="$t('database.slowLog')" name="6">
<SlowLog ref="slowLogRef" /> <SlowLog ref="slowLogRef" />
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>

View File

@@ -64,17 +64,9 @@
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button @click="onSaveStart(variableFormRef)" type="primary">
icon="Collection"
@click="onSaveStart(variableFormRef)"
type="primary"
size="default"
>
{{ $t('commons.button.save') }} {{ $t('commons.button.save') }}
</el-button> </el-button>
<el-button icon="RefreshLeft" size="default">
{{ $t('database.restart') }}
</el-button>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="2"><br /></el-col> <el-col :span="2"><br /></el-col>
@@ -285,7 +277,7 @@ const onSaveVariables = async () => {
if (oldVariables.value?.max_connections !== mysqlVariables.max_connections) { if (oldVariables.value?.max_connections !== mysqlVariables.max_connections) {
param.push({ param: 'max_connections', value: mysqlVariables.max_connections }); param.push({ param: 'max_connections', value: mysqlVariables.max_connections });
} }
await updateMysqlVariables(mysqlName.value, param); await updateMysqlVariables(param);
ElMessage.success(i18n.global.t('commons.msg.operationSuccess')); ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
}; };

View File

@@ -6,7 +6,8 @@
<div v-show="redisIsExist"> <div v-show="redisIsExist">
<Setting ref="settingRef" style="margin-top: 20px" /> <Setting ref="settingRef" style="margin-top: 20px" />
<Terminal v-show="!isOnSetting" style="margin-top: 20px" ref="terminalRef" /> <el-button style="margin-top: 20px" type="p" @click="goDashboard" icon="Position">Redis-Command</el-button>
<Terminal v-show="!isOnSetting" ref="terminalRef" />
</div> </div>
</div> </div>
</template> </template>
@@ -18,21 +19,34 @@ import Terminal from '@/views/database/redis/terminal/index.vue';
import AppStatus from '@/components/app-status/index.vue'; import AppStatus from '@/components/app-status/index.vue';
import { ref } from 'vue'; import { ref } from 'vue';
import { App } from '@/api/interface/app'; import { App } from '@/api/interface/app';
import { GetAppPort } from '@/api/modules/app';
const terminalRef = ref(); const terminalRef = ref();
const settingRef = ref(); const settingRef = ref();
const isOnSetting = ref(false); const isOnSetting = ref(false);
const redisIsExist = ref(false); const redisIsExist = ref(false);
const redisCommandPort = ref();
const onSetting = async () => { const onSetting = async () => {
isOnSetting.value = true; isOnSetting.value = true;
terminalRef.value.onClose(); terminalRef.value.onClose();
settingRef.value!.acceptParams(); settingRef.value!.acceptParams();
}; };
const goDashboard = async () => {
window.open('http://localhost:' + redisCommandPort.value, '_blank');
};
const loadDashboardPort = async () => {
const res = await GetAppPort('phpmyadmin');
redisCommandPort.value = res.data;
};
const checkExist = (data: App.CheckInstalled) => { const checkExist = (data: App.CheckInstalled) => {
redisIsExist.value = data.isExist; redisIsExist.value = data.isExist;
if (redisIsExist.value) { if (redisIsExist.value) {
loadDashboardPort();
terminalRef.value.acceptParams(); terminalRef.value.acceptParams();
} }
}; };

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="demo-collapse" v-show="settingShow"> <div class="demo-collapse" v-show="settingShow">
<el-card style="margin-top: 5px"> <el-card style="margin-top: 5px">
<LayoutContent :header="$t('database.setting')" back-name="Redis" :reload="true"> <LayoutContent :header="$t('database.setting')" back-name="Redis" :reload="true" v-loading="loading">
<el-collapse v-model="activeName" accordion> <el-collapse v-model="activeName" accordion>
<el-collapse-item :title="$t('database.baseSetting')" name="1"> <el-collapse-item :title="$t('database.baseSetting')" name="1">
<el-radio-group v-model="confShowType" @change="onChangeMode"> <el-radio-group v-model="confShowType" @change="onChangeMode">
@@ -21,7 +21,7 @@
<el-form-item :label="$t('setting.port')" prop="port" :rules="Rules.port"> <el-form-item :label="$t('setting.port')" prop="port" :rules="Rules.port">
<el-input clearable type="number" v-model.number="form.port"> <el-input clearable type="number" v-model.number="form.port">
<template #append> <template #append>
<el-button @click="onChangePort(formRef)" icon="Collection"> <el-button @click="onSavePort()" icon="Collection">
{{ $t('commons.button.save') }} {{ $t('commons.button.save') }}
</el-button> </el-button>
</template> </template>
@@ -44,12 +44,7 @@
<span class="input-help">{{ $t('database.maxmemoryHelper') }}</span> <span class="input-help">{{ $t('database.maxmemoryHelper') }}</span>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" @click="onSave(formRef)">
type="primary"
size="default"
@click="onSave(formRef)"
style="width: 90px"
>
{{ $t('commons.button.save') }} {{ $t('commons.button.save') }}
</el-button> </el-button>
</el-form-item> </el-form-item>
@@ -92,6 +87,7 @@
</el-card> </el-card>
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitSave"></ConfirmDialog> <ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitSave"></ConfirmDialog>
<ConfirmDialog ref="confirmDialogRef2" @confirm="onChangePort(formRef)"></ConfirmDialog>
</div> </div>
</template> </template>
@@ -114,6 +110,8 @@ import { ChangePort } from '@/api/modules/app';
const extensions = [javascript(), oneDark]; const extensions = [javascript(), oneDark];
const confShowType = ref('base'); const confShowType = ref('base');
const loading = ref(false);
const form = reactive({ const form = reactive({
name: '', name: '',
port: 6379, port: 6379,
@@ -136,6 +134,7 @@ const persistenceRef = ref();
const formRef = ref<FormInstance>(); const formRef = ref<FormInstance>();
const mysqlConf = ref(); const mysqlConf = ref();
const confirmDialogRef = ref(); const confirmDialogRef = ref();
const confirmDialogRef2 = ref();
const settingShow = ref<boolean>(false); const settingShow = ref<boolean>(false);
@@ -149,6 +148,15 @@ const onClose = (): void => {
settingShow.value = false; settingShow.value = false;
}; };
const onSavePort = async () => {
let params = {
header: i18n.global.t('database.confChange'),
operationInfo: i18n.global.t('database.restartNowHelper1'),
submitInputInfo: i18n.global.t('database.restartNow'),
};
confirmDialogRef2.value!.acceptParams(params);
};
const onChangePort = async (formEl: FormInstance | undefined) => { const onChangePort = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
const result = await formEl.validateField('port', callback); const result = await formEl.validateField('port', callback);
@@ -160,9 +168,15 @@ const onChangePort = async (formEl: FormInstance | undefined) => {
name: form.name, name: form.name,
port: form.port, port: form.port,
}; };
await ChangePort(params); loading.value = true;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess')); await ChangePort(params)
return; .then(() => {
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
})
.finally(() => {
loading.value = false;
});
}; };
function callback(error: any) { function callback(error: any) {
if (error) { if (error) {
@@ -193,9 +207,16 @@ const onSave = async (formEl: FormInstance | undefined) => {
requirepass: form.requirepass, requirepass: form.requirepass,
maxmemory: form.maxmemory + '', maxmemory: form.maxmemory + '',
}; };
await updateRedisConf(param); loading.value = true;
loadform(); await updateRedisConf(param)
ElMessage.success(i18n.global.t('commons.msg.operationSuccess')); .then(() => {
loadform();
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
})
.finally(() => {
loading.value = false;
});
}); });
}; };

View File

@@ -1,7 +1,7 @@
<template> <template>
<div v-show="terminalShow" style="height: 100%"> <div v-show="terminalShow" style="height: 100%">
<el-card style="margin-top: 5px"> <el-card>
<div style="height: calc(100vh - 220px)" :id="'terminal-exec'"></div> <div style="height: calc(100vh - 230px)" :id="'terminal-exec'"></div>
</el-card> </el-card>
</div> </div>
</template> </template>