E企盈营销工具技术服务商 热线:4006-838-530

小程序之文件上云阳县E企盈小程序传

小程序前端数据处理// 引入Model类import {PlayModel} from "../../../models/PlayModel";import {FileModel} from "../../../models/FileModel";import {TimeStorage} from "../../../utils/timeStorage";let playModel = new PlayModel();let fileModel = new FileModel();let timeStorage = new TimeStorage();Page({  /**   * 页面的初始数据   */  data: {    // 详情数    contentCount: 0,    // 标题内容    content: '',    // 图片列表    images: [],    // 视频    video : '',  },  // 表单提交事件  submitClick() {        if (this.data.content == '') {      wx.show开通拖把桶旋转小程序电话:4006-838-530Toast({        title: '内容不能为空!',        duration: 2000,        icon: 'none',        mask:true      })    } else if (this.data.images.length == 0 && this.data.video == '') {      wx.showToast({        title: '视频和图片必须添加一个!',        duration: 2000,        icon: 'none',        mask:true      })    } else {      let artContent = this.data.content;      let userId = timeStorage.getStorage("userInfo").user.userId;      wx.showToast({        title: '加载中...',        mask: true,        icon: 'loading'      })      if(this.data.video == ''){        playModel.submitArticle({          data: {            userId: userId,            artContent: artContent,          },          success: (res) = {            let artId = res.object;            // 多图片上传              this.data.images.map(function(value, index){              fileModel.uploadImages({                data: value,                success: (res) = {                  playModel.submitImages({                    data: {                      artId: artId,                      imgUrl: res.msg                    },                    success: (res) = {                      console.log(res)                    }                  })                }              })            })            wx.showToast({              title: '成功',              icon: 'success',              duration: 2000,              success: function() {                // 成功后返回上一页                  wx.navigateBack({delta:1})              }            })          }        });      }else{        // 视频上传          fileModel.uploadVideo({          data: this.data.video,          success: (res) = {            playModel.submitArticle({              data: {                userId: userId,                artVideo: res.msg,                artContent: artContent,              },              success: (res) = {                if(res.code == '200'){                  wx.showToast({                    title: '成功',                    icon: 'success',                    duration: 2000,                    success: function() {                      // 成功后返回上一页                          wx.navigateBack({delta:1})                    }                  })                }else{                  wx.showToast({                    title: '失败',                    icon: 'none',                    duration: 2000                  })                }              }            });          }        })      }    }  }})

对图片和视频上传的处理import { FileUpload } from "../utils/fileUpload.js"class FileModel extends FileUpload {      // 视频上传开通男士睡衣小程序电话:4006-838-530  uploadVideo(params) {    this.request({      url: 'article/uploadVideo',      data: params.data,      success: (res) = {        params.开通内裤男小程序电话:4006-838-530success && params.success(res)      }    })  }  // 图片上传  uploadImages(params) {    this.request({      url: 'article/uploadImage',      data: params.data,      success: (res) = {        params.success && params.success(res)      }    })  }}export { FileModel }

对图片和视频API上传import { config } from "../config.js"import { tips } from "./error_code.js"class FileUpload{    request(params) {        wx.uploadFile({            url: config.api_local_url + params.url,            filePath: params.data,            name: 'file',            success: (res) = {                let code = res.statusCode.toString()                if (code.startsWith("2")) {                    params.success && params.success(JSON.parse(res.data))                } else {                    let error_code = res.data.error_code                    this._error_status(error_code)                }            },            fail: (error) = {                this._error_status(1000)            }        })    }    _error_status(error_code) {        wx.showToast({          title: tips[error_code],          icon: 'none',          duration: 2000        })      }}export { FileUpload }

springboot后台的处理Controller处理@RestController@RequestMapping("/api")public class ArticleAPI {    @Autowired    private ArticleService articleService;    @Autowired    private ArticleImagesService imagesService;    /**     * @function 视频上传     * @return     */    @PostMapping("/article/uploadVideo")    public JsonResult uploadVideo(@RequestParam(value = "file", required = false) MultipartFile file) {        if(file == null){            return new JsonResult(ResultCode.FAIL, "内容为空");        }else{            return new JsonResult(ResultCode.SUCCESS, FileUpload.fileOne(file, UploadType.ARTICLE_VIDEO));        }    }    /**     * @function 图片上传     * @param file     * @return     */    @PostMapping("/article/uploadImage")    public JsonResult uploadImages(@RequestParam(value = "file", required = false) MultipartFile file) {        if(file == null) {            return new JsonResult(ResultCode.FAIL, "内容为空");        }else {            return new JsonResult(ResultCode.SUCCESS, FileUpload.fileOne(file, UploadType.ARTICLE_IMAGES));        }    }    /**     * @function 表单提交     * @param userId     * @param artContent     * @param artVideo     * @return     */    @PostMapping("/article/submitArticle")    public JsonResult submitArticle(AD:【E企盈】模王系统:拼购电商卖货系统,直播电商系统,多商户入驻系统

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 小程序之文件上云阳县E企盈小程序传
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

模王系统开发

联系我们升级日志

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏