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 } 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-option>
</el-select> </el-select>
</el-form-item> </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> </template>
<el-form-item label="姓名" prop="name"> <el-form-item label="姓名" prop="name">
@ -63,17 +69,35 @@
<el-button type="primary" @click="save">保存</el-button> <el-button type="primary" @click="save">保存</el-button>
</el-form-item> </el-form-item>
</el-form> </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> </div>
</template> </template>
<script> <script>
import { import {
getAvailablePermissions, getAvailablePermissions,
createSubAccount, createSubAccount,
getSubAccountList, getSubAccountList,
getSubAccountDetail, getSubAccountDetail,
updateSubAccount, updateSubAccount,
checkUsername checkUsername,
resetPassword
} from '@/api/modules/subaccount' } from '@/api/modules/subaccount'
import routerConfig from '@/router/full-routers' import routerConfig from '@/router/full-routers'
@ -84,8 +108,8 @@ const filterTreeByPerms = (tree, availablePerms) => {
} }
return tree.reduce((acc, node) => { return tree.reduce((acc, node) => {
// Recursively filter children // Recursively filter children
const children = node.list && node.list.length > 0 const children = node.list && node.list.length > 0
? filterTreeByPerms(node.list, availablePerms) ? filterTreeByPerms(node.list, availablePerms)
: []; : [];
// A node is kept if its permission is in the available list, // A node is kept if its permission is in the available list,
@ -131,6 +155,8 @@ export default {
}; };
return { return {
resetPasswordDialogVisible: false,
newPassword: '',
form: { form: {
operationType: 'create', operationType: 'create',
username: '', username: '',
@ -139,7 +165,8 @@ export default {
mobile: '', mobile: '',
permissionCodes: [], permissionCodes: [],
remark: '', remark: '',
accountId: null accountId: null,
enable: true
}, },
subAccountList: [], subAccountList: [],
permissionList: [], permissionList: [],
@ -182,7 +209,7 @@ export default {
this.form.permissionCodes = []; this.form.permissionCodes = [];
this.form.remark = ''; this.form.remark = '';
this.form.accountId = null; this.form.accountId = null;
// Clear validation messages after the DOM has updated // Clear validation messages after the DOM has updated
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.ruleFormRef.clearValidate(); this.$refs.ruleFormRef.clearValidate();
@ -210,13 +237,30 @@ export default {
this.permissionList = mapTreeForElTree(filteredTree); 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() { handleTreeCheck() {
// getCheckedKeys(true) will return an array of keys of the currently checked leaf nodes. // getCheckedKeys(true) will return an array of keys of the currently checked leaf nodes.
this.form.permissionCodes = this.$refs.permissionTree.getCheckedKeys(true); this.form.permissionCodes = this.$refs.permissionTree.getCheckedKeys(true);
}, },
loadSubAccountList() { loadSubAccountList() {
getSubAccountList().then(res => { getSubAccountList().then(res => {
this.subAccountList = res.data.data || []; this.subAccountList = res.data.data.data || [];
}); });
}, },
handleAccountChange(accountId) { handleAccountChange(accountId) {
@ -227,6 +271,7 @@ export default {
this.form.mobile = accountDetails.mobile; this.form.mobile = accountDetails.mobile;
this.form.remark = accountDetails.remark; this.form.remark = accountDetails.remark;
this.form.permissionCodes = accountDetails.permissionCodes || []; this.form.permissionCodes = accountDetails.permissionCodes || [];
this.form.enable = accountDetails.enabled;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.permissionTree.setCheckedKeys(this.form.permissionCodes); this.$refs.permissionTree.setCheckedKeys(this.form.permissionCodes);
}); });
@ -255,7 +300,7 @@ export default {
mobile: this.form.mobile, mobile: this.form.mobile,
permissionCodes: this.form.permissionCodes, permissionCodes: this.form.permissionCodes,
remark: this.form.remark, remark: this.form.remark,
enabled: true // true enabled: this.form.enable
}; };
updateSubAccount(updateData).then(() => { updateSubAccount(updateData).then(() => {
this.$message.success('更新成功'); this.$message.success('更新成功');