浏览代码

静态页面

xcx 4 年前
父节点
当前提交
c13585b6d3
共有 1 个文件被更改,包括 29 次插入3 次删除
  1. 29
    3
      src/pages/WoDe/GeRenXinXi/index.jsx

+ 29
- 3
src/pages/WoDe/GeRenXinXi/index.jsx 查看文件

@@ -8,7 +8,7 @@ import '@/assets/css/reset.less'
8 8
 import '@/assets/css/iconfont.less'
9 9
 import './index.less'
10 10
 
11
-export default function GeRenXinXi (props) {
11
+export default function GeRenXinXi () {
12 12
 
13 13
   const { user, setUser } = useModel('user')
14 14
   const [Name, setName] = useState(null)
@@ -26,7 +26,7 @@ export default function GeRenXinXi (props) {
26 26
       setPhone(user.tel || user.phone)
27 27
       setBirthday(user.birthday)
28 28
       SexList.map((item, index) => {
29
-        if (user.sex - 0 === item.id - 0 ||user.gender - 0 === item.id - 0) {
29
+        if (user.sex - 0 === item.id - 0 || user.gender - 0 === item.id - 0) {
30 30
           setSex(index)
31 31
         }
32 32
       })
@@ -85,13 +85,39 @@ export default function GeRenXinXi (props) {
85 85
     })
86 86
   }
87 87
 
88
+  const AddImg = () => { // 添加图片
89
+    Taro.chooseImage({
90
+      count: 1,
91
+      sizeType: ['compressed'],
92
+      sourceType: ['album', 'camera'],
93
+      success: (res) => {
94
+        const tempFilePaths = res.tempFilePaths
95
+        Taro.uploadFile({
96
+          url: apis.uploadImage.url,
97
+          filePath: tempFilePaths[0],
98
+          name: 'file',
99
+          formData: { user: 'upload' },
100
+          header: { 'x-action': 'miniapp', 'authorization': `Bearer ${Taro.getStorageSync('token')}` },
101
+          success: (cRes) => {
102
+            request({ ...apis.EditUserInfo, data: { avatar: JSON.parse(cRes.data).data } }).then(() => {
103
+              Taro.showToast({ title: '修改成功', icon: 'none' })
104
+              setUser({ ...user, avatarurl: JSON.parse(cRes.data).data })
105
+            }).catch((eRes) => {
106
+              Taro.showToast({ title: eRes, icon: 'none' })
107
+            })
108
+          }
109
+        })
110
+      }
111
+    })
112
+  }
113
+
88 114
   return (
89 115
     <Page>
90 116
       <view className='GeRenXinXi'>
91 117
         <view className='Form'>
92 118
           <view className='flex-h'>
93 119
             <text className='flex-item'>头像</text>
94
-            <view className='UserIcon'>
120
+            <view className='UserIcon' onClick={AddImg}>
95 121
               <image mode='aspectFill' src={user !== null ? user.avatarurl : null}></image>
96 122
             </view>
97 123
           </view>