index.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { useState } from 'react';
  2. import { View, Text } from '@tarojs/components';
  3. import Taro, { useLoad } from '@tarojs/taro';
  4. import { Avatar, Cell, CellGroup, Button, Dialog } from '@nutui/nutui-react-taro';
  5. import { ArrowRight, User } from '@nutui/icons-react-taro';
  6. import { useUserStore } from '@/stores/user';
  7. import './index.less';
  8. interface UserInfo {
  9. name: string;
  10. avatar: string;
  11. }
  12. const userInfo: UserInfo = {
  13. name: '公司管理',
  14. avatar: '',
  15. };
  16. export default function Mine() {
  17. const [statusBarHeight, setStatusBarHeight] = useState<number | undefined>(0);
  18. const [showLogoutConfirm, setShowLogoutConfirm] = useState<boolean>(false);
  19. const [loading, setLoading] = useState<boolean>(false);
  20. useLoad(() => {
  21. const { statusBarHeight: sHeight } = Taro.getSystemInfoSync();
  22. setStatusBarHeight(sHeight);
  23. });
  24. const handleMenuClick = (value: string) => {
  25. console.log('Menu clicked:', value);
  26. };
  27. const handleLogout = () => {
  28. setShowLogoutConfirm(true);
  29. };
  30. function handleConfirmLogout() {
  31. try {
  32. setLoading(true);
  33. setShowLogoutConfirm(false);
  34. useUserStore.getState().logout();
  35. } finally {
  36. setLoading(false);
  37. }
  38. }
  39. return (
  40. <View className="mine">
  41. {/* 用户信息区域 */}
  42. <View
  43. className="user-section"
  44. style={{ paddingTop: `${statusBarHeight! + 30}px`, paddingBottom: '30px' }}
  45. >
  46. <View className="user-info">
  47. <Avatar
  48. size="large"
  49. icon={userInfo.avatar || <User width="50px" height="50px" />}
  50. className="user-avatar"
  51. />
  52. <View className="user-details">
  53. <Text className="user-name">{userInfo.name}</Text>
  54. <Text className="user-guide-no"></Text>
  55. </View>
  56. </View>
  57. </View>
  58. {/* 功能菜单区域 */}
  59. <View className="menu-section">
  60. <CellGroup title="系统设置" className="menu-group">
  61. {/* <Cell title="设置" onClick={() => handleMenuClick('settings')} extra={<ArrowRight />} /> */}
  62. <Cell title="关于" onClick={() => handleMenuClick('about')} extra={<ArrowRight />} />
  63. </CellGroup>
  64. </View>
  65. {/* 退出登录 */}
  66. <View className="logout-section">
  67. <Button
  68. fill="outline"
  69. size="large"
  70. type="danger"
  71. block
  72. className="logout-btn"
  73. onClick={handleLogout}
  74. disabled={loading}
  75. >
  76. 退出登录
  77. </Button>
  78. </View>
  79. <Dialog
  80. visible={showLogoutConfirm}
  81. title="确认退出登录"
  82. confirmText="确认"
  83. cancelText="取消"
  84. footerDirection="vertical"
  85. onConfirm={handleConfirmLogout}
  86. onCancel={() => setShowLogoutConfirm(false)}
  87. ></Dialog>
  88. </View>
  89. );
  90. }