|
|
@@ -41,14 +41,15 @@ export default function Component(props: { addItem: Function }) {
|
|
|
success: function (res) {
|
|
|
console.log(res)
|
|
|
var tempFilePaths = res.tempFilePaths
|
|
|
- Taro.saveFile({
|
|
|
+ Taro.getFileSystemManager().saveFile({
|
|
|
tempFilePath: tempFilePaths[0],
|
|
|
- apFilePath: '',
|
|
|
success: function (res) {
|
|
|
var savedFilePath = res.savedFilePath
|
|
|
Taro.setStorageSync('pic', savedFilePath)
|
|
|
console.log(savedFilePath)
|
|
|
setImgUrl(savedFilePath as any)
|
|
|
+
|
|
|
+ uploadFile(savedFilePath)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -57,7 +58,7 @@ export default function Component(props: { addItem: Function }) {
|
|
|
|
|
|
|
|
|
function clearFile() {
|
|
|
- Taro.getSavedFileList({
|
|
|
+ Taro.getFileSystemManager().getSavedFileList({
|
|
|
success: function (res) {
|
|
|
if (res.fileList.length > 0) {
|
|
|
Taro.removeSavedFile({
|
|
|
@@ -94,9 +95,12 @@ export default function Component(props: { addItem: Function }) {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- function uploadFile(e) {
|
|
|
- var dot = imgUrl.lastIndexOf('.')
|
|
|
- var fileExt = dot > 0 ? imgUrl.substring(dot) : ''
|
|
|
+ function uploadFile(path) {
|
|
|
+ Taro.showLoading({
|
|
|
+ title:'加载中'
|
|
|
+ })
|
|
|
+ var dot = path.lastIndexOf('.')
|
|
|
+ var fileExt = dot > 0 ? path.substring(dot) : ''
|
|
|
// console.log(avatarUrl)
|
|
|
Taro.request({
|
|
|
method: 'GET',
|
|
|
@@ -112,16 +116,18 @@ export default function Component(props: { addItem: Function }) {
|
|
|
console.log(rsp)
|
|
|
Taro.uploadFile({
|
|
|
url: rsp.data.upload_url,
|
|
|
- filePath: imgUrl,
|
|
|
+ filePath: path,
|
|
|
name: 'file',
|
|
|
formData: rsp.data.fields,
|
|
|
success: rlt => {
|
|
|
console.log(rlt)
|
|
|
createData(rsp.data.view_url)
|
|
|
+
|
|
|
// uploadAvatar(rsp.data.view_url)
|
|
|
// _this.changeAvatar(rsp.data.view_url);
|
|
|
},
|
|
|
fail: rlt => {
|
|
|
+ Taro.hideLoading()
|
|
|
Taro.showModal({
|
|
|
content: rlt.errMsg
|
|
|
})
|
|
|
@@ -146,8 +152,9 @@ export default function Component(props: { addItem: Function }) {
|
|
|
clearFile()
|
|
|
setImgUrl('')
|
|
|
Taro.removeStorageSync('pic')
|
|
|
+ Taro.hideLoading()
|
|
|
}).catch(e => {
|
|
|
-
|
|
|
+ Taro.hideLoading()
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -155,14 +162,21 @@ export default function Component(props: { addItem: Function }) {
|
|
|
<View style={{ display: 'flex', width: rpxToPx(750), alignItems: 'center', justifyContent: 'center', flexDirection: 'column' }}>
|
|
|
<View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
<Slider />
|
|
|
- <View className='box11' onClick={()=>choose(true)}>{
|
|
|
+ {/* <View className='box11' onClick={()=>choose(true)}>{
|
|
|
imgUrl && <Image style={{ width: '100%', height: '100%' }} src={imgUrl} mode="aspectFill" />
|
|
|
}
|
|
|
+ </View> */}
|
|
|
+ <View className='camera_bg' onClick={()=>choose(false)}>
|
|
|
+ <Image src={require('@assets/images/camera2.png')} className='camera_icon'/>
|
|
|
+ <Text className='camera_text'>拍摄食物</Text>
|
|
|
+ <Text className='album_text'>从相册选择</Text>
|
|
|
+ <View className='album_bottom' onClick={(e)=>{choose(true);e.stopPropagation()}}/>
|
|
|
</View>
|
|
|
<Slider />
|
|
|
</View>
|
|
|
- <Text style={{ color: '#fff',marginBottom:20 }} onClick={()=>choose(false)}>拍照</Text>
|
|
|
- <Text style={{ color: '#fff' }} onClick={uploadFile}>上传</Text>
|
|
|
+ <View className='demo1'/>
|
|
|
+ {/* <Text style={{ color: '#fff',marginBottom:20 }} onClick={()=>choose(false)}>拍照</Text>
|
|
|
+ <Text style={{ color: '#fff' }} onClick={uploadFile}>上传</Text> */}
|
|
|
|
|
|
</View>
|
|
|
</View>
|