优化项目结构

This commit is contained in:
李宇奇 2025-07-09 14:47:04 +08:00
parent 1705ace101
commit e937988771
16 changed files with 37 additions and 150 deletions

32
App.tsx
View File

@ -1,25 +1,3 @@
// /**
// * Sample React Native App
// * https://github.com/facebook/react-native
// *
// * @format
// */
//
// import React from 'react';
// import Navigation from './src/navigation';
// import {ThemeProvider} from './src/contexts/ThemeContext';
//
// function App(): JSX.Element {
// return (
// <ThemeProvider>
// <Navigation />
// </ThemeProvider>
// );
// }
//
// export default App;
/**
* Sample React Native App
* https://github.com/facebook/react-native
@ -27,11 +5,11 @@
* @format
*/
import React, { useState, useEffect } from 'react';
import React, {useState, useEffect} from 'react';
import Navigation from './src/navigation';
import {ThemeProvider} from './src/contexts/ThemeContext';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { View, Text, ActivityIndicator, StyleSheet } from 'react-native';
import {View, Text, ActivityIndicator, StyleSheet} from 'react-native';
function App(): JSX.Element {
const [fontLoaded, setFontLoaded] = useState(false);
@ -71,9 +49,7 @@ function App(): JSX.Element {
return (
<View style={styles.container}>
<ActivityIndicator size="large" />
<Text style={styles.statusText}>
{fontError || 'Loading icons...'}
</Text>
<Text style={styles.statusText}>{fontError || 'Loading icons...'}</Text>
<Text style={styles.debugText}>
Using MaterialIcons font family: {MaterialIcons.getFontFamily()}
</Text>
@ -108,4 +84,4 @@ const styles = StyleSheet.create({
},
});
export default App;
export default App;

View File

@ -1,6 +1,6 @@
{
"name": "pda_react_native_template",
"version": "0.0.1",
"version": "1.0.0",
"private": true,
"scripts": {
"android": "react-native run-android",

View File

@ -1,26 +0,0 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import {StatusBar} from 'react-native';
import Navigation from './navigation';
import {ThemeProvider} from './contexts/ThemeContext';
import {theme} from './constants/theme';
const App = () => {
return (
<ThemeProvider theme={theme}>
<StatusBar
backgroundColor={theme.colors.primary}
barStyle="light-content"
/>
<Navigation />
</ThemeProvider>
);
};
export default App;

View File

@ -2,4 +2,4 @@ export const ENV = {
API_URL: __DEV__ ? 'http://dev-api.example.com' : 'https://api.example.com',
APP_NAME: 'PdaRnTemplate',
VERSION: '1.0.0',
};
};

View File

@ -1,31 +1,31 @@
export const theme = {
colors: {
// 基础颜色
aqua: '#05DCEF', // 青色主色调 (0xff05dcef)
background: '#ffffff', // 背景色
aqua: '#05DCEF', // 青色主色调 (0xff05dcef)
background: '#ffffff', // 背景色
backgroundGray: '#F5F5F5', // 灰色背景
text: '#333333', // 文本颜色
textLight: '#666666', // 次要文本颜色
border: '#dddddd', // 边框颜色
error: '#ff3b30', // 错误颜色
cyan: '#00FFFF', // 青色背景
lightGreen: '#7FFFAA', // 浅绿色
text: '#333333', // 文本颜色
textLight: '#666666', // 次要文本颜色
border: '#dddddd', // 边框颜色
error: '#ff3b30', // 错误颜色
cyan: '#00FFFF', // 青色背景
lightGreen: '#7FFFAA', // 浅绿色
// 渐变色配置
gradients: {
primary: ['#05DCEF', '#7DE2F5', '#B8F2FF'], // 主要渐变(青蓝白,小清新)
contrast: ['#00F5A0', '#00D9F5'], // 对比渐变(绿青)
header: ['#05DCEF', '#7DE2F5'], // 头部渐变
button: ['#05DCEF', '#7DE2F5'], // 按钮渐变
primary: ['#05DCEF', '#7DE2F5', '#B8F2FF'], // 主要渐变(青蓝白,小清新)
contrast: ['#00F5A0', '#00D9F5'], // 对比渐变(绿青)
header: ['#05DCEF', '#7DE2F5'], // 头部渐变
button: ['#05DCEF', '#7DE2F5'], // 按钮渐变
},
// 图表颜色
chart: {
cyan: '#00FFFF', // 青色
cyan: '#00FFFF', // 青色
lightGreen: '#7FFFAA', // 浅绿色
},
},
// 字体大小
fontSize: {
small: 12,
@ -36,7 +36,7 @@ export const theme = {
xxlarge: 24,
title: 32,
},
// 间距
spacing: {
xs: 4,
@ -45,7 +45,7 @@ export const theme = {
large: 24,
xl: 32,
},
// 圆角
borderRadius: {
small: 4,
@ -54,7 +54,7 @@ export const theme = {
xl: 16,
circle: 999,
},
// 阴影
shadow: {
small: {
@ -73,7 +73,7 @@ export const theme = {
width: 0,
height: 4,
},
shadowOpacity: 0.30,
shadowOpacity: 0.3,
shadowRadius: 4.65,
elevation: 4,
},
@ -88,8 +88,6 @@ export const theme = {
elevation: 6,
},
},
};
// 类型定义
@ -98,4 +96,4 @@ export type Theme = typeof theme;
// 导出类型
declare module '@react-navigation/native' {
export type ExtendedTheme = Theme;
}
}

View File

@ -18,4 +18,4 @@ export const useTheme = () => {
throw new Error('useTheme must be used within a ThemeProvider');
}
return theme;
};
};

View File

@ -1,23 +0,0 @@
class ScannerService {
async init(): Promise<void> {
// 初始化扫描器
console.log('Scanner initialized');
}
async startScan(): Promise<string> {
// 开始扫描
return new Promise((resolve) => {
// 模拟扫描结果
setTimeout(() => {
resolve('Scanned barcode result');
}, 1000);
});
}
async stopScan(): Promise<void> {
// 停止扫描
console.log('Scanner stopped');
}
}
export const scannerService = new ScannerService();

View File

@ -1,38 +0,0 @@
import {useState, useCallback} from 'react';
import {scannerService} from '../device/scanner';
export const useScanner = () => {
const [isScanning, setIsScanning] = useState(false);
const [result, setResult] = useState<string | null>(null);
const [error, setError] = useState<Error | null>(null);
const startScan = useCallback(async () => {
try {
setIsScanning(true);
setError(null);
const scanResult = await scannerService.startScan();
setResult(scanResult);
} catch (err) {
setError(err as Error);
} finally {
setIsScanning(false);
}
}, []);
const stopScan = useCallback(async () => {
try {
await scannerService.stopScan();
setIsScanning(false);
} catch (err) {
setError(err as Error);
}
}, []);
return {
isScanning,
result,
error,
startScan,
stopScan,
};
};

View File

@ -4,7 +4,7 @@ import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {LoginScreen} from '../screens/auth/LoginScreen';
import {HomeScreen} from '../screens/home/HomeScreen';
import {StockInEmpty} from '../screens/stockIn/StockInEmpty';
import StockInWheelManual from '../screens/stockIn/StockInWheelManual';
import {StockInManual} from '../screens/stockIn/StockInManual';
import {RootStackParamList} from './types';
import {Platform} from 'react-native';
import {screensEnabled, enableScreens} from 'react-native-screens';
@ -50,8 +50,8 @@ const Navigation = () => {
}}
/>
<Stack.Screen
name="StockInWheelManual"
component={StockInWheelManual}
name="StockInManual"
component={StockInManual}
options={{
animation: 'none',
}}

View File

@ -4,8 +4,8 @@ export type RootStackParamList = {
Login: undefined;
Home: undefined;
StockInEmpty: undefined;
StockInWheelEBS: undefined;
StockInWheelManual: undefined;
StockInEBS: undefined;
StockInManual: undefined;
Pick: undefined;
StockCheck: undefined;
// 在这里添加其他页面的路由参数定义
@ -18,4 +18,4 @@ declare global {
namespace ReactNavigation {
interface RootParamList extends RootStackParamList {}
}
}
}

View File

@ -49,7 +49,7 @@ export const HomeScreen: React.FC = () => {
const menuItems: MenuItem[] = [
{ title: '空载具入库', icon: 'local-shipping', route: 'StockInEmpty' },
{ title: '手动码盘入库', icon: 'inventory', route: 'StockInWheelManual' },
{ title: '手动码盘入库', icon: 'inventory', route: 'StockInManual' },
];
const stockData = [

View File

@ -34,7 +34,7 @@ interface PackageDataItem {
lineLocationId: string;
}
const StockInWheelManual: React.FC = () => {
export const StockInManual: React.FC = () => {
const theme = useTheme();
const navigation = useNavigation();
const [vehicleCode, setVehicleCode] = useState('');
@ -656,4 +656,4 @@ const styles = StyleSheet.create({
},
});
export default StockInWheelManual;
export default StockInManual;

View File

@ -18,4 +18,4 @@ export interface DeviceInfo {
model: string;
osVersion: string;
serialNumber: string;
}
}

View File

@ -35,4 +35,4 @@ export const storage = {
console.error('Error clearing data', error);
}
},
};
};