【新增】前端代码第一次提交
This commit is contained in:
28
src/views/system/mail/account/MailAccountDetail.vue
Normal file
28
src/views/system/mail/account/MailAccountDetail.vue
Normal file
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" title="详情">
|
||||
<Descriptions :data="detailData" :schema="allSchemas.detailSchema" />
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as MailAccountApi from '@/api/system/mail/account'
|
||||
import { allSchemas } from './account.data'
|
||||
|
||||
defineOptions({ name: 'SystemMailAccountDetail' })
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const detailLoading = ref(false) // 表单的加载中
|
||||
const detailData = ref() // 详情数据
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (id: number) => {
|
||||
dialogVisible.value = true
|
||||
// 设置数据
|
||||
detailLoading.value = true
|
||||
try {
|
||||
detailData.value = await MailAccountApi.getMailAccount(id)
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
</script>
|
||||
68
src/views/system/mail/account/MailAccountForm.vue
Normal file
68
src/views/system/mail/account/MailAccountForm.vue
Normal file
@@ -0,0 +1,68 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" :title="dialogTitle">
|
||||
<Form ref="formRef" v-loading="formLoading" :rules="rules" :schema="allSchemas.formSchema" />
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as MailAccountApi from '@/api/system/mail/account'
|
||||
import { allSchemas, rules } from './account.data'
|
||||
|
||||
defineOptions({ name: 'SystemMailAccountForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = await MailAccountApi.getMailAccount(id)
|
||||
formRef.value.setValues(data)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.getElFormRef().validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formRef.value.formModel as MailAccountApi.MailAccountVO
|
||||
if (formType.value === 'create') {
|
||||
await MailAccountApi.createMailAccount(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await MailAccountApi.updateMailAccount(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
100
src/views/system/mail/account/account.data.ts
Normal file
100
src/views/system/mail/account/account.data.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
// 表单校验
|
||||
export const rules = reactive({
|
||||
mail: [
|
||||
{ required: true, message: t('profile.rules.mail'), trigger: 'blur' },
|
||||
{
|
||||
type: 'email',
|
||||
message: t('profile.rules.truemail'),
|
||||
trigger: ['blur', 'change']
|
||||
}
|
||||
],
|
||||
username: [required],
|
||||
password: [required],
|
||||
host: [required],
|
||||
port: [required],
|
||||
sslEnable: [required],
|
||||
starttlsEnable: [required]
|
||||
})
|
||||
|
||||
// CrudSchema:https://doc.iocoder.cn/vue3/crud-schema/
|
||||
const crudSchemas = reactive<CrudSchema[]>([
|
||||
{
|
||||
label: '邮箱',
|
||||
field: 'mail',
|
||||
isSearch: true,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '用户名',
|
||||
field: 'username',
|
||||
isSearch: true,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '密码',
|
||||
field: 'password',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: 'SMTP 服务器域名',
|
||||
field: 'host'
|
||||
},
|
||||
{
|
||||
label: 'SMTP 服务器端口',
|
||||
field: 'port',
|
||||
form: {
|
||||
component: 'InputNumber',
|
||||
value: 465
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '是否开启 SSL',
|
||||
field: 'sslEnable',
|
||||
dictType: DICT_TYPE.INFRA_BOOLEAN_STRING,
|
||||
dictClass: 'boolean',
|
||||
form: {
|
||||
component: 'Radio'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '是否开启 STARTTLS',
|
||||
field: 'starttlsEnable',
|
||||
dictType: DICT_TYPE.INFRA_BOOLEAN_STRING,
|
||||
dictClass: 'boolean',
|
||||
form: {
|
||||
component: 'Radio'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
field: 'createTime',
|
||||
isForm: false,
|
||||
formatter: dateFormatter,
|
||||
detail: {
|
||||
dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
field: 'action',
|
||||
isForm: false,
|
||||
isDetail: false
|
||||
}
|
||||
])
|
||||
export const { allSchemas } = useCrudSchemas(crudSchemas)
|
||||
106
src/views/system/mail/account/index.vue
Normal file
106
src/views/system/mail/account/index.vue
Normal file
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<doc-alert title="邮件配置" url="https://doc.iocoder.cn/mail" />
|
||||
|
||||
<!-- 搜索工作栏 -->
|
||||
<ContentWrap>
|
||||
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams">
|
||||
<!-- 新增等操作按钮 -->
|
||||
<template #actionMore>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['system:mail-account:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
</template>
|
||||
</Search>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<Table
|
||||
:columns="allSchemas.tableColumns"
|
||||
:data="tableObject.tableList"
|
||||
:loading="tableObject.loading"
|
||||
:pagination="{
|
||||
total: tableObject.total
|
||||
}"
|
||||
v-model:pageSize="tableObject.pageSize"
|
||||
v-model:currentPage="tableObject.currentPage"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', row.id)"
|
||||
v-hasPermi="['system:mail-account:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openDetail(row.id)"
|
||||
v-hasPermi="['system:mail-account:query']"
|
||||
>
|
||||
详情
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
v-hasPermi="['system:mail-account:delete']"
|
||||
@click="handleDelete(row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</Table>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<MailAccountForm ref="formRef" @success="getList" />
|
||||
<!-- 详情弹窗 -->
|
||||
<MailAccountDetail ref="detailRef" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { allSchemas } from './account.data'
|
||||
import * as MailAccountApi from '@/api/system/mail/account'
|
||||
import MailAccountForm from './MailAccountForm.vue'
|
||||
import MailAccountDetail from './MailAccountDetail.vue'
|
||||
|
||||
defineOptions({ name: 'SystemMailAccount' })
|
||||
|
||||
// tableObject:表格的属性对象,可获得分页大小、条数等属性
|
||||
// tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
|
||||
// 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
|
||||
const { tableObject, tableMethods } = useTable({
|
||||
getListApi: MailAccountApi.getMailAccountPage, // 分页接口
|
||||
delListApi: MailAccountApi.deleteMailAccount // 删除接口
|
||||
})
|
||||
// 获得表格的各种操作
|
||||
const { getList, setSearchParams } = tableMethods
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 详情操作 */
|
||||
const detailRef = ref()
|
||||
const openDetail = (id: number) => {
|
||||
detailRef.value.open(id)
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = (id: number) => {
|
||||
tableMethods.delList(id, false)
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
33
src/views/system/mail/log/MailLogDetail.vue
Normal file
33
src/views/system/mail/log/MailLogDetail.vue
Normal file
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" :max-height="500" :scroll="true" title="详情">
|
||||
<Descriptions :data="detailData" :schema="allSchemas.detailSchema">
|
||||
<!-- 展示 HTML 内容 -->
|
||||
<template #templateContent="{ row }">
|
||||
<div v-dompurify-html="row.templateContent"></div>
|
||||
</template>
|
||||
</Descriptions>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as MailLogApi from '@/api/system/mail/log'
|
||||
import { allSchemas } from './log.data'
|
||||
|
||||
defineOptions({ name: 'SystemMailLogDetail' })
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const detailLoading = ref(false) // 表单的加载中
|
||||
const detailData = ref() // 详情数据
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (id: number) => {
|
||||
dialogVisible.value = true
|
||||
// 设置数据
|
||||
detailLoading.value = true
|
||||
try {
|
||||
detailData.value = await MailLogApi.getMailLog(id)
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
</script>
|
||||
63
src/views/system/mail/log/index.vue
Normal file
63
src/views/system/mail/log/index.vue
Normal file
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<doc-alert title="邮件配置" url="https://doc.iocoder.cn/mail" />
|
||||
|
||||
<!-- 搜索工作栏 -->
|
||||
<ContentWrap>
|
||||
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<Table
|
||||
:columns="allSchemas.tableColumns"
|
||||
:data="tableObject.tableList"
|
||||
:loading="tableObject.loading"
|
||||
:pagination="{
|
||||
total: tableObject.total
|
||||
}"
|
||||
v-model:pageSize="tableObject.pageSize"
|
||||
v-model:currentPage="tableObject.currentPage"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openDetail(row.id)"
|
||||
v-hasPermi="['system:mail-log:query']"
|
||||
>
|
||||
详情
|
||||
</el-button>
|
||||
</template>
|
||||
</Table>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:详情 -->
|
||||
<mail-log-detail ref="detailRef" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { allSchemas } from './log.data'
|
||||
import * as MailLogApi from '@/api/system/mail/log'
|
||||
import MailLogDetail from './MailLogDetail.vue'
|
||||
|
||||
defineOptions({ name: 'SystemMailLog' })
|
||||
|
||||
// tableObject:表格的属性对象,可获得分页大小、条数等属性
|
||||
// tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
|
||||
// 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
|
||||
const { tableObject, tableMethods } = useTable({
|
||||
getListApi: MailLogApi.getMailLogPage // 分页接口
|
||||
})
|
||||
// 获得表格的各种操作
|
||||
const { getList, setSearchParams } = tableMethods
|
||||
|
||||
/** 详情操作 */
|
||||
const detailRef = ref()
|
||||
const openDetail = (id: number) => {
|
||||
detailRef.value.open(id)
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
167
src/views/system/mail/log/log.data.ts
Normal file
167
src/views/system/mail/log/log.data.ts
Normal file
@@ -0,0 +1,167 @@
|
||||
import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import * as MailAccountApi from '@/api/system/mail/account'
|
||||
|
||||
// 邮箱账号的列表
|
||||
const accountList = await MailAccountApi.getSimpleMailAccountList()
|
||||
|
||||
// CrudSchema:https://doc.iocoder.cn/vue3/crud-schema/
|
||||
const crudSchemas = reactive<CrudSchema[]>([
|
||||
{
|
||||
label: '编号',
|
||||
field: 'id'
|
||||
},
|
||||
{
|
||||
label: '发送时间',
|
||||
field: 'sendTime',
|
||||
formatter: dateFormatter,
|
||||
search: {
|
||||
show: true,
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
type: 'daterange',
|
||||
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')],
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
},
|
||||
detail: {
|
||||
dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '接收邮箱',
|
||||
field: 'toMail'
|
||||
},
|
||||
{
|
||||
label: '用户编号',
|
||||
field: 'userId',
|
||||
isSearch: true,
|
||||
isTable: false,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '用户类型',
|
||||
field: 'userType',
|
||||
dictType: DICT_TYPE.USER_TYPE,
|
||||
dictClass: 'number',
|
||||
isSearch: true,
|
||||
isTable: false,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '邮件标题',
|
||||
field: 'templateTitle'
|
||||
},
|
||||
{
|
||||
label: '邮件内容',
|
||||
field: 'templateContent',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '邮箱参数',
|
||||
field: 'templateParams',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '发送状态',
|
||||
field: 'sendStatus',
|
||||
dictType: DICT_TYPE.SYSTEM_MAIL_SEND_STATUS,
|
||||
dictClass: 'string',
|
||||
isSearch: true,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '邮箱账号',
|
||||
field: 'accountId',
|
||||
isTable: false,
|
||||
search: {
|
||||
show: true,
|
||||
component: 'Select',
|
||||
api: () => accountList,
|
||||
componentProps: {
|
||||
optionsAlias: {
|
||||
labelField: 'mail',
|
||||
valueField: 'id'
|
||||
},
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '发送邮箱地址',
|
||||
field: 'fromMail',
|
||||
table: {
|
||||
label: '邮箱账号'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '模板编号',
|
||||
field: 'templateId',
|
||||
isSearch: true,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '模板编码',
|
||||
field: 'templateCode',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '模版发送人名称',
|
||||
field: 'templateNickname',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '发送返回的消息编号',
|
||||
field: 'sendMessageId',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '发送异常',
|
||||
field: 'sendException',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
field: 'createTime',
|
||||
isTable: false,
|
||||
formatter: dateFormatter,
|
||||
detail: {
|
||||
dateFormat: 'YYYY-MM-DD HH:mm:ss'
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
field: 'action',
|
||||
isDetail: false
|
||||
}
|
||||
])
|
||||
export const { allSchemas } = useCrudSchemas(crudSchemas)
|
||||
74
src/views/system/mail/template/MailTemplateForm.vue
Normal file
74
src/views/system/mail/template/MailTemplateForm.vue
Normal file
@@ -0,0 +1,74 @@
|
||||
<template>
|
||||
<Dialog
|
||||
v-model="dialogVisible"
|
||||
:max-height="500"
|
||||
:scroll="true"
|
||||
:title="dialogTitle"
|
||||
:width="800"
|
||||
>
|
||||
<Form ref="formRef" v-loading="formLoading" :rules="rules" :schema="allSchemas.formSchema" />
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as MailTemplateApi from '@/api/system/mail/template'
|
||||
import { allSchemas, rules } from './template.data'
|
||||
|
||||
defineOptions({ name: 'SystemMailTemplateForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = await MailTemplateApi.getMailTemplate(id)
|
||||
formRef.value.setValues(data)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.getElFormRef().validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formRef.value.formModel as MailTemplateApi.MailTemplateVO
|
||||
if (formType.value === 'create') {
|
||||
await MailTemplateApi.createMailTemplate(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await MailTemplateApi.updateMailTemplate(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
115
src/views/system/mail/template/MailTemplateSendForm.vue
Normal file
115
src/views/system/mail/template/MailTemplateSendForm.vue
Normal file
@@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" title="测试">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
v-loading="formLoading"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="120px"
|
||||
>
|
||||
<el-form-item label="模板内容" prop="content">
|
||||
<Editor :model-value="formData.content" height="150px" readonly />
|
||||
</el-form-item>
|
||||
<el-form-item label="收件邮箱" prop="mail">
|
||||
<el-input v-model="formData.mail" placeholder="请输入收件邮箱" />
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-for="param in formData.params"
|
||||
:key="param"
|
||||
:label="'参数 {' + param + '}'"
|
||||
:prop="'templateParams.' + param"
|
||||
>
|
||||
<el-input
|
||||
v-model="formData.templateParams[param]"
|
||||
:placeholder="'请输入 ' + param + ' 参数'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as MailTemplateApi from '@/api/system/mail/template'
|
||||
|
||||
defineOptions({ name: 'SystemMailTemplateSendForm' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formData = ref({
|
||||
content: '',
|
||||
params: {},
|
||||
mail: '',
|
||||
templateCode: '',
|
||||
templateParams: new Map()
|
||||
})
|
||||
const formRules = reactive({
|
||||
mail: [{ required: true, message: '邮箱不能为空', trigger: 'blur' }],
|
||||
templateCode: [{ required: true, message: '模版编号不能为空', trigger: 'blur' }],
|
||||
templateParams: {}
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (id: number) => {
|
||||
dialogVisible.value = true
|
||||
resetForm()
|
||||
// 设置数据
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = await MailTemplateApi.getMailTemplate(id)
|
||||
// 设置动态表单
|
||||
formData.value.content = data.content
|
||||
formData.value.params = data.params
|
||||
formData.value.templateCode = data.code
|
||||
formData.value.templateParams = data.params.reduce((obj, item) => {
|
||||
obj[item] = '' // 给每个动态属性赋值,避免无法读取
|
||||
return obj
|
||||
}, {})
|
||||
formRules.templateParams = data.params.reduce((obj, item) => {
|
||||
obj[item] = { required: true, message: '参数 ' + item + ' 不能为空', trigger: 'blur' }
|
||||
return obj
|
||||
}, {})
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as MailTemplateApi.MailSendReqVO
|
||||
const logId = await MailTemplateApi.sendMail(data)
|
||||
if (logId) {
|
||||
message.success('提交发送成功!发送结果,见发送日志编号:' + logId)
|
||||
}
|
||||
dialogVisible.value = false
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
content: '',
|
||||
params: {},
|
||||
mail: '',
|
||||
templateCode: '',
|
||||
templateParams: new Map()
|
||||
}
|
||||
formRules.templateParams = {}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
||||
107
src/views/system/mail/template/index.vue
Normal file
107
src/views/system/mail/template/index.vue
Normal file
@@ -0,0 +1,107 @@
|
||||
<template>
|
||||
<doc-alert title="邮件配置" url="https://doc.iocoder.cn/mail" />
|
||||
|
||||
<!-- 搜索工作栏 -->
|
||||
<ContentWrap>
|
||||
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams">
|
||||
<!-- 新增等操作按钮 -->
|
||||
<template #actionMore>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['system:mail-template:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
</template>
|
||||
</Search>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<Table
|
||||
:columns="allSchemas.tableColumns"
|
||||
:data="tableObject.tableList"
|
||||
:loading="tableObject.loading"
|
||||
:pagination="{
|
||||
total: tableObject.total
|
||||
}"
|
||||
v-model:pageSize="tableObject.pageSize"
|
||||
v-model:currentPage="tableObject.currentPage"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openSendForm(row.id)"
|
||||
v-hasPermi="['system:mail-template:send-mail']"
|
||||
>
|
||||
测试
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', row.id)"
|
||||
v-hasPermi="['system:mail-template:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
v-hasPermi="['system:mail-template:delete']"
|
||||
@click="handleDelete(row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</Table>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<MailTemplateForm ref="formRef" @success="getList" />
|
||||
|
||||
<!-- 表单弹窗:发送测试 -->
|
||||
<MailTemplateSendForm ref="sendFormRef" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { allSchemas } from './template.data'
|
||||
import * as MailTemplateApi from '@/api/system/mail/template'
|
||||
import MailTemplateForm from './MailTemplateForm.vue'
|
||||
import MailTemplateSendForm from './MailTemplateSendForm.vue'
|
||||
|
||||
defineOptions({ name: 'SystemMailTemplate' })
|
||||
|
||||
// tableObject:表格的属性对象,可获得分页大小、条数等属性
|
||||
// tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
|
||||
// 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
|
||||
const { tableObject, tableMethods } = useTable({
|
||||
getListApi: MailTemplateApi.getMailTemplatePage, // 分页接口
|
||||
delListApi: MailTemplateApi.deleteMailTemplate // 删除接口
|
||||
})
|
||||
// 获得表格的各种操作
|
||||
const { getList, setSearchParams } = tableMethods
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = (id: number) => {
|
||||
tableMethods.delList(id, false)
|
||||
}
|
||||
|
||||
/** 发送测试操作 */
|
||||
const sendFormRef = ref()
|
||||
const openSendForm = (id: number) => {
|
||||
sendFormRef.value.open(id)
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
140
src/views/system/mail/template/template.data.ts
Normal file
140
src/views/system/mail/template/template.data.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import { TableColumn } from '@/types/table'
|
||||
import * as MailAccountApi from '@/api/system/mail/account'
|
||||
|
||||
// 邮箱账号的列表
|
||||
const accountList = await MailAccountApi.getSimpleMailAccountList()
|
||||
|
||||
// 表单校验
|
||||
export const rules = reactive({
|
||||
name: [required],
|
||||
code: [required],
|
||||
accountId: [required],
|
||||
label: [required],
|
||||
content: [required],
|
||||
params: [required],
|
||||
status: [required]
|
||||
})
|
||||
|
||||
// CrudSchema:https://doc.iocoder.cn/vue3/crud-schema/
|
||||
const crudSchemas = reactive<CrudSchema[]>([
|
||||
{
|
||||
label: '模板编码',
|
||||
field: 'code',
|
||||
isSearch: true,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '模板名称',
|
||||
field: 'name',
|
||||
isSearch: true,
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '模板标题',
|
||||
field: 'title'
|
||||
},
|
||||
{
|
||||
label: '模板内容',
|
||||
field: 'content',
|
||||
form: {
|
||||
component: 'Editor',
|
||||
componentProps: {
|
||||
valueHtml: '',
|
||||
height: 200
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '邮箱账号',
|
||||
field: 'accountId',
|
||||
width: '200px',
|
||||
formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
|
||||
return accountList.find((account) => account.id === cellValue)?.mail
|
||||
},
|
||||
search: {
|
||||
show: true,
|
||||
component: 'Select',
|
||||
api: () => accountList,
|
||||
componentProps: {
|
||||
optionsAlias: {
|
||||
labelField: 'mail',
|
||||
valueField: 'id'
|
||||
},
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
},
|
||||
form: {
|
||||
component: 'Select',
|
||||
api: () => accountList,
|
||||
componentProps: {
|
||||
optionsAlias: {
|
||||
labelField: 'mail',
|
||||
valueField: 'id'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '发送人名称',
|
||||
field: 'nickname'
|
||||
},
|
||||
{
|
||||
label: '开启状态',
|
||||
field: 'status',
|
||||
isSearch: true,
|
||||
dictType: DICT_TYPE.COMMON_STATUS,
|
||||
dictClass: 'number',
|
||||
search: {
|
||||
componentProps: {
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
field: 'remark',
|
||||
isTable: false
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
field: 'createTime',
|
||||
isForm: false,
|
||||
formatter: dateFormatter,
|
||||
search: {
|
||||
show: true,
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
type: 'daterange',
|
||||
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')],
|
||||
style: {
|
||||
width: '240px'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
field: 'action',
|
||||
isForm: false
|
||||
}
|
||||
])
|
||||
export const { allSchemas } = useCrudSchemas(crudSchemas)
|
||||
Reference in New Issue
Block a user