144 lines
3.8 KiB
TypeScript
144 lines
3.8 KiB
TypeScript
import { computed, ref } from 'vue';
|
|
import { cloneDeep } from 'lodash-es';
|
|
import { FormSchema } from '@/components/Form';
|
|
import { defRangeShortcuts } from '@/utils/dateUtil';
|
|
import { useDictStore } from '@/store/modules/dict';
|
|
import { loadImTenantOptions } from '@/views/imTenantOptions';
|
|
|
|
const dict = useDictStore();
|
|
|
|
export const tenantOptions = ref<any[]>([]);
|
|
|
|
export class State {
|
|
public tenantId = 0;
|
|
public tenantName = '';
|
|
public source = 'business';
|
|
public id = 0;
|
|
public eventId = '';
|
|
public targetType = '';
|
|
public target = '';
|
|
public actorUserId = 0;
|
|
public eventType = '';
|
|
public payload = '';
|
|
public status = '';
|
|
public attempts = 0;
|
|
public nextRetryAt = '';
|
|
public deliveredAt = '';
|
|
public createdAt = '';
|
|
public updatedAt = '';
|
|
|
|
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: false,
|
|
options: computed(() => tenantOptions.value),
|
|
placeholder: '请选择商户',
|
|
},
|
|
},
|
|
{
|
|
field: 'source',
|
|
component: 'NSelect',
|
|
label: '来源',
|
|
defaultValue: 'business',
|
|
componentProps: {
|
|
clearable: false,
|
|
options: dict.getOption('ImOutboxSourceOptions'),
|
|
placeholder: '请选择来源',
|
|
},
|
|
},
|
|
{
|
|
field: 'status',
|
|
component: 'NSelect',
|
|
label: '状态',
|
|
componentProps: {
|
|
clearable: true,
|
|
options: dict.getOption('ImOutboxStatusOptions'),
|
|
placeholder: '请选择状态',
|
|
},
|
|
},
|
|
{
|
|
field: 'eventType',
|
|
component: 'NInput',
|
|
label: '事件类型',
|
|
componentProps: { placeholder: '请输入事件类型' },
|
|
},
|
|
{
|
|
field: 'eventId',
|
|
component: 'NInput',
|
|
label: '事件ID',
|
|
componentProps: { placeholder: '请输入事件ID' },
|
|
},
|
|
{
|
|
field: 'target',
|
|
component: 'NInput',
|
|
label: '目标',
|
|
componentProps: { placeholder: '请输入目标/Topic' },
|
|
},
|
|
{
|
|
field: 'createdAt',
|
|
component: 'NDatePicker',
|
|
label: '创建时间',
|
|
componentProps: {
|
|
type: 'datetimerange',
|
|
clearable: true,
|
|
shortcuts: defRangeShortcuts(),
|
|
},
|
|
},
|
|
]);
|
|
|
|
export const columns = [
|
|
{ title: 'ID', key: 'id', align: 'left', width: 90 },
|
|
{
|
|
title: '来源',
|
|
key: 'source',
|
|
align: 'left',
|
|
width: 110,
|
|
render(row: State) {
|
|
return dict.getLabel('ImOutboxSourceOptions', row.source);
|
|
},
|
|
},
|
|
{
|
|
title: '状态',
|
|
key: 'status',
|
|
align: 'left',
|
|
width: 110,
|
|
render(row: State) {
|
|
return dict.getLabel('ImOutboxStatusOptions', row.status);
|
|
},
|
|
},
|
|
{ title: '事件类型', key: 'eventType', align: 'left', width: 220 },
|
|
{ title: '事件ID', key: 'eventId', align: 'left', width: 240 },
|
|
{ title: '目标类型', key: 'targetType', align: 'left', width: 120 },
|
|
{ title: '目标', key: 'target', align: 'left', width: 180 },
|
|
{ title: '操作用户', key: 'actorUserId', align: 'left', width: 120 },
|
|
{ title: '尝试次数', key: 'attempts', align: 'left', width: 100 },
|
|
{ title: '下次重试', key: 'nextRetryAt', align: 'left', width: 180 },
|
|
{ title: '投递时间', key: 'deliveredAt', align: 'left', width: 180 },
|
|
{ title: '创建时间', key: 'createdAt', align: 'left', width: 180 },
|
|
{ title: '更新时间', key: 'updatedAt', align: 'left', width: 180 },
|
|
];
|
|
|
|
export function loadOptions() {
|
|
dict.loadOptions(['ImOutboxSourceOptions', 'ImOutboxStatusOptions']);
|
|
}
|
|
|
|
export async function loadTenantOptions() {
|
|
return loadImTenantOptions(tenantOptions, { page: 1, perPage: 20 });
|
|
}
|