feat(system): 添加 webhook 管理功能
- 新增 webhook API 和相关接口 - 实现 webhook 列表页面,包括搜索、添加、编辑和删除功能 - 添加 webhook 表单组件,用于创建和更新 webhook 信息 - 在字典工具中添加新的字典类型:WEBHOOK_TYPE 和 ON_OFF - 优化日期格式化函数,增加对空值的处理pull/788/head
parent
b14df2e01b
commit
e1332212c8
|
|
@ -0,0 +1,50 @@
|
||||||
|
import request from '@/config/axios'
|
||||||
|
import type { Dayjs } from 'dayjs';
|
||||||
|
|
||||||
|
/** webhook信息 */
|
||||||
|
export interface Webhook {
|
||||||
|
id: number; // ID
|
||||||
|
bizName?: string; // 群名称
|
||||||
|
accessToken?: string; // 通证
|
||||||
|
secret?: string; // 加签密钥
|
||||||
|
type?: number; // 类型(0:钉钉,1:企微,2:飞书)
|
||||||
|
status?: number; // 状态(0正常 1关闭)
|
||||||
|
}
|
||||||
|
|
||||||
|
// webhook API
|
||||||
|
export const WebhookApi = {
|
||||||
|
// 查询webhook分页
|
||||||
|
getWebhookPage: async (params: any) => {
|
||||||
|
return await request.get({ url: `/system/webhook/page`, params })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 查询webhook详情
|
||||||
|
getWebhook: async (id: number) => {
|
||||||
|
return await request.get({ url: `/system/webhook/get?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增webhook
|
||||||
|
createWebhook: async (data: Webhook) => {
|
||||||
|
return await request.post({ url: `/system/webhook/create`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改webhook
|
||||||
|
updateWebhook: async (data: Webhook) => {
|
||||||
|
return await request.put({ url: `/system/webhook/update`, data })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 删除webhook
|
||||||
|
deleteWebhook: async (id: number) => {
|
||||||
|
return await request.delete({ url: `/system/webhook/delete?id=` + id })
|
||||||
|
},
|
||||||
|
|
||||||
|
/** 批量删除webhook */
|
||||||
|
deleteWebhookList: async (ids: number[]) => {
|
||||||
|
return await request.delete({ url: `/system/webhook/delete-list?ids=${ids.join(',')}` })
|
||||||
|
},
|
||||||
|
|
||||||
|
// 导出webhook Excel
|
||||||
|
exportWebhook: async (params) => {
|
||||||
|
return await request.download({ url: `/system/webhook/export-excel`, params })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -244,5 +244,7 @@ export enum DICT_TYPE {
|
||||||
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态
|
IOT_PLUGIN_STATUS = 'iot_plugin_status', // IOT 插件状态
|
||||||
IOT_PLUGIN_TYPE = 'iot_plugin_type', // IOT 插件类型
|
IOT_PLUGIN_TYPE = 'iot_plugin_type', // IOT 插件类型
|
||||||
IOT_DATA_BRIDGE_DIRECTION_ENUM = 'iot_data_bridge_direction_enum', // 桥梁方向
|
IOT_DATA_BRIDGE_DIRECTION_ENUM = 'iot_data_bridge_direction_enum', // 桥梁方向
|
||||||
IOT_DATA_BRIDGE_TYPE_ENUM = 'iot_data_bridge_type_enum' // 桥梁类型
|
IOT_DATA_BRIDGE_TYPE_ENUM = 'iot_data_bridge_type_enum', // 桥梁类型
|
||||||
|
WEBHOOK_TYPE = 'webhook_type',
|
||||||
|
ON_OFF = 'on_off'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,10 @@ export function formatPast2(ms: number): string {
|
||||||
* @param cellValue 字段值
|
* @param cellValue 字段值
|
||||||
*/
|
*/
|
||||||
export function dateFormatter(_row: any, _column: TableColumnCtx<any>, cellValue: any): string {
|
export function dateFormatter(_row: any, _column: TableColumnCtx<any>, cellValue: any): string {
|
||||||
|
if (!cellValue) {
|
||||||
|
console.warn('dateFormatter received falsy value:', cellValue)
|
||||||
|
return 'N/A' // 或者返回 '--'
|
||||||
|
}
|
||||||
return cellValue ? formatDate(cellValue) : ''
|
return cellValue ? formatDate(cellValue) : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,132 @@
|
||||||
|
<template>
|
||||||
|
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="100px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
|
<el-form-item label="业务标识" prop="bizName">
|
||||||
|
<el-input v-model="formData.bizName" placeholder="请输入业务标识" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="通证" prop="accessToken">
|
||||||
|
<el-input v-model="formData.accessToken" placeholder="请输入通证" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="加签密钥" prop="secret">
|
||||||
|
<el-input v-model="formData.secret" placeholder="请输入加签密钥" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="平台类型" prop="type">
|
||||||
|
<el-select v-model="formData.type" placeholder="请选择类型">
|
||||||
|
<el-option
|
||||||
|
v-for="dict in getIntDictOptions(DICT_TYPE.WEBHOOK_TYPE)"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="formData.status">
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in getIntDictOptions(DICT_TYPE.ON_OFF)"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value"
|
||||||
|
>
|
||||||
|
{{ dict.label }}
|
||||||
|
</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { WebhookApi, Webhook } from '@/api/system/webhook'
|
||||||
|
|
||||||
|
/** webhook 表单 */
|
||||||
|
defineOptions({ name: 'WebhookForm' })
|
||||||
|
|
||||||
|
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 formData = ref({
|
||||||
|
id: undefined,
|
||||||
|
bizName: undefined,
|
||||||
|
accessToken: undefined,
|
||||||
|
secret: undefined,
|
||||||
|
type: undefined,
|
||||||
|
status: undefined
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
bizName: [{ required: true, message: '群名称不能为空', trigger: 'blur' }],
|
||||||
|
accessToken: [{ required: true, message: '通证不能为空', trigger: 'blur' }],
|
||||||
|
secret: [{ required: true, message: '加签密钥不能为空', trigger: 'blur' }],
|
||||||
|
type: [{ required: true, message: '类型(0:钉钉,1:企微,2:飞书)不能为空', trigger: 'change' }],
|
||||||
|
status: [{ required: true, message: '状态(0正常 1关闭)不能为空', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async (type: string, id?: number) => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
dialogTitle.value = t('action.' + type)
|
||||||
|
formType.value = type
|
||||||
|
resetForm()
|
||||||
|
// 修改时,设置数据
|
||||||
|
if (id) {
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
formData.value = await WebhookApi.getWebhook(id)
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
await formRef.value.validate()
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = formData.value as unknown as Webhook
|
||||||
|
if (formType.value === 'create') {
|
||||||
|
await WebhookApi.createWebhook(data)
|
||||||
|
message.success(t('common.createSuccess'))
|
||||||
|
} else {
|
||||||
|
await WebhookApi.updateWebhook(data)
|
||||||
|
message.success(t('common.updateSuccess'))
|
||||||
|
}
|
||||||
|
dialogVisible.value = false
|
||||||
|
// 发送操作成功的事件
|
||||||
|
emit('success')
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
id: undefined,
|
||||||
|
bizName: undefined,
|
||||||
|
accessToken: undefined,
|
||||||
|
secret: undefined,
|
||||||
|
type: undefined,
|
||||||
|
status: undefined
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
@ -0,0 +1,275 @@
|
||||||
|
<template>
|
||||||
|
<ContentWrap>
|
||||||
|
<!-- 搜索工作栏 -->
|
||||||
|
<el-form
|
||||||
|
class="-mb-15px"
|
||||||
|
:model="queryParams"
|
||||||
|
ref="queryFormRef"
|
||||||
|
:inline="true"
|
||||||
|
label-width="68px"
|
||||||
|
>
|
||||||
|
<el-form-item label="群名称" prop="bizName">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.bizName"
|
||||||
|
placeholder="请输入群名称"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="通证" prop="accessToken">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.accessToken"
|
||||||
|
placeholder="请输入通证"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="加签密钥" prop="secret">
|
||||||
|
<el-input
|
||||||
|
v-model="queryParams.secret"
|
||||||
|
placeholder="请输入加签密钥"
|
||||||
|
clearable
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
class="!w-240px"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="类型" prop="type">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.type"
|
||||||
|
placeholder="请选择类型"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in getIntDictOptions(DICT_TYPE.WEBHOOK_TYPE)"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.status"
|
||||||
|
placeholder="请选择状态"
|
||||||
|
clearable
|
||||||
|
class="!w-240px"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in getIntDictOptions(DICT_TYPE.ON_OFF)"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button @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-button
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
@click="openForm('create')"
|
||||||
|
v-hasPermi="['system:webhook:create']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
@click="handleExport"
|
||||||
|
:loading="exportLoading"
|
||||||
|
v-hasPermi="['system:webhook:export']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
plain
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
@click="handleDeleteBatch"
|
||||||
|
v-hasPermi="['system:webhook:delete']"
|
||||||
|
>
|
||||||
|
<Icon icon="ep:delete" class="mr-5px" /> 批量删除
|
||||||
|
</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 列表 -->
|
||||||
|
<ContentWrap>
|
||||||
|
<el-table
|
||||||
|
row-key="id"
|
||||||
|
v-loading="loading"
|
||||||
|
:data="list"
|
||||||
|
:stripe="true"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
@selection-change="handleRowCheckboxChange"
|
||||||
|
>
|
||||||
|
<el-table-column type="selection" width="55" />
|
||||||
|
<!-- <el-table-column label="ID" align="center" prop="id" />-->
|
||||||
|
<el-table-column label="群名称" align="center" prop="bizName" />
|
||||||
|
<el-table-column label="通证" align="center" prop="accessToken" />
|
||||||
|
<el-table-column label="加签密钥" align="center" prop="secret" />
|
||||||
|
<el-table-column label="类型" align="center" prop="type">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.WEBHOOK_TYPE" :value="scope.row.type" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" align="center" prop="status">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :type="DICT_TYPE.ON_OFF" :value="scope.row.status" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
label="创建时间"
|
||||||
|
align="center"
|
||||||
|
prop="createTime"
|
||||||
|
:formatter="dateFormatter"
|
||||||
|
width="180px"
|
||||||
|
/>
|
||||||
|
<el-table-column label="操作" align="center" min-width="120px">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
@click="openForm('update', scope.row.id)"
|
||||||
|
v-hasPermi="['system:webhook:update']"
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
type="danger"
|
||||||
|
@click="handleDelete(scope.row.id)"
|
||||||
|
v-hasPermi="['system:webhook:delete']"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
|
||||||
|
<!-- 表单弹窗:添加/修改 -->
|
||||||
|
<WebhookForm ref="formRef" @success="getList" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||||
|
import { isEmpty } from '@/utils/is'
|
||||||
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
|
import download from '@/utils/download'
|
||||||
|
import { WebhookApi, Webhook } from '@/api/system/webhook'
|
||||||
|
import WebhookForm from './WebhookForm.vue'
|
||||||
|
|
||||||
|
/** webhook 列表 */
|
||||||
|
defineOptions({ name: 'Webhook' })
|
||||||
|
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
|
const loading = ref(true) // 列表的加载中
|
||||||
|
const list = ref<Webhook[]>([]) // 列表的数据
|
||||||
|
const total = ref(0) // 列表的总页数
|
||||||
|
const queryParams = reactive({
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
bizName: undefined,
|
||||||
|
accessToken: undefined,
|
||||||
|
secret: undefined,
|
||||||
|
type: undefined,
|
||||||
|
status: undefined,
|
||||||
|
createTime: undefined
|
||||||
|
})
|
||||||
|
const queryFormRef = ref() // 搜索的表单
|
||||||
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const data = await WebhookApi.getWebhookPage(queryParams)
|
||||||
|
list.value = data.list
|
||||||
|
total.value = data.total
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.pageNo = 1
|
||||||
|
getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value.resetFields()
|
||||||
|
handleQuery()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 添加/修改操作 */
|
||||||
|
const formRef = ref()
|
||||||
|
const openForm = (type: string, id?: number) => {
|
||||||
|
formRef.value.open(type, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (id: number) => {
|
||||||
|
try {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
// 发起删除
|
||||||
|
await WebhookApi.deleteWebhook(id)
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
// 刷新列表
|
||||||
|
await getList()
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量删除webhook */
|
||||||
|
const handleDeleteBatch = async () => {
|
||||||
|
try {
|
||||||
|
// 删除的二次确认
|
||||||
|
await message.delConfirm()
|
||||||
|
await WebhookApi.deleteWebhookList(checkedIds.value);
|
||||||
|
message.success(t('common.delSuccess'))
|
||||||
|
await getList();
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([])
|
||||||
|
const handleRowCheckboxChange = (records: Webhook[]) => {
|
||||||
|
checkedIds.value = records.map((item) => item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
const handleExport = async () => {
|
||||||
|
try {
|
||||||
|
// 导出的二次确认
|
||||||
|
await message.exportConfirm()
|
||||||
|
// 发起导出
|
||||||
|
exportLoading.value = true
|
||||||
|
const data = await WebhookApi.exportWebhook(queryParams)
|
||||||
|
download.excel(data, 'webhook.xls')
|
||||||
|
} catch {
|
||||||
|
} finally {
|
||||||
|
exportLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化 **/
|
||||||
|
onMounted(() => {
|
||||||
|
getList()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue