index.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { Component, PropsWithChildren, useEffect } from 'react'
  2. import { View, Text, Button, Input } from '@tarojs/components'
  3. // import './index.scss'
  4. import Taro, { useReady } from '@tarojs/taro'
  5. // import ComponentA from './component'
  6. import Rings from '@components/Rings';
  7. import SingleSelect from '@components/SingleSelect';
  8. import { useDispatch, useSelector } from 'react-redux';
  9. import { getInfoSuccess } from '@/store/user';
  10. import { wxPubFollow } from '@/services/permission';
  11. import { staticResources } from '@/services/common';
  12. import { use } from 'i18next';
  13. // import TabBar from '../../components/Tabbar';
  14. export default function IndexPage() {
  15. const dispatch = useDispatch();
  16. const array: any[] = []
  17. const user = useSelector((state: any) => state.user);
  18. const permission = useSelector((state: any) => state.permission);
  19. const common = useSelector((state: any) => state.common);
  20. array.push('ffff');
  21. array.push(<Text>ffff</Text>)
  22. // array.push(<Rings radius={50}/>)
  23. useEffect(() => {
  24. dispatch(staticResources() as any);
  25. }, [])
  26. useReady(async () => {
  27. const userData = await getStorage('userData');
  28. if (userData) {
  29. dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
  30. // return JSON.parse(userData as string) as UserState;
  31. setTimeout(() => {
  32. checkWXPubFollow()
  33. }, 200)
  34. }
  35. })
  36. function checkWXPubFollow() {
  37. wxPubFollow().then(res => {
  38. console.log(res);
  39. })
  40. }
  41. function followWxPub() {
  42. const resource = common.resources.filter((item: any) => {
  43. return item.code == 'follow_wx_pub'
  44. })
  45. Taro.showModal({
  46. title: '提示',
  47. content: '关注公众号后可接收提醒\n点击确定,前往关注',
  48. showCancel: true,
  49. success(result) {
  50. if (result.confirm) {
  51. Taro.navigateTo({
  52. url: '/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url,
  53. })
  54. }
  55. },
  56. })
  57. }
  58. async function getStorage(key: string) {
  59. try {
  60. const res = await Taro.getStorage({ key });
  61. return res.data;
  62. } catch {
  63. return '';
  64. }
  65. }
  66. function goDetail() {
  67. Taro.navigateTo({
  68. // url: '/pages/index/detail'
  69. //src/moduleA/pages/third.tsx
  70. url: '../../moduleA/pages/third'
  71. })
  72. }
  73. function login() {
  74. if (user.isLogin) {
  75. Taro.navigateTo({
  76. url: '/pages/ChooseScenario'
  77. })
  78. }
  79. else {
  80. Taro.navigateTo({
  81. url: '/pages/ChooseAuth'
  82. })
  83. }
  84. }
  85. return (
  86. <View style={{ backgroundColor: '#fff', flex: 1, flexDirection: 'column', display: 'flex' }}>
  87. <Text>homepage12234</Text>
  88. <Text>{user.isLogin ? '已登录' : '未登录'}</Text>
  89. <Text>{user.isLogin ? `用户昵称:${user.nickname}` : ''}</Text>
  90. {
  91. permission.wxPubFollow == false && <Text onClick={() => followWxPub()}>去关注公众号</Text>
  92. }
  93. {/* <ComponentA value="ABBBB" /> */}
  94. <Button onClick={() => goDetail()}>go detail</Button>
  95. {/* <SingleSelect items={array}></SingleSelect> */}
  96. <Rings radius={50} />
  97. <Input placeholder="请输入用户名1" style={{ textAlign: 'left', backgroundColor: 'pink' }} />
  98. <Text className='login' onClick={() => login()}>sss</Text>
  99. {/* <TabBar /> */}
  100. </View>
  101. )
  102. }
  103. // export default class Index extends Component<PropsWithChildren> {
  104. // componentDidMount () { }
  105. // componentWillUnmount () { }
  106. // componentDidShow () { }
  107. // componentDidHide () { }
  108. // goDetail(){
  109. // Taro.navigateTo({
  110. // url: '/pages/index/detail'
  111. // })
  112. // }
  113. // render () {
  114. // return (
  115. // <View className='index'>
  116. // <Text>Hello world123!</Text>
  117. // <ComponentA value="A"/>
  118. // <Button onClick={()=>this.goDetail()}>detail</Button>
  119. // </View>
  120. // )
  121. // }
  122. // }