feat: 邮箱账号
This commit is contained in:
178
src/pages/system/messages/mail/account/config.tsx
Normal file
178
src/pages/system/messages/mail/account/config.tsx
Normal file
@@ -0,0 +1,178 @@
|
||||
import type {
|
||||
ProColumns,
|
||||
ProDescriptionsItemProps,
|
||||
ProFormColumnsType,
|
||||
} from '@ant-design/pro-components';
|
||||
import dayjs from 'dayjs';
|
||||
import type { MailAccountVO } from '@/services/system/message/mail/account';
|
||||
export const baseTenantColumns: ProColumns<MailAccountVO>[] = [
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: 'mail',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '用户名',
|
||||
dataIndex: 'username',
|
||||
},
|
||||
{
|
||||
title: 'SMTP 服务器域名',
|
||||
dataIndex: 'host',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: 'SMTP 服务器端口',
|
||||
dataIndex: 'port',
|
||||
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '是否开启 SSL',
|
||||
dataIndex: 'sslEnable',
|
||||
valueType: 'radio',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
},
|
||||
{
|
||||
title: '是否开启 STARTTLS',
|
||||
dataIndex: 'starttlsEnable',
|
||||
valueType: 'radio',
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateRange',
|
||||
hideInSearch: true, // 在搜索表单中隐藏
|
||||
render: (_, record: MailAccountVO) =>
|
||||
dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
|
||||
},
|
||||
];
|
||||
|
||||
export const formColumns = (): ProFormColumnsType[] => [
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: 'mail',
|
||||
},
|
||||
{
|
||||
title: '用户名',
|
||||
dataIndex: 'username',
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入用户名',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '密码',
|
||||
dataIndex: 'password',
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入密码',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'SMTP 服务器域名',
|
||||
dataIndex: 'host',
|
||||
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入SMTP 服务器域名',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'SMTP 服务器端口',
|
||||
dataIndex: 'port',
|
||||
valueType: 'digit',
|
||||
fieldProps: {
|
||||
defaultValue: 465,
|
||||
},
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: 'SMTP 服务器端口',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '是否开启 SSL',
|
||||
dataIndex: 'sslEnable',
|
||||
valueType: 'select',
|
||||
fieldProps: {
|
||||
placeholder: '请选择是否开启 SSL',
|
||||
options: [
|
||||
{
|
||||
label: '正常',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: '禁用',
|
||||
value: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择是否开启 SSL',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '是否开启 STARTTLS',
|
||||
dataIndex: 'starttlsEnable',
|
||||
valueType: 'select',
|
||||
fieldProps: {
|
||||
placeholder: '请选择是否开启 STARTTLS',
|
||||
options: [
|
||||
{
|
||||
label: '正常',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: '禁用',
|
||||
value: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
formItemProps: {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择是否开启 STARTTLS',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export const formTestColumns = (type: string): ProFormColumnsType[] => [
|
||||
{
|
||||
title: '模板内容',
|
||||
dataIndex: 'content',
|
||||
valueType: 'textarea',
|
||||
},
|
||||
{
|
||||
title: '手机号',
|
||||
dataIndex: 'mobile',
|
||||
},
|
||||
];
|
||||
// {
|
||||
// title: "模板内容",
|
||||
// dataIndex: "content",
|
||||
// valueType: "textarea",
|
||||
// },
|
||||
152
src/pages/system/messages/mail/account/index.tsx
Normal file
152
src/pages/system/messages/mail/account/index.tsx
Normal file
@@ -0,0 +1,152 @@
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import type {
|
||||
ActionType,
|
||||
ProColumns,
|
||||
ProCoreActionType,
|
||||
} from '@ant-design/pro-components';
|
||||
import { message, Popconfirm } from 'antd';
|
||||
import React, { useCallback, useRef, useState } from 'react';
|
||||
import ConfigurableDrawerForm, {
|
||||
type ConfigurableDrawerFormRef,
|
||||
} from '@/components/DrawerForm';
|
||||
import EnhancedProTable from '@/components/EnhancedProTable';
|
||||
import type { ToolbarAction } from '@/components/EnhancedProTable/types';
|
||||
import { formStatusType } from '@/constants';
|
||||
import {
|
||||
createMailAccount,
|
||||
deleteMailAccount,
|
||||
getMailAccount,
|
||||
getMailAccountPage,
|
||||
type MailAccountVO,
|
||||
updateMailAccount,
|
||||
} from '@/services/system/message/mail/account';
|
||||
import { baseTenantColumns, formColumns, formTestColumns } from './config';
|
||||
|
||||
const SyStemMessageSmsTemplate = () => {
|
||||
const tableRef = useRef<ActionType>(null);
|
||||
const configurableDrawerRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||
const [type, setType] = useState<'create' | 'update' | 'test'>('create');
|
||||
const testRef = useRef<ConfigurableDrawerFormRef>(null);
|
||||
const [currentItem, setCurrentItem] = useState<MailAccountVO>();
|
||||
const onFetch = async (
|
||||
params: MailAccountVO & {
|
||||
pageSize?: number;
|
||||
current?: number;
|
||||
},
|
||||
) => {
|
||||
const data = await getMailAccountPage({
|
||||
...params,
|
||||
pageNo: params.current,
|
||||
pageSize: params.pageSize,
|
||||
});
|
||||
return {
|
||||
data: data.list,
|
||||
success: true,
|
||||
total: data.total,
|
||||
};
|
||||
};
|
||||
|
||||
const handleSend = async (record: MailAccountVO) => {
|
||||
setType('test');
|
||||
setCurrentItem(record);
|
||||
testRef.current?.open(record);
|
||||
};
|
||||
|
||||
const handleEdit = (record: MailAccountVO) => {
|
||||
setType('update');
|
||||
setCurrentItem(record);
|
||||
|
||||
configurableDrawerRef.current?.open(record);
|
||||
};
|
||||
|
||||
const handleAdd = () => {
|
||||
setType('create');
|
||||
configurableDrawerRef.current?.open();
|
||||
};
|
||||
const handleSubmit = useCallback(
|
||||
async (values: MailAccountVO) => {
|
||||
if (type === 'create') {
|
||||
await createMailAccount(values);
|
||||
message.success('创建成功');
|
||||
} else {
|
||||
await updateMailAccount({
|
||||
...values,
|
||||
id: currentItem!.id,
|
||||
});
|
||||
message.success('编辑成功');
|
||||
}
|
||||
tableRef.current?.reload();
|
||||
return true;
|
||||
},
|
||||
[type, currentItem],
|
||||
);
|
||||
|
||||
const toolbarActions: ToolbarAction[] = [
|
||||
{
|
||||
key: 'add',
|
||||
label: '新建',
|
||||
type: 'primary',
|
||||
icon: <PlusOutlined />,
|
||||
onClick: handleAdd,
|
||||
},
|
||||
];
|
||||
const actionColumns: ProColumns<MailAccountVO> = {
|
||||
title: '操作',
|
||||
dataIndex: 'option',
|
||||
valueType: 'option',
|
||||
fixed: 'right',
|
||||
width: 120,
|
||||
render: (
|
||||
text: React.ReactNode,
|
||||
record: MailAccountVO,
|
||||
_: number,
|
||||
action: ProCoreActionType | undefined,
|
||||
) => [
|
||||
<a key="edit" onClick={() => handleEdit(record)}>
|
||||
编辑
|
||||
</a>,
|
||||
<a key="detail" onClick={() => handleSend(record)}>
|
||||
详情
|
||||
</a>,
|
||||
<Popconfirm
|
||||
title="是否删除?"
|
||||
key="delete"
|
||||
onConfirm={async () => {
|
||||
await deleteMailAccount(record.id);
|
||||
message.success('删除成功');
|
||||
action?.reload?.();
|
||||
}}
|
||||
okText="是"
|
||||
cancelText="否"
|
||||
>
|
||||
<a style={{ color: 'var(--ant-red)' }} key="delete">
|
||||
删除
|
||||
</a>
|
||||
</Popconfirm>,
|
||||
],
|
||||
};
|
||||
const columns = [...baseTenantColumns, actionColumns];
|
||||
return (
|
||||
<>
|
||||
<EnhancedProTable<MailAccountVO>
|
||||
ref={tableRef}
|
||||
columns={columns}
|
||||
request={onFetch}
|
||||
headerTitle="登录日志"
|
||||
showIndex={false}
|
||||
toolbarActions={toolbarActions}
|
||||
showSelection={false}
|
||||
/>
|
||||
<ConfigurableDrawerForm
|
||||
labelCol={{ span: 7 }}
|
||||
wrapperCol={{ span: 17 }}
|
||||
ref={configurableDrawerRef}
|
||||
title={formStatusType[type]}
|
||||
columns={formColumns()}
|
||||
onSubmit={handleSubmit}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default SyStemMessageSmsTemplate;
|
||||
Reference in New Issue
Block a user