Skip to content

Commit 85f6d9c

Browse files
JustaCatttiSecloud
authored andcommitted
feat(frontend): 临时密码修改异步改造 #7031
# Reviewed, transaction id: 23353
1 parent 29befbe commit 85f6d9c

File tree

4 files changed

+129
-55
lines changed

4 files changed

+129
-55
lines changed

dbm-ui/frontend/src/services/source/permission.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,38 @@ interface AdminPasswordResultItem {
4040
}[];
4141
}
4242

43+
const path = '/apis/conf/password_policy';
44+
4345
/**
4446
* 查询密码安全策略
4547
*/
4648
export const getPasswordPolicy = (params: { name: string }) =>
47-
http.get<PasswordPolicy>('/apis/conf/password_policy/get_password_policy/', params);
49+
http.get<PasswordPolicy>(`${path}/get_password_policy/`, params);
4850

4951
/**
5052
* 更新密码安全策略
5153
*/
5254
export const updatePasswordPolicy = (params: PasswordPolicy & { reset: boolean }) =>
53-
http.post('/apis/conf/password_policy/update_password_policy/', params);
55+
http.post(`${path}/update_password_policy/`, params);
5456

5557
/**
5658
* 查询随机化周期
5759
*/
5860
export const queryRandomCycle = (params = {}, payload = {} as IRequestPayload) =>
59-
http.get<RamdomCycle>('/apis/conf/password_policy/query_random_cycle/', params, payload);
61+
http.get<RamdomCycle>(`${path}/query_random_cycle/`, params, payload);
6062

6163
/**
6264
* 更新随机化周期
6365
*/
64-
export const modifyRandomCycle = (params: RamdomCycle) =>
65-
http.post('/apis/conf/password_policy/modify_random_cycle/', params);
66+
export const modifyRandomCycle = (params: RamdomCycle) => http.post(`${path}/modify_random_cycle/`, params);
6667

6768
/**
6869
* 获取符合密码强度的字符串
6970
*/
7071
export const getRandomPassword = (params?: { security_type: string }) =>
7172
http.get<{
7273
password: string;
73-
}>('/apis/conf/password_policy/get_random_password/', params);
74+
}>(`${path}/get_random_password/`, params);
7475

7576
/**
7677
* 修改实例密码(admin)
@@ -85,11 +86,16 @@ export const modifyAdminPassword = (params: {
8586
cluster_type: ClusterTypes;
8687
role: string;
8788
}[];
89+
// 是否异步
90+
is_async?: boolean;
8891
}) =>
89-
http.post<{
90-
success: AdminPasswordResultItem[] | null;
91-
fail: AdminPasswordResultItem[] | null;
92-
}>('/apis/conf/password_policy/modify_admin_password/', params);
92+
http.post<
93+
| {
94+
success: AdminPasswordResultItem[] | null;
95+
fail: AdminPasswordResultItem[] | null;
96+
}
97+
| string // 异步修改时返回root_id
98+
>(`${path}/modify_admin_password/`, params);
9399

94100
/**
95101
* 查询生效实例密码(admin)
@@ -102,11 +108,23 @@ export const queryAdminPassword = (params: {
102108
instances?: string;
103109
db_type?: DBTypes;
104110
}) =>
105-
http.post<ListBase<AdminPasswordModel[]>>('/apis/conf/password_policy/query_admin_password/', params).then((res) => ({
111+
http.post<ListBase<AdminPasswordModel[]>>(`${path}/query_admin_password/`, params).then((res) => ({
106112
...res,
107113
results: res.results.map((item) => new AdminPasswordModel(item)),
108114
}));
109115

116+
/**
117+
* 查询异步密码修改执行结果
118+
*/
119+
export const queryAsyncModifyResult = (params: { root_id: string }) =>
120+
http.post<{
121+
data: {
122+
success: AdminPasswordResultItem[] | null;
123+
fail: AdminPasswordResultItem[] | null;
124+
};
125+
status: string;
126+
}>(`${path}/query_async_modify_result/`, params);
127+
110128
/**
111129
* 获取公钥列表
112130
*/
@@ -123,4 +141,4 @@ export const getRSAPublicKeys = (params: { names: string[] }) =>
123141
* 校验密码强度
124142
*/
125143
export const verifyPasswordStrength = (params: { security_type: string; password: string }) =>
126-
http.post<PasswordStrength>('/apis/conf/password_policy/verify_password_strength/', params);
144+
http.post<PasswordStrength>(`${path}/verify_password_strength/`, params);

dbm-ui/frontend/src/views/db-manage/common/password-input/Index.vue

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@
127127
},
128128
});
129129
130-
const { run: getPasswordPolicyRun } = useRequest(getPasswordPolicy, {
131-
manual: true,
130+
useRequest(getPasswordPolicy, {
131+
defaultParams: [{ name: passwordParam.value }],
132132
onSuccess(data) {
133133
const {
134134
min_length: minLength,
@@ -198,6 +198,13 @@
198198
},
199199
});
200200
201+
watch(
202+
() => props.dbType,
203+
() => {
204+
modelValue.value = '';
205+
},
206+
);
207+
201208
/**
202209
* 获取加密密码
203210
*/
@@ -287,18 +294,6 @@
287294
tippyInstance.hide();
288295
};
289296
290-
watch(modelValue, () => {
291-
if (modelValue.value) {
292-
debounceVerifyPassword();
293-
}
294-
});
295-
296-
onMounted(() => {
297-
getPasswordPolicyRun({
298-
name: passwordParam.value,
299-
});
300-
});
301-
302297
onUnmounted(() => {
303298
tippyInstance.destroy();
304299
});

dbm-ui/frontend/src/views/temporary-paassword-modify/index/Index.vue

Lines changed: 89 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,50 @@
1414
<template>
1515
<SmartAction :offset-target="getSmartActionOffsetTarget">
1616
<div class="password-temporary-modify">
17-
<div
18-
v-if="submitting"
19-
class="submitting-mask">
20-
<DbIcon
21-
class="submitting-icon"
22-
svg
23-
type="sync-pending" />
24-
<p class="submitting-text">
25-
{{ t('密码正在修改中,请稍等') }}
26-
</p>
27-
</div>
28-
<UpdateResult
29-
v-else-if="submitted"
30-
:password="formData.password"
31-
:submit-length="submitLength"
32-
:submit-res="submitRes"
33-
:submit-role-map="submitRoleMap"
34-
@refresh="handleRefresh"
35-
@retry="handleSubmit" />
17+
<template v-if="submitted">
18+
<div
19+
v-if="isActive"
20+
class="submitting-mask">
21+
<DbIcon
22+
class="submitting-icon"
23+
svg
24+
type="sync-pending" />
25+
<p class="submitting-text mt16">
26+
{{ t('密码正在修改中,请稍等') }}
27+
</p>
28+
<RouterLink
29+
class="mt16 mb16"
30+
target="_blank"
31+
:to="{
32+
name: 'taskHistoryDetail',
33+
params: {
34+
root_id: rootId,
35+
},
36+
}">
37+
{{ t('查看详情') }}
38+
</RouterLink>
39+
</div>
40+
<UpdateResult
41+
v-else
42+
:password="formData.password"
43+
:submit-length="submitLength"
44+
:submit-res="modifyResult"
45+
:submit-role-map="submitRoleMap"
46+
@refresh="handleRefresh"
47+
@retry="handleSubmit">
48+
<RouterLink
49+
class="mt16 mb16"
50+
target="_blank"
51+
:to="{
52+
name: 'taskHistoryDetail',
53+
params: {
54+
root_id: rootId,
55+
},
56+
}">
57+
{{ t('查看详情') }}
58+
</RouterLink>
59+
</UpdateResult>
60+
</template>
3661
<DbForm
3762
v-else
3863
ref="formRef"
@@ -81,17 +106,21 @@
81106
import { useI18n } from 'vue-i18n';
82107
import { useRequest } from 'vue-request';
83108
84-
import { modifyAdminPassword } from '@services/source/permission';
109+
import { modifyAdminPassword, queryAsyncModifyResult } from '@services/source/permission';
85110
86111
import { ClusterTypes, DBTypes } from '@common/const';
87112
88113
import PasswordInput from '@views/db-manage/common/password-input/Index.vue';
89114
115+
import { useTimeoutPoll } from '@vueuse/core';
116+
90117
import InstanceList from './components/form-item/InstanceList.vue';
91118
import ValidDuration from './components/form-item/ValidDuration.vue';
92119
import RenderPasswordInstance from './components/render-passwrod-instance/Index.vue';
93120
import UpdateResult from './components/UpdateResult.vue';
94121
122+
type ModifyAdminPassword = ServiceReturnType<typeof modifyAdminPassword>;
123+
95124
const { t } = useI18n();
96125
97126
const createDefaultData = () => ({
@@ -130,23 +159,48 @@
130159
},
131160
);
132161
133-
const {
134-
loading: submitting,
135-
run: modifyAdminPasswordRun,
136-
data: submitRes,
137-
} = useRequest(modifyAdminPassword, {
162+
const rootId = ref('');
163+
const modifyResult = ref<ModifyAdminPassword>('');
164+
165+
// 轮询
166+
const { isActive, resume, pause } = useTimeoutPoll(() => {
167+
queryAsyncModifyResultRun({
168+
root_id: rootId.value,
169+
});
170+
}, 2000);
171+
172+
const { run: queryAsyncModifyResultRun } = useRequest(queryAsyncModifyResult, {
138173
manual: true,
139-
onSuccess() {
174+
onSuccess({ data, status }) {
175+
/**
176+
* 设置轮询
177+
* FINISHED: 完成态
178+
* FAILED: 失败态
179+
* REVOKED: 取消态
180+
*/
181+
if (['FINISHED', 'FAILED', 'REVOKED'].includes(status)) {
182+
modifyResult.value = data;
183+
pause();
184+
} else if (!isActive.value) {
185+
resume();
186+
}
187+
},
188+
});
189+
190+
const { run: modifyAdminPasswordRun, loading: submitting } = useRequest(modifyAdminPassword, {
191+
manual: true,
192+
onSuccess(data) {
140193
submitted.value = true;
141194
window.changeConfirm = false;
195+
rootId.value = data as string;
196+
resume();
142197
},
143198
});
144199
145200
const getSmartActionOffsetTarget = () => document.querySelector('.bk-form-content');
146201
147202
const submitValidator = async () => {
148203
await formRef.value.validate();
149-
150204
handleSubmit(formData.instanceList);
151205
};
152206
@@ -183,6 +237,7 @@
183237
lock_hour: lockHour,
184238
password: formData.password,
185239
instance_list: instanceListParam,
240+
is_async: true,
186241
};
187242
188243
submitLength.value = instanceListParam.length;
@@ -198,6 +253,10 @@
198253
handleReset();
199254
submitted.value = false;
200255
};
256+
257+
onBeforeUnmount(() => {
258+
pause();
259+
});
201260
</script>
202261

203262
<style lang="less" scoped>
@@ -207,8 +266,10 @@
207266
border-radius: 2px;
208267
209268
.submitting-mask {
269+
display: flex;
210270
padding: 90px 0 138px;
211-
text-align: center;
271+
flex-direction: column;
272+
align-items: center;
212273
213274
.submitting-icon {
214275
font-size: 64px;
@@ -217,7 +278,6 @@
217278
}
218279
219280
.submitting-text {
220-
margin-top: 36px;
221281
font-size: 24px;
222282
color: #313238;
223283
}

dbm-ui/frontend/src/views/temporary-paassword-modify/index/components/UpdateResult.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<span class="title-error">{{ errorListLength }}</span>
2424
</I18nT>
2525
</template>
26+
<slot />
2627
<div class="password-display">
2728
{{ t('当前密码') }} : {{ passwordDisplay }}
2829
<BkButton

0 commit comments

Comments
 (0)