taro-uno-ui 0.9.0-beta
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/LICENSE +100 -0
- package/README.md +273 -0
- package/dist/js/index-6NJ3A1Dn.js +26535 -0
- package/dist/js/index-6NJ3A1Dn.js.map +1 -0
- package/dist/js/index-DFdcksbe.js +1165 -0
- package/dist/js/index-DFdcksbe.js.map +1 -0
- package/dist/js/index-DXRIkWX1.js +1148 -0
- package/dist/js/index-DXRIkWX1.js.map +1 -0
- package/dist/js/index-DffLRSro.js +26519 -0
- package/dist/js/index-DffLRSro.js.map +1 -0
- package/package.json +119 -0
- package/src/app.config.ts +55 -0
- package/src/app.scss +508 -0
- package/src/app.tsx +44 -0
- package/src/components/basic/Button/Button.styles.ts +130 -0
- package/src/components/basic/Button/Button.test.tsx +154 -0
- package/src/components/basic/Button/Button.tsx +93 -0
- package/src/components/basic/Button/Button.types.ts +45 -0
- package/src/components/basic/Button/index.tsx +6 -0
- package/src/components/basic/Divider/Divider.styles.ts +488 -0
- package/src/components/basic/Divider/Divider.test.tsx +551 -0
- package/src/components/basic/Divider/Divider.tsx +361 -0
- package/src/components/basic/Divider/Divider.types.ts +261 -0
- package/src/components/basic/Divider/index.tsx +25 -0
- package/src/components/basic/Icon/Icon.styles.ts +359 -0
- package/src/components/basic/Icon/Icon.test.tsx +357 -0
- package/src/components/basic/Icon/Icon.tsx +154 -0
- package/src/components/basic/Icon/Icon.types.ts +210 -0
- package/src/components/basic/Icon/index.tsx +22 -0
- package/src/components/basic/Text/Text.styles.ts +500 -0
- package/src/components/basic/Text/Text.test.tsx +299 -0
- package/src/components/basic/Text/Text.tsx +340 -0
- package/src/components/basic/Text/Text.types.ts +319 -0
- package/src/components/basic/Text/index.tsx +27 -0
- package/src/components/basic/Typography/Typography.styles.ts +346 -0
- package/src/components/basic/Typography/Typography.tsx +205 -0
- package/src/components/basic/Typography/Typography.types.ts +296 -0
- package/src/components/basic/Typography/index.tsx +14 -0
- package/src/components/basic/index.tsx +302 -0
- package/src/components/common/ErrorBoundary.tsx +87 -0
- package/src/components/common/LazyComponent.tsx +246 -0
- package/src/components/common/ResponsiveContainer.tsx +93 -0
- package/src/components/common/ResponsiveGrid.tsx +183 -0
- package/src/components/common/SecurityProvider.tsx +110 -0
- package/src/components/common/ThemeProvider.tsx +128 -0
- package/src/components/common/VirtualList.tsx +368 -0
- package/src/components/common/__tests__/ErrorBoundary.test.tsx +249 -0
- package/src/components/common/index.tsx +7 -0
- package/src/components/display/Avatar/Avatar.styles.ts +62 -0
- package/src/components/display/Avatar/Avatar.test.tsx +390 -0
- package/src/components/display/Avatar/Avatar.tsx +79 -0
- package/src/components/display/Avatar/Avatar.types.ts +40 -0
- package/src/components/display/Avatar/index.ts +3 -0
- package/src/components/display/Badge/Badge.tsx +42 -0
- package/src/components/display/Badge/Badge.types.ts +29 -0
- package/src/components/display/Badge/index.ts +2 -0
- package/src/components/display/Calendar/Calendar.styles.ts +255 -0
- package/src/components/display/Calendar/Calendar.test.tsx +30 -0
- package/src/components/display/Calendar/Calendar.tsx +337 -0
- package/src/components/display/Calendar/Calendar.types.ts +91 -0
- package/src/components/display/Calendar/index.ts +3 -0
- package/src/components/display/Card/Card.styles.ts +89 -0
- package/src/components/display/Card/Card.test.tsx +180 -0
- package/src/components/display/Card/Card.tsx +135 -0
- package/src/components/display/Card/Card.types.ts +55 -0
- package/src/components/display/Card/index.ts +3 -0
- package/src/components/display/Carousel/Carousel.styles.ts +206 -0
- package/src/components/display/Carousel/Carousel.tsx +295 -0
- package/src/components/display/Carousel/Carousel.types.ts +57 -0
- package/src/components/display/Carousel/index.ts +3 -0
- package/src/components/display/List/List.styles.ts +79 -0
- package/src/components/display/List/List.tsx +115 -0
- package/src/components/display/List/List.types.ts +68 -0
- package/src/components/display/List/index.ts +3 -0
- package/src/components/display/Rate/Rate.styles.ts +266 -0
- package/src/components/display/Rate/Rate.tsx +332 -0
- package/src/components/display/Rate/Rate.types.ts +111 -0
- package/src/components/display/Rate/index.ts +28 -0
- package/src/components/display/Table/Table.styles.ts +269 -0
- package/src/components/display/Table/Table.test.tsx +343 -0
- package/src/components/display/Table/Table.tsx +430 -0
- package/src/components/display/Table/Table.types.ts +255 -0
- package/src/components/display/Table/index.tsx +16 -0
- package/src/components/display/Tag/Tag.styles.ts +197 -0
- package/src/components/display/Tag/Tag.test.tsx +541 -0
- package/src/components/display/Tag/Tag.tsx +156 -0
- package/src/components/display/Tag/Tag.types.ts +49 -0
- package/src/components/display/Tag/index.ts +3 -0
- package/src/components/display/Timeline/Timeline.styles.ts +211 -0
- package/src/components/display/Timeline/Timeline.tsx +239 -0
- package/src/components/display/Timeline/Timeline.types.ts +56 -0
- package/src/components/display/Timeline/index.ts +3 -0
- package/src/components/display/index.tsx +143 -0
- package/src/components/feedback/Loading/Loading.styles.ts +117 -0
- package/src/components/feedback/Loading/Loading.test.tsx +534 -0
- package/src/components/feedback/Loading/Loading.tsx +127 -0
- package/src/components/feedback/Loading/Loading.types.ts +33 -0
- package/src/components/feedback/Loading/index.ts +9 -0
- package/src/components/feedback/Message/Message.styles.ts +41 -0
- package/src/components/feedback/Message/Message.test.tsx +234 -0
- package/src/components/feedback/Message/Message.tsx +96 -0
- package/src/components/feedback/Message/Message.types.ts +37 -0
- package/src/components/feedback/Message/index.ts +9 -0
- package/src/components/feedback/Modal/Modal.styles.ts +21 -0
- package/src/components/feedback/Modal/Modal.test.tsx +11 -0
- package/src/components/feedback/Modal/Modal.tsx +291 -0
- package/src/components/feedback/Modal/Modal.types.ts +141 -0
- package/src/components/feedback/Modal/index.tsx +11 -0
- package/src/components/feedback/Notification/Notification.styles.ts +443 -0
- package/src/components/feedback/Notification/Notification.test.tsx +401 -0
- package/src/components/feedback/Notification/Notification.tsx +370 -0
- package/src/components/feedback/Notification/Notification.types.ts +336 -0
- package/src/components/feedback/Notification/NotificationManager.tsx +376 -0
- package/src/components/feedback/Notification/index.ts +33 -0
- package/src/components/feedback/Notification/index.tsx +164 -0
- package/src/components/feedback/Progress/Progress.styles.ts +460 -0
- package/src/components/feedback/Progress/Progress.test.simple.tsx +14 -0
- package/src/components/feedback/Progress/Progress.test.tsx +312 -0
- package/src/components/feedback/Progress/Progress.tsx +508 -0
- package/src/components/feedback/Progress/Progress.types.ts +163 -0
- package/src/components/feedback/Progress/index.ts +3 -0
- package/src/components/feedback/Progress/index.tsx +38 -0
- package/src/components/feedback/Progress/utils/animation.ts +204 -0
- package/src/components/feedback/Progress/utils/index.ts +26 -0
- package/src/components/feedback/Progress/utils/progress-calculator.ts +217 -0
- package/src/components/feedback/Result/Result.styles.ts +139 -0
- package/src/components/feedback/Result/Result.tsx +233 -0
- package/src/components/feedback/Result/Result.types.ts +128 -0
- package/src/components/feedback/Result/index.tsx +3 -0
- package/src/components/feedback/Toast/Toast.styles.ts +17 -0
- package/src/components/feedback/Toast/Toast.test.tsx +10 -0
- package/src/components/feedback/Toast/Toast.tsx +372 -0
- package/src/components/feedback/Toast/Toast.types.ts +86 -0
- package/src/components/feedback/Toast/index.tsx +3 -0
- package/src/components/feedback/Tooltip/Tooltip.examples.tsx +458 -0
- package/src/components/feedback/Tooltip/Tooltip.styles.ts +346 -0
- package/src/components/feedback/Tooltip/Tooltip.test.tsx +446 -0
- package/src/components/feedback/Tooltip/Tooltip.tsx +283 -0
- package/src/components/feedback/Tooltip/Tooltip.types.ts +172 -0
- package/src/components/feedback/Tooltip/index.ts +3 -0
- package/src/components/feedback/Tooltip/index.tsx +258 -0
- package/src/components/feedback/index.tsx +164 -0
- package/src/components/form/Cascader/Cascader.styles.ts +526 -0
- package/src/components/form/Cascader/Cascader.test.tsx +77 -0
- package/src/components/form/Cascader/Cascader.tsx +585 -0
- package/src/components/form/Cascader/Cascader.types.ts +582 -0
- package/src/components/form/Cascader/hooks/index.ts +3 -0
- package/src/components/form/Cascader/hooks/useCascaderFieldNames.ts +16 -0
- package/src/components/form/Cascader/hooks/useCascaderOptions.ts +109 -0
- package/src/components/form/Cascader/hooks/useCascaderState.ts +133 -0
- package/src/components/form/Cascader/index.ts +25 -0
- package/src/components/form/Cascader/utils/formatDisplayValue.ts +19 -0
- package/src/components/form/Cascader/utils/index.ts +1 -0
- package/src/components/form/Checkbox/Checkbox.styles.ts +608 -0
- package/src/components/form/Checkbox/Checkbox.test.tsx +1140 -0
- package/src/components/form/Checkbox/Checkbox.tsx +496 -0
- package/src/components/form/Checkbox/Checkbox.types.ts +472 -0
- package/src/components/form/Checkbox/CheckboxGroup.tsx +444 -0
- package/src/components/form/Checkbox/index.tsx +27 -0
- package/src/components/form/DatePicker/DatePicker.styles.ts +393 -0
- package/src/components/form/DatePicker/DatePicker.test.tsx +407 -0
- package/src/components/form/DatePicker/DatePicker.tsx +360 -0
- package/src/components/form/DatePicker/DatePicker.types.ts +247 -0
- package/src/components/form/DatePicker/index.tsx +15 -0
- package/src/components/form/Form/Form.styles.ts +357 -0
- package/src/components/form/Form/Form.test.tsx +122 -0
- package/src/components/form/Form/Form.tsx +695 -0
- package/src/components/form/Form/Form.types.ts +407 -0
- package/src/components/form/Form/index.tsx +31 -0
- package/src/components/form/Input/Input.enhanced.tsx +732 -0
- package/src/components/form/Input/Input.styles.ts +438 -0
- package/src/components/form/Input/Input.test.tsx +494 -0
- package/src/components/form/Input/Input.tsx +541 -0
- package/src/components/form/Input/Input.types.ts +285 -0
- package/src/components/form/Input/index.tsx +26 -0
- package/src/components/form/InputNumber/InputNumber.styles.ts +665 -0
- package/src/components/form/InputNumber/InputNumber.tsx +370 -0
- package/src/components/form/InputNumber/InputNumber.types.ts +318 -0
- package/src/components/form/InputNumber/components/InputNumberClearButton.tsx +32 -0
- package/src/components/form/InputNumber/components/InputNumberControls.tsx +42 -0
- package/src/components/form/InputNumber/components/index.ts +2 -0
- package/src/components/form/InputNumber/hooks/index.ts +4 -0
- package/src/components/form/InputNumber/hooks/useInputNumberState.ts +315 -0
- package/src/components/form/InputNumber/hooks/useInputNumberValidation.ts +147 -0
- package/src/components/form/InputNumber/index.ts +25 -0
- package/src/components/form/Radio/Radio.styles.ts +458 -0
- package/src/components/form/Radio/Radio.test.tsx +547 -0
- package/src/components/form/Radio/Radio.tsx +283 -0
- package/src/components/form/Radio/Radio.types.ts +410 -0
- package/src/components/form/Radio/index.tsx +21 -0
- package/src/components/form/Select/Select.styles.ts +514 -0
- package/src/components/form/Select/Select.test.tsx +648 -0
- package/src/components/form/Select/Select.tsx +474 -0
- package/src/components/form/Select/Select.types.ts +428 -0
- package/src/components/form/Select/index.tsx +30 -0
- package/src/components/form/Slider/Slider.styles.ts +139 -0
- package/src/components/form/Slider/Slider.test.tsx +553 -0
- package/src/components/form/Slider/Slider.tsx +326 -0
- package/src/components/form/Slider/Slider.types.ts +108 -0
- package/src/components/form/Slider/index.tsx +10 -0
- package/src/components/form/Switch/Switch.styles.ts +540 -0
- package/src/components/form/Switch/Switch.test.tsx +345 -0
- package/src/components/form/Switch/Switch.tsx +464 -0
- package/src/components/form/Switch/Switch.types.ts +386 -0
- package/src/components/form/Switch/index.tsx +26 -0
- package/src/components/form/Textarea/Textarea.styles.ts +592 -0
- package/src/components/form/Textarea/Textarea.test.tsx +1075 -0
- package/src/components/form/Textarea/Textarea.tsx +602 -0
- package/src/components/form/Textarea/Textarea.types.ts +371 -0
- package/src/components/form/Textarea/index.tsx +26 -0
- package/src/components/form/TimePicker/TimePicker.styles.ts +438 -0
- package/src/components/form/TimePicker/TimePicker.test.tsx +306 -0
- package/src/components/form/TimePicker/TimePicker.tsx +228 -0
- package/src/components/form/TimePicker/TimePicker.types.ts +385 -0
- package/src/components/form/TimePicker/index.ts +21 -0
- package/src/components/form/Transfer/Transfer.styles.ts +502 -0
- package/src/components/form/Transfer/Transfer.test.tsx +316 -0
- package/src/components/form/Transfer/Transfer.tsx +402 -0
- package/src/components/form/Transfer/Transfer.types.ts +557 -0
- package/src/components/form/Transfer/components/TransferItem.tsx +101 -0
- package/src/components/form/Transfer/components/TransferList.tsx +285 -0
- package/src/components/form/Transfer/components/TransferOperations.tsx +84 -0
- package/src/components/form/Transfer/components/TransferPagination.tsx +135 -0
- package/src/components/form/Transfer/components/TransferSearch.tsx +88 -0
- package/src/components/form/Transfer/components/index.ts +6 -0
- package/src/components/form/Transfer/hooks/index.ts +3 -0
- package/src/components/form/Transfer/hooks/useTransferData.ts +192 -0
- package/src/components/form/Transfer/hooks/useTransferState.ts +114 -0
- package/src/components/form/Transfer/index.ts +33 -0
- package/src/components/form/Upload/Upload.styles.ts +145 -0
- package/src/components/form/Upload/Upload.test.tsx +10 -0
- package/src/components/form/Upload/Upload.tsx +451 -0
- package/src/components/form/Upload/Upload.types.ts +200 -0
- package/src/components/form/Upload/index.tsx +12 -0
- package/src/components/form/index.tsx +121 -0
- package/src/components/index.tsx +146 -0
- package/src/components/layout/Affix/Affix.styles.ts +37 -0
- package/src/components/layout/Affix/Affix.test.tsx +10 -0
- package/src/components/layout/Affix/Affix.tsx +91 -0
- package/src/components/layout/Affix/Affix.types.ts +29 -0
- package/src/components/layout/Affix/index.tsx +3 -0
- package/src/components/layout/Col/Col.styles.ts +185 -0
- package/src/components/layout/Col/Col.test.tsx +535 -0
- package/src/components/layout/Col/Col.tsx +115 -0
- package/src/components/layout/Col/Col.types.ts +59 -0
- package/src/components/layout/Col/index.tsx +3 -0
- package/src/components/layout/Container/Container.styles.ts +161 -0
- package/src/components/layout/Container/Container.test.tsx +380 -0
- package/src/components/layout/Container/Container.tsx +132 -0
- package/src/components/layout/Container/Container.types.ts +63 -0
- package/src/components/layout/Container/index.tsx +3 -0
- package/src/components/layout/Grid/Grid.styles.ts +183 -0
- package/src/components/layout/Grid/Grid.test.tsx +637 -0
- package/src/components/layout/Grid/Grid.tsx +173 -0
- package/src/components/layout/Grid/Grid.types.ts +78 -0
- package/src/components/layout/Grid/index.tsx +3 -0
- package/src/components/layout/Layout/Content.tsx +38 -0
- package/src/components/layout/Layout/Footer.tsx +38 -0
- package/src/components/layout/Layout/Header.tsx +38 -0
- package/src/components/layout/Layout/Layout.styles.ts +84 -0
- package/src/components/layout/Layout/Layout.test.tsx +10 -0
- package/src/components/layout/Layout/Layout.tsx +39 -0
- package/src/components/layout/Layout/Layout.types.ts +58 -0
- package/src/components/layout/Layout/Sider.tsx +56 -0
- package/src/components/layout/Layout/index.tsx +8 -0
- package/src/components/layout/Row/Row.styles.ts +159 -0
- package/src/components/layout/Row/Row.test.tsx +467 -0
- package/src/components/layout/Row/Row.tsx +139 -0
- package/src/components/layout/Row/Row.types.ts +60 -0
- package/src/components/layout/Row/index.tsx +3 -0
- package/src/components/layout/Space/Space.styles.ts +255 -0
- package/src/components/layout/Space/Space.test.tsx +682 -0
- package/src/components/layout/Space/Space.tsx +211 -0
- package/src/components/layout/Space/Space.types.ts +92 -0
- package/src/components/layout/Space/index.tsx +12 -0
- package/src/components/layout/index.tsx +68 -0
- package/src/components/navigation/Menu/Menu.styles.ts +779 -0
- package/src/components/navigation/Menu/Menu.tsx +355 -0
- package/src/components/navigation/Menu/Menu.types.ts +231 -0
- package/src/components/navigation/Menu/Menu.utils.ts +187 -0
- package/src/components/navigation/Menu/MenuItem.tsx +126 -0
- package/src/components/navigation/Menu/SubMenu.tsx +148 -0
- package/src/components/navigation/Menu/__tests__/Menu.test.tsx +687 -0
- package/src/components/navigation/Menu/index.tsx +124 -0
- package/src/components/navigation/NavBar/NavBar.styles.ts +129 -0
- package/src/components/navigation/NavBar/NavBar.test.tsx +287 -0
- package/src/components/navigation/NavBar/NavBar.tsx +231 -0
- package/src/components/navigation/NavBar/NavBar.types.ts +54 -0
- package/src/components/navigation/NavBar/index.tsx +3 -0
- package/src/components/navigation/Pagination/Pagination.styles.ts +187 -0
- package/src/components/navigation/Pagination/Pagination.test.tsx +673 -0
- package/src/components/navigation/Pagination/Pagination.tsx +395 -0
- package/src/components/navigation/Pagination/Pagination.types.ts +86 -0
- package/src/components/navigation/Pagination/index.ts +18 -0
- package/src/components/navigation/Pagination/index.tsx +9 -0
- package/src/components/navigation/Steps/Step.tsx +56 -0
- package/src/components/navigation/Steps/Steps.styles.ts +154 -0
- package/src/components/navigation/Steps/Steps.test.tsx +12 -0
- package/src/components/navigation/Steps/Steps.tsx +113 -0
- package/src/components/navigation/Steps/Steps.types.ts +47 -0
- package/src/components/navigation/Steps/index.tsx +3 -0
- package/src/components/navigation/Tabs/Tabs.styles.ts +199 -0
- package/src/components/navigation/Tabs/Tabs.test.tsx +661 -0
- package/src/components/navigation/Tabs/Tabs.tsx +253 -0
- package/src/components/navigation/Tabs/Tabs.types.ts +114 -0
- package/src/components/navigation/Tabs/index.tsx +3 -0
- package/src/components/navigation/Tree/Tree.styles.ts +553 -0
- package/src/components/navigation/Tree/Tree.test.basic.tsx +7 -0
- package/src/components/navigation/Tree/Tree.test.functional.tsx +496 -0
- package/src/components/navigation/Tree/Tree.test.import.check.tsx +6 -0
- package/src/components/navigation/Tree/Tree.test.import.tsx +6 -0
- package/src/components/navigation/Tree/Tree.test.minimal.tsx +5 -0
- package/src/components/navigation/Tree/Tree.test.simple.tsx +30 -0
- package/src/components/navigation/Tree/Tree.test.tsx +908 -0
- package/src/components/navigation/Tree/Tree.test.working.tsx +673 -0
- package/src/components/navigation/Tree/Tree.tsx +600 -0
- package/src/components/navigation/Tree/Tree.types.ts +909 -0
- package/src/components/navigation/Tree/Tree.utils.ts +452 -0
- package/src/components/navigation/Tree/index.ts +33 -0
- package/src/components/navigation/Tree/index.tsx +23 -0
- package/src/components/navigation/index.tsx +83 -0
- package/src/constants/index.ts +785 -0
- package/src/hooks/index.ts +110 -0
- package/src/hooks/types.ts +10 -0
- package/src/hooks/useAsync.ts +65 -0
- package/src/hooks/useEventHandling.ts +444 -0
- package/src/hooks/useLifecycle.ts +399 -0
- package/src/hooks/usePerformance.ts +441 -0
- package/src/hooks/usePerformanceMonitor.ts +348 -0
- package/src/hooks/usePlatform.ts +62 -0
- package/src/hooks/useRequest.test.ts +11 -0
- package/src/hooks/useRequest.ts +135 -0
- package/src/hooks/useStateManagement.ts +300 -0
- package/src/hooks/useStyle.ts +537 -0
- package/src/hooks/useTheme.ts +347 -0
- package/src/hooks/useVirtualScroll.ts +331 -0
- package/src/index.ts +298 -0
- package/src/platform/index.ts +1188 -0
- package/src/providers/AppProvider.test.tsx +63 -0
- package/src/providers/AppProvider.tsx +155 -0
- package/src/providers/index.ts +1 -0
- package/src/theme/ThemeProvider.tsx +283 -0
- package/src/theme/ThemeProvider.types.ts +26 -0
- package/src/theme/animations.tsx +660 -0
- package/src/theme/defaults.ts +188 -0
- package/src/theme/design-system.ts +562 -0
- package/src/theme/design-tokens.ts +1136 -0
- package/src/theme/generated/dark-theme.scss +120 -0
- package/src/theme/generated/tokens.css +441 -0
- package/src/theme/generated/tokens.scss +320 -0
- package/src/theme/index.ts +120 -0
- package/src/theme/responsive.tsx +193 -0
- package/src/theme/styles/mixins.scss +612 -0
- package/src/theme/styles/variables.scss +295 -0
- package/src/theme/styles.ts +403 -0
- package/src/theme/tokens/colors.ts +256 -0
- package/src/theme/tokens/effects.ts +260 -0
- package/src/theme/tokens/index.ts +217 -0
- package/src/theme/tokens/spacing.ts +137 -0
- package/src/theme/tokens/typography.ts +186 -0
- package/src/theme/types.ts +188 -0
- package/src/theme/useThemeUtils.ts +313 -0
- package/src/theme/utils.ts +501 -0
- package/src/theme/variables.ts +583 -0
- package/src/types/accessibility.ts +51 -0
- package/src/types/button.ts +562 -0
- package/src/types/component-props.ts +317 -0
- package/src/types/env.d.ts +20 -0
- package/src/types/index.ts +427 -0
- package/src/types/modules.d.ts +40 -0
- package/src/types/standardized-components.ts +544 -0
- package/src/types/taro-adapter.d.ts +174 -0
- package/src/types/taro-components.d.ts +73 -0
- package/src/types/utils.ts +410 -0
- package/src/utils/__tests__/inputValidator.test.ts +338 -0
- package/src/utils/__tests__/responsiveUtils.test.ts +310 -0
- package/src/utils/__tests__/xssProtection.test.ts +268 -0
- package/src/utils/cache.ts +83 -0
- package/src/utils/createNamespace.ts +24 -0
- package/src/utils/environment.ts +95 -0
- package/src/utils/error-handler.ts +88 -0
- package/src/utils/errorLogger.ts +197 -0
- package/src/utils/formatUtils.ts +444 -0
- package/src/utils/index.ts +115 -0
- package/src/utils/inputValidator.ts +261 -0
- package/src/utils/network/http-client.test.ts +18 -0
- package/src/utils/network/http-client.ts +151 -0
- package/src/utils/performance/performance.ts +850 -0
- package/src/utils/responsiveUtils.ts +357 -0
- package/src/utils/rtl-support.ts +344 -0
- package/src/utils/security/api-security.ts +386 -0
- package/src/utils/security/xss-protection.ts +69 -0
- package/src/utils/securityHeaders.ts +314 -0
- package/src/utils/typeHelpers.ts +16 -0
- package/src/utils/types/dataProcessing.ts +543 -0
- package/src/utils/types/typeHelpers.ts +187 -0
- package/src/utils/xssProtection.ts +420 -0
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Taro-Uno UI 组件库平台适配工具
|
|
3
|
+
* 提供跨平台开发的统一接口和适配器
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as Taro from '@tarojs/taro';
|
|
7
|
+
import type { Platform, PlatformInfo, RequestConfig, RequestResponse, RequestError } from '../types';
|
|
8
|
+
import { PLATFORM_APIS, PLATFORM_FEATURES, PLATFORM_NAMES } from '../constants';
|
|
9
|
+
|
|
10
|
+
// 全局类型声明
|
|
11
|
+
declare global {
|
|
12
|
+
interface Window {
|
|
13
|
+
wx?: any;
|
|
14
|
+
my?: any;
|
|
15
|
+
swan?: any;
|
|
16
|
+
tt?: any;
|
|
17
|
+
qq?: any;
|
|
18
|
+
jd?: any;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ==================== 平台适配器接口 ====================
|
|
23
|
+
|
|
24
|
+
/** 平台适配器接口 */
|
|
25
|
+
export interface PlatformAdapter {
|
|
26
|
+
/** 获取平台信息 */
|
|
27
|
+
getPlatformInfo(): PlatformInfo;
|
|
28
|
+
|
|
29
|
+
/** 网络请求 */
|
|
30
|
+
request<T = any>(config: RequestConfig): Promise<RequestResponse<T>>;
|
|
31
|
+
|
|
32
|
+
/** 存储操作 */
|
|
33
|
+
storage: {
|
|
34
|
+
set(key: string, value: any): Promise<void>;
|
|
35
|
+
get(key: string): Promise<any>;
|
|
36
|
+
remove(key: string): Promise<void>;
|
|
37
|
+
clear(): Promise<void>;
|
|
38
|
+
getInfo(): Promise<{ currentSize: number; limitSize: number }>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** 位置服务 */
|
|
42
|
+
location: {
|
|
43
|
+
getCurrentPosition(): Promise<Taro.getLocation.SuccessCallbackResult>;
|
|
44
|
+
openLocation(options: Taro.openLocation.Option): Promise<void>;
|
|
45
|
+
chooseLocation(): Promise<Taro.chooseLocation.SuccessCallbackResult>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** 相机服务 */
|
|
49
|
+
camera: {
|
|
50
|
+
takePhoto(options?: any): Promise<any>;
|
|
51
|
+
chooseImage(options?: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult>;
|
|
52
|
+
chooseVideo(options?: Taro.chooseVideo.Option): Promise<Taro.chooseVideo.SuccessCallbackResult>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** 支付服务 */
|
|
56
|
+
payment: {
|
|
57
|
+
requestPayment(options: Taro.requestPayment.Option): Promise<void>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** 分享服务 */
|
|
61
|
+
share: {
|
|
62
|
+
shareAppMessage(options?: any): Promise<void>;
|
|
63
|
+
shareToTimeline(options?: any): Promise<void>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** 生物识别 */
|
|
67
|
+
biometrics: {
|
|
68
|
+
checkIsAvailable(): Promise<boolean>;
|
|
69
|
+
startVerify(
|
|
70
|
+
options: Taro.startSoterAuthentication.Option,
|
|
71
|
+
): Promise<Taro.startSoterAuthentication.SuccessCallbackResult>;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** 系统信息 */
|
|
75
|
+
system: {
|
|
76
|
+
getSystemInfo(): Promise<Taro.getSystemInfoSync.Result>;
|
|
77
|
+
getNetworkType(): Promise<Taro.getNetworkType.SuccessCallbackResult>;
|
|
78
|
+
getBatteryInfo(): Promise<Taro.getBatteryInfo.SuccessCallbackResult>;
|
|
79
|
+
getScreenBrightness(): Promise<number>;
|
|
80
|
+
setScreenBrightness(value: number): Promise<void>;
|
|
81
|
+
keepScreenOn(keepScreenOn: boolean): Promise<void>;
|
|
82
|
+
vibrate(): Promise<void>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** 剪贴板 */
|
|
86
|
+
clipboard: {
|
|
87
|
+
set(text: string): Promise<void>;
|
|
88
|
+
get(): Promise<string>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** 扫码 */
|
|
92
|
+
scan: {
|
|
93
|
+
scanCode(options?: Taro.scanCode.Option): Promise<Taro.scanCode.SuccessCallbackResult>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** 文件操作 */
|
|
97
|
+
file: {
|
|
98
|
+
saveFile(options: Taro.saveFile.Option): Promise<Taro.saveFile.SuccessCallbackResult>;
|
|
99
|
+
getFileInfo(options: Taro.getFileInfo.Option): Promise<Taro.getFileInfo.SuccessCallbackResult>;
|
|
100
|
+
getSavedFileList(): Promise<Taro.getSavedFileList.SuccessCallbackResult>;
|
|
101
|
+
removeSavedFile(options: Taro.removeSavedFile.Option): Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ==================== 微信小程序适配器 ====================
|
|
106
|
+
|
|
107
|
+
class WeappAdapter implements PlatformAdapter {
|
|
108
|
+
getPlatformInfo(): PlatformInfo {
|
|
109
|
+
const system = Taro.getSystemInfoSync();
|
|
110
|
+
const accountInfo = Taro.getAccountInfoSync();
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
platform: 'weapp',
|
|
114
|
+
isMiniProgram: true,
|
|
115
|
+
isH5: false,
|
|
116
|
+
isRN: false,
|
|
117
|
+
system,
|
|
118
|
+
SDKVersion: (accountInfo.miniProgram as any).sdkVersion || accountInfo.miniProgram.version,
|
|
119
|
+
version: accountInfo.miniProgram.version,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async request<T = any>(config: RequestConfig): Promise<RequestResponse<T>> {
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
Taro.request({
|
|
126
|
+
url: config.url,
|
|
127
|
+
method: (config.method as any) || 'GET',
|
|
128
|
+
header: config.header,
|
|
129
|
+
data: config.data,
|
|
130
|
+
timeout: config.timeout,
|
|
131
|
+
success: (res) => {
|
|
132
|
+
resolve({
|
|
133
|
+
data: res.data as T,
|
|
134
|
+
statusCode: res.statusCode,
|
|
135
|
+
statusMessage: res.errMsg,
|
|
136
|
+
header: res.header,
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
fail: (err) => {
|
|
140
|
+
const error: RequestError = {
|
|
141
|
+
message: err.errMsg || 'Request failed',
|
|
142
|
+
code: (err as any).errCode,
|
|
143
|
+
detail: err,
|
|
144
|
+
};
|
|
145
|
+
reject(error);
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
storage = {
|
|
152
|
+
async set(key: string, value: any): Promise<void> {
|
|
153
|
+
return new Promise((resolve, reject) => {
|
|
154
|
+
Taro.setStorage({
|
|
155
|
+
key,
|
|
156
|
+
data: value,
|
|
157
|
+
success: () => resolve(),
|
|
158
|
+
fail: reject,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
async get(key: string): Promise<any> {
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
Taro.getStorage({
|
|
166
|
+
key,
|
|
167
|
+
success: (res) => resolve(res.data),
|
|
168
|
+
fail: reject,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
async remove(key: string): Promise<void> {
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
Taro.removeStorage({
|
|
176
|
+
key,
|
|
177
|
+
success: () => resolve(),
|
|
178
|
+
fail: reject,
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
async clear(): Promise<void> {
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
Taro.clearStorage({
|
|
186
|
+
success: () => resolve(),
|
|
187
|
+
fail: reject,
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
async getInfo(): Promise<{ currentSize: number; limitSize: number }> {
|
|
193
|
+
return new Promise((resolve, reject) => {
|
|
194
|
+
Taro.getStorageInfo({
|
|
195
|
+
success: (res) =>
|
|
196
|
+
resolve({
|
|
197
|
+
currentSize: res.currentSize,
|
|
198
|
+
limitSize: res.limitSize,
|
|
199
|
+
}),
|
|
200
|
+
fail: reject,
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
location = {
|
|
207
|
+
async getCurrentPosition(): Promise<Taro.getLocation.SuccessCallbackResult> {
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
Taro.getLocation({
|
|
210
|
+
success: resolve,
|
|
211
|
+
fail: reject,
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
async openLocation(options: Taro.openLocation.Option): Promise<void> {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
Taro.openLocation({
|
|
219
|
+
...options,
|
|
220
|
+
success: () => resolve(),
|
|
221
|
+
fail: reject,
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
async chooseLocation(): Promise<Taro.chooseLocation.SuccessCallbackResult> {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
Taro.chooseLocation({
|
|
229
|
+
success: resolve,
|
|
230
|
+
fail: reject,
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
camera = {
|
|
237
|
+
async takePhoto(options?: any): Promise<any> {
|
|
238
|
+
return new Promise((resolve, reject) => {
|
|
239
|
+
(Taro as any).cameraTakePhoto({
|
|
240
|
+
...options,
|
|
241
|
+
success: resolve,
|
|
242
|
+
fail: reject,
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
async chooseImage(options?: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
249
|
+
Taro.chooseImage({
|
|
250
|
+
...options,
|
|
251
|
+
success: resolve,
|
|
252
|
+
fail: reject,
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
async chooseVideo(options?: Taro.chooseVideo.Option): Promise<Taro.chooseVideo.SuccessCallbackResult> {
|
|
258
|
+
return new Promise((resolve, reject) => {
|
|
259
|
+
Taro.chooseVideo({
|
|
260
|
+
...options,
|
|
261
|
+
success: resolve,
|
|
262
|
+
fail: reject,
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
payment = {
|
|
269
|
+
async requestPayment(options: Taro.requestPayment.Option): Promise<void> {
|
|
270
|
+
return new Promise((resolve, reject) => {
|
|
271
|
+
Taro.requestPayment({
|
|
272
|
+
...options,
|
|
273
|
+
success: () => resolve(),
|
|
274
|
+
fail: reject,
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
share = {
|
|
281
|
+
async shareAppMessage(options?: any): Promise<void> {
|
|
282
|
+
return new Promise((resolve, reject) => {
|
|
283
|
+
(Taro as any).shareAppMessage({
|
|
284
|
+
...options,
|
|
285
|
+
success: () => resolve(),
|
|
286
|
+
fail: reject,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
async shareToTimeline(options?: any): Promise<void> {
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
(Taro as any).shareToTimeline({
|
|
294
|
+
...options,
|
|
295
|
+
success: () => resolve(),
|
|
296
|
+
fail: reject,
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
biometrics = {
|
|
303
|
+
async checkIsAvailable(): Promise<boolean> {
|
|
304
|
+
return new Promise((resolve) => {
|
|
305
|
+
Taro.checkIsSoterEnrolledInDevice({
|
|
306
|
+
checkAuthMode: 'fingerPrint',
|
|
307
|
+
success: (res) => resolve(res.isEnrolled),
|
|
308
|
+
fail: () => resolve(false),
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
async startVerify(
|
|
314
|
+
options: Taro.startSoterAuthentication.Option,
|
|
315
|
+
): Promise<Taro.startSoterAuthentication.SuccessCallbackResult> {
|
|
316
|
+
return new Promise((resolve, reject) => {
|
|
317
|
+
Taro.startSoterAuthentication({
|
|
318
|
+
...options,
|
|
319
|
+
success: resolve,
|
|
320
|
+
fail: reject,
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
system = {
|
|
327
|
+
async getSystemInfo(): Promise<Taro.getSystemInfoSync.Result> {
|
|
328
|
+
return Promise.resolve(Taro.getSystemInfoSync());
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
async getNetworkType(): Promise<Taro.getNetworkType.SuccessCallbackResult> {
|
|
332
|
+
return new Promise((resolve, reject) => {
|
|
333
|
+
Taro.getNetworkType({
|
|
334
|
+
success: resolve,
|
|
335
|
+
fail: reject,
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
async getBatteryInfo(): Promise<Taro.getBatteryInfo.SuccessCallbackResult> {
|
|
341
|
+
return new Promise((resolve, reject) => {
|
|
342
|
+
Taro.getBatteryInfo({
|
|
343
|
+
success: resolve,
|
|
344
|
+
fail: reject,
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
async getScreenBrightness(): Promise<number> {
|
|
350
|
+
return new Promise((resolve, reject) => {
|
|
351
|
+
Taro.getScreenBrightness({
|
|
352
|
+
success: (res) => resolve(res.value),
|
|
353
|
+
fail: reject,
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
|
|
358
|
+
async setScreenBrightness(value: number): Promise<void> {
|
|
359
|
+
return new Promise((resolve, reject) => {
|
|
360
|
+
Taro.setScreenBrightness({
|
|
361
|
+
value,
|
|
362
|
+
success: () => resolve(),
|
|
363
|
+
fail: reject,
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
},
|
|
367
|
+
|
|
368
|
+
async keepScreenOn(keepScreenOn: boolean): Promise<void> {
|
|
369
|
+
return new Promise((resolve, reject) => {
|
|
370
|
+
Taro.setKeepScreenOn({
|
|
371
|
+
keepScreenOn,
|
|
372
|
+
success: () => resolve(),
|
|
373
|
+
fail: reject,
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
async vibrate(): Promise<void> {
|
|
379
|
+
return new Promise((resolve, reject) => {
|
|
380
|
+
(Taro as any).vibrate({
|
|
381
|
+
success: () => resolve(),
|
|
382
|
+
fail: reject,
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
clipboard = {
|
|
389
|
+
async set(text: string): Promise<void> {
|
|
390
|
+
return new Promise((resolve, reject) => {
|
|
391
|
+
Taro.setClipboardData({
|
|
392
|
+
data: text,
|
|
393
|
+
success: () => resolve(),
|
|
394
|
+
fail: reject,
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
async get(): Promise<string> {
|
|
400
|
+
return new Promise((resolve, reject) => {
|
|
401
|
+
Taro.getClipboardData({
|
|
402
|
+
success: (res) => resolve(res.data),
|
|
403
|
+
fail: reject,
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
scan = {
|
|
410
|
+
async scanCode(options?: Taro.scanCode.Option): Promise<Taro.scanCode.SuccessCallbackResult> {
|
|
411
|
+
return new Promise((resolve, reject) => {
|
|
412
|
+
Taro.scanCode({
|
|
413
|
+
...options,
|
|
414
|
+
success: resolve,
|
|
415
|
+
fail: reject,
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
file = {
|
|
422
|
+
async saveFile(options: Taro.saveFile.Option): Promise<Taro.saveFile.SuccessCallbackResult> {
|
|
423
|
+
return new Promise((resolve, reject) => {
|
|
424
|
+
Taro.saveFile({
|
|
425
|
+
...options,
|
|
426
|
+
success: resolve,
|
|
427
|
+
fail: reject,
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
async getFileInfo(options: Taro.getFileInfo.Option): Promise<Taro.getFileInfo.SuccessCallbackResult> {
|
|
433
|
+
return new Promise((resolve, reject) => {
|
|
434
|
+
Taro.getFileInfo({
|
|
435
|
+
...options,
|
|
436
|
+
success: resolve,
|
|
437
|
+
fail: reject,
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
|
|
442
|
+
async getSavedFileList(): Promise<Taro.getSavedFileList.SuccessCallbackResult> {
|
|
443
|
+
return new Promise((resolve, reject) => {
|
|
444
|
+
Taro.getSavedFileList({
|
|
445
|
+
success: resolve,
|
|
446
|
+
fail: reject,
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
async removeSavedFile(options: Taro.removeSavedFile.Option): Promise<void> {
|
|
452
|
+
return new Promise((resolve, reject) => {
|
|
453
|
+
Taro.removeSavedFile({
|
|
454
|
+
...options,
|
|
455
|
+
success: () => resolve(),
|
|
456
|
+
fail: reject,
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// ==================== H5适配器 ====================
|
|
464
|
+
|
|
465
|
+
class H5Adapter implements PlatformAdapter {
|
|
466
|
+
getPlatformInfo(): PlatformInfo {
|
|
467
|
+
const system = Taro.getSystemInfoSync();
|
|
468
|
+
|
|
469
|
+
return {
|
|
470
|
+
platform: 'h5',
|
|
471
|
+
isMiniProgram: false,
|
|
472
|
+
isH5: true,
|
|
473
|
+
isRN: false,
|
|
474
|
+
system,
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** Headers对象转普通对象 */
|
|
479
|
+
private headersToObject(headers: Headers): Record<string, string> {
|
|
480
|
+
const result: Record<string, string> = {};
|
|
481
|
+
headers.forEach((value, key) => {
|
|
482
|
+
result[key] = value;
|
|
483
|
+
});
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
async request<T = any>(config: RequestConfig): Promise<RequestResponse<T>> {
|
|
488
|
+
const url = new URL(config.url, window.location.origin);
|
|
489
|
+
|
|
490
|
+
// 添加查询参数
|
|
491
|
+
if (config.params) {
|
|
492
|
+
Object.entries(config.params).forEach(([key, value]) => {
|
|
493
|
+
url.searchParams.append(key, String(value));
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const options: RequestInit = {
|
|
498
|
+
method: config.method || 'GET',
|
|
499
|
+
headers: {
|
|
500
|
+
'Content-Type': 'application/json',
|
|
501
|
+
...config.header,
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
if (config.data && ['POST', 'PUT', 'PATCH'].includes(config.method || 'GET')) {
|
|
506
|
+
options.body = JSON.stringify(config.data);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
try {
|
|
510
|
+
const response = await fetch(url.toString(), options);
|
|
511
|
+
const data = await response.json();
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
data,
|
|
515
|
+
statusCode: response.status,
|
|
516
|
+
statusMessage: response.statusText,
|
|
517
|
+
header: this.headersToObject(response.headers),
|
|
518
|
+
};
|
|
519
|
+
} catch (error) {
|
|
520
|
+
const requestError: RequestError = {
|
|
521
|
+
message: error instanceof Error ? error.message : 'Network error',
|
|
522
|
+
detail: error,
|
|
523
|
+
};
|
|
524
|
+
throw requestError;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
storage = {
|
|
529
|
+
async set(key: string, value: any): Promise<void> {
|
|
530
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
async get(key: string): Promise<any> {
|
|
534
|
+
const value = localStorage.getItem(key);
|
|
535
|
+
return value ? JSON.parse(value) : null;
|
|
536
|
+
},
|
|
537
|
+
|
|
538
|
+
async remove(key: string): Promise<void> {
|
|
539
|
+
localStorage.removeItem(key);
|
|
540
|
+
},
|
|
541
|
+
|
|
542
|
+
async clear(): Promise<void> {
|
|
543
|
+
localStorage.clear();
|
|
544
|
+
},
|
|
545
|
+
|
|
546
|
+
async getInfo(): Promise<{ currentSize: number; limitSize: number }> {
|
|
547
|
+
// 估算localStorage使用空间
|
|
548
|
+
let size = 0;
|
|
549
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
550
|
+
const key = localStorage.key(i);
|
|
551
|
+
if (key) {
|
|
552
|
+
size += (key + localStorage.getItem(key)).length;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return {
|
|
557
|
+
currentSize: size,
|
|
558
|
+
limitSize: 5 * 1024 * 1024, // 5MB 估算
|
|
559
|
+
};
|
|
560
|
+
},
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
location = {
|
|
564
|
+
async getCurrentPosition(): Promise<Taro.getLocation.SuccessCallbackResult> {
|
|
565
|
+
return new Promise((resolve, reject) => {
|
|
566
|
+
if (!navigator.geolocation) {
|
|
567
|
+
reject(new Error('Geolocation is not supported'));
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
navigator.geolocation.getCurrentPosition(
|
|
572
|
+
(position) => {
|
|
573
|
+
resolve({
|
|
574
|
+
latitude: position.coords.latitude || 0,
|
|
575
|
+
longitude: position.coords.longitude || 0,
|
|
576
|
+
accuracy: position.coords.accuracy || 0,
|
|
577
|
+
altitude: position.coords.altitude || 0,
|
|
578
|
+
verticalAccuracy: position.coords.altitudeAccuracy || 0,
|
|
579
|
+
horizontalAccuracy: position.coords.accuracy || 0,
|
|
580
|
+
speed: position.coords.speed || 0,
|
|
581
|
+
errMsg: 'getLocation:ok',
|
|
582
|
+
});
|
|
583
|
+
},
|
|
584
|
+
(error) => {
|
|
585
|
+
reject(error);
|
|
586
|
+
},
|
|
587
|
+
);
|
|
588
|
+
});
|
|
589
|
+
},
|
|
590
|
+
|
|
591
|
+
async openLocation(options: Taro.openLocation.Option): Promise<void> {
|
|
592
|
+
const url = `https://maps.google.com/maps?q=${options.latitude},${options.longitude}`;
|
|
593
|
+
window.open(url, '_blank');
|
|
594
|
+
},
|
|
595
|
+
|
|
596
|
+
async chooseLocation(): Promise<Taro.chooseLocation.SuccessCallbackResult> {
|
|
597
|
+
// H5环境下需要用户手动输入或使用地图选择
|
|
598
|
+
throw new Error('chooseLocation is not supported in H5 environment');
|
|
599
|
+
},
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
camera = {
|
|
603
|
+
async takePhoto(): Promise<any> {
|
|
604
|
+
throw new Error('takePhoto is not supported in H5 environment');
|
|
605
|
+
},
|
|
606
|
+
|
|
607
|
+
async chooseImage(options?: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
608
|
+
return new Promise((resolve, reject) => {
|
|
609
|
+
const input = document.createElement('input');
|
|
610
|
+
input.type = 'file';
|
|
611
|
+
input.accept = 'image/*';
|
|
612
|
+
|
|
613
|
+
if (options?.count && options.count > 1) {
|
|
614
|
+
input.multiple = true;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
input.onchange = (event) => {
|
|
618
|
+
const files = Array.from((event.target as HTMLInputElement).files || []);
|
|
619
|
+
const tempFilePaths = files.map((file) => URL.createObjectURL(file));
|
|
620
|
+
|
|
621
|
+
resolve({
|
|
622
|
+
tempFilePaths,
|
|
623
|
+
tempFiles: files.map((file) => ({
|
|
624
|
+
path: URL.createObjectURL(file),
|
|
625
|
+
size: file.size,
|
|
626
|
+
type: file.type,
|
|
627
|
+
originalFileObj: file,
|
|
628
|
+
})),
|
|
629
|
+
errMsg: 'chooseImage:ok',
|
|
630
|
+
});
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
input.onerror = () => {
|
|
634
|
+
reject(new Error('Failed to choose image'));
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
input.click();
|
|
638
|
+
});
|
|
639
|
+
},
|
|
640
|
+
|
|
641
|
+
async chooseVideo(): Promise<Taro.chooseVideo.SuccessCallbackResult> {
|
|
642
|
+
return new Promise((resolve, reject) => {
|
|
643
|
+
const input = document.createElement('input');
|
|
644
|
+
input.type = 'file';
|
|
645
|
+
input.accept = 'video/*';
|
|
646
|
+
|
|
647
|
+
input.onchange = (event) => {
|
|
648
|
+
const file = (event.target as HTMLInputElement).files?.[0];
|
|
649
|
+
if (!file) {
|
|
650
|
+
reject(new Error('No file selected'));
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
resolve({
|
|
655
|
+
tempFilePath: URL.createObjectURL(file),
|
|
656
|
+
duration: 0, // 需要额外的逻辑获取视频时长
|
|
657
|
+
size: file.size,
|
|
658
|
+
height: 0, // 需要额外的逻辑获取视频尺寸
|
|
659
|
+
width: 0,
|
|
660
|
+
errMsg: 'chooseVideo:ok',
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
input.onerror = () => {
|
|
665
|
+
reject(new Error('Failed to choose video'));
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
input.click();
|
|
669
|
+
});
|
|
670
|
+
},
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
payment = {
|
|
674
|
+
async requestPayment(): Promise<void> {
|
|
675
|
+
throw new Error('Payment is not supported in H5 environment');
|
|
676
|
+
},
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
share = {
|
|
680
|
+
async shareAppMessage(): Promise<void> {
|
|
681
|
+
// 使用Web Share API如果可用
|
|
682
|
+
if (navigator.share) {
|
|
683
|
+
await navigator.share({
|
|
684
|
+
title: document.title,
|
|
685
|
+
url: window.location.href,
|
|
686
|
+
});
|
|
687
|
+
} else {
|
|
688
|
+
throw new Error('Web Share API is not supported');
|
|
689
|
+
}
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
async shareToTimeline(): Promise<void> {
|
|
693
|
+
throw new Error('shareToTimeline is not supported in H5 environment');
|
|
694
|
+
},
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
biometrics = {
|
|
698
|
+
async checkIsAvailable(): Promise<boolean> {
|
|
699
|
+
return false;
|
|
700
|
+
},
|
|
701
|
+
|
|
702
|
+
async startVerify(): Promise<Taro.startSoterAuthentication.SuccessCallbackResult> {
|
|
703
|
+
throw new Error('Biometric authentication is not supported in H5 environment');
|
|
704
|
+
},
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
system = {
|
|
708
|
+
async getSystemInfo(): Promise<Taro.getSystemInfoSync.Result> {
|
|
709
|
+
return Promise.resolve(Taro.getSystemInfoSync());
|
|
710
|
+
},
|
|
711
|
+
|
|
712
|
+
async getNetworkType(): Promise<Taro.getNetworkType.SuccessCallbackResult> {
|
|
713
|
+
// 估算网络类型
|
|
714
|
+
const connection = (navigator as any).connection;
|
|
715
|
+
let networkType = 'unknown';
|
|
716
|
+
|
|
717
|
+
if (connection) {
|
|
718
|
+
if (connection.effectiveType) {
|
|
719
|
+
networkType = connection.effectiveType;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return {
|
|
724
|
+
networkType: networkType as any,
|
|
725
|
+
errMsg: 'getNetworkType:ok',
|
|
726
|
+
};
|
|
727
|
+
},
|
|
728
|
+
|
|
729
|
+
async getBatteryInfo(): Promise<Taro.getBatteryInfo.SuccessCallbackResult> {
|
|
730
|
+
// 需要Battery API支持
|
|
731
|
+
throw new Error('Battery API is not supported');
|
|
732
|
+
},
|
|
733
|
+
|
|
734
|
+
async getScreenBrightness(): Promise<number> {
|
|
735
|
+
// H5环境下无法获取屏幕亮度
|
|
736
|
+
return 1;
|
|
737
|
+
},
|
|
738
|
+
|
|
739
|
+
async setScreenBrightness(): Promise<void> {
|
|
740
|
+
// H5环境下无法设置屏幕亮度
|
|
741
|
+
},
|
|
742
|
+
|
|
743
|
+
async keepScreenOn(): Promise<void> {
|
|
744
|
+
// H5环境下无法保持屏幕常亮
|
|
745
|
+
},
|
|
746
|
+
|
|
747
|
+
async vibrate(): Promise<void> {
|
|
748
|
+
if (navigator.vibrate) {
|
|
749
|
+
navigator.vibrate(200);
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
clipboard = {
|
|
755
|
+
async set(text: string): Promise<void> {
|
|
756
|
+
if (navigator.clipboard) {
|
|
757
|
+
await navigator.clipboard.writeText(text);
|
|
758
|
+
} else {
|
|
759
|
+
// 降级方案
|
|
760
|
+
const textArea = document.createElement('textarea');
|
|
761
|
+
textArea.value = text;
|
|
762
|
+
document.body.appendChild(textArea);
|
|
763
|
+
textArea.select();
|
|
764
|
+
document.execCommand('copy');
|
|
765
|
+
document.body.removeChild(textArea);
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
|
|
769
|
+
async get(): Promise<string> {
|
|
770
|
+
if (navigator.clipboard) {
|
|
771
|
+
return await navigator.clipboard.readText();
|
|
772
|
+
} else {
|
|
773
|
+
// 降级方案
|
|
774
|
+
return '';
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
scan = {
|
|
780
|
+
async scanCode(): Promise<Taro.scanCode.SuccessCallbackResult> {
|
|
781
|
+
throw new Error('scanCode is not supported in H5 environment');
|
|
782
|
+
},
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
file = {
|
|
786
|
+
async saveFile(): Promise<Taro.saveFile.SuccessCallbackResult> {
|
|
787
|
+
throw new Error('saveFile is not supported in H5 environment');
|
|
788
|
+
},
|
|
789
|
+
|
|
790
|
+
async getFileInfo(): Promise<Taro.getFileInfo.SuccessCallbackResult> {
|
|
791
|
+
throw new Error('getFileInfo is not supported in H5 environment');
|
|
792
|
+
},
|
|
793
|
+
|
|
794
|
+
async getSavedFileList(): Promise<Taro.getSavedFileList.SuccessCallbackResult> {
|
|
795
|
+
throw new Error('getSavedFileList is not supported in H5 environment');
|
|
796
|
+
},
|
|
797
|
+
|
|
798
|
+
async removeSavedFile(): Promise<void> {
|
|
799
|
+
throw new Error('removeSavedFile is not supported in H5 environment');
|
|
800
|
+
},
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ==================== React Native适配器 ====================
|
|
805
|
+
|
|
806
|
+
class RNAdapter implements PlatformAdapter {
|
|
807
|
+
getPlatformInfo(): PlatformInfo {
|
|
808
|
+
const system = Taro.getSystemInfoSync();
|
|
809
|
+
|
|
810
|
+
return {
|
|
811
|
+
platform: 'rn',
|
|
812
|
+
isMiniProgram: false,
|
|
813
|
+
isH5: false,
|
|
814
|
+
isRN: true,
|
|
815
|
+
system,
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/** Headers对象转普通对象 */
|
|
820
|
+
private headersToObject(headers: Headers): Record<string, string> {
|
|
821
|
+
const result: Record<string, string> = {};
|
|
822
|
+
headers.forEach((value, key) => {
|
|
823
|
+
result[key] = value;
|
|
824
|
+
});
|
|
825
|
+
return result;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
async request<T = any>(config: RequestConfig): Promise<RequestResponse<T>> {
|
|
829
|
+
// 使用React Native的fetch实现
|
|
830
|
+
const url = new URL(config.url);
|
|
831
|
+
|
|
832
|
+
if (config.params) {
|
|
833
|
+
Object.entries(config.params).forEach(([key, value]) => {
|
|
834
|
+
url.searchParams.append(key, String(value));
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
const options: RequestInit = {
|
|
839
|
+
method: config.method || 'GET',
|
|
840
|
+
headers: {
|
|
841
|
+
'Content-Type': 'application/json',
|
|
842
|
+
...config.header,
|
|
843
|
+
},
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
if (config.data && ['POST', 'PUT', 'PATCH'].includes(config.method || 'GET')) {
|
|
847
|
+
options.body = JSON.stringify(config.data);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
try {
|
|
851
|
+
const response = await fetch(url.toString(), options);
|
|
852
|
+
const data = await response.json();
|
|
853
|
+
|
|
854
|
+
return {
|
|
855
|
+
data,
|
|
856
|
+
statusCode: response.status,
|
|
857
|
+
statusMessage: response.statusText,
|
|
858
|
+
header: this.headersToObject(response.headers),
|
|
859
|
+
};
|
|
860
|
+
} catch (error) {
|
|
861
|
+
const requestError: RequestError = {
|
|
862
|
+
message: error instanceof Error ? error.message : 'Network error',
|
|
863
|
+
detail: error,
|
|
864
|
+
};
|
|
865
|
+
throw requestError;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// React Native的存储实现需要使用AsyncStorage
|
|
870
|
+
storage = {
|
|
871
|
+
async set(_key: string, _value: any): Promise<void> {
|
|
872
|
+
// 这里需要导入AsyncStorage
|
|
873
|
+
// const { AsyncStorage } = require('react-native')
|
|
874
|
+
// await AsyncStorage.setItem(key, JSON.stringify(value))
|
|
875
|
+
throw new Error('AsyncStorage not implemented');
|
|
876
|
+
},
|
|
877
|
+
|
|
878
|
+
async get(_key: string): Promise<any> {
|
|
879
|
+
// const { AsyncStorage } = require('react-native')
|
|
880
|
+
// const value = await AsyncStorage.getItem(key)
|
|
881
|
+
// return value ? JSON.parse(value) : null
|
|
882
|
+
throw new Error('AsyncStorage not implemented');
|
|
883
|
+
},
|
|
884
|
+
|
|
885
|
+
async remove(_key: string): Promise<void> {
|
|
886
|
+
// const { AsyncStorage } = require('react-native')
|
|
887
|
+
// await AsyncStorage.removeItem(key)
|
|
888
|
+
throw new Error('AsyncStorage not implemented');
|
|
889
|
+
},
|
|
890
|
+
|
|
891
|
+
async clear(): Promise<void> {
|
|
892
|
+
// const { AsyncStorage } = require('react-native')
|
|
893
|
+
// await AsyncStorage.clear()
|
|
894
|
+
throw new Error('AsyncStorage not implemented');
|
|
895
|
+
},
|
|
896
|
+
|
|
897
|
+
async getInfo(): Promise<{ currentSize: number; limitSize: number }> {
|
|
898
|
+
throw new Error('Storage info not available in React Native');
|
|
899
|
+
},
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
// 其他React Native平台的实现...
|
|
903
|
+
// 由于React Native的API实现较为复杂,这里只提供基础框架
|
|
904
|
+
location = {
|
|
905
|
+
async getCurrentPosition(): Promise<Taro.getLocation.SuccessCallbackResult> {
|
|
906
|
+
throw new Error('Location service not implemented');
|
|
907
|
+
},
|
|
908
|
+
|
|
909
|
+
async openLocation(): Promise<void> {
|
|
910
|
+
throw new Error('openLocation not implemented');
|
|
911
|
+
},
|
|
912
|
+
|
|
913
|
+
async chooseLocation(): Promise<Taro.chooseLocation.SuccessCallbackResult> {
|
|
914
|
+
throw new Error('chooseLocation not implemented');
|
|
915
|
+
},
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
camera = {
|
|
919
|
+
async takePhoto(): Promise<any> {
|
|
920
|
+
throw new Error('Camera service not implemented');
|
|
921
|
+
},
|
|
922
|
+
|
|
923
|
+
async chooseImage(): Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
924
|
+
throw new Error('chooseImage not implemented');
|
|
925
|
+
},
|
|
926
|
+
|
|
927
|
+
async chooseVideo(): Promise<Taro.chooseVideo.SuccessCallbackResult> {
|
|
928
|
+
throw new Error('chooseVideo not implemented');
|
|
929
|
+
},
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
payment = {
|
|
933
|
+
async requestPayment(): Promise<void> {
|
|
934
|
+
throw new Error('Payment service not implemented');
|
|
935
|
+
},
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
share = {
|
|
939
|
+
async shareAppMessage(): Promise<void> {
|
|
940
|
+
throw new Error('Share service not implemented');
|
|
941
|
+
},
|
|
942
|
+
|
|
943
|
+
async shareToTimeline(): Promise<void> {
|
|
944
|
+
throw new Error('Share service not implemented');
|
|
945
|
+
},
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
biometrics = {
|
|
949
|
+
async checkIsAvailable(): Promise<boolean> {
|
|
950
|
+
throw new Error('Biometric service not implemented');
|
|
951
|
+
},
|
|
952
|
+
|
|
953
|
+
async startVerify(): Promise<Taro.startSoterAuthentication.SuccessCallbackResult> {
|
|
954
|
+
throw new Error('Biometric service not implemented');
|
|
955
|
+
},
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
system = {
|
|
959
|
+
async getSystemInfo(): Promise<Taro.getSystemInfoSync.Result> {
|
|
960
|
+
return Promise.resolve(Taro.getSystemInfoSync());
|
|
961
|
+
},
|
|
962
|
+
|
|
963
|
+
async getNetworkType(): Promise<Taro.getNetworkType.SuccessCallbackResult> {
|
|
964
|
+
throw new Error('Network type service not implemented');
|
|
965
|
+
},
|
|
966
|
+
|
|
967
|
+
async getBatteryInfo(): Promise<Taro.getBatteryInfo.SuccessCallbackResult> {
|
|
968
|
+
throw new Error('Battery service not implemented');
|
|
969
|
+
},
|
|
970
|
+
|
|
971
|
+
async getScreenBrightness(): Promise<number> {
|
|
972
|
+
throw new Error('Screen brightness service not implemented');
|
|
973
|
+
},
|
|
974
|
+
|
|
975
|
+
async setScreenBrightness(): Promise<void> {
|
|
976
|
+
throw new Error('Screen brightness service not implemented');
|
|
977
|
+
},
|
|
978
|
+
|
|
979
|
+
async keepScreenOn(): Promise<void> {
|
|
980
|
+
throw new Error('Keep screen on service not implemented');
|
|
981
|
+
},
|
|
982
|
+
|
|
983
|
+
async vibrate(): Promise<void> {
|
|
984
|
+
throw new Error('Vibrate service not implemented');
|
|
985
|
+
},
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
clipboard = {
|
|
989
|
+
async set(_text: string): Promise<void> {
|
|
990
|
+
throw new Error('Clipboard service not implemented');
|
|
991
|
+
},
|
|
992
|
+
|
|
993
|
+
async get(): Promise<string> {
|
|
994
|
+
throw new Error('Clipboard service not implemented');
|
|
995
|
+
},
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
scan = {
|
|
999
|
+
async scanCode(): Promise<Taro.scanCode.SuccessCallbackResult> {
|
|
1000
|
+
throw new Error('Scan service not implemented');
|
|
1001
|
+
},
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
file = {
|
|
1005
|
+
async saveFile(): Promise<Taro.saveFile.SuccessCallbackResult> {
|
|
1006
|
+
throw new Error('File service not implemented');
|
|
1007
|
+
},
|
|
1008
|
+
|
|
1009
|
+
async getFileInfo(): Promise<Taro.getFileInfo.SuccessCallbackResult> {
|
|
1010
|
+
throw new Error('File service not implemented');
|
|
1011
|
+
},
|
|
1012
|
+
|
|
1013
|
+
async getSavedFileList(): Promise<Taro.getSavedFileList.SuccessCallbackResult> {
|
|
1014
|
+
throw new Error('File service not implemented');
|
|
1015
|
+
},
|
|
1016
|
+
|
|
1017
|
+
async removeSavedFile(): Promise<void> {
|
|
1018
|
+
throw new Error('File service not implemented');
|
|
1019
|
+
},
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// ==================== 平台管理器 ====================
|
|
1024
|
+
|
|
1025
|
+
/** 平台管理器 */
|
|
1026
|
+
export class PlatformManager {
|
|
1027
|
+
private static instance: PlatformManager;
|
|
1028
|
+
private adapter: PlatformAdapter;
|
|
1029
|
+
private platformInfo: PlatformInfo;
|
|
1030
|
+
|
|
1031
|
+
private constructor() {
|
|
1032
|
+
const platform = this.detectPlatform();
|
|
1033
|
+
this.adapter = this.createAdapter(platform);
|
|
1034
|
+
this.platformInfo = this.adapter.getPlatformInfo();
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/** 获取单例实例 */
|
|
1038
|
+
static getInstance(): PlatformManager {
|
|
1039
|
+
if (!PlatformManager.instance) {
|
|
1040
|
+
PlatformManager.instance = new PlatformManager();
|
|
1041
|
+
}
|
|
1042
|
+
return PlatformManager.instance;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** 检测当前平台 */
|
|
1046
|
+
private detectPlatform(): Platform {
|
|
1047
|
+
if (typeof window !== 'undefined' && window.wx && (window.wx as any).getSystemInfo) {
|
|
1048
|
+
return 'weapp';
|
|
1049
|
+
} else if (typeof window !== 'undefined' && window.my && (window.my as any).getSystemInfo) {
|
|
1050
|
+
return 'alipay';
|
|
1051
|
+
} else if (typeof window !== 'undefined' && window.swan && (window.swan as any).getSystemInfo) {
|
|
1052
|
+
return 'swan';
|
|
1053
|
+
} else if (typeof window !== 'undefined' && window.tt && (window.tt as any).getSystemInfo) {
|
|
1054
|
+
return 'tt';
|
|
1055
|
+
} else if (typeof window !== 'undefined' && window.qq && (window.qq as any).getSystemInfo) {
|
|
1056
|
+
return 'qq';
|
|
1057
|
+
} else if (typeof window !== 'undefined' && window.jd && (window.jd as any).getSystemInfo) {
|
|
1058
|
+
return 'jd';
|
|
1059
|
+
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
1060
|
+
return 'rn';
|
|
1061
|
+
} else {
|
|
1062
|
+
return 'h5';
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
/** 创建平台适配器 */
|
|
1067
|
+
private createAdapter(platform: Platform): PlatformAdapter {
|
|
1068
|
+
switch (platform) {
|
|
1069
|
+
case 'weapp':
|
|
1070
|
+
return new WeappAdapter();
|
|
1071
|
+
case 'alipay':
|
|
1072
|
+
// 支付宝小程序适配器与微信类似,这里使用相同的实现
|
|
1073
|
+
return new WeappAdapter();
|
|
1074
|
+
case 'swan':
|
|
1075
|
+
// 百度小程序适配器与微信类似,这里使用相同的实现
|
|
1076
|
+
return new WeappAdapter();
|
|
1077
|
+
case 'tt':
|
|
1078
|
+
// 字节跳动小程序适配器与微信类似,这里使用相同的实现
|
|
1079
|
+
return new WeappAdapter();
|
|
1080
|
+
case 'qq':
|
|
1081
|
+
// QQ小程序适配器与微信类似,这里使用相同的实现
|
|
1082
|
+
return new WeappAdapter();
|
|
1083
|
+
case 'jd':
|
|
1084
|
+
// 京东小程序适配器与微信类似,这里使用相同的实现
|
|
1085
|
+
return new WeappAdapter();
|
|
1086
|
+
case 'h5':
|
|
1087
|
+
return new H5Adapter();
|
|
1088
|
+
case 'rn':
|
|
1089
|
+
return new RNAdapter();
|
|
1090
|
+
default:
|
|
1091
|
+
return new H5Adapter(); // 默认使用H5适配器
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** 获取平台适配器 */
|
|
1096
|
+
getAdapter(): PlatformAdapter {
|
|
1097
|
+
return this.adapter;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
/** 获取平台信息 */
|
|
1101
|
+
getPlatformInfo(): PlatformInfo {
|
|
1102
|
+
return this.platformInfo;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/** 获取当前平台 */
|
|
1106
|
+
getPlatform(): Platform {
|
|
1107
|
+
return this.platformInfo.platform;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/** 判断是否为指定平台 */
|
|
1111
|
+
isPlatform(targetPlatform: Platform): boolean {
|
|
1112
|
+
return this.platformInfo.platform === targetPlatform;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
/** 判断是否为小程序环境 */
|
|
1116
|
+
isMiniProgram(): boolean {
|
|
1117
|
+
return this.platformInfo.isMiniProgram;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/** 判断是否为H5环境 */
|
|
1121
|
+
isH5(): boolean {
|
|
1122
|
+
return this.platformInfo.isH5;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
/** 判断是否为React Native环境 */
|
|
1126
|
+
isRN(): boolean {
|
|
1127
|
+
return this.platformInfo.isRN;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/** 检查功能支持 */
|
|
1131
|
+
isFeatureSupported(feature: keyof typeof PLATFORM_FEATURES.weapp): boolean {
|
|
1132
|
+
const platform = this.platformInfo.platform;
|
|
1133
|
+
return PLATFORM_FEATURES[platform]?.[feature] || false;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/** 获取平台API映射 */
|
|
1137
|
+
getPlatformAPIs(): typeof PLATFORM_APIS.weapp {
|
|
1138
|
+
const platform = this.platformInfo.platform;
|
|
1139
|
+
return PLATFORM_APIS[platform] || PLATFORM_APIS.h5;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/** 获取平台名称 */
|
|
1143
|
+
getPlatformName(): string {
|
|
1144
|
+
const platform = this.platformInfo.platform;
|
|
1145
|
+
return PLATFORM_NAMES[platform] || 'Unknown';
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/** 重置平台管理器(主要用于测试) */
|
|
1149
|
+
reset(): void {
|
|
1150
|
+
PlatformManager.instance = new PlatformManager();
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// ==================== 导出平台工具 ====================
|
|
1155
|
+
|
|
1156
|
+
/** 创建平台管理器实例 */
|
|
1157
|
+
export const platformManager = PlatformManager.getInstance();
|
|
1158
|
+
|
|
1159
|
+
/** 导出平台适配器 */
|
|
1160
|
+
export const platformAdapter = platformManager.getAdapter();
|
|
1161
|
+
|
|
1162
|
+
/** 导出平台检测工具 */
|
|
1163
|
+
export const platformUtils = {
|
|
1164
|
+
getPlatform: () => platformManager.getPlatform(),
|
|
1165
|
+
getPlatformInfo: () => platformManager.getPlatformInfo(),
|
|
1166
|
+
isPlatform: (platform: Platform) => platformManager.isPlatform(platform),
|
|
1167
|
+
isMiniProgram: () => platformManager.isMiniProgram(),
|
|
1168
|
+
isH5: () => platformManager.isH5(),
|
|
1169
|
+
isRN: () => platformManager.isRN(),
|
|
1170
|
+
isFeatureSupported: (feature: keyof typeof PLATFORM_FEATURES.weapp) => platformManager.isFeatureSupported(feature),
|
|
1171
|
+
getPlatformAPIs: () => platformManager.getPlatformAPIs(),
|
|
1172
|
+
getPlatformName: () => platformManager.getPlatformName(),
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
/** 导出快捷方法 */
|
|
1176
|
+
export const {
|
|
1177
|
+
getPlatform,
|
|
1178
|
+
getPlatformInfo,
|
|
1179
|
+
isPlatform,
|
|
1180
|
+
isMiniProgram,
|
|
1181
|
+
isH5,
|
|
1182
|
+
isRN,
|
|
1183
|
+
isFeatureSupported,
|
|
1184
|
+
getPlatformAPIs,
|
|
1185
|
+
getPlatformName,
|
|
1186
|
+
} = platformUtils;
|
|
1187
|
+
|
|
1188
|
+
// 类型已经在前面导出,这里不需要重复导出
|