feat: 添加分类名称更新功能,支持在交易记录中同步更新分类名称
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 23s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s

This commit is contained in:
2026-01-01 15:20:59 +08:00
parent c58404491f
commit 8c72102e87
6 changed files with 173 additions and 34 deletions

View File

@@ -13,10 +13,10 @@
>
<van-tabs v-model:active="activeTab" shrink>
<van-tab title="一句话录账" name="one">
<OneLineBillAdd @success="handleSuccess" />
<OneLineBillAdd :key="componentKey" @success="handleSuccess" />
</van-tab>
<van-tab title="手动录账" name="manual">
<ManualBillAdd @success="handleSuccess" />
<ManualBillAdd :key="componentKey" @success="handleSuccess" />
</van-tab>
</van-tabs>
</PopupContainer>
@@ -33,11 +33,15 @@ const emit = defineEmits(['success'])
const showAddBill = ref(false)
const activeTab = ref('one')
const componentKey = ref(0)
const openAddBill = () => {
showAddBill.value = true
// Reset to default tab if needed, or keep last used
// activeTab.value = 'one'
// 清理状态,默认选中一句话录账
activeTab.value = 'one'
// 清理子组件状态通过 key 强制重渲染
componentKey.value++
}
const handleSuccess = () => {
@@ -50,7 +54,7 @@ const handleSuccess = () => {
<style scoped>
.floating-add {
position: fixed;
bottom: 80px; /* Above tabbar */
bottom: 95px; /* Above tabbar */
right: 20px;
width: 50px;
height: 50px;

View File

@@ -41,7 +41,11 @@
<van-cell-group v-else inset>
<van-swipe-cell v-for="category in categories" :key="category.id">
<van-cell :title="category.name" />
<van-cell
:title="category.name"
is-link
@click="handleEdit(category)"
/>
<template #right>
<van-button
square
@@ -85,6 +89,24 @@
</van-form>
</van-dialog>
<!-- 编辑分类对话框 -->
<van-dialog
v-model:show="showEditDialog"
title="编辑分类"
show-cancel-button
@confirm="handleConfirmEdit"
>
<van-form ref="editFormRef">
<van-field
v-model="editForm.name"
name="name"
label="分类名称"
placeholder="请输入分类名称"
:rules="[{ required: true, message: '请输入分类名称' }]"
/>
</van-form>
</van-dialog>
<!-- 删除确认对话框 -->
<van-dialog
v-model:show="showDeleteConfirm"
@@ -108,7 +130,8 @@ import {
import {
getCategoryList,
createCategory,
deleteCategory
deleteCategory,
updateCategory
} from '@/api/transactionCategory'
const router = useRouter()
@@ -142,6 +165,14 @@ const addForm = ref({
const showDeleteConfirm = ref(false)
const deleteTarget = ref(null)
// 编辑对话框
const showEditDialog = ref(false)
const editFormRef = ref(null)
const editForm = ref({
id: 0,
name: ''
})
// 计算导航栏标题
const navTitle = computed(() => {
if (currentLevel.value === 0) {
@@ -251,6 +282,50 @@ const handleConfirmAdd = async () => {
}
}
/**
* 编辑分类
*/
const handleEdit = (category) => {
editForm.value = {
id: category.id,
name: category.name
}
showEditDialog.value = true
}
/**
* 确认编辑
*/
const handleConfirmEdit = async () => {
try {
await editFormRef.value?.validate()
showLoadingToast({
message: '保存中...',
forbidClick: true,
duration: 0
})
const { success, message } = await updateCategory({
id: editForm.value.id,
name: editForm.value.name
})
if (success) {
showSuccessToast('保存成功')
showEditDialog.value = false
await loadCategories()
} else {
showToast(message || '保存失败')
}
} catch (error) {
console.error('保存失败:', error)
showToast('保存失败: ' + (error.message || '未知错误'))
} finally {
closeToast()
}
}
/**
* 删除分类
*/

View File

@@ -57,18 +57,23 @@
</van-pull-refresh>
<!-- 详情弹出层 -->
<van-popup
v-model:show="detailVisible"
position="bottom"
:style="{ height: '80%' }"
round
closeable
<PopupContainer
v-model="detailVisible"
:title="currentEmail ? (currentEmail.Subject || currentEmail.subject || '(无主题)') : ''"
height="80%"
>
<div class="popup-container" v-if="currentEmail">
<div class="popup-header-fixed">
<h3>{{ currentEmail.Subject || currentEmail.subject || '(无主题)' }}</h3>
</div>
<div class="popup-scroll-content">
<template #header-actions>
<van-button
size="small"
type="primary"
:loading="refreshingAnalysis"
@click="handleRefreshAnalysis"
>
重新分析
</van-button>
</template>
<div v-if="currentEmail">
<van-cell-group inset style="margin-top: 12px;">
<van-cell title="发件人" :value="currentEmail.From || currentEmail.from || '未知'" />
<van-cell title="接收时间" :value="formatDate(currentEmail.ReceivedDate || currentEmail.receivedDate)" />
@@ -101,21 +106,8 @@
</div>
</div>
</div>
<div style="margin: 16px;">
<van-button
round
block
type="primary"
:loading="refreshingAnalysis"
@click="handleRefreshAnalysis"
>
重新分析
</van-button>
</div>
</div>
</div>
</van-popup>
</PopupContainer>
<!-- 账单列表弹出层 -->
<PopupContainer
@@ -343,6 +335,7 @@ const viewTransactions = async () => {
// 监听全局删除事件,保持弹窗内交易列表一致
const onGlobalTransactionDeleted = (e) => {
console.log('收到全局交易删除事件:', e)
// 如果交易列表弹窗打开,尝试重新加载邮箱的交易列表
if (transactionListVisible.value && currentEmail.value) {
const emailId = currentEmail.value.id || currentEmail.value.Id
@@ -362,6 +355,7 @@ onBeforeUnmount(() => {
// 监听新增/修改/批量更新事件,刷新弹窗内交易或邮件列表
const onGlobalTransactionsChanged = (e) => {
console.log('收到全局交易变更事件:', e)
if (transactionListVisible.value && currentEmail.value) {
const emailId = currentEmail.value.id || currentEmail.value.Id
getEmailTransactions(emailId).then(response => {
@@ -413,7 +407,12 @@ const handleTransactionDelete = (transactionId) => {
}
})
}
try { window.dispatchEvent(new CustomEvent('transaction-deleted', { detail: transactionId })) } catch(e) {}
try {
window.dispatchEvent(
new CustomEvent('transaction-deleted', { detail: transactionId }))
} catch(e) {
console.error(e)
}
}
// 账单保存后刷新列表
@@ -426,7 +425,18 @@ const handleTransactionSave = async () => {
transactionList.value = response.data || []
}
}
try { window.dispatchEvent(new CustomEvent('transactions-changed', { detail: { emailId: currentEmail.value?.id } })) } catch(e) {}
try {
window.dispatchEvent(
new CustomEvent(
'transactions-changed',
{
detail: {
emailId: currentEmail.value?.id
}
}))
} catch(e) {
console.error(e)
}
}
// 格式化日期