|
|
@@ -1,10 +1,21 @@
|
|
|
-import { View } from "@tarojs/components";
|
|
|
+import { Textarea, View, Image, Input } from "@tarojs/components";
|
|
|
import './log_publish.scss'
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
-import { useState } from "react";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
import { useSelector } from "react-redux";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
-import { IconClose } from "@/components/basic/Icons";
|
|
|
+import { IconArrow, IconClose } from "@/components/basic/Icons";
|
|
|
+import NewButton, { NewButtonType } from "@/_health/base/new_button";
|
|
|
+import showAlert from "@/components/basic/Alert";
|
|
|
+import { IconCamera, IconClock } from "@/_record/components/record_icon";
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
+import { MainColorType } from "@/context/themes/color";
|
|
|
+import dayjs from "dayjs";
|
|
|
+import { addEvents } from "@/services/health";
|
|
|
+import { TimeFormatter } from "@/utils/time_format";
|
|
|
+import { BASE_IMG_URL } from "@/services/http/api";
|
|
|
+import LogTags from "./log_tags";
|
|
|
+import PickerCard from "@/_record/components/picker_card";
|
|
|
|
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
|
@@ -15,7 +26,8 @@ if (process.env.TARO_ENV == 'rn') {
|
|
|
LinearGradient = require('react-native-linear-gradient').default
|
|
|
}
|
|
|
|
|
|
-export default function LogPublish(props: { onClose: any }) {
|
|
|
+export default function LogPublish(props: { onClose: any, scenario: string, tag?: any, tags: any, addTag: boolean }) {
|
|
|
+ const scale = '?x-oss-process=image/format,jpg/resize,w_400'
|
|
|
const systemInfo: any = Taro.getWindowInfo ? Taro.getWindowInfo() : Taro.getSystemInfoSync();
|
|
|
const navigationBarHeight = systemInfo.statusBarHeight + 44;
|
|
|
const screenHeight = systemInfo.screenHeight
|
|
|
@@ -23,6 +35,127 @@ export default function LogPublish(props: { onClose: any }) {
|
|
|
const [showChoose, setShowChoose] = useState(false)
|
|
|
const record = useSelector((state: any) => state.record);
|
|
|
|
|
|
+ const [pics, setPics] = useState<any>([])
|
|
|
+ const [desc, setDesc] = useState('')
|
|
|
+ const [focus, setFocus] = useState(false)
|
|
|
+
|
|
|
+ const [time, setTime] = useState(dayjs().format('HH:mm'))
|
|
|
+ const [selDate, setSelDate] = useState(dayjs().format('YYYY-MM-DD'))
|
|
|
+
|
|
|
+ const [enterTimestmap] = useState(new Date().getTime())
|
|
|
+
|
|
|
+ const [scenario, setScenarios] = useState(props.scenario)
|
|
|
+ const [posting, setPosting] = useState(false)
|
|
|
+
|
|
|
+ const [title, setTitle] = useState(props.tag ? props.tag.title : '')
|
|
|
+ const [step, setStep] = useState(props.addTag ? 1 : 2)
|
|
|
+ const [inputFocus, setInputFocus] = useState(false)
|
|
|
+ const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
+
|
|
|
+ const { t } = useTranslation()
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (step == 1) {
|
|
|
+ setTimeout(() => {
|
|
|
+ setInputFocus(true)
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
+ }, [step])
|
|
|
+
|
|
|
+ function tapPic() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function save() {
|
|
|
+ var date = TimeFormatter.stringToDate(selDate, time)
|
|
|
+ date.setMilliseconds(new Date(enterTimestmap).getMilliseconds())
|
|
|
+
|
|
|
+
|
|
|
+ var params: any = {
|
|
|
+ scenario: scenario, //ACTIVITY
|
|
|
+ type: 'POINT',
|
|
|
+ sub_type: scenario,
|
|
|
+ title: title,
|
|
|
+
|
|
|
+ time: {
|
|
|
+ start_timestamp: date.getTime()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (router.params.join_id) {
|
|
|
+ // params.join_key = router.params.join_id
|
|
|
+ // }
|
|
|
+
|
|
|
+ var moment: any = {
|
|
|
+ description: desc,
|
|
|
+ }
|
|
|
+ if (pics.length > 0) {
|
|
|
+ var picList: any = []
|
|
|
+ pics.map((item) => {
|
|
|
+ picList.push({
|
|
|
+ url: item.url,
|
|
|
+ type: item.url.indexOf('mp4') != -1 ? 'video' : 'image',
|
|
|
+ source: 'album',
|
|
|
+ width: item.width,
|
|
|
+ height: item.height,
|
|
|
+ format: item.format
|
|
|
+ })
|
|
|
+ })
|
|
|
+ moment.media = picList
|
|
|
+ }
|
|
|
+ params.moment = moment
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // if (event_id && event_id != 'undefined') {
|
|
|
+ // params.event_id = event_id
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (is_temp) {
|
|
|
+ // params.event = window == 'EAT' ? 'EAT_CUSTOM' : 'ACTIVE_CUSTOM'
|
|
|
+ // }
|
|
|
+ // params.op_page = window == 'EAT' ? 'HOME_EAT' : 'HOME_ACTIVE'
|
|
|
+
|
|
|
+
|
|
|
+ params.extra = {
|
|
|
+ set_time: global.set_time ? global.set_time : new Date().getTime(),
|
|
|
+ confirm_time: new Date().getTime()
|
|
|
+ }
|
|
|
+ if (posting) return
|
|
|
+ setPosting(true)
|
|
|
+ // Taro.showLoading({
|
|
|
+ // title: t('health.uploading')
|
|
|
+ // })
|
|
|
+ addEvents(params).then(res => {
|
|
|
+ // setShowResult(true)
|
|
|
+ // setResult(res)
|
|
|
+ setPosting(false)
|
|
|
+ // Taro.hideLoading()
|
|
|
+ Taro.reLaunch({
|
|
|
+ url: '/pages/moment/moment'
|
|
|
+ })
|
|
|
+ props.onClose()
|
|
|
+ }).catch(e => {
|
|
|
+ setPosting(false)
|
|
|
+ // Taro.hideLoading()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDate() {
|
|
|
+ var sel = dayjs(selDate)
|
|
|
+ var now = dayjs().format('YYYY-MM-DD')
|
|
|
+ const yesterday = dayjs().subtract(1, 'day');
|
|
|
+ if (sel.format('YYYY-MM-DD') == now) {
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+ if (yesterday.format('YYYY-MM-DD') == sel.format('YYYY-MM-DD')) {
|
|
|
+ return global.language == 'en' ? 'Yesterday ' : '昨天 '
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return global.language == 'en' ? sel.format('MMM D ') : sel.format('MMMD日 ')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function getBackground() {
|
|
|
var time = record.time
|
|
|
if (!time) return '#fff'
|
|
|
@@ -64,8 +197,192 @@ export default function LogPublish(props: { onClose: any }) {
|
|
|
end={{ x: 0, y: 1 }} pointerEvents="none" />
|
|
|
}
|
|
|
|
|
|
+ function publishCard() {
|
|
|
+ return <View className="cardShowAni" style={{ paddingTop: rpxToPx(26) }}>
|
|
|
+
|
|
|
+ <View className="content_card">
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row' }} >
|
|
|
+ <NewButton type={NewButtonType.custom}
|
|
|
+ onClick={() => {
|
|
|
+ // setStep(0)
|
|
|
+ // setFocus(false)
|
|
|
+ setStep(0)
|
|
|
+ }}>
|
|
|
+
|
|
|
+ <View className="sel_tag">
|
|
|
+ {/* <View className="h34 bold">{selPostCount}</View>
|
|
|
+ <View className="h34" style={{ marginLeft: rpxToPx(6) }}>次</View>
|
|
|
+ <View style={{
|
|
|
+ width: rpxToPx(2),
|
|
|
+ height: rpxToPx(32),
|
|
|
+ backgroundColor: '#000',
|
|
|
+ opacity: 0.2,
|
|
|
+ marginLeft: rpxToPx(12),
|
|
|
+ marginRight: rpxToPx(12)
|
|
|
+ }} /> */}
|
|
|
+ <View className="h34 bold">{title}</View>
|
|
|
+ <View style={{ width: rpxToPx(6) }} />
|
|
|
+ <IconArrow width={rpxToPx(34)} color='#000' />
|
|
|
+
|
|
|
+ </View>
|
|
|
+ </NewButton>
|
|
|
+ </View>
|
|
|
+ {/* <Input placeholder="hhhhhhh" style={{textAlign:'center'}}/> */}
|
|
|
+
|
|
|
+ <Textarea placeholder={t('health.add_text')} className="textarea2 h44"
|
|
|
+ placeholder-style="color:rgba(0,0,0,0.2)"
|
|
|
+ value={desc}
|
|
|
+ focus={focus}
|
|
|
+ onBlur={() => {
|
|
|
+ setFocus(false)
|
|
|
+ }}
|
|
|
+ onInput={e => {
|
|
|
+ setDesc(e.detail.value)
|
|
|
+ }} />
|
|
|
+ <View className="form2">
|
|
|
+
|
|
|
+
|
|
|
+ {
|
|
|
+ pics.map((item, index) => {
|
|
|
+ return <View className="cover1" key={index}>
|
|
|
+ <Image src={item.url + scale} mode="aspectFill" className="cover2" key={index} onClick={() => {
|
|
|
+ Taro.previewImage({
|
|
|
+ current: pics[index].url,
|
|
|
+ urls: pics.map(file => file.url)
|
|
|
+ })
|
|
|
+ }} />
|
|
|
+ <View className="cover_del" onClick={() => {
|
|
|
+ showAlert({
|
|
|
+ title: t('health.del_title'),
|
|
|
+ content: '',
|
|
|
+ cancelText: t('health.del_cancel'),
|
|
|
+ confirmText: t('health.del_confirm'),
|
|
|
+ showCancel: true,
|
|
|
+ confirm: () => {
|
|
|
+ var array = JSON.parse(JSON.stringify(pics))
|
|
|
+ array.splice(index, 1)
|
|
|
+ setPics(array)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }}>
|
|
|
+ <View className="cover_del_btn">
|
|
|
+ <IconClose width={10} height={10} color="#fff" />
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ })
|
|
|
+ }
|
|
|
+ {
|
|
|
+ pics.length < 9 && <NewButton
|
|
|
+ type={NewButtonType.custom}
|
|
|
+ onClick={tapPic}>
|
|
|
+ <View className="cover1" style={{}}><IconCamera color="#000" width={rpxToPx(48)} /></View>
|
|
|
+ </NewButton>
|
|
|
+ }
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ <View className="time_view" onClick={() => {
|
|
|
+ setShowTimePicker(true)
|
|
|
+ }}>
|
|
|
+
|
|
|
+ <IconClock width={rpxToPx(36)} color={MainColorType.black_25} />
|
|
|
+
|
|
|
+
|
|
|
+ <View className="h30" style={{ opacity: 0.25, marginLeft: rpxToPx(12) }}>{t('health.time')}</View>
|
|
|
+ <View style={{ flex: 1 }} />
|
|
|
+ <View className="h30" style={{ opacity: 0.25 }}>{getDate() + time}</View>
|
|
|
+ <IconArrow width={rpxToPx(34)} color={MainColorType.black_25} />
|
|
|
+ <View className="border_footer_line" style={{ left: rpxToPx(48) }} />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ {/* {
|
|
|
+ router.params.join_id && <FollowInfo user={long.follow} />
|
|
|
+ } */}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function publishBtn() {
|
|
|
+ return <View className="main_footer" style={{ backgroundColor: 'transparent' }}>
|
|
|
+ <NewButton
|
|
|
+ type={NewButtonType.fill}
|
|
|
+ color={MainColorType.orange}
|
|
|
+ width={rpxToPx(646)}
|
|
|
+ height={rpxToPx(108)}
|
|
|
+ title={t('health.share_to_moment')}
|
|
|
+ onClick={save}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function tagsContent() {
|
|
|
+ return <View style={{ display: 'flex', alignItems: 'center', flexDirection: 'column', marginTop: rpxToPx(26) }}>
|
|
|
+ <Image src={BASE_IMG_URL + 'tag.svg'} style={{ width: rpxToPx(96), height: rpxToPx(96), marginBottom: rpxToPx(24) }} />
|
|
|
+ <View className="h50 bold" style={{ textAlign: 'center', width: rpxToPx(600), }}>{t('health.add_a_tag')}</View>
|
|
|
+ <LogTags tags={props.tags} scenario={props.scenario} showPublish={(scenario, item, addTag) => {
|
|
|
+ // props.showPublish(scenario, item, tags)
|
|
|
+ if (addTag) {
|
|
|
+ setStep(1)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ setTitle(item.title)
|
|
|
+ setStep(2)
|
|
|
+ }} />
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
+ function addTagContent() {
|
|
|
+ return <View className="cardShowAni" style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', marginTop: rpxToPx(300) }}>
|
|
|
+ <View className="input_form">
|
|
|
+ <Input className="input_content h36" placeholder={t('health.custom_name')} value={title}
|
|
|
+ placeholderClass="input_content_placeholder"
|
|
|
+ focus={inputFocus}
|
|
|
+ autoFocus={inputFocus}
|
|
|
+ maxlength={30}
|
|
|
+ onBlur={() => {
|
|
|
+ setInputFocus(false)
|
|
|
+ }}
|
|
|
+ onInput={(e: any) => {
|
|
|
+ setTitle(e.target.value)
|
|
|
+ }} />
|
|
|
+ <View className="form_btns">
|
|
|
+ <View className="form_cancel">
|
|
|
+ <NewButton btnStyle={{ flex: 1 }} type={NewButtonType.img}
|
|
|
+ onClick={() => {
|
|
|
+ setStep(0)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <View className="h30 bold">{t('health.cancel')}</View>
|
|
|
+ </NewButton>
|
|
|
+ </View>
|
|
|
+ <View className="form_cancel">
|
|
|
+ <NewButton btnStyle={{ flex: 1 }} type={NewButtonType.img}
|
|
|
+ onClick={() => {
|
|
|
+ if (!title || title.length == 0) return
|
|
|
+ // setChooseTitle(title)
|
|
|
+ // setPostCount(1)
|
|
|
+ setStep(2)
|
|
|
+ // addTag()
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <View className={!title || title.length == 0 ? 'form_cancel form_confirm h30 bold' : 'form_cancel h30 bold'}
|
|
|
+
|
|
|
+ >{t('health.confirm')}</View>
|
|
|
+ </NewButton>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- return <View className="log_publish_bg" style={{ position: 'relative', overflow: showChoose ? 'hidden' : 'visible' }}>
|
|
|
+ return <View className="log_publish_bg" style={{ overflow: showChoose ? 'hidden' : 'visible' }}>
|
|
|
{
|
|
|
bgView()
|
|
|
}
|
|
|
@@ -88,28 +405,30 @@ export default function LogPublish(props: { onClose: any }) {
|
|
|
top: 22 - rpxToPx(32)
|
|
|
}}
|
|
|
onClick={() => {
|
|
|
- props.onClose()
|
|
|
+
|
|
|
// if (showResult) {
|
|
|
// process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
|
|
|
// return
|
|
|
// }
|
|
|
- // if (chooseTitle.length > 0 && step == 0) {
|
|
|
- // setStep(2)
|
|
|
- // return
|
|
|
- // }
|
|
|
- // if (step == 2 && (desc.length > 0 || pics.length > 0)) {
|
|
|
- // showAlert({
|
|
|
- // title: t('health.back_no_save'),
|
|
|
- // content: '',
|
|
|
- // showCancel: true,
|
|
|
- // cancelText: t('health.cancel'),
|
|
|
- // confirmText: t('health.exit'),
|
|
|
- // confirm: () => {
|
|
|
- // process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
|
|
|
- // }
|
|
|
- // })
|
|
|
- // return
|
|
|
- // }
|
|
|
+ if (title && title.length > 0 && step == 0) {
|
|
|
+ setStep(2)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (step == 2 && (desc.length > 0 || pics.length > 0)) {
|
|
|
+ showAlert({
|
|
|
+ title: t('health.back_no_save'),
|
|
|
+ content: '',
|
|
|
+ showCancel: true,
|
|
|
+ cancelText: t('health.cancel'),
|
|
|
+ confirmText: t('health.exit'),
|
|
|
+ confirm: () => {
|
|
|
+ props.onClose()
|
|
|
+ // process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ props.onClose()
|
|
|
// process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
|
|
|
}}>
|
|
|
<IconClose color={"#000"} width={rpxToPx(64)} height={rpxToPx(64)} />
|
|
|
@@ -117,5 +436,29 @@ export default function LogPublish(props: { onClose: any }) {
|
|
|
</View>
|
|
|
</View>
|
|
|
<View style={{ height: navigationBarHeight }} />
|
|
|
+ {
|
|
|
+ step == 2 && publishCard()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ step == 2 && publishBtn()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ step == 0 && tagsContent()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ step == 1 && addTagContent()
|
|
|
+ }
|
|
|
+ {
|
|
|
+ showTimePicker && <PickerCard onClose={() => { setShowTimePicker(false) }}
|
|
|
+ value={new Date(selDate + 'T' + time + ':00').getTime()}
|
|
|
+ title={global.language == 'en' ? 'Choose Time' : "选择时间"}
|
|
|
+ type="datetime"
|
|
|
+ onConfirm={(e) => {
|
|
|
+ setSelDate(dayjs(e).format('YYYY-MM-DD'))
|
|
|
+ setTime(dayjs(e).format('HH:mm'))
|
|
|
+ setShowTimePicker(false)
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ }
|
|
|
</View>
|
|
|
}
|