fix: 优化旧账号的重置密码逻辑

This commit is contained in:
lzhizhao 2025-09-11 09:28:17 +08:00
parent f48f8da512
commit c2732a05a6
2 changed files with 63 additions and 9 deletions

View File

@ -50,3 +50,12 @@ export function checkUsername (username) {
params: { username }
})
}
// 重置子账号密码
export function resetPassword (subAccountId, newPassword) {
return httpRequest({
url: httpRequest.adornUrl(`/merchant-api/subaccount/${subAccountId}/reset-password`),
method: 'put',
data: httpRequest.adornData({ newPassword })
})
}

View File

@ -35,6 +35,12 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="warning" @click="openResetPasswordDialog">重置密码</el-button>
</el-form-item>
<el-form-item label="状态">
<el-switch v-model="form.enable" active-text="启用" inactive-text="禁用"></el-switch>
</el-form-item>
</template>
<el-form-item label="姓名" prop="name">
@ -63,17 +69,35 @@
<el-button type="primary" @click="save">保存</el-button>
</el-form-item>
</el-form>
<el-dialog
title="重置密码"
:visible.sync="resetPasswordDialogVisible"
width="30%"
@close="newPassword = ''"
>
<el-form label-width="80px">
<el-form-item label="新密码">
<el-input v-model="newPassword" type="password" placeholder="请输入新密码"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="resetPasswordDialogVisible = false"> </el-button>
<el-button type="primary" @click="handleResetPassword"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {
getAvailablePermissions,
import {
getAvailablePermissions,
createSubAccount,
getSubAccountList,
getSubAccountDetail,
updateSubAccount,
checkUsername
checkUsername,
resetPassword
} from '@/api/modules/subaccount'
import routerConfig from '@/router/full-routers'
@ -84,8 +108,8 @@ const filterTreeByPerms = (tree, availablePerms) => {
}
return tree.reduce((acc, node) => {
// Recursively filter children
const children = node.list && node.list.length > 0
? filterTreeByPerms(node.list, availablePerms)
const children = node.list && node.list.length > 0
? filterTreeByPerms(node.list, availablePerms)
: [];
// A node is kept if its permission is in the available list,
@ -131,6 +155,8 @@ export default {
};
return {
resetPasswordDialogVisible: false,
newPassword: '',
form: {
operationType: 'create',
username: '',
@ -139,7 +165,8 @@ export default {
mobile: '',
permissionCodes: [],
remark: '',
accountId: null
accountId: null,
enable: true
},
subAccountList: [],
permissionList: [],
@ -182,7 +209,7 @@ export default {
this.form.permissionCodes = [];
this.form.remark = '';
this.form.accountId = null;
// Clear validation messages after the DOM has updated
this.$nextTick(() => {
this.$refs.ruleFormRef.clearValidate();
@ -210,13 +237,30 @@ export default {
this.permissionList = mapTreeForElTree(filteredTree);
});
},
openResetPasswordDialog() {
if (!this.form.accountId) {
this.$message.error('请先选择要更新的账号');
return;
}
this.resetPasswordDialogVisible = true;
},
handleResetPassword() {
if (!this.newPassword) {
this.$message.error('请输入新密码');
return;
}
resetPassword(this.form.accountId, this.newPassword).then(() => {
this.$message.success('密码重置成功');
this.resetPasswordDialogVisible = false;
});
},
handleTreeCheck() {
// getCheckedKeys(true) will return an array of keys of the currently checked leaf nodes.
this.form.permissionCodes = this.$refs.permissionTree.getCheckedKeys(true);
},
loadSubAccountList() {
getSubAccountList().then(res => {
this.subAccountList = res.data.data || [];
this.subAccountList = res.data.data.data || [];
});
},
handleAccountChange(accountId) {
@ -227,6 +271,7 @@ export default {
this.form.mobile = accountDetails.mobile;
this.form.remark = accountDetails.remark;
this.form.permissionCodes = accountDetails.permissionCodes || [];
this.form.enable = accountDetails.enabled;
this.$nextTick(() => {
this.$refs.permissionTree.setCheckedKeys(this.form.permissionCodes);
});
@ -255,7 +300,7 @@ export default {
mobile: this.form.mobile,
permissionCodes: this.form.permissionCodes,
remark: this.form.remark,
enabled: true // true
enabled: this.form.enable
};
updateSubAccount(updateData).then(() => {
this.$message.success('更新成功');