|
|
@@ -0,0 +1,291 @@
|
|
|
+
|
|
|
+
|
|
|
+import TabBar from "@/components/navigation/TabBar";
|
|
|
+import { rpxToPx } from "@/utils/tools";
|
|
|
+import { View, Text, Image, ScrollView, Button } from "@tarojs/components";
|
|
|
+import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
|
|
|
+import { useDispatch, useSelector } from "react-redux";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
+import { followUser, getFriendDashBoard, getFriendMoments, getMyFriends, getUserHome } from "@/services/friend";
|
|
|
+import FriendGuide from "./guide";
|
|
|
+import EmptyContent from "./empty_content";
|
|
|
+import MomentItem from "./moment_item";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+import { windows } from "@/services/health";
|
|
|
+import { setFastWithSleep, setFinishSetup, setLongFast, setRefreshs, setWindows } from "@/store/health";
|
|
|
+import { getInfoSuccess } from "@/store/user";
|
|
|
+import showActionSheet from "@/components/basic/ActionSheet";
|
|
|
+import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
|
|
|
+
|
|
|
+let useRoute;
|
|
|
+let useNavigation;
|
|
|
+if (process.env.TARO_ENV == 'rn') {
|
|
|
+ useRoute = require("@react-navigation/native").useRoute
|
|
|
+ useNavigation = require("@react-navigation/native").useNavigation
|
|
|
+}
|
|
|
+
|
|
|
+let timer;
|
|
|
+export default function FriendMain() {
|
|
|
+ const user = useSelector((state: any) => state.user);
|
|
|
+ const launchObj = Taro.getLaunchOptionsSync()
|
|
|
+
|
|
|
+ const observerObjBottom = Taro.createIntersectionObserver().relativeToViewport({ bottom: 100 })
|
|
|
+
|
|
|
+ const [friends, setFriends] = useState<any>([])
|
|
|
+ const [count, setCount] = useState(0)
|
|
|
+
|
|
|
+ const systemInfo: any = Taro.getWindowInfo ? Taro.getWindowInfo() : Taro.getSystemInfoSync();
|
|
|
+ const navigationBarHeight = systemInfo.statusBarHeight + 44;
|
|
|
+
|
|
|
+ let router
|
|
|
+ let navigation;
|
|
|
+ if (useNavigation) {
|
|
|
+ navigation = useNavigation()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ router = useRoute()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ router = useRouter()
|
|
|
+ }
|
|
|
+
|
|
|
+ const [loaded, setLoaded] = useState(false)
|
|
|
+ const [homeType, setHomeType] = useState('NO_FRIEND')
|
|
|
+ const [dashBoard, setDashBoard] = useState<any>(null)
|
|
|
+ const [moments, setMoments] = useState<any>([])
|
|
|
+ const dispatch = useDispatch()
|
|
|
+ const { t } = useTranslation()
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ loadData()
|
|
|
+ timer = setInterval(() => {
|
|
|
+ setCount(count => count + 1)
|
|
|
+ }, 1000)
|
|
|
+ return () => {
|
|
|
+ clearInterval(timer)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ function loadData() {
|
|
|
+ var userData = Taro.getStorageSync('userData')
|
|
|
+ if (userData) {
|
|
|
+ console.log('load user cache')
|
|
|
+ dispatch(getInfoSuccess(JSON.parse(userData)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ myFriends()
|
|
|
+ if (router.params.type == 'share') {
|
|
|
+ if (launchObj.shareTicket) {
|
|
|
+ Taro.getShareInfo({
|
|
|
+ shareTicket: launchObj.shareTicket,
|
|
|
+ success(result) {
|
|
|
+ console.log('share info', result)
|
|
|
+ updateRelation(result)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ updateRelation(null)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, [user.isLogin])
|
|
|
+
|
|
|
+ function myFriends() {
|
|
|
+ if (!user.isLogin) {
|
|
|
+ setLoaded(true)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ getFriendDashBoard().then(res => {
|
|
|
+ setLoaded(true)
|
|
|
+ setHomeType((res as any).homepage_type)
|
|
|
+ setDashBoard(res)
|
|
|
+ })
|
|
|
+
|
|
|
+ getFriendMoments({
|
|
|
+ page: 1,
|
|
|
+ limit: 10
|
|
|
+ }).then(res => {
|
|
|
+ setMoments((res as any).data)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateRelation(obj) {
|
|
|
+ if (!user.isLogin) {
|
|
|
+ Taro.setStorageSync('share_uid', router.params.uid)
|
|
|
+ Taro.setStorageSync('share_info', JSON.stringify(obj))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log('user login')
|
|
|
+ if (user.id != router.params.uid) {
|
|
|
+ var params: any = {
|
|
|
+ follow_origin: obj ? 'WECHAT_GROUP_CHAT' : 'WECHAT_PRIVATE_CHAT'
|
|
|
+ }
|
|
|
+ if (obj) {
|
|
|
+ params.wechat = obj
|
|
|
+ }
|
|
|
+ followUser(router.params.uid, params).then(res => {
|
|
|
+ myFriends()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ // observerObjBottom.observe('#a', (res) => {
|
|
|
+ // console.log('a')
|
|
|
+ // })
|
|
|
+ // observerObjBottom.observe('#b', (res) => {
|
|
|
+ // console.log('b')
|
|
|
+ // })
|
|
|
+ // observerObjBottom.observe('#c', (res) => {
|
|
|
+ // console.log('c')
|
|
|
+ // })
|
|
|
+ // observerObjBottom.observe('#d', (res) => {
|
|
|
+ // console.log('d')
|
|
|
+ // })
|
|
|
+ observerObjBottom.observe('#e', (res) => {
|
|
|
+ console.log('e')
|
|
|
+ })
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ if (process.env.TARO_ENV == 'weapp' /*&& global.allowShare*/) {
|
|
|
+ Taro.updateShareMenu({
|
|
|
+ withShareTicket: true,
|
|
|
+ success() { }
|
|
|
+ })
|
|
|
+
|
|
|
+ useShareAppMessage((e) => {
|
|
|
+ var sharePath = ``
|
|
|
+ if (global.shareData) {
|
|
|
+ console.log(global.shareData)
|
|
|
+ }
|
|
|
+ console.log('share_url', '/pages/friend/friend?type=share&uid=' + user.id)
|
|
|
+ return {
|
|
|
+ title: 'Friends ',
|
|
|
+ path: '/pages/friend/friend?type=share&uid=' + user.id,
|
|
|
+ // imageUrl: imageUrl
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function more(){
|
|
|
+ showActionSheet({
|
|
|
+ title:'',
|
|
|
+ itemList:['个人主页','我的搭子','消息通知'],
|
|
|
+ success:(index)=>{
|
|
|
+ switch(index){
|
|
|
+ case 0:
|
|
|
+ jumpPage('/_moment/pages/home')
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ jumpPage('/_moment/pages/relation')
|
|
|
+ break
|
|
|
+ case 2:
|
|
|
+ jumpPage('/_moment/pages/message')
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function friendGuide() {
|
|
|
+ return <View>
|
|
|
+ <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
|
|
|
+ <FriendGuide />
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
+ }</View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function empty() {
|
|
|
+ return <View>
|
|
|
+ <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
|
|
|
+ <EmptyContent friends={dashBoard.friends} />
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function content() {
|
|
|
+ if (!loaded) {
|
|
|
+ return <View >
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ if (!user.isLogin) {
|
|
|
+ return friendGuide()
|
|
|
+ }
|
|
|
+ switch (homeType) {
|
|
|
+ case 'NO_FRIEND':
|
|
|
+ return friendGuide()
|
|
|
+ case 'NO_MOMENT':
|
|
|
+ return empty()
|
|
|
+
|
|
|
+ }
|
|
|
+ return <View >
|
|
|
+ <View style={{
|
|
|
+ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff', display: 'flex',
|
|
|
+ flexDirection: 'column', justifyContent: 'flex-end'
|
|
|
+ }}>
|
|
|
+ <View style={{ height: 44, width: rpxToPx(750),position:'relative', display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
+ <View>{t('health.moments')}</View>
|
|
|
+ <View onClick={more} style={{position:'absolute',left:0,top:0,bottom:0,width:80,display:'flex',alignItems:'center',justifyContent:'center'}}>More</View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View style={{ backgroundColor: '#fff', minHeight: '100vh' }}>
|
|
|
+ {
|
|
|
+ moments.map((item, index) => {
|
|
|
+ return <View key={index}>
|
|
|
+ <MomentItem data={item} />
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ return content()
|
|
|
+
|
|
|
+
|
|
|
+ return <View>
|
|
|
+ <ScrollView scrollY style={{ height: '100vh' }}>
|
|
|
+ <Button openType="share">分享</Button>
|
|
|
+ <View>好友数量{count}</View>
|
|
|
+ {
|
|
|
+ friends.map((item, index) => {
|
|
|
+ return <View key={index}>
|
|
|
+ <Image src={item.avatar} style={{ width: 70, height: 70 }} />
|
|
|
+ <Text>{item.nickname}</Text>
|
|
|
+ <Text>{item.relation}</Text>
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ <View style={{ height: '100vh', backgroundColor: 'pink', width: rpxToPx(750) }} id="a"></View>
|
|
|
+ <View style={{ height: '100vh', backgroundColor: 'blue', width: rpxToPx(750) }} id="b"></View>
|
|
|
+ <View style={{ height: '100vh', backgroundColor: 'yellow', width: rpxToPx(750) }} id="c"></View>
|
|
|
+ <View style={{ height: '100vh', backgroundColor: 'green', width: rpxToPx(750) }} id="d"></View>
|
|
|
+ <View style={{ height: '100vh', backgroundColor: 'red', width: rpxToPx(750) }} id="e"></View>
|
|
|
+ </ScrollView>
|
|
|
+ {
|
|
|
+ process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+}
|