From 4b0e57f0f2804e29793c0382e63553adb0dc3652 Mon Sep 17 00:00:00 2001 From: COOL Date: Sun, 16 Apr 2023 23:02:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/base/init.sql | 8 ++++++++ src/modules/user/service/info.ts | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/modules/base/init.sql b/src/modules/base/init.sql index 0377aeb..8431f7e 100644 --- a/src/modules/base/init.sql +++ b/src/modules/base/init.sql @@ -289,6 +289,14 @@ INSERT INTO `base_sys_menu` VALUES (450, '2023-03-07 10:28:17.692000', '2023-03- INSERT INTO `base_sys_menu` VALUES (451, '2023-03-07 10:28:44.322000', '2023-03-07 10:28:44.322000', 449, '编辑器', '/demo/editor', NULL, 1, 'icon-favor', 2, 'modules/demo/views/editor.vue', 1, 1); INSERT INTO `base_sys_menu` VALUES (452, '2023-03-07 10:29:06.344000', '2023-03-07 10:29:06.344000', 449, '文件上传', '/demo/upload', NULL, 1, 'icon-favor', 3, 'modules/demo/views/upload.vue', 1, 1); INSERT INTO `base_sys_menu` VALUES (453, '2023-03-15 10:38:43.677000', '2023-03-15 10:38:43.677000', 8, '编辑', NULL, 'base:sys:menu:info,base:sys:menu:update', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (454, '2023-04-16 21:59:16.442000', '2023-04-16 21:59:16.442000', NULL, '用户管理', NULL, NULL, 0, 'icon-user', 8, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (455, '2023-04-16 21:59:58.296000', '2023-04-16 21:59:58.296000', 454, '用户列表', '/user/list', NULL, 1, 'icon-menu', 1, 'modules/user/views/list.vue', 1, 1); +INSERT INTO `base_sys_menu` VALUES (456, '2023-04-16 21:59:58.525729', '2023-04-16 21:59:58.525729', 455, '删除', NULL, 'user:info:delete', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (457, '2023-04-16 21:59:58.525729', '2023-04-16 21:59:58.525729', 455, '修改', NULL, 'user:info:update,user:info:info', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (458, '2023-04-16 21:59:58.525729', '2023-04-16 21:59:58.525729', 455, '单个信息', NULL, 'user:info:info', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (459, '2023-04-16 21:59:58.525729', '2023-04-16 21:59:58.525729', 455, '列表查询', NULL, 'user:info:list', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (460, '2023-04-16 21:59:58.525729', '2023-04-16 21:59:58.525729', 455, '分页查询', NULL, 'user:info:page', 2, NULL, 0, NULL, 1, 1); +INSERT INTO `base_sys_menu` VALUES (461, '2023-04-16 21:59:58.525729', '2023-04-16 21:59:58.525729', 455, '新增', NULL, 'user:info:add', 2, NULL, 0, NULL, 1, 1); COMMIT; -- ---------------------------- diff --git a/src/modules/user/service/info.ts b/src/modules/user/service/info.ts index d67a3b6..e9d7eae 100644 --- a/src/modules/user/service/info.ts +++ b/src/modules/user/service/info.ts @@ -1,5 +1,5 @@ import { Inject, Provide } from '@midwayjs/decorator'; -import { BaseService } from '@cool-midway/core'; +import { BaseService, CoolCommException } from '@cool-midway/core'; import { InjectEntityModel } from '@midwayjs/typeorm'; import { Repository } from 'typeorm'; import { UserInfoEntity } from '../entity/info'; @@ -27,14 +27,18 @@ export class UserInfoService extends BaseService { } async updatePerson(id, param) { - const info = await this.person(id); - // 修改了头像要重新处理 - if (param.avatarUrl && info.avatarUrl != param.avatarUrl) { - param.avatarUrl = await this.file.downAndUpload( - param.avatarUrl, - uuid() + '.png' - ); + try { + const info = await this.person(id); + // 修改了头像要重新处理 + if (param.avatarUrl && info.avatarUrl != param.avatarUrl) { + param.avatarUrl = await this.file.downAndUpload( + param.avatarUrl, + uuid() + '.png' + ); + } + return await this.userInfoEntity.update({ id }, param); + } catch (err) { + throw new CoolCommException('更新失败,参数错误或者手机号已存在'); } - return await this.userInfoEntity.update({ id }, param); } }