From cf3b2a9186bac62270fa0d9f28579d60a892c4ef Mon Sep 17 00:00:00 2001 From: lxy Date: Thu, 8 Aug 2024 18:13:41 +0800 Subject: [PATCH] =?UTF-8?q?applicaionPassport=E6=A0=B7=E5=BC=8F=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/applicationPassport/index.js | 49 ++++++++++---- es/components/applicationPassport/web.pc.d.ts | 16 +++-- es/components/applicationPassport/web.pc.js | 30 ++++----- src/components/applicationPassport/index.ts | 67 +++++++++++++------ src/components/applicationPassport/web.pc.tsx | 58 ++++++++-------- 5 files changed, 139 insertions(+), 81 deletions(-) diff --git a/es/components/applicationPassport/index.js b/es/components/applicationPassport/index.js index 026b80140..b74442ea2 100644 --- a/es/components/applicationPassport/index.js +++ b/es/components/applicationPassport/index.js @@ -1,4 +1,4 @@ -import { isEqual } from "oak-domain/lib/utils/lodash"; +import { groupBy, isEqual } from "oak-domain/lib/utils/lodash"; import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; export default OakComponent({ entity: 'applicationPassport', @@ -54,17 +54,18 @@ export default OakComponent({ let item = { aId: a.id, aName: a.name, - passports: [] + passports: [], + defaultOptions: [], + defaultValue: '', }; let pArray = []; for (const p of next.passports) { const { disabled, disabledTip } = this.checkDisabled(a, p); pArray.push({ - apId: await generateNewIdAsync(), pId: p.id, - disabled, + apId: await generateNewIdAsync(), checked: false, - isDefault: false, + disabled, disabledTip, }); } @@ -72,14 +73,22 @@ export default OakComponent({ apArray.push(item); } if (next.aps && next.aps.length > 0) { + const applicationPassports = groupBy(next.aps, 'applicationId'); + const aIds = Object.keys(applicationPassports); for (const ap of next.aps) { - const idx = apArray.findIndex((ele) => ele.aId === ap.applicationId); - if (idx !== -1) { - const pIdx = apArray[idx].passports.findIndex((ele) => ele.pId === ap.passportId); + const aIdx = apArray.findIndex((ele) => ele.aId === ap.applicationId); + if (aIdx !== -1) { + const pIdx = apArray[aIdx].passports.findIndex((ele) => ele.pId === ap.passportId); if (pIdx !== -1) { - apArray[idx].passports[pIdx].apId = ap.id; - apArray[idx].passports[pIdx].checked = true; - apArray[idx].passports[pIdx].isDefault = ap.isDefault; + apArray[aIdx].passports[pIdx].apId = ap.id; + apArray[aIdx].passports[pIdx].checked = true; + apArray[aIdx].defaultOptions.push({ + label: this.t(`passport:v.type.${ap.passport.type}`), + value: ap.id, + }); + if (ap.isDefault) { + apArray[aIdx].defaultValue = ap.id; + } } } } @@ -122,7 +131,13 @@ export default OakComponent({ filter: { systemId, enabled: true, - } + }, + sorter: [{ + $attr: { + $$updateAt$$: 1, + }, + $direction: 'desc' + }] }); const applications = applicationDatas; const passports = passportDatas; @@ -156,6 +171,12 @@ export default OakComponent({ disabledTip: '短信登录未配置验证码模板名称', }; } + if (!pConfig.defaultOrigin) { + return { + disabled: true, + disabledTip: '短信登录未配置默认渠道', + }; + } } break; case 'email': @@ -194,6 +215,8 @@ export default OakComponent({ }; } break; + default: + break; } switch (aType) { case 'web': @@ -238,6 +261,8 @@ export default OakComponent({ }; } break; + default: + break; } return { disabled: false, diff --git a/es/components/applicationPassport/web.pc.d.ts b/es/components/applicationPassport/web.pc.d.ts index b53d4f5c6..949f246c6 100644 --- a/es/components/applicationPassport/web.pc.d.ts +++ b/es/components/applicationPassport/web.pc.d.ts @@ -1,24 +1,28 @@ import React from 'react'; import { WebComponentProps } from 'oak-frontend-base'; import { EntityDict } from '../../oak-app-domain'; -type ShowItem = { +type RowItem = { aId: string; aName: string; passports: { - apId: string; pId: string; - disabled: boolean; + apId: string; checked: boolean; - isDefault: boolean; - disabledTip?: string; + disabled: boolean; + disabledTip: string; }[]; + defaultOptions: { + label: string; + value: string; + }[]; + defaultValue: string; }; export default function render(props: WebComponentProps void; checkLastOne: (aId: string, apId: string) => boolean; diff --git a/es/components/applicationPassport/web.pc.js b/es/components/applicationPassport/web.pc.js index 9cee619aa..29ba88143 100644 --- a/es/components/applicationPassport/web.pc.js +++ b/es/components/applicationPassport/web.pc.js @@ -1,7 +1,7 @@ import React from 'react'; -import { Button, Space, Switch, Table, Tooltip, Modal } from 'antd'; +import { Button, Space, Switch, Table, Tooltip, Modal, Select } from 'antd'; import Styles from './web.pc.module.less'; -import { CheckOutlined, CloseOutlined, CheckCircleOutlined, CloseCircleOutlined, ExclamationCircleFilled } from '@ant-design/icons'; +import { CheckOutlined, CloseOutlined, ExclamationCircleFilled } from '@ant-design/icons'; const { confirm } = Modal; export default function render(props) { const { data, methods } = props; @@ -18,6 +18,7 @@ export default function render(props) { title: '', key: 'applicationName', dataIndex: 'aName', + fixed: 'left', }, ]; const showConfirm = (apId, pId, aId) => { @@ -37,7 +38,7 @@ export default function render(props) { columns.push({ title: t(`passport:v.type.${passports[idx].type}`) + t('login'), dataIndex: 'passports[' + idx + ']', - key: `${passports[idx].type} `, + key: `${passports[idx].id} `, align: 'center', render: (_, { passports, aId }) => @@ -50,20 +51,19 @@ export default function render(props) { } }}/> - {passports[idx].checked && - { - if (!passports[idx].isDefault) { - updateItem({ - isDefault: true, - }, passports[idx].apId); - } - }}> -
默认
- {passports[idx].isDefault ? () : ()} -
}
}); } + columns.push({ + title: '默认登录方式', + key: 'default', + dataIndex: 'defaultValue', + fixed: 'right', + width: 140, + render: (_, { defaultOptions, defaultValue, aId }) => <> + { updateItem({ isDefault: true, }, value) }} + options={defaultOptions} + /> + + }); } + return ( <>
@@ -150,6 +149,7 @@ export default function render(props: WebComponentProps< columns={columns} dataSource={apArray} pagination={false} + scroll={{ x: 1200 }} /> );