优化表格组件,新增过滤功能,调整数据获取逻辑,更新相关页面及路由
This commit is contained in:
@@ -14,16 +14,21 @@ import type { TableColumnCheck } from '~/packages/hooks/src';
|
||||
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
|
||||
const title = t(route.meta.i18nKey as string);
|
||||
const props = defineProps<{
|
||||
fetchData: TableFetchData;
|
||||
columns: TableBaseColumns;
|
||||
showHeaderOperation?: boolean;
|
||||
filterColumns?: TableFilterColumns;
|
||||
}>();
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
fetchData: TableFetchData;
|
||||
columns: TableBaseColumns;
|
||||
showHeaderOperation?: boolean;
|
||||
filterColumns?: TableFilterColumns;
|
||||
}>(),
|
||||
{
|
||||
filterColumns: () => []
|
||||
}
|
||||
);
|
||||
const emit = defineEmits<{
|
||||
(e: 'add'): void;
|
||||
(e: 'refresh'): void;
|
||||
(e: 'delete'): void;
|
||||
}>();
|
||||
|
||||
@@ -86,7 +91,7 @@ defineExpose({
|
||||
|
||||
<template>
|
||||
<div class="space-y-5">
|
||||
<TableFilter :columns="filterColumns" @confirm="handleSearch" />
|
||||
<TableFilter v-if="filterColumns.length > 0" :columns="filterColumns" @confirm="handleSearch" />
|
||||
|
||||
<div class="rounded-lg bg-white p-5 space-y-5">
|
||||
<TableHeaderOperation
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { NInput } from 'naive-ui';
|
||||
import type { TableFilterColumns } from '.';
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
columns?: TableFilterColumns;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
(e: 'confirm', form: Record<string, any>): void;
|
||||
}>();
|
||||
|
||||
const inlineForm: Record<string, any> = {};
|
||||
|
||||
const form = ref<Record<string, any>>({});
|
||||
|
||||
onMounted(() => {
|
||||
props.columns?.forEach(col => {
|
||||
inlineForm[col.key] = null;
|
||||
form.value[col.key] = null;
|
||||
});
|
||||
});
|
||||
|
||||
function handleReset() {
|
||||
form.value = {};
|
||||
form.value = { ...inlineForm };
|
||||
emit('confirm', form.value);
|
||||
}
|
||||
|
||||
@@ -30,7 +39,12 @@ function handleConfirm() {
|
||||
<NGrid x-gap="20" :cols="4">
|
||||
<NGi v-for="col in columns" :key="col.key">
|
||||
<NFormItem :label="col.title" :path="col.key">
|
||||
<component :is="col.component || NInput" v-model:value="form[col.key]" v-bind="col.componentProps" />
|
||||
<component
|
||||
:is="col.component || NInput"
|
||||
:value="form[col.key]"
|
||||
v-bind="col.componentProps"
|
||||
@update:value="(val: any) => (form[col.key] = val)"
|
||||
/>
|
||||
</NFormItem>
|
||||
</NGi>
|
||||
<NGi>
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, useTemplateRef } from 'vue';
|
||||
import { NInputNumber, useDialog, useMessage } from 'naive-ui';
|
||||
import { NInputNumber, NSelect, useDialog, useMessage } from 'naive-ui';
|
||||
import { client, safeClient } from '@/service/api';
|
||||
import { DepositTypeEnum } from '@/enum';
|
||||
import type { Pagination, TableBaseColumns, TableFetchData, TableInst } from '@/components/table';
|
||||
import type { TableBaseColumns, TableFetchData, TableFilterColumns, TableInst } from '@/components/table';
|
||||
|
||||
const dialog = useDialog();
|
||||
const message = useMessage();
|
||||
const tableInst = useTemplateRef<TableInst>('tableInst');
|
||||
|
||||
const fetchData: TableFetchData = (pagination: Pagination) => {
|
||||
const fetchData: TableFetchData = ({ pagination, filter }) => {
|
||||
return safeClient(() =>
|
||||
client.api.admin.deposit.pending.get({
|
||||
query: pagination
|
||||
query: { ...pagination, ...filter }
|
||||
})
|
||||
);
|
||||
};
|
||||
@@ -108,10 +108,38 @@ const columns: TableBaseColumns = [
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const filterColumns: TableFilterColumns = [
|
||||
{
|
||||
title: '用户ID',
|
||||
key: 'userId'
|
||||
},
|
||||
{
|
||||
title: '资产代码',
|
||||
key: 'assetCode'
|
||||
},
|
||||
{
|
||||
title: '充值类型',
|
||||
key: 'depositType',
|
||||
component: NSelect,
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '法币充值', value: 'fiat' },
|
||||
{ label: '加密货币充值', value: 'crypto' }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TableBase ref="tableInst" :columns="columns" :fetch-data="fetchData" />
|
||||
<TableBase
|
||||
ref="tableInst"
|
||||
:columns="columns"
|
||||
:fetch-data="fetchData"
|
||||
show-header-operation
|
||||
:filter-columns="filterColumns"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style lang="css" scoped></style>
|
||||
|
||||
Reference in New Issue
Block a user