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

uniapp 之 图片 视频 文件上传

在这里插入图片描述

<view class="" style="padding: 24rpx 0"><text>相关资料 <text class="fs-26 color-666">(图片、视频、文档不超过9个)</text> </text><view class="flex align-center" style="margin-top: 17rpx;"><u-upload accept="all" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple:maxCount="9"></u-upload></view></view>
submit() {if (this.fileList1.length) {let urls = [];this.fileList1.forEach(el => {urls.push({type: el.types,url: el.url,})});this.info.pic = JSON.stringify(urls);}uni.showModal({title: '',content: '确认提交?',success: res => {if (res.confirm) {// 创建订单this.$http({url: "/api",data: this.info,}).then(res1 => {uni.$u.toast('提交成功');setTimeout(()=>{this.$xf.on('/pages/mine');},2000)})} else if (res.cancel) {console.log('用户点击取消');}}});},// 删除图片deletePic(event) {this[`fileList${event.name}`].splice(event.index, 1);},// 新增图片async afterRead(event) {// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式let lists = [].concat(event.file);let fileListLen = this[`fileList${event.name}`].length;lists.map((item) => {this[`fileList${event.name}`].push({...item,status: "uploading",message: "上传中",});});for (let i = 0; i < lists.length; i++) {// 接口返回数据const result = await this.uploadFilePromise(lists[i].url);let item = this[`fileList${event.name}`][fileListLen];if (item.type == "video") {item.types = 2;} else if (item.type == "image") {item.types = 1;} else {item.types = 3;}this[`fileList${event.name}`].splice(fileListLen,1,Object.assign(item, {status: "success",message: "",url: JSON.parse(result).data.url,}));fileListLen++;}console.log(this.fileList1);},uploadFilePromise(url) {return new Promise((resolve, reject) => {let a = uni.uploadFile({url: getApp().globalData.baseURL + "/api", // 仅为示例,非真实的接口地址filePath: url,name: "file",header: {"Authorization": uni.getStorageSync("token")},success: (res) => {setTimeout(() => {resolve(res.data);}, 500);},});});},
http://www.lryc.cn/news/259757.html

相关文章:

  • MIT线性代数笔记-第28讲-正定矩阵,最小值
  • Python:五种算法RFO、GWO、DBO、HHO、SSA求解23个测试函数
  • 如何参与开源项目
  • twitter开发如何避坑
  • 人工智能算法合集
  • PythonStudio:一款国人写的python及窗口开发编辑IDE,可以替代pyqt designer等设计器了
  • 大模型应用_FastGPT
  • elasticsearch|大数据|elasticsearch的api部分实战操作以及用户和密码的管理
  • Android多进程和跨进程通讯方式
  • 通过Jenkins将应用发布到K8s1.24.3
  • 正则表达式入门与实践
  • C++初阶(十六)优先级队列
  • 深入探索C语言中的二叉树:数据结构之旅
  • 如何发现服务器被入侵了,服务器被入侵了该如何处理?
  • CSDN一键注释功能
  • 基于JAVA的校园电子商城系统论文
  • 直播传媒公司网站搭建作用如何
  • 数据结构与算法-动态规划-机器人达到指定位置方法数
  • K8S学习指南(2)-docker的基本使用
  • java 执行linux 命令
  • ubuntu将本机的wifi网络通过网线分享给另一台机器(用于没有有线网络,重装系统后无wifi驱动或者另一台设备没有wifi网卡)
  • Docker + Jenkins + Gitee 自动化部署项目
  • ChatGPT 应用开发(一)ChatGPT OpenAI API 免代理调用方式(通过 Cloudflare 的 AI Gateway)
  • 【TC3xx】GETH
  • 不需要联网的ocr项目
  • 【Git使用总结】
  • 仿照MyBatis手写一个持久层框架学习
  • 关东升老师极简系列丛书(由清华大学出版社出版)
  • 要求CHATGPT高质量回答的艺术:提示工程技术的完整指南—第 27 章:如何避开和绕过所有人工智能内容检测器
  • JavaWeb笔记之MySQL数据库