refactor: 取消用户默认密码,改为表单填写密码

This commit is contained in:
2024-02-02 23:44:42 +08:00
parent 735982373a
commit e519d746c9
4 changed files with 121 additions and 62 deletions

View File

@@ -6,6 +6,18 @@
<a href="https://github.com/Charles7c/continew-admin-ui" target="_blank">
<img src="https://img.shields.io/badge/SNAPSHOT-v2.4.0-%23ff3f59.svg" alt="Release" />
</a>
<a href="https://cn.vuejs.org/" target="_blank">
<img src="https://img.shields.io/badge/Vue-3.3.7-%236CB52D.svg?logo=Vue.js" alt="Release" />
</a>
<a href="https://arco.design/vue/docs/start" target="_blank">
<img src="https://img.shields.io/badge/Arco Design-2.53.3-%236CB52D.svg" alt="Release" />
</a>
<a href="https://ts.nodejs.cn/" target="_blank">
<img src="https://img.shields.io/badge/TypeScript-5.3.3-%236CB52D.svg?logo=TypeScript&logoColor=FFF" alt="Release" />
</a>
<a href="https://cn.vitejs.dev/" target="_blank">
<img src="https://img.shields.io/badge/Vite-4.5.1-%236CB52D.svg?logo=Vite&logoColor=FFF" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-admin" target="_blank">
<img src="https://img.shields.io/github/stars/Charles7c/continew-admin?style=social" alt="GitHub stars" />
</a>
@@ -18,18 +30,6 @@
<a href="https://gitee.com/Charles7c/continew-admin" target="_blank">
<img src="https://gitee.com/Charles7c/continew-admin/badge/fork.svg?theme=white" alt="Gitee forks" />
</a>
<a href="https://github.com/Charles7c/continew-admin-ui" target="_blank">
<img src="https://img.shields.io/badge/Vue-3.3.7-%236CB52D.svg" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-admin-ui" target="_blank">
<img src="https://img.shields.io/badge/Arco Design Vue-2.53.3-%236CB52D.svg" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-admin-ui" target="_blank">
<img src="https://img.shields.io/badge/TypeScript-5.3.3-%236CB52D.svg" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-admin-ui" target="_blank">
<img src="https://img.shields.io/badge/Vite-4.5.1-%236CB52D.svg" alt="Release" />
</a>
📚 [在线文档](https://doc.charles7c.top) | 🚀 [演示地址](https://cnadmin.charles7c.top)(账号/密码admin/admin123

View File

@@ -7,6 +7,7 @@ export interface DataRecord {
id?: number;
username?: string;
nickname?: string;
password?: string;
gender?: number;
email?: string;
phone?: string;
@@ -25,6 +26,10 @@ export interface DataRecord {
disabled?: boolean;
}
export interface UserResetReq {
newPassword: string;
}
export interface ListParam {
username?: string;
status?: number;
@@ -64,8 +69,8 @@ export function del(ids: number | Array<number>) {
return axios.delete(`${BASE_URL}/${ids}`);
}
export function resetPassword(id: number) {
return axios.patch(`${BASE_URL}/${id}/password`);
export function resetPassword(req: UserResetReq, id: number) {
return axios.patch(`${BASE_URL}/${id}/password`, req);
}
export interface UpdateUserRoleReq {

View File

@@ -68,7 +68,7 @@
callback(
t(
'userCenter.securitySettings.updatePwd.form.error.validator.rePassword'
)
),
);
} else {
callback();

View File

@@ -15,6 +15,7 @@
import { LabelValueState } from '@/store/modules/dict/types';
import getAvatar from '@/utils/avatar';
import checkPermission from '@/utils/permission';
import { encryptByRsa } from '@/utils/encrypt';
const { proxy } = getCurrentInstance() as any;
const { dis_enable_status_enum } = proxy.useDict('dis_enable_status_enum');
@@ -31,6 +32,7 @@
const detailLoading = ref(false);
const exportLoading = ref(false);
const visible = ref(false);
const resetPasswordVisible = ref(false);
const userRoleVisible = ref(false);
const detailVisible = ref(false);
const deptLoading = ref(false);
@@ -57,6 +59,7 @@
rules: {
username: [{ required: true, message: '请输入用户名' }],
nickname: [{ required: true, message: '请输入昵称' }],
password: [{ required: true, message: '请输入密码' }],
deptId: [{ required: true, message: '请选择所属部门' }],
roleIds: [{ required: true, message: '请选择所属角色' }],
},
@@ -126,6 +129,17 @@
});
};
/**
* 打开重置密码对话框
*
* @param id ID
*/
const toResetPassword = (id: number) => {
reset();
form.value.id = id;
resetPasswordVisible.value = true;
};
/**
* 打开分配角色对话框
*
@@ -183,8 +197,10 @@
*/
const handleCancel = () => {
visible.value = false;
resetPasswordVisible.value = false;
userRoleVisible.value = false;
proxy.$refs.formRef?.resetFields();
proxy.$refs.resetPasswordFormRef?.resetFields();
proxy.$refs.userRoleFormRef?.resetFields();
};
@@ -201,16 +217,42 @@
proxy.$message.success(res.msg);
});
} else {
add(form.value).then((res) => {
const rawPassword = form.value.password;
if (rawPassword) {
form.value.password = encryptByRsa(rawPassword) || '';
}
add(form.value)
.then((res) => {
handleCancel();
getList();
proxy.$message.success(res.msg);
})
.catch(() => {
form.value.password = rawPassword;
});
}
}
});
};
/**
* 重置密码
*/
const handleResetPassword = () => {
proxy.$refs.resetPasswordFormRef.validate((valid: any) => {
if (!valid && form.value.id !== undefined) {
const newPassword = form.value.password;
resetPassword({ newPassword: encryptByRsa(newPassword) }, form.value.id)
.then((res) => {
handleCancel();
getList();
proxy.$message.success(res.msg);
})
.catch();
}
});
};
/**
* 修改角色
*/
@@ -285,17 +327,6 @@
});
};
/**
* 重置密码
*
* @param id ID
*/
const handleResetPassword = (id: number) => {
resetPassword(id).then((res) => {
proxy.$message.success(res.msg);
});
};
/**
* 已选择的数据行发生改变时触发
*
@@ -578,7 +609,13 @@
}}</a-link>
</template>
</a-table-column>
<a-table-column title="昵称" data-index="nickname" :width="115" ellipsis tooltip />
<a-table-column
title="昵称"
data-index="nickname"
:width="115"
ellipsis
tooltip
/>
<a-table-column title="性别" align="center">
<template #cell="{ record }">
<span v-if="record.gender === 1"></span>
@@ -622,7 +659,12 @@
<a-tag v-else color="arcoblue"></a-tag>
</template>
</a-table-column>
<a-table-column title="描述" data-index="description" ellipsis tooltip />
<a-table-column
title="描述"
data-index="description"
ellipsis
tooltip
/>
<a-table-column title="创建人/创建时间" :width="175">
<template #cell="{ record }">
{{ record.createUserString }}<br />
@@ -668,22 +710,15 @@
<template #icon><icon-delete /></template>
</a-button>
</a-popconfirm>
<a-popconfirm
content="是否确定重置当前用户的密码?"
type="warning"
@ok="handleResetPassword(record.id)"
>
<a-button
v-permission="['system:user:password:reset']"
type="text"
size="small"
title="重置密码"
@click="toResetPassword(record.id)"
>
<template #icon
><svg-icon icon-class="privacy"
/></template>
<template #icon><svg-icon icon-class="privacy" /></template>
</a-button>
</a-popconfirm>
<a-button
v-permission="['system:user:role:update']"
type="text"
@@ -715,19 +750,11 @@
@ok="handleOk"
@cancel="handleCancel"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col-style="{ width: '84px' }"
size="large"
layout="inline"
>
<a-form ref="formRef" :model="form" :rules="rules" size="large">
<a-form-item label="用户名" field="username">
<a-input
v-model="form.username"
placeholder="请输入用户名"
style="width: 162px"
:max-length="64"
/>
</a-form-item>
@@ -736,7 +763,13 @@
v-model="form.nickname"
placeholder="请输入昵称"
:max-length="30"
style="width: 162px"
/>
</a-form-item>
<a-form-item v-if="!form.id" label="密码" field="password">
<a-input-password
v-model="form.password"
placeholder="请输入密码"
:max-length="32"
/>
</a-form-item>
<a-form-item label="邮箱" field="email">
@@ -744,7 +777,6 @@
v-model="form.email"
placeholder="请输入邮箱"
:max-length="255"
style="width: 162px"
/>
</a-form-item>
<a-form-item label="手机号码" field="phone">
@@ -752,11 +784,10 @@
v-model="form.phone"
placeholder="请输入手机号码"
:max-length="15"
style="width: 162px"
/>
</a-form-item>
<a-form-item label="性别" field="gender">
<a-radio-group v-model="form.gender">
<a-radio-group v-model="form.gender" style="width: 197px">
<a-radio :value="1">男</a-radio>
<a-radio :value="2">女</a-radio>
<a-radio :value="0" disabled>未知</a-radio>
@@ -770,7 +801,6 @@
allow-clear
allow-search
:filter-tree-node="filterDeptOptions"
style="width: 431px"
/>
</a-form-item>
<a-form-item
@@ -786,7 +816,6 @@
multiple
allow-clear
:allow-search="{ retainInputValue: true }"
style="width: 431px"
/>
</a-form-item>
<a-form-item label="描述" field="description">
@@ -798,7 +827,32 @@
minRows: 3,
}"
show-word-limit
style="width: 431px"
/>
</a-form-item>
</a-form>
</a-modal>
<a-modal
title="重置密码"
:visible="resetPasswordVisible"
:mask-closable="false"
:esc-to-close="false"
unmount-on-close
render-to-body
@ok="handleResetPassword"
@cancel="handleCancel"
>
<a-form
ref="resetPasswordFormRef"
:model="form"
:rules="rules"
size="large"
>
<a-form-item label="密码" field="password">
<a-input-password
v-model="form.password"
placeholder="请输入密码"
:max-length="32"
/>
</a-form-item>
</a-form>