feat: 优化预算管理界面,增强预算编辑功能,添加预算删除接口
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 24s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 1s

This commit is contained in:
孙诚
2026-01-07 19:19:53 +08:00
parent 851886a601
commit 35a856c6e3
5 changed files with 267 additions and 134 deletions

View File

@@ -1,8 +1,8 @@
<template>
<PopupContainer
v-model="visible"
:title="isEdit ? '编辑预算' : '新增预算'"
height="70%"
:title="isEdit ? `编辑${getCategoryName(form.category)}预算` : `新增${getCategoryName(form.category)}预算`"
height="85%"
>
<div class="add-budget-form">
<van-form>
@@ -20,7 +20,6 @@
<van-radio :name="BudgetPeriodType.Week"></van-radio>
<van-radio :name="BudgetPeriodType.Month"></van-radio>
<van-radio :name="BudgetPeriodType.Year"></van-radio>
<van-radio :name="BudgetPeriodType.Longterm">长期</van-radio>
</van-radio-group>
</template>
</van-field>
@@ -36,15 +35,6 @@
<span></span>
</template>
</van-field>
<van-field name="category" label="类型">
<template #input>
<van-radio-group v-model="form.category" direction="horizontal" :disabled="isEdit">
<van-radio :name="BudgetCategory.Expense">支出</van-radio>
<van-radio :name="BudgetCategory.Income">收入</van-radio>
<van-radio :name="BudgetCategory.Savings">存款</van-radio>
</van-radio-group>
</template>
</van-field>
<van-field label="相关分类">
<template #input>
<div v-if="form.selectedCategories.length === 0" style="color: #c8c9cc;">可多选分类</div>
@@ -95,17 +85,10 @@ import { createBudget, updateBudget } from '@/api/budget'
import { BudgetPeriodType, BudgetCategory } from '@/constants/enums'
import PopupContainer from '@/components/PopupContainer.vue'
const props = defineProps({
editData: {
type: Object,
default: null
}
})
const emit = defineEmits(['success'])
const visible = ref(false)
const isEdit = computed(() => !!props.editData)
const isEdit = ref(false)
const categories = ref([])
const form = reactive({
@@ -117,13 +100,23 @@ const form = reactive({
selectedCategories: []
})
const open = (data = null) => {
const open = ({
data,
isEditFlag,
category
}) => {
if(category === undefined) {
showToast('缺少必要参数category')
return
}
isEdit.value = isEditFlag
if (data) {
Object.assign(form, {
id: data.id,
name: data.name,
type: data.type,
category: data.category,
category: category,
limit: data.limit,
selectedCategories: data.selectedCategories ? [...data.selectedCategories] : []
})
@@ -132,7 +125,7 @@ const open = (data = null) => {
id: undefined,
name: '',
type: BudgetPeriodType.Month,
category: BudgetCategory.Expense,
category: category,
limit: '',
selectedCategories: []
})
@@ -199,18 +192,30 @@ const onSubmit = async () => {
}
const res = form.id ? await updateBudget(data) : await createBudget(data)
if (res.success) {
showToast('保存成功')
visible.value = false
emit('success')
}
} catch (err) {
showToast('保存失败')
showToast(err.message || '保存失败')
console.error('保存预算失败', err)
}
}
const getCategoryName = (category) => {
switch(category) {
case BudgetCategory.Expense:
return '支出'
case BudgetCategory.Income:
return '收入'
case BudgetCategory.Savings:
return '存款'
default:
return ''
}
}
onMounted(() => {
fetchCategories()
})
@@ -243,7 +248,6 @@ onMounted(() => {
flex-wrap: wrap;
gap: 8px;
padding: 12px 16px;
max-height: 200px;
overflow-y: auto;
}