-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
171 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.__dumi_taro-hook-hidden { | ||
display: none; | ||
} | ||
|
||
.__dumi-default-mobile-demo-layout { | ||
font-size: 0.36rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
export default { | ||
esm: 'rollup', | ||
cjs: 'rollup', | ||
esm: { | ||
type: 'babel', | ||
}, | ||
cjs: { | ||
type: 'babel', | ||
lazy: true, | ||
}, | ||
umd: { | ||
globals: 'taro-hooks', | ||
name: 'taro-hooks', | ||
miniFile: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export default { | ||
pages: ['pages/index/index'], | ||
pages: ['pages/index/index', 'pages/useEnv/index'], | ||
window: { | ||
backgroundTextStyle: 'light', | ||
navigationBarBackgroundColor: '#fff', | ||
navigationBarTitleText: 'WeChat', | ||
navigationBarTitleText: 'taro-hooks', | ||
navigationBarTextStyle: 'black', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,48 @@ | ||
import React, { Component } from 'react'; | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { View, Text } from '@tarojs/components'; | ||
import Taro from '@tarojs/taro'; | ||
import { AtButton } from 'taro-ui'; | ||
import 'taro-ui/dist/style/components/button.scss'; // 按需引入 | ||
import './index.less'; | ||
import { AtList, AtListItem } from 'taro-ui'; | ||
|
||
import Taro, { ENV_TYPE } from '@tarojs/taro'; | ||
import { useEnv } from 'taro-hooks'; | ||
|
||
export default class Index extends Component { | ||
componentWillMount() {} | ||
import 'taro-ui/dist/style/components/icon.scss'; | ||
import './index.less'; | ||
|
||
componentDidMount() {} | ||
import { webPages, weappPages } from '../../route'; | ||
|
||
componentWillUnmount() {} | ||
const Index = () => { | ||
const env = useEnv(); | ||
|
||
componentDidShow() {} | ||
const pages = useMemo(() => { | ||
return env === ENV_TYPE.WEB ? webPages : weappPages; | ||
}, [env]); | ||
|
||
componentDidHide() {} | ||
const handleLocation = useCallback( | ||
(route) => { | ||
if (env === ENV_TYPE.WEAPP) { | ||
Taro.navigateTo({ | ||
url: route, | ||
}); | ||
} else { | ||
window.parent.location = route; | ||
} | ||
}, | ||
[env], | ||
); | ||
return ( | ||
<AtList> | ||
{pages.map((config) => { | ||
const [name, route] = Object.entries(config)[0]; | ||
return ( | ||
<AtListItem | ||
key={name} | ||
title={name} | ||
onClick={() => handleLocation(route)} | ||
/> | ||
); | ||
})} | ||
</AtList> | ||
); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<View className="index"> | ||
<Text>Hello world!</Text> | ||
<AtButton type="primary">I need Taro UI</AtButton> | ||
<Text>Taro UI 支持 Vue 了吗?</Text> | ||
<AtButton type="primary" circle> | ||
支持 | ||
</AtButton> | ||
<Text>共建?</Text> | ||
<AtButton type="secondary" circle> | ||
来 | ||
</AtButton> | ||
</View> | ||
); | ||
} | ||
} | ||
export default Index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
navigationBarTitleText: 'useEnv', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useCallback } from 'react'; | ||
import { AtRadio, AtMessage } from 'taro-ui'; | ||
|
||
import { useEnv } from 'taro-hooks'; | ||
import Taro, { ENV_TYPE } from '@tarojs/taro'; | ||
|
||
import 'taro-ui/dist/style/components/icon.scss'; | ||
|
||
const radioOptions = (env: ENV_TYPE) => | ||
Object.entries(ENV_TYPE).map(([label, value]) => ({ | ||
label, | ||
value, | ||
desc: `环境: ${label}`, | ||
disabled: value !== env, | ||
})); | ||
|
||
export default () => { | ||
const env = useEnv(); | ||
|
||
const handleRadioClick = useCallback(() => { | ||
Taro.atMessage({ | ||
message: '当前环境类型: ' + env, | ||
type: 'info', | ||
}); | ||
}, [env]); | ||
|
||
return ( | ||
<> | ||
<AtMessage /> | ||
<AtRadio | ||
options={radioOptions(env)} | ||
value={env} | ||
onClick={() => handleRadioClick()} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// 自动生成demos导航 | ||
import appConfig from '../app.config'; | ||
|
||
const BASEURL = '/~demos/pages-'; | ||
const weappRoute = appConfig.pages.filter((v) => !v.includes('index/index')); | ||
const roureName = weappRoute.map((v) => v.split('/')[1].toLocaleLowerCase()); | ||
const webPages = weappRoute.map((v, i) => ({ | ||
[roureName[i]]: BASEURL + v, | ||
})); | ||
const weappPages = weappRoute.map((v, i) => ({ | ||
[roureName[i]]: v, | ||
})); | ||
|
||
export { webPages, weappPages }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import useEnv from './useEnv'; | ||
|
||
export { useEnv }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,13 @@ group: | |
--- | ||
|
||
# useEnv | ||
|
||
获取当前环境值 | ||
|
||
## 何时使用 | ||
|
||
当需要获取当前环境值做一些判断时 | ||
|
||
## 代码演示 | ||
|
||
<code src="@pages/useEnv" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Taro from '@tarojs/taro'; | ||
|
||
const useEnv = (): Taro.ENV_TYPE => { | ||
return Taro.getEnv(); | ||
}; | ||
|
||
export default useEnv; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
declare module '*.css'; | ||
declare module '*.less'; | ||
|
||
declare module 'taro-hooks'; |