|
|
@@ -1,4 +1,4 @@
|
|
|
-import { Textarea, View, Image, Input } from "@tarojs/components";
|
|
|
+import { Textarea, View, Image, Input, ScrollView } from "@tarojs/components";
|
|
|
import './log_publish.scss'
|
|
|
import { rpxToPx } from "@/utils/tools";
|
|
|
import { useEffect, useState } from "react";
|
|
|
@@ -13,9 +13,10 @@ 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 { BASE_IMG_URL, baseUrl } from "@/services/http/api";
|
|
|
import LogTags from "./log_tags";
|
|
|
import PickerCard from "@/_record/components/picker_card";
|
|
|
+import showActionSheet from "@/components/basic/ActionSheet";
|
|
|
|
|
|
let useRoute;
|
|
|
let useNavigation;
|
|
|
@@ -51,19 +52,160 @@ export default function LogPublish(props: { onClose: any, scenario: string, tag?
|
|
|
const [step, setStep] = useState(props.addTag ? 1 : 2)
|
|
|
const [inputFocus, setInputFocus] = useState(false)
|
|
|
const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
+ const [addEnter, setAddEnter] = useState(props.addTag ?? false)
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (step == 1) {
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
setInputFocus(true)
|
|
|
}, 300)
|
|
|
}
|
|
|
+ else {
|
|
|
+ setAddEnter(false)
|
|
|
+ }
|
|
|
}, [step])
|
|
|
|
|
|
- function tapPic() {
|
|
|
+ function addImage(isCamera) {
|
|
|
+ var source: any = isCamera ? ['camera'] : ['album']
|
|
|
+ Taro.chooseImage({
|
|
|
+ count: 9 - pics.length,
|
|
|
+ sizeType: ['compressed'],
|
|
|
+ // mediaType: ['image'],
|
|
|
+ sourceType: source,
|
|
|
+ success: async function (res) {
|
|
|
+ const results = await Promise.all(res.tempFiles.map(getImageInfo));
|
|
|
+
|
|
|
+
|
|
|
+ chooseSuccess(results, true)
|
|
|
+ // checkAuthorized()
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async function chooseSuccess(res, isAlbum) {
|
|
|
+ // 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(res.map(path => uploadFile2(path, isAlbum ? 'album' : 'camera')))
|
|
|
+ setPics([...pics, ...uploadedUrls])
|
|
|
+ Taro.hideLoading()
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error uploading files:', error)
|
|
|
+ Taro.hideLoading()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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({
|
|
|
+ method: 'GET',
|
|
|
+ timeout: 30000,
|
|
|
+ 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) {
|
|
|
+ reject(new Error(t('health.networkError')))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Taro.uploadFile({
|
|
|
+ timeout: 30000,
|
|
|
+ url: rsp.data.upload_url,
|
|
|
+ filePath: path,
|
|
|
+ name: 'file',
|
|
|
+ formData: rsp.data.fields,
|
|
|
+ success: () => {
|
|
|
+ var temp = JSON.parse(JSON.stringify(obj))
|
|
|
+ temp.url = rsp.data.view_url
|
|
|
+ // resolve(rsp.data.view_url)
|
|
|
+ resolve(temp)
|
|
|
+ },
|
|
|
+ fail: (error) => {
|
|
|
+
|
|
|
+ reject(error)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: reject
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ const getImageInfo = (src) => {
|
|
|
+ const { tempFilePath, path } = src
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ Taro.getImageInfo({
|
|
|
+ src: tempFilePath ? tempFilePath : path,
|
|
|
+ success: (result) => resolve({
|
|
|
+ height: result.height,
|
|
|
+ width: result.width,
|
|
|
+ orientation: result.orientation,
|
|
|
+ path: result.path,
|
|
|
+ type: result.type
|
|
|
+ }),
|
|
|
+ fail: (error) => resolve({
|
|
|
+ height: 1024,
|
|
|
+ width: 1024,
|
|
|
+ orientation: 'up',
|
|
|
+ path: tempFilePath,
|
|
|
+ type: 'unknown'
|
|
|
+ }),
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ function tapPic() {
|
|
|
+ var list = process.env.TARO_ENV == 'weapp' ? [t('health.add_photos'), t('health.camera2'), t('health.import_chat')] :
|
|
|
+ [t('health.add_photos'), t('health.camera2')]
|
|
|
+ showActionSheet({
|
|
|
+ title: '',
|
|
|
+ // showActionSheetWithOptions: showActionSheetWithOptions,
|
|
|
+ itemList: list,
|
|
|
+ success: function (res) {
|
|
|
+ switch (res) {
|
|
|
+ case 0:
|
|
|
+ addImage(false)
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ addImage(true)
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ Taro.chooseMessageFile({
|
|
|
+ count: 9 - pics.length,
|
|
|
+ type: 'image',
|
|
|
+ success: async function (res) {
|
|
|
+ const results = await Promise.all(res.tempFiles.map(getImageInfo));
|
|
|
+ chooseSuccess(results, true)
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ // setImgUrl('')
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
function save() {
|
|
|
@@ -322,19 +464,21 @@ export default function LogPublish(props: { onClose: any, scenario: string, tag?
|
|
|
}
|
|
|
|
|
|
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>
|
|
|
+ return <ScrollView scrollY style={{height:screenHeight-navigationBarHeight}}>
|
|
|
+ <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>
|
|
|
+ </ScrollView>
|
|
|
}
|
|
|
|
|
|
function addTagContent() {
|
|
|
@@ -355,6 +499,10 @@ export default function LogPublish(props: { onClose: any, scenario: string, tag?
|
|
|
<View className="form_cancel">
|
|
|
<NewButton btnStyle={{ flex: 1 }} type={NewButtonType.img}
|
|
|
onClick={() => {
|
|
|
+ if (addEnter) {
|
|
|
+ props.onClose()
|
|
|
+ return
|
|
|
+ }
|
|
|
setStep(0)
|
|
|
}}
|
|
|
>
|
|
|
@@ -364,6 +512,7 @@ export default function LogPublish(props: { onClose: any, scenario: string, tag?
|
|
|
<View className="form_cancel">
|
|
|
<NewButton btnStyle={{ flex: 1 }} type={NewButtonType.img}
|
|
|
onClick={() => {
|
|
|
+
|
|
|
if (!title || title.length == 0) return
|
|
|
// setChooseTitle(title)
|
|
|
// setPostCount(1)
|
|
|
@@ -405,7 +554,10 @@ export default function LogPublish(props: { onClose: any, scenario: string, tag?
|
|
|
top: 22 - rpxToPx(32)
|
|
|
}}
|
|
|
onClick={() => {
|
|
|
-
|
|
|
+ if (addEnter) {
|
|
|
+ props.onClose()
|
|
|
+ return
|
|
|
+ }
|
|
|
// if (showResult) {
|
|
|
// process.env.TARO_ENV == 'weapp' ? Taro.navigateBack() : navigation.goBack()
|
|
|
// return
|