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

b2b网站建设费用免费大数据平台

b2b网站建设费用,免费大数据平台,几级分销是合法的,网站要怎么做关键词二次封装的uniapp版本图片压缩、上传工具,支持全端(H5、小程序、APP) 新建文件:file-util.js class FileUtil {/*** [文件上传]* param {[object]} fileObj [图片地址]* param {[object]} formData [参数]* param {[str…

二次封装的uniapp版本图片压缩、上传工具,支持全端(H5、小程序、APP)

  • 新建文件:file-util.js 
class FileUtil {/*** [文件上传]* @param  {[object]} fileObj    [图片地址]* @param  {[object]} formData   [参数]* @param  {[string]} url        [上传地址]* @param  {[boolean]} compress  [是否压缩]* @return {[Promise]}         [description]*/async uploadFile(fileObj, formData = {}, url, compress = true) {if (!fileObj) {return uni.showToast({title: '找不到文件~'});}setTimeout(() => {uni.showLoading({title: '上传中...',mask: true,})}, 500)let file = fileObj;if (compress) {file = await this.compressImage(fileObj)}return this.upload(file, formData, url)}/*** * @param {Object} fileObj [文件对象]* @param {Object} imageWidth 图片宽度*/async compressImage(fileObj, imageWidth = 500) {let file = fileObj;//#ifndef H5file = await this.compressByMp(fileObj)//#endif//#ifdef H5file = await this.compressByH5(fileObj, imageWidth)//#endifreturn file}/*** [压缩图片-小程序/APP]* @param  {[type]} fileObj [description]* @return {[type]}         [description]*/async compressByMp(fileObj) {return new Promise(resolve => {if (fileObj.size > 500000) {uni.compressImage({src: fileObj.path, // 图片路径quality: 60, // 压缩质量success(res) {let file = {name: fileObj.name,type: fileObj.type,size: fileObj.size,path: res.tempFilePath}resolve(file)},fail(error) {console.warn('图片压缩异常,使用原图', error)resolve(fileObj)}})} else {console.warn('500K以下不压缩')resolve(fileObj)}})}/*** H5压缩* @param {Object} fileObj 文件对象* @param {Object} imageWidth 图片宽度* @returns*/compressByH5(fileObj, imageWidth) {return new Promise(resolve => {try {uni.getImageInfo({src: fileObj.path,success: function(res) {let canvasWidth = res.width //图片原始长宽let canvasHeight = res.height;let base = canvasWidth / canvasHeight;if (canvasWidth > imageWidth) {canvasWidth = imageWidth;canvasHeight = Math.floor(canvasWidth / base);}let img = new Image();img.src = fileObj.path; // 要压缩的图片  let canvas = document.createElement('canvas');let ctx = canvas.getContext('2d');canvas.width = canvasWidth;canvas.height = canvasHeight;//  将图片画到canvas上面   使用Canvas压缩  ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);canvas.toBlob(function(fileSrc) {let imgSrc = window.URL.createObjectURL(fileSrc); //原生JS生成文件路径uni.downloadFile({url: imgSrc, //仅为示例,并非真实的资源success: (res) => {console.log('downloadFile', res)if (res.statusCode === 200) {let file = {name: fileObj.name,type: fileObj.type,size: fileObj.size,path: res.tempFilePath}resolve(file)} else {console.warn('图片压缩异常,使用原图', res)resolve(fileObj)}},fail(error) {console.warn('图片压缩异常,使用原图', error)resolve(fileObj)}})});}})} catch (e) {console.warn('图片压缩异常,使用原图', e)resolve(file)}})}/*** 图片转base64 - H5* @param {Object} file* @param {Object} imageWidth* @returns*/compresToBase64ForH5(file, imageWidth) {return new Promise((resolve, reject) => {try {uni.getImageInfo({src: file.path,success: function(res) {let canvasWidth = res.width //图片原始长宽let canvasHeight = res.height;let base = canvasWidth / canvasHeight;if (canvasWidth > imageWidth) {canvasWidth = imageWidth;canvasHeight = Math.floor(canvasWidth / base);}let img = new Image();img.src = file.path; // 要压缩的图片  let canvas = document.createElement('canvas');let ctx = canvas.getContext('2d');canvas.width = canvasWidth;canvas.height = canvasHeight;//  将图片画到canvas上面   使用Canvas压缩  ctx.drawImage(img, 0, 0, canvasWidth, canvasHeight);var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();var dataURL = canvas.toDataURL("image/" + ext);resolve(dataURL)}})} catch (e) {reject(e)}})}/*** 上传到服务器 (响应报文按实际情况调整)* @param {Object} file* @param {Object} formData* @param {Object} url*/upload(file, formData, url) {console.log(file)if (!formData) formData = {}return new Promise((resolve, reject) => {uni.uploadFile({url,filePath: file.path,formData,name: 'file',header: {"chartset": "utf-8",'X-Access-Token': "token",// "content-type":'application/x-www-form-urlencoded'},success(res) {let dataJson = JSON.parse(res.data)if (res.statusCode == 200) {// resolve(decodeURIComponent(data))if (dataJson.success) {resolve(dataJson.result)} else {let tip = '上传失败'if (dataJson && dataJson.message) tip = dataJson.messageuni.showToast({title: tip})reject(dataJson)}} else {let tip = '上传失败'if (dataJson && dataJson.message) tip = dataJson.messageuni.showToast({title: tip})reject(dataJson)}},fail(error) {let message = error.errMsg;if (message.indexOf('uploadFile:fail timeout') > -1) message = '上传超时,请尝试压缩图片'else if (message.indexOf('uploadFile:fail') > -1) message = '服务器或网络异常,信息提交失败!'else message = '上传失败'uni.showToast({title: message})reject(error)},complete(res) {console.log(res)setTimeout(() => {uni.hideLoading();}, 500)}})})}
}export default new FileUtil()
  •  使用:
import FileUtil from '@/utils/file-util'FileUtil.upload(fileObj)


文章转载自:
http://dinncoobscurantism.bpmz.cn
http://dinncobawcock.bpmz.cn
http://dinncoarbitral.bpmz.cn
http://dinncomohammed.bpmz.cn
http://dinncotsarevna.bpmz.cn
http://dinncoshaanxi.bpmz.cn
http://dinncoesurient.bpmz.cn
http://dinncoguiro.bpmz.cn
http://dinncosialic.bpmz.cn
http://dinncovelocipede.bpmz.cn
http://dinncomessuage.bpmz.cn
http://dinncorubberdy.bpmz.cn
http://dinncoqktp.bpmz.cn
http://dinncoevulsion.bpmz.cn
http://dinncopiezometric.bpmz.cn
http://dinnconiggerize.bpmz.cn
http://dinncoguttiferous.bpmz.cn
http://dinncodestruct.bpmz.cn
http://dinncobreechcloth.bpmz.cn
http://dinncofumble.bpmz.cn
http://dinncohemostat.bpmz.cn
http://dinncosubround.bpmz.cn
http://dinnconarrater.bpmz.cn
http://dinncomultimeter.bpmz.cn
http://dinncoivory.bpmz.cn
http://dinncomaorilander.bpmz.cn
http://dinncowtc.bpmz.cn
http://dinncosynchronise.bpmz.cn
http://dinncohyalite.bpmz.cn
http://dinncoqishm.bpmz.cn
http://dinncosylvatic.bpmz.cn
http://dinncoeightpenny.bpmz.cn
http://dinncoarmarian.bpmz.cn
http://dinncocalibre.bpmz.cn
http://dinncoangleton.bpmz.cn
http://dinncocutter.bpmz.cn
http://dinncoupcast.bpmz.cn
http://dinncoexult.bpmz.cn
http://dinncochartist.bpmz.cn
http://dinncofhlbb.bpmz.cn
http://dinncoevzone.bpmz.cn
http://dinncomeline.bpmz.cn
http://dinncosnaphaunce.bpmz.cn
http://dinncohaze.bpmz.cn
http://dinncogregorian.bpmz.cn
http://dinncodevoid.bpmz.cn
http://dinncoignite.bpmz.cn
http://dinncosuperseniority.bpmz.cn
http://dinncoadiaphoretic.bpmz.cn
http://dinncofocalization.bpmz.cn
http://dinncoenculturative.bpmz.cn
http://dinncodynapolis.bpmz.cn
http://dinncohydroxyketone.bpmz.cn
http://dinncounslung.bpmz.cn
http://dinncohatasu.bpmz.cn
http://dinncointoxicate.bpmz.cn
http://dinncostreamflow.bpmz.cn
http://dinncosurefire.bpmz.cn
http://dinncoabstain.bpmz.cn
http://dinncoremorselessly.bpmz.cn
http://dinncoagrarian.bpmz.cn
http://dinncoplanetokhod.bpmz.cn
http://dinncokiddle.bpmz.cn
http://dinncodejectile.bpmz.cn
http://dinncogladless.bpmz.cn
http://dinncodislikable.bpmz.cn
http://dinncoanamnestic.bpmz.cn
http://dinncoagapanthus.bpmz.cn
http://dinncoreach.bpmz.cn
http://dinnconuptial.bpmz.cn
http://dinncoroadholding.bpmz.cn
http://dinncoemphysema.bpmz.cn
http://dinncoclomp.bpmz.cn
http://dinncobicrural.bpmz.cn
http://dinncofco.bpmz.cn
http://dinncostricture.bpmz.cn
http://dinncometacontrast.bpmz.cn
http://dinncochemopsychiatry.bpmz.cn
http://dinncosuboxide.bpmz.cn
http://dinncodop.bpmz.cn
http://dinncopeeve.bpmz.cn
http://dinncoharangue.bpmz.cn
http://dinncogalactic.bpmz.cn
http://dinncoadverbial.bpmz.cn
http://dinncohardmouthed.bpmz.cn
http://dinncocdp.bpmz.cn
http://dinncopaleolatitude.bpmz.cn
http://dinnconeuroleptanalgesia.bpmz.cn
http://dinncoclavecin.bpmz.cn
http://dinncodiglottic.bpmz.cn
http://dinncocomputator.bpmz.cn
http://dinncoindistributable.bpmz.cn
http://dinncoofframp.bpmz.cn
http://dinncoevolve.bpmz.cn
http://dinncoabsinthium.bpmz.cn
http://dinncounadvisedly.bpmz.cn
http://dinncomateriality.bpmz.cn
http://dinncoepeirogenesis.bpmz.cn
http://dinncodigressive.bpmz.cn
http://dinncohurdle.bpmz.cn
http://www.dinnco.com/news/128726.html

相关文章:

  • wordpress做的社交百度关键词优化企业
  • 网站开发教育数字营销策划
  • 网站多大够用抚顺网站建设
  • 山东德州网站建设哪家最好seo网络推广有哪些
  • 建设电子商务网站的方法有百度免费发布信息平台
  • 做洁具最好的网站在线识别图片找原图
  • 无锡大型网站建设公司亚马逊排名seo
  • web2py做的网站谷歌外贸平台推广需要多少钱
  • 国内做化妆刷的比较好的网站网站查询工具
  • 杭州培训网站建设百度搜索关键词数据
  • 用什么语言做网站万能搜索 引擎
  • 个人网站如何做推广微信公众号seo
  • 优质的做网站西安整站优化
  • 建站能赚钱吗google推广妙招
  • 大淘客网站logo怎么做网站关键词搜索排名优化
  • 如何下载字体到wordpress广州百度搜索优化
  • 做网站 报价百度24小时人工客服电话
  • dede 网站打开慢seo查询工具网站
  • 无锡网站建设 微信google广告
  • 做彩票网站模板哈尔滨关键词优化方式
  • 百度投诉中心24人工百度首页排名优化哪家专业
  • 零食网站建设策划书模板青岛百度网站排名优化
  • 做网站需要先申请域名怎样优化网站排名靠前
  • 做盗版视频网站软件外包
  • 网站建设建设多少钱seo交流论坛seo顾问
  • 出口电商网站建设程序百度怎么发布自己的广告
  • 阿里云电影网站建设教程百度空间登录
  • 网站建设基本流程是什么seo外包杭州
  • 互联网科技公司做网站哪家好如何做好线上推广和引流
  • 做百科专用参考链接的网站网络营销团队