Skip to content

Commit af6a09e

Browse files
committed
fix: mysql 数据库连接信息样式调整
1 parent ac7e47b commit af6a09e

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

backend/app/repo/databse_mysql.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type IMysqlRepo interface {
2020
Delete(ctx context.Context, opts ...DBOption) error
2121
Update(id uint, vars map[string]interface{}) error
2222
UpdateDatabaseInfo(id uint, vars map[string]interface{}) error
23-
DeleteAll(ctx context.Context) error
23+
DeleteLocal(ctx context.Context) error
2424
}
2525

2626
func NewIMysqlRepo() IMysqlRepo {
@@ -67,8 +67,8 @@ func (u *MysqlRepo) Delete(ctx context.Context, opts ...DBOption) error {
6767
return getTx(ctx, opts...).Delete(&model.DatabaseMysql{}).Error
6868
}
6969

70-
func (u *MysqlRepo) DeleteAll(ctx context.Context) error {
71-
return getTx(ctx).Where("1 = 1").Delete(&model.DatabaseMysql{}).Error
70+
func (u *MysqlRepo) DeleteLocal(ctx context.Context) error {
71+
return getTx(ctx).Where("`from` = ?", "local").Delete(&model.DatabaseMysql{}).Error
7272
}
7373

7474
func (u *MysqlRepo) Update(id uint, vars map[string]interface{}) error {

backend/app/service/app_utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func deleteAppInstall(install model.AppInstall, deleteBackup bool, forceDelete b
200200
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), backupRepo.WithByDetailName(install.Name))
201201
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(install.App.Key))
202202
if install.App.Key == constant.AppMysql {
203-
_ = mysqlRepo.DeleteAll(ctx)
203+
_ = mysqlRepo.DeleteLocal(ctx)
204204
}
205205
uploadDir := path.Join(global.CONF.System.BaseDir, fmt.Sprintf("1panel/uploads/app/%s/%s", install.App.Key, install.Name))
206206
if _, err := os.Stat(uploadDir); err == nil {

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

+20-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</span>
1717
</el-form-item>
1818
<el-form-item :label="$t('database.remoteConn')">
19-
<el-tag>{{ $t('database.localIP') + ':' + form.port }}</el-tag>
19+
<el-tag>{{ form.systemIP + ':' + form.port }}</el-tag>
2020
<span class="input-help">{{ $t('database.remoteConnHelper2') }}</span>
2121
</el-form-item>
2222

@@ -81,13 +81,15 @@ import { GetAppConnInfo } from '@/api/modules/app';
8181
import DrawerHeader from '@/components/drawer-header/index.vue';
8282
import { MsgError, MsgSuccess } from '@/utils/message';
8383
import { getRandomStr } from '@/utils/util';
84+
import { getSettingInfo } from '@/api/modules/setting';
8485
import useClipboard from 'vue-clipboard3';
8586
const { toClipboard } = useClipboard();
8687
8788
const loading = ref(false);
8889
8990
const dialogVisiable = ref(false);
9091
const form = reactive({
92+
systemIP: '',
9193
password: '',
9294
serviceName: '',
9395
privilege: false,
@@ -112,11 +114,10 @@ interface DialogProps {
112114
const acceptParams = (param: DialogProps): void => {
113115
form.password = '';
114116
form.from = param.from;
115-
if (form.from !== 'local') {
116-
loadRemoteInfo();
117+
if (form.from === 'local') {
118+
loadAccess();
117119
}
118120
loadPassword();
119-
loadAccess();
120121
dialogVisiable.value = true;
121122
};
122123
@@ -142,18 +143,26 @@ const loadAccess = async () => {
142143
form.privilege = res.data;
143144
};
144145
145-
const loadRemoteInfo = async () => {
146-
const res = await getRemoteDB(form.from);
147-
form.remoteIP = res.data.address;
148-
form.username = res.data.username;
149-
form.password = res.data.password;
146+
const loadSystemIP = async () => {
147+
const res = await getSettingInfo();
148+
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
150149
};
151150
152151
const loadPassword = async () => {
153-
const res = await GetAppConnInfo('mysql');
152+
if (form.from === 'local') {
153+
const res = await GetAppConnInfo('mysql');
154+
form.password = res.data.password || '';
155+
form.port = res.data.port || 3306;
156+
form.serviceName = res.data.serviceName || '';
157+
loadSystemIP();
158+
return;
159+
}
160+
const res = await getRemoteDB(form.from);
154161
form.password = res.data.password || '';
155162
form.port = res.data.port || 3306;
156-
form.serviceName = res.data.serviceName || '';
163+
form.username = res.data.username;
164+
form.password = res.data.password;
165+
form.remoteIP = res.data.address;
157166
};
158167
159168
const onSubmit = async () => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
>
3939
{{ $t('database.create') }}
4040
</el-button>
41-
<el-button @click="onChangeConn" type="primary" plain>
41+
<el-button :disabled="!mysqlIsExist && isLocal()" @click="onChangeConn" type="primary" plain>
4242
{{ $t('database.databaseConnInfo') }}
4343
</el-button>
4444
<el-button

0 commit comments

Comments
 (0)