React
-
介绍一下react
-
React单项数据流
-
react生命周期函数和react组件的生命周期
-
react和Vue的原理,区别,亮点,作用
-
reactJs的组件交流
-
有了解过react的虚拟DOM吗,虚拟DOM是怎么对比的呢
-
项目里用到了react,为什么要选择react,react有哪些好处
-
怎么获取真正的dom
-
选择react的原因
-
react的生命周期函数
-
setState之后的流程
-
react高阶组件知道吗?
-
React的jsx,函数式编程
-
react的组件是通过什么去判断是否刷新的
-
如何配置React-Router
-
路由的动态加载模块
-
Redux中间件是什么东西,接受几个参数
-
redux请求中间件如何处理并发
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】
// ... 此处省略数据查询条件...
// 查询数据
List<ProQrcode> list = service.list(queryWrapper);
int width = 800;
if (StringUtils.isNotBlank(widthStr)) {
width = Integer.parseInt(widthStr);
}
byte[] data = genQrcodeImg(list, width);
zip(response, data);
}
/\*\*
* 批量生产图片zip压缩包数据
* */
private byte[] genQrcodeImg(List list, int width) {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream)) {
for (int i = 0; i < list.size(); i++) {
ProQrcode qrcode = list.get(i);
try {
// 添加到zip,设置文件名,后缀.png
zip.putNextEntry(new ZipEntry(String.format("%d.%s.png", i + 1, qrcode.getCode())));
// 查询是否配置了logo,如果有logo,则把logo添加到二维码中
BufferedImage logo = CustomerBrandCache.getLogo(qrcode.getCustomerBrandId());
QrConfig config = new QrConfig();
config.setWidth(width).setHeight(width);
if (logo != null) {
config.setImg(logo);
}
// 生成二维码图片
byte[] bytes = QrCodeUtil.generatePng(qrcode.getLinkUrl(), config);
// 将byte[]写入到压缩包中
IOUtils.write(bytes, zip);
zip.flush();
zip.closeEntry();
} catch (IOException e) {
log.error("addQrcode,error:", e);
}
}
return outputStream.toByteArray();
} catch (Exception e) {
log.error("", e);
}
return new byte[0];
}
/\*\*
* 生成zip文件,设置响应头为文件下载
*/
private void zip(HttpServletResponse response, byte[] data) throws IOException {
response.reset();
response.addHeader(“Access-Control-Allow-Origin”, “*”);
response.addHeader(“Access-Control-Expose-Headers”, “Content-Disposition”);
response.setHeader(“Content-Disposition”, “attachment; filename=“qrcode.zip””);
response.addHeader(“Content-Length”, “” + data.length);
response.setContentType(“application/octet-stream; charset=UTF-8”);
IOUtils.write(data, response.getOutputStream());
}
>
> * 通过`cn.hutool.extra.qrcode.QrCodeUtil`生成二维码图片,得到`byte[]`
> * 通过`java.util.zip.ZipOutputStream`将`byte[]`写入压缩包
> * 通过`java.io.ByteArrayOutputStream`返回完整的`byte[]`
> * 全部写入完成后,得到完整的`byte[]`输出到`HttpServletResponse`
> * 设置`HttpServletResponse`响应头数据,标记为文件下载
>
>
>
### 二、Vue前端调用后端接口实现下载
/**
* 导出二维码数据
*/
export const exportQrcode = async (name, params) => {
const data = await defHttp.get({ url: Api.exportQrcode, params, responseType: ‘blob’, timeout: 30000 }, { isTransformResponse: false })
if (!data) {
createMessage.warning(‘文件下载失败’)
return
}
if (!name || typeof name != ‘string’) {
name = ‘导出文件’
}
const blobOptions = { type: ‘application/octet-stream’ }
const fileSuffix = ‘.zip’
debugger
if (typeof window.navigator.msSaveBlob !== ‘undefined’) {
window.navigator.msSaveBlob(new Blob([data], blobOptions), name + fileSuffix)
} else {
const url = window.URL.createObjectURL(new Blob([data], blobOptions))
const link = document.createElement(‘a’)
link.style.display = ‘none’
link.href = url
React
-
介绍一下react
-
React单项数据流
-
react生命周期函数和react组件的生命周期
-
react和Vue的原理,区别,亮点,作用
-
reactJs的组件交流
-
有了解过react的虚拟DOM吗,虚拟DOM是怎么对比的呢
-
项目里用到了react,为什么要选择react,react有哪些好处
-
怎么获取真正的dom
-
选择react的原因
-
react的生命周期函数
-
setState之后的流程
-
react高阶组件知道吗?
-
React的jsx,函数式编程
-
react的组件是通过什么去判断是否刷新的
-
如何配置React-Router
-
路由的动态加载模块
-
Redux中间件是什么东西,接受几个参数
-
redux请求中间件如何处理并发
开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】