|
|
@@ -0,0 +1,253 @@
|
|
|
+import { View, Image, Text, Input, Textarea } from "@tarojs/components";
|
|
|
+import { useSelector } from "react-redux";
|
|
|
+import './timeline_detail.scss'
|
|
|
+import { useEffect, useState } from "react";
|
|
|
+import Taro, { useRouter } from "@tarojs/taro";
|
|
|
+import dayjs from "dayjs";
|
|
|
+import { getThemeColor } from "@/features/health/hooks/health_hooks";
|
|
|
+import { baseUrl } from "@/services/http/api";
|
|
|
+import { checkAuthorized } from "@/utils/check_authorized";
|
|
|
+import { createMoment, getEvents } from "@/services/health";
|
|
|
+
|
|
|
+let timestamp = 0;
|
|
|
+let useRoute;
|
|
|
+let useNavigation;
|
|
|
+let scenario = '';
|
|
|
+if (process.env.TARO_ENV == 'rn') {
|
|
|
+ useRoute = require("@react-navigation/native").useRoute
|
|
|
+ useNavigation = require("@react-navigation/native").useNavigation
|
|
|
+}
|
|
|
+export default function TimelineDetail() {
|
|
|
+ const health = useSelector((state: any) => state.health);
|
|
|
+ const user = useSelector((state: any) => state.user);
|
|
|
+ const [list, setList] = useState<any>([])
|
|
|
+ const [desc, setDesc] = useState('')
|
|
|
+ const [imgUrl, setImgUrl] = useState('')
|
|
|
+ const [btnDisable, setBtnDisable] = useState(true)
|
|
|
+ const [showPop, setShowPop] = useState(false)
|
|
|
+ const [publish, setPublish] = useState<any>(null)
|
|
|
+ const [bottom, setBottom] = useState(0)
|
|
|
+ let router
|
|
|
+ let navigation;
|
|
|
+ if (useNavigation) {
|
|
|
+ navigation = useNavigation()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ router = useRoute()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ router = useRouter()
|
|
|
+ }
|
|
|
+
|
|
|
+ const { schedule_id, event_id } = router.params
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ Taro.onKeyboardHeightChange(res => {
|
|
|
+ setBottom(res.height)
|
|
|
+ })
|
|
|
+
|
|
|
+ getDatas()
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (desc.length > 0 || imgUrl.length > 0) {
|
|
|
+ setBtnDisable(false)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setBtnDisable(true)
|
|
|
+ }
|
|
|
+ }, [desc, imgUrl])
|
|
|
+
|
|
|
+ function getDatas() {
|
|
|
+ getEvents(event_id).then(res => {
|
|
|
+ setList((res as any).moments)
|
|
|
+ setPublish((res as any).publish)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function addImage(isCamera: boolean) {
|
|
|
+ Taro.chooseMedia({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['compressed'],
|
|
|
+ mediaType: ['image'],
|
|
|
+ sourceType: [isCamera ? 'camera' : 'album'],
|
|
|
+ success: function (res) {
|
|
|
+ chooseSuccess(res, true)
|
|
|
+ // checkAuthorized()
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async function chooseSuccess(res, isAlbum) {
|
|
|
+ var params = {
|
|
|
+ event: 'add_a_picture',
|
|
|
+ value: isAlbum ? 'choose_from_album_confirm' : 'use_camera_confirm',
|
|
|
+ }
|
|
|
+
|
|
|
+ // saveFoodCache('create', params)
|
|
|
+
|
|
|
+ var savedFilePath = process.env.TARO_ENV == 'rn' ? res.tempFiles[0].path : res.tempFiles[0].tempFilePath
|
|
|
+
|
|
|
+ // var savedFilePath = res.savedFilePath
|
|
|
+ await Taro.setStorage({ key: 'pic', data: savedFilePath })
|
|
|
+ setImgUrl(savedFilePath as any)
|
|
|
+
|
|
|
+ uploadFile(savedFilePath, isAlbum ? 'album' : 'camera')
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function uploadFile(path, source) {
|
|
|
+ Taro.showLoading({
|
|
|
+ title: '加载中'
|
|
|
+ })
|
|
|
+ var dot = path.lastIndexOf('.')
|
|
|
+ var fileExt = dot > 0 ? path.substring(dot) : ''
|
|
|
+ Taro.request({
|
|
|
+ method: 'GET',
|
|
|
+ url: `${baseUrl}/api/thirdparty/aliyun/oss-form-upload`,
|
|
|
+ header: {
|
|
|
+ 'Authorization': 'bearer ' + global.token
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+ type: 'FOOD_JOURNAL',
|
|
|
+ file_ext: fileExt
|
|
|
+ },
|
|
|
+ success: (rsp) => {
|
|
|
+ if (rsp.statusCode != 200) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: '操作失败,请检查网络',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Taro.uploadFile({
|
|
|
+ url: rsp.data.upload_url,
|
|
|
+ filePath: path,
|
|
|
+ name: 'file',
|
|
|
+ formData: rsp.data.fields,
|
|
|
+ success: rlt => {
|
|
|
+ setImgUrl(rsp.data.view_url)
|
|
|
+ Taro.hideLoading()
|
|
|
+ // createData(rsp.data.view_url, source)
|
|
|
+
|
|
|
+ // uploadAvatar(rsp.data.view_url)
|
|
|
+ // _this.changeAvatar(rsp.data.view_url);
|
|
|
+ },
|
|
|
+ fail: rlt => {
|
|
|
+ Taro.hideLoading()
|
|
|
+ Taro.showModal({
|
|
|
+ content: rlt.errMsg
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function tapPost() {
|
|
|
+ if (desc.length == 0 && imgUrl.length == 0) {
|
|
|
+ Taro.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '请输入描述或添加图片'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var params: any = {
|
|
|
+ schedule_id: schedule_id,
|
|
|
+ description: desc,
|
|
|
+ start: {
|
|
|
+ date: dayjs(timestamp).format('YYYYMMDD'),
|
|
|
+ timestamp: timestamp
|
|
|
+ },
|
|
|
+
|
|
|
+ // real_end_time: meal.target_end_time,
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (imgUrl.length > 0) {
|
|
|
+ params.media = [{
|
|
|
+ url: imgUrl,
|
|
|
+ type: imgUrl.indexOf('mp4') != -1 ? 'video' : 'image',
|
|
|
+ source: 'album'
|
|
|
+ }]
|
|
|
+ }
|
|
|
+
|
|
|
+ params.event_id = event_id
|
|
|
+ createMoment(params).then(res => {
|
|
|
+ getDatas()
|
|
|
+
|
|
|
+ global.refreshWindow()
|
|
|
+ global.refreshHistory()
|
|
|
+ setShowPop(false)
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return <View style={{ display: 'flex', flex: 1 }}>
|
|
|
+ <View className="detail_header">
|
|
|
+ <Image className="detail_header_header"
|
|
|
+ src={user.avatar}
|
|
|
+ mode="aspectFill"
|
|
|
+ />
|
|
|
+ <View className="detail_header_content">
|
|
|
+ <Text className="detail_nickname">{user.nickname}</Text>
|
|
|
+ {
|
|
|
+ list.map((item, index) => {
|
|
|
+ return <View key={index} style={{flexDirection:'column',display:'flex'}}>
|
|
|
+ <Text>{dayjs(item.time.timestamp).format('HH:mm')}</Text>
|
|
|
+ {
|
|
|
+ item.title && <Text>{item.title}</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ item.description && <Text>{item.description}</Text>
|
|
|
+ }
|
|
|
+ {
|
|
|
+ item.media && <Image src={item.media[0].url} style={{width:60,height:60}}/>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ {
|
|
|
+ publish && <Text>发布于{dayjs(publish.timestamp).format('MM-DD HH:mm')}</Text>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ <View className="add_note" onClick={() => {
|
|
|
+ timestamp = new Date().getTime()
|
|
|
+ setShowPop(true)
|
|
|
+ }}>写个笔记</View>
|
|
|
+ {
|
|
|
+ showPop && <View className="publish_bg">
|
|
|
+ <View style={{
|
|
|
+ position: 'absolute', left: 50,
|
|
|
+ top: 30,
|
|
|
+ color: '#fff'
|
|
|
+ }} onClick={() => setShowPop(false)}>关闭</View>
|
|
|
+ <Text className="time">{dayjs(timestamp).format('HH:mm')}</Text>
|
|
|
+ <Textarea placeholder="What's on your mind?" style={{ flex: 1, color: '#fff', caretColor: getThemeColor(health.mode) }} focus value={desc} onInput={(e) => {
|
|
|
+ setDesc(e.detail.value)
|
|
|
+ }} />
|
|
|
+ <View className="toolbar">
|
|
|
+ {
|
|
|
+ imgUrl.length > 0 && <Image src={imgUrl} mode="aspectFill" className="album" onClick={() => addImage(false)} />
|
|
|
+ }
|
|
|
+ {
|
|
|
+ imgUrl.length == 0 && <Image src={require('@assets/_health/album.png')} className="album" onClick={() => addImage(false)} />
|
|
|
+ }
|
|
|
+ {
|
|
|
+ imgUrl.length == 0 && <Image src={require('@assets/_health/camera.png')} className="album" onClick={() => addImage(true)} />
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ <View className="btn" style={{ backgroundColor: btnDisable ? '#b2b2b2' : getThemeColor(health.mode) }} onClick={tapPost}>发布</View>
|
|
|
+ </View>
|
|
|
+ <View style={{ height: bottom, flexShrink: 0 }} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+}
|