当前位置: 首页 > news >正文

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账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1ea4y137xf/图文投票和文字投票基本一样,就是在投票选项里面,多了一个选项图片;

<view class="option_item" v-for="(item,index) in options" :key="item.id"><view class="option_input"><text class="removeOption" @click="removeOption(item.id)">&#xe618;</text><input type="text" v-model="item.name" placeholder="输入选项名称" placeholder-style="color:#bababa;font-size:14px"></view>				<view class="option_upload"><uni-file-picker@select="selectVoteItemFileFunc($event,index)":auto-upload="false" limit="1":del-icon="false" disable-preview file-mediatype="image" :imageStyles="voteItemImageStyles"><view class="upload"><text class="smallUploadImg">&#xe727;</text></view></uni-file-picker></view></view>
.option_item{margin-top: 10px;border-radius: 5px;background-color: white;padding: 10px;.option_input{display: flex;}.option_upload{margin-top: 20rpx;.upload{margin: 10rpx;background-color: #f4f5f7;width:90rpx;height: 90rpx;display: flex;align-items: center;justify-content: center;}}}
			voteItemImageStyles:{width:"150rpx",height:"120rpx",border:false},
selectVoteItemFileFunc:function(e,index){console.log("index="+index)console.log(e.tempFilePaths[0])uni.uploadFile({header:{token:uni.getStorageSync("token")},url:getBaseUrl()+"/vote/uploadVoteItemImage",filePath:e.tempFilePaths[0],name:"voteItemImage",success: (res) => {let result=JSON.parse(res.data);if(result.code==0){this.options[index].image=result.voteItemImageFileName;}}})},

加个image属性:

提交加上验证:

// 验证投票选项,如果有名称的,必须要上传图片for(var i=0;i<this.options.length;i++){var option=this.options[i];if(!isEmpty(option.name)){if(isEmpty(option.image)){console.log("请上传第"+(i+1)+"个投票选项图片")uni.showToast({icon:"error",title:"请上传第"+(i+1)+"个投票选项图片"})return;}}}

后端:

voteItemImagesFilePath: D://uniapp/voteItemImgs/
@Value("${voteItemImagesFilePath}")
private String voteItemImagesFilePath;
/*** 上传投票选项图片* @param voteItemImage* @return* @throws Exception*/
@RequestMapping("/uploadVoteItemImage")
public Map<String,Object> uploadVoteItemImage(MultipartFile voteItemImage)throws Exception{System.out.println("filename:"+voteItemImage.getName());Map<String,Object> resultMap=new HashMap<>();if(!voteItemImage.isEmpty()){// 获取文件名String originalFilename = voteItemImage.getOriginalFilename();String suffixName=originalFilename.substring(originalFilename.lastIndexOf("."));String newFileName= DateUtil.getCurrentDateStr()+suffixName;FileUtils.copyInputStreamToFile(voteItemImage.getInputStream(),new File(voteItemImagesFilePath+newFileName));resultMap.put("code",0);resultMap.put("msg","上传成功");resultMap.put("voteItemImageFileName",newFileName);}return resultMap;
}

相关文章:

  • sd-webui-EasyPhoto win 安装笔记
  • 冲刺2024年AMC8模拟题:往年真题限时练一练和答案详解(4)
  • 【LeetCode每日一题】2645. 构造有效字符串的最少插入数(计算组数+动态规划+考虑相邻字母)
  • 携程testab算法分析
  • vue面试题集锦
  • LC 2645. 构造有效字符串的最少插入数
  • 【笔记】书生·浦语大模型实战营——第三课(基于 InternLM 和 LangChain 搭建你的知识库)
  • 【Flink精讲】Flink数据延迟处理
  • 【前端】使用javascript开发一个在线RGB颜色转换
  • wpf的资源路径
  • 基于ssm运动会管理系统的设计与实现 【附源码】
  • 少儿编程 2023年12月中国电子学会图形化编程等级考试Scratch编程三级真题解析(判断题)
  • 秋招阿里巴巴java笔试试题-精
  • GitHub pull request(傻瓜式入门版)
  • STM32F103RCT6使用数据手册及应用示例程序分享
  • [译]Python中的类属性与实例属性的区别
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • Codepen 每日精选(2018-3-25)
  • css选择器
  • scrapy学习之路4(itemloder的使用)
  • spark本地环境的搭建到运行第一个spark程序
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • 测试如何在敏捷团队中工作?
  • 搭建gitbook 和 访问权限认证
  • 力扣(LeetCode)21
  • 少走弯路,给Java 1~5 年程序员的建议
  • 新书推荐|Windows黑客编程技术详解
  • 责任链模式的两种实现
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • ​软考-高级-系统架构设计师教程(清华第2版)【第9章 软件可靠性基础知识(P320~344)-思维导图】​
  • #if #elif #endif
  • (day 12)JavaScript学习笔记(数组3)
  • (超详细)2-YOLOV5改进-添加SimAM注意力机制
  • (二)换源+apt-get基础配置+搜狗拼音
  • (七)c52学习之旅-中断
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (转)Google的Objective-C编码规范
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • .Net 6.0 处理跨域的方式
  • .NET MVC第五章、模型绑定获取表单数据
  • .NET面试题解析(11)-SQL语言基础及数据库基本原理
  • .NET中的Event与Delegates,从Publisher到Subscriber的衔接!
  • @GlobalLock注解作用与原理解析
  • [ CTF ]【天格】战队WriteUp- 2022年第三届“网鼎杯”网络安全大赛(青龙组)
  • [2008][note]腔内级联拉曼发射的,二极管泵浦多频调Q laser——
  • [BJDCTF2020]The mystery of ip
  • [docker] Docker容器服务更新与发现之consul
  • [Excel]如何找到非固定空白格數列的條件數據? 以月份報價表單為例
  • [hdu2196]Computer树的直径
  • [hive]中的字段的数据类型有哪些
  • [I2C]I2C通信协议详解(二) --- I2C时序及规格指引
  • [iphone-cocos2d]关于Loading的若干处理和讨论
  • [leetcode] 61. 旋转链表
  • [Linux]进程创建➕进程终止
  • [NOIP2014] 提高组 洛谷P1941 飞扬的小鸟