提交 90163681 authored 作者: 吴强's avatar 吴强

上传界面

上级 804c9bd7
...@@ -7258,6 +7258,11 @@ ...@@ -7258,6 +7258,11 @@
} }
} }
}, },
"react-native-background-upload": {
"version": "4.1.0",
"resolved": "http://registry.npm.taobao.org/react-native-background-upload/download/react-native-background-upload-4.1.0.tgz",
"integrity": "sha1-EAZmWc1miVxHrBGXiahtai1zALo="
},
"react-native-camera": { "react-native-camera": {
"version": "0.12.0", "version": "0.12.0",
"resolved": "http://registry.npm.taobao.org/react-native-camera/download/react-native-camera-0.12.0.tgz", "resolved": "http://registry.npm.taobao.org/react-native-camera/download/react-native-camera-0.12.0.tgz",
......
...@@ -14,6 +14,7 @@ import { encrypt } from '../utils/helper'; ...@@ -14,6 +14,7 @@ import { encrypt } from '../utils/helper';
import config from '../utils/config'; import config from '../utils/config';
import { futch } from '../utils/polyfill'; import { futch } from '../utils/polyfill';
import { userApi } from '../services/interfaces'; import { userApi } from '../services/interfaces';
import { uploadResource } from '../services/resource';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
...@@ -76,6 +77,7 @@ class CameraComponent extends React.Component { ...@@ -76,6 +77,7 @@ class CameraComponent extends React.Component {
this.takePicture = this.takePicture.bind(this); this.takePicture = this.takePicture.bind(this);
this.uploadImage = this.uploadImage.bind(this); this.uploadImage = this.uploadImage.bind(this);
this.clear = this.clear.bind(this); this.clear = this.clear.bind(this);
this.goToUpload = this.goToUpload.bind(this);
} }
typeIcon= () => { typeIcon= () => {
const { back, front } = Camera.constants.Type; const { back, front } = Camera.constants.Type;
...@@ -127,7 +129,7 @@ class CameraComponent extends React.Component { ...@@ -127,7 +129,7 @@ class CameraComponent extends React.Component {
this.camera.stopCapture(); this.camera.stopCapture();
this.setState({ isRecording: false }); this.setState({ isRecording: false });
} }
console.log('stopped '); console.log('stopped');
} }
} }
takePicture() { takePicture() {
...@@ -192,6 +194,16 @@ class CameraComponent extends React.Component { ...@@ -192,6 +194,16 @@ class CameraComponent extends React.Component {
clear() { clear() {
this.setState({ imageURI: '' }); this.setState({ imageURI: '' });
} }
uploadImage2 = () => {
console.info('输出上传');
console.info(this.state);
uploadResource(this.state.imageURI, (uploadId, arg) => console.info(arg), (uploadId, arg) => console.info(`陈宫${arg}`), (uploadId, arg) => console.info(arg))
.then(uploadId => console.log(`start task ${uploadId}`))
.catch(err => console.log(err));
}
goToUpload() {
this.props.navigation.navigate('DSRInfoTuPian', { imageURI: this.state.imageURI });
}
render() { render() {
if (this.state.imageURI === '') { if (this.state.imageURI === '') {
...@@ -227,7 +239,7 @@ class CameraComponent extends React.Component { ...@@ -227,7 +239,7 @@ class CameraComponent extends React.Component {
/> />
<View style={[styles.overlay, styles.bottomOverlay]}> <View style={[styles.overlay, styles.bottomOverlay]}>
<Icon.Button name="clear" size={48} backgroundColor="transparent" onPress={this.clear} /> <Icon.Button name="clear" size={48} backgroundColor="transparent" onPress={this.clear} />
<Icon.Button name="done" size={48} backgroundColor="transparent" onPress={this.uploadImage} /> <Icon.Button name="done" size={48} backgroundColor="transparent" onPress={this.uploadImage2} />
</View> </View>
</View> </View>
); );
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { import {
View, View,
Stylesheet, StyleSheet,
Text, Text,
TouchableOpacity, TouchableOpacity,
Dimensions, Dimensions,
Image, Image,
Platform,
ScrollView,
} from 'react-native'; } from 'react-native';
import TagInput from 'react-native-tag-input'; import TagInput from 'react-native-tag-input';
import { InputItem } from 'antd-mobile'; import { InputItem } from 'antd-mobile';
import { futch } from '../utils/polyfill';
import { getToken } from '../utils/auth';
import { encrypt } from '../utils/helper';
import config from '../utils/config';
import { userApi } from '../services/interfaces';
import { errors } from '../utils/error';
const styles = StyleSheet.create({
container: {
flex: 1,
},
view_header_container: {
height: 56,
backgroundColor: 'white',
flexDirection: 'row',
alignItems: 'center',
},
text_right_title: {
color: '#000',
position: 'absolute',
right: 16,
},
text_left_title: {
color: '#000',
position: 'absolute',
left: 16,
},
text_title: {
color: '#000',
fontSize: 18,
},
// uploadImage: {
// height: Dimensions.get('window').height,
// width: Dimensions.get('window').width,
// },
});
const inputProps = {
keyboardType: 'default',
placeholder: '如:身份证',
autoFocus: true,
style: {
fontSize: 14,
marginVertical: Platform.OS === 'ios' ? 10 : -2,
},
};
class UploadPageComponent extends PureComponent { class UploadPageComponent extends PureComponent {
constructor(props) {
console.info('未过滤之前');
console.info(props);
super(props);
console.info('过滤之后');
console.info(props);
const { imageURI } = this.props.navigation.state.params;
this.state = {
imageURI,
tags: ['身份证', '红本', '绿本'],
text: '',
imageName: '',
};
}
onChangeTags = (tags) => {
this.setState({ tags });
};
onChangeText = (text) => {
this.setState({ text });
const lastTyped = text.charAt(text.length - 1);
const parseWhen = [',', ' ', ';', '\n'];
if (parseWhen.indexOf(lastTyped) > -1) {
this.setState({
tags: [...this.state.tags, this.state.text],
text: '',
});
}
};
onCancel = () => { onCancel = () => {
this.props.onCancel(); this.props.onCancel();
}; };
onUploadPhoto = () => { onUploadPhoto = () => {
this.props.onUploadPhoto(); let token;
getToken().then((Apptoken) => {
if (!Apptoken) {
return Promise.reject(errors.tokenMissing());
}
token = encrypt(Apptoken);
const uri = `${config.apiContextPath}/resource/${token}`;
const formData = new global.FormData();
const file = { uri: this.state.imageURI, type: 'image/jpg', name: this.state.imageName !== '' ? this.state.imageName : this.state.imageURI.split('/')[this.state.imageURI.split('/').length - 1] };
formData.append('file', file);
console.info(formData);
futch(uri, {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
},
body: formData,
}, (progressEvent) => {
const progress = progressEvent.loaded / progressEvent.total;
})
.then(request => request.responseText)// response.text())
.then((responseData) => {
const response = JSON.parse(responseData);
if (response.errorCode === 0) {
const name = 'addTags';// 添加标签
const PicUri = `${config.apiContextPath}/api/interface/user/${name}/invoke`;
console.info(PicUri);
const postjson = { uri: response.data[0], tags: ['当事人信息', '当事人信息'] };
console.info(JSON.stringify(postjson));
userApi.invokeInterface(name, postjson)
// futch(PicUri, {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify(postjson),
// }, (progressEvent) => {
// console.info(progressEvent);
// })
.then(request => console.info(request));// response.text())
// 这里需要调用接口,对图片数据进行绑定,等待完善
// 页面跳转,跳转到前面的详情的页面
console.info('跳转');
this.props.navigation.navigate('DSRInfoDetail', this.props.navigation.state.params.pID);
}
})
.catch((error) => {
console.info(error);
});
});
}; };
setImageName = (val) => {
this.setState({ imageName: val });
}
labelExtractor = tag => tag;
renderHeaderMenu() { renderHeaderMenu() {
return ( return (
<View style={[styles.view_header_container, { backgroundColor: this.props.bgColor }]}> <View style={[styles.view_header_container, { backgroundColor: 'lightgray' }]}>
<TouchableOpacity <TouchableOpacity
onPress={this.onCancel()} onPress={this.onCancel}
> >
<Text style={[styles.text_title, { color: this.props.titleColor }]}>取消</Text> <Text style={[styles.text_title, { color: this.props.titleColor }]}>取消</Text>
</TouchableOpacity> </TouchableOpacity>
<Text style={[styles.text_title, { color: this.props.titleColor }]}>传照片</Text> <Text style={[styles.text_title, { color: this.props.titleColor }]}>传照片</Text>
<TouchableOpacity <TouchableOpacity
onPress={this.onUploadPhoto()} onPress={this.onUploadPhoto}
> >
<Text style={styles.text_right_title}> <Text style={styles.text_right_title}>
上传 上传
...@@ -37,59 +169,40 @@ class UploadPageComponent extends PureComponent { ...@@ -37,59 +169,40 @@ class UploadPageComponent extends PureComponent {
); );
} }
render() { render() {
const { getFieldProps, getFieldError } = this.props.form;
return ( return (
<View style={styles.container}> <View style={styles.container}>
{this.renderHeaderMenu()} {this.renderHeaderMenu()}
<Image <ScrollView>
style={{ height: Dimensions.get('window').height, width: Dimensions.get('window').width }} <Image
source={{ uri: this.props.imageURI, isStatic: true }} style={{ height: 80, width: 80 }}
/> source={{ uri: this.state.imageURI, isStatic: true }}
<InputItem />
{...getFieldProps('account', { <InputItem
initialValue: 'little ant', placeholder="如:张三"
rules: [ data-seed="logId"
{ required: true, message: '名称不能为空' }, onChange={this.setImageName}
], >照片名称
})} </InputItem>
clear <View style={{ flexDirection: 'row', alignItems: 'center', backgroundColor: 'lightgray' }}>
error={!!getFieldError('account')} <Text>类型</Text>
placeholder="请输入名字" <TagInput
>照片名称 value={this.state.tags}
</InputItem> onChange={this.onChangeTags}
labelExtractor={this.labelExtractor}
text={this.state.text}
onChangeText={this.onChangeText}
tagColor="blue"
tagTextColor="white"
inputProps={inputProps}
maxHeight={75}
/>
</View>
</ScrollView>
</View> </View>
); );
} }
} }
const styles = Stylesheet.create({
container: {
flex: 1,
},
view_header_container: {
height: 56,
backgroundColor: 'white',
flexDirection: 'row',
alignItems: 'center',
},
text_right_title: {
color: '#000',
position: 'absolute',
right: 16,
},
text_left_title: {
color: '#000',
position: 'absolute',
left: 16,
},
text_title: {
color: '#000',
fontSize: 18,
},
uploadImage: {
height: Dimensions.get('window').height,
width: Dimensions.get('window').width,
},
});
export default UploadPageComponent; export default UploadPageComponent;
...@@ -2,6 +2,7 @@ import { StackNavigator } from 'react-navigation'; ...@@ -2,6 +2,7 @@ import { StackNavigator } from 'react-navigation';
import DSRInfoScreen from './DSRInfoScreeen'; import DSRInfoScreen from './DSRInfoScreeen';
import DSRInfoDetailScreen from './DSRInfoDetailScreen'; import DSRInfoDetailScreen from './DSRInfoDetailScreen';
import FileViewList from './fileViewList'; import FileViewList from './fileViewList';
import UploadPageComponent from '../../../components/uploadPageComponent';
const DSRErJiScreen = StackNavigator( const DSRErJiScreen = StackNavigator(
{ {
...@@ -14,6 +15,9 @@ const DSRErJiScreen = StackNavigator( ...@@ -14,6 +15,9 @@ const DSRErJiScreen = StackNavigator(
DSRInfoFileView: { DSRInfoFileView: {
screen: FileViewList, screen: FileViewList,
}, },
DSRInfoTuPian: {
screen: UploadPageComponent,
},
}, },
{ {
headerMode: 'none', headerMode: 'none',
......
...@@ -32,7 +32,7 @@ const config = { ...@@ -32,7 +32,7 @@ const config = {
contextPath: '', contextPath: '',
updateContextPath: 'http://192.168.1.22:8080/app', updateContextPath: 'http://192.168.1.22:8080/app',
// apiContextPath: 'http://14.21.68.149:9089/test', // apiContextPath: 'http://14.21.68.149:9089/test',
apiContextPath: 'http://192.168.1.22:8080/bm', apiContextPath: 'http://192.168.1.22:8080/sz',
defaultDateFormat, defaultDateFormat,
defaultTimeFormat, defaultTimeFormat,
defaultDateTimeFormat, defaultDateTimeFormat,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论