@coze-arch/cli 0.0.1-alpha.01c0ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -0
- package/bin/main +2 -0
- package/lib/__templates__/expo/.coze +12 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +229 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
- package/lib/__templates__/expo/README.md +74 -0
- package/lib/__templates__/expo/_gitignore +11 -0
- package/lib/__templates__/expo/_npmrc +20 -0
- package/lib/__templates__/expo/client/app/+not-found.tsx +30 -0
- package/lib/__templates__/expo/client/app/_layout.tsx +36 -0
- package/lib/__templates__/expo/client/app/index.tsx +1 -0
- package/lib/__templates__/expo/client/app.config.ts +76 -0
- package/lib/__templates__/expo/client/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/lib/__templates__/expo/client/assets/images/adaptive-icon.png +0 -0
- package/lib/__templates__/expo/client/assets/images/default-avatar.png +0 -0
- package/lib/__templates__/expo/client/assets/images/favicon.png +0 -0
- package/lib/__templates__/expo/client/assets/images/icon.png +0 -0
- package/lib/__templates__/expo/client/assets/images/partial-react-logo.png +0 -0
- package/lib/__templates__/expo/client/assets/images/react-logo.png +0 -0
- package/lib/__templates__/expo/client/assets/images/react-logo@2x.png +0 -0
- package/lib/__templates__/expo/client/assets/images/react-logo@3x.png +0 -0
- package/lib/__templates__/expo/client/assets/images/splash-icon.png +0 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +314 -0
- package/lib/__templates__/expo/client/components/SmartDateInput.tsx +238 -0
- package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
- package/lib/__templates__/expo/client/components/ThemedView.tsx +37 -0
- package/lib/__templates__/expo/client/constants/theme.ts +177 -0
- package/lib/__templates__/expo/client/contexts/AuthContext.tsx +49 -0
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/client/eslint-formatter-simple.mjs +49 -0
- package/lib/__templates__/expo/client/eslint.config.mjs +128 -0
- package/lib/__templates__/expo/client/hooks/useColorScheme.tsx +48 -0
- package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
- package/lib/__templates__/expo/client/hooks/useTheme.ts +33 -0
- package/lib/__templates__/expo/client/metro.config.js +124 -0
- package/lib/__templates__/expo/client/package.json +95 -0
- package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
- package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +105 -0
- package/lib/__templates__/expo/client/tsconfig.json +24 -0
- package/lib/__templates__/expo/client/utils/index.ts +76 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
- package/lib/__templates__/expo/package.json +25 -0
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +12657 -0
- package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +34 -0
- package/lib/__templates__/expo/server/src/index.ts +20 -0
- package/lib/__templates__/expo/server/tsconfig.json +24 -0
- package/lib/__templates__/expo/template.config.js +106 -0
- package/lib/__templates__/expo/tsconfig.json +1 -0
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/.babelrc +15 -0
- package/lib/__templates__/nextjs/.coze +12 -0
- package/lib/__templates__/nextjs/README.md +363 -0
- package/lib/__templates__/nextjs/_gitignore +99 -0
- package/lib/__templates__/nextjs/_npmrc +23 -0
- package/lib/__templates__/nextjs/components.json +21 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +23 -0
- package/lib/__templates__/nextjs/next-env.d.ts +6 -0
- package/lib/__templates__/nextjs/next.config.ts +18 -0
- package/lib/__templates__/nextjs/package.json +93 -0
- package/lib/__templates__/nextjs/pnpm-lock.yaml +12404 -0
- package/lib/__templates__/nextjs/postcss.config.mjs +7 -0
- package/lib/__templates__/nextjs/public/file.svg +1 -0
- package/lib/__templates__/nextjs/public/globe.svg +1 -0
- package/lib/__templates__/nextjs/public/next.svg +1 -0
- package/lib/__templates__/nextjs/public/vercel.svg +1 -0
- package/lib/__templates__/nextjs/public/window.svg +1 -0
- package/lib/__templates__/nextjs/scripts/build.sh +17 -0
- package/lib/__templates__/nextjs/scripts/dev.sh +39 -0
- package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
- package/lib/__templates__/nextjs/scripts/start.sh +21 -0
- package/lib/__templates__/nextjs/src/app/favicon.ico +0 -0
- package/lib/__templates__/nextjs/src/app/globals.css +137 -0
- package/lib/__templates__/nextjs/src/app/layout.tsx +74 -0
- package/lib/__templates__/nextjs/src/app/page.tsx +35 -0
- package/lib/__templates__/nextjs/src/app/robots.ts +11 -0
- package/lib/__templates__/nextjs/src/components/ui/accordion.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/alert-dialog.tsx +157 -0
- package/lib/__templates__/nextjs/src/components/ui/alert.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/aspect-ratio.tsx +11 -0
- package/lib/__templates__/nextjs/src/components/ui/avatar.tsx +53 -0
- package/lib/__templates__/nextjs/src/components/ui/badge.tsx +46 -0
- package/lib/__templates__/nextjs/src/components/ui/breadcrumb.tsx +109 -0
- package/lib/__templates__/nextjs/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/nextjs/src/components/ui/button.tsx +62 -0
- package/lib/__templates__/nextjs/src/components/ui/calendar.tsx +220 -0
- package/lib/__templates__/nextjs/src/components/ui/card.tsx +92 -0
- package/lib/__templates__/nextjs/src/components/ui/carousel.tsx +241 -0
- package/lib/__templates__/nextjs/src/components/ui/chart.tsx +357 -0
- package/lib/__templates__/nextjs/src/components/ui/checkbox.tsx +32 -0
- package/lib/__templates__/nextjs/src/components/ui/collapsible.tsx +33 -0
- package/lib/__templates__/nextjs/src/components/ui/command.tsx +184 -0
- package/lib/__templates__/nextjs/src/components/ui/context-menu.tsx +252 -0
- package/lib/__templates__/nextjs/src/components/ui/dialog.tsx +143 -0
- package/lib/__templates__/nextjs/src/components/ui/drawer.tsx +135 -0
- package/lib/__templates__/nextjs/src/components/ui/dropdown-menu.tsx +257 -0
- package/lib/__templates__/nextjs/src/components/ui/empty.tsx +104 -0
- package/lib/__templates__/nextjs/src/components/ui/field.tsx +248 -0
- package/lib/__templates__/nextjs/src/components/ui/form.tsx +167 -0
- package/lib/__templates__/nextjs/src/components/ui/hover-card.tsx +44 -0
- package/lib/__templates__/nextjs/src/components/ui/input-group.tsx +170 -0
- package/lib/__templates__/nextjs/src/components/ui/input-otp.tsx +77 -0
- package/lib/__templates__/nextjs/src/components/ui/input.tsx +21 -0
- package/lib/__templates__/nextjs/src/components/ui/item.tsx +193 -0
- package/lib/__templates__/nextjs/src/components/ui/kbd.tsx +28 -0
- package/lib/__templates__/nextjs/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/nextjs/src/components/ui/menubar.tsx +276 -0
- package/lib/__templates__/nextjs/src/components/ui/navigation-menu.tsx +168 -0
- package/lib/__templates__/nextjs/src/components/ui/pagination.tsx +127 -0
- package/lib/__templates__/nextjs/src/components/ui/popover.tsx +48 -0
- package/lib/__templates__/nextjs/src/components/ui/progress.tsx +31 -0
- package/lib/__templates__/nextjs/src/components/ui/radio-group.tsx +45 -0
- package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +63 -0
- package/lib/__templates__/nextjs/src/components/ui/scroll-area.tsx +58 -0
- package/lib/__templates__/nextjs/src/components/ui/select.tsx +190 -0
- package/lib/__templates__/nextjs/src/components/ui/separator.tsx +28 -0
- package/lib/__templates__/nextjs/src/components/ui/sheet.tsx +139 -0
- package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +724 -0
- package/lib/__templates__/nextjs/src/components/ui/skeleton.tsx +13 -0
- package/lib/__templates__/nextjs/src/components/ui/slider.tsx +63 -0
- package/lib/__templates__/nextjs/src/components/ui/sonner.tsx +40 -0
- package/lib/__templates__/nextjs/src/components/ui/spinner.tsx +16 -0
- package/lib/__templates__/nextjs/src/components/ui/switch.tsx +31 -0
- package/lib/__templates__/nextjs/src/components/ui/table.tsx +116 -0
- package/lib/__templates__/nextjs/src/components/ui/tabs.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/textarea.tsx +18 -0
- package/lib/__templates__/nextjs/src/components/ui/toggle-group.tsx +83 -0
- package/lib/__templates__/nextjs/src/components/ui/toggle.tsx +47 -0
- package/lib/__templates__/nextjs/src/components/ui/tooltip.tsx +61 -0
- package/lib/__templates__/nextjs/src/hooks/use-mobile.ts +19 -0
- package/lib/__templates__/nextjs/src/lib/utils.ts +6 -0
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/template.config.js +120 -0
- package/lib/__templates__/nextjs/tsconfig.json +34 -0
- package/lib/__templates__/nuxt-vue/.coze +12 -0
- package/lib/__templates__/nuxt-vue/README.md +73 -0
- package/lib/__templates__/nuxt-vue/_gitignore +24 -0
- package/lib/__templates__/nuxt-vue/_npmrc +23 -0
- package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
- package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
- package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
- package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
- package/lib/__templates__/nuxt-vue/package.json +35 -0
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
- package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
- package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
- package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +39 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -0
- package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
- package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
- package/lib/__templates__/nuxt-vue/template.config.js +87 -0
- package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
- package/lib/__templates__/taro/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
- package/lib/__templates__/taro/README.md +763 -0
- package/lib/__templates__/taro/_gitignore +40 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +237 -0
- package/lib/__templates__/taro/config/prod.ts +34 -0
- package/lib/__templates__/taro/eslint.config.mjs +135 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +112 -0
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +23412 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +40 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +156 -0
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
- package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
- package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
- package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
- package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
- package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
- package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
- package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
- package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
- package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
- package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
- package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
- package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
- package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
- package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
- package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
- package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
- package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
- package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
- package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
- package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
- package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
- package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
- package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
- package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
- package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
- package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
- package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
- package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
- package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
- package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
- package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
- package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
- package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
- package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
- package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
- package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
- package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
- package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
- package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
- package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
- package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
- package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
- package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
- package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
- package/lib/__templates__/taro/src/lib/measure.ts +115 -0
- package/lib/__templates__/taro/src/lib/platform.ts +12 -0
- package/lib/__templates__/taro/src/lib/utils.ts +6 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +238 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +220 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +162 -0
- package/lib/__templates__/vite/.coze +12 -0
- package/lib/__templates__/vite/README.md +418 -0
- package/lib/__templates__/vite/_gitignore +67 -0
- package/lib/__templates__/vite/_npmrc +23 -0
- package/lib/__templates__/vite/eslint.config.mjs +14 -0
- package/lib/__templates__/vite/index.html +13 -0
- package/lib/__templates__/vite/package.json +44 -0
- package/lib/__templates__/vite/pnpm-lock.yaml +3465 -0
- package/lib/__templates__/vite/postcss.config.js +6 -0
- package/lib/__templates__/vite/scripts/build.sh +17 -0
- package/lib/__templates__/vite/scripts/dev.sh +39 -0
- package/lib/__templates__/vite/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite/scripts/start.sh +21 -0
- package/lib/__templates__/vite/server/routes/index.ts +31 -0
- package/lib/__templates__/vite/server/server.ts +65 -0
- package/lib/__templates__/vite/server/vite.ts +67 -0
- package/lib/__templates__/vite/src/index.css +21 -0
- package/lib/__templates__/vite/src/index.ts +5 -0
- package/lib/__templates__/vite/src/main.ts +34 -0
- package/lib/__templates__/vite/tailwind.config.js +9 -0
- package/lib/__templates__/vite/template.config.js +127 -0
- package/lib/__templates__/vite/tsconfig.json +17 -0
- package/lib/__templates__/vite/vite.config.ts +20 -0
- package/lib/cli.js +2631 -0
- package/package.json +81 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Keyboard,
|
|
8
|
+
Platform,
|
|
9
|
+
useColorScheme,
|
|
10
|
+
ViewStyle,
|
|
11
|
+
TextStyle
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import DateTimePickerModal from 'react-native-modal-datetime-picker';
|
|
14
|
+
import dayjs from 'dayjs';
|
|
15
|
+
import { FontAwesome6 } from '@expo/vector-icons';
|
|
16
|
+
|
|
17
|
+
// --------------------------------------------------------
|
|
18
|
+
// 1. 配置 Dayjs
|
|
19
|
+
// --------------------------------------------------------
|
|
20
|
+
// 即使服务端返回 '2023-10-20T10:00:00Z' (UTC),
|
|
21
|
+
// dayjs(utcString).format() 会自动转为手机当前的本地时区显示。
|
|
22
|
+
// 如果需要传回给后端,我们再转回 ISO 格式。
|
|
23
|
+
|
|
24
|
+
interface SmartDateInputProps {
|
|
25
|
+
label?: string; // 表单标题 (可选)
|
|
26
|
+
value?: string | null; // 服务端返回的时间字符串 (ISO 8601, 带 T)
|
|
27
|
+
onChange: (isoDate: string) => void; // 回调给父组件的值,依然是标准 ISO 字符串
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
mode?: 'date' | 'time' | 'datetime'; // 支持日期、时间、或两者
|
|
30
|
+
displayFormat?: string; // UI展示的格式,默认 YYYY-MM-DD
|
|
31
|
+
error?: string; // 错误信息
|
|
32
|
+
|
|
33
|
+
// 样式自定义(可选)
|
|
34
|
+
containerStyle?: ViewStyle; // 外层容器样式
|
|
35
|
+
inputStyle?: ViewStyle; // 输入框样式
|
|
36
|
+
textStyle?: TextStyle; // 文字样式
|
|
37
|
+
labelStyle?: TextStyle; // 标签样式
|
|
38
|
+
placeholderTextStyle?: TextStyle; // 占位符文字样式
|
|
39
|
+
errorTextStyle?: TextStyle; // 错误信息文字样式
|
|
40
|
+
iconColor?: string; // 图标颜色
|
|
41
|
+
iconSize?: number; // 图标大小
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const SmartDateInput = ({
|
|
45
|
+
label,
|
|
46
|
+
value,
|
|
47
|
+
onChange,
|
|
48
|
+
placeholder = '请选择',
|
|
49
|
+
mode = 'date',
|
|
50
|
+
displayFormat,
|
|
51
|
+
error,
|
|
52
|
+
containerStyle,
|
|
53
|
+
inputStyle,
|
|
54
|
+
textStyle,
|
|
55
|
+
labelStyle,
|
|
56
|
+
placeholderTextStyle,
|
|
57
|
+
errorTextStyle,
|
|
58
|
+
iconColor,
|
|
59
|
+
iconSize = 18
|
|
60
|
+
}: SmartDateInputProps) => {
|
|
61
|
+
const [isDatePickerVisible, setDatePickerVisibility] = useState(false);
|
|
62
|
+
const colorScheme = useColorScheme();
|
|
63
|
+
const isDark = colorScheme === 'dark';
|
|
64
|
+
|
|
65
|
+
// 默认展示格式
|
|
66
|
+
const format = displayFormat || (mode === 'time' ? 'HH:mm' : 'YYYY-MM-DD');
|
|
67
|
+
|
|
68
|
+
// --------------------------------------------------------
|
|
69
|
+
// 2. 核心:数据转换逻辑
|
|
70
|
+
// --------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
// 解析服务端值,确保无效值不传给控件;time 模式兼容仅时间字符串
|
|
73
|
+
const parsedValue = useMemo(() => {
|
|
74
|
+
if (!value) return null;
|
|
75
|
+
|
|
76
|
+
const direct = dayjs(value);
|
|
77
|
+
if (direct.isValid()) return direct;
|
|
78
|
+
|
|
79
|
+
if (mode === 'time') {
|
|
80
|
+
const timeOnly = dayjs(`1970-01-01T${value}`);
|
|
81
|
+
if (timeOnly.isValid()) return timeOnly;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
}, [value, mode]);
|
|
86
|
+
|
|
87
|
+
// A. 将字符串转为 JS Date 对象给控件使用
|
|
88
|
+
// 如果 value 是空或无效,回退到当前时间
|
|
89
|
+
const dateObjectForPicker = useMemo(() => {
|
|
90
|
+
return parsedValue ? parsedValue.toDate() : new Date();
|
|
91
|
+
}, [parsedValue]);
|
|
92
|
+
|
|
93
|
+
// B. 将 Date 对象转为展示字符串
|
|
94
|
+
const displayString = useMemo(() => {
|
|
95
|
+
if (!parsedValue) return '';
|
|
96
|
+
return parsedValue.format(format);
|
|
97
|
+
}, [parsedValue, format]);
|
|
98
|
+
|
|
99
|
+
// --------------------------------------------------------
|
|
100
|
+
// 3. 核心:交互逻辑 (解决键盘遮挡/无法收起)
|
|
101
|
+
// --------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
const showDatePicker = () => {
|
|
104
|
+
// 【关键点】打开日期控件前,必须强制收起键盘!
|
|
105
|
+
// 否则键盘会遮挡 iOS 的底部滚轮,或者导致 Android 焦点混乱
|
|
106
|
+
Keyboard.dismiss();
|
|
107
|
+
setDatePickerVisibility(true);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const hideDatePicker = () => {
|
|
111
|
+
setDatePickerVisibility(false);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleConfirm = (date: Date) => {
|
|
115
|
+
hideDatePicker();
|
|
116
|
+
// 采用带本地偏移的 ISO 字符串,避免 date 模式在非 UTC 时区出现跨天
|
|
117
|
+
const serverString = dayjs(date).format(format);
|
|
118
|
+
onChange(serverString);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// 根据 mode 选择图标
|
|
122
|
+
const iconName = mode === 'time' ? 'clock' : 'calendar';
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<View style={[styles.container, containerStyle]}>
|
|
126
|
+
{/* 标题 */}
|
|
127
|
+
{label && <Text style={[styles.label, labelStyle]}>{label}</Text>}
|
|
128
|
+
|
|
129
|
+
{/*
|
|
130
|
+
这里用 TouchableOpacity 模拟 Input。
|
|
131
|
+
模拟组件永远不会唤起键盘。
|
|
132
|
+
*/}
|
|
133
|
+
<TouchableOpacity
|
|
134
|
+
style={[
|
|
135
|
+
styles.inputBox,
|
|
136
|
+
error ? styles.inputBoxError : null,
|
|
137
|
+
inputStyle
|
|
138
|
+
]}
|
|
139
|
+
onPress={showDatePicker}
|
|
140
|
+
activeOpacity={0.7}
|
|
141
|
+
>
|
|
142
|
+
<Text
|
|
143
|
+
style={[
|
|
144
|
+
styles.text,
|
|
145
|
+
textStyle,
|
|
146
|
+
!value && styles.placeholder,
|
|
147
|
+
!value && placeholderTextStyle
|
|
148
|
+
]}
|
|
149
|
+
numberOfLines={1}
|
|
150
|
+
>
|
|
151
|
+
{displayString || placeholder}
|
|
152
|
+
</Text>
|
|
153
|
+
|
|
154
|
+
<FontAwesome6
|
|
155
|
+
name={iconName}
|
|
156
|
+
size={iconSize}
|
|
157
|
+
color={iconColor || (value ? '#4B5563' : '#9CA3AF')}
|
|
158
|
+
style={styles.icon}
|
|
159
|
+
/>
|
|
160
|
+
</TouchableOpacity>
|
|
161
|
+
|
|
162
|
+
{error && <Text style={[styles.errorText, errorTextStyle]}>{error}</Text>}
|
|
163
|
+
|
|
164
|
+
{/*
|
|
165
|
+
DateTimePickerModal 是 React Native Modal。
|
|
166
|
+
它会覆盖在所有 View 之上。
|
|
167
|
+
*/}
|
|
168
|
+
<DateTimePickerModal
|
|
169
|
+
isVisible={isDatePickerVisible}
|
|
170
|
+
mode={mode}
|
|
171
|
+
date={dateObjectForPicker} // 传入 Date 对象
|
|
172
|
+
onConfirm={handleConfirm}
|
|
173
|
+
onCancel={hideDatePicker}
|
|
174
|
+
// iOS 只有用这个 display 样式才最稳,避免乱七八糟的 inline 样式
|
|
175
|
+
display={Platform.OS === 'ios' ? 'spinner' : 'default'}
|
|
176
|
+
// 自动适配系统深色模式,或者根据 isDark 变量控制
|
|
177
|
+
isDarkModeEnabled={isDark}
|
|
178
|
+
// 强制使用中文环境
|
|
179
|
+
locale="zh-CN"
|
|
180
|
+
confirmTextIOS="确定"
|
|
181
|
+
cancelTextIOS="取消"
|
|
182
|
+
/>
|
|
183
|
+
</View>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// 设计样式
|
|
188
|
+
const styles = StyleSheet.create({
|
|
189
|
+
container: {
|
|
190
|
+
marginBottom: 20,
|
|
191
|
+
},
|
|
192
|
+
label: {
|
|
193
|
+
fontSize: 14,
|
|
194
|
+
fontWeight: '600',
|
|
195
|
+
color: '#374151', // Gray 700
|
|
196
|
+
marginBottom: 8,
|
|
197
|
+
marginLeft: 2,
|
|
198
|
+
},
|
|
199
|
+
inputBox: {
|
|
200
|
+
height: 52, // 增加高度提升触控体验
|
|
201
|
+
backgroundColor: '#FFFFFF',
|
|
202
|
+
borderRadius: 12, // 更圆润的角
|
|
203
|
+
flexDirection: 'row',
|
|
204
|
+
alignItems: 'center',
|
|
205
|
+
justifyContent: 'space-between',
|
|
206
|
+
paddingHorizontal: 16,
|
|
207
|
+
borderWidth: 1,
|
|
208
|
+
borderColor: '#E5E7EB', // Gray 200
|
|
209
|
+
// 增加轻微阴影提升层次感 (iOS)
|
|
210
|
+
shadowColor: '#000',
|
|
211
|
+
shadowOffset: { width: 0, height: 1 },
|
|
212
|
+
shadowOpacity: 0.05,
|
|
213
|
+
shadowRadius: 2,
|
|
214
|
+
// Android
|
|
215
|
+
elevation: 1,
|
|
216
|
+
},
|
|
217
|
+
inputBoxError: {
|
|
218
|
+
borderColor: '#EF4444', // Red 500
|
|
219
|
+
backgroundColor: '#FEF2F2', // Red 50
|
|
220
|
+
},
|
|
221
|
+
text: {
|
|
222
|
+
fontSize: 16,
|
|
223
|
+
color: '#111827', // Gray 900
|
|
224
|
+
flex: 1,
|
|
225
|
+
},
|
|
226
|
+
placeholder: {
|
|
227
|
+
color: '#9CA3AF', // Gray 400 - 标准占位符颜色
|
|
228
|
+
},
|
|
229
|
+
icon: {
|
|
230
|
+
marginLeft: 12,
|
|
231
|
+
},
|
|
232
|
+
errorText: {
|
|
233
|
+
marginTop: 4,
|
|
234
|
+
marginLeft: 2,
|
|
235
|
+
fontSize: 12,
|
|
236
|
+
color: '#EF4444',
|
|
237
|
+
}
|
|
238
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text, TextProps, TextStyle } from 'react-native';
|
|
3
|
+
import { useTheme } from '@/hooks/useTheme';
|
|
4
|
+
import { Typography } from '@/constants/theme';
|
|
5
|
+
|
|
6
|
+
type TypographyVariant = keyof typeof Typography;
|
|
7
|
+
|
|
8
|
+
interface ThemedTextProps extends TextProps {
|
|
9
|
+
variant?: TypographyVariant;
|
|
10
|
+
color?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ThemedText({
|
|
14
|
+
variant = 'body',
|
|
15
|
+
color,
|
|
16
|
+
style,
|
|
17
|
+
children,
|
|
18
|
+
...props
|
|
19
|
+
}: ThemedTextProps) {
|
|
20
|
+
const { theme } = useTheme();
|
|
21
|
+
const typographyStyle = Typography[variant];
|
|
22
|
+
|
|
23
|
+
const textStyle: TextStyle = {
|
|
24
|
+
...typographyStyle,
|
|
25
|
+
color: color ?? theme.textPrimary,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Text style={[textStyle, style]} {...props}>
|
|
30
|
+
{children}
|
|
31
|
+
</Text>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, ViewProps, ViewStyle } from 'react-native';
|
|
3
|
+
import { useTheme } from '@/hooks/useTheme';
|
|
4
|
+
|
|
5
|
+
type BackgroundLevel = 'root' | 'default' | 'tertiary';
|
|
6
|
+
|
|
7
|
+
interface ThemedViewProps extends ViewProps {
|
|
8
|
+
level?: BackgroundLevel;
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const backgroundMap: Record<BackgroundLevel, string> = {
|
|
13
|
+
root: 'backgroundRoot',
|
|
14
|
+
default: 'backgroundDefault',
|
|
15
|
+
tertiary: 'backgroundTertiary',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function ThemedView({
|
|
19
|
+
level = 'root',
|
|
20
|
+
backgroundColor,
|
|
21
|
+
style,
|
|
22
|
+
children,
|
|
23
|
+
...props
|
|
24
|
+
}: ThemedViewProps) {
|
|
25
|
+
const { theme } = useTheme();
|
|
26
|
+
const bgColor = backgroundColor ?? (theme as any)[backgroundMap[level]];
|
|
27
|
+
|
|
28
|
+
const viewStyle: ViewStyle = {
|
|
29
|
+
backgroundColor: bgColor,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<View style={[viewStyle, style]} {...props}>
|
|
34
|
+
{children}
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export const Colors = {
|
|
2
|
+
light: {
|
|
3
|
+
textPrimary: "#1C1917",
|
|
4
|
+
textSecondary: "#78716c",
|
|
5
|
+
textMuted: "#9CA3AF",
|
|
6
|
+
primary: "#4F46E5", // Indigo-600 - 品牌主色,代表科技与智能
|
|
7
|
+
accent: "#8B5CF6", // Violet-500 - 辅助色,代表创造力
|
|
8
|
+
success: "#10B981", // Emerald-500
|
|
9
|
+
error: "#EF4444",
|
|
10
|
+
backgroundRoot: "#FAFAFA",
|
|
11
|
+
backgroundDefault: "#FFFFFF",
|
|
12
|
+
backgroundTertiary: "#F9FAFB", // 更浅的背景色,用于去线留白
|
|
13
|
+
buttonPrimaryText: "#FFFFFF",
|
|
14
|
+
tabIconSelected: "#4F46E5",
|
|
15
|
+
border: "#E5E7EB",
|
|
16
|
+
borderLight: "#F3F4F6",
|
|
17
|
+
},
|
|
18
|
+
dark: {
|
|
19
|
+
textPrimary: "#FAFAF9",
|
|
20
|
+
textSecondary: "#A8A29E",
|
|
21
|
+
textMuted: "#6F767E",
|
|
22
|
+
primary: "#818CF8", // Indigo-400 - 暗色模式品牌主色
|
|
23
|
+
accent: "#A78BFA", // Violet-400
|
|
24
|
+
success: "#34D399",
|
|
25
|
+
error: "#F87171",
|
|
26
|
+
backgroundRoot: "#09090B", // 更深的背景色
|
|
27
|
+
backgroundDefault: "#1C1C1E",
|
|
28
|
+
backgroundTertiary: "#1F1F22", // 暗色模式去线留白背景
|
|
29
|
+
buttonPrimaryText: "#09090B",
|
|
30
|
+
tabIconSelected: "#818CF8",
|
|
31
|
+
border: "#3F3F46",
|
|
32
|
+
borderLight: "#27272A",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const Spacing = {
|
|
37
|
+
xs: 4,
|
|
38
|
+
sm: 8,
|
|
39
|
+
md: 12,
|
|
40
|
+
lg: 16,
|
|
41
|
+
xl: 20,
|
|
42
|
+
"2xl": 24,
|
|
43
|
+
"3xl": 32,
|
|
44
|
+
"4xl": 40,
|
|
45
|
+
"5xl": 48,
|
|
46
|
+
"6xl": 64,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const BorderRadius = {
|
|
50
|
+
xs: 4,
|
|
51
|
+
sm: 8,
|
|
52
|
+
md: 12,
|
|
53
|
+
lg: 16,
|
|
54
|
+
xl: 20,
|
|
55
|
+
"2xl": 24,
|
|
56
|
+
"3xl": 28,
|
|
57
|
+
"4xl": 32,
|
|
58
|
+
full: 9999,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const Typography = {
|
|
62
|
+
display: {
|
|
63
|
+
fontSize: 112,
|
|
64
|
+
lineHeight: 112,
|
|
65
|
+
fontWeight: "200" as const,
|
|
66
|
+
letterSpacing: -4,
|
|
67
|
+
},
|
|
68
|
+
displayLarge: {
|
|
69
|
+
fontSize: 112,
|
|
70
|
+
lineHeight: 112,
|
|
71
|
+
fontWeight: "200" as const,
|
|
72
|
+
letterSpacing: -2,
|
|
73
|
+
},
|
|
74
|
+
displayMedium: {
|
|
75
|
+
fontSize: 48,
|
|
76
|
+
lineHeight: 56,
|
|
77
|
+
fontWeight: "200" as const,
|
|
78
|
+
},
|
|
79
|
+
h1: {
|
|
80
|
+
fontSize: 32,
|
|
81
|
+
lineHeight: 40,
|
|
82
|
+
fontWeight: "700" as const,
|
|
83
|
+
},
|
|
84
|
+
h2: {
|
|
85
|
+
fontSize: 28,
|
|
86
|
+
lineHeight: 36,
|
|
87
|
+
fontWeight: "700" as const,
|
|
88
|
+
},
|
|
89
|
+
h3: {
|
|
90
|
+
fontSize: 24,
|
|
91
|
+
lineHeight: 32,
|
|
92
|
+
fontWeight: "300" as const,
|
|
93
|
+
},
|
|
94
|
+
h4: {
|
|
95
|
+
fontSize: 20,
|
|
96
|
+
lineHeight: 28,
|
|
97
|
+
fontWeight: "600" as const,
|
|
98
|
+
},
|
|
99
|
+
title: {
|
|
100
|
+
fontSize: 18,
|
|
101
|
+
lineHeight: 24,
|
|
102
|
+
fontWeight: "700" as const,
|
|
103
|
+
},
|
|
104
|
+
body: {
|
|
105
|
+
fontSize: 16,
|
|
106
|
+
lineHeight: 24,
|
|
107
|
+
fontWeight: "400" as const,
|
|
108
|
+
},
|
|
109
|
+
bodyMedium: {
|
|
110
|
+
fontSize: 16,
|
|
111
|
+
lineHeight: 24,
|
|
112
|
+
fontWeight: "500" as const,
|
|
113
|
+
},
|
|
114
|
+
small: {
|
|
115
|
+
fontSize: 14,
|
|
116
|
+
lineHeight: 20,
|
|
117
|
+
fontWeight: "400" as const,
|
|
118
|
+
},
|
|
119
|
+
smallMedium: {
|
|
120
|
+
fontSize: 14,
|
|
121
|
+
lineHeight: 20,
|
|
122
|
+
fontWeight: "500" as const,
|
|
123
|
+
},
|
|
124
|
+
caption: {
|
|
125
|
+
fontSize: 12,
|
|
126
|
+
lineHeight: 16,
|
|
127
|
+
fontWeight: "400" as const,
|
|
128
|
+
},
|
|
129
|
+
captionMedium: {
|
|
130
|
+
fontSize: 12,
|
|
131
|
+
lineHeight: 16,
|
|
132
|
+
fontWeight: "500" as const,
|
|
133
|
+
},
|
|
134
|
+
label: {
|
|
135
|
+
fontSize: 14,
|
|
136
|
+
lineHeight: 20,
|
|
137
|
+
fontWeight: "500" as const,
|
|
138
|
+
letterSpacing: 2,
|
|
139
|
+
textTransform: "uppercase" as const,
|
|
140
|
+
},
|
|
141
|
+
labelSmall: {
|
|
142
|
+
fontSize: 12,
|
|
143
|
+
lineHeight: 16,
|
|
144
|
+
fontWeight: "500" as const,
|
|
145
|
+
letterSpacing: 1,
|
|
146
|
+
textTransform: "uppercase" as const,
|
|
147
|
+
},
|
|
148
|
+
labelTitle: {
|
|
149
|
+
fontSize: 14,
|
|
150
|
+
lineHeight: 20,
|
|
151
|
+
fontWeight: "700" as const,
|
|
152
|
+
letterSpacing: 2,
|
|
153
|
+
textTransform: "uppercase" as const,
|
|
154
|
+
},
|
|
155
|
+
link: {
|
|
156
|
+
fontSize: 16,
|
|
157
|
+
lineHeight: 24,
|
|
158
|
+
fontWeight: "400" as const,
|
|
159
|
+
},
|
|
160
|
+
stat: {
|
|
161
|
+
fontSize: 30,
|
|
162
|
+
lineHeight: 36,
|
|
163
|
+
fontWeight: "300" as const,
|
|
164
|
+
},
|
|
165
|
+
tiny: {
|
|
166
|
+
fontSize: 10,
|
|
167
|
+
lineHeight: 14,
|
|
168
|
+
fontWeight: "400" as const,
|
|
169
|
+
},
|
|
170
|
+
navLabel: {
|
|
171
|
+
fontSize: 10,
|
|
172
|
+
lineHeight: 14,
|
|
173
|
+
fontWeight: "500" as const,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export type Theme = typeof Colors.light;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* 通用认证上下文
|
|
4
|
+
*
|
|
5
|
+
* 基于固定的 API 接口实现,可复用到其他项目
|
|
6
|
+
* 其他项目使用时,只需修改 @api 的导入路径指向项目的 api 模块
|
|
7
|
+
*
|
|
8
|
+
* 注意:
|
|
9
|
+
* - 如果需要登录/鉴权场景,请扩展本文件,完善 login/logout、token 管理、用户信息获取与刷新等逻辑
|
|
10
|
+
* - 将示例中的占位实现替换为项目实际的接口调用与状态管理
|
|
11
|
+
*/
|
|
12
|
+
import React, { createContext, useContext, ReactNode } from "react";
|
|
13
|
+
|
|
14
|
+
interface UserOut {
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface AuthContextType {
|
|
19
|
+
user: UserOut | null;
|
|
20
|
+
token: string | null;
|
|
21
|
+
isAuthenticated: boolean;
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
login: (token: string) => Promise<void>;
|
|
24
|
+
logout: () => Promise<void>;
|
|
25
|
+
updateUser: (userData: Partial<UserOut>) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
|
31
|
+
const value: AuthContextType = {
|
|
32
|
+
user: null,
|
|
33
|
+
token: null,
|
|
34
|
+
isAuthenticated: false,
|
|
35
|
+
isLoading: false,
|
|
36
|
+
login: async (token: string) => {},
|
|
37
|
+
logout: async () => {},
|
|
38
|
+
updateUser: () => {},
|
|
39
|
+
};
|
|
40
|
+
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const useAuth = (): AuthContextType => {
|
|
44
|
+
const context = useContext(AuthContext);
|
|
45
|
+
if (context === undefined) {
|
|
46
|
+
throw new Error("useAuth must be used within an AuthProvider");
|
|
47
|
+
}
|
|
48
|
+
return context;
|
|
49
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export default function (results) {
|
|
2
|
+
|
|
3
|
+
return results
|
|
4
|
+
.flatMap(file =>
|
|
5
|
+
file.messages.map(m => {
|
|
6
|
+
// split into lines
|
|
7
|
+
const lines = m.message.split('\n');
|
|
8
|
+
|
|
9
|
+
// 第一行(句子):直接用
|
|
10
|
+
const first = lines[0];
|
|
11
|
+
|
|
12
|
+
// 附加解释:过滤掉所有 codeframe/箭头/行号/重复路径
|
|
13
|
+
const details = lines
|
|
14
|
+
.slice(1)
|
|
15
|
+
.filter(l => {
|
|
16
|
+
// 移除空行
|
|
17
|
+
if (!l.trim()) return false;
|
|
18
|
+
|
|
19
|
+
// 移除 "58 | xxx" 这样的行
|
|
20
|
+
if (/^\s*\d+\s*\|/.test(l)) return false;
|
|
21
|
+
|
|
22
|
+
// 移除 "> 60 | ..." 这样的箭头行
|
|
23
|
+
if (/^\s*>/.test(l)) return false;
|
|
24
|
+
|
|
25
|
+
// 移除只有箭头提示的行,如 "| ^^^^^"
|
|
26
|
+
if (/^\s*\|/.test(l)) return false;
|
|
27
|
+
|
|
28
|
+
// 移除 "…" 省略号行
|
|
29
|
+
if (/^\s*…/.test(l)) return false;
|
|
30
|
+
|
|
31
|
+
// 移除重复路径行(eslint message 有时夹带 file:line)
|
|
32
|
+
if (/\.tsx:\d+:\d+/.test(l)) return false;
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
})
|
|
36
|
+
.join('\n')
|
|
37
|
+
.trim();
|
|
38
|
+
|
|
39
|
+
let output = `${file.filePath}:${m.line}:${m.column} ${
|
|
40
|
+
m.severity === 2 ? 'error' : 'warn'
|
|
41
|
+
} ${first}`;
|
|
42
|
+
|
|
43
|
+
if (details) output += `\n${details}\n`;
|
|
44
|
+
|
|
45
|
+
return output;
|
|
46
|
+
})
|
|
47
|
+
)
|
|
48
|
+
.join('\n');
|
|
49
|
+
};
|