leon 1 anno fa
parent
commit
a672fc1cf5

+ 4 - 4
src/_health/components/cover_list.scss

@@ -8,8 +8,8 @@
 }
 
 .media_item {
-    width: 178px;
-    height: 178px;
-    margin-right: 7px;
-    margin-bottom: 7px;
+    width: 155px;
+    height: 155px;
+    margin-right: 4px;
+    margin-bottom: 4px;
 }

+ 39 - 30
src/_health/pages/add_moment.tsx

@@ -96,13 +96,15 @@ export default function AddMoment() {
             var timeObj = moment.time
             setTime(dayjs(timeObj.timestamp).format('HH:mm'))
             setSelDate(dayjs(timeObj.timestamp).format('YYYY-MM-DD'))
+            
             if (moment.media.length > 0) {
+                setPics(moment.media)
                 // setImgUrl(moment.media[0].url)
-                var urls: any = []
-                moment.media.map((item) => {
-                    urls.push(item.url)
-                })
-                setPics(urls)
+                // var urls: any = []
+                // moment.media.map((item) => {
+                //     urls.push(item.url)
+                // })
+                // setPics(urls)
             }
         }
         else {
@@ -132,10 +134,10 @@ export default function AddMoment() {
     })
 
     const getImageInfo = (src) => {
-        const { tempFilePath } = src
+        const { tempFilePath, path } = src
         return new Promise((resolve) => {
             Taro.getImageInfo({
-                src: tempFilePath,
+                src: tempFilePath ? tempFilePath : path,
                 success: (result) => resolve({
                     height: result.height,
                     width: result.width,
@@ -164,7 +166,6 @@ export default function AddMoment() {
             sourceType: source,
             success: async function (res) {
                 const results = await Promise.all(res.tempFiles.map(getImageInfo));
-                debugger
 
                 // Taro.downloadFile({
                 //     url: 'https://fast-prod.oss-cn-beijing.aliyuncs.com/users/832f82c2bf616063fcf5619063a060c9/food-journal/2024/64efc6fe-5fca-49a3-9828-497e87ad9582_20241216120746_684.jpg',
@@ -184,7 +185,7 @@ export default function AddMoment() {
                 // })
 
 
-                chooseSuccess(res, true)
+                chooseSuccess(results, true)
                 checkAuthorized()
             },
             fail: function (res) {
@@ -221,9 +222,12 @@ export default function AddMoment() {
             var picList: any = []
             pics.map((item) => {
                 picList.push({
-                    url: item,
-                    type: item.indexOf('mp4') != -1 ? 'video' : 'image',
-                    source: 'album'
+                    url: item.url,
+                    type: item.url.indexOf('mp4') != -1 ? 'video' : 'image',
+                    source: 'album',
+                    width: item.width,
+                    height: item.height,
+                    format: item.format
                 })
             })
             params.media = picList
@@ -317,9 +321,12 @@ export default function AddMoment() {
             var picList: any = []
             pics.map((item) => {
                 picList.push({
-                    url: item,
-                    type: item.indexOf('mp4') != -1 ? 'video' : 'image',
-                    source: 'album'
+                    url: item.url,
+                    type: item.url.indexOf('mp4') != -1 ? 'video' : 'image',
+                    source: 'album',
+                    width: item.width,
+                    height: item.height,
+                    format: item.format
                 })
             })
             params.media = picList
@@ -365,18 +372,17 @@ export default function AddMoment() {
         })
     }
 
-    async function chooseSuccess(res, isAlbum, isFilePath = false) {
+    async function chooseSuccess(res, isAlbum) {
         console.log('选择图片', res)
-        const filePaths = res.tempFiles.map(file =>
-            process.env.TARO_ENV === 'rn' || isFilePath ? file.path : file.tempFilePath
-        )
+        // const filePaths = res.map(file => file.path
+        //     // process.env.TARO_ENV === 'rn' || isFilePath ? file.path : file.tempFilePath
+        // )
         Taro.showLoading({
             title: t('health.uploading')
         })
 
         try {
-            const uploadedUrls = await Promise.all(filePaths.map(path => uploadFile2(path, isAlbum ? 'album' : 'camera')))
-            console.log(uploadedUrls)
+            const uploadedUrls = await Promise.all(res.map(path => uploadFile2(path, isAlbum ? 'album' : 'camera')))
             setPics([...pics, ...uploadedUrls])
             Taro.hideLoading()
         } catch (error) {
@@ -385,8 +391,9 @@ export default function AddMoment() {
         }
     }
 
-    function uploadFile2(path: string, source: string): Promise<string> {
+    function uploadFile2(obj: any, source: string): Promise<string> {
         return new Promise((resolve, reject) => {
+            var path = obj.path
             const dot = path.lastIndexOf('.')
             const fileExt = dot > 0 ? path.substring(dot) : ''
             Taro.request({
@@ -410,8 +417,10 @@ export default function AddMoment() {
                         name: 'file',
                         formData: rsp.data.fields,
                         success: () => {
-
-                            resolve(rsp.data.view_url)
+                            var temp = JSON.parse(JSON.stringify(obj))
+                            temp.url = rsp.data.view_url
+                            // resolve(rsp.data.view_url)
+                            resolve(temp)
                         },
                         fail: (error) => {
 
@@ -495,8 +504,9 @@ export default function AddMoment() {
                         Taro.chooseMessageFile({
                             count: 9 - pics.length,
                             type: 'image',
-                            success: function (res) {
-                                chooseSuccess(res, true, true)
+                            success: async function (res) {
+                                const results = await Promise.all(res.tempFiles.map(getImageInfo));
+                                chooseSuccess(results, true)
                             },
                             fail(res) {
                             },
@@ -513,7 +523,6 @@ export default function AddMoment() {
         })
     }
 
-
     return <View>
         <View style={{
             display: 'flex',
@@ -596,12 +605,12 @@ export default function AddMoment() {
                 {
                     pics.map((item, index) => {
                         return <View className="cover" key={index}>
-                            <Image src={item + scale} mode="aspectFill" className="cover" style={{
+                            <Image src={item.url + scale} mode="aspectFill" className="cover" style={{
                                 margin: 0
                             }} key={index} onClick={() => {
                                 Taro.previewImage({
-                                    current: item,
-                                    urls: pics
+                                    current: item.url + scale,
+                                    urls: pics.map(file => file.url)
                                 })
                             }} />
                             <View className="cover_del" onClick={() => {

+ 12 - 0
src/_moment/components/recent_item.scss

@@ -0,0 +1,12 @@
+.recent_item1 {
+    display: flex;
+    flex-direction: row;
+    width: 750px;
+    padding: 40px;
+    padding-bottom: 0;
+    padding-top: 60px;
+    box-sizing: border-box;
+    position: relative;
+    background-color: #fff;
+    flex-shrink: 0;
+}

+ 20 - 7
src/_moment/components/recent_item.tsx

@@ -9,6 +9,7 @@ import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import { rpxToPx } from "@/utils/tools";
 import { View, Text, Image, ScrollView } from "@tarojs/components";
 import dayjs from "dayjs";
+import './recent_item.scss'
 
 export default function RecentItem(props: { data: any, index: number }) {
     const { time, moment, link } = props.data
@@ -34,22 +35,34 @@ export default function RecentItem(props: { data: any, index: number }) {
     }
 
     function goDetail() {
+        if (link.scenario == 'MOVE') {
+            jumpPage('/_health/pages/move_detail?id=' + link.move.id)
+            return;
+        }
         jumpPage(`/_health/pages/timeline_detail?window_id=${link.window_id}`)
     }
 
+    const hasImg = moment && moment.media.length > 0
+    var hasText = moment && (moment.title || moment.description)
+    if (hasText == undefined){
+        hasText = false
+    }
+
+    const spaceY = rpxToPx(7)
+
     return <View>
         {
             historyMonth(props.index)
         }
-        <View className="history_item2" style={{ display: 'flex', flexDirection: 'row' }} onClick={goDetail}>
+        <View className="recent_item1" style={{ paddingTop: time.is_start_day ? rpxToPx(60) : spaceY }} onClick={goDetail}>
             <TimelineDate timestamp={time.timestamp} pre_timestamp={0} isJournal={false} hideDate={!time.is_start_day} />
             <View className="history_content" style={{ paddingTop: rpxToPx(0) }}>
-                <View style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(12), flex: 1 }}>
+                <View style={{ display: 'flex', flexDirection: 'row', marginBottom: rpxToPx(0), flex: 1 }}>
                     {
-                        moment.media.length > 0 && medias()
+                        hasImg && medias()
                     }
                     {
-                        (moment.title || moment.description) && <View style={{
+                        hasText && <View style={{
                             display: 'flex',
                             flex: 1,
                             flexShrink: 0,
@@ -57,7 +70,7 @@ export default function RecentItem(props: { data: any, index: number }) {
                             backgroundColor: moment.media.length > 0 ? 'transparent' : '#fafafa',
                             paddingLeft: moment.media.length > 0 ? 0 : rpxToPx(20),
                             paddingRight: rpxToPx(20),
-                            paddingTop: rpxToPx(12),
+                            paddingTop: hasImg ? rpxToPx(12) : rpxToPx(12),
                             paddingBottom: rpxToPx(12)
                         }}>
                             <TimeTitleDesc
@@ -70,7 +83,7 @@ export default function RecentItem(props: { data: any, index: number }) {
 
                 </View>
                 {
-                    link && link.ring && <View style={{ marginTop: rpxToPx(24) }}>
+                    link && link.ring && <View style={{ marginTop: (hasImg || hasText)?spaceY:0 }}>
                         <TargetProgress
                             color={getThemeColor(link.window)}
                             showRing={true}
@@ -82,7 +95,7 @@ export default function RecentItem(props: { data: any, index: number }) {
                     </View>
                 }
                 {
-                    link && link.move && <View style={{ marginTop: rpxToPx(24) }}>
+                    link && link.move && <View style={{ marginTop: (hasImg || hasText)?spaceY:0 }}>
                         <TargetProgress
                             color={getThemeColor(link.window)}
                             showRing={false}

+ 2 - 0
src/_moment/pages/home.scss

@@ -3,6 +3,7 @@ page{
 }
 .home_top{
     position: relative;
+    z-index: 1;
 }
 
 .cover{
@@ -26,4 +27,5 @@ page{
     color: #000;
     right: 186px;
     bottom: 20px;
+    font-weight: bold;
 }

+ 8 - 10
src/_moment/pages/home.tsx

@@ -19,8 +19,9 @@ if (process.env.TARO_ENV == 'rn') {
     useNavigation = require("@react-navigation/native").useNavigation
 }
 
-let myScrollTop = 0
+
 export default function UserHome() {
+    let myScrollTop = 0
     const user = useSelector((state: any) => state.user);
     const [profile, setProfile] = useState<any>(null)
     const [loaded, setLoaded] = useState(false)
@@ -75,7 +76,7 @@ export default function UserHome() {
 
     useEffect(() => {
         if (moments.length == 0) return
-        loadMore()
+        // loadMore()
     }, [endSignal])
 
     function getProfile() {
@@ -89,7 +90,6 @@ export default function UserHome() {
         if (loading) return;
         if (noMore) return;
         setLoading(true)
-        console.log('more page:',page)
         var index = page;
         index++;
         setPage(index)
@@ -106,9 +106,7 @@ export default function UserHome() {
         if (index != 1 && list.length>0) {
             params.last_timestamp = list[list.length - 1].time.timestamp
         }
-        console.log('load data page',index)
         getUserMoments(params).then(res => {
-            console.log('result page',index)
             if (index == 1) {
                 setList((res as any).data)
             }
@@ -153,7 +151,6 @@ export default function UserHome() {
             query.exec((res) => {
                 var layouts: any = []
                 var heights: any = []
-                // console.log(res)
                 res.forEach((rect, index) => {
 
                     if (rect) {
@@ -163,7 +160,6 @@ export default function UserHome() {
                 });
                 setItemLayouts([...itemLayouts, ...layouts])
                 setItemHeights([...itemHeights, ...heights])
-                console.log('结束计算位置', new Date().getTime())
             })
 
         }
@@ -172,6 +168,7 @@ export default function UserHome() {
     function onScroll(e) {
         // var top = e.detail.scrollTop
         // myScrollTop = top
+        console.log('deltaY',e.detail.deltaY)
         var top = e.detail.scrollTop - e.detail.deltaY
         myScrollTop = e.detail.scrollTop
         setPageTop(top)
@@ -205,12 +202,13 @@ export default function UserHome() {
 
     if (!loaded) return <View />
 
+    console.log(pageTop)
     return <ScrollView style='height:100vh'
         enableBackToTop
         scrollY={true}
         // refresherEnabled={props.onRefresherRefresh}
         // upperThreshold={70}
-        // lowerThreshold={140}
+        lowerThreshold={140}
         // refresherBackground={MainColorType.g05}
         // onRefresherRefresh={props.onRefresherRefresh}
         // refresherTriggered={props.isPulling}
@@ -225,7 +223,7 @@ export default function UserHome() {
             }
 
         }}
-    // onScrollToLower={props.loadMore}
+    onScrollToLower={loadMore}
     ><View>
             <View className="home_top">
                 <View className="cover" />
@@ -268,7 +266,7 @@ export default function UserHome() {
                     }
                 </View>
             }
-            <View style={{height:rpxToPx(60)}}/>
+            {/* <View style={{height:rpxToPx(60)}}/> */}
             {
                 list.map((item, index) => {
                     if (itemLayouts.length >= index + 1 && pageTop > 0 && index > 5) {

+ 1 - 0
src/_moment/pages/message.scss

@@ -6,6 +6,7 @@
   align-items: center;
   box-sizing: border-box;
   padding: 0 40px;
+  position: relative;
 }
 
 .message_item_avatar{

+ 1 - 0
src/_moment/pages/message.tsx

@@ -111,6 +111,7 @@ export default function Message() {
           item.relation == 'FRIEND' ? <Text className="h30 g02">Friend</Text> :
             item.relation == 'FOLLOWING' ? <Text className="h30 g02">Following</Text> : null
       }
+      <View className='border_footer_line' style={{left:rpxToPx(150)}}/>
     </View>
   }
 

+ 1 - 0
src/_moment/pages/relation.scss

@@ -7,6 +7,7 @@
     padding-right: 40px;
     box-sizing: border-box;
     width: 750px;
+    position: relative;
 }
 
 .relation_avatar{

+ 6 - 2
src/_moment/pages/relation.tsx

@@ -249,6 +249,7 @@ export default function Relation() {
                 />
             }
             <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
+            <View className="border_footer_line" style={{left:rpxToPx(150)}}/>
         </View>
     }
 
@@ -256,8 +257,8 @@ export default function Relation() {
 
     }
 
-    if (loaded && list.length == 0)
-        return <NoRecord />
+    // if (loaded && list.length == 0)
+    //     return <NoRecord />
 
     return <ScrollView style='height:100vh'
         enableBackToTop
@@ -282,6 +283,9 @@ export default function Relation() {
             {
                 userList()
             }
+            {
+                loaded && list.length == 0 && <NoRecord />
+            }
 
             {/* {
             index == 0 && friendsList()

+ 14 - 5
src/app.tsx

@@ -5,7 +5,7 @@ import { Provider, useDispatch } from 'react-redux'
 import store from './store/store'
 import { View } from '@tarojs/components'
 import GlobalModal from './components/layout/GlobalModal'
-import Taro from '@tarojs/taro'
+import Taro, { useLaunch } from '@tarojs/taro'
 import { getInfoSuccess } from './store/user'
 import { uploadLocalPushInfo } from './features/trackTimeDuration/actions/TrackTimeActions'
 import { kIsAndroid } from './utils/tools'
@@ -35,11 +35,20 @@ if (process.env.TARO_ENV == 'rn') {
 
 const App: React.FC<PropsWithChildren> = ({ children }) => {
 
-  
+
   global.hideRingIcon = false
 
   Taro.setStorage({ key: 'showedDisqualifiedAlert', data: false })
 
+  Taro.onAppShow((res) => {
+    if (res.shareTicket) {
+      global.shareTicket = res.shareTicket
+    }
+    else {
+      global.shareTicket = null
+    }
+  })
+
 
   // if (process.env.TARO_ENV == 'rn') {
   //   global.language = 'en'
@@ -82,7 +91,7 @@ const App: React.FC<PropsWithChildren> = ({ children }) => {
       // Do something with return value
 
       if (value == 'wechat') {
-        const isZh = Taro.getAppBaseInfo?Taro.getAppBaseInfo().language == 'zh_CN':'zh_CN'
+        const isZh = Taro.getAppBaseInfo ? Taro.getAppBaseInfo().language == 'zh_CN' : 'zh_CN'
         global.language = isZh ? 'zh' : 'en'
       }
       else {
@@ -94,7 +103,7 @@ const App: React.FC<PropsWithChildren> = ({ children }) => {
 
     }
     else {
-      const isZh = Taro.getAppBaseInfo?Taro.getAppBaseInfo().language == 'zh_CN':'zh_CN'
+      const isZh = Taro.getAppBaseInfo ? Taro.getAppBaseInfo().language == 'zh_CN' : 'zh_CN'
       global.language = isZh ? 'zh' : 'en'
     }
     loadWXCache()
@@ -229,7 +238,7 @@ const App: React.FC<PropsWithChildren> = ({ children }) => {
 
     </ActionSheetProvider>
   }
-  console.log('当前微信版本',WX_VERSION)
+  console.log('当前微信版本', WX_VERSION)
   return <Provider store={store}>
     {children}
   </Provider>

BIN
src/assets/_health/user.png


+ 0 - 1
src/pages/clock/Clock.tsx

@@ -83,7 +83,6 @@ export default function Clock() {
         globalSetting({
             keys: 'mp_status'
         }).then(res => {
-            debugger
             if ((res as any).data && (res as any).data.length > 0 && (res as any).data[0].value.status == 'PENDING') {
                 global.allowShare = false
             }

+ 4 - 0
src/pages/friend/friend.tsx

@@ -22,7 +22,11 @@ export default function Friend() {
     const user = useSelector((state: any) => state.user);
     const [loaded, setLoaded] = useState(false)
 
+    const launchObj = Taro.getLaunchOptionsSync()
+
+
     useEffect(() => {
+        console.log('launchObj',launchObj)
         if (process.env.TARO_ENV == 'weapp') {
             loadWXCache()
         }

+ 38 - 18
src/pages/friend/friend_main.tsx

@@ -19,6 +19,9 @@ import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import './friend.scss'
 import ListFooter from "@/_health/components/list_footer";
 import { MainColorType } from "@/context/themes/color";
+import dayjs from "dayjs";
+
+
 
 let useRoute;
 let useNavigation;
@@ -33,7 +36,7 @@ let myScrollTop = 0
 
 export default function FriendMain() {
     const user = useSelector((state: any) => state.user);
-    const launchObj = Taro.getLaunchOptionsSync()
+
 
     const observerObjBottom = Taro.createIntersectionObserver().relativeToViewport({ bottom: 100 })
     const [loading, setLoading] = useState(false)
@@ -69,12 +72,18 @@ export default function FriendMain() {
     const [moments, setMoments] = useState<any>([])
     const [page, setPage] = useState(1)
     const [endSignal, setEndSignal] = useState(0)
+
+    const [closeGuide, setCloseGuide] = useState(false)
     const query = Taro.createSelectorQuery()
 
     const dispatch = useDispatch()
     const { t } = useTranslation()
 
     useEffect(() => {
+        dayjs.locale(global.language == 'en' ? 'en' : 'zh-cn');
+        require('moment/locale/en-gb')
+        require('moment/locale/zh-cn')
+
         timer = setInterval(() => {
             setCount(count => count + 1)
         }, 1000)
@@ -88,6 +97,8 @@ export default function FriendMain() {
         }
 
 
+
+
     }, [])
 
     function listenFollowUser(e) {
@@ -104,10 +115,14 @@ export default function FriendMain() {
 
     useEffect(() => {
         myFriends()
+        // const launchObj = Taro.getLaunchOptionsSync()
+        // console.log("heeee", router.params, launchObj)
         if (router.params.type == 'share') {
-            if (launchObj.shareTicket) {
+            // console.log('share begin')
+            // console.log(launchObj)
+            if (global.shareTicket) {
                 Taro.getShareInfo({
-                    shareTicket: launchObj.shareTicket,
+                    shareTicket: global.shareTicket,
                     success(result) {
                         console.log('share info', result)
                         updateRelation(result)
@@ -120,6 +135,7 @@ export default function FriendMain() {
         }
     }, [user.isLogin])
 
+
     useEffect(() => {
         if (moments.length == 0) return
 
@@ -148,7 +164,6 @@ export default function FriendMain() {
                 query.select(`#history2-${index}`).boundingClientRect()
             });
             query.exec((res) => {
-                debugger
                 var layouts: any = []
                 var heights: any = []
                 res.forEach((rect, index) => {
@@ -205,6 +220,8 @@ export default function FriendMain() {
 
             return
         }
+        setItemHeights([])
+        setItemLayouts([])
 
 
         getDashBoard()
@@ -212,7 +229,7 @@ export default function FriendMain() {
         getMoments(1)
     }
 
-    function onRefresh(){
+    function onRefresh() {
         setIsPulling(true)
         getMoments(1)
     }
@@ -311,11 +328,11 @@ export default function FriendMain() {
     }
 
     function friendGuide() {
-        return <View>
+        return <View style={{ position: 'fixed', left: 0, top: 0, width: rpxToPx(750), height: '100vh', zIndex: 100 }}>
             <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
             <View onClick={() => {
-                jumpPage('/_moment/pages/message')
-            }}>My Message</View>
+                setCloseGuide(true)
+            }}>关闭</View>
             <FriendGuide />
             {
                 process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
@@ -323,8 +340,11 @@ export default function FriendMain() {
     }
 
     function empty() {
-        return <View>
+        return <View style={{ position: 'fixed', left: 0, top: 0, width: rpxToPx(750), height: '100vh', zIndex: 100 }}>
             <View style={{ height: navigationBarHeight, width: rpxToPx(750), backgroundColor: '#fff' }} />
+            <View onClick={() => {
+                setCloseGuide(true)
+            }}>关闭</View>
             <EmptyContent friends={dashBoard.friends} />
             {
                 process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
@@ -345,13 +365,13 @@ export default function FriendMain() {
                 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 style={{fontWeight:'bold',}}>{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>
             <ScrollView style={{
-                marginTop:navigationBarHeight,
-                height:'90vh'
+                marginTop: navigationBarHeight,
+                height: '90vh'
             }}
                 enableBackToTop
                 scrollY={true}
@@ -414,6 +434,12 @@ export default function FriendMain() {
             {
                 process.env.TARO_ENV == 'weapp' && <TabBar index={4} />
             }
+            {
+                homeType == 'NO_FRIEND' && !closeGuide && friendGuide()
+            }
+            {
+                homeType == 'NO_MOMENT' && !closeGuide && empty()
+            }
         </View>
 
     }
@@ -429,13 +455,7 @@ export default function FriendMain() {
         if (!user.isLogin) {
             return friendGuide()
         }
-        switch (homeType) {
-            case 'NO_FRIEND':
-                return friendGuide()
-            case 'NO_MOMENT':
-                return empty()
 
-        }
 
         return listDetail()
         return <View >

+ 2 - 0
src/pages/friend/moment_item.scss

@@ -2,8 +2,10 @@
     display: flex;
     flex-direction: row;
     padding-bottom: 60px;
+    padding-top: 60px;
     padding-left: 40px;
     padding-right: 40px;
+    position: relative;
 }
 
 .moment_avatar {

+ 40 - 20
src/pages/friend/moment_item.tsx

@@ -13,48 +13,63 @@ import { getThemeColor } from "@/features/health/hooks/health_hooks";
 import CoverList from "@/_health/components/cover_list";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import { IconActive } from "@/components/basic/Icons";
+import Taro from "@tarojs/taro";
 
 dayjs.extend(relativeTime);
 dayjs.extend(isToday);
 dayjs.extend(isTomorrow);
 dayjs.extend(isYesterday);
+dayjs.extend(relativeTime);
 
 
 export default function MomentItem(props: { data: any }) {
+    const scale = '?x-oss-process=image/format,webp/resize,w_400'
     const { link, moment, user } = props.data
 
-    const formatTime = (timestamp) => {
-        const now = dayjs();
-        const time = dayjs(timestamp);
-
-        if (time.isToday()) {
-            return time.format('HH:mm'); // 今天的时间
-        }
-
-        const diffInMinutes = now.diff(time, 'minute');
-
-        if (diffInMinutes < 60) {
-            return `${diffInMinutes} min ago`; // xx分钟之前
-        } else {
-            return time.format('YYYY-MM-DD'); // 显示完整日期
-        }
-    };
-
     const formatImages = (list) => {
         return list.map(obj => obj.url);
     }
 
     function goProfile(e) {
-        if (process.env.TARO_ENV=='weapp'){
+        if (process.env.TARO_ENV == 'weapp') {
             e.stopPropagation()
         }
         jumpPage(`/_moment/pages/home?uid=${user.id}`)
     }
 
     function goDetail() {
+        if (link.scenario == 'MOVE') {
+            jumpPage('/_health/pages/move_detail?id=' + link.move.id)
+            return;
+        }
+        debugger
         jumpPage(`/_health/pages/timeline_detail?disable_edit=1&window_id=${link.window_id}`)
     }
 
+    function singleImage() {
+        var width = 346
+        var height = 346
+        var imgObj = moment.media[0]
+
+        if (imgObj.width && imgObj.height) {
+            if (imgObj.width >= imgObj.height) {
+                height = 346 * imgObj.height / imgObj.width
+            }
+            else {
+                width = 346 * imgObj.width / imgObj.height
+            }
+        }
+
+        return <Image onClick={(e) => {
+            if (process.env.TARO_ENV == 'weapp'){
+                e.stopPropagation()
+            }
+            Taro.previewImage({
+                urls: [imgObj.url]
+            })
+        }} mode="aspectFill" style={{ width: rpxToPx(width), height: rpxToPx(height) }} src={imgObj.url + scale} />
+    }
+
     return <View className="moment_item">
         <Image className="moment_avatar" src={user.avatar} mode="aspectFill" onClick={goProfile} />
         <View className="moment_detail" onClick={goDetail}>
@@ -64,8 +79,12 @@ export default function MomentItem(props: { data: any }) {
             }
             <View style={{ height: rpxToPx(12) }} />
             {
-                moment.media.length > 0 && <CoverList imgs={formatImages(moment.media)} count={moment.media.length} />
+                moment.media.length > 1 && <CoverList imgs={formatImages(moment.media)} count={moment.media.length} />
+            }
+            {
+                moment.media.length == 1 && singleImage()
             }
+
             {
                 link && link.ring && <View style={{ marginTop: rpxToPx(24) }}>
                     <TargetProgress
@@ -91,11 +110,12 @@ export default function MomentItem(props: { data: any }) {
                 </View>
             }
             <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', marginTop: rpxToPx(24) }}>
-                <View className="h26 g02">{formatTime(moment.timestamp)}</View>
+                <View className="h26 g02">{dayjs(moment.timestamp).fromNow()}</View>
                 <View style={{ position: 'relative' }}>
                     <Button className="item_share" openType="share" onClick={() => { global.shareData = '9527'; console.log('sgareeeeeee') }}></Button>
                 </View>
             </View>
         </View>
+        <View className="border_footer_line"/>
     </View>
 }