Vue3 重构:邮件日志的列表

pull/34/MERGE
YunaiV 2023-03-18 12:24:21 +08:00
parent e8d83d4718
commit 3c75d6065d
3 changed files with 169 additions and 201 deletions

View File

@ -1,98 +1,59 @@
<template> <template>
<ContentWrap> <!-- 搜索工作栏 -->
<content-wrap>
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
</content-wrap>
<!-- 列表 --> <!-- 列表 -->
<XTable @register="registerTable"> <content-wrap>
<template #accountId_search> <Table
<el-select v-model="queryParams.accountId"> :columns="allSchemas.tableColumns"
<el-option :key="undefined" label="全部" :value="undefined" /> :data="tableObject.tableList"
<el-option :loading="tableObject.loading"
v-for="item in accountOptions" :pagination="{
:key="item.id" total: tableObject.total
:label="item.mail" }"
:value="item.id" v-model:pageSize="tableObject.pageSize"
/> v-model:currentPage="tableObject.currentPage"
</el-select> >
</template> <template #action="{ row }">
<template #toMail_default="{ row }"> <el-button
<div>{{ row.toMail }}</div> link
<div v-if="row.userType && row.userId"> type="primary"
<DictTag :type="DICT_TYPE.USER_TYPE" :value="row.userType" />{{ '(' + row.userId + ')' }} @click="openModal('update', row.id)"
</div>
</template>
<template #actionbtns_default="{ row }">
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['system:mail-log:query']" v-hasPermi="['system:mail-log:query']"
@click="handleDetail(row.id)" >
/> 详情
</el-button>
</template> </template>
</XTable> </Table>
</ContentWrap> </content-wrap>
<!-- 弹窗 -->
<XModal id="mailLogModel" :loading="modelLoading" v-model="modelVisible" :title="modelTitle"> <!-- 表单弹窗添加/修改 -->
<!-- 表单详情 --> <!-- <mail-account-form ref="modalRef" @success="getList" />-->
<Descriptions
v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema"
:data="detailData"
/>
<template #footer>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="modelVisible = false" />
</template>
</XModal>
</template> </template>
<script setup lang="ts" name="MailLog"> <script setup lang="ts" name="MailLog">
// import
import { DICT_TYPE } from '@/utils/dict'
import { allSchemas } from './log.data' import { allSchemas } from './log.data'
import * as MailLogApi from '@/api/system/mail/log' import * as MailLogApi from '@/api/system/mail/log'
import * as MailAccountApi from '@/api/system/mail/account' // import MailAccountForm from './form.vue'
const { t } = useI18n() // // tableObject
// tableMethods
// // https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/table.html#usetable
const queryParams = reactive({ const { tableObject, tableMethods } = useTable({
accountId: null getListApi: MailLogApi.getMailLogPageApi //
}) })
const [registerTable] = useXTable({ //
allSchemas: allSchemas, const { getList, setSearchParams } = tableMethods
topActionSlots: false,
params: queryParams,
getListApi: MailLogApi.getMailLogPageApi
})
const accountOptions = ref<any[]>([]) //
// /** 添加/修改操作 */
const modelVisible = ref(false) // const modalRef = ref()
const modelTitle = ref('edit') // const openModal = (type: string, id?: number) => {
const modelLoading = ref(false) // loading modalRef.value.openModal(type, id)
const actionType = ref('') //
const actionLoading = ref(false) // Loading
const detailData = ref() // Ref
//
const setDialogTile = (type: string) => {
modelLoading.value = true
modelTitle.value = t('action.' + type)
actionType.value = type
modelVisible.value = true
} }
// /** 初始化 **/
const handleDetail = async (rowId: number) => {
setDialogTile('detail')
const res = await MailLogApi.getMailLogApi(rowId)
detailData.value = res
modelLoading.value = false
}
// ========== ==========
onMounted(() => { onMounted(() => {
MailAccountApi.getSimpleMailAccountList().then((data) => { getList()
accountOptions.value = data
})
}) })
</script> </script>

View File

@ -1,46 +1,42 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas' import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
import * as MailAccountApi from '@/api/system/mail/account'
// CrudSchema // 邮箱账号的列表
const crudSchemas = reactive<VxeCrudSchema>({ const accounts = await MailAccountApi.getSimpleMailAccountList()
primaryKey: 'id',
primaryTitle: '编号', // CrudSchemahttps://kailong110120130.gitee.io/vue-element-plus-admin-doc/hooks/useCrudSchemas.html
primaryType: 'id', const crudSchemas = reactive<CrudSchema[]>([
action: true,
actionWidth: '70',
columns: [
{ {
title: '发送时间', label: '编号',
field: 'sendTime', field: 'id'
table: {
width: 180
}, },
formatter: 'formatDate', {
label: '发送时间',
field: 'sendTime',
formatter: dateFormatter,
search: { search: {
show: true, show: true,
itemRender: { component: 'DatePicker',
name: 'XDataTimePicker' componentProps: {
valueFormat: 'YYYY-MM-DD HH:mm:ss',
type: 'daterange',
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
} }
} }
}, },
{ {
title: '接收邮箱', label: '接收邮箱',
field: 'toMail', field: 'toMail'
isSearch: true,
table: {
width: 180,
slots: {
default: 'toMail_default'
}
}
}, },
{ {
title: '用户编号', label: '用户编号',
field: 'userId', field: 'userId',
isSearch: true, isSearch: true,
isTable: false isTable: false
}, },
{ {
title: '用户类型', label: '用户类型',
field: 'userType', field: 'userType',
dictType: DICT_TYPE.USER_TYPE, dictType: DICT_TYPE.USER_TYPE,
dictClass: 'number', dictClass: 'number',
@ -48,74 +44,84 @@ const crudSchemas = reactive<VxeCrudSchema>({
isTable: false isTable: false
}, },
{ {
title: '邮件标题', label: '邮件标题',
field: 'templateTitle' field: 'templateTitle'
}, },
{ {
title: '邮件内容', label: '邮件内容',
field: 'templateContent', field: 'templateContent',
isTable: false isTable: false
}, },
{ {
title: '邮箱参数', label: '邮箱参数',
field: 'templateParams', field: 'templateParams',
isTable: false isTable: false
}, },
{ {
title: '发送状态', label: '发送状态',
field: 'sendStatus', field: 'sendStatus',
dictType: DICT_TYPE.SYSTEM_MAIL_SEND_STATUS, dictType: DICT_TYPE.SYSTEM_MAIL_SEND_STATUS,
dictClass: 'string', dictClass: 'string',
isSearch: true isSearch: true
}, },
{ {
title: '邮箱账号', label: '邮箱账号',
field: 'accountId', field: 'accountId',
isSearch: true,
isTable: false, isTable: false,
search: { search: {
slots: { show: true,
default: 'accountId_search' component: 'Select',
api: () => accounts,
componentProps: {
optionsAlias: {
labelField: 'mail',
valueField: 'id'
}
} }
} }
}, },
{ {
title: '发送邮箱地址', label: '发送邮箱地址',
field: 'fromMail', field: 'fromMail',
table: { table: {
title: '邮箱账号' label: '邮箱账号'
} }
}, },
{ {
title: '模板编号', label: '模板编号',
field: 'templateId', field: 'templateId',
isSearch: true isSearch: true
}, },
{ {
title: '模板编码', label: '模板编码',
field: 'templateCode', field: 'templateCode',
isTable: false isTable: false
}, },
{ {
title: '模版发送人名称', label: '模版发送人名称',
field: 'templateNickname', field: 'templateNickname',
isTable: false isTable: false
}, },
{ {
title: '发送返回的消息编号', label: '发送返回的消息编号',
field: 'sendMessageId', field: 'sendMessageId',
isTable: false isTable: false
}, },
{ {
title: '发送异常', label: '发送异常',
field: 'sendException', field: 'sendException',
isTable: false isTable: false
}, },
{ {
title: '创建时间', label: '创建时间',
field: 'createTime', field: 'createTime',
isTable: false isTable: false,
formatter: dateFormatter
},
{
label: '操作',
field: 'action',
isForm: false
} }
] ])
}) export const { allSchemas } = useCrudSchemas(crudSchemas)
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)

View File

@ -3,6 +3,7 @@ import { dateFormatter } from '@/utils/formatTime'
import { TableColumn } from '@/types/table' import { TableColumn } from '@/types/table'
import * as MailAccountApi from '@/api/system/mail/account' import * as MailAccountApi from '@/api/system/mail/account'
// 邮箱账号的列表
const accounts = await MailAccountApi.getSimpleMailAccountList() const accounts = await MailAccountApi.getSimpleMailAccountList()
// 表单校验 // 表单校验