|
@@ -10,241 +10,81 @@ import { followUser, getFriendDashBoard, getFriendMoments, getMyFriends, getUser
|
|
|
import FriendGuide from "./guide";
|
|
import FriendGuide from "./guide";
|
|
|
import EmptyContent from "./empty_content";
|
|
import EmptyContent from "./empty_content";
|
|
|
import MomentItem from "./moment_item";
|
|
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 FriendMain from "./friend_main";
|
|
|
|
|
|
|
|
-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 Friend() {
|
|
export default function Friend() {
|
|
|
|
|
+ const dispatch = useDispatch();
|
|
|
const user = useSelector((state: any) => state.user);
|
|
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 [loaded, setLoaded] = useState(false)
|
|
|
- const [homeType, setHomeType] = useState('NO_FRIEND')
|
|
|
|
|
- const [dashBoard, setDashBoard] = useState<any>(null)
|
|
|
|
|
- const [moments, setMoments] = useState<any>([])
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- timer = setInterval(() => {
|
|
|
|
|
- setCount(count => count + 1)
|
|
|
|
|
- }, 1000)
|
|
|
|
|
- return () => {
|
|
|
|
|
- clearInterval(timer)
|
|
|
|
|
|
|
+ if (process.env.TARO_ENV == 'weapp') {
|
|
|
|
|
+ loadWXCache()
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ loadRNCache()
|
|
|
}
|
|
}
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
-
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- myFriends()
|
|
|
|
|
- if (router.params.type == 'share') {
|
|
|
|
|
- console.log('b', launchObj.shareTicket)
|
|
|
|
|
- if (launchObj.shareTicket) {
|
|
|
|
|
- Taro.getShareInfo({
|
|
|
|
|
- shareTicket: launchObj.shareTicket,
|
|
|
|
|
- success(result) {
|
|
|
|
|
- console.log('share info', result)
|
|
|
|
|
- updateRelation(result)
|
|
|
|
|
- },
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- updateRelation(null)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- console.log('c')
|
|
|
|
|
|
|
+ getWindows()
|
|
|
}, [user.isLogin])
|
|
}, [user.isLogin])
|
|
|
|
|
|
|
|
- function myFriends() {
|
|
|
|
|
- if (!user.isLogin) {
|
|
|
|
|
- setLoaded(true)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- getMyFriends({
|
|
|
|
|
- page: 1,
|
|
|
|
|
- limit: 10
|
|
|
|
|
- }).then(res => {
|
|
|
|
|
- console.log(res)
|
|
|
|
|
- setCount((res as any).total)
|
|
|
|
|
- setFriends((res as any).data)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- getFriendDashBoard().then(res => {
|
|
|
|
|
- setLoaded(true)
|
|
|
|
|
- setHomeType((res as any).homepage_type)
|
|
|
|
|
- setDashBoard(res)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- getFriendMoments({
|
|
|
|
|
- page: 1,
|
|
|
|
|
- limit: 50
|
|
|
|
|
- }).then(res => {
|
|
|
|
|
- setMoments((res as any).data)
|
|
|
|
|
|
|
+ function getWindows() {
|
|
|
|
|
+ windows().then(res => {
|
|
|
|
|
+ dispatch(setFastWithSleep((res as any).fast_with_sleep))
|
|
|
|
|
+ dispatch(setWindows((res as any).windows))
|
|
|
|
|
+ dispatch(setLongFast((res as any).long_fast))
|
|
|
|
|
+ dispatch(setRefreshs((res as any).refresh_timestamps))
|
|
|
|
|
+ dispatch(setFinishSetup((res as any).finish_setup))
|
|
|
|
|
+ }).catch(e => {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updateRelation(obj) {
|
|
|
|
|
- if (!user.isLogin) {
|
|
|
|
|
- Taro.setStorageSync('share_uid', router.params.uid)
|
|
|
|
|
- Taro.setStorageSync('share_info', JSON.stringify(obj))
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ function loadWXCache() {
|
|
|
|
|
+ var gps = Taro.getStorageSync('gps')
|
|
|
|
|
+ if (gps) {
|
|
|
|
|
+ global.locationDetail = JSON.parse(gps)
|
|
|
}
|
|
}
|
|
|
- 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()
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ global.memberAlert = Taro.getStorageSync('memberAlert') || false
|
|
|
|
|
+ var userData = Taro.getStorageSync('userData')
|
|
|
|
|
+ if (userData) {
|
|
|
|
|
+ console.log('load user cache')
|
|
|
|
|
+ dispatch(getInfoSuccess(JSON.parse(userData)));
|
|
|
}
|
|
}
|
|
|
|
|
+ setLoaded(true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- 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 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>
|
|
|
|
|
|
|
+ async function loadRNCache() {
|
|
|
|
|
+ var showDayRing = await getStorage('showDayRing') || false;
|
|
|
|
|
+ var showNightRing = await getStorage('showNightRing') || false;
|
|
|
|
|
+ global.memberAlert = await getStorage('memberAlert') || false
|
|
|
|
|
+ var gps = await getStorage('gps')
|
|
|
|
|
+ if (gps) {
|
|
|
|
|
+ global.locationDetail = JSON.parse(gps)
|
|
|
}
|
|
}
|
|
|
- if (!user.isLogin) {
|
|
|
|
|
- return friendGuide()
|
|
|
|
|
- }
|
|
|
|
|
- switch (homeType) {
|
|
|
|
|
- case 'NO_FRIEND':
|
|
|
|
|
- return friendGuide()
|
|
|
|
|
- case 'NO_MOMENT':
|
|
|
|
|
- return empty()
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var userData = await getStorage('userData')
|
|
|
|
|
+ console.log(userData)
|
|
|
|
|
+ if (userData) {
|
|
|
|
|
+ dispatch(getInfoSuccess(JSON.parse(userData)));
|
|
|
}
|
|
}
|
|
|
- return <View >
|
|
|
|
|
- <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
|
|
|
|
|
- <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>
|
|
|
|
|
|
|
+ setLoaded(true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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} />
|
|
|
|
|
|
|
+ async function getStorage(key: string) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await Taro.getStorage({ key });
|
|
|
|
|
+ return res.data;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return '';
|
|
|
}
|
|
}
|
|
|
- </View>
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!loaded)
|
|
|
|
|
+ return <View />
|
|
|
|
|
+ return <FriendMain />
|
|
|
}
|
|
}
|