import { Component } from "react"; import { View, Text, Image,Input, Button } from "@tarojs/components"; import { AtInput } from "taro-ui"; import Taro from "@tarojs/taro"; import { updateUserInfo,getUserInfo } from "../../../service"; import avatar from "../../../images/mine/avatar.png"; import "./index.less"; export default class Index extends Component { state = { wxAccount: "", nickName: "", phone: "", avatar: "", }; componentDidMount() { this.getUserInfo(); } // 获取用户信息 async getUserInfo() { const res = await getUserInfo(); this.setState({ wxAccount: res.wechat_account, nickName: res.name, phone: res.phone, avatar: res.icon, }); } // 微信账号 handleAccountChange(value) { this.setState({ wxAccount: value, }); return value; } // 昵称 handleNickNameChange(value) { this.setState({ nickName: value, }); return value; } // 手机号 handlePhoneChange(value) { this.setState({ phone: value, }); return value; } // 选择头像 handleChooseAvatar = (e) => { this.setState({ avatar: e.detail.avatarUrl, }); } // 提交 handleSubmit = async () => { const phoneRegex = /^1[3-9]\d{9}$/; // 中国大陆手机号正则 if (!this.state.nickName || !this.state.phone) { Taro.showToast({ title: "请输入完整信息", icon: "none", }); return; } else if (!phoneRegex.test(this.state.phone)) { Taro.showToast({ title: "请输入正确的手机号", icon: "none", }); return; } const res = await updateUserInfo({ icon: this.state.avatar, name: this.state.nickName, phone: this.state.phone, wechat_account: this.state.wxAccount, }); Taro.showToast({ title: '修改成功', icon: "none", }); }; render() { return ( {/* 头像 */} {/* */} {/* 内容 */} {/* 提交按钮 */} 提交 ); } }