feat: 通知配置调试页面+接口联调

This commit is contained in:
JiangQiming 2023-01-29 16:02:20 +08:00
parent e0c8e413bb
commit 1aa7839a54
7 changed files with 245 additions and 9 deletions

View File

@ -1,4 +1,5 @@
import { patch, post, get, remove } from '@/utils/request'
import { TemplateFormData } from '@/views/notice/Template/types'
export default {
// 列表
@ -10,8 +11,8 @@ export default {
// 修改
update: (data: any) => patch(`/notifier/config`, data),
del: (id: string) => remove(`/notifier/config/${id}`),
getTemplate: (data: any, id: string) => post(`/notifier/template/${id}/_query`, data),
getTemplateDetail: (id: string) => get(`/notifier/template/${id}/detail`),
getTemplate: (data: any, id: string) => post<TemplateFormData[]>(`/notifier/template/${id}/_query`, data),
getTemplateDetail: (id: string) => get<TemplateFormData>(`/notifier/template/${id}/detail`),
debug: (data: any, configId: string, templateId: string) => post(`/notifier/${configId}/${templateId}/_send`, data),
getHistory: (data: any, id: string) => post(`/notify/history/config/${id}/_query`, data),
// 获取所有平台用户

View File

@ -109,7 +109,7 @@ const props = defineProps({
//
itemType: {
type: String,
default: () => 'geoPoint',
default: () => 'string',
},
//
options: {

View File

@ -0,0 +1,201 @@
<template>
<a-modal
v-model:visible="_vis"
title="调试"
cancelText="取消"
okText="确定"
@ok="handleOk"
@cancel="handleCancel"
:confirmLoading="btnLoading"
>
<a-form layout="vertical">
<a-form-item label="通知模版" v-bind="validateInfos.templateId">
<a-select
v-model:value="formData.templateId"
placeholder="请选择通知模版"
@change="getTemplateDetail"
>
<a-select-option
v-for="(item, index) in templateList"
:key="index"
:value="item.id"
>
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item
label="变量"
v-bind="validateInfos.variableDefinitions"
v-if="templateDetailTable && templateDetailTable.length"
>
<a-table
ref="myTable"
class="debug-table"
:columns="columns"
:data-source="templateDetailTable"
:pagination="false"
:rowKey="
(record, index) => {
return record.id;
}
"
>
<template #bodyCell="{ column, text, record }">
<template
v-if="['id', 'name'].includes(column.dataIndex)"
>
<span>{{ record[column.dataIndex] }}</span>
</template>
<template v-else>
<ValueItem
v-model:modelValue="record.value"
:itemType="record.type"
/>
</template>
</template>
</a-table>
</a-form-item>
</a-form>
</a-modal>
</template>
<script setup lang="ts">
import { Form } from 'ant-design-vue';
import { PropType } from 'vue';
import ConfigApi from '@/api/notice/config';
import {
TemplateFormData,
IVariableDefinitions,
} from '@/views/notice/Template/types';
import { message } from 'ant-design-vue';
const useForm = Form.useForm;
type Emits = {
(e: 'update:visible', data: boolean): void;
};
const emit = defineEmits<Emits>();
const props = defineProps({
visible: { type: Boolean, default: false },
data: {
type: Object as PropType<Partial<Record<string, any>>>,
default: () => ({}),
},
});
const _vis = computed({
get: () => props.visible,
set: (val) => emit('update:visible', val),
});
/**
* 获取通知模板
*/
const templateList = ref<TemplateFormData[]>([]);
const getTemplateList = async () => {
const params = {
terms: [
{ column: 'type', value: props.data.type },
{ column: 'provider', value: props.data.provider },
],
};
const { result } = await ConfigApi.getTemplate(params, props.data.id);
templateList.value = result;
};
watch(
() => _vis.value,
(val) => {
if (val) getTemplateList();
},
);
/**
* 获取模板详情
*/
const templateDetailTable = ref<IVariableDefinitions[]>();
const getTemplateDetail = async () => {
const { result } = await ConfigApi.getTemplateDetail(
formData.value.templateId,
);
templateDetailTable.value = result.variableDefinitions.map((m: any) => ({
...m,
value: undefined,
}));
};
const columns = [
{
title: '变量',
dataIndex: 'id',
scopedSlots: { customRender: 'id' },
},
{
title: '名称',
dataIndex: 'name',
scopedSlots: { customRender: 'name' },
},
{
title: '值',
dataIndex: 'type',
width: 160,
scopedSlots: { customRender: 'type' },
},
];
//
const formData = ref({
templateId: '',
variableDefinitions: '',
});
//
const formRules = ref({
templateId: [{ required: true, message: '请选择通知模板' }],
variableDefinitions: [{ required: false, message: '该字段是必填字段' }],
});
const { resetFields, validate, validateInfos, clearValidate } = useForm(
formData.value,
formRules.value,
);
/**
* 提交
*/
const btnLoading = ref(false);
const handleOk = () => {
validate()
.then(async () => {
const params = {};
templateDetailTable.value?.forEach((item) => {
params[item.id] = item.value;
});
// console.log('params: ', params);
btnLoading.value = true;
ConfigApi.debug(params, props.data.id, formData.value.templateId)
.then((res) => {
if (res.success) {
message.success('操作成功');
handleCancel();
}
})
.finally(() => {
btnLoading.value = false;
});
})
.catch((err) => {
console.log('err: ', err);
});
};
const handleCancel = () => {
_vis.value = false;
templateDetailTable.value = [];
resetFields();
};
</script>
<style lang="less" scoped></style>

View File

@ -0,0 +1,13 @@
<template>
<div class="page-container">
</div>
</template>
<script setup lang="ts">
</script>
<style lang="less" scoped>
</style>

View File

@ -0,0 +1,13 @@
<template>
<div class="page-container">
</div>
</template>
<script setup lang="ts">
</script>
<style lang="less" scoped>
</style>

View File

@ -150,6 +150,8 @@
</template>
</JTable>
</a-card>
<Debug v-model:visible="debugVis" :data="currentConfig" />
</div>
</template>
@ -158,13 +160,12 @@ import configApi from '@/api/notice/config';
import type { ActionsType } from '@/components/Table/index.vue';
import { getImage, LocalStore } from '@/utils/comm';
import { message } from 'ant-design-vue';
// import Import from './Import/index.vue';
// import Export from './Export/index.vue';
// import Process from './Process/index.vue';
// import Save from './Save/index.vue';
import { BASE_API_PATH, TOKEN_KEY } from '@/utils/variable';
import { NOTICE_METHOD, MSG_TYPE } from '@/views/notice/const';
import SyncUser from './SyncUser/index.vue'
import Debug from './Debug/index.vue'
import Log from './Log/index.vue'
let providerList: any = [];
Object.keys(MSG_TYPE).forEach((key) => {
@ -274,6 +275,10 @@ const handleView = (id: string) => {
message.warn(id + '暂未开发');
};
const syncVis = ref(false);
const debugVis = ref(false);
const logVis = ref(false);
const currentConfig = ref<Partial<Record<string, any>>>();
const getActions = (
data: Partial<Record<string, any>>,
type: 'card' | 'table',
@ -301,7 +306,8 @@ const getActions = (
},
icon: 'BugOutlined',
onClick: () => {
// debugVis.value = true;
debugVis.value = true;
currentConfig.value = data;
},
},
{
@ -312,7 +318,8 @@ const getActions = (
},
icon: 'BarsOutlined',
onClick: () => {
// debugVis.value = true;
logVis.value = true;
currentConfig.value = data;
},
},
{

View File

@ -14,6 +14,7 @@ interface IVariableDefinitions {
name: string;
type: string;
format: string;
value?: string;
}
interface IMarkDown {