From add4fab79405a2ae839cd3ce93c96f405931086b Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 6 Sep 2023 21:20:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=88=96=E8=BF=9C=E7=A8=8B=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E8=BF=94=E5=9B=9E=E6=97=B6=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E5=8E=9F=E8=B7=AF=E7=94=B1=20(#2207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/database.go | 1 + backend/app/service/database.go | 1 + frontend/src/store/index.ts | 4 ++++ frontend/src/store/interface/index.ts | 1 + frontend/src/views/database/mysql/index.vue | 21 +++++++++++++++++-- .../database/mysql/remote/operate/index.vue | 12 +++++++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/backend/app/dto/database.go b/backend/app/dto/database.go index 6406eb5f0..3e325995b 100644 --- a/backend/app/dto/database.go +++ b/backend/app/dto/database.go @@ -276,6 +276,7 @@ type DatabaseCreate struct { type DatabaseUpdate struct { ID uint `json:"id"` + Type string `json:"type" validate:"required"` Version string `json:"version" validate:"required"` Address string `json:"address"` Port uint `json:"port"` diff --git a/backend/app/service/database.go b/backend/app/service/database.go index 010d73fab..e7f2e6f8b 100644 --- a/backend/app/service/database.go +++ b/backend/app/service/database.go @@ -148,6 +148,7 @@ func (u *DatabaseService) Update(req dto.DatabaseUpdate) error { } upMap := make(map[string]interface{}) + upMap["type"] = req.Type upMap["version"] = req.Version upMap["address"] = req.Address upMap["port"] = req.Port diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts index f8dffc1ef..212e8ac29 100644 --- a/frontend/src/store/index.ts +++ b/frontend/src/store/index.ts @@ -27,6 +27,7 @@ export const GlobalStore = defineStore({ ignoreCaptcha: true, device: DeviceType.Desktop, lastFilePath: '', + currentDB: '', }), getters: {}, actions: { @@ -64,6 +65,9 @@ export const GlobalStore = defineStore({ setLastFilePath(path: string) { this.lastFilePath = path; }, + setCurrentDB(name: string) { + this.currentDB = name; + }, }, persist: piniaPersistConfig('GlobalState'), }); diff --git a/frontend/src/store/interface/index.ts b/frontend/src/store/interface/index.ts index 563797705..97d656750 100644 --- a/frontend/src/store/interface/index.ts +++ b/frontend/src/store/interface/index.ts @@ -22,6 +22,7 @@ export interface GlobalState { ignoreCaptcha: boolean; device: DeviceType; lastFilePath: string; + currentDB: string; } export interface MenuState { diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue index 5b2a8029d..59c9ba097 100644 --- a/frontend/src/views/database/mysql/index.vue +++ b/frontend/src/views/database/mysql/index.vue @@ -30,7 +30,7 @@ @@ -42,7 +42,7 @@ @@ -235,6 +235,8 @@ import router from '@/routers'; import { MsgError, MsgSuccess } from '@/utils/message'; import useClipboard from 'vue-clipboard3'; const { toClipboard } = useClipboard(); +import { GlobalStore } from '@/store'; +const globalStore = GlobalStore(); const loading = ref(false); const maskShow = ref(true); @@ -293,12 +295,14 @@ const onChangeConn = async () => { }; const goRemoteDB = async () => { + globalStore.setCurrentDB(currentDB.value.database); router.push({ name: 'MySQL-Remote' }); }; const passwordRef = ref(); const onSetting = async () => { + globalStore.setCurrentDB(currentDB.value.database); router.push({ name: 'MySQL-Setting', params: { type: currentDB.value.type, database: currentDB.value.database } }); }; @@ -401,13 +405,26 @@ const loadDBOptions = async () => { let datas = res.data || []; dbOptionsLocal.value = []; dbOptionsRemote.value = []; + currentDBName.value = globalStore.currentDB; for (const item of datas) { + if (currentDBName.value && item.database === currentDBName.value) { + currentDB.value = item; + if (item.from === 'local') { + appKey.value = item.type; + appName.value = item.database; + } + } if (item.from === 'local') { dbOptionsLocal.value.push(item); } else { dbOptionsRemote.value.push(item); } } + if (currentDB.value) { + globalStore.setCurrentDB(''); + search(); + return; + } if (dbOptionsLocal.value.length !== 0) { currentDB.value = dbOptionsLocal.value[0]; currentDBName.value = dbOptionsLocal.value[0].database; diff --git a/frontend/src/views/database/mysql/remote/operate/index.vue b/frontend/src/views/database/mysql/remote/operate/index.vue index 485541e23..a8d12e10e 100644 --- a/frontend/src/views/database/mysql/remote/operate/index.vue +++ b/frontend/src/views/database/mysql/remote/operate/index.vue @@ -99,6 +99,18 @@ const loading = ref(); const acceptParams = (params: DialogProps): void => { dialogData.value = params; + if (dialogData.value.rowData.version.startsWith('5.6')) { + dialogData.value.rowData.version = '5.6'; + } + if (dialogData.value.rowData.version.startsWith('5.7')) { + dialogData.value.rowData.version = '5.7'; + } + if (dialogData.value.rowData.version.startsWith('8.')) { + dialogData.value.rowData.version = '8.x'; + } + if (dialogData.value.rowData.version.startsWith('10.')) { + dialogData.value.rowData.version = '10.x'; + } title.value = i18n.global.t('database.' + dialogData.value.title + 'RemoteDB'); drawerVisiable.value = true; };