add: 短信日志vue2迁移到vue3,使用ts改写

This commit is contained in:
puhui999 2023-03-22 17:52:06 +08:00
parent 496862e197
commit 9e2c3476c8
2 changed files with 411 additions and 66 deletions

View File

@ -1,39 +1,40 @@
import request from '@/config/axios' import request from '@/config/axios'
export interface SmsLogVO { export interface SmsLogVO {
id: number id: number | null
channelId: number channelId: number | null
channelCode: string channelCode: string
templateId: number templateId: number | null
templateCode: string templateCode: string
templateType: number templateType: number | null
templateContent: string templateContent: string
templateParams: Map<string, object> templateParams: Map<string, object> | null
apiTemplateId: string
mobile: string mobile: string
userId: number userId: number | null
userType: number userType: number | null
sendStatus: number sendStatus: number | null
sendTime: Date sendTime: Date | null
sendCode: number sendCode: number | null
sendMsg: string sendMsg: string
apiSendCode: string apiSendCode: string
apiSendMsg: string apiSendMsg: string
apiRequestId: string apiRequestId: string
apiSerialNo: string apiSerialNo: string
receiveStatus: number receiveStatus: number | null
receiveTime: Date receiveTime: Date | null
apiReceiveCode: string apiReceiveCode: string
apiReceiveMsg: string apiReceiveMsg: string
createTime: Date createTime: Date | null
} }
export interface SmsLogPageReqVO extends PageParam { export interface SmsLogPageReqVO extends PageParam {
channelId?: number channelId?: number | null
templateId?: number templateId?: number | null
mobile?: string mobile?: string
sendStatus?: number sendStatus?: number | null
sendTime?: Date[] sendTime?: Date[]
receiveStatus?: number receiveStatus?: number | null
receiveTime?: Date[] receiveTime?: Date[]
} }
export interface SmsLogExportReqVO { export interface SmsLogExportReqVO {

View File

@ -1,57 +1,401 @@
<template> <template>
<ContentWrap> <content-wrap>
<!-- 搜索工作栏 -->
<el-form
:model="queryParams"
ref="queryForm"
:inline="true"
v-show="showSearch"
label-width="100px"
>
<el-form-item label="手机号" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="短信渠道" prop="channelId">
<el-select v-model="queryParams.channelId" placeholder="请选择短信渠道" clearable>
<el-option
v-for="channel in channelOptions"
:key="channel.id"
:value="channel.id"
:label="
channel.signature + optionLabel(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, channel.code)
"
/>
</el-select>
</el-form-item>
<el-form-item label="模板编号" prop="templateId">
<el-input
v-model="queryParams.templateId"
placeholder="请输入模板编号"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="发送状态" prop="sendStatus">
<el-select v-model="queryParams.sendStatus" placeholder="请选择发送状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_SEND_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="发送时间" prop="sendTime">
<el-date-picker
v-model="queryParams.sendTime"
style="width: 240px"
value-format="yyyy-MM-dd HH:mm:ss"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"
/>
</el-form-item>
<el-form-item label="接收状态" prop="receiveStatus">
<el-select v-model="queryParams.receiveStatus" placeholder="请选择接收状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_RECEIVE_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="接收时间" prop="receiveTime">
<el-date-picker
v-model="queryParams.receiveTime"
style="width: 240px"
value-format="yyyy-MM-dd HH:mm:ss"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery"
><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button
>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
<!-- 操作工具栏 -->
<el-row class="mb-10px">
<el-col :span="12">
<el-row :gutter="10">
<el-col :span="1.5">
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['system:sms-log:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-col>
</el-row>
</el-col>
<el-col :span="12">
<right-toolbar v-model:showSearch="showSearch" @query-table="getList" />
</el-col>
</el-row>
<!-- 列表 --> <!-- 列表 -->
<XTable @register="registerTable"> <el-table v-loading="loading" :data="smsLoglist">
<!-- 操作导出 --> <el-table-column label="编号" align="center" prop="id" />
<template #toolbar_buttons> <el-table-column label="创建时间" align="center" prop="createTime" width="180">
<XButton <template #default="scope">
type="warning" <span>{{ parseTime(scope.row.createTime) }}</span>
preIcon="ep:download"
:title="t('action.export')"
@click="exportList('短信日志.xls')"
/>
</template> </template>
<template #actionbtns_default="{ row }"> </el-table-column>
<XTextButton preIcon="ep:view" :title="t('action.detail')" @click="handleDetail(row)" /> <el-table-column label="手机号" align="center" prop="mobile" width="120">
<template #default="scope">
<div>{{ scope.row.mobile }}</div>
<div v-if="scope.row.userType && scope.row.userId">
<dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType" />{{
'(' + scope.row.userId + ')'
}}
</div>
</template> </template>
</XTable> </el-table-column>
</ContentWrap> <el-table-column label="短信内容" align="center" prop="templateContent" width="300" />
<el-table-column label="发送状态" align="center" width="180">
<XModal id="smsLog" v-model="dialogVisible" :title="dialogTitle"> <template #default="scope">
<!-- 对话框(详情) --> <dict-tag :type="DICT_TYPE.SYSTEM_SMS_SEND_STATUS" :value="scope.row.sendStatus" />
<Descriptions <div>{{ parseTime(scope.row.sendTime) }}</div>
v-if="actionType === 'detail'" </template>
:schema="allSchemas.detailSchema" </el-table-column>
:data="detailData" <el-table-column label="接收状态" align="center" width="180">
<template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_RECEIVE_STATUS" :value="scope.row.receiveStatus" />
<div>{{ parseTime(scope.row.receiveTime) }}</div>
</template>
</el-table-column>
<el-table-column label="短信渠道" align="center" width="120">
<template #default="scope">
<div>{{ formatChannelSignature(scope.row.channelId) }}</div>
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="scope.row.channelCode" />
</template>
</el-table-column>
<el-table-column label="模板编号" align="center" prop="templateId" />
<el-table-column label="短信类型" align="center" prop="templateType">
<template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="scope.row.templateType" />
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
fixed="right"
class-name="small-padding fixed-width"
>
<template #default="scope">
<el-button
link
type="primary"
@click="handleView(scope.row)"
v-hasPermi="['system:sms-log:query']"
><Icon icon="ep:view" class="mr-3px" />详情</el-button
>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/> />
<!-- 操作按钮 --> <!-- 短信日志详细 -->
<el-dialog title="短信日志详细" v-model="open" width="700px" append-to-body>
<el-form ref="form" :model="form" label-width="140px" size="mini">
<el-row>
<el-col :span="24">
<el-form-item label="日志主键:">{{ form.id }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="短信渠道:">
{{ formatChannelSignature(form.channelId) }}
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="form.channelCode" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="短信模板:">
{{ form.templateId }} | {{ form.templateCode }}
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="form.templateType" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="API 的模板编号:">{{ form.apiTemplateId }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="用户信息:"
>{{ form.mobile }}
<span v-if="form.userType && form.userId">
<dict-tag :type="DICT_TYPE.USER_TYPE" :value="form.userType" />({{ form.userId }})
</span>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="短信内容:">{{ form.templateContent }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="短信参数:">{{ form.templateParams }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="创建时间:">{{ parseTime(form.createTime) }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="发送状态:">
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_SEND_STATUS" :value="form.sendStatus" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="发送时间:">{{ parseTime(form.sendTime) }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="发送结果:"
>{{ form.sendCode }} | {{ form.sendMsg }}
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="API 发送结果:"
>{{ form.apiSendCode }} | {{ form.apiSendMsg }}</el-form-item
>
</el-col>
<el-col :span="24">
<el-form-item label="API 短信编号:">{{ form.apiSerialNo }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="API 请求编号:">{{ form.apiRequestId }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="接收状态:">
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_RECEIVE_STATUS" :value="form.receiveStatus" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="接收时间:">{{ parseTime(form.receiveTime) }}</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="API 接收结果:"
>{{ form.apiReceiveCode }} | {{ form.apiReceiveMsg }}
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer> <template #footer>
<XButton :title="t('dialog.close')" @click="dialogVisible = false" /> <el-button @click="open = false"> </el-button>
</template> </template>
</XModal> </el-dialog>
</content-wrap>
</template> </template>
<script setup lang="ts" name="SmsLog"> <script setup lang="ts" name="smsLog">
import { allSchemas } from './sms.log.data' import { DICT_TYPE, getDictOptions, getDictLabel } from '@/utils/dict'
import * as SmsLoglApi from '@/api/system/sms/smsLog' import download from '@/utils/download'
const { t } = useI18n() // import { parseTime } from '@/utils/formatTime'
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
import * as SmsLogApi from '@/api/system/sms/smsLog'
// const message = useMessage() //
const [registerTable, { exportList }] = useXTable({
allSchemas: allSchemas, // ================= ================
getListApi: SmsLoglApi.getSmsLogPageApi, const showSearch = ref(true) //
exportListApi: SmsLoglApi.exportSmsLogApi const queryForm = ref() // queryFormRef
//
const queryParams = ref<SmsLogApi.SmsLogPageReqVO>({
pageNo: 1,
pageSize: 10,
channelId: null,
templateId: null,
mobile: '',
sendStatus: null,
receiveStatus: null,
sendTime: [],
receiveTime: []
}) })
//
// const channelOptions = ref<SmsChannelApi.SmsChannelListVO[]>([])
const dialogVisible = ref(false) // onMounted(() => {
const dialogTitle = ref(t('action.detail')) // SmsChannelApi.getSimpleSmsChannels().then((res) => {
const actionType = ref('') // channelOptions.value = res
// ========== ========== })
const detailData = ref() // Ref })
const handleDetail = (row: SmsLoglApi.SmsLogVO) => { const optionLabel = computed(
// () => (type: string, code: string) => `${getDictLabel(type, code)}`
actionType.value = 'detail' )
detailData.value = row /** 格式化短信渠道 */
dialogVisible.value = true const formatChannelSignature = (channelId: number | null) => {
channelOptions.value.forEach((item) => {
if (item.id === channelId) {
return item.signature
}
})
return '找不到签名:' + channelId
} }
// ================= ================
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
resetForm()
handleQuery()
}
/** 重置搜索表单 */
const resetForm = () => {
queryParams.value = {
pageNo: 1,
pageSize: 10,
channelId: null,
templateId: null,
mobile: '',
sendStatus: null,
receiveStatus: null,
sendTime: [],
receiveTime: []
}
queryForm.value?.resetFields()
}
//
const exportLoading = ref(false)
/** 导出按钮操作 */
const handleExport = () => {
//
let params = queryParams.value as SmsLogApi.SmsLogExportReqVO
//
message
.confirm('是否确认导出所有短信日志数据项?')
.then(() => {
exportLoading.value = true
return SmsLogApi.exportSmsLogApi(params)
})
.then((response) => {
download.excel(response, '短信日志.xls')
exportLoading.value = false
})
.catch(() => {})
}
// ================== ====================
//
const total = ref(0)
//
const smsLoglist = ref([])
const loading = ref(false)
/** 查询列表 */
const getList = () => {
loading.value = true
//
SmsLogApi.getSmsLogPageApi(queryParams.value).then((response) => {
smsLoglist.value = response.list
total.value = response.total
loading.value = false
})
}
// ================== ====================
const open = ref(false)
const form = ref<SmsLogApi.SmsLogVO>({
id: null,
channelId: null,
channelCode: '',
templateId: null,
templateCode: '',
templateType: null,
templateContent: '',
templateParams: null,
apiTemplateId: '',
mobile: '',
userId: null,
userType: null,
sendStatus: null,
sendTime: null,
sendCode: null,
sendMsg: '',
apiSendCode: '',
apiSendMsg: '',
apiRequestId: '',
apiSerialNo: '',
receiveStatus: null,
receiveTime: null,
apiReceiveCode: '',
apiReceiveMsg: '',
createTime: null
})
/** 详细按钮操作 */
const handleView = (row: SmsLogApi.SmsLogVO) => {
open.value = true
form.value = row
}
getList()
</script> </script>