index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import React,{Component} from 'react';
  2. import { StyleSheet, Text, View,Image } from 'react-native';
  3. import { List,ActionSheet,Toast } from 'antd-mobile-rn';
  4. import { connect } from 'react-redux';
  5. import LeanCloudAPI from '../../../leancloud';
  6. import ImagePicker from 'react-native-image-crop-picker';
  7. // const Buffer = require('buffer').Buffer;
  8. import commonStyle from '../../../styles/styles.js';
  9. // import FileSystem from 'react-native-filesystem';
  10. import {Device ,Icon} from '../../../tool';
  11. const Item = List.Item;
  12. const Brief = Item.Brief;
  13. class Infomation extends Component {
  14. constructor(props){
  15. super(props)
  16. this.state={
  17. }
  18. }
  19. static navigationOptions ={
  20. title:'个人信息'
  21. }
  22. push(routeName){
  23. const { navigation } =this.props
  24. navigation.navigate({ routeName })
  25. }
  26. showActionSheet(){
  27. const {navigation,UserAction} =this.props
  28. const {id} = UserAction
  29. const BUTTONS = [
  30. '拍照换头像',
  31. '从相册中选择新头像',
  32. '取消',
  33. ];
  34. ActionSheet.showActionSheetWithOptions(
  35. {
  36. options: BUTTONS,
  37. cancelButtonIndex: 2
  38. },
  39. (buttonIndex) => {
  40. const opction = {
  41. width: 400,
  42. height: 400,
  43. cropping: true,
  44. cropperChooseText:'确认',
  45. cropperCancelText:"取消",
  46. loadingLabelText:'处理中...',
  47. cropperStatusBarColor:"#1c90f5",
  48. cropperToolbarColor:"#1c90f5",
  49. compressImageQuality:0.8,
  50. hideBottomControls:true,
  51. }
  52. switch(buttonIndex){
  53. case 0 :
  54. ImagePicker.openCamera(opction).then(image => {
  55. UserAction.head = image.path
  56. let file= {filename:image.filename,height:400,isStored:false,type:image.mime,uri: image.path,width:400,localFile:image.path}
  57. let name = (id+new Date().getTime() + image.filename +'').toLocaleLowerCase()
  58. Toast.loading('头像修改中',50)
  59. LeanCloudAPI.upFile(name,file,(e)=>{
  60. LeanCloudAPI.updateUser('head',e,()=>{
  61. Toast.success('修改成功')
  62. navigation.dispatch({type:'USER',user:UserAction})
  63. })
  64. })
  65. });
  66. break;
  67. case 1 :
  68. ImagePicker.openPicker(opction).then(image => {
  69. UserAction.head = image.path
  70. let file= {filename:image.filename,height:400,isStored:false,type:image.mime,uri: image.path,width:400,localFile:image.path}
  71. let name = (id+new Date().getTime() + image.filename +'').toLocaleLowerCase()
  72. Toast.loading('头像修改中',50)
  73. LeanCloudAPI.upFile(name,file,(e)=>{
  74. LeanCloudAPI.updateUser('head',e,()=>{
  75. Toast.success('修改成功')
  76. navigation.dispatch({type:'USER',user:UserAction})
  77. })
  78. })
  79. });
  80. break;
  81. }
  82. },
  83. );
  84. }
  85. render(){
  86. const {UserAction } =this.props
  87. const { id ,username ,head,mobilePhoneNumber} =UserAction
  88. if(head){
  89. source = {
  90. uri:head,
  91. cache: 'force-cache'
  92. }
  93. }else{
  94. source = Icon.icon
  95. }
  96. return (
  97. <View style={commonStyle.page}>
  98. <List style={commonStyle.list}>
  99. <Item
  100. style={commonStyle.item}
  101. onClick={()=>{this.showActionSheet()}}
  102. extra={
  103. <View style={{ width: Device.scale(29), height: Device.scale(29) ,borderRadius:Device.scale(5),overflow:'hidden'}}>
  104. <Image
  105. source={source}
  106. style={{ width: Device.scale(29), height: Device.scale(29) }}
  107. />
  108. </View>
  109. }
  110. arrow="horizontal"
  111. >
  112. <Text style={styles.title}>头像</Text>
  113. </Item>
  114. </List>
  115. <List style={commonStyle.list}>
  116. <Item
  117. style={commonStyle.item}
  118. extra={username} arrow="horizontal" onClick={() => {this.push('ReName')}}>
  119. <Text style={styles.title}>昵称</Text>
  120. </Item>
  121. </List>
  122. <List style={commonStyle.list}>
  123. <Item
  124. style={commonStyle.item}
  125. extra={
  126. <View>
  127. <Brief style={{ textAlign: 'right' }}>{id}</Brief>
  128. </View>
  129. }
  130. >
  131. <Text style={styles.title}>ID</Text>
  132. </Item>
  133. </List>
  134. <List style={commonStyle.list}>
  135. <Item
  136. style={commonStyle.item}
  137. extra={
  138. <View>
  139. <Brief style={{ textAlign: 'right' }}>{mobilePhoneNumber}</Brief>
  140. </View>
  141. }
  142. >
  143. <Text style={styles.title}>手机号</Text>
  144. </Item>
  145. </List>
  146. <List style={commonStyle.list}>
  147. <Item
  148. style={commonStyle.item}
  149. onClick={() => {this.push('QrCode')}}
  150. extra={
  151. <Image
  152. source={Icon.Mine.code}
  153. style={{ width: Device.scale(29), height: Device.scale(29) }}
  154. />
  155. }
  156. arrow="horizontal"
  157. >
  158. <Text style={styles.title}>我的二维码</Text>
  159. </Item>
  160. </List>
  161. </View>
  162. )
  163. }
  164. }
  165. const styles = StyleSheet.create({
  166. title:{
  167. fontSize:Device.scale(16)
  168. }
  169. });
  170. const mapStateToProps = ({UserAction} )=> {
  171. return {UserAction}
  172. }
  173. ;
  174. export default connect(mapStateToProps)(Infomation);