-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathindex.vue
More file actions
259 lines (238 loc) · 9.17 KB
/
index.vue
File metadata and controls
259 lines (238 loc) · 9.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<template>
<DrawerPro v-model="dialogVisible" :header="$t('database.databaseConnInfo')" :back="handleClose" size="small">
<el-form @submit.prevent v-loading="loading" ref="formRef" :model="form" label-position="top">
<el-form-item :label="$t('database.containerConn')" v-if="form.from === 'local'">
<el-card class="mini-border-card">
<el-descriptions :column="1">
<el-descriptions-item :label="$t('database.connAddress')">
<el-tooltip v-if="loadPgInfo(true).length > 48" :content="loadPgInfo(true)" placement="top">
{{ loadPgInfo(true).substring(0, 48) }}...
</el-tooltip>
<span else>
{{ loadPgInfo(true) }}
</span>
<CopyButton :content="loadPgInfo(true)" type="icon" />
</el-descriptions-item>
<el-descriptions-item :label="$t('commons.table.port')">
5432
<CopyButton content="5432" type="icon" />
</el-descriptions-item>
</el-descriptions>
</el-card>
<span class="input-help">
{{ $t('database.containerConnHelper') }}
</span>
</el-form-item>
<el-form-item :label="$t('database.remoteConn')">
<el-card class="mini-border-card">
<el-descriptions :column="1">
<el-descriptions-item :label="$t('database.connAddress')">
<el-tooltip
v-if="loadPgInfo(false).length > 48"
:content="loadPgInfo(false)"
placement="top"
>
{{ loadPgInfo(false).substring(0, 48) }}...
</el-tooltip>
<span else>
{{ loadPgInfo(false) }}
</span>
<CopyButton :content="loadPgInfo(false)" type="icon" />
</el-descriptions-item>
<el-descriptions-item :label="$t('commons.table.port')">
{{ form.port }}
<CopyButton :content="form.port + ''" type="icon" />
</el-descriptions-item>
</el-descriptions>
</el-card>
<span v-if="form.from === 'local'" class="input-help">
{{ $t('database.remoteConnHelper2') }}
</span>
</el-form-item>
<el-divider border-style="dashed" />
<div v-if="form.from === 'local'">
<el-form-item :label="$t('commons.login.username')" prop="username">
<el-input type="text" readonly disabled v-model="form.username">
<template #append>
<el-button-group>
<CopyButton :content="form.username" />
</el-button-group>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('commons.login.password')" :rules="Rules.paramComplexity" prop="password">
<el-input
style="width: calc(100% - 205px)"
type="password"
show-password
clearable
v-model="form.password"
/>
<el-button-group>
<CopyButton class="copy_button" :content="form.password" />
<el-button @click="random">
{{ $t('commons.button.random') }}
</el-button>
</el-button-group>
</el-form-item>
</div>
<div v-if="form.from !== 'local'">
<el-form-item :label="$t('commons.login.username')">
<el-tag>{{ form.username }}</el-tag>
<CopyButton :content="form.username" type="icon" />
</el-form-item>
<el-form-item :label="$t('commons.login.password')">
<el-tag>{{ form.password }}</el-tag>
<CopyButton :content="form.password" type="icon" />
</el-form-item>
</div>
</el-form>
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmit" @cancel="loadPassword"></ConfirmDialog>
<template #footer>
<span class="dialog-footer">
<el-button :disabled="loading" @click="dialogVisible = false">
{{ $t('commons.button.cancel') }}
</el-button>
<el-button :disabled="loading || form.status !== 'Running'" type="primary" @click="onSave(formRef)">
{{ $t('commons.button.confirm') }}
</el-button>
</span>
</template>
</DrawerPro>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm } from 'element-plus';
import { getDatabase, updatePostgresqlPassword } from '@/api/modules/database';
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const loading = ref(false);
const dialogVisible = ref(false);
const form = reactive({
status: '',
systemIP: '',
password: '',
containerName: '',
serviceName: '',
privilege: false,
port: 0,
from: '',
type: '',
database: '',
username: '',
remoteIP: '',
});
const confirmDialogRef = ref();
type FormInstance = InstanceType<typeof ElForm>;
const formRef = ref<FormInstance>();
interface DialogProps {
from: string;
type: string;
database: string;
}
const acceptParams = (param: DialogProps): void => {
form.password = '';
form.from = param.from;
form.type = param.type;
form.database = param.database;
loadAccess();
loadPassword();
dialogVisible.value = true;
};
function loadPgInfo(isContainer: boolean) {
if (isContainer) {
return form.from === 'local' ? form.containerName : form.systemIP;
} else {
return form.from === 'local' ? form.systemIP : form.remoteIP;
}
}
const random = async () => {
form.password = getRandomStr(16);
};
const handleClose = () => {
dialogVisible.value = false;
};
const loadAccess = async () => {
if (form.from === 'local') {
form.privilege = false;
}
};
const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};
const loadPassword = async () => {
if (form.from === 'local') {
const res = await getAppConnInfo(form.type, form.database);
form.status = res.data.status;
form.username = res.data.username || '';
form.password = res.data.password || '';
form.port = res.data.port || 5432;
form.containerName = res.data.containerName || '';
form.serviceName = res.data.serviceName || '';
loadSystemIP();
return;
}
const res = await getDatabase(form.database);
form.password = res.data.password || '';
form.port = res.data.port || 5432;
form.username = res.data.username;
form.password = res.data.password;
form.remoteIP = res.data.address;
};
const onSubmit = async () => {
let param = {
id: 0,
from: form.from,
type: form.type,
database: form.database,
value: form.password,
};
loading.value = true;
await updatePostgresqlPassword(param)
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
dialogVisible.value = false;
})
.catch(() => {
loading.value = false;
});
};
const onSave = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
let params = {
header: i18n.global.t('database.confChange'),
operationInfo: i18n.global.t('database.restartNowHelper'),
submitInputInfo: i18n.global.t('database.restartNow'),
};
confirmDialogRef.value!.acceptParams(params);
});
};
defineExpose({
acceptParams,
});
</script>
<style lang="scss" scoped>
.copy_button {
border-radius: 0px;
border-left-width: 0px;
}
:deep(.el-input__wrapper) {
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
}
</style>