feat: 新增电工 APP 账号开通与密码重置功能

- 新增后端重置密码接口及前端对应操作入口
- 新增补开电工 APP 账号的更新参数
- 新增 hasAccount 字段标识电工是否开通 APP 账号
- 新增数据库菜单及角色绑定支持密码重置权限
- 移除后台角色中错误的 WORKER 和 CUSTOMER 角色
This commit is contained in:
andyesfly committed 2026-10-11 15:07:45 +08:00
1 parent 6cf6a3d5b9
commit f8117e33b6
9 files changed
+164 -18

No files matched your search

+23 -4
View File
@@ -104,10 +104,12 @@ export class WorkerService {
};
}
// 剔除敏感字段
// 剔除敏感字段;额外返回是否已开通 APP 登录账号
private cleanWorker(worker: Worker): any {
const data = worker.toJSON ? worker.toJSON() : { ...worker };
const hasAccount = !!data.passwordHash;
delete data.passwordHash;
data.hasAccount = hasAccount;
return data;
}
@@ -171,7 +173,6 @@ export class WorkerService {
if (certStatus) {
const rows = await this.workerModel.findAll({
where,
attributes: { exclude: ["passwordHash"] },
order: [["rating", "DESC"]]
});
const certMap = await this.loadCertMap(rows.map((r) => Number(r.id)));
@@ -195,7 +196,6 @@ export class WorkerService {
// 常规分页:仅对当前页电工批量加载证书
const { count, rows } = await this.workerModel.findAndCountAll({
where,
attributes: { exclude: ["passwordHash"] },
limit: pageSize,
offset: (page - 1) * pageSize,
order: [["rating", "DESC"]],
@@ -240,7 +240,7 @@ export class WorkerService {
// 详情:含完整证书数组
async detail(id: number): Promise<any> {
const worker = await this.workerModel.findByPk(id, { attributes: { exclude: ["passwordHash"] } });
const worker = await this.workerModel.findByPk(id);
if (!worker) {
return { code: 404, message: "电工不存在", data: null };
}
@@ -310,6 +310,10 @@ export class WorkerService {
if (dto.status !== undefined) payload.status = dto.status;
if (dto.rating !== undefined) payload.rating = dto.rating;
if (dto.certInfo !== undefined) payload.certInfo = dto.certInfo;
// 补开 APP 账号:仅对尚未开通(无密码哈希)的电工生效,默认密码为手机号后 6 位
if (dto.withAccount === true && !worker.passwordHash) {
payload.passwordHash = await hashPassword(getDefaultPassword(dto.phone || worker.phone));
}
await worker.update(payload);
@@ -326,6 +330,21 @@ export class WorkerService {
return { code: 200, message: "更新电工成功", data: this.cleanWorker(worker) };
}
// 重置 APP 登录密码:固定重置为手机号后 6 位;未开通账号时一并开通
async resetPassword(id: number): Promise<any> {
const worker = await this.workerModel.findByPk(id);
if (!worker) {
return { code: 404, message: "电工不存在", data: null };
}
if (!worker.phone) {
return { code: 400, message: "该电工未登记手机号,无法重置密码", data: null };
}
await worker.update({ passwordHash: await hashPassword(getDefaultPassword(worker.phone)) });
return { code: 200, message: "重置密码成功", data: this.cleanWorker(worker) };
}
// 删除电工:存在派单记录则拒绝;否则级联删除证书并清理通知
async remove(id: number): Promise<any> {
const worker = await this.workerModel.findByPk(id);