healthapp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 KiB

01-项目初始化和模拟数据

目标

初始化 React Native 项目并搭建模拟数据服务,为原型开发提供完整的数据支持。


前置要求

  • 已完成 React Native 环境搭建
  • Node.js 18+
  • Android Studio / Xcode

实施步骤

步骤 1:创建 React Native 项目

# 进入项目目录
cd I:/apps/demo/healthApps

# 创建 React Native 项目
npx react-native init HealthAIApp --template react-native-template-typescript

# 进入项目
cd HealthAIApp

步骤 2:安装核心依赖

# 导航
npm install @react-navigation/native @react-navigation/bottom-tabs @react-navigation/native-stack
npm install react-native-screens react-native-safe-area-context

# UI 组件库
npm install react-native-paper react-native-vector-icons

# 状态管理
npm install zustand

# 图表
npm install react-native-gifted-charts react-native-linear-gradient react-native-svg

# 存储
npm install @react-native-async-storage/async-storage

# 表单
npm install react-hook-form

# 工具
npm install dayjs lodash-es
npm install -D @types/lodash-es

步骤 3:创建项目目录结构

HealthAIApp/
├── src/
│   ├── api/                    # API 接口(后续对接用)
│   ├── components/             # 公共组件
│   │   ├── Button.tsx
│   │   ├── Card.tsx
│   │   ├── Input.tsx
│   │   └── Loading.tsx
│   ├── mock/                   # 模拟数据 ⭐
│   │   ├── index.ts            # 统一导出
│   │   ├── user.ts             # 用户数据
│   │   ├── constitution.ts     # 体质问卷和结果
│   │   ├── chat.ts             # AI 对话数据
│   │   └── products.ts         # 产品数据
│   ├── navigation/             # 导航配置
│   │   └── index.tsx
│   ├── screens/                # 页面
│   │   ├── auth/               # 登录相关
│   │   ├── home/               # 首页
│   │   ├── constitution/       # 体质辨识
│   │   ├── chat/               # AI 对话
│   │   └── profile/            # 个人中心
│   ├── services/               # 业务服务
│   │   └── mockService.ts      # 模拟服务
│   ├── stores/                 # Zustand 状态
│   │   ├── useAuthStore.ts
│   │   ├── useConstitutionStore.ts
│   │   └── useChatStore.ts
│   ├── theme/                  # 主题配置
│   │   └── index.ts
│   ├── types/                  # TypeScript 类型
│   │   └── index.ts
│   └── utils/                  # 工具函数
│       └── index.ts
├── App.tsx
└── package.json

步骤 4:创建模拟数据服务

4.1 类型定义 src/types/index.ts

// 用户类型
export interface User {
  id: number;
  phone: string;
  nickname: string;
  avatar: string;
  surveyCompleted: boolean;
}

// 体质类型
export type ConstitutionType = 
  | 'pinghe'   // 平和质
  | 'qixu'     // 气虚质
  | 'yangxu'   // 阳虚质
  | 'yinxu'    // 阴虚质
  | 'tanshi'   // 痰湿质
  | 'shire'    // 湿热质
  | 'xueyu'    // 血瘀质
  | 'qiyu'     // 气郁质
  | 'tebing';  // 特禀质

// 体质问卷题目
export interface ConstitutionQuestion {
  id: number;
  constitutionType: ConstitutionType;
  question: string;
  options: { value: number; label: string }[];
}

// 体质评估结果
export interface ConstitutionResult {
  primaryType: ConstitutionType;
  scores: Record<ConstitutionType, number>;
  description: string;
  suggestions: string[];
  assessedAt: string;
}

// 对话消息
export interface Message {
  id: string;
  role: 'user' | 'assistant';
  content: string;
  createdAt: string;
}

// 对话
export interface Conversation {
  id: string;
  title: string;
  messages: Message[];
  createdAt: string;
  updatedAt: string;
}

// 产品
export interface Product {
  id: number;
  name: string;
  category: string;
  description: string;
  efficacy: string;
  price: number;
  imageUrl: string;
  mallUrl: string;
}

4.2 用户模拟数据 src/mock/user.ts

import { User } from '../types';

// 测试用户
export const mockUsers: User[] = [
  {
    id: 1,
    phone: '13800138000',
    nickname: '健康达人',
    avatar: 'https://api.dicebear.com/7.x/avataaars/png?seed=1',
    surveyCompleted: true,
  },
  {
    id: 2,
    phone: '13900139000',
    nickname: '新用户',
    avatar: 'https://api.dicebear.com/7.x/avataaars/png?seed=2',
    surveyCompleted: false,
  },
];

// 模拟登录
export const mockLogin = (phone: string, code: string): Promise<User | null> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      // 验证码固定为 123456
      if (code !== '123456') {
        resolve(null);
        return;
      }
      const user = mockUsers.find((u) => u.phone === phone);
      resolve(user || mockUsers[0]); // 默认返回第一个用户
    }, 800);
  });
};

4.3 体质问卷模拟数据 src/mock/constitution.ts

import { ConstitutionQuestion, ConstitutionResult, ConstitutionType } from '../types';

// 体质类型中文名
export const constitutionNames: Record<ConstitutionType, string> = {
  pinghe: '平和质',
  qixu: '气虚质',
  yangxu: '阳虚质',
  yinxu: '阴虚质',
  tanshi: '痰湿质',
  shire: '湿热质',
  xueyu: '血瘀质',
  qiyu: '气郁质',
  tebing: '特禀质',
};

// 体质描述
export const constitutionDescriptions: Record<ConstitutionType, {
  description: string;
  features: string[];
  suggestions: string[];
}> = {
  pinghe: {
    description: '阴阳气血调和,体态适中,面色红润,精力充沛',
    features: ['体态匀称', '面色红润', '精力充沛', '睡眠良好', '性格开朗'],
    suggestions: ['保持均衡饮食', '适度运动', '规律作息', '心态平和'],
  },
  qixu: {
    description: '元气不足,容易疲乏,气短懒言,易出汗',
    features: ['容易疲劳', '气短懒言', '易出汗', '抵抗力差', '声音低弱'],
    suggestions: ['多食补气食物(黄芪、人参、山药)', '避免过度劳累', '适当午休', '温和运动'],
  },
  yangxu: {
    description: '阳气不足,畏寒怕冷,手脚冰凉,精神不振',
    features: ['畏寒怕冷', '手脚冰凉', '喜热饮食', '精神不振', '小便清长'],
    suggestions: ['多食温阳食物(羊肉、生姜、桂圆)', '注意保暖', '避免寒凉', '晒太阳'],
  },
  yinxu: {
    description: '阴液亏少,口燥咽干,手足心热,易失眠',
    features: ['口干咽燥', '手足心热', '失眠多梦', '皮肤干燥', '大便干结'],
    suggestions: ['多食滋阴食物(枸杞、银耳、百合)', '避免熬夜', '少食辛辣', '保持心情平静'],
  },
  tanshi: {
    description: '痰湿凝聚,体形肥胖,腹部肥满,胸闷痰多',
    features: ['体形肥胖', '腹部肥满', '胸闷痰多', '身重乏力', '面部油腻'],
    suggestions: ['控制饮食', '多食祛湿食物(薏米、冬瓜)', '加强运动', '少食甜腻'],
  },
  shire: {
    description: '湿热内蕴,面垢油光,口苦口干,身重困倦',
    features: ['面部油腻', '口苦口干', '身重困倦', '大便黏滞', '小便短黄'],
    suggestions: ['清淡饮食', '多食清热利湿食物', '避免辛辣油腻', '保持环境干燥'],
  },
  xueyu: {
    description: '血行不畅,面色晦暗,皮肤粗糙,易生斑点',
    features: ['面色晦暗', '皮肤粗糙', '易生色斑', '唇色偏暗', '健忘'],
    suggestions: ['多食活血食物(山楂、黑木耳)', '适当运动', '避免久坐', '保持心情舒畅'],
  },
  qiyu: {
    description: '气机郁滞,情志抑郁,忧虑脆弱,胸胁胀满',
    features: ['情绪低落', '忧虑善感', '胸胁胀满', '咽部异物感', '睡眠不佳'],
    suggestions: ['疏肝理气', '多食理气食物(玫瑰花、陈皮)', '保持心情愉快', '多交流倾诉'],
  },
  tebing: {
    description: '先天失常,易过敏,适应能力差',
    features: ['易过敏', '喷嚏频繁', '皮肤易起疹', '适应力差', '遗传倾向'],
    suggestions: ['避免过敏原', '增强体质', '饮食清淡', '注意环境卫生'],
  },
};

// 体质问卷题目(共60题,每种体质7题,平和质4题)
export const constitutionQuestions: ConstitutionQuestion[] = [
  // 气虚质 (7题)
  { id: 1, constitutionType: 'qixu', question: '您容易疲乏吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 2, constitutionType: 'qixu', question: '您容易气短(呼吸短促,接不上气)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 3, constitutionType: 'qixu', question: '您容易心慌吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 4, constitutionType: 'qixu', question: '您容易头晕或站起时晕眩吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 5, constitutionType: 'qixu', question: '您比别人容易感冒吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 6, constitutionType: 'qixu', question: '您喜欢安静、懒得说话吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 7, constitutionType: 'qixu', question: '您说话声音低弱无力吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 阳虚质 (7题)
  { id: 8, constitutionType: 'yangxu', question: '您手脚发凉吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 9, constitutionType: 'yangxu', question: '您胃脘部、背部或腰膝部怕冷吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 10, constitutionType: 'yangxu', question: '您比一般人耐受不了寒冷吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 11, constitutionType: 'yangxu', question: '您容易感受风寒吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 12, constitutionType: 'yangxu', question: '您吃(喝)凉的东西会感到不舒服或者怕吃凉的东西吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 13, constitutionType: 'yangxu', question: '您受凉或吃凉的东西后,容易拉肚子吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 14, constitutionType: 'yangxu', question: '您比别人更容易患感冒吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 阴虚质 (7题)
  { id: 15, constitutionType: 'yinxu', question: '您感到手脚心发热吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 16, constitutionType: 'yinxu', question: '您感觉身体、脸上发热吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 17, constitutionType: 'yinxu', question: '您皮肤或口唇干吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 18, constitutionType: 'yinxu', question: '您口唇的颜色比一般人红吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 19, constitutionType: 'yinxu', question: '您容易便秘或大便干燥吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 20, constitutionType: 'yinxu', question: '您面部两颧潮红或偏红吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 21, constitutionType: 'yinxu', question: '您感到眼睛干涩吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 痰湿质 (7题)
  { id: 22, constitutionType: 'tanshi', question: '您感到胸闷或腹部胀满吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 23, constitutionType: 'tanshi', question: '您感到身体沉重不轻松或不爽快吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 24, constitutionType: 'tanshi', question: '您腹部肥满松软吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 25, constitutionType: 'tanshi', question: '您有额部油脂分泌多的现象吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 26, constitutionType: 'tanshi', question: '您上眼睑比别人肿(上眼睑有轻微隆起的现象)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 27, constitutionType: 'tanshi', question: '您嘴里有黏黏的感觉吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 28, constitutionType: 'tanshi', question: '您平时痰多,特别是咽喉部总感到有痰堵着吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 湿热质 (7题)
  { id: 29, constitutionType: 'shire', question: '您面部或鼻部有油腻感或者油亮发光吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 30, constitutionType: 'shire', question: '您容易生痤疮或者疮疖吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 31, constitutionType: 'shire', question: '您感到口苦或嘴里有异味吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 32, constitutionType: 'shire', question: '您大便黏滞不爽、有解不尽的感觉吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 33, constitutionType: 'shire', question: '您小便时尿道有发热感、尿色浓(深)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 34, constitutionType: 'shire', question: '您带下色黄(白带颜色发黄)吗?(限女性回答)', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 35, constitutionType: 'shire', question: '您的阴囊部位潮湿吗?(限男性回答)', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 血瘀质 (7题)
  { id: 36, constitutionType: 'xueyu', question: '您的皮肤在不知不觉中会出现青紫瘀斑(皮下出血)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 37, constitutionType: 'xueyu', question: '您两颧部有细微红丝(毛细血管扩张)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 38, constitutionType: 'xueyu', question: '您身体上有哪里疼痛吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 39, constitutionType: 'xueyu', question: '您面色晦暗或容易出现褐斑吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 40, constitutionType: 'xueyu', question: '您容易有黑眼圈吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 41, constitutionType: 'xueyu', question: '您容易忘事(健忘)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 42, constitutionType: 'xueyu', question: '您口唇颜色偏暗吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 气郁质 (7题)
  { id: 43, constitutionType: 'qiyu', question: '您感到闷闷不乐、情绪低沉吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 44, constitutionType: 'qiyu', question: '您容易精神紧张、焦虑不安吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 45, constitutionType: 'qiyu', question: '您多愁善感、感情脆弱吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 46, constitutionType: 'qiyu', question: '您容易感到害怕或受到惊吓吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 47, constitutionType: 'qiyu', question: '您胁肋部或乳房胀痛吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 48, constitutionType: 'qiyu', question: '您无缘无故叹气吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 49, constitutionType: 'qiyu', question: '您咽喉部有异物感,且吐之不出、咽之不下吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 特禀质 (7题)
  { id: 50, constitutionType: 'tebing', question: '您没有感冒时也会打喷嚏吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 51, constitutionType: 'tebing', question: '您没有感冒时也会鼻塞、流鼻涕吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 52, constitutionType: 'tebing', question: '您有因季节变化、温度变化或异味等原因而咳喘的现象吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 53, constitutionType: 'tebing', question: '您容易过敏(对药物、食物、气味、花粉或在季节交替、气候变化时)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 54, constitutionType: 'tebing', question: '您的皮肤容易起荨麻疹(风团、风疹块、风疙瘩)吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 55, constitutionType: 'tebing', question: '您的皮肤一抓就红,并出现抓痕吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 56, constitutionType: 'tebing', question: '您的皮肤在不知不觉中会出现紫红色瘀点、瘀斑吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},

  // 平和质 (4题)
  { id: 57, constitutionType: 'pinghe', question: '您精力充沛吗?', options: [
    { value: 5, label: '总是' }, { value: 4, label: '经常' }, { value: 3, label: '有时' }, { value: 2, label: '很少' }, { value: 1, label: '从不' }
  ]},
  { id: 58, constitutionType: 'pinghe', question: '您容易疲乏吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 59, constitutionType: 'pinghe', question: '您说话声音低弱无力吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
  { id: 60, constitutionType: 'pinghe', question: '您感到闷闷不乐、情绪低沉吗?', options: [
    { value: 1, label: '从不' }, { value: 2, label: '很少' }, { value: 3, label: '有时' }, { value: 4, label: '经常' }, { value: 5, label: '总是' }
  ]},
];

// 计算体质结果
export const calculateConstitution = (
  answers: Record<number, number>
): ConstitutionResult => {
  const scores: Record<ConstitutionType, number> = {
    pinghe: 0, qixu: 0, yangxu: 0, yinxu: 0, tanshi: 0,
    shire: 0, xueyu: 0, qiyu: 0, tebing: 0,
  };

  // 计算各体质得分
  constitutionQuestions.forEach((q) => {
    const answer = answers[q.id] || 3;
    scores[q.constitutionType] += answer;
  });

  // 转换为百分制
  const questionCounts: Record<ConstitutionType, number> = {
    pinghe: 4, qixu: 7, yangxu: 7, yinxu: 7, tanshi: 7,
    shire: 7, xueyu: 7, qiyu: 7, tebing: 7,
  };

  Object.keys(scores).forEach((key) => {
    const type = key as ConstitutionType;
    const count = questionCounts[type];
    // 转换公式:(原始分 - 题目数) / (题目数 * 4) * 100
    scores[type] = Math.round(((scores[type] - count) / (count * 4)) * 100);
  });

  // 平和质特殊处理(反向计算)
  scores.pinghe = 100 - scores.pinghe;

  // 找出主体质(平和质需要特殊判断)
  let primaryType: ConstitutionType = 'pinghe';
  
  // 平和质判定:平和质得分≥60,且其他偏颇体质得分<40
  const isPinghe = scores.pinghe >= 60 && 
    Object.entries(scores)
      .filter(([k]) => k !== 'pinghe')
      .every(([, v]) => v < 40);

  if (!isPinghe) {
    // 找最高分的偏颇体质
    let maxScore = 0;
    Object.entries(scores).forEach(([type, score]) => {
      if (type !== 'pinghe' && score > maxScore) {
        maxScore = score;
        primaryType = type as ConstitutionType;
      }
    });
  }

  const info = constitutionDescriptions[primaryType];

  return {
    primaryType,
    scores,
    description: info.description,
    suggestions: info.suggestions,
    assessedAt: new Date().toISOString(),
  };
};

4.4 AI对话模拟数据 src/mock/chat.ts

import { Conversation, Message } from '../types';

// 预设对话模板
export const chatTemplates: Record<string, string[]> = {
  greeting: [
    '您好!我是健康AI助手,很高兴为您服务。',
    '我可以根据您的体质特点,为您提供个性化的健康建议。',
    '请问有什么可以帮助您的吗?',
  ],
  fatigue: [
    '【情况分析】根据您描述的疲劳症状,结合您的气虚体质,这可能与气血不足有关。',
    '【建议】\n1. 保证充足睡眠,每天7-8小时\n2. 适当运动,如太极、散步\n3. 饮食上多吃补气食物',
    '【用药参考】\n- 黄芪精口服液:每日2次,每次1支(建议咨询药师)',
    '【推荐调养产品】\n- 黄芪精口服液 ¥68 [点击购买](https://mall.example.com/product/1)',
    '【提醒】如果疲劳症状持续超过2周且伴有其他不适,建议就医检查。',
  ],
  sleep: [
    '【情况分析】失眠问题可能与您的阴虚体质有关,阴虚容易导致心神不宁。',
    '【建议】\n1. 睡前避免使用电子设备\n2. 保持卧室温度适宜\n3. 睡前可以泡脚、喝温牛奶',
    '【用药参考】\n- 酸枣仁膏:睡前30分钟服用(建议咨询药师)',
    '【推荐调养产品】\n- 酸枣仁百合膏 ¥58 [点击购买](https://mall.example.com/product/30)',
    '【提醒】如长期严重失眠,建议到医院睡眠科就诊。',
  ],
  joint: [
    '【情况分析】关节疼痛在中老年人群中较为常见,可能与骨关节退化有关。',
    '【建议】\n1. 适度运动,避免长时间保持同一姿势\n2. 注意关节保暖\n3. 控制体重减轻关节负担',
    '【用药参考】\n- 氨糖软骨素:每日1-2次,每次2粒(建议咨询药师)',
    '【推荐调养产品】\n- 氨糖软骨素钙片 ¥168 [点击购买](https://mall.example.com/product/24)',
    '【提醒】如关节疼痛加重或出现红肿,请及时就医。',
  ],
  default: [
    '感谢您的咨询!根据您的描述,我为您提供以下建议:',
    '1. 保持良好的作息习惯\n2. 均衡饮食,多吃蔬果\n3. 适当运动,增强体质',
    '如果症状持续或加重,建议您及时就医检查。还有其他问题吗?',
  ],
};

// 模拟对话历史
export const mockConversations: Conversation[] = [
  {
    id: '1',
    title: '关于疲劳的咨询',
    messages: [
      { id: '1-1', role: 'user', content: '最近总是感觉很累,没精神', createdAt: '2024-01-15T10:00:00Z' },
      { id: '1-2', role: 'assistant', content: chatTemplates.fatigue.join('\n\n'), createdAt: '2024-01-15T10:00:05Z' },
    ],
    createdAt: '2024-01-15T10:00:00Z',
    updatedAt: '2024-01-15T10:00:05Z',
  },
  {
    id: '2',
    title: '睡眠问题咨询',
    messages: [
      { id: '2-1', role: 'user', content: '晚上睡不着觉怎么办', createdAt: '2024-01-14T22:00:00Z' },
      { id: '2-2', role: 'assistant', content: chatTemplates.sleep.join('\n\n'), createdAt: '2024-01-14T22:00:05Z' },
    ],
    createdAt: '2024-01-14T22:00:00Z',
    updatedAt: '2024-01-14T22:00:05Z',
  },
];

// 模拟AI回复
export const mockAIReply = (message: string): Promise<string> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      // 简单关键词匹配
      const lowerMsg = message.toLowerCase();
      
      if (lowerMsg.includes('累') || lowerMsg.includes('疲劳') || lowerMsg.includes('没精神')) {
        resolve(chatTemplates.fatigue.join('\n\n'));
      } else if (lowerMsg.includes('睡') || lowerMsg.includes('失眠')) {
        resolve(chatTemplates.sleep.join('\n\n'));
      } else if (lowerMsg.includes('关节') || lowerMsg.includes('腿疼') || lowerMsg.includes('膝盖')) {
        resolve(chatTemplates.joint.join('\n\n'));
      } else if (lowerMsg.includes('你好') || lowerMsg.includes('在吗')) {
        resolve(chatTemplates.greeting.join('\n\n'));
      } else {
        resolve(chatTemplates.default.join('\n\n'));
      }
    }, 1500); // 模拟网络延迟
  });
};

4.5 产品模拟数据 src/mock/products.ts

import { Product } from '../types';

export const mockProducts: Product[] = [
  // 补气类
  { id: 1, name: '黄芪精口服液', category: '补气类', description: '补气固表,增强免疫力', efficacy: '适用于气虚质、易疲劳人群', price: 68, imageUrl: '', mallUrl: 'https://mall.example.com/product/1' },
  { id: 2, name: '人参蜂王浆', category: '补气类', description: '补气养血,改善疲劳', efficacy: '适用于气虚质、体力不足人群', price: 128, imageUrl: '', mallUrl: 'https://mall.example.com/product/2' },
  
  // 温阳类
  { id: 4, name: '鹿茸参精胶囊', category: '温阳类', description: '温肾壮阳,补气养血', efficacy: '适用于阳虚质、畏寒怕冷人群', price: 268, imageUrl: '', mallUrl: 'https://mall.example.com/product/4' },
  { id: 5, name: '桂圆红枣茶', category: '温阳类', description: '温中补血,养心安神', efficacy: '适用于阳虚质、手脚冰凉人群', price: 45, imageUrl: '', mallUrl: 'https://mall.example.com/product/5' },
  
  // 滋阴类
  { id: 6, name: '枸杞原浆', category: '滋阴类', description: '滋补肝肾,明目润肺', efficacy: '适用于阴虚质、眼睛干涩人群', price: 158, imageUrl: '', mallUrl: 'https://mall.example.com/product/6' },
  
  // 心脑血管类
  { id: 21, name: '深海鱼油软胶囊', category: '心脑血管类', description: '辅助降血脂,保护心脑血管', efficacy: '适用于高血脂、动脉硬化人群', price: 128, imageUrl: '', mallUrl: 'https://mall.example.com/product/21' },
  { id: 22, name: '纳豆激酶胶囊', category: '心脑血管类', description: '溶解血栓,改善血液循环', efficacy: '适用于中老年心脑血管亚健康人群', price: 198, imageUrl: '', mallUrl: 'https://mall.example.com/product/22' },
  
  // 骨关节类
  { id: 24, name: '氨糖软骨素钙片', category: '骨关节类', description: '修复软骨,润滑关节,补充钙质', efficacy: '适用于关节疼痛、骨质疏松人群', price: 168, imageUrl: '', mallUrl: 'https://mall.example.com/product/24' },
  { id: 25, name: '液体钙维D软胶囊', category: '骨关节类', description: '补钙,促进钙吸收,预防骨质疏松', efficacy: '适用于中老年人、骨质疏松人群', price: 78, imageUrl: '', mallUrl: 'https://mall.example.com/product/25' },
  
  // 助眠安神类
  { id: 29, name: '褪黑素维生素B6片', category: '助眠安神类', description: '改善睡眠,调节生物钟', efficacy: '适用于失眠、睡眠质量差人群', price: 68, imageUrl: '', mallUrl: 'https://mall.example.com/product/29' },
  { id: 30, name: '酸枣仁百合膏', category: '助眠安神类', description: '养心安神,改善睡眠', efficacy: '适用于心烦失眠、多梦易醒人群', price: 58, imageUrl: '', mallUrl: 'https://mall.example.com/product/30' },
  
  // 增强免疫类
  { id: 36, name: '灵芝孢子粉胶囊', category: '增强免疫类', description: '增强免疫力,抗疲劳', efficacy: '适用于免疫力低下、体质虚弱人群', price: 298, imageUrl: '', mallUrl: 'https://mall.example.com/product/36' },
];

// 根据体质获取推荐产品
export const getProductsByConstitution = (constitutionType: string): Product[] => {
  const mapping: Record<string, number[]> = {
    qixu: [1, 2, 36],
    yangxu: [4, 5],
    yinxu: [6, 30],
    tanshi: [9, 10],
    xueyu: [21, 22],
    pinghe: [20, 36],
  };
  
  const ids = mapping[constitutionType] || [20, 36];
  return mockProducts.filter((p) => ids.includes(p.id));
};

4.6 统一导出 src/mock/index.ts

export * from './user';
export * from './constitution';
export * from './chat';
export * from './products';

步骤 5:创建主题配置

创建 src/theme/index.ts

import { MD3LightTheme } from 'react-native-paper';

export const theme = {
  ...MD3LightTheme,
  colors: {
    ...MD3LightTheme.colors,
    primary: '#52C41A',       // 主色调 - 健康绿
    secondary: '#1890FF',     // 辅助色 - 蓝色
    background: '#F5F5F5',    // 背景色
    surface: '#FFFFFF',       // 卡片背景
    error: '#FF4D4F',         // 错误色
    text: '#333333',          // 主要文字
    textSecondary: '#666666', // 次要文字
    border: '#E8E8E8',        // 边框色
  },
  roundness: 12,              // 圆角
};

export const spacing = {
  xs: 4,
  sm: 8,
  md: 16,
  lg: 24,
  xl: 32,
};

验收标准

  • React Native 项目创建成功
  • 所有依赖安装完成
  • 目录结构创建完成
  • 模拟数据文件创建完成
  • 类型定义完整
  • 项目可正常启动(空白页面)

预计耗时

40-60 分钟


下一步

完成后进入 02-APP原型开发/02-导航和布局设计.md