|
|
@@ -14,6 +14,8 @@ import { TimeFormatter } from "@/utils/time_format";
|
|
|
import TargetProgress from "@/_health/components/target_progress";
|
|
|
import { getThemeColor } from "@/features/health/hooks/health_hooks";
|
|
|
import formatMilliseconds from "@/utils/format_time";
|
|
|
+import SingleImage from "@/_health/components/single_img";
|
|
|
+import { journalDetail } from "@/services/health";
|
|
|
|
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
|
@@ -28,6 +30,7 @@ export default function JournalDetail() {
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
const [imgs, setImgs] = useState<any>([])
|
|
|
const [events, setEvents] = useState<any>([])
|
|
|
+ const [loaded, setLoaded] = useState(false)
|
|
|
|
|
|
let router
|
|
|
let navigation;
|
|
|
@@ -41,13 +44,19 @@ export default function JournalDetail() {
|
|
|
else {
|
|
|
router = useRouter()
|
|
|
}
|
|
|
- const [data, setData] = useState<any>(JSON.parse(router.params.detail))
|
|
|
+ const [data, setData] = useState<any>()
|
|
|
+ const date = router.params.date
|
|
|
// const [detail, setDetail] = useState(JSON.parse(router.params.detail))
|
|
|
|
|
|
useEffect(() => {
|
|
|
- let obj = JSON.parse(router.params.detail)
|
|
|
+ journalDetail(date).then(res => {
|
|
|
+ setData(res)
|
|
|
+ updateData(res)
|
|
|
+ setLoaded(true)
|
|
|
+ })
|
|
|
+ }, [])
|
|
|
|
|
|
- console.log(obj)
|
|
|
+ function updateData(obj) {
|
|
|
|
|
|
var array: any = []
|
|
|
|
|
|
@@ -82,43 +91,27 @@ export default function JournalDetail() {
|
|
|
// 合并其他项和排序后的 fastStartItems
|
|
|
const result = otherItems.concat(fastStartItems);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ let array2: any = []
|
|
|
+ obj.windows.map(item => {
|
|
|
+ item.events.map(event => {
|
|
|
+ event.moments && event.moments.map(moment => {
|
|
|
+ if (moment.media && moment.media.length > 0) {
|
|
|
+ moment.media.map(media => {
|
|
|
+ array2.push(media.url)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+ })
|
|
|
+ obj.imgs = array2
|
|
|
+
|
|
|
+
|
|
|
setImgs(obj.imgs)
|
|
|
setEvents(result)
|
|
|
- }, [])
|
|
|
-
|
|
|
- // function demo() {
|
|
|
- // const array = [
|
|
|
- // { id: 1, event: "START" },
|
|
|
- // { id: 2, event: "FAST_START1" },
|
|
|
- // { id: 3, event: "STOP" },
|
|
|
- // { id: 4, event: "FAST_START5" },
|
|
|
- // { id: 5, event: "FAST_START3" },
|
|
|
- // { id: 6, event: "FAST_START2" },
|
|
|
- // { id: 7, event: "PAUSE" }
|
|
|
- // ];
|
|
|
-
|
|
|
- // // 定义排序的顺序
|
|
|
- // const order = {
|
|
|
- // "FAST_START1": 1,
|
|
|
- // "FAST_START2": 2,
|
|
|
- // "FAST_START3": 3,
|
|
|
- // "FAST_START4": 4
|
|
|
- // };
|
|
|
-
|
|
|
- // // 分离出需要排序的项和其他项
|
|
|
- // const otherItems = array.filter(item => !order[item.event]);
|
|
|
- // const fastStartItems = array.filter(item => order[item.event]);
|
|
|
-
|
|
|
- // // 排序 fastStartItems
|
|
|
- // fastStartItems.sort((a, b) => {
|
|
|
- // return (order[a.event] || 0) - (order[b.event] || 0);
|
|
|
- // });
|
|
|
-
|
|
|
- // // 合并其他项和排序后的 fastStartItems
|
|
|
- // const result = otherItems.concat(fastStartItems);
|
|
|
-
|
|
|
- // console.log(result);
|
|
|
- // }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
function preview(url) {
|
|
|
@@ -173,44 +166,15 @@ export default function JournalDetail() {
|
|
|
</View>
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
- {/* {
|
|
|
- (detail.scenario != 'MEAL' && detail.scenario != 'ACTIVITY') && <View style={{ flexDirection: 'column', display: 'flex', marginBottom: rpxToPx(48) }}>
|
|
|
- <TimeTitleDesc
|
|
|
- timeObj={detail.time}
|
|
|
- time={dayjs(detail.time.timestamp).format('HH:mm')}
|
|
|
- title={detail.title}
|
|
|
- />
|
|
|
- </View>
|
|
|
- }
|
|
|
- {
|
|
|
- detail.scenario == 'ACTIVITY' && !list && <View style={{ flexDirection: 'column', display: 'flex', marginBottom: rpxToPx(48) }}>
|
|
|
- <TimeTitleDesc
|
|
|
- timeObj={detail.time}
|
|
|
- time={dayjs(detail.time.timestamp).format('HH:mm')}
|
|
|
- title={detail.title}
|
|
|
- />
|
|
|
- </View>
|
|
|
- }
|
|
|
- {
|
|
|
- list && list.map((item, index) => {
|
|
|
- return <View key={index} style={{ flexDirection: 'column', display: 'flex', marginBottom: rpxToPx(48) }}>
|
|
|
- <TimeTitleDesc
|
|
|
- timeObj={detail.time}
|
|
|
- time={dayjs(detail.time.timestamp).format('HH:mm')}
|
|
|
- title={detail.title}
|
|
|
- desc={item.description}
|
|
|
- />
|
|
|
- </View>
|
|
|
- })
|
|
|
- } */}
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
+ if (!loaded) return <View />
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- return <View style={{backgroundColor:'#fff'}}>
|
|
|
+ return <View style={{ backgroundColor: '#fff' }}>
|
|
|
<View className="journal_detail">
|
|
|
<Image className="header_avatar" src={user.avatar} mode="aspectFill" />
|
|
|
<View className="jounal_content">
|
|
|
@@ -219,59 +183,18 @@ export default function JournalDetail() {
|
|
|
{
|
|
|
events.map((item, index) => {
|
|
|
return eventList(item, index)
|
|
|
- // if (item.scenario != 'MEAL' && item.scenario != 'ACTIVITY') {
|
|
|
- // return <View key={index} style={{ marginBottom: index < events.length - 1 ? rpxToPx(48) : 0, display: 'flex', flexDirection: 'column' }}>
|
|
|
-
|
|
|
- // <Text style={{ color: '#5C7099' }}>{dayjs(item.time.timestamp).format('HH:mm')}
|
|
|
- // {
|
|
|
- // item.title && <Text> {item.title}</Text>
|
|
|
- // }
|
|
|
- // </Text>
|
|
|
- // </View>
|
|
|
- // }
|
|
|
-
|
|
|
- // if (item.scenario == 'ACTIVITY') {
|
|
|
- // return <View key={index} style={{ marginBottom: index < events.length - 1 ? rpxToPx(48) : 0, display: 'flex', flexDirection: 'column' }}>
|
|
|
-
|
|
|
- // <Text style={{ color: '#5C7099' }}>{dayjs(item.time.timestamp).format('HH:mm')}
|
|
|
- // {
|
|
|
- // item.title && <Text> {item.title}</Text>
|
|
|
- // }
|
|
|
- // </Text>
|
|
|
- // </View>
|
|
|
- // }
|
|
|
-
|
|
|
- // return <View key={index} style={{ marginBottom: index < events.length - 1 ? rpxToPx(48) : 0, display: 'flex', flexDirection: 'column' }}>
|
|
|
- // <Text >
|
|
|
- // {
|
|
|
- // item.time && <Text style={{ color: '#5C7099' }}>{dayjs(item.time.timestamp).format('HH:mm')} </Text>
|
|
|
- // }
|
|
|
- // {
|
|
|
- // item.title && <Text> {item.title} </Text>
|
|
|
- // }
|
|
|
- // {
|
|
|
- // item.moments && item.moment.description && <Text> {item.moment.description} </Text>
|
|
|
- // }
|
|
|
-
|
|
|
- // </Text>
|
|
|
- // </View>
|
|
|
})
|
|
|
}
|
|
|
</View>
|
|
|
|
|
|
|
|
|
- <View className="img_container" style={{ marginTop: -rpxToPx(24),marginBottom:rpxToPx(17) }}>
|
|
|
- <CoverList
|
|
|
- imgs={imgs}
|
|
|
- count={imgs.length}
|
|
|
- />
|
|
|
- {/* {
|
|
|
- imgs.map((item, index) => {
|
|
|
- return <Image key={index} src={item} className="journal_img" mode="aspectFill" onClick={() => {
|
|
|
- preview(item)
|
|
|
- }} />
|
|
|
- })
|
|
|
- } */}
|
|
|
+ <View className="img_container" style={{ marginTop: -rpxToPx(24), marginBottom: rpxToPx(17) }}>
|
|
|
+ {
|
|
|
+ imgs.length == 1 ? <SingleImage url={imgs[0]} /> : <CoverList
|
|
|
+ imgs={imgs}
|
|
|
+ count={imgs.length}
|
|
|
+ />
|
|
|
+ }
|
|
|
</View>
|
|
|
|
|
|
{
|
|
|
@@ -290,7 +213,7 @@ export default function JournalDetail() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- <Text className="h24" style={{ color: MainColorType.g02,marginTop:rpxToPx(17),lineHeight:rpxToPx(60)+'px' }}>发布于{dayjs(data.publish_timestamp).format('M月D日 HH:mm')}</Text>
|
|
|
+ <Text className="h24" style={{ color: MainColorType.g02, marginTop: rpxToPx(17), lineHeight: rpxToPx(60) + 'px' }}>发布于{dayjs(data.publish_timestamp).format('M月D日 HH:mm')}</Text>
|
|
|
</View>
|
|
|
|
|
|
|