大量的代码格式化
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 1m10s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
Some checks failed
Docker Build & Deploy / Build Docker Image (push) Failing after 1m10s
Docker Build & Deploy / Deploy to Production (push) Has been skipped
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
<template>
|
||||
<div class="reason-group-list-v2">
|
||||
<van-empty v-if="groups.length === 0 && !loading" description="暂无数据" />
|
||||
|
||||
<van-cell-group v-else inset>
|
||||
<van-cell
|
||||
v-for="group in groups"
|
||||
<van-empty
|
||||
v-if="groups.length === 0 && !loading"
|
||||
description="暂无数据"
|
||||
/>
|
||||
|
||||
<van-cell-group
|
||||
v-else
|
||||
inset
|
||||
>
|
||||
<van-cell
|
||||
v-for="group in groups"
|
||||
:key="group.reason"
|
||||
clickable
|
||||
@click="handleGroupClick(group)"
|
||||
@@ -12,7 +18,7 @@
|
||||
>
|
||||
<template #title>
|
||||
<div class="group-header">
|
||||
<van-checkbox
|
||||
<van-checkbox
|
||||
v-if="selectable"
|
||||
:model-value="isSelected(group.reason)"
|
||||
@click.stop="handleToggleSelection(group.reason)"
|
||||
@@ -24,23 +30,26 @@
|
||||
</template>
|
||||
<template #label>
|
||||
<div class="group-info">
|
||||
<van-tag
|
||||
:type="getTypeColor(group.sampleType)"
|
||||
<van-tag
|
||||
:type="getTypeColor(group.sampleType)"
|
||||
size="medium"
|
||||
style="margin-right: 8px;"
|
||||
style="margin-right: 8px"
|
||||
>
|
||||
{{ getTypeName(group.sampleType) }}
|
||||
</van-tag>
|
||||
<van-tag
|
||||
v-if="group.sampleClassify"
|
||||
type="primary"
|
||||
<van-tag
|
||||
v-if="group.sampleClassify"
|
||||
type="primary"
|
||||
size="medium"
|
||||
style="margin-right: 8px;"
|
||||
style="margin-right: 8px"
|
||||
>
|
||||
{{ group.sampleClassify }}
|
||||
</van-tag>
|
||||
<span class="count-text">{{ group.count }} 条</span>
|
||||
<span v-if="group.totalAmount" class="amount-text">
|
||||
<span
|
||||
v-if="group.totalAmount"
|
||||
class="amount-text"
|
||||
>
|
||||
¥{{ Math.abs(group.totalAmount).toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
@@ -59,8 +68,8 @@
|
||||
height="75%"
|
||||
>
|
||||
<template #header-actions>
|
||||
<van-button
|
||||
type="primary"
|
||||
<van-button
|
||||
type="primary"
|
||||
size="small"
|
||||
class="batch-classify-btn"
|
||||
@click.stop="handleBatchClassify(selectedGroup)"
|
||||
@@ -68,7 +77,7 @@
|
||||
批量分类
|
||||
</van-button>
|
||||
</template>
|
||||
|
||||
|
||||
<TransactionList
|
||||
:transactions="groupTransactions"
|
||||
:loading="transactionLoading"
|
||||
@@ -92,7 +101,10 @@
|
||||
title="批量设置分类"
|
||||
height="60%"
|
||||
>
|
||||
<van-form ref="batchFormRef" class="setting-form">
|
||||
<van-form
|
||||
ref="batchFormRef"
|
||||
class="setting-form"
|
||||
>
|
||||
<van-cell-group inset>
|
||||
<!-- 显示选中的摘要 -->
|
||||
<van-field
|
||||
@@ -101,7 +113,7 @@
|
||||
readonly
|
||||
input-align="left"
|
||||
/>
|
||||
|
||||
|
||||
<!-- 显示记录数量 -->
|
||||
<van-field
|
||||
:model-value="`${batchGroup?.count || 0} 条`"
|
||||
@@ -111,24 +123,42 @@
|
||||
/>
|
||||
|
||||
<!-- 交易类型 -->
|
||||
<van-field name="type" label="交易类型">
|
||||
<van-field
|
||||
name="type"
|
||||
label="交易类型"
|
||||
>
|
||||
<template #input>
|
||||
<van-radio-group v-model="batchForm.type" direction="horizontal">
|
||||
<van-radio :name="0">支出</van-radio>
|
||||
<van-radio :name="1">收入</van-radio>
|
||||
<van-radio :name="2">不计</van-radio>
|
||||
<van-radio-group
|
||||
v-model="batchForm.type"
|
||||
direction="horizontal"
|
||||
>
|
||||
<van-radio :name="0">
|
||||
支出
|
||||
</van-radio>
|
||||
<van-radio :name="1">
|
||||
收入
|
||||
</van-radio>
|
||||
<van-radio :name="2">
|
||||
不计
|
||||
</van-radio>
|
||||
</van-radio-group>
|
||||
</template>
|
||||
</van-field>
|
||||
|
||||
<!-- 分类选择 -->
|
||||
<van-field name="classify" label="分类">
|
||||
<van-field
|
||||
name="classify"
|
||||
label="分类"
|
||||
>
|
||||
<template #input>
|
||||
<span v-if="!batchForm.classify" style="opacity: 0.4;">请选择分类</span>
|
||||
<span
|
||||
v-if="!batchForm.classify"
|
||||
style="opacity: 0.4"
|
||||
>请选择分类</span>
|
||||
<span v-else>{{ batchForm.classify }}</span>
|
||||
</template>
|
||||
</van-field>
|
||||
|
||||
|
||||
<!-- 分类选择组件 -->
|
||||
<ClassifySelector
|
||||
v-model="batchForm.classify"
|
||||
@@ -138,9 +168,9 @@
|
||||
</van-form>
|
||||
<template #footer>
|
||||
<van-button
|
||||
round
|
||||
block
|
||||
type="primary"
|
||||
round
|
||||
block
|
||||
type="primary"
|
||||
@click="handleConfirmBatchUpdate"
|
||||
>
|
||||
确定
|
||||
@@ -152,13 +182,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, onBeforeUnmount } from 'vue'
|
||||
import {
|
||||
showToast,
|
||||
showSuccessToast,
|
||||
showLoadingToast,
|
||||
closeToast,
|
||||
showConfirmDialog
|
||||
} from 'vant'
|
||||
import { showToast, showSuccessToast, showLoadingToast, closeToast, showConfirmDialog } from 'vant'
|
||||
import { getReasonGroups, batchUpdateByReason, getTransactionList } from '@/api/transactionRecord'
|
||||
import ClassifySelector from './ClassifySelector.vue'
|
||||
import TransactionList from './TransactionList.vue'
|
||||
@@ -212,9 +236,12 @@ const batchForm = ref({
|
||||
})
|
||||
|
||||
// 监听交易类型变化,重新加载分类
|
||||
watch(() => batchForm.value.type, (newVal) => {
|
||||
batchForm.value.classify = ''
|
||||
})
|
||||
watch(
|
||||
() => batchForm.value.type,
|
||||
(newVal) => {
|
||||
batchForm.value.classify = ''
|
||||
}
|
||||
)
|
||||
|
||||
// 获取类型名称
|
||||
const getTypeName = (type) => {
|
||||
@@ -256,8 +283,10 @@ const handleGroupClick = async (group) => {
|
||||
|
||||
// 加载分组的交易记录
|
||||
const loadGroupTransactions = async () => {
|
||||
if (transactionFinished.value || !selectedGroup.value) return
|
||||
|
||||
if (transactionFinished.value || !selectedGroup.value) {
|
||||
return
|
||||
}
|
||||
|
||||
transactionLoading.value = true
|
||||
try {
|
||||
const res = await getTransactionList({
|
||||
@@ -265,17 +294,17 @@ const loadGroupTransactions = async () => {
|
||||
pageIndex: transactionPageIndex.value,
|
||||
pageSize: transactionPageSize.value
|
||||
})
|
||||
|
||||
|
||||
if (res.success) {
|
||||
const newData = res.data || []
|
||||
groupTransactions.value = [...groupTransactions.value, ...newData]
|
||||
groupTransactionsTotal.value = res.total || 0
|
||||
|
||||
|
||||
// 判断是否还有更多数据
|
||||
if (newData.length < transactionPageSize.value) {
|
||||
transactionFinished.value = true
|
||||
}
|
||||
|
||||
|
||||
transactionPageIndex.value++
|
||||
} else {
|
||||
showToast(res.message || '获取交易记录失败')
|
||||
@@ -323,7 +352,7 @@ const handleConfirmBatchUpdate = async () => {
|
||||
try {
|
||||
// 表单验证
|
||||
await batchFormRef.value?.validate()
|
||||
|
||||
|
||||
// 二次确认
|
||||
await showConfirmDialog({
|
||||
title: '确认批量设置',
|
||||
@@ -352,21 +381,19 @@ const handleConfirmBatchUpdate = async () => {
|
||||
await refresh()
|
||||
// 通知父组件数据已更改
|
||||
emit('data-changed')
|
||||
try {
|
||||
try {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent(
|
||||
'transactions-changed',
|
||||
{
|
||||
detail: {
|
||||
reason: batchGroup.value.reason
|
||||
}
|
||||
})
|
||||
)
|
||||
} catch(e) {
|
||||
new CustomEvent('transactions-changed', {
|
||||
detail: {
|
||||
reason: batchGroup.value.reason
|
||||
}
|
||||
})
|
||||
)
|
||||
} catch (e) {
|
||||
console.error('触发全局 transactions-changed 事件失败:', e)
|
||||
}
|
||||
// 关闭弹窗
|
||||
showTransactionList.value = false
|
||||
}
|
||||
// 关闭弹窗
|
||||
showTransactionList.value = false
|
||||
} else {
|
||||
showToast(res.message || '批量更新失败')
|
||||
}
|
||||
@@ -398,18 +425,18 @@ const handleTransactionClick = (transaction) => {
|
||||
|
||||
// 处理分组中的删除事件
|
||||
const handleGroupTransactionDelete = async (transactionId) => {
|
||||
groupTransactions.value = groupTransactions.value.filter(t => t.id !== transactionId)
|
||||
groupTransactions.value = groupTransactions.value.filter((t) => t.id !== transactionId)
|
||||
groupTransactionsTotal.value = Math.max(0, (groupTransactionsTotal.value || 0) - 1)
|
||||
|
||||
if(groupTransactions.value.length === 0 && !transactionFinished.value) {
|
||||
if (groupTransactions.value.length === 0 && !transactionFinished.value) {
|
||||
// 如果当前页数据为空且未加载完,则尝试加载下一页
|
||||
await loadGroupTransactions()
|
||||
}
|
||||
|
||||
if(groupTransactions.value.length === 0){
|
||||
if (groupTransactions.value.length === 0) {
|
||||
// 如果删除后当前分组没有交易了,关闭弹窗
|
||||
showTransactionList.value = false
|
||||
groups.value = groups.value.filter(g => g.reason !== selectedGroup.value.reason)
|
||||
groups.value = groups.value.filter((g) => g.reason !== selectedGroup.value.reason)
|
||||
selectedGroup.value = null
|
||||
total.value--
|
||||
}
|
||||
@@ -433,10 +460,12 @@ const onGlobalTransactionDeleted = () => {
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener && window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
window.addEventListener &&
|
||||
window.addEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener && window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
window.removeEventListener &&
|
||||
window.removeEventListener('transaction-deleted', onGlobalTransactionDeleted)
|
||||
})
|
||||
|
||||
// 当有交易新增/修改/批量更新时的刷新监听
|
||||
@@ -451,10 +480,12 @@ const onGlobalTransactionsChanged = () => {
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener && window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
window.addEventListener &&
|
||||
window.addEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener && window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
window.removeEventListener &&
|
||||
window.removeEventListener('transactions-changed', onGlobalTransactionsChanged)
|
||||
})
|
||||
|
||||
// 处理账单保存后的回调
|
||||
@@ -471,8 +502,10 @@ const handleTransactionSaved = async () => {
|
||||
* 加载数据(支持分页)
|
||||
*/
|
||||
const loadData = async () => {
|
||||
if (finished.value) return
|
||||
|
||||
if (finished.value) {
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await getReasonGroups(pageIndex.value, props.pageSize)
|
||||
@@ -480,14 +513,14 @@ const loadData = async () => {
|
||||
const newData = res.data || []
|
||||
groups.value = [...groups.value, ...newData]
|
||||
total.value = res.total || 0
|
||||
|
||||
|
||||
// 判断是否还有更多数据
|
||||
if (groups.value.length >= total.value) {
|
||||
finished.value = true
|
||||
}
|
||||
|
||||
|
||||
pageIndex.value++
|
||||
|
||||
|
||||
emit('data-loaded', {
|
||||
groups: groups.value,
|
||||
total: total.value,
|
||||
@@ -522,7 +555,7 @@ const refresh = async () => {
|
||||
*/
|
||||
const getList = (onlySelected = false) => {
|
||||
if (onlySelected && props.selectable) {
|
||||
return groups.value.filter(g => selectedReasons.value.has(g.reason))
|
||||
return groups.value.filter((g) => selectedReasons.value.has(g.reason))
|
||||
}
|
||||
return [...groups.value]
|
||||
}
|
||||
@@ -564,7 +597,7 @@ const clearSelection = () => {
|
||||
* 全选
|
||||
*/
|
||||
const selectAll = () => {
|
||||
selectedReasons.value = new Set(groups.value.map(g => g.reason))
|
||||
selectedReasons.value = new Set(groups.value.map((g) => g.reason))
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
|
||||
Reference in New Issue
Block a user