feat: update
This commit is contained in:
@@ -4,8 +4,7 @@ import { Link, Tabs } from 'expo-router';
|
||||
import { Pressable } from 'react-native';
|
||||
|
||||
import Colors from '@/constants/Colors';
|
||||
import { useColorScheme } from '@/components/useColorScheme';
|
||||
import { useClientOnlyValue } from '@/components/useClientOnlyValue';
|
||||
import { useColorScheme, useClientOnlyValue } from '@/hooks';
|
||||
|
||||
// You can explore the built-in icon families and icons on the web at https://icons.expo.fyi/
|
||||
function TabBarIcon(props: {
|
||||
|
||||
@@ -18,17 +18,23 @@ import {
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { Image } from 'expo-image';
|
||||
import { useRouter } from 'expo-router';
|
||||
|
||||
// 导入所有工具
|
||||
// ✅ 扁平化导入:从根目录的各个模块导入
|
||||
|
||||
// 工具函数
|
||||
import {
|
||||
// 工具函数
|
||||
Storage,
|
||||
STORAGE_KEYS,
|
||||
SessionStorage,
|
||||
SESSION_KEYS,
|
||||
formatDate,
|
||||
formatRelativeTime,
|
||||
formatChatTime,
|
||||
formatChatTime
|
||||
} from '@/utils';
|
||||
|
||||
// 状态管理
|
||||
// 状态管理
|
||||
import {
|
||||
useUserStore,
|
||||
useUser,
|
||||
useIsLoggedIn,
|
||||
@@ -36,24 +42,28 @@ import {
|
||||
useTheme,
|
||||
useLanguage,
|
||||
useHapticsEnabled,
|
||||
useSettingsActions,
|
||||
useTenantStates,
|
||||
useTenantInfo,
|
||||
} from '@/stores';
|
||||
|
||||
// 验证规则
|
||||
loginSchema,
|
||||
type LoginFormData,
|
||||
// 验证规则
|
||||
import { loginSchema } from '@/schemas';
|
||||
import type { LoginFormData } from '@/schemas';
|
||||
|
||||
// API 服务
|
||||
authService,
|
||||
appService,
|
||||
// API 服务
|
||||
import { authService } from '@/services';
|
||||
|
||||
// 自定义 Hooks
|
||||
useDebounce,
|
||||
useThrottle,
|
||||
useHaptics,
|
||||
} from '@/src';
|
||||
// 自定义 Hooks
|
||||
import { useDebounce, useThrottle, useHaptics } from '@/hooks';
|
||||
|
||||
// 主题组件
|
||||
import { ThemeDemo } from '@/components/ThemeDemo';
|
||||
|
||||
export default function DemoScreen() {
|
||||
console.log('=== DemoScreen 组件已渲染 ===');
|
||||
const haptics = useHaptics();
|
||||
const router = useRouter();
|
||||
|
||||
// 状态管理示例
|
||||
const user = useUser();
|
||||
@@ -61,13 +71,17 @@ export default function DemoScreen() {
|
||||
const login = useUserStore((state) => state.login);
|
||||
const logout = useUserStore((state) => state.logout);
|
||||
|
||||
const { tenantLoad } = useTenantStates();
|
||||
const tenantInfo = useTenantInfo();
|
||||
|
||||
// 设置状态
|
||||
const theme = useTheme();
|
||||
const language = useLanguage();
|
||||
const hapticsEnabled = useHapticsEnabled();
|
||||
const setTheme = useSettingsStore((state) => state.setTheme);
|
||||
const setLanguage = useSettingsStore((state) => state.setLanguage);
|
||||
const setHapticsEnabled = useSettingsStore((state) => state.setHapticsEnabled);
|
||||
const { setTheme, setLanguage, setHapticsEnabled } = useSettingsActions();
|
||||
// const setTheme = useSettingsStore((state) => state.setTheme);
|
||||
// const setLanguage = useSettingsStore((state) => state.setLanguage);
|
||||
// const setHapticsEnabled = useSettingsStore((state) => state.setHapticsEnabled);
|
||||
|
||||
// 本地状态
|
||||
const [searchText, setSearchText] = useState('');
|
||||
@@ -75,6 +89,7 @@ export default function DemoScreen() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [counter, setCounter] = useState(0);
|
||||
const [storageValue, setStorageValue] = useState('');
|
||||
const [sessionValue, setSessionValue] = useState('');
|
||||
|
||||
// 表单配置
|
||||
const {
|
||||
@@ -103,21 +118,6 @@ export default function DemoScreen() {
|
||||
setSearchResults([`结果 1: ${text}`, `结果 2: ${text}`, `结果 3: ${text}`]);
|
||||
}, 500);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('=== useEffect 开始执行 ===');
|
||||
console.log('appService:', appService);
|
||||
console.log('getPlatformData 方法:', appService.getPlatformData);
|
||||
|
||||
appService
|
||||
.getPlatformData()
|
||||
.then((res: any) => {
|
||||
console.log('getPlatformData 成功:', res);
|
||||
})
|
||||
.catch((err: any) => {
|
||||
console.error('getPlatformData 失败:', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
// 监听搜索文本变化
|
||||
useEffect(() => {
|
||||
debouncedSearch(searchText);
|
||||
@@ -216,6 +216,59 @@ export default function DemoScreen() {
|
||||
}
|
||||
};
|
||||
|
||||
// SessionStorage 处理函数
|
||||
const handleSaveToSession = () => {
|
||||
try {
|
||||
haptics.light();
|
||||
const testData = {
|
||||
formDraft: {
|
||||
title: '草稿标题',
|
||||
content: '这是一个表单草稿示例',
|
||||
},
|
||||
timestamp: new Date().toISOString(),
|
||||
counter: Math.floor(Math.random() * 100),
|
||||
};
|
||||
|
||||
SessionStorage.setObject(SESSION_KEYS.FORM_DRAFT, testData);
|
||||
haptics.success();
|
||||
Alert.alert('成功', '数据已保存到会话存储(应用重启后会丢失)');
|
||||
} catch (error) {
|
||||
haptics.error();
|
||||
Alert.alert('失败', '保存失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleLoadFromSession = () => {
|
||||
try {
|
||||
haptics.light();
|
||||
const data = SessionStorage.getObject<any>(SESSION_KEYS.FORM_DRAFT);
|
||||
|
||||
if (data) {
|
||||
setSessionValue(JSON.stringify(data, null, 2));
|
||||
haptics.success();
|
||||
} else {
|
||||
setSessionValue('暂无数据(会话存储为空)');
|
||||
haptics.warning();
|
||||
}
|
||||
} catch (error) {
|
||||
haptics.error();
|
||||
Alert.alert('失败', '读取失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleClearSession = () => {
|
||||
try {
|
||||
haptics.light();
|
||||
SessionStorage.clear();
|
||||
setSessionValue('');
|
||||
haptics.success();
|
||||
Alert.alert('成功', '会话存储已清空');
|
||||
} catch (error) {
|
||||
haptics.error();
|
||||
Alert.alert('失败', '清空失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 主题切换
|
||||
const handleThemeChange = () => {
|
||||
haptics.selection();
|
||||
@@ -238,6 +291,68 @@ export default function DemoScreen() {
|
||||
<Text style={styles.title}>🎯 完整功能演示</Text>
|
||||
<Text style={styles.subtitle}>展示所有工具的使用方法</Text>
|
||||
|
||||
{/* 页面导航 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>📱 页面导航</Text>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.primaryButton]}
|
||||
onPress={() => {
|
||||
haptics.light();
|
||||
router.push('/test-page');
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>跳转到测试页面 →</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.infoText}>
|
||||
测试页面是一个独立的业务页面示例,不包含底部 tabs
|
||||
</Text>
|
||||
|
||||
<TouchableOpacity
|
||||
style={[styles.button, { backgroundColor: '#9333ea', marginTop: 12 }]}
|
||||
onPress={() => {
|
||||
haptics.light();
|
||||
router.push('/theme-test');
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>🎨 主题测试页面 →</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.infoText}>
|
||||
专门的主题测试页面,可以清楚地看到主题切换效果
|
||||
</Text>
|
||||
|
||||
<TouchableOpacity
|
||||
style={[styles.button, { backgroundColor: '#06b6d4', marginTop: 12 }]}
|
||||
onPress={() => {
|
||||
haptics.light();
|
||||
router.push('/theme-example');
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>📚 主题系统示例 →</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.infoText}>
|
||||
展示四种主题样式使用方式(类似 CSS 类名)
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{/* 租户信息显示 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>🏢 租户信息</Text>
|
||||
<Text style={styles.infoText}>
|
||||
状态: {tenantLoad ? '✅ 已加载' : '❌ 未加载'}
|
||||
</Text>
|
||||
{tenantInfo && (
|
||||
<>
|
||||
<Text style={styles.infoText}>TID: {tenantInfo.tid || '无'}</Text>
|
||||
<Text style={styles.infoText}>
|
||||
创建时间: {tenantInfo.create_time || '无'}
|
||||
</Text>
|
||||
<Text style={styles.infoText}>
|
||||
域名: {tenantInfo.domain_addr || '无'}
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* 用户状态显示 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>👤 用户状态 (Zustand)</Text>
|
||||
@@ -373,6 +488,39 @@ export default function DemoScreen() {
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* 会话存储示例 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>🔄 会话存储 (SessionStorage)</Text>
|
||||
<Text style={styles.infoText}>
|
||||
会话存储数据保存在内存中,应用重启后会丢失,适合临时数据
|
||||
</Text>
|
||||
<View style={styles.buttonRow}>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.primaryButton, styles.thirdButton]}
|
||||
onPress={handleSaveToSession}
|
||||
>
|
||||
<Text style={styles.buttonText}>保存</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.secondaryButton, styles.thirdButton]}
|
||||
onPress={handleLoadFromSession}
|
||||
>
|
||||
<Text style={styles.buttonText}>读取</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
style={[styles.button, styles.errorButton, styles.thirdButton]}
|
||||
onPress={handleClearSession}
|
||||
>
|
||||
<Text style={styles.buttonText}>清空</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
{sessionValue && (
|
||||
<View style={styles.codeBlock}>
|
||||
<Text style={styles.codeText}>{sessionValue}</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* 日期格式化示例 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>📅 日期格式化 (Day.js)</Text>
|
||||
@@ -383,6 +531,12 @@ export default function DemoScreen() {
|
||||
<Text style={styles.infoText}>聊天时间: {formatChatTime(Date.now())}</Text>
|
||||
</View>
|
||||
|
||||
{/* 主题演示 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>🎨 主题系统演示</Text>
|
||||
<ThemeDemo />
|
||||
</View>
|
||||
|
||||
{/* 设置示例 */}
|
||||
<View style={styles.section}>
|
||||
<Text style={styles.sectionTitle}>⚙️ 应用设置</Text>
|
||||
@@ -598,6 +752,10 @@ const styles = StyleSheet.create({
|
||||
halfButton: {
|
||||
flex: 1,
|
||||
},
|
||||
thirdButton: {
|
||||
flex: 1,
|
||||
marginHorizontal: 4,
|
||||
},
|
||||
searchResults: {
|
||||
marginTop: 12,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user