登录配置passport修改
This commit is contained in:
parent
8a258d55d4
commit
c75be91c8f
|
|
@ -112,13 +112,13 @@ const checkers = [
|
|||
};
|
||||
if (remove instanceof Promise) {
|
||||
return remove.then((r) => {
|
||||
if (r[0].isDefault) {
|
||||
if (r[0]?.isDefault) {
|
||||
return updateDefaultFn(r[0].id, r[0].applicationId);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (remove[0].isDefault) {
|
||||
if (remove[0]?.isDefault) {
|
||||
return updateDefaultFn(remove[0].id, remove[0].applicationId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { cloneDeep, set } from "oak-domain/lib/utils/lodash";
|
||||
import { cloneDeep, set, } from "oak-domain/lib/utils/lodash";
|
||||
export default OakComponent({
|
||||
entity: 'passport',
|
||||
isList: true,
|
||||
|
|
@ -23,16 +23,16 @@ export default OakComponent({
|
|||
}
|
||||
}
|
||||
],
|
||||
sorters: [
|
||||
{
|
||||
sorter: {
|
||||
$attr: {
|
||||
enabled: 1,
|
||||
},
|
||||
$direction: 'desc',
|
||||
}
|
||||
}
|
||||
],
|
||||
// sorters: [
|
||||
// {
|
||||
// sorter: {
|
||||
// $attr: {
|
||||
// enabled: 1,
|
||||
// },
|
||||
// $direction: 'desc',
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
formData({ data }) {
|
||||
return {
|
||||
passports: data || [],
|
||||
|
|
@ -83,9 +83,126 @@ export default OakComponent({
|
|||
updateConfig(id, config, path, value) {
|
||||
const newConfig = cloneDeep(config);
|
||||
set(newConfig, path, value);
|
||||
if (path === 'mockSend' && !value) {
|
||||
if (!newConfig.templateName || newConfig.templateName === '') {
|
||||
this.setMessage({
|
||||
type: 'warning',
|
||||
content: '短信登录未配置模板名称,将无法正常使用短信登录'
|
||||
});
|
||||
}
|
||||
else if (!newConfig.defaultOrigin) {
|
||||
this.setMessage({
|
||||
type: 'warning',
|
||||
content: '短信登录未选择默认渠道,将无法正常使用短信登录'
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (path === 'appId' && (!value || value === '')) {
|
||||
this.setMessage({
|
||||
type: 'warning',
|
||||
content: '未填写appId,该登录方式将无法正常使用'
|
||||
});
|
||||
}
|
||||
this.updateItem({
|
||||
config: newConfig,
|
||||
}, id);
|
||||
},
|
||||
checkConfrim() {
|
||||
const { passports } = this.state;
|
||||
let warnings = [];
|
||||
for (const passport of passports) {
|
||||
const { type, config, enabled, id } = passport;
|
||||
if (enabled) {
|
||||
//检查启用的passport对应的config是否设置
|
||||
switch (type) {
|
||||
case 'sms':
|
||||
if (!config.mockSend) {
|
||||
if (!config.templateName || config.templateName === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '短信登录未配置验证码模板名称',
|
||||
});
|
||||
}
|
||||
if (!config.defaultOrigin) {
|
||||
const smsWarning = warnings.find((ele) => ele.id === id);
|
||||
if (smsWarning) {
|
||||
Object.assign(smsWarning, { tip: '短信登录未选择默认渠道且未配置验证码模板名称' });
|
||||
}
|
||||
else {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '短信登录未选择默认渠道',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'email':
|
||||
if (!config.smtpUrl || config.smtpUrl === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '邮箱登录未配置smtpUrl',
|
||||
});
|
||||
}
|
||||
if (!config.smtpAccount || config.smtpAccount === '') {
|
||||
const emailWarning = warnings.find((ele) => ele.id === id);
|
||||
if (emailWarning) {
|
||||
Object.assign(emailWarning, { tip: emailWarning.tip + '、smtpAccount' });
|
||||
}
|
||||
else {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '邮箱登录未配置smtpAccount',
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!config.smtpPassword || config.smtpPassword === '') {
|
||||
const emailWarning = warnings.find((ele) => ele.id === id);
|
||||
if (emailWarning) {
|
||||
Object.assign(emailWarning, { tip: emailWarning.tip + '、smtpPassword' });
|
||||
}
|
||||
else {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '邮箱登录未配置smtpPassword',
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'wechatPublicForWeb':
|
||||
if (!config.appId || config.appId === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '公众号授权登录未选择appId',
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'wechatMpForWeb':
|
||||
if (!config.appId || config.appId === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '小程序授权登录未选择appId',
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return warnings;
|
||||
},
|
||||
async myConfirm(ids) {
|
||||
//存在不完整的配置更新,保存更新时将相应的applicationPassport移除
|
||||
await this.features.cache.exec('removeApplicationPassportsByPIds', { passportIds: ids });
|
||||
await this.execute();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,4 +10,10 @@ export default function render(props: WebComponentProps<EntityDict, 'passport',
|
|||
publicAppIds: string[];
|
||||
}, {
|
||||
updateConfig: (id: string, config: SmsConfig | EmailConfig | PfwConfig | MfwConfig, path: string, value: any) => void;
|
||||
checkConfrim: () => {
|
||||
id: string;
|
||||
type: EntityDict['passport']['Schema']['type'];
|
||||
tip: string;
|
||||
}[];
|
||||
myConfirm: (ids: string[]) => void;
|
||||
}>): React.JSX.Element | undefined;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Space, Switch, Affix, Alert, Typography, Form, Input, Tooltip, Select } from 'antd';
|
||||
import { Button, Space, Switch, Affix, Alert, Typography, Form, Input, Tooltip, Select, Modal, Divider } from 'antd';
|
||||
import Styles from './web.pc.module.less';
|
||||
import classNames from 'classnames';
|
||||
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||||
const { confirm } = Modal;
|
||||
function AppView(props) {
|
||||
const { passport, mpAppIds, publicAppIds, t, changeEnabled, updateConfig } = props;
|
||||
const { id, type, config, enabled } = passport;
|
||||
|
|
@ -220,7 +222,31 @@ function AppView(props) {
|
|||
export default function render(props) {
|
||||
const { data, methods } = props;
|
||||
const { oakFullpath, oakExecutable, oakExecuting, oakDirty, systemId, passports, systemName, mpAppIds, publicAppIds, } = data;
|
||||
const { clean, execute, t, updateItem, updateConfig, } = methods;
|
||||
const { clean, execute, t, updateItem, updateConfig, checkConfrim, myConfirm } = methods;
|
||||
const showConfirm = (warnings) => {
|
||||
confirm({
|
||||
title: '确定保存当前更新吗?',
|
||||
icon: <ExclamationCircleFilled />,
|
||||
width: 540,
|
||||
content: <Space direction='vertical'>
|
||||
<div>当前登录方式配置存在以下问题可能影响登录:</div>
|
||||
{warnings.map((ele) => {
|
||||
return (<div key={ele.id}>
|
||||
<div style={{ width: 200 }}>
|
||||
<Divider orientation="left">{t(`passport:v.type.${ele.type}`)}{t('login')}</Divider>
|
||||
</div>
|
||||
<div style={{ fontSize: 13 }}>{ele.tip}</div>
|
||||
</div>);
|
||||
})}
|
||||
</Space>,
|
||||
async onOk() {
|
||||
const ids = warnings.map((ele) => ele.id);
|
||||
await myConfirm(ids);
|
||||
},
|
||||
onCancel() {
|
||||
},
|
||||
});
|
||||
};
|
||||
if (passports?.length > 0) {
|
||||
return (<>
|
||||
<Affix offsetTop={64}>
|
||||
|
|
@ -242,7 +268,15 @@ export default function render(props) {
|
|||
}}>
|
||||
重置
|
||||
</Button>
|
||||
<Button disabled={!oakDirty} type="primary" onClick={() => execute()}>
|
||||
<Button disabled={!oakDirty} type="primary" onClick={async () => {
|
||||
const warnings = checkConfrim();
|
||||
if (warnings && warnings.length > 0) {
|
||||
showConfirm(warnings);
|
||||
}
|
||||
else {
|
||||
await execute();
|
||||
}
|
||||
}}>
|
||||
确定
|
||||
</Button>
|
||||
</Space>}/>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import { Trigger } from 'oak-domain/lib/types/Trigger';
|
||||
import { EntityDict } from '../oak-app-domain/EntityDict';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
declare const triggers: Trigger<EntityDict, 'passport', BRC<EntityDict>>[];
|
||||
export default triggers;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
const triggers = [
|
||||
{
|
||||
name: '禁用passport时,将关联的passport删除',
|
||||
entity: 'passport',
|
||||
action: 'update',
|
||||
check: (operation) => {
|
||||
const { data } = operation;
|
||||
return data.hasOwnProperty('enabled') && data.enabled === false;
|
||||
},
|
||||
when: 'after',
|
||||
fn: async ({ operation }, context, option) => {
|
||||
const { data, filter } = operation;
|
||||
const applicationPassports = await context.select('applicationPassport', {
|
||||
data: {
|
||||
id: 1,
|
||||
},
|
||||
filter: {
|
||||
passport: filter,
|
||||
}
|
||||
}, { forUpdate: true });
|
||||
if (applicationPassports && applicationPassports.length > 0) {
|
||||
const ids = applicationPassports.map((ele) => ele.id);
|
||||
await context.operate('applicationPassport', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'remove',
|
||||
data: {},
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
];
|
||||
export default triggers;
|
||||
|
|
@ -114,13 +114,13 @@ const checkers = [
|
|||
};
|
||||
if (remove instanceof Promise) {
|
||||
return remove.then((r) => {
|
||||
if (r[0].isDefault) {
|
||||
if (r[0]?.isDefault) {
|
||||
return updateDefaultFn(r[0].id, r[0].applicationId);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (remove[0].isDefault) {
|
||||
if (remove[0]?.isDefault) {
|
||||
return updateDefaultFn(remove[0].id, remove[0].applicationId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import { Trigger } from 'oak-domain/lib/types/Trigger';
|
||||
import { EntityDict } from '../oak-app-domain/EntityDict';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
declare const triggers: Trigger<EntityDict, 'passport', BRC<EntityDict>>[];
|
||||
export default triggers;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||||
const triggers = [
|
||||
{
|
||||
name: '禁用passport时,将关联的passport删除',
|
||||
entity: 'passport',
|
||||
action: 'update',
|
||||
check: (operation) => {
|
||||
const { data } = operation;
|
||||
return data.hasOwnProperty('enabled') && data.enabled === false;
|
||||
},
|
||||
when: 'after',
|
||||
fn: async ({ operation }, context, option) => {
|
||||
const { data, filter } = operation;
|
||||
const applicationPassports = await context.select('applicationPassport', {
|
||||
data: {
|
||||
id: 1,
|
||||
},
|
||||
filter: {
|
||||
passport: filter,
|
||||
}
|
||||
}, { forUpdate: true });
|
||||
if (applicationPassports && applicationPassports.length > 0) {
|
||||
const ids = applicationPassports.map((ele) => ele.id);
|
||||
await context.operate('applicationPassport', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'remove',
|
||||
data: {},
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
];
|
||||
exports.default = triggers;
|
||||
|
|
@ -408,7 +408,13 @@ export type AspectDict<ED extends EntityDict> = {
|
|||
applicationId: string;
|
||||
},
|
||||
context: BackendRuntimeContext<ED>
|
||||
) => Promise<EntityDict['applicationPassport']['Schema'][]>
|
||||
) => Promise<EntityDict['applicationPassport']['Schema'][]>;
|
||||
removeApplicationPassportsByPIds: (
|
||||
params: {
|
||||
passportIds: string[];
|
||||
},
|
||||
content: BackendRuntimeContext<ED>
|
||||
) => Promise<void>;
|
||||
};
|
||||
|
||||
export default AspectDict;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { pipeline } from "oak-domain/lib/utils/executor";
|
||||
import { EntityDict } from "../oak-app-domain";
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
import { generateNewIdAsync } from "oak-domain/lib/utils/uuid";
|
||||
|
||||
export async function getApplicationPassports<ED extends EntityDict>(
|
||||
params: {
|
||||
|
|
@ -30,4 +32,41 @@ export async function getApplicationPassports<ED extends EntityDict>(
|
|||
closeRoot();
|
||||
|
||||
return applicationPassports;
|
||||
}
|
||||
|
||||
export async function removeApplicationPassportsByPIds<ED extends EntityDict>(
|
||||
params: {
|
||||
passportIds: string[];
|
||||
},
|
||||
context: BRC<ED>
|
||||
) {
|
||||
const { passportIds } = params;
|
||||
const applicationPassports = await context.select(
|
||||
'applicationPassport',
|
||||
{
|
||||
data: {
|
||||
id: 1,
|
||||
passportId: 1,
|
||||
},
|
||||
filter: {
|
||||
passportId: {
|
||||
$in: passportIds,
|
||||
},
|
||||
}
|
||||
},
|
||||
{});
|
||||
if (applicationPassports && applicationPassports.length) {
|
||||
const ids = applicationPassports.map((ele) => ele.id!);
|
||||
await context.operate('applicationPassport',
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'remove',
|
||||
data: {},
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
},
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ import {
|
|||
import {
|
||||
wechatMpJump,
|
||||
} from './wechatMpJump';
|
||||
import { getApplicationPassports } from './applicationPassport';
|
||||
import { getApplicationPassports, removeApplicationPassportsByPIds } from './applicationPassport';
|
||||
|
||||
const aspectDict = {
|
||||
mergeUser,
|
||||
|
|
@ -119,6 +119,7 @@ const aspectDict = {
|
|||
wechatMpJump,
|
||||
syncSmsTemplate,
|
||||
getApplicationPassports,
|
||||
removeApplicationPassportsByPIds,
|
||||
};
|
||||
|
||||
export default aspectDict;
|
||||
|
|
|
|||
|
|
@ -123,12 +123,12 @@ const checkers: Checker<EntityDict, 'applicationPassport', RuntimeCxt<EntityDict
|
|||
}
|
||||
if (remove instanceof Promise) {
|
||||
return remove.then((r) => {
|
||||
if (r[0].isDefault) {
|
||||
if (r[0]?.isDefault) {
|
||||
return updateDefaultFn(r[0].id!, r[0].applicationId!);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (remove[0].isDefault) {
|
||||
if (remove[0]?.isDefault) {
|
||||
return updateDefaultFn(remove[0].id!, remove[0].applicationId!);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { cloneDeep, set } from "oak-domain/lib/utils/lodash";
|
||||
import { cloneDeep, set, } from "oak-domain/lib/utils/lodash";
|
||||
import { EmailConfig, MfwConfig, PfwConfig, SmsConfig, Type } from "../../entities/Passport";
|
||||
import { WebConfig, WechatMpConfig, WechatPublicConfig } from "../../entities/Application";
|
||||
import { generateNewIdAsync } from "oak-domain/lib/utils/uuid";
|
||||
|
||||
export default OakComponent({
|
||||
entity: 'passport',
|
||||
|
|
@ -26,16 +27,16 @@ export default OakComponent({
|
|||
}
|
||||
}
|
||||
],
|
||||
sorters: [
|
||||
{
|
||||
sorter: {
|
||||
$attr: {
|
||||
enabled: 1,
|
||||
},
|
||||
$direction: 'desc',
|
||||
}
|
||||
}
|
||||
],
|
||||
// sorters: [
|
||||
// {
|
||||
// sorter: {
|
||||
// $attr: {
|
||||
// enabled: 1,
|
||||
// },
|
||||
// $direction: 'desc',
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
formData({ data }) {
|
||||
return {
|
||||
passports: data || [],
|
||||
|
|
@ -88,10 +89,123 @@ export default OakComponent({
|
|||
updateConfig(id: string, config: SmsConfig | EmailConfig | PfwConfig | MfwConfig, path: string, value: any) {
|
||||
const newConfig = cloneDeep(config);
|
||||
set(newConfig, path, value);
|
||||
if (path === 'mockSend' && !value) {
|
||||
if (!(newConfig as SmsConfig).templateName || (newConfig as SmsConfig).templateName === '') {
|
||||
this.setMessage({
|
||||
type: 'warning',
|
||||
content: '短信登录未配置模板名称,将无法正常使用短信登录'
|
||||
})
|
||||
} else if (!(newConfig as SmsConfig).defaultOrigin) {
|
||||
this.setMessage({
|
||||
type: 'warning',
|
||||
content: '短信登录未选择默认渠道,将无法正常使用短信登录'
|
||||
})
|
||||
}
|
||||
} else if (path === 'appId' && (!value || value === '')) {
|
||||
this.setMessage({
|
||||
type: 'warning',
|
||||
content: '未填写appId,该登录方式将无法正常使用'
|
||||
})
|
||||
}
|
||||
this.updateItem({
|
||||
config: newConfig,
|
||||
}, id);
|
||||
|
||||
},
|
||||
checkConfrim() {
|
||||
const { passports } = this.state;
|
||||
let warnings = [];
|
||||
for (const passport of passports) {
|
||||
const { type, config, enabled, id } = passport;
|
||||
if (enabled) {
|
||||
//检查启用的passport对应的config是否设置
|
||||
switch (type) {
|
||||
case 'sms':
|
||||
if (!(config as SmsConfig).mockSend) {
|
||||
if (!(config as SmsConfig).templateName || (config as SmsConfig).templateName === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '短信登录未配置验证码模板名称',
|
||||
});
|
||||
}
|
||||
if (!(config as SmsConfig).defaultOrigin) {
|
||||
const smsWarning = warnings.find((ele) => ele.id === id);
|
||||
if (smsWarning) {
|
||||
Object.assign(smsWarning, { tip: '短信登录未选择默认渠道且未配置验证码模板名称' });
|
||||
} else {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '短信登录未选择默认渠道',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'email':
|
||||
if (!(config as EmailConfig).smtpUrl || (config as EmailConfig).smtpUrl === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '邮箱登录未配置smtpUrl',
|
||||
});
|
||||
}
|
||||
if (!(config as EmailConfig).smtpAccount || (config as EmailConfig).smtpAccount === '') {
|
||||
const emailWarning = warnings.find((ele) => ele.id === id);
|
||||
if (emailWarning) {
|
||||
Object.assign(emailWarning, { tip: emailWarning.tip + '、smtpAccount' });
|
||||
} else {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '邮箱登录未配置smtpAccount',
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!(config as EmailConfig).smtpPassword || (config as EmailConfig).smtpPassword === '') {
|
||||
const emailWarning = warnings.find((ele) => ele.id === id);
|
||||
if (emailWarning) {
|
||||
Object.assign(emailWarning, { tip: emailWarning.tip + '、smtpPassword' });
|
||||
} else {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '邮箱登录未配置smtpPassword',
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'wechatPublicForWeb':
|
||||
if (!(config as PfwConfig).appId || (config as PfwConfig).appId === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '公众号授权登录未选择appId',
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'wechatMpForWeb':
|
||||
if (!(config as MfwConfig).appId || (config as MfwConfig).appId === '') {
|
||||
warnings.push({
|
||||
id,
|
||||
type,
|
||||
tip: '小程序授权登录未选择appId',
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return warnings;
|
||||
},
|
||||
async myConfirm(ids: string[]) {
|
||||
//存在不完整的配置更新,保存更新时将相应的applicationPassport移除
|
||||
await this.features.cache.exec('removeApplicationPassportsByPIds', { passportIds: ids })
|
||||
await this.execute();
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Space, Switch, Affix, Alert, Typography, Form, Input, Tooltip, Select } from 'antd';
|
||||
import { Button, Space, Switch, Affix, Alert, Typography, Form, Input, Tooltip, Select, Modal, Divider } from 'antd';
|
||||
import { WebComponentProps } from 'oak-frontend-base';
|
||||
import { EntityDict } from '../../oak-app-domain';
|
||||
import Styles from './web.pc.module.less';
|
||||
import classNames from 'classnames';
|
||||
import { SmsConfig, EmailConfig, PfwConfig, MfwConfig } from '../../entities/Passport';
|
||||
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||||
|
||||
const { confirm } = Modal;
|
||||
|
||||
function AppView(props: {
|
||||
passport: EntityDict['passport']['OpSchema'];
|
||||
|
|
@ -21,8 +24,6 @@ function AppView(props: {
|
|||
const [smtpUrl, setSmtpUrl] = useState((config as EmailConfig)?.smtpUrl || '');
|
||||
const [smtpAccount, setSmtpAccount] = useState((config as EmailConfig)?.smtpAccount || '');
|
||||
const [smtpPassword, setSmtpPassword] = useState((config as EmailConfig)?.smtpPassword || '');
|
||||
const [mAppId, setMAppId] = useState((config as MfwConfig)?.appId || '');
|
||||
const [pAppId, setPAppId] = useState((config as PfwConfig)?.appId || '');
|
||||
|
||||
useEffect(() => {
|
||||
if (type === 'sms') {
|
||||
|
|
@ -32,10 +33,6 @@ function AppView(props: {
|
|||
setSmtpUrl((config as EmailConfig)?.smtpUrl || '');
|
||||
setSmtpAccount((config as EmailConfig)?.smtpAccount || '');
|
||||
setSmtpPassword((config as EmailConfig)?.smtpPassword || '');
|
||||
} else if (type === 'wechatMpForWeb') {
|
||||
setMAppId((config as MfwConfig)?.appId || '');
|
||||
} else if (type === 'wechatPublicForWeb') {
|
||||
setPAppId((config as PfwConfig)?.appId || '');
|
||||
}
|
||||
}, [config]);
|
||||
switch (type) {
|
||||
|
|
@ -233,8 +230,8 @@ function AppView(props: {
|
|||
unCheckedChildren="关闭"
|
||||
checked={enabled}
|
||||
onChange={(checked) => {
|
||||
changeEnabled(checked)
|
||||
if (checked && publicAppIds.length === 1) {
|
||||
changeEnabled(checked);
|
||||
if (checked && !(config as PfwConfig)?.appId) {
|
||||
updateConfig(id, config!, 'appId', publicAppIds[0]);
|
||||
}
|
||||
}}
|
||||
|
|
@ -249,16 +246,16 @@ function AppView(props: {
|
|||
style={{ maxWidth: 900, marginTop: 16 }}
|
||||
>
|
||||
<Form.Item label="appId">
|
||||
<Input
|
||||
<Select
|
||||
placeholder="请输入appId"
|
||||
type="text"
|
||||
value={pAppId}
|
||||
onChange={(e) => {
|
||||
setPAppId(e.target.value);
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (pAppId !== (config as PfwConfig)?.appId) {
|
||||
updateConfig(id, config!, 'appId', pAppId);
|
||||
value={(config as PfwConfig)?.appId}
|
||||
options={publicAppIds.map((ele) => ({
|
||||
label: ele,
|
||||
value: ele
|
||||
}))}
|
||||
onChange={(value) => {
|
||||
if (value !== (config as PfwConfig)?.appId) {
|
||||
updateConfig(id, config!, 'appId', value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
@ -280,8 +277,8 @@ function AppView(props: {
|
|||
unCheckedChildren="关闭"
|
||||
checked={enabled}
|
||||
onChange={(checked) => {
|
||||
changeEnabled(checked)
|
||||
if (checked && mpAppIds.length === 1) {
|
||||
changeEnabled(checked);
|
||||
if (checked && !(config as MfwConfig)?.appId) {
|
||||
updateConfig(id, config!, 'appId', mpAppIds[0]);
|
||||
}
|
||||
}}
|
||||
|
|
@ -296,16 +293,17 @@ function AppView(props: {
|
|||
style={{ maxWidth: 900, marginTop: 16 }}
|
||||
>
|
||||
<Form.Item label="appId">
|
||||
<Input
|
||||
|
||||
<Select
|
||||
placeholder="请输入appId"
|
||||
type="text"
|
||||
value={mAppId}
|
||||
onChange={(e) => {
|
||||
setMAppId(e.target.value);
|
||||
}}
|
||||
onBlur={() => {
|
||||
if (mAppId !== (config as MfwConfig)?.appId) {
|
||||
updateConfig(id, config!, 'appId', mAppId);
|
||||
value={(config as MfwConfig)?.appId}
|
||||
options={mpAppIds.map((ele) => ({
|
||||
label: ele,
|
||||
value: ele
|
||||
}))}
|
||||
onChange={(value) => {
|
||||
if (value !== (config as PfwConfig)?.appId) {
|
||||
updateConfig(id, config!, 'appId', value);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
@ -383,11 +381,45 @@ export default function render(props: WebComponentProps<
|
|||
},
|
||||
{
|
||||
updateConfig: (id: string, config: SmsConfig | EmailConfig | PfwConfig | MfwConfig, path: string, value: any) => void;
|
||||
checkConfrim: () => {
|
||||
id: string;
|
||||
type: EntityDict['passport']['Schema']['type'];
|
||||
tip: string;
|
||||
}[];
|
||||
myConfirm: (ids: string[]) => void;
|
||||
}
|
||||
>) {
|
||||
const { data, methods } = props;
|
||||
const { oakFullpath, oakExecutable, oakExecuting, oakDirty, systemId, passports, systemName, mpAppIds, publicAppIds, } = data;
|
||||
const { clean, execute, t, updateItem, updateConfig, } = methods;
|
||||
const { clean, execute, t, updateItem, updateConfig, checkConfrim, myConfirm } = methods;
|
||||
|
||||
const showConfirm = (warnings: { id: string, type: EntityDict['passport']['Schema']['type'], tip: string }[]) => {
|
||||
confirm({
|
||||
title: '确定保存当前更新吗?',
|
||||
icon: <ExclamationCircleFilled />,
|
||||
width: 540,
|
||||
content: <Space direction='vertical'>
|
||||
<div>当前登录方式配置存在以下问题可能影响登录:</div>
|
||||
{warnings.map((ele) => {
|
||||
return (
|
||||
<div key={ele.id}>
|
||||
<div style={{ width: 200 }}>
|
||||
<Divider orientation="left">{t(`passport:v.type.${ele.type}`)}{t('login')}</Divider>
|
||||
</div>
|
||||
<div style={{ fontSize: 13 }}>{ele.tip}</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</Space>,
|
||||
async onOk() {
|
||||
const ids = warnings.map((ele) => ele.id);
|
||||
await myConfirm(ids);
|
||||
},
|
||||
onCancel() {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
if (passports?.length > 0) {
|
||||
return (
|
||||
|
|
@ -427,7 +459,14 @@ export default function render(props: WebComponentProps<
|
|||
<Button
|
||||
disabled={!oakDirty}
|
||||
type="primary"
|
||||
onClick={() => execute()}
|
||||
onClick={async () => {
|
||||
const warnings = checkConfrim();
|
||||
if (warnings && warnings.length > 0) {
|
||||
showConfirm(warnings);
|
||||
} else {
|
||||
await execute();
|
||||
}
|
||||
}}
|
||||
>
|
||||
确定
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import wechatMenuTriggers from './wechatMenu';
|
|||
import wechatPublicTag from './wechatPublicTag';
|
||||
import wechatMpJump from './wechatMpJump';
|
||||
import systemTriggers from './system';
|
||||
import passportTriggers from './passport';
|
||||
|
||||
// import accountTriggers from './account';
|
||||
|
||||
|
|
@ -38,4 +39,5 @@ export default [
|
|||
...wechatPublicTag,
|
||||
...wechatMpJump,
|
||||
...systemTriggers,
|
||||
...passportTriggers,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
||||
import { Trigger, } from 'oak-domain/lib/types/Trigger';
|
||||
import { EntityDict } from '../oak-app-domain/EntityDict';
|
||||
import { BRC } from '../types/RuntimeCxt';
|
||||
|
||||
const triggers: Trigger<EntityDict, 'passport', BRC<EntityDict>>[] = [
|
||||
{
|
||||
name: '禁用passport时,将关联的passport删除',
|
||||
entity: 'passport',
|
||||
action: 'update',
|
||||
check: (operation) => {
|
||||
const { data } = operation;
|
||||
return data.hasOwnProperty('enabled') && data.enabled === false;
|
||||
},
|
||||
when: 'after',
|
||||
fn: async ({ operation }, context, option) => {
|
||||
const { data, filter } = operation;
|
||||
const applicationPassports = await context.select('applicationPassport',
|
||||
{
|
||||
data: {
|
||||
id: 1,
|
||||
},
|
||||
filter: {
|
||||
passport: filter,
|
||||
}
|
||||
},
|
||||
{ forUpdate: true }
|
||||
);
|
||||
if (applicationPassports && applicationPassports.length > 0) {
|
||||
const ids = applicationPassports.map((ele) => ele.id!);
|
||||
await context.operate('applicationPassport', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'remove',
|
||||
data: {},
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
export default triggers;
|
||||
Loading…
Reference in New Issue