From 58ee44987bc44ffb7be63fdbbad4ff2a187a7ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Thu, 8 Jan 2026 14:41:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/BudgetRecord.cs | 12 +- Service/BudgetService.cs | 11 +- Web/src/components/Bill/BillForm.vue | 109 +------- Web/src/components/Budget/BudgetCard.vue | 4 +- Web/src/components/Budget/BudgetEditPopup.vue | 100 +------ Web/src/components/Budget/BudgetSummary.vue | 1 - .../components/Budget/SavingsConfigPopup.vue | 89 +------ Web/src/components/ClassifySelector.vue | 249 ++++++++++++++++++ Web/src/components/ReasonGroupList.vue | 126 +-------- Web/src/components/TransactionDetail.vue | 122 +-------- Web/src/constants/enums.js | 4 +- Web/src/views/BudgetView.vue | 78 +++--- Web/src/views/PeriodicRecord.vue | 116 +------- WebApi/Controllers/BudgetController.cs | 2 - WebApi/Controllers/Dto/BudgetDto.cs | 2 - 15 files changed, 353 insertions(+), 672 deletions(-) create mode 100644 Web/src/components/ClassifySelector.vue diff --git a/Entity/BudgetRecord.cs b/Entity/BudgetRecord.cs index d7289e0..83a1f06 100644 --- a/Entity/BudgetRecord.cs +++ b/Entity/BudgetRecord.cs @@ -43,22 +43,14 @@ public class BudgetRecord : BaseEntity public enum BudgetPeriodType { - /// - /// 周 - /// - Week, /// /// 月 /// - Month, + Month = 1, /// /// 年 /// - Year, - /// - /// 长期 - /// - Longterm + Year = 2 } public enum BudgetCategory diff --git a/Service/BudgetService.cs b/Service/BudgetService.cs index c9ba9a3..40f1833 100644 --- a/Service/BudgetService.cs +++ b/Service/BudgetService.cs @@ -61,19 +61,10 @@ public class BudgetService( public static (DateTime start, DateTime end) GetPeriodRange(DateTime startDate, BudgetPeriodType type, DateTime referenceDate) { - if (type == BudgetPeriodType.Longterm) return (startDate, DateTime.MaxValue); - DateTime start; DateTime end; - if (type == BudgetPeriodType.Week) - { - var daysFromStart = (referenceDate.Date - startDate.Date).Days; - var weeksFromStart = daysFromStart / 7; - start = startDate.Date.AddDays(weeksFromStart * 7); - end = start.AddDays(6).AddHours(23).AddMinutes(59).AddSeconds(59); - } - else if (type == BudgetPeriodType.Month) + if (type == BudgetPeriodType.Month) { start = new DateTime(referenceDate.Year, referenceDate.Month, 1); end = start.AddMonths(1).AddDays(-1).AddHours(23).AddMinutes(59).AddSeconds(59); diff --git a/Web/src/components/Bill/BillForm.vue b/Web/src/components/Bill/BillForm.vue index 5d4fbd6..aa8259d 100644 --- a/Web/src/components/Bill/BillForm.vue +++ b/Web/src/components/Bill/BillForm.vue @@ -52,27 +52,11 @@ - -
- - + 新增 - - - {{ item.name }} - -
+ +
@@ -83,12 +67,6 @@
- - - { if (reason !== undefined) form.value.note = reason if (type !== undefined) form.value.type = type - // 加载分类列表 - await loadClassifyList(form.value.type) - - // 如果有传入分类名称,尝试匹配 + // 如果有传入分类名称,尝试设置 if (classify) { - const found = categoryList.value.find(c => c.name === classify) - if (found) { - selectClassify(found) - } else { - // 如果没找到对应分类,但有分类名称,可能需要特殊处理或者就显示名称但不关联ID? - // 这里暂时只显示名称,ID为空,或者需要自动创建? - // 按照原有逻辑,后端需要分类名称,所以这里只要设置 categoryName 即可 - // 但是 ManualBillAdd 原逻辑是需要 categoryId 的。 - // 不过 createTransaction 接口传的是 classify (name)。 - // 让我们看 ManualBillAdd 的 handleSave: - // classify: categoryName.value - // 所以只要 categoryName 有值就行。 - categoryName.value = classify - } + categoryName.value = classify } - } else { - await loadClassifyList(form.value.type) } } @@ -213,50 +166,6 @@ watch(() => props.initialData, () => { const handleTypeChange = (newType) => { categoryName.value = '' - form.value.categoryId = null - loadClassifyList(newType) -} - -const loadClassifyList = async (type = null) => { - try { - const response = await getCategoryList(type) - if (response.success) { - categoryList.value = response.data || [] - } - } catch (error) { - console.error('加载分类列表出错:', error) - } -} - -const selectClassify = (item) => { - categoryName.value = item.name - form.value.categoryId = item.id -} - -const handleAddClassify = async (name) => { - try { - // 调用API创建分类 - const response = await createCategory({ - name: name, - type: form.value.type - }) - - if (response.success) { - showToast('分类创建成功') - const newId = response.data - // 重新加载分类列表 - await loadClassifyList(form.value.type) - - // 选中新创建的分类 - categoryName.value = name - form.value.categoryId = newId - } else { - showToast(response.message || '创建分类失败') - } - } catch (error) { - console.error('创建分类出错:', error) - showToast('创建分类失败') - } } const onConfirmDate = ({ selectedValues }) => { diff --git a/Web/src/components/Budget/BudgetCard.vue b/Web/src/components/Budget/BudgetCard.vue index b3452dd..2c61669 100644 --- a/Web/src/components/Budget/BudgetCard.vue +++ b/Web/src/components/Budget/BudgetCard.vue @@ -41,7 +41,7 @@ {{ percentage }}% -
+
时间进度 { }) const timePercentage = computed(() => { - if (!props.budget.periodStart || !props.budget.periodEnd || props.budget.type === BudgetPeriodType.Longterm) return 0 + if (!props.budget.periodStart || !props.budget.periodEnd) return 0 const start = new Date(props.budget.periodStart).getTime() const end = new Date(props.budget.periodEnd).getTime() const now = new Date().getTime() diff --git a/Web/src/components/Budget/BudgetEditPopup.vue b/Web/src/components/Budget/BudgetEditPopup.vue index a02fa25..11b6b12 100644 --- a/Web/src/components/Budget/BudgetEditPopup.vue +++ b/Web/src/components/Budget/BudgetEditPopup.vue @@ -17,7 +17,6 @@ -
- - {{ isAllSelected ? '取消全选' : '全选' }} - - - {{ item.name }} - -
暂无分类
-
- +
@@ -78,19 +61,18 @@ diff --git a/Web/src/components/Budget/BudgetSummary.vue b/Web/src/components/Budget/BudgetSummary.vue index 15c44cb..aec0ba3 100644 --- a/Web/src/components/Budget/BudgetSummary.vue +++ b/Web/src/components/Budget/BudgetSummary.vue @@ -30,7 +30,6 @@ const props = defineProps({ }) const periodConfigs = { - week: { label: '本周', showDivider: true }, month: { label: '本月', showDivider: true }, year: { label: '年度', showDivider: false } } diff --git a/Web/src/components/Budget/SavingsConfigPopup.vue b/Web/src/components/Budget/SavingsConfigPopup.vue index 8c429fc..00c408a 100644 --- a/Web/src/components/Budget/SavingsConfigPopup.vue +++ b/Web/src/components/Budget/SavingsConfigPopup.vue @@ -11,29 +11,13 @@
可多选分类
-
- - {{ isAllSelected ? '取消全选' : '全选' }} - - - {{ item.name }} - -
暂无收入分类
-
+
@@ -44,21 +28,19 @@ + + diff --git a/Web/src/components/ReasonGroupList.vue b/Web/src/components/ReasonGroupList.vue index be19df4..88167d2 100644 --- a/Web/src/components/ReasonGroupList.vue +++ b/Web/src/components/ReasonGroupList.vue @@ -129,36 +129,11 @@ - -
- - + 新增 - - - {{ item.text }} - - - 清空 - -
+ + - - - @@ -191,8 +160,7 @@ import { showConfirmDialog } from 'vant' import { getReasonGroups, batchUpdateByReason, getTransactionList } from '@/api/transactionRecord' -import { getCategoryList, createCategory } from '@/api/transactionCategory' -import AddClassifyDialog from './AddClassifyDialog.vue' +import ClassifySelector from './ClassifySelector.vue' import TransactionList from './TransactionList.vue' import TransactionDetail from './TransactionDetail.vue' import PopupContainer from './PopupContainer.vue' @@ -219,8 +187,6 @@ const selectedReasons = ref(new Set()) const pageIndex = ref(1) const finished = ref(false) const total = ref(0) -const categories = ref([]) - // 弹窗状态 const showTransactionList = ref(false) const showTransactionDetail = ref(false) @@ -239,27 +205,15 @@ const transactionPageSize = ref(20) const showBatchDialog = ref(false) const batchFormRef = ref(null) const batchGroup = ref(null) -const addClassifyDialogRef = ref() const batchForm = ref({ type: null, typeName: '', classify: '' }) -// 根据选中的类型过滤分类选项 -const classifyOptions = computed(() => { - if (batchForm.value.type === null) return [] - return categories.value - .filter(c => c.type === batchForm.value.type) - .map(c => ({ text: c.name, value: c.name, id: c.id })) -}) - // 监听交易类型变化,重新加载分类 watch(() => batchForm.value.type, (newVal) => { batchForm.value.classify = '' - if (newVal !== null) { - loadCategories(newVal) - } }) // 获取类型名称 @@ -361,62 +315,9 @@ const handleBatchClassify = (group) => { typeName: getTypeName(group.sampleType), classify: group.sampleClassify || '' } - // 加载对应类型的分类列表 - loadCategories(group.sampleType) showBatchDialog.value = true } -// 获取所有分类 -const loadCategories = async (type = null) => { - try { - const res = await getCategoryList(type) - if (res.success) { - categories.value = res.data || [] - } - } catch (error) { - console.error('获取分类列表失败:', error) - } -} - -// 选择分类 -const selectClassify = (classify) => { - batchForm.value.classify = classify -} - -// 新增分类 -const handleAddClassify = async (categoryName) => { - if (batchForm.value.type === null) { - showToast('请先选择交易类型') - return - } - - try { - // 调用API创建分类 - const response = await createCategory({ - name: categoryName, - type: batchForm.value.type - }) - - if (response.success) { - showToast('分类创建成功') - // 重新加载分类列表 - await loadCategories(batchForm.value.type) - batchForm.value.classify = categoryName - } else { - showToast(response.message || '创建分类失败') - } - } catch (error) { - console.error('创建分类出错:', error) - showToast('创建分类失败') - } -} - -// 清空分类 -const clearClassify = () => { - batchForm.value.classify = '' - showToast('已清空分类') -} - // 确认批量更新 const handleConfirmBatchUpdate = async () => { try { @@ -744,20 +645,5 @@ defineExpose({ padding: 16px 0; } -.classify-buttons { - display: flex; - flex-wrap: wrap; - gap: 8px; - padding: 12px 16px; - max-height: 300px; - overflow-y: auto; -} - -.classify-btn { - flex: 0 0 auto; - min-width: 70px; - border-radius: 16px; -} - /* 交易列表弹窗 - 自定义样式 */ diff --git a/Web/src/components/TransactionDetail.vue b/Web/src/components/TransactionDetail.vue index cb9ddcd..ead8700 100644 --- a/Web/src/components/TransactionDetail.vue +++ b/Web/src/components/TransactionDetail.vue @@ -61,36 +61,12 @@ - -
- - + 新增 - - - {{ item.text }} - - - 清空 - -
+ + @@ -107,12 +83,6 @@ - - - props.transaction, (newVal) => { editForm.balance = String(newVal.balance) editForm.type = newVal.type editForm.classify = newVal.classify || '' - - // 根据交易类型加载分类 - loadClassifyList(newVal.type) } }) @@ -200,26 +162,8 @@ watch(visible, (newVal) => { watch(() => editForm.type, (newVal) => { // 清空已选的分类 editForm.classify = '' - // 重新加载对应类型的分类列表 - loadClassifyList(newVal) }) -// 加载分类列表 -const loadClassifyList = async (type = null) => { - try { - const response = await getCategoryList(type) - if (response.success) { - classifyColumns.value = (response.data || []).map(item => ({ - text: item.name, - value: item.name, - id: item.id - })) - } - } catch (error) { - console.error('加载分类列表出错:', error) - } -} - // 提交编辑 const onSubmit = async () => { try { @@ -239,8 +183,6 @@ const onSubmit = async () => { showToast('保存成功') visible.value = false emit('save', data) - // 重新加载分类列表 - await loadClassifyList(editForm.type) } else { showToast(response.message || '保存失败') } @@ -252,47 +194,15 @@ const onSubmit = async () => { } } -// 选择分类 -const selectClassify = (classify) => { - editForm.classify = classify - - if(editForm.id > 0 && editForm.type >= 0) { +// 分类选择变化 +const handleClassifyChange = () => { + if (editForm.id > 0 && editForm.type >= 0) { // 直接保存 onSubmit() } - -} - -// 新增分类 -const handleAddClassify = async (categoryName) => { - try { - // 调用API创建分类 - const response = await createCategory({ - name: categoryName, - type: editForm.type - }) - - if (response.success) { - showToast('分类创建成功') - // 重新加载分类列表 - await loadClassifyList(editForm.type) - editForm.classify = categoryName - } else { - showToast(response.message || '创建分类失败') - } - } catch (error) { - console.error('创建分类出错:', error) - showToast('创建分类失败') - } } // 清空分类 -const clearClassify = () => { - editForm.classify = '' - showToast('已清空分类') -} - -// 格式化日期 const formatDate = (dateString) => { if (!dateString) return '' const date = new Date(dateString) @@ -352,16 +262,4 @@ const handleCandidateSelect = (candidate) => { diff --git a/Web/src/constants/enums.js b/Web/src/constants/enums.js index 6d152a0..46b3b87 100644 --- a/Web/src/constants/enums.js +++ b/Web/src/constants/enums.js @@ -2,10 +2,8 @@ * 预算周期类型 */ export const BudgetPeriodType = { - Week: 0, Month: 1, - Year: 2, - Longterm: 3 + Year: 2 } /** diff --git a/Web/src/views/BudgetView.vue b/Web/src/views/BudgetView.vue index d2c37cb..5e34d1d 100644 --- a/Web/src/views/BudgetView.vue +++ b/Web/src/views/BudgetView.vue @@ -17,15 +17,16 @@ -
-
- - - + + + + +
+ +
+
- -
+
+