140 lines
3.7 KiB
TypeScript
140 lines
3.7 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 { List as TenantList } from '@/api/imTenant';
|
||
|
||
const dict = useDictStore();
|
||
|
||
export const tenantOptions = ref<any[]>([]);
|
||
|
||
export class State {
|
||
public id = 0;
|
||
public commandId = '';
|
||
public tenantId = 0;
|
||
public tenantCode = '';
|
||
public eventId = '';
|
||
public eventType = '';
|
||
public bizType = '';
|
||
public bizId = '';
|
||
public idempotencyKey = '';
|
||
public status = '';
|
||
public reason = '';
|
||
public message = '';
|
||
public payload = '';
|
||
public envelope = '';
|
||
public result = '';
|
||
public sentAt = '';
|
||
public completedAt = '';
|
||
public createdBy = 0;
|
||
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: true,
|
||
options: computed(() => tenantOptions.value),
|
||
placeholder: '请选择商户',
|
||
},
|
||
},
|
||
{
|
||
field: 'commandId',
|
||
component: 'NInput',
|
||
label: '命令ID',
|
||
componentProps: { placeholder: '请输入命令ID' },
|
||
},
|
||
{
|
||
field: 'eventId',
|
||
component: 'NInput',
|
||
label: '事件ID',
|
||
componentProps: { placeholder: '请输入事件ID' },
|
||
},
|
||
{
|
||
field: 'eventType',
|
||
component: 'NInput',
|
||
label: '事件类型',
|
||
componentProps: { placeholder: '请输入事件类型' },
|
||
},
|
||
{
|
||
field: 'bizId',
|
||
component: 'NInput',
|
||
label: '业务ID',
|
||
componentProps: { placeholder: '请输入业务ID' },
|
||
},
|
||
{
|
||
field: 'status',
|
||
component: 'NSelect',
|
||
label: '状态',
|
||
componentProps: {
|
||
clearable: true,
|
||
options: dict.getOption('ImAdminCommandStatusOptions'),
|
||
placeholder: '请选择状态',
|
||
},
|
||
},
|
||
{
|
||
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: 'tenantCode', align: 'left', width: 120 },
|
||
{ title: '命令ID', key: 'commandId', align: 'left', width: 210 },
|
||
{ title: '事件类型', key: 'eventType', align: 'left', width: 190 },
|
||
{ title: '业务类型', key: 'bizType', align: 'left', width: 110 },
|
||
{ title: '业务ID', key: 'bizId', align: 'left', width: 180 },
|
||
{
|
||
title: '状态',
|
||
key: 'status',
|
||
align: 'left',
|
||
width: 110,
|
||
render(row: State) {
|
||
return dict.getLabel('ImAdminCommandStatusOptions', row.status);
|
||
},
|
||
},
|
||
{ title: '错误码', key: 'reason', align: 'left', width: 170 },
|
||
{ title: '消息', key: 'message', align: 'left', width: 220 },
|
||
{ title: '投递时间', key: 'sentAt', align: 'left', width: 180 },
|
||
{ title: '完成时间', key: 'completedAt', align: 'left', width: 180 },
|
||
{ title: '创建时间', key: 'createdAt', align: 'left', width: 180 },
|
||
];
|
||
|
||
export function loadOptions() {
|
||
dict.loadOptions(['ImAdminCommandStatusOptions']);
|
||
}
|
||
|
||
export async function loadTenantOptions() {
|
||
const res = await TenantList({ page: 1, perPage: 20 });
|
||
tenantOptions.value = (res?.list || []).map((item) => ({
|
||
label: `${item.name}(${item.code})`,
|
||
value: item.id,
|
||
code: item.code,
|
||
}));
|
||
return tenantOptions.value;
|
||
}
|