Files
im_manager/web/src/views/imDeadLetter/model.ts
T

123 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { computed, ref } from 'vue';
import { cloneDeep } from 'lodash-es';
import { FormSchema } from '@/components/Form';
import { useDictStore } from '@/store/modules/dict';
import { List as TenantList } from '@/api/imTenant';
const dict = useDictStore();
export const tenantOptions = ref<any[]>([]);
export class State {
public id = 0;
public tenantId = 0;
public deadId = '';
public eventId = '';
public parentEventId = '';
public sourceTopic = '';
public consumerGroup = '';
public eventType = '';
public bizType = '';
public bizId = '';
public retryCount = 0;
public lastReason = '';
public lastError = '';
public status = '';
public replayCount = 0;
public createdAt = '';
public updatedAt = '';
public envelope = '';
public envelopeRaw = '';
constructor(state?: Partial<State>) {
if (state) Object.assign(this, state);
}
}
export function newState(state: State | Record<string, any> | null): State {
if (state !== null) {
if (state instanceof State) return cloneDeep(state);
return new State(state);
}
return new State();
}
export const schemas = ref<FormSchema[]>([
{
field: 'tenantId',
component: 'NSelect',
label: '租户',
componentProps: {
clearable: true,
options: computed(() => tenantOptions.value),
placeholder: '请选择租户',
},
},
{
field: 'status',
component: 'NSelect',
label: '状态',
componentProps: {
clearable: true,
options: computed(() => dict.getOptions('ImKafkaDeadLetterStatusOptions')),
placeholder: '请选择状态',
},
},
{
field: 'eventType',
component: 'NInput',
label: '事件类型',
componentProps: { placeholder: '请输入事件类型' },
},
{
field: 'bizType',
component: 'NInput',
label: '业务类型',
componentProps: { placeholder: '请输入业务类型' },
},
{
field: 'bizId',
component: 'NInput',
label: '业务ID',
componentProps: { placeholder: '请输入业务ID' },
},
]);
export const columns = [
{ title: 'ID', key: 'id', align: 'left', width: 90 },
{ title: '死信ID', key: 'deadId', align: 'left', width: 220 },
{ title: '事件ID', key: 'eventId', align: 'left', width: 220 },
{ title: '来源Topic', key: 'sourceTopic', align: 'left', width: 150 },
{ title: '消费组', key: 'consumerGroup', align: 'left', width: 160 },
{ title: '事件类型', key: 'eventType', align: 'left', width: 190 },
{ title: '业务类型', key: 'bizType', align: 'left', width: 130 },
{ title: '业务ID', key: 'bizId', align: 'left', width: 180 },
{
title: '状态',
key: 'status',
align: 'left',
width: 120,
render(row: State) {
return dict.getLabel('ImKafkaDeadLetterStatusOptions', row.status);
},
},
{ title: '重试', key: 'retryCount', align: 'left', width: 80 },
{ title: '重放', key: 'replayCount', align: 'left', width: 80 },
{ title: '原因', key: 'lastReason', align: 'left', width: 180 },
{ title: '创建时间', key: 'createdAt', align: 'left', width: 180 },
{ title: '更新时间', key: 'updatedAt', align: 'left', width: 180 },
];
export function loadOptions() {
dict.loadOptions(['ImKafkaDeadLetterStatusOptions']);
}
export async function loadTenantOptions() {
const res = await TenantList({ page: 1, perPage: 200 });
tenantOptions.value = (res?.list || []).map((item) => ({
label: `${item.name}(${item.code})`,
value: item.id,
}));
return tenantOptions.value;
}