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