feat: 新增转账功能,包含转账视图及相关路由配置;更新 API 类型依赖至 0.0.64

This commit is contained in:
2025-12-24 19:22:30 +07:00
parent d46f696085
commit 984aff06b6
8 changed files with 168 additions and 12 deletions

View File

@@ -0,0 +1,141 @@
<script lang="ts" setup>
import { h, useTemplateRef } from 'vue';
import { useDateFormat } from '@vueuse/core';
import { NInput, NSelect, NTag } from 'naive-ui';
import { client, safeClient } from '@/service/api';
import type { TableBaseColumns, TableFetchData, TableFilterColumns, TableInst } from '@/components/table';
const tableInst = useTemplateRef<TableInst>('tableInst');
const fetchData: TableFetchData = ({ pagination, filter }) => {
return safeClient(() =>
client.api.admin.transfer.get({
query: {
...pagination,
...filter
}
})
);
};
// 状态枚举映射
const TransferStatusEnum = {
pending: '待完成',
completed: '已完成',
failed: '失败'
};
// 状态标签类型映射
const getStatusTagType = (status: string) => {
const typeMap: Record<string, 'warning' | 'success' | 'error'> = {
pending: 'warning',
completed: 'success',
failed: 'error'
};
return typeMap[status] || 'default';
};
const columns: TableBaseColumns = [
{
title: '订单ID',
key: 'id',
width: 180
},
{
title: '订单号',
key: 'orderNo',
width: 200
},
{
title: '转出账户ID',
key: 'fromUserId',
width: 150
},
{
title: '资产代码',
key: 'assetCode',
width: 120
},
{
title: '金额',
key: 'amount',
width: 150,
render: row => {
return Number(row.amount).toFixed(2);
}
},
{
title: '手续费',
key: 'fee',
width: 120,
render: row => {
return Number(row.fee || 0).toFixed(2);
}
},
{
title: '状态',
key: 'status',
width: 120,
render: row => {
return h(
NTag,
{
type: getStatusTagType(row.status)
},
{
default: () => TransferStatusEnum[row.status as keyof typeof TransferStatusEnum] || row.status
}
);
}
},
{
title: '创建时间',
key: 'createdAt',
width: 180,
render: (row: any) => {
return useDateFormat(row.createdAt, 'YYYY-MM-DD HH:mm:ss').value;
}
}
];
const filterColumns: TableFilterColumns = [
{
title: '用户ID',
key: 'userId',
component: NInput,
componentProps: {
placeholder: '请输入用户ID',
clearable: true
}
},
{
title: '资产代码',
key: 'assetCode',
component: NInput,
componentProps: {
placeholder: '请输入资产代码',
clearable: true
}
},
{
title: '状态',
key: 'status',
component: NSelect,
componentProps: {
placeholder: '请选择状态',
clearable: true,
options: [
{ label: '待完成', value: 'pending' },
{ label: '已完成', value: 'completed' },
{ label: '失败', value: 'failed' }
]
}
}
];
</script>
<template>
<TableBase ref="tableInst" :columns="columns" :filter-columns="filterColumns" :fetch-data="fetchData" />
</template>
<style lang="css" scoped></style>