|
@@ -1,24 +1,29 @@
|
1
|
1
|
import { useState } from "react"
|
|
2
|
+import { useModel } from '@/store'
|
2
|
3
|
import Taro from "@tarojs/taro"
|
3
|
4
|
import { Input, View, Image } from "@tarojs/components"
|
4
|
5
|
import withLayout from '@/layouts'
|
5
|
6
|
import CustomNav from "@/components/CustomNav"
|
6
|
7
|
import MyButton from "@/components/MyButton"
|
|
8
|
+import { updateInfo } from '@/services/login'
|
7
|
9
|
import banner1 from '@/assets/banner/1.jpg'
|
8
|
10
|
import resetImg from '@/assets/user/cancel.png'
|
9
|
11
|
import './style.less'
|
10
|
12
|
|
11
|
13
|
export default withLayout((props) => {
|
12
|
|
- const [name, setName] = useState()
|
13
|
|
- const [phone, setPhone] = useState()
|
14
|
|
- const [avatar, setAvatar] = useState(banner1)
|
|
14
|
+
|
|
15
|
+ const { person, setPerson } = useModel('person')
|
|
16
|
+
|
|
17
|
+ const [name, setName] = useState(person.nickName)
|
|
18
|
+ const [phone, setPhone] = useState(person.phone)
|
|
19
|
+ const [avatar, setAvatar] = useState(person.avatar)
|
15
|
20
|
const changeName = (e) => {
|
16
|
21
|
setName(e.detail.value)
|
17
|
22
|
}
|
18
|
23
|
const changePhone = (e) => {
|
19
|
24
|
setPhone(e.detail.value)
|
20
|
25
|
}
|
21
|
|
- const rulePhone=(val)=>{
|
|
26
|
+ const rulePhone = (val) => {
|
22
|
27
|
if (!/^1[0-9]{10}$/.test(val)) {
|
23
|
28
|
Taro.showToast({
|
24
|
29
|
title: '请输入正确的11位手机号',
|
|
@@ -30,34 +35,39 @@ export default withLayout((props) => {
|
30
|
35
|
}
|
31
|
36
|
const handleSave = () => {
|
32
|
37
|
if (rulePhone(phone)) {
|
33
|
|
- Taro.showToast({
|
34
|
|
- title: '保存成功',
|
35
|
|
- icon: 'none',
|
|
38
|
+ updateInfo(person.personId, { ...person, avatar: avatar, phone: phone, nickName: name }).then((res) => {
|
|
39
|
+ setPerson(res)
|
|
40
|
+ Taro.showToast({
|
|
41
|
+ title: '保存成功',
|
|
42
|
+ icon: 'none',
|
|
43
|
+ })
|
|
44
|
+ Taro.navigateBack({ delta: 1 })
|
|
45
|
+ }).catch((e) => {
|
|
46
|
+ console.log(e)
|
|
47
|
+ Taro.showToast({
|
|
48
|
+ title: '网络异常, 请刷新小程序重试',
|
|
49
|
+ icon: 'none',
|
|
50
|
+ })
|
36
|
51
|
})
|
37
|
|
- Taro.navigateBack({delta:1})
|
38
|
52
|
}
|
39
|
53
|
}
|
40
|
|
- const resetName=()=>{
|
|
54
|
+ const resetName = () => {
|
41
|
55
|
setName()
|
42
|
56
|
}
|
43
|
|
- const resetPhone=()=>{
|
|
57
|
+ const resetPhone = () => {
|
44
|
58
|
setPhone()
|
45
|
59
|
}
|
46
|
|
- const changeAvatar=()=>{
|
47
|
|
- Taro.chooseImage({
|
48
|
|
- count: 1,
|
|
60
|
+ const changeAvatar = () => {
|
|
61
|
+ Taro.getUserProfile({
|
|
62
|
+ lang: 'zh_CN',
|
|
63
|
+ desc: "获取你的昵称、头像、地区及性别",
|
49
|
64
|
success: function (res) {
|
50
|
|
- setAvatar(res.tempFilePaths[0])
|
51
|
|
- // uploadFile(res.tempFilePaths[0]).then((res2) => {
|
52
|
|
- // const date = {
|
53
|
|
- // targetId: roomId,
|
54
|
|
- // targetType: 'room',
|
55
|
|
- // content: res2,
|
56
|
|
- // contentType: 'image'
|
57
|
|
- // }
|
58
|
|
- // saveExtend(date)
|
59
|
|
- // setReset(!reset)
|
60
|
|
- // })
|
|
65
|
+ setAvatar(res.userInfo.avatarUrl)
|
|
66
|
+ },
|
|
67
|
+ fail: () => {
|
|
68
|
+ //拒绝授权
|
|
69
|
+ console.error("拒绝了请求");
|
|
70
|
+ return;
|
61
|
71
|
}
|
62
|
72
|
})
|
63
|
73
|
}
|