我们需要是通过第一张图里的按钮打开第二张图弹窗,里面的spreadjs模版是通过接口拿到的,每个按钮点击出来的模版不一样,点击多个后出现了内存溢出,比较急
附上一段代码 大神们帮看下:
<template>
<div :style="{'height':domH+'px'}">
<div ref="spread" v-loading="loading" class="ss" id="tss" :style="{'height':domH-20+'px'}"></div>
<div id="s-foot" style="height:20px"></div>
</div>
</template>
<script>
import request from '@/utils/request'
import mixin from '../mixins'
import sheetKeys from '@/utils/licensen.js'
export default {
name:"templateS2",
mixins:[mixin],
props:{
params:{
type:Object,
default)=>{}
},
args:{
type:Array,
default)=>[]
},
h:{
type:[String,Number],
default:"700"
}
},
data() {
return {
SPREAD:null,
loading:false,
domH:'',
paramStr:''
}
},
watch:{
params:{
handler(v) {
this.inits()
},
deep:true,
immediate:true
}
},
created() {
},
mounted() {
let dh=document.documentElement.clientHeight||document.body.clientHeight;
let buildReact=this.$refs.spread.getBoundingClientRect();
let domH=Math.min(this.h,dh-buildReact.top);
let statusBar = new GC.Spread.Sheets.StatusBar.StatusBar(document.getElementById('s-foot'));
// 授权信息
GC.Spread.Sheets.LicenseKey = sheetKeys.sheetKey;
this.domH=domH;
this.SPREAD=this.SPREAD ? this.SPREAD : this.init('tss').Workbook;
statusBar.bind(this.SPREAD);
},
beforeDestroy() {
this.SPREAD && this.SPREAD.destroy();
this.SPREAD=null;
},
methods:{
inits() {
let _this=this;
let param=this.params;
var activeSheetChanged = GC.Spread.Sheets.Events.ActiveSheetChanged;
if(!param.url) return;
this.loading=true;
request({
url: `${param.url}`,
method: 'post',
data: param.data
}).then(res => {
this.loading=false;
if(!res) return;
let argsArrs=[];
let arrObj=res.data;
let objs={};
let keyObj=Object.keys(arrObj).filter(k=>!['initDataJson','jsonData','notShow'].includes(k));
let json=JSON.parse(arrObj.jsonData);
let initDataJson=arrObj.initDataJson||'';
let args=arrObj.notShow?arrObj.notShow:[];
let SPREAD=_this.SPREAD;
argsArrs=args.concat(_this.args);
if(keyObj.length>0){
keyObj.forEach(i=>{
objs=arrObj
})
this.$store.dispatch('task/setObj',objs)
}
SPREAD.suspendPaint();
SPREAD.fromJSON(json);
json=null;
SPREAD.options.allowContextMenu = false;
SPREAD.options.highlightInvalidData=false;
let sheetslen=SPREAD.getSheetCount();
// //需要隐藏的sheet
if(argsArrs.length>0){
for(let i=0; i<sheetslen;i++){
let name=SPREAD.getSheet(i).name();
argsArrs.includes(name) && SPREAD.sheets.visible(false)
}
}
// 渲染数据源
if(!!initDataJson){
for(let i=0; i<sheetslen;i++){
let curSheet=SPREAD.getSheet(i);
let name=curSheet.name().replace(/^\d*\.?\d*/,'');
let dataJson=JSON.parse(initDataJson);
let da=dataJson[name]?dataJson[name]:null;
if(!!da){
let nDa={[name]:da}
let dataSource = new GC.Spread.Sheets.Bindings.CellBindingSource(nDa);
curSheet.setDataSource(dataSource);
}
}
}
SPREAD.resumePaint();
_this.$emit('sChange',initDataJson);
SPREAD.bind(activeSheetChanged, function(e,args) { // spread event
_this.$emit('sChange',initDataJson)
});
}).catch(err=>{
this.loading=false;
})
},
}
}
</script>
<style lang="scss" scoped>
</style>
|
|