feat:余额排序

This commit is contained in:
dzc committed 2026-11-06 08:53:09 +08:00
1 parent 528f2e0b3d
commit cf7d21cd04
3 files changed
+50 -6

No files matched your search

+3
View File
@@ -52,6 +52,7 @@ export function qbTotal(data: any, signal?: AbortSignal) {
})
}
/** 查询月末钱包余额;排序参数随分页参数传入 URL,由后端完成全量排序后分页。 */
export function fetchListJoinQb(query: any) {
return request({
url: "/wallet/wallet-manage/page-join-qb",
@@ -59,6 +60,8 @@ export function fetchListJoinQb(query: any) {
params: {
current: query.current,
size: query.size,
ascs: query.ascs || undefined,
descs: query.descs || undefined,
},
data: query,
})
+12 -4
View File
@@ -38,7 +38,7 @@
</el-row>
<el-table :data="state.dataList" v-loading="state.loading" border :summary-method="getSummaries"
show-summary :cell-style="tableStyle.cellStyle" :header-cell-style="tableStyle.headerCellStyle"
@selection-change="selectionChangHandle" @sort-change="sortChangeHandle">
@selection-change="selectionChangHandle" @sort-change="handleBalanceSortChange">
<el-table-column type="index" label="#" width="60" />
<el-table-column prop="username" width="120" label="用户" />
<el-table-column prop="userAvatar" width="80" label="头像">
@@ -59,7 +59,7 @@
</template>
</el-table-column>
<el-table-column prop="cardNumber" width="150" label="饭卡卡号" />
<el-table-column prop="balance" align="center" width="100" label="余额">
<el-table-column prop="balance" align="center" width="100" label="余额" sortable="custom">
<template #default="{ row }">
<div class="color-primary">{{ displayPrice(row.balance) }}</div>
</template>
@@ -78,7 +78,7 @@
</el-table-column>
</el-table>
<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
v-bind="state.pagination" />
v-bind="state.pagination" :disabled="Boolean(state.loading)" />
</template>
</DraggableDepTree>
</div>
@@ -150,7 +150,15 @@ const state: BasicTableProps = reactive<BasicTableProps>({
})
// table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, tableStyle } = useTable(state)
const { getDataList, currentChangeHandle, sizeChangeHandle, tableStyle } = useTable(state)
/** 按所选月份的全部筛选结果排序;切换或取消排序时回到首页,翻页继续沿用当前方向。 */
const handleBalanceSortChange = ({ prop, order }: { prop?: string; order: "ascending" | "descending" | null }) => {
// 每次替换单列排序条件,避免重复点击累积字段;月末余额由后端先排序再分页。
state.ascs = prop === "balance" && order === "ascending" ? ["balance"] : []
state.descs = prop === "balance" && order === "descending" ? ["balance"] : []
return getDataList()
}
// 清空搜索条件
const resetQuery = () => {
+35 -2
View File
@@ -26,7 +26,12 @@ function load(source, mocks) {
function mount() {
const requests = []
const lists = []
const listRequests = []
const errors = []
const api = load(fs.readFileSync(path.join(root, "api/wallet/wallet-manage.ts"), "utf8"), {
"/@/utils/request": options => { listRequests.push(options); return Promise.resolve({ data: { records: [], total: 100 } }) },
"/@/api/asyncTask": {},
})
const table = load(fs.readFileSync(path.join(root, "hooks/table.ts"), "utf8"), {
"element-plus": { ElMessage: { error: message => errors.push(message) } },
"/@/utils/other": {}, "../utils/formatTime": {},
@@ -34,7 +39,7 @@ function mount() {
const page = load(source, {
"/@/hooks/table": table,
"/@/api/wallet/wallet-manage": {
fetchListJoinQb: query => { lists.push(query); return Promise.resolve({ data: { records: [], total: 100 } }) },
fetchListJoinQb: query => { lists.push(query); return api.fetchListJoinQb(query) },
qbTotal: (query, signal) => new Promise((resolve, reject) => requests.push({ query, signal, resolve, reject })),
},
"/@/hooks/batchExport": { useBatchExport: () => ({}) },
@@ -53,12 +58,40 @@ function mount() {
setup() { state = page.default.setup({}, { expose() {} }); return () => null },
})
app.mount({})
return { state, requests, lists, errors, close: () => app.unmount() }
return { state, requests, lists, listRequests, errors, close: () => app.unmount() }
}
const settle = () => new Promise(resolve => setImmediate(resolve))
const result = total => ({ code: 0, data: { total, eatTotal: total, payTotal: 0, topupTotal: 0 } })
test("余额排序经真实表格 hook 和 API 传至后端,切换回首页、翻页保留筛选且取消后恢复默认", async () => {
const page = mount()
try {
await settle()
Object.assign(page.state.state.queryForm, { deptIds: ["11"], walletTypeIdList: ["21"], isInclude: false })
page.state.currentChangeHandle(3)
await settle()
await page.state.handleBalanceSortChange({ prop: "balance", order: "ascending" })
const ascending = page.listRequests.at(-1)
assert.equal(ascending.url, "/wallet/wallet-manage/page-join-qb")
assert.equal(ascending.method, "post")
assert.deepEqual(ascending.params, { current: 1, size: 10, ascs: "balance", descs: undefined })
assert.equal(ascending.data.walletRecordMonth, "2026-10")
assert.deepEqual(ascending.data.deptIds, ["11"])
assert.deepEqual(ascending.data.walletTypeIdList, ["21"])
assert.equal(ascending.data.isInclude, false)
page.state.currentChangeHandle(2)
await settle()
assert.deepEqual(page.listRequests.at(-1).params, { current: 2, size: 10, ascs: "balance", descs: undefined })
await page.state.handleBalanceSortChange({ prop: "balance", order: "descending" })
await page.state.handleBalanceSortChange({ prop: "balance", order: "descending" })
assert.deepEqual(page.listRequests.at(-1).params, { current: 1, size: 10, ascs: undefined, descs: "balance" })
await page.state.handleBalanceSortChange({ order: null })
assert.deepEqual(page.listRequests.at(-1).params, { current: 1, size: 10, ascs: undefined, descs: undefined })
assert.equal(page.requests.length, 0)
} finally { page.close() }
})
test("列表首次加载、筛选和翻页均不触发全量余额统计", async () => {
const page = mount()
try {