From 26ff2381b7225fb13aec008972491a3f66061e48 Mon Sep 17 00:00:00 2001 From: oneao Date: Thu, 5 Mar 2026 22:24:22 +0800 Subject: [PATCH] u --- .../allapp-go/api/handler/finance/record.go | 12 +- code/allapp/allapp-go/api/types/finance.go | 4 +- .../allapp-go/db/queries/finance_record.sql | 6 +- .../allapp-go/db/repo/finance_record.sql.go | 6 +- code/allapp/allapp-rn/app.json | 1 + code/allapp/allapp-rn/package.json | 5 +- code/allapp/allapp-rn/pnpm-lock.yaml | 22 +- .../src/app/(tabs)/finance/index.tsx | 51 ++- .../allapp/allapp-rn/src/app/(tabs)/index.tsx | 27 +- code/allapp/allapp-rn/src/app/+not-found.tsx | 2 +- .../src/app/finance/analysis/index.tsx | 285 ++++++++++++++ .../editor/components/AmountKeyboard.tsx | 27 +- .../src/app/finance/record/editor/index.tsx | 3 +- .../components/common/ao/DateMorePicker.tsx | 20 +- .../src/components/common/ao/DatePicker.tsx | 64 +--- .../allapp-rn/src/types/finance/record.ts | 4 +- code/allapp/allapp-rn/test.html | 362 ++++++++++-------- 17 files changed, 596 insertions(+), 305 deletions(-) create mode 100644 code/allapp/allapp-rn/src/app/finance/analysis/index.tsx diff --git a/code/allapp/allapp-go/api/handler/finance/record.go b/code/allapp/allapp-go/api/handler/finance/record.go index 493249f6..8e77fc02 100644 --- a/code/allapp/allapp-go/api/handler/finance/record.go +++ b/code/allapp/allapp-go/api/handler/finance/record.go @@ -51,14 +51,22 @@ func ListFinanceRecords(c fiber.Ctx) error { endTime = &t } - categoryId := dto.CategoryId + var categoryId int64 = -1 + if dto.CategoryId != nil { + categoryId = *dto.CategoryId + } + + var categoryType int16 = -1 + if dto.CategoryType != nil { + categoryType = *dto.CategoryType + } records, err := db.Queries.ListFinanceRecords(c.Context(), repo.ListFinanceRecordsParams{ SpaceID: spaceID, RecordTime: pgtypex.TimePtrToPgDate(startTime), RecordTime_2: pgtypex.TimePtrToPgDate(endTime), Column4: categoryId, - Column5: dto.CategoryType, + Column5: categoryType, }) if err != nil { diff --git a/code/allapp/allapp-go/api/types/finance.go b/code/allapp/allapp-go/api/types/finance.go index 7f51fcfc..db9a9c7e 100644 --- a/code/allapp/allapp-go/api/types/finance.go +++ b/code/allapp/allapp-go/api/types/finance.go @@ -65,8 +65,8 @@ type FinanceRecord struct { type ListFinanceRecordsDTO struct { StartTime string `json:"start_time"` EndTime string `json:"end_time"` - CategoryId int64 `json:"category_id"` - CategoryType int16 `json:"category_type"` + CategoryId *int64 `json:"category_id"` + CategoryType *int16 `json:"category_type"` } type ListFinanceRecordsVO struct { diff --git a/code/allapp/allapp-go/db/queries/finance_record.sql b/code/allapp/allapp-go/db/queries/finance_record.sql index 2b555bac..f2387161 100644 --- a/code/allapp/allapp-go/db/queries/finance_record.sql +++ b/code/allapp/allapp-go/db/queries/finance_record.sql @@ -9,9 +9,9 @@ FROM finance_record fr WHERE fr.space_id = $1 AND fr.record_time >= $2 - AND fr.record_time < $3 - AND fr.category_id = COALESCE(NULLIF($4::bigint, 0), fr.category_id) - AND fcs.type = COALESCE(NULLIF($5::smallint, 0), fcs.type) + AND fr.record_time <= $3 + AND ($4::bigint = -1 OR fr.category_id = $4) + AND ($5::smallint = -1 OR fcs.type = $5) ORDER BY fr.record_time DESC, fr.create_time DESC; diff --git a/code/allapp/allapp-go/db/repo/finance_record.sql.go b/code/allapp/allapp-go/db/repo/finance_record.sql.go index 1642daa5..faf0fdf1 100644 --- a/code/allapp/allapp-go/db/repo/finance_record.sql.go +++ b/code/allapp/allapp-go/db/repo/finance_record.sql.go @@ -123,9 +123,9 @@ FROM finance_record fr WHERE fr.space_id = $1 AND fr.record_time >= $2 - AND fr.record_time < $3 - AND fr.category_id = COALESCE(NULLIF($4::bigint, 0), fr.category_id) - AND fcs.type = COALESCE(NULLIF($5::smallint, 0), fcs.type) + AND fr.record_time <= $3 + AND ($4::bigint = -1 OR fr.category_id = $4) + AND ($5::smallint = -1 OR fcs.type = $5) ORDER BY fr.record_time DESC, fr.create_time DESC diff --git a/code/allapp/allapp-rn/app.json b/code/allapp/allapp-rn/app.json index 26c0d9f3..1b126b3e 100644 --- a/code/allapp/allapp-rn/app.json +++ b/code/allapp/allapp-rn/app.json @@ -32,6 +32,7 @@ "web": { "favicon": "./assets/favicon.png" }, + "plugins": [ "./plugins/withAndroidSignature", "expo-router", diff --git a/code/allapp/allapp-rn/package.json b/code/allapp/allapp-rn/package.json index 1c56b96c..c6ca2b2e 100644 --- a/code/allapp/allapp-rn/package.json +++ b/code/allapp/allapp-rn/package.json @@ -4,8 +4,8 @@ "private": true, "main": "expo-router/entry", "scripts": { - "start": "expo start", - "android": "expo run:android", + "start": "expo start --port 8088", + "android": "expo run:android --port 8088", "ios": "expo run:ios", "web": "expo start --web" }, @@ -46,6 +46,7 @@ "react-native": "0.81.5", "react-native-css-interop": "^0.2.1", "react-native-drawer-layout": "^4.2.0", + "react-native-enriched": "^0.5.1", "react-native-gesture-handler": "~2.28.0", "react-native-keyboard-controller": "1.18.5", "react-native-pager-view": "6.9.1", diff --git a/code/allapp/allapp-rn/pnpm-lock.yaml b/code/allapp/allapp-rn/pnpm-lock.yaml index 47f683bc..7aee9cb6 100644 --- a/code/allapp/allapp-rn/pnpm-lock.yaml +++ b/code/allapp/allapp-rn/pnpm-lock.yaml @@ -116,6 +116,9 @@ importers: react-native-drawer-layout: specifier: ^4.2.0 version: 4.2.0(react-native-gesture-handler@2.28.0(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0))(react-native-reanimated@4.1.5(@babel/core@7.28.5)(react-native-worklets@0.5.1(@babel/core@7.28.5)(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0))(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0))(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0) + react-native-enriched: + specifier: ^0.5.1 + version: 0.5.1(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0) react-native-gesture-handler: specifier: ~2.28.0 version: 2.28.0(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0) @@ -4129,56 +4132,48 @@ packages: engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] - libc: [glibc] lightningcss-linux-arm64-gnu@1.30.2: resolution: {integrity: sha512-UK65WJAbwIJbiBFXpxrbTNArtfuznvxAJw4Q2ZGlU8kPeDIWEX1dg3rn2veBVUylA2Ezg89ktszWbaQnxD/e3A==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] - libc: [glibc] lightningcss-linux-arm64-musl@1.27.0: resolution: {integrity: sha512-rCGBm2ax7kQ9pBSeITfCW9XSVF69VX+fm5DIpvDZQl4NnQoMQyRwhZQm9pd59m8leZ1IesRqWk2v/DntMo26lg==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] - libc: [musl] lightningcss-linux-arm64-musl@1.30.2: resolution: {integrity: sha512-5Vh9dGeblpTxWHpOx8iauV02popZDsCYMPIgiuw97OJ5uaDsL86cnqSFs5LZkG3ghHoX5isLgWzMs+eD1YzrnA==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] - libc: [musl] lightningcss-linux-x64-gnu@1.27.0: resolution: {integrity: sha512-Dk/jovSI7qqhJDiUibvaikNKI2x6kWPN79AQiD/E/KeQWMjdGe9kw51RAgoWFDi0coP4jinaH14Nrt/J8z3U4A==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] - libc: [glibc] lightningcss-linux-x64-gnu@1.30.2: resolution: {integrity: sha512-Cfd46gdmj1vQ+lR6VRTTadNHu6ALuw2pKR9lYq4FnhvgBc4zWY1EtZcAc6EffShbb1MFrIPfLDXD6Xprbnni4w==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] - libc: [glibc] lightningcss-linux-x64-musl@1.27.0: resolution: {integrity: sha512-QKjTxXm8A9s6v9Tg3Fk0gscCQA1t/HMoF7Woy1u68wCk5kS4fR+q3vXa1p3++REW784cRAtkYKrPy6JKibrEZA==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] - libc: [musl] lightningcss-linux-x64-musl@1.30.2: resolution: {integrity: sha512-XJaLUUFXb6/QG2lGIW6aIk6jKdtjtcffUT0NKvIqhSBY3hh9Ch+1LCeH80dR9q9LBjG3ewbDjnumefsLsP6aiA==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] - libc: [musl] lightningcss-win32-arm64-msvc@1.27.0: resolution: {integrity: sha512-/wXegPS1hnhkeG4OXQKEMQeJd48RDC3qdh+OA8pCuOPCyvnm/yEayrJdJVqzBsqpy1aJklRCVxscpFur80o6iQ==} @@ -5023,6 +5018,12 @@ packages: react-native-gesture-handler: '>= 2.0.0' react-native-reanimated: '>= 2.0.0' + react-native-enriched@0.5.1: + resolution: {integrity: sha512-MYwTVRBIkAl6fOosCBE26wFgNgk/2sOX7r+qnvDirsuecJ6H+6Zz4rHP5LnLFLDPZIon+lEQyZoWIdoEsGCZtw==} + peerDependencies: + react: '*' + react-native: '*' + react-native-gesture-handler@2.28.0: resolution: {integrity: sha512-0msfJ1vRxXKVgTgvL+1ZOoYw3/0z1R+Ked0+udoJhyplC2jbVKIJ8Z1bzWdpQRCV3QcQ87Op0zJVE5DhKK2A0A==} peerDependencies: @@ -12233,6 +12234,11 @@ snapshots: react-native-reanimated: 4.1.5(@babel/core@7.28.5)(react-native-worklets@0.5.1(@babel/core@7.28.5)(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0))(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0) use-latest-callback: 0.2.6(react@19.1.0) + react-native-enriched@0.5.1(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0): + dependencies: + react: 19.1.0 + react-native: 0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0) + react-native-gesture-handler@2.28.0(react-native@0.81.5(@babel/core@7.28.5)(@types/react@19.1.17)(react@19.1.0))(react@19.1.0): dependencies: '@egjs/hammerjs': 2.0.17 diff --git a/code/allapp/allapp-rn/src/app/(tabs)/finance/index.tsx b/code/allapp/allapp-rn/src/app/(tabs)/finance/index.tsx index 260726c5..1761f2e0 100644 --- a/code/allapp/allapp-rn/src/app/(tabs)/finance/index.tsx +++ b/code/allapp/allapp-rn/src/app/(tabs)/finance/index.tsx @@ -1,11 +1,11 @@ import type { DateMorePickerMode } from '@/components/common/ao/DateMorePicker' import type { FinanceCategory } from '@/types/finance/category' import { useFocusEffect, useRouter } from 'expo-router' -import React, { useCallback, useEffect, useState } from 'react' +import React, { useCallback, useState } from 'react' import { Image, Text, TouchableOpacity, View } from 'react-native' import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context' import { toast } from 'sonner-native' -import { ADateMorePicker, ADatePicker, ADrawer, AListItem, LucideIcon } from '@/components/common/ao' +import { ADateMorePicker, ADrawer, AListItem, LucideIcon } from '@/components/common/ao' import { resolveDateRange } from '@/components/common/ao/DateMorePicker' import { Fab, FabIcon } from '@/components/ui/fab' import { AddIcon } from '@/components/ui/icon' @@ -45,18 +45,32 @@ export default function Money() { function fetchFinanceRecords() { const resolveDate = resolveDateRange(dateMode, searchParams.startTime) - let searchType = 0 + let searchType: number | null = 0 + let searchId: number | null = 0 if (searchParams.category) { - if (searchParams.category.id === -1 || searchParams.category.id === -2) { + if (searchParams.category.id === 0) { + searchId = null + searchType = null + } + else if (searchParams.category.id === -1 || searchParams.category.id === -2) { + searchId = null searchType = searchParams.category.type } + else { + searchId = searchParams.category.id + searchType = null + } + } + else { + searchId = null + searchType = null } listFinanceRecordsApi({ start_time: resolveDate.startTime, end_time: resolveDate.endTime, - category_id: searchParams.category ? searchParams.category.id : 0, + category_id: searchId, category_type: searchType, }).then((res) => { if (res.isSuccess) { @@ -92,7 +106,7 @@ export default function Money() { function timeModeTip() { if (dateMode === 'unlimited') { - return '全部' + return '全部时间' } else if (dateMode === 'range') { return `${searchParams.startTime} - ${searchParams.endTime}` @@ -135,21 +149,21 @@ export default function Money() { > { - searchParams.category ? searchParams.category.name : '分类' + searchParams.category ? searchParams.category.name : '全部分类' } - { setShowActionsMenu(true) }} > - + */} - {/* { - setSearchParams({ - ...searchParams, - record_time: val, - }) - setShowDatePicker(false) - }} - onClose={() => { - setShowDatePicker(false) - }} - /> */} - + {/* { @@ -328,7 +327,7 @@ export default function Money() { - + */} ) } diff --git a/code/allapp/allapp-rn/src/app/(tabs)/index.tsx b/code/allapp/allapp-rn/src/app/(tabs)/index.tsx index 4fe80fcc..66a905bf 100644 --- a/code/allapp/allapp-rn/src/app/(tabs)/index.tsx +++ b/code/allapp/allapp-rn/src/app/(tabs)/index.tsx @@ -2,9 +2,10 @@ import { useRouter } from 'expo-router' import { Image, Text, View } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { AButton } from '@/components/common/ao' +import { useNavStore } from '@/store/navigation' export default function Index() { - const router = useRouter() + const navStore = useNavStore() return ( @@ -24,28 +25,14 @@ export default function Index() { 记录生活,记录情绪 - {/* ('/finance')} + onPress={() => { + navStore.navigateTo('finance/index') + }} > 开始使用 - */} - - ('/finance')} - > - 创建空间 - - ('/finance')} - > - 加入空间 - - - + ) diff --git a/code/allapp/allapp-rn/src/app/+not-found.tsx b/code/allapp/allapp-rn/src/app/+not-found.tsx index 696b40b5..69ccb36d 100644 --- a/code/allapp/allapp-rn/src/app/+not-found.tsx +++ b/code/allapp/allapp-rn/src/app/+not-found.tsx @@ -11,7 +11,7 @@ export default function NotFound() { title="(´・ω・`) 页面走丢了~" description="回首页看看吧!" footer={( - router.replace('/')}> + router.navigate('/finance')}> 返回应用首页 )} diff --git a/code/allapp/allapp-rn/src/app/finance/analysis/index.tsx b/code/allapp/allapp-rn/src/app/finance/analysis/index.tsx new file mode 100644 index 00000000..14bf0e1e --- /dev/null +++ b/code/allapp/allapp-rn/src/app/finance/analysis/index.tsx @@ -0,0 +1,285 @@ +import type { AnalysisMoneyAmount } from '@/types/money/analysis' +import dayjs from 'dayjs' +import { useEffect, useState } from 'react' +import { ScrollView, Text, TouchableOpacity, View } from 'react-native' +import { VictoryChart, VictoryLabel, VictoryLine, VictoryPie, VictoryTheme, VictoryTooltip } from 'victory-native' +import { ADatePicker, ADateRangePicker, ASegmentedTabs, LucideIcon } from '@/components/common/ao' +import EmptyState from '@/components/common/EmptyStatus' +import CustomHeader from '@/components/custom/Header' +import PagerTabs from '@/components/custom/PagerTabs' +import { analysisMoneyLineApi, analysisMoneyPieApi } from '@/request/api/money/analysis' +import { MoneyCategoryEnum } from '@/types/money/category' +import { add } from '@/utils/math' +import { getCurrentYear, getCurrentYearMonth, getEndOfMonth, getStartOfMonth } from '@/utils/time' + +interface AnalysisContentProps { + analysisType: MoneyCategoryEnum +} + +export default function Analysis() { + function AnalysisContent({ analysisType }: AnalysisContentProps) { + // 按月0 按年1 自定义2 + const [timeType, setTimeType] = useState(0) + + // 开始结束时间 + const [startDate, setStartDate] = useState(getCurrentYearMonth()) + const [endDate, setEndDate] = useState('') + + // 显示 + const [showDatePicker, setShowDatePicker] = useState(false) + + // 数据 + const [lineRecords, setLineRecords] = useState([]) + const [pieRecords, setPieRecords] = useState([]) + + // 请求 + function fetchChartsData() { + let start = '' + let end = '' + + const selectedStartDate = dayjs(startDate) + const selectedEndDate = dayjs(endDate) + + let periodType = 0 + + if (timeType === 0) { + start = selectedStartDate.startOf('month').format('YYYY-MM-DD') + end = selectedStartDate.endOf('month').format('YYYY-MM-DD') + + periodType = 0 + } + else if (timeType === 1) { + start = selectedStartDate.startOf('year').format('YYYY-MM-DD') + end = selectedStartDate.endOf('year').format('YYYY-MM-DD') + + periodType = 1 + } + else { + if (selectedStartDate.isSame(selectedEndDate, 'month')) { + periodType = 0 + start = selectedStartDate.startOf('month').format('YYYY-MM-DD') + end = selectedEndDate.endOf('month').format('YYYY-MM-DD') + } + else if (selectedStartDate.isSame(selectedEndDate, 'year')) { + periodType = 1 + start = selectedStartDate.startOf('year').format('YYYY-MM-DD') + end = selectedEndDate.endOf('year').format('YYYY-MM-DD') + } + else { + periodType = 2 + start = selectedStartDate.format('YYYY-MM-DD') + end = selectedEndDate.format('YYYY-MM-DD') + } + } + + analysisMoneyLineApi({ + start_date: start, + end_date: end, + type: analysisType, + period_type: periodType, + }).then((res) => { + if (res.isSuccess) { + setLineRecords(res.data.records) + } + }) + + analysisMoneyPieApi({ + start_date: start, + end_date: end, + type: analysisType, + period_type: periodType, + }).then((res) => { + if (res.isSuccess) { + setPieRecords(res.data.records) + } + }) + } + const totalAmount: number = pieRecords.reduce( + (sum, item) => Number(add(sum, Number(item.y) || 0)), + 0, + ) + + useEffect(() => { + fetchChartsData() + }, [timeType, startDate, endDate]) + + return ( + + { + setTimeType(index) + if (index === 2) { + // 自定义类型,本月的 1号 - 终止号 + setStartDate(getStartOfMonth()) + setEndDate(getEndOfMonth()) + } + else if (index === 1) { + // 按年 + setStartDate(getCurrentYear()) + setEndDate('') + } + else { + // 按月 + setStartDate(getCurrentYearMonth()) + setEndDate('') + } + }} + tabs={[ + { key: '1', label: '按月' }, + { key: '2', label: '按年' }, + { key: '3', label: '自定义' }, + ]} + /> + + + + {startDate} + {timeType === 2 && ( + <> + - + + {endDate} + + + )} + + + + + 趋势分析 + + + + + + + + 分类构成 + + { + pieRecords.length > 0 + ? ( + + ) + : ( + + ) + } + + + + + + 分类详细 + + 总: + {totalAmount} + {' '} + 元 + + + + { + pieRecords.length > 0 + ? ( + + {pieRecords.map((item, index) => ( + + {item.x} + + {item.y} + {' '} + 元 + + + ))} + + ) + : ( + + ) + + } + + + + { + timeType === 2 + ? ( + { + setStartDate(startDate) + setEndDate(endDate) + setShowDatePicker(false) + }} + onClose={() => { + setShowDatePicker(false) + }} + /> + ) + : ( + { + setStartDate(val) + setShowDatePicker(false) + }} + onClose={() => { + setShowDatePicker(false) + }} + /> + ) + } + + ) + } + + return ( + + + + , + }, + { + key: 'income', + title: '收入', + element: , + }, + ]} + /> + + ) +} diff --git a/code/allapp/allapp-rn/src/app/finance/record/editor/components/AmountKeyboard.tsx b/code/allapp/allapp-rn/src/app/finance/record/editor/components/AmountKeyboard.tsx index a4fb0e3f..d1e660c7 100644 --- a/code/allapp/allapp-rn/src/app/finance/record/editor/components/AmountKeyboard.tsx +++ b/code/allapp/allapp-rn/src/app/finance/record/editor/components/AmountKeyboard.tsx @@ -1,7 +1,9 @@ +import type { DateMorePickerMode } from '@/components/common/ao/DateMorePicker' import type { FinanceRecord } from '@/types/finance/record' import Big from 'big.js' import { useEffect, useState } from 'react' import { Keyboard, Pressable, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native' +import { ADateMorePicker } from '@/components/common/ao' import { ADatePicker, AInput, LucideIcon } from '@/components/common/ao/index' import { useKeyboardHeight } from '@/hooks/useKeyboardHeight' import { getCurrentDate } from '@/utils/time' @@ -51,10 +53,11 @@ export default function AmountKeyboard({ record, onDone, }: AmountKeyboardProps) { + // 日期 + const [showDatePicker, setShowDatePicker] = useState(false) + const [dateMode, setDateMode] = useState('date') // 自定义键盘计算过程 const [keydownInput, setKeydownInput] = useState('') - // 日期选择 - const [showDatePicker, setShowDatePicker] = useState(false) // 备注聚焦 const [remarkIsFocused, setRemarkIsFocused] = useState(false) // 键盘高度 @@ -342,7 +345,7 @@ export default function AmountKeyboard({ )} - */} + + { + setShowDatePicker(false) + }} + startDate={innerRecord.record_time} + oneMode="date" + onConfirm={(value) => { + setDateMode(value.mode) + + setInnerRecord(val => ({ + ...val, + record_time: value.startTime, + })) + }} /> ) diff --git a/code/allapp/allapp-rn/src/app/finance/record/editor/index.tsx b/code/allapp/allapp-rn/src/app/finance/record/editor/index.tsx index abb17bbf..d739c0e0 100644 --- a/code/allapp/allapp-rn/src/app/finance/record/editor/index.tsx +++ b/code/allapp/allapp-rn/src/app/finance/record/editor/index.tsx @@ -4,7 +4,7 @@ import { useLocalSearchParams, useRouter } from 'expo-router' import { useEffect, useState } from 'react' import { Text, TouchableOpacity, View } from 'react-native' import { toast } from 'sonner-native' -import { LucideIcon } from '@/components/common/ao' +import { ADateMorePicker, LucideIcon } from '@/components/common/ao' import CustomHeader from '@/components/custom/Header' import PagerTabs from '@/components/custom/PagerTabs' import { createFinanceRecordApi, updateFinanceRecordApi } from '@/request/api/finance/record' @@ -21,6 +21,7 @@ export default function MoenyRecordEditor() { const income = financeStore.getIncomeCategories() const { id: updateId } = useLocalSearchParams<{ id: string }>() + // 自定义键盘 const [showKeydown, setShowKeydown] = useState(false) // 选中分类 diff --git a/code/allapp/allapp-rn/src/components/common/ao/DateMorePicker.tsx b/code/allapp/allapp-rn/src/components/common/ao/DateMorePicker.tsx index 5298e577..5b8d8f46 100644 --- a/code/allapp/allapp-rn/src/components/common/ao/DateMorePicker.tsx +++ b/code/allapp/allapp-rn/src/components/common/ao/DateMorePicker.tsx @@ -37,6 +37,7 @@ interface DateMorePickerProps { endTime: string }) => void hiddenModes?: DateMorePickerMode[] + oneMode?: DateMorePickerMode onChange?: (mode: DateMorePickerMode) => void } @@ -108,6 +109,7 @@ export default function DateMorePicker({ onClose, onConfirm, onChange, + oneMode, hiddenModes = [], }: DateMorePickerProps) { const [localVisible, setLocalVisible] = useState(false) @@ -249,6 +251,13 @@ export default function DateMorePicker({ ] const visibleTabItems = tabItems.filter((item) => { + if (oneMode) { + if (oneMode === item.key) { + return true + } + return false + } + if (item.key === 'unlimited' && isHidden('unlimited')) return false if (item.key === 'range' && isHidden('range')) @@ -271,6 +280,12 @@ export default function DateMorePicker({ ] const visibleCoreModeOptions = coreModeOptions.filter((item) => { + if (oneMode) { + if (oneMode === item.mode) { + return true + } + return false + } if (item.mode === 'date' && isHidden('date')) return false if (item.mode === 'month' && isHidden('month')) @@ -293,9 +308,6 @@ export default function DateMorePicker({ const canConfirm = (() => { if (internalMode !== 'range') return true - console.log(internalMode) - console.log(internalStart) - console.log(internalEnd) const startValid = dayjs(internalStart).isValid() const endValid = dayjs(internalEnd).isValid() @@ -323,7 +335,7 @@ export default function DateMorePicker({ {/* 模式选择 */} - {!['unlimited', 'range'].includes(internalMode) && ( + {!oneMode && !['unlimited', 'range'].includes(internalMode) && ( 选择模式 {visibleCoreModeOptions.length > 0 && ( diff --git a/code/allapp/allapp-rn/src/components/common/ao/DatePicker.tsx b/code/allapp/allapp-rn/src/components/common/ao/DatePicker.tsx index 3c46cf5b..1bfef59f 100644 --- a/code/allapp/allapp-rn/src/components/common/ao/DatePicker.tsx +++ b/code/allapp/allapp-rn/src/components/common/ao/DatePicker.tsx @@ -1,5 +1,4 @@ import type { IDatePickerProps } from '@yz1311/react-native-wheel-picker' -import SegmentedControl from '@react-native-segmented-control/segmented-control' import { DatePicker } from '@yz1311/react-native-wheel-picker' import dayjs from 'dayjs' import React, { useEffect, useRef, useState } from 'react' @@ -33,6 +32,7 @@ export default function ADatePicker({ date, show = false, onClose, + mode = 'date', onConfirm, format, ...restProps @@ -40,8 +40,6 @@ export default function ADatePicker({ const fadeAnim = useRef(new Animated.Value(0)).current const slideAnim = useRef(new Animated.Value(300)).current const [visible, setVisible] = useState(show) - const [index, setIndex] = useState(0) - const [mode, setMode] = useState('month') // 使用传入 format 或默认 format const finalFormat = format || defaultFormatMap[mode] @@ -83,58 +81,6 @@ export default function ADatePicker({ - - - 快速选择 - {/* { - setMode('datetime') - }} - /> */} - - - - 选择模式 - setIndex(event.nativeEvent.selectedSegmentIndex)} - /> - - - - { - console.log(value) + handleConfirm(value) }} /> - - - {/* 取消 - 确认 */} - ) diff --git a/code/allapp/allapp-rn/src/types/finance/record.ts b/code/allapp/allapp-rn/src/types/finance/record.ts index 9ccbf736..ebcb1cc2 100644 --- a/code/allapp/allapp-rn/src/types/finance/record.ts +++ b/code/allapp/allapp-rn/src/types/finance/record.ts @@ -18,8 +18,8 @@ export interface FinanceRecord { export interface ListFinanceRecordsParams { start_time: string end_time: string - category_id: number - category_type: number + category_id: number | null + category_type: number | null } export interface ListFinanceRecordsResult { diff --git a/code/allapp/allapp-rn/test.html b/code/allapp/allapp-rn/test.html index d90f90cb..3c17f341 100644 --- a/code/allapp/allapp-rn/test.html +++ b/code/allapp/allapp-rn/test.html @@ -1,177 +1,207 @@ -import type { FinanceRecord } from '@/types/finance/record' -import Big from 'big.js' -import { useEffect, useState } from 'react' -import { Keyboard, Pressable, StyleSheet, Text, TouchableWithoutFeedback, View } from 'react-native' -import { ADatePicker, AInput, LucideIcon } from '@/components/common/ao/index' -import { useKeyboardHeight } from '@/hooks/useKeyboardHeight' -import { getCurrentDate } from '@/utils/time' + + + + + +家庭菜单 + + + -interface KeydownItem { - key: string | number - content: React.ReactNode +
家庭做饭助手
+ + +
+

菜谱

+
+
+ + +
+

下单

+
+
+ + +
+

库存

+ + + +
+
+ +
+
菜谱
+
下单
+
库存
+
+ + + + \ No newline at end of file