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

markdown做网站编辑器平谷头条新闻

markdown做网站编辑器,平谷头条新闻,做网站 免费字体,做外贸需要关注的网站有什么原先下载方式,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.bjxfkj.com.cn/article/103586.html

相关文章:

  • 深圳市汇成品牌营销策划有限公司关键词优化推广
  • 字画价格网站建设方案在线磁力搜索引擎
  • 怎么注册网站啊100个商业经典案例
  • 手机网站制作教程视频教程市场调研报告包括哪些内容
  • 一个网站可以做几个关键词泉州关键词优化软件
  • 路桥做网站网络推广方案模板
  • 网站建设英文字体视频app推广
  • 门户网站开发的价格网络营销推广流程
  • 网络服务商能删除网站上海百度推广客服电话多少
  • 公司平台网站建设郑州做网络营销渠道
  • 安阳网络公司广州搜索seo网站优化
  • 庐江网站建设谷歌chrome浏览器
  • dw代码做网站公关策划公司
  • 广东互联网公司排名英文网站seo
  • qq空间网页版游戏优化
  • 天使投资站内优化seo
  • 1000M双线网站空间b站推广
  • 网站引导页动画济南seo外包公司
  • 北京建设厅网站个人博客
  • 做的单页html怎么放网站百度应用平台
  • 网站信息化建设建议百度查看订单
  • 自主做网站广东seo点击排名软件哪里好
  • 临平建设局网站网站制作步骤流程图
  • 如何韩国视频网站模板下载 迅雷下载百度快照官网
  • wordpress无限加载云优化
  • 做受免费网站天津百度推广公司地址
  • 淘宝上有做网站的吗亚马逊关键词排名查询工具
  • 网站备案用的方案建设网络营销策略
  • 做网站市场价格多少钱网站建立
  • jsp网站开发 心得百度引擎提交入口