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

中国建筑工程网校有必要买优化大师会员吗

中国建筑工程网校,有必要买优化大师会员吗,小程序外包,成都网站制作028net原先下载方式,PC管理端和浏览器打开文件能下载,xls没出现乱码,pdf能正常显示,H5下载xls乱码锟斤拷,PDF显示空白内容 怀疑是前端问题,也尝试过修改后端代码 后端设置编码格式 response.setCharacterEncoding(characte…

原先下载方式,PC管理端和浏览器打开文件能下载,xls没出现乱码,pdf能正常显示,H5下载xls乱码锟斤拷,PDF显示空白内容

怀疑是前端问题,也尝试过修改后端代码
后端设置编码格式

  1. response.setCharacterEncoding(characterEncoding),前端用Blob接受,xls文件会打不开。
  2. 怀疑文件读编码格式有问题,锟斤拷 出现原因是GBK->UTF-8->GBK导致的,设置后端读取文件的编码格式 ,也没有效果。

前端设置编码格式,查看h5下载代码,怀疑是blob转换导致的

  1. 在new Blob 时指定文件类型和编码格式,还是不能解决。
原先代码
// 通用下载方法
export function download(url, params, method) {return tools.http(url, params, {method: !method ? 'GET' : method,responseType: 'blob'}).then(async (res) => {const isLogin = await blobValidate(res.data);if (isLogin) {let fileName = '';let fileType = '';if (res.header['download-filename']) {fileName = res.header['download-filename']fileType = res.header['download-content-type']} else {// showFailToast(message || errorCode[httpStatus] || errorCode['default']);uni.showToast({icon: 'error',title: message || errorCode[httpStatus] || errorCode['default']})// closeToast();return;}const blob = new Blob([res.data], {type: fileType});if (typeof window.navigator.msSaveBlob !== 'undefined') {// 兼容IE,window.navigator.msSaveBlob:以本地方式保存文件window.navigator.msSaveBlob(blob, decodeURI(fileName));} else {let url = window.URL.createObjectURL(blob);let link = document.createElement('a');link.style.display = 'none';link.href = url;link.setAttribute('download', decodeURI(fileName));document.body.appendChild(link);link.click();document.body.removeChild(link);// 释放blob URL地址window.URL.revokeObjectURL(url);}// closeToast();} else {// closeToast();const resText = await res.data.text();const rspObj = JSON.parse(resText);const errMsg = rspObj.message || errorCode[rspObj.httpStatus] || errorCode['default'];// showFailToast(errMsg);uni.showToast({icon: 'error',title: errMsg})}}).catch((r) => {// closeToast();console.log(r)uni.showToast({icon: 'error',title: '文件出现错误,请联系管理员!'})})
}
解决方案

看到若依框架有个工具类,在uni-app安装,完美解决问题,还是要多接触代码,站在大佬的肩膀上,看看人家处理blob源码

  // prepend BOM for UTF-8 XML and text/* types (including HTML)// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BFif (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {return new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type })}return blob

FileSaver

npm install file-saver --save
import { saveAs } from 'file-saver';
export function downloadBySaveAs(url, fileName) {saveAs(url,fileName)
}
http://www.hengruixuexiao.com/news/16458.html

相关文章:

  • 企业营销型网站建设哪家好北大青鸟
  • 做网站傻瓜西安seo教程
  • 电子商务网站的设计要求长沙公司网络营销推广
  • 网站做测试郑州千锋教育培训机构怎么样
  • 如何建立自己的网站去推广网络营销是什么工作主要干啥
  • 阿里云虚拟主机多网站北京网聘咨询有限公司
  • 西安企业网站建站企业培训课程表
  • 一个不懂技术的人如何做网站seo关键词布局
  • 学做网站论坛会员免费推广seo
  • 云存储能用来做网站吗ui培训
  • wordpress 洛神的主题广州市口碑seo推广外包
  • wordpress仿站工具搜索引擎营销方案例子
  • 仿今日头条wordpress模板百度搜索优化怎么做
  • 合肥php网站开发曲靖seo
  • wordpress安装空白页快手seo关键词优化
  • 龙岗优化网站建设磁力蜘蛛
  • 外贸批发网站建设北京百度推广公司
  • 国外网站流量发软文是什么意思
  • 学校统一发的银行卡怎么激活360优化大师旧版本
  • 怎么做钓鱼网站盗取qq色盲测试图数字
  • 网站空间在哪里买中国国际新闻
  • 网站怎么去优化成人培训机构
  • 做网站 流量怎么抓钱关键词是什么
  • 建设地区网站建议建网站软件工具
  • 如何做网站运营呢谷歌seo网站运营
  • wordpress author 404株洲百度seo
  • 淄博晨曦网站建设网址域名
  • 做网站 客户一直要求改百度热搜榜排名今日
  • wordpress视频下载太仓seo网站优化软件
  • 怎么做网站在谷歌竞价推广账户竞价托管