工具类解压和压缩:
import pako from 'pako';
// 解压
export function ungzip(str) {
let reportStr = str;
try {
reportStr = pako.ungzip(str, {to: 'string'});
} catch (err) {
console.log(`------${err}`);
}
return reportStr;
}
// 压缩
export function gzip(str) {
let reportStr = str;
try {
reportStr = pako.gzip(str, { to: 'string'});
} catch (err) {
console.log(`------${err}`);
}
return reportStr;
}
把后台传过来的数据解压:
import { ungzip } from "../../../utils/GZipUtil"
// sms后台传过来的数据
let mxadata = [];
let arrStr = '';
sms ? arrStr = (ungzip (sms.mxadata)):'';
if(arrStr) {
mxadata = eval(arrStr);
}
if(mxadata) {
for (let i = 0; i < mxadata.length; i += 1) {
mxadata[i] = Object.assign({}, mxadata[i]);
}
}
OK!