perf: 选项显示图标

This commit is contained in:
xiaojunnuo
2024-11-30 01:57:09 +08:00
parent 7b55337c5e
commit aedc462135
54 changed files with 298 additions and 52 deletions

View File

@@ -2,6 +2,7 @@ import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { LoginService } from '../../modules/login/service/login-service.js';
import { BaseController, Constants, SysPublicSettings, SysSettingsService } from '@certd/lib-server';
import { CodeService } from '../../modules/basic/service/code-service.js';
import { checkComm } from '@certd/plus-core';
/**
*/
@@ -21,11 +22,6 @@ export class LoginController extends BaseController {
@Body(ALL)
user: any
) {
const settings = await this.sysSettingsService.getSetting<SysPublicSettings>(SysPublicSettings);
if (settings.passwordLoginEnabled === false) {
throw new Error('当前站点已禁止密码登录');
}
const token = await this.loginService.loginByPassword(user);
this.ctx.cookies.set('token', token.token, {
maxAge: 1000 * token.expire,
@@ -43,6 +39,7 @@ export class LoginController extends BaseController {
if (settings.smsLoginEnabled !== true) {
throw new Error('当前站点禁止短信验证码登录');
}
checkComm();
const token = await this.loginService.loginBySmsCode({
phoneCode: body.phoneCode,

View File

@@ -2,6 +2,7 @@ import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { BaseController, Constants, SysSettingsService } from '@certd/lib-server';
import { RegisterType, UserService } from '../../modules/sys/authority/service/user-service.js';
import { CodeService } from '../../modules/basic/service/code-service.js';
import { checkComm, checkPlus } from '@certd/plus-core';
export type RegisterReq = {
type: RegisterType;
@@ -53,6 +54,7 @@ export class RegisterController extends BaseController {
if (sysPublicSettings.mobileRegisterEnabled === false) {
throw new Error('当前站点已禁止手机号注册功能');
}
checkComm();
//验证短信验证码
await this.codeService.checkSmsCode({
mobile: body.mobile,
@@ -71,6 +73,7 @@ export class RegisterController extends BaseController {
if (sysPublicSettings.emailRegisterEnabled === false) {
throw new Error('当前站点已禁止Email注册功能');
}
checkPlus();
this.codeService.checkEmailCode({
email: body.email,
randomStr: body.randomStr,

View File

@@ -2,6 +2,7 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/c
import { Constants, CrudController } from '@certd/lib-server';
import { AccessService } from '../../modules/pipeline/service/access-service.js';
import { AuthService } from '../../modules/sys/authority/service/auth-service.js';
import { AccessDefine } from '@certd/pipeline';
/**
* 授权
@@ -77,12 +78,13 @@ export class AccessController extends CrudController<AccessService> {
@Post('/accessTypeDict', { summary: Constants.per.authOnly })
async getAccessTypeDict() {
const list = this.service.getDefineList();
const list: AccessDefine[] = this.service.getDefineList();
const dict = [];
for (const item of list) {
dict.push({
value: item.name,
label: item.title,
icon: item.icon,
});
}
return this.ok(dict);

View File

@@ -2,6 +2,8 @@ import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/c
import { Constants, CrudController, ValidateException } from '@certd/lib-server';
import { NotificationService } from '../../modules/pipeline/service/notification-service.js';
import { AuthService } from '../../modules/sys/authority/service/auth-service.js';
import { NotificationDefine } from '@certd/pipeline';
import { checkPlus } from '@certd/plus-core';
/**
* 通知
@@ -43,12 +45,35 @@ export class NotificationController extends CrudController<NotificationService>
@Post('/add', { summary: Constants.per.authOnly })
async add(@Body(ALL) bean) {
bean.userId = this.getUserId();
const type = bean.type;
const define: NotificationDefine = this.service.getDefineByType(type);
if (!define) {
throw new ValidateException('通知类型不存在');
}
if (define.needPlus) {
checkPlus();
}
return super.add(bean);
}
@Post('/update', { summary: Constants.per.authOnly })
async update(@Body(ALL) bean) {
await this.service.checkUserId(bean.id, this.getUserId());
const old = await this.service.info(bean.id);
if (!old) {
throw new ValidateException('通知配置不存在');
}
if (old.type !== bean.type) {
const type = bean.type;
const define: NotificationDefine = this.service.getDefineByType(type);
if (!define) {
throw new ValidateException('通知类型不存在');
}
if (define.needPlus) {
checkPlus();
}
}
return super.update(bean);
}
@Post('/info', { summary: Constants.per.authOnly })
@@ -71,14 +96,19 @@ export class NotificationController extends CrudController<NotificationService>
@Post('/getTypeDict', { summary: Constants.per.authOnly })
async getTypeDict() {
const list = this.service.getDefineList();
const dict = [];
const list: any = this.service.getDefineList();
let dict = [];
for (const item of list) {
dict.push({
value: item.name,
label: item.title,
needPlus: item.needPlus ?? false,
icon: item.icon,
});
}
dict = dict.sort(a => {
return a.needPlus ? 0 : -1;
});
return this.ok(dict);
}

View File

@@ -1,11 +1,12 @@
import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
import { CrudController, SysPrivateSettings, SysPublicSettings, SysSettingsEntity, SysSettingsService } from '@certd/lib-server';
import * as _ from 'lodash-es';
import { merge } from 'lodash-es';
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
import { UserSettingsService } from '../../../modules/mine/service/user-settings-service.js';
import { getEmailSettings } from '../../../modules/sys/settings/fix.js';
import { http, logger } from '@certd/basic';
import { merge } from 'lodash-es';
import { http, logger, simpleNanoId } from '@certd/basic';
import { CodeService } from '../../../modules/basic/service/code-service.js';
/**
*/
@@ -18,6 +19,8 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
userSettingsService: UserSettingsService;
@Inject()
pipelineService: PipelineService;
@Inject()
codeService: CodeService;
getService() {
return this.service;
@@ -111,7 +114,7 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
return this.ok({});
}
@Post('/testProxy', { summary: 'sys:settings:view' })
@Post('/testProxy', { summary: 'sys:settings:edit' })
async testProxy(@Body(ALL) body) {
const google = 'https://www.google.com/';
const baidu = 'https://www.baidu.com/';
@@ -148,4 +151,10 @@ export class SysSettingsController extends CrudController<SysSettingsService> {
baidu: baiduRes,
});
}
@Post('/testSms', { summary: 'sys:settings:edit' })
async testSms(@Body(ALL) body) {
await this.codeService.sendSmsCode(body.phoneCode, body.mobile, simpleNanoId());
return this.ok({});
}
}