From c75be91c8ff00f41ba2afb3b83df9e00feeb2662 Mon Sep 17 00:00:00 2001 From: lxy Date: Thu, 8 Aug 2024 18:12:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=85=8D=E7=BD=AEpassport?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/checkers/applicationPassport.js | 4 +- es/components/passport/index.js | 139 +++++++++++++++++++++++++--- es/components/passport/web.pc.d.ts | 6 ++ es/components/passport/web.pc.js | 40 +++++++- es/triggers/passport.d.ts | 5 + es/triggers/passport.js | 39 ++++++++ lib/checkers/applicationPassport.js | 4 +- lib/triggers/passport.d.ts | 5 + lib/triggers/passport.js | 41 ++++++++ src/aspects/AspectDict.ts | 8 +- src/aspects/applicationPassport.ts | 39 ++++++++ src/aspects/index.ts | 3 +- src/checkers/applicationPassport.ts | 4 +- src/components/passport/index.ts | 136 ++++++++++++++++++++++++--- src/components/passport/web.pc.tsx | 101 +++++++++++++------- src/triggers/index.ts | 2 + src/triggers/passport.ts | 47 ++++++++++ 17 files changed, 559 insertions(+), 64 deletions(-) create mode 100644 es/triggers/passport.d.ts create mode 100644 es/triggers/passport.js create mode 100644 lib/triggers/passport.d.ts create mode 100644 lib/triggers/passport.js create mode 100644 src/triggers/passport.ts diff --git a/es/checkers/applicationPassport.js b/es/checkers/applicationPassport.js index 55de2457c..c5e4afe11 100644 --- a/es/checkers/applicationPassport.js +++ b/es/checkers/applicationPassport.js @@ -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); } } diff --git a/es/components/passport/index.js b/es/components/passport/index.js index dd8580d66..88fa4109d 100644 --- a/es/components/passport/index.js +++ b/es/components/passport/index.js @@ -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(); + } }, }); diff --git a/es/components/passport/web.pc.d.ts b/es/components/passport/web.pc.d.ts index 9c4db739e..1776b3f48 100644 --- a/es/components/passport/web.pc.d.ts +++ b/es/components/passport/web.pc.d.ts @@ -10,4 +10,10 @@ export default function render(props: WebComponentProps void; + checkConfrim: () => { + id: string; + type: EntityDict['passport']['Schema']['type']; + tip: string; + }[]; + myConfirm: (ids: string[]) => void; }>): React.JSX.Element | undefined; diff --git a/es/components/passport/web.pc.js b/es/components/passport/web.pc.js index 884959827..baeb979e8 100644 --- a/es/components/passport/web.pc.js +++ b/es/components/passport/web.pc.js @@ -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: , + width: 540, + content: +
当前登录方式配置存在以下问题可能影响登录:
+ {warnings.map((ele) => { + return (
+
+ {t(`passport:v.type.${ele.type}`)}{t('login')} +
+
{ele.tip}
+
); + })} +
, + async onOk() { + const ids = warnings.map((ele) => ele.id); + await myConfirm(ids); + }, + onCancel() { + }, + }); + }; if (passports?.length > 0) { return (<> @@ -242,7 +268,15 @@ export default function render(props) { }}> 重置 - }/> diff --git a/es/triggers/passport.d.ts b/es/triggers/passport.d.ts new file mode 100644 index 000000000..29fab3054 --- /dev/null +++ b/es/triggers/passport.d.ts @@ -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>[]; +export default triggers; diff --git a/es/triggers/passport.js b/es/triggers/passport.js new file mode 100644 index 000000000..6506e6183 --- /dev/null +++ b/es/triggers/passport.js @@ -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; diff --git a/lib/checkers/applicationPassport.js b/lib/checkers/applicationPassport.js index 106bae058..354071e26 100644 --- a/lib/checkers/applicationPassport.js +++ b/lib/checkers/applicationPassport.js @@ -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); } } diff --git a/lib/triggers/passport.d.ts b/lib/triggers/passport.d.ts new file mode 100644 index 000000000..29fab3054 --- /dev/null +++ b/lib/triggers/passport.d.ts @@ -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>[]; +export default triggers; diff --git a/lib/triggers/passport.js b/lib/triggers/passport.js new file mode 100644 index 000000000..d7a548aec --- /dev/null +++ b/lib/triggers/passport.js @@ -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; diff --git a/src/aspects/AspectDict.ts b/src/aspects/AspectDict.ts index 3fc3488f6..f4ef950b1 100644 --- a/src/aspects/AspectDict.ts +++ b/src/aspects/AspectDict.ts @@ -408,7 +408,13 @@ export type AspectDict = { applicationId: string; }, context: BackendRuntimeContext - ) => Promise + ) => Promise; + removeApplicationPassportsByPIds: ( + params: { + passportIds: string[]; + }, + content: BackendRuntimeContext + ) => Promise; }; export default AspectDict; diff --git a/src/aspects/applicationPassport.ts b/src/aspects/applicationPassport.ts index 47a0f3c01..72a169e89 100644 --- a/src/aspects/applicationPassport.ts +++ b/src/aspects/applicationPassport.ts @@ -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( params: { @@ -30,4 +32,41 @@ export async function getApplicationPassports( closeRoot(); return applicationPassports; +} + +export async function removeApplicationPassportsByPIds( + params: { + passportIds: string[]; + }, + context: BRC +) { + 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, + } + }, + }, {}); + } } \ No newline at end of file diff --git a/src/aspects/index.ts b/src/aspects/index.ts index 11d201ec9..b66f788ca 100644 --- a/src/aspects/index.ts +++ b/src/aspects/index.ts @@ -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; diff --git a/src/checkers/applicationPassport.ts b/src/checkers/applicationPassport.ts index 092d9ac29..ec1ddc071 100644 --- a/src/checkers/applicationPassport.ts +++ b/src/checkers/applicationPassport.ts @@ -123,12 +123,12 @@ const checkers: Checker { - 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!); } } diff --git a/src/components/passport/index.ts b/src/components/passport/index.ts index 8397321e9..8831f6d29 100644 --- a/src/components/passport/index.ts +++ b/src/components/passport/index.ts @@ -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(); + } }, }); \ No newline at end of file diff --git a/src/components/passport/web.pc.tsx b/src/components/passport/web.pc.tsx index 80d0b72f6..725cecef0 100644 --- a/src/components/passport/web.pc.tsx +++ b/src/components/passport/web.pc.tsx @@ -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 }} > - { - 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 }} > - { - 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: , + width: 540, + content: +
当前登录方式配置存在以下问题可能影响登录:
+ {warnings.map((ele) => { + return ( +
+
+ {t(`passport:v.type.${ele.type}`)}{t('login')} +
+
{ele.tip}
+
+ ) + })} +
, + 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< diff --git a/src/triggers/index.ts b/src/triggers/index.ts index e54cbd849..f5bb1e524 100644 --- a/src/triggers/index.ts +++ b/src/triggers/index.ts @@ -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, ]; diff --git a/src/triggers/passport.ts b/src/triggers/passport.ts new file mode 100644 index 000000000..c17403d46 --- /dev/null +++ b/src/triggers/passport.ts @@ -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>[] = [ + { + 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;