uniapp微信小程序投票系统实战 (SpringBoot2+vue3.2+element plus ) -用户信息修改实现

锋哥原创的uniapp微信小程序投票系统实战:

uniapp微信小程序投票系统实战课程 (SpringBoot2+vue3.2+element plus ) ( 火爆连载更新中... )_哔哩哔哩_bilibiliuniapp微信小程序投票系统实战课程 (SpringBoot2+vue3.2+element plus ) ( 火爆连载更新中... )共计21条视频,包括:uniapp微信小程序投票系统实战课程 (SpringBoot2+vue3.2+element plus ) ( 火爆连载更新中... )、第2讲 投票项目后端架构搭建、第3讲 小程序端 TabBar搭建等,UP主更多精彩视频,请关注UP账号。https://www.bilibili.com/video/BV1ea4y137xf/后端修改用户昵称:

java 复制代码
/**
 * 更新用户昵称
 * @param wxUserInfo
 * @param token
 * @return
 */
@RequestMapping("/updateNickName")
public R updateNickName(@RequestBody WxUserInfo wxUserInfo,@RequestHeader String token){
    if(StringUtil.isNotEmpty(wxUserInfo.getNickName())) {
        Claims claims = JwtUtils.validateJWT(token).getClaims();
        wxUserInfoService.update(new UpdateWrapper<WxUserInfo>().eq("openid", claims.getId()).set("nick_name", wxUserInfo.getNickName()));
    }
    return R.ok();
}

前端修改用户昵称:

XML 复制代码
<input type="nickname"  placeholder="请输入昵称" v-model="userInfo.nickName" @blur="onChangeNickName"/>
javascript 复制代码
onChangeNickName:async function(e){
				console.log(e.detail.value);
				let nickName=e.detail.value;
				if(!isEmpty(nickName)){
					const result=await requestUtil({url:"/user/updateNickName",data:{nickName:nickName},method:"post"});
				}
			}
javascript 复制代码
export const isEmpty=(str)=>{
	if(str === '' || str.trim().length === 0 ){
		return true
	}else{
		return false;
	}
}

头像上传 后端:

定义上传路径:

javascript 复制代码
userImagesFilePath: D://uniapp/userImgs/
java 复制代码
@Value("${userImagesFilePath}")
private String userImagesFilePath;
java 复制代码
/**
 * 上传用户头像图片
 * @param userImage
 * @return
 * @throws Exception
 */
@RequestMapping("/uploadUserImage")
public Map<String,Object> uploadUserImage(MultipartFile userImage, @RequestHeader String token)throws Exception{
    System.out.println("filename:"+userImage.getName());
    Map<String,Object> resultMap=new HashMap<>();
    if(!userImage.isEmpty()){
        // 获取文件名
        String originalFilename = userImage.getOriginalFilename();
        String suffixName=originalFilename.substring(originalFilename.lastIndexOf("."));
        String newFileName= DateUtil.getCurrentDateStr()+suffixName;
        FileUtils.copyInputStreamToFile(userImage.getInputStream(),new File(userImagesFilePath+newFileName));
        resultMap.put("code",0);
        resultMap.put("msg","上传成功");
        resultMap.put("userImageFileName",newFileName);
        // 更新到数据库
        UpdateWrapper<WxUserInfo> updateWrapper=new UpdateWrapper<>();
        Claims claims = JwtUtils.validateJWT(token).getClaims();
        updateWrapper
                .eq("openid",claims.getId())
                .set("avatar_url",newFileName);
        wxUserInfoService.update(new UpdateWrapper<WxUserInfo>().eq("openid",claims.getId()).set("avatar_url",newFileName));
    }

    return resultMap;
}

前端头像实现:

button上加下 open-type="chooseAvatar"

javascript 复制代码
		onChooseAvatar:function(e){
			console.log(e.detail.avatarUrl)
			uni.uploadFile({
				header:{token:uni.getStorageSync("token")},
				url:getBaseUrl()+"/user/uploadUserImage",
				filePath:e.detail.avatarUrl,
				name:"userImage",
				success: (res) => {
					let result=JSON.parse(res.data);
					if(result.code==0){
						this.userInfo.avatarUrl=result.userImageFileName;
					}
				}
			})
		},
相关推荐
2401_845937538 小时前
PHP一键约课高效健身智能健身管理系统小程序源码
微信·微信小程序·小程序·微信公众平台·微信开放平台
程序员入门进阶10 小时前
基于微信小程序的科创微应用平台设计与实现+ssm(lw+演示+源码+运行)
微信小程序·小程序
鸭子嘎鹅子呱13 小时前
uniapp使用高德地图设置marker标记点,后续根据接口数据改变某个marker标记点,动态更新
uni-app·map·高德地图
计算机源码社18 小时前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
DreamByte20 小时前
Python Tkinter小程序
开发语言·python·小程序
说私域20 小时前
开源 AI 智能名片小程序:开启内容营销新境界
人工智能·小程序
汇匠源20 小时前
零工市场小程序:保障灵活就业
java·小程序·零工市场
哈尔滨财富通科技20 小时前
家居小程序有什么用?
小程序
双普拉斯21 小时前
微信小程序点赞动画特效实现
nginx·微信小程序·notepad++
程序员阿龙21 小时前
【2025】基于微信小程序的网上点餐系统设计与实现、基于微信小程序的智能网上点餐系统、微信小程序点餐系统设计、智能点餐系统开发、微信小程序网上点餐平台设计
微信小程序·小程序·毕业设计·订单管理·在线点餐·订单跟踪·在线支付