我看了看确实好像时spread对象是同一个,但是我是使用路由跳转的,应该没错进入组件都重新初- async mounted() {
- if (!this.designer) {
- let config = this.initRibbon();
- let designer = new GC.Spread.Sheets.Designer.Designer(
- document.getElementById("designer-content"),
- config
- );
- this.designerInitialized(designer);
- }
- this.initRegObj();
- this.initRule();
- console.log(this.regObj);
- // 加载编辑数据
- console.log(this.$route);
- console.log(this.$route.query);
- console.log(this.$route.query.type);
- const { type, reportId } = this.$route.query;
- if (type == "edit" && reportId) {
- let styleRes = {};
- // 字段数据
- let strRes = {
- $schema: "http://json-schema.org/draft-04/schema#",
- properties: {
- name: { dataFieldType: "text", type: "string" },
- age: { dataFieldType: "text", type: "string" },
- height: { dataFieldType: "text", type: "string" },
- sex: { dataFieldType: "text", type: "string" },
- },
- type: "object",
- };
- //获取报表样式与源数据
- let {
- data: {
- data: { reportStyle, dictionaryList },
- },
- status,
- } = await seGetReportAllData(reportId);
- if (status === 200) {
- //需要替换数据
- reportStyle ? (styleRes = JSON.parse(reportStyle.reportJson)) : "";
- let properties = {};
- dictionaryList.forEach((item) => {
- properties[item.name] = {
- dataFieldType: item.dataFieldType,
- type: item.type,
- id: item.id,
- properties: item.extra ? JSON.parse(item.extra) : null,
- };
- });
- strRes.properties = properties;
- }
- this.curSource = dictionaryList;
- this.initDesigner(styleRes, strRes);
- }
- this.isLoading = false;
- this.listenCellEvent();
- },
- designerInitialized: function (designer) {
- this.designer = designer;
- this.spread = designer.getWorkbook();
- let config = GC.Spread.Sheets.Designer.DefaultConfig;
- let json = this.spread.toJSON();
- console.log("json", json);
- // 添加自定义tab
- designer.bind(
- GC.Spread.Sheets.Designer.Events.FileLoaded,
- (event, data) => {
- this.spread = designer.getWorkbook();
- this.listenCellEvent();
- console.log("spread", this.spread);
- }
- );
- this.config = config;
- this.spread.options.newTabVisible = true;
- this.spread.options.tabNavigationVisible = false;
- this.spread.options.scrollbarMaxAlign = true;
- this.spread.options.isProtected = true;
- this.spread.invalidateLayout();
- this.spread.repaint();
- this.initSpreadSheet();
- this.initRibbon(config);
- // console.log("calculate",this.spread.options.calcOnDemand)
- },
- //保存的获取toJson
- var spread1 = this.spread;
- this.jsonStr = JSON.stringify(spread1.toJSON());
复制代码 始化,我把组件贴出来,可以帮忙看看吗 |