- <script>
- import GC from "@grapecity/spread-sheets";
- import {
- seGetReportAllData,
- seReportPublishing,
- seGetRegularList,
- seSaveReportSourceData,
- seAddRegularItem,
- seSaveReportStyleData,
- getReportDataSource,
- } from "@/api/se-report-design";
- import dataConnectDia from "./se-report-compoment/dataConnectDia.vue";
- import localReRule from "@/utils/local-re-rule.js";
- import { checkRules, regRules } from "./ruleConfig.js";
- import { VerificationRules, MultipleChoiceVerification } from "./config";
- import { permissionVerification } from "@/utils/se-permission-verification";
- import { seGetSystemDictionary } from "@/api/se-admin/se-admin-data-manage/se-admin-dictionary.js";
- import dialogCom from "./compoment/dialogCom.vue"
- import axios from "axios";
- GC.Spread.Common.CultureManager.culture("zh-cn");
- this.GC = GC;
- let _this;
- export default {
- components: { dataConnectDia,dialogCom },
- name: "CreatReport",
- data() {
- return {
- test:"11111",
- styleInfo: { height: "800px", width: "100%", border: "solid black 1px" },
- config: null,
- designer: null,
- dataTable: null,
- spread: null,
- sheets: null,
- designerBindingPathSchema: null,
- jsonStr: null,
- // 配置
- import_bindingSource: true,
- import_noFormula: false,
- import_noStyle: false,
- import_rowHeaders: false,
- import_columnHeaders: false,
- import_donotrecalculateafterload: false,
- noFormula: false,
- noStyle: false,
- SaveCustomRowHeaders: false,
- SaveCustomColumnHeaders: false,
- // 设计器编辑配置
- designer2: null,
- dataTable2: null,
- spread2: null,
- //自定义函数
- customFunctions: {},
- //当前数据源配置
- curSource: {},
- //loading状态更新
- isLoading: true,
- //审核点输入文字
- auditpoints: "",
- //填报要求文字
- wordRequest: "",
- curCellRow: "",
- curCellCol: "",
- sendRegOption: [],
- dialogVisible: false,
- regObj: {
- 995: {
- name: "数字",
- des: "数字",
- re: /^(\-|\+)?\d+(\.\d+)?$/,
- },
- 110000: {
- name: "最少9个",
- des: "最少9个选择",
- max: 11,
- },
- },
- isRequire: false, // 是否必填
- regStatus: "选择", // 用于显示校验规则的状态
- regOption: [], // 用于显示校验规则的选项列表
- regDataObj: {
- input: "",
- name: "",
- des: "",
- select: "995",
- },
- // 用于输入正则校验规则的输入框的值
- curCellReg: "",
- //弹出框校验模式
- diaMode: "reg", // reg正则 checkBox多选校验
- checkOption: [], // 用于显示校验规则的选项列表
- checkDataObj: {
- min: "",
- max: "",
- name: "",
- des: "",
- select: "110000",
- }, // 用于输入正则校验规则的输入框的值
- //数据关联dia控制
- dialogDataConnect: false,
- //多选数据关联其他
- multipleDataConnect: [],
- //多选框添加的校验规则
- checkRules: checkRules,
- //正则添加的校验规则
- regRule: regRules,
- //动态尺寸
- timer: false,
- screenWidth: document.body.clientWidth,
- permissionVerification: permissionVerification,
- getAllUsedDataSourceArr: [],
- reWriteDia: false,
- reWriteSelect: "",
- openInitPassDia: false,
- lostBinging: [],
- // 回填数据选择列表
- backWriteList: [],
- sourceList: [], //数据源列表
- selectSourceView: "", //当前选择的数据源
- sourceLocation: false, //当前查看数据源绑定对应单元格弹窗
- sourceLocationList: [], //数据源绑定对应单元格列表
- useSource: {}, // 存储当前数据源绑定的单元格
- useDialog: false, //是否弹出框
- showList: [], //当前数据源绑定的单元格列表
- };
- },
- created() {
- console.log(this.$route);
- _this = this;
- },
- async mounted() {
- window.addEventListener("resize", () => {
- this.screenWidth = document.body.clientWidth;
- });
- _this.config = this.initRibbon();
- let designer = new GC.Spread.Sheets.Designer.Designer(
- document.getElementById("designer-content"),
- _this.config
- );
- this.designerInitialized(designer);
- // if (!this.designer) {
-
- // }
- // 加载编辑数据
- const { type, reportId } = this.$route.query;
- if (type == "edit" && reportId) {
- let styleRes = {};
- // 字典数据
- let strRes = {
- $schema: "http://json-schema.org/draft-04/schema#",
- properties: {},
- type: "object",
- };
- //获取字典数据
- let data = null;
- if (this.$route.query.template) {
- let res = await seGetSystemDictionary({
- prefix: true,
- });
- data = res.data.data;
- } else {
- let res = await getReportDataSource(this.$route.query.projectId);
- data = res.data.data;
- }
- // 固定的回填字段
- this.backWriteList.push({
- label: "社会统一编码",
- value: "socialCode",
- });
- this.backWriteList.push({
- label: "企业名称",
- value: "businessName",
- });
- //获取报表样式与源数据
- let {
- data: {
- data: { reportStyle, customDataFields },
- },
- status,
- } = await seGetReportAllData(reportId);
- if (status === 200) {
- if (customDataFields) {
- // 获取回填字段列表
- customDataFields.forEach((item) => {
- this.backWriteList.push({
- label: item.cnName,
- value: item.id,
- });
- });
- }
- if (reportStyle) {
- //请求线上的数据,暂定是使用axios请求传来的url uploadType 0 代表本地 1 代表 阿里云 2 代表 天翼云
- if (reportStyle.uploadType != 0 && reportStyle.filePath) {
- await new Promise((resolve, reject) => {
- axios.get(reportStyle.filePath).then((res) => {
- if (res.status == 200) {
- styleRes = res.data;
- resolve(res.data);
- } else {
- resolve("error");
- }
- });
- });
- } else if (reportStyle.uploadType == 0 && reportStyle.reportJson) {
- styleRes = JSON.parse(reportStyle.reportJson); //读取线下资源
- }
- }
- let properties = {};
- data.forEach((item) => {
- if (item.dataFieldType !== "table") {
- properties[item.name] = {
- dataFieldType: item.dataFieldType,
- type: item.type,
- id: item.id,
- properties: item.extra ? JSON.parse(item.extra) : null,
- };
- } else {
- properties[item.name] = {
- dataFieldType: item.dataFieldType,
- type: item.type,
- id: item.id,
- items: item.extra ? JSON.parse(item.extra) : null,
- };
- }
- });
- strRes.properties = properties;
- _this.curSource = properties;
- }
- this.initDesigner(styleRes, strRes);
- }
- this.isLoading = false;
- this.listenCellEvent();
- this.curCellCol = this.getActiveSheet().getSelections()[0].col;
- this.curCellRow = this.getActiveSheet().getSelections()[0].row;
- let curSourceList = JSON.parse(
- _this.designer.getData("updatedTreeNode") ||
- _this.designer.getData("oldTreeNodeFromJson")
- ).properties;
- this.sourceList = Object.keys(curSourceList).map((i) => ({
- label: i,
- value: i,
- }));
- this.useDialog = true
- },
- beforeDestroy(){
-
-
- this.designer = null
- console.log(this.designer,'------>');
- },
- methods: {
- //获取spread 创建设计器实例
- designerInitialized: function (designer) {
- this.designer = designer;
- designer.bind(
- GC.Spread.Sheets.Designer.Events.FileLoaded,
- (event, data) => {
- this.spread = designer.getWorkbook();
- this.listenCellEvent();
- }
- );
- this.spread = designer.getWorkbook();
- let json = this.spread.toJSON();
- this.spread.options.newTabVisible = true;
- this.spread.options.tabNavigationVisible = false;
- this.spread.options.scrollbarMaxAlign = true;
- this.spread.invalidateLayout();
- this.spread.repaint();
- this.initSpreadSheet();
- this.getRegObj();
- },
- //初始化自定义Tab
- initRibbon() {
- _this.config = GC.Spread.Sheets.Designer.DefaultConfig;
- let configTab = GC.Spread.Sheets.Designer.DefaultConfig;
- if (configTab.ribbon[0].buttonGroups[7]) {
- let editFirstElement =
- configTab.ribbon[0].buttonGroups[7].commandGroup.children[0]
- .children[2];
- let edit = configTab.ribbon[0].buttonGroups[7];
- edit.commandGroup = editFirstElement;
- _this.config.ribbon[4].buttonGroups.push(edit);
- }
- // add new tab
- let newTab = {
- id: "operate",
- text: "自定义",
- buttonGroups: [],
- };
- if (
- Array.isArray(_this.config && _this.config.ribbon) &&
- !_this.config.ribbon.filter((d) => d && d.text === "自定义").length
- ) {
- _this.config.ribbon.unshift(newTab);
- let dataSaveInfo = {};
- if (
- localStorage.getItem("se_oss_authority") &&
- JSON.parse(localStorage.getItem("se_oss_authority")).indexOf(
- "MY_REPORT_SUBMIT"
- ) !== -1
- ) {
- dataSaveInfo.release = {
- iconClass: "ribbon-button-save", //按钮的样式
- text: "发布", //显示的文字
- bigButton: true,
- commandName: "reportRelease", //命令名称,需要全局唯一
- execute: this.reportRelease, //对应执行内容的function
- };
- }
- //创建按钮
- dataSaveInfo = Object.assign(dataSaveInfo, {
- exit: {
- iconClass: "ribbon-button-save", //按钮的样式
- text: "退出",
- bigButton: true,
- commandName: "exitReport",
- execute: this.exitReport,
- },
- saveTemplateCommand: {
- iconClass: "ribbon-button-save", //按钮的样式
- text: "保存", //显示的文字
- bigButton: true,
- commandName: "saveDatas", //命令名称,需要全局唯一
- execute: this.saveInfos, //对应执行内容的function
- },
- relateMutCheck: {
- iconClass: "ribbon-button-save", //按钮的样式
- text: "多选其他关联",
- bigButton: true,
- commandName: "relateMutCheck",
- execute: this.relateMutCheck,
- },
- reWrite: {
- iconClass: "ribbon-button-save", //按钮的样式
- text: "自动回填", //显示的文字
- bigButton: true,
- commandName: "reWriteBtn", //命令名称,需要全局唯一
- execute: this.reWriteBtn, //对应执行内容的function
- },
- overReWrite: {
- iconClass: "ribbon-button-save", //按钮的样式
- text: "取消自动回填", //显示的文字
- bigButton: true,
- commandName: "overReWriteBtn", //命令名称,需要全局唯一
- execute: this.overReWriteBtn, //对应执行内容的function
- },
- childrenDropdown: {
- commandName: "childrenDropdown",
- text: "校验规则",
- title: "Children",
- iconClass: "ribbon-button-welcome",
- bigButton: "true",
- // direction: "vertical",
- },
- childrenDropdown2: {
- title: "设置正则",
- text: "设置正则",
- iconClass: "ribbon-button-welcome",
- commandName: "childrenDropdown2",
- execute: function (context, propertyName, fontItalicChecked) {
- _this.diaMode = "reg";
- _this.dialogVisible = true;
- // let spread = context.Spread; //获取工作簿
- // let activeCell = _this.getCell(); //获取激活单元格
- // let sheet = _this.getActiveSheet(); //获取工作表
- // let style = new GC.Spread.Sheets.Style();
- // style.locked = false;
- // style.backColor = "#C3C3C3";
- // sheet.setStyle(activeCell.row, activeCell.col, style);
- },
- },
- ruleSource: {
- title: "多选框校验",
- text: "多选框校验",
- iconClass: "ruleSource",
- commandName: "ruleSource",
- execute: this.ruleSources,
- },
- resetDataSourceList: {
- title: "清除所选数据",
- text: "清除所选数据",
- iconClass: "resetDataSourceList",
- commandName: "resetDataSourceList",
- execute: this.resetDSList,
- },
- });
- //将图标放入工具栏
- if (
- !_this.config.ribbon[0].buttonGroups[0] ||
- (!(_this.config.ribbon[0].buttonGroups[0].label === "保存设计") &&
- !_this.config.ribbon[0].buttonGroups.filter(
- (d) => d.label === "保存设计"
- ).length)
- ) {
- _this.config.ribbon[0].buttonGroups.unshift({
- label: "常用操作",
- thumbnailClass: "ribbon-thumbnail-spreadsettings",
- commandGroup: {
- children: [
- {
- direction: "vertical",
- commands: ["saveTemplateCommand"],
- },
- {
- type: "separator",
- },
- {
- direction: "vertical",
- commands: ["release"],
- },
- {
- type: "separator",
- },
- {
- direction: "vertical",
- commands: ["exit"],
- },
- {
- type: "separator",
- },
- {
- direction: "vertical",
- commands: ["relateMutCheck"],
- },
- {
- type: "separator",
- },
- {
- direction: "vertical",
- commands: ["reWrite"],
- },
- {
- type: "separator",
- },
- {
- direction: "vertical",
- commands: ["overReWrite"],
- },
- {
- type: "separator",
- },
- {
- command: "childrenDropdown", //父命令可以有自己的execute,点击执行;也可以没有,点击弹出children
- type: "dropdown",
- children: [
- // "childrenDropdown1",
- "childrenDropdown2",
- "ruleSource",
- // "resetDataSourceList",
- ],
- },
- {
- type: "separator",
- },
- ],
- },
- });
- }
- _this.config.commandMap = {};
- Object.assign(_this.config.commandMap, dataSaveInfo);
- }
- return _this.config;
- },
- // 初始化校验规则
- initRule() {
- VerificationRules.prototype =
- new GC.Spread.CalcEngine.Functions.Function();
- VerificationRules.prototype.evaluate = function (arg, type) {
- // 自定义正则校验
- if (arguments.length === 2 && !isNaN(type)) {
- return _this.regObj[type].re.test(arg);
- }
- return "#VALUE!";
- };
- _this.customFunctions.VerificationRules = VerificationRules;
- MultipleChoiceVerification.prototype =
- new GC.Spread.CalcEngine.Functions.Function();
- MultipleChoiceVerification.prototype.evaluate = function (arg, type) {
- // 多选题数量校验
- if (arguments.length === 2 && !isNaN(type)) {
- let { min = 0, max = 100 } = _this.regObj[type];
- return min < arg.length && arg.length < max;
- }
- return "#VALUE!";
- };
- _this.customFunctions.MultipleChoiceVerification =
- MultipleChoiceVerification;
- },
- //初始化报表表格
- initSpreadSheet() {
- for (let i = 0; i < this.spread.getSheetCount(); i++) {
- let sheet = this.spread.getSheet(i);
- var len = sheet.tables.all().length;
- var tmp = {};
- for (var i = 0; i < len; i++) {
- var bp = sheet.tables.all()[i].bindingPath();
- tmp[bp] = [{}];
- }
- }
- this.spread.resumePaint();
- },
- //初始化正则对象
- initRegObj() {
- this.regOption = [];
- this.checkOption = [];
- if (!this.regObj) return;
- Object.keys(this.regObj).forEach((key) => {
- if (key <= 100000) {
- this.regOption.push({
- code: key,
- name: this.regObj[key].name || null,
- des: this.regObj[key].des || null,
- re: this.regObj[key].re || null,
- });
- this.sendRegOption.push({
- code: key,
- name: this.regObj[key].name || null,
- des: this.regObj[key].des || null,
- re: String(this.regObj[key].re) || null,
- });
- } else if (key <= 200000) {
- this.checkOption.push({
- code: key,
- name: this.regObj[key].name || null,
- des: this.regObj[key].des || null,
- min: this.regObj[key].min || null,
- max: this.regObj[key].max || null,
- });
- this.sendRegOption.push({
- code: key,
- name: this.regObj[key].name || null,
- des: this.regObj[key].des || null,
- min: this.regObj[key].min || null,
- max: this.regObj[key].max || null,
- });
- }
- });
- if (!this.regOption[0]) {
- this.regOption.push({
- code: "995",
- name: "无校验规则",
- des: "无校验规则",
- re: null,
- });
- }
- if (!this.checkOption[0]) {
- this.checkOption.push({
- code: "110000",
- name: "空",
- des: "空",
- });
- }
- console.log(this.regOption[0]);
- this.regDataObj.select = this.regOption[0]
- ? this.regOption[0].code
- : null;
- this.checkDataObj.select = this.checkOption[0]
- ? this.checkOption[0].code
- : null;
- },
- //保存时检测哪些数据源被使用
- getAllUsedDataSource(json) {
- this.getAllUsedDataSourceArr = [];
- let ToJSON = json;
- for (let i = 0; i < this.spread.getSheetCount(); i++) {
- let sheet = this.spread.getSheet(i);
- let curDataTable = ToJSON.sheets[sheet.name()].data.dataTable;
- let curDataSourceTable = ToJSON.sheets[sheet.name()].tables;
- if (!curDataTable) {
- continue;
- }
- for (let j in curDataTable) {
- if (curDataTable[j]) {
- for (let k in curDataTable[j]) {
- if (curDataTable[j][k].bindingPath) {
- this.getAllUsedDataSourceArr.push(
- curDataTable[j][k].bindingPath
- );
- }
- }
- }
- }
- if (!curDataSourceTable) {
- continue;
- }
- this.getAllUsedDataSourceArr.push(
- ...curDataSourceTable.map((item) => {
- return item.bindingPath;
- })
- );
- }
- this.getAllUsedDataSourceArr = Array.from(
- new Set(this.getAllUsedDataSourceArr)
- );
- },
- // 转换regOption到regObj
- async handleOptionToRegObj(data) {
- this.regObj = localReRule;
- let regObj = {};
- let similar = data.data;
- if (!!similar && similar[0].des != "暂无数据请添加") {
- similar.forEach((item) => {
- regObj[item.code] = {
- ...item,
- reCode: item.code,
- };
- delete regObj[item.code].code;
- });
- this.regObj = regObj;
- } else {
- await seAddRegularItem([...localReRule]);
- this.regObj.forEach((item) => {
- regObj[item.code] = {
- ...item,
- reCode: item.code,
- };
- delete regObj[item.code].code;
- });
- this.regObj = regObj;
- }
- this.regObj[""] = {
- des: "空",
- };
- this.initRegObj();
- this.initRule();
- this.listenSheetChange();
- },
- //获取正则对象
- async getRegObj() {
- let data = [];
- let res = await seGetRegularList({
- pageSize: 999,
- current: 1,
- });
- // let res = {data:{data:[]}} //测试返回数据为是否为空
- data = res.data || { data: [] };
- if (!data.data[0]) {
- this.handleOptionToRegObj({
- data: [
- { code: 995, des: "暂无数据请添加", name: "暂无数据请添加" },
- { code: 110000, des: "暂无数据请添加", name: "暂无数据请添加" },
- ],
- });
- } else {
- this.handleOptionToRegObj(data);
- }
- },
- // 退出报表编辑
- exitReport() {
- // console.log(1,this.designer);
- // this.spread.destroy()
- this.designer.destroy();
- this.designer = null
- console.log(this.designer,'--------<');
-
- this.$router.back();
- },
- // 对比新旧的数据源并且提示用户
- handleDataSource() {
- //如果本身没有数据源,直接通过
- if (
- !_this.designer.getData("updatedTreeNode") &&
- !_this.designer.getData("oldTreeNodeFromJson")
- ) { return true }
-
- let curDesignerBindingPathSchema = JSON.parse(
- _this.designer.getData("updatedTreeNode") ||
- _this.designer.getData("oldTreeNodeFromJson")
- ).properties;
- let recviceSourceKey = Object.keys(_this.curSource);
- let curSourceKey = Object.keys(curDesignerBindingPathSchema);
- let diffrentDir = [];
- recviceSourceKey.forEach((oldKey) => {
- if (curSourceKey.indexOf(oldKey) === -1 && !oldKey.startsWith("@") ) {
- diffrentDir.push(oldKey);
- }
- });
- debugger
- let curBinding = this.handleDataTableReturn();
- Object.keys(this.spread.toJSON().sheets).forEach(sheetName=>{
- if(this.spread.toJSON().sheets[sheetName].tables && Array.isArray(this.spread.toJSON().sheets[sheetName].tables)){
- this.spread.toJSON().sheets[sheetName].tables.forEach(table=>{
- curBinding.push({
- bindingPath:table.bindingPath,
- col: table.col,
- row: table.row,
- sheetName: sheetName
- })
- })
- }
- })
- this.lostBinging = [];
- // let curBinding = this.handleDataTableReturn();
- if (curBinding) {
- curBinding.forEach((item) => {
- if(!item.bindingPath) return
- if (diffrentDir.indexOf(item.bindingPath) > -1) {
- this.lostBinging.push(Object.assign(item,{
- col:Number(item.col) +1,
- row:Number(item.row)+ 1,
- }));
- }
- if(item.bindingPath && item.bindingPath.startsWith("@") && recviceSourceKey.indexOf(item.bindingPath)== -1){
- this.lostBinging.push(Object.assign(item,{
- col:Number(item.col) +1,
- row:Number(item.row)+ 1,
- }));
- }
- if(item.bindingPath && curSourceKey.indexOf(item.bindingPath) == -1 && !item.bindingPath.startsWith("@")){
- this.lostBinging.push(Object.assign(item,{
- col:Number(item.col) +1,
- row:Number(item.row)+ 1,
- }));
- }
- });
- }
- if (this.lostBinging.length > 0) {
- return false;
- }
- return true;
- },
- handleTest(){
- this.handleAllSelectSourceView()
- },
- //保存点击事件,进行信息保存
- saveInfos(type) {
- this.jsonStr = JSON.stringify(_this.getAllSheetsData());
- this.getAllUsedDataSource(JSON.parse(this.jsonStr));
- // if (!this.handleDataSource()) {
- // this.$nextTick(()=>{
- // this.$message.error("该表引用了被删除字典,请修改后再保存");
- // _this.openInitPassDia = true;
- // console.log(this.lostBinging);
-
- // })
- // return;
- // }
- // if (this.getActiveSheetData().data && !this.getActiveSheetData().data.dataTable) {
- // this.$message.error("当前报表内容为空,请添加后再保存");
- // return;
- // }
- // //判断回填是否设置了数据源
- // if (!this.handleAutoFillData()) {
- // this.$message.error("自动回填没有设置数据源");
- // return;
- // }
-
- //判断数据源是否被绑定两次
- if (!this.handleAllSelectSourceView()) {
- // if(typeof type != 'boolean' || !type) {
-
-
- // this.$refs.saveBtn.handleClick(true)
-
- // }
- // console.log(,9999);
-
- // this.$refs.saveBtn.click()
- // this.$message.error("数据源设置了两次");
- // this.test = "6666666"
-
- // alert(this.test)
- debugger
- let _this = this
- _this.useDialog = true;
- // setTimeout(()=>{
-
-
- // },300)
- }
-
- this.saveInfoConfirm();
- },
- // 调用保存的接口
- async saveInfoConfirm() {
-
- _this.designerBindingPathSchema =
- _this.designer.getData("updatedTreeNode") ||
- _this.designer.getData("oldTreeNodeFromJson");
- let submitSource = [];
- let source = JSON.parse(_this.designerBindingPathSchema);
- if (source && source.properties) {
- for (let i in source.properties) {
- let curSourceKeys = Object.keys(_this.curSource);
- let extra;
- if (source.properties[i].dataFieldType !== "table") {
- extra = source.properties[i].properties
- ? source.properties[i].properties
- : curSourceKeys.filter((item) => {
- if (item === i) return;
- })[0]
- ? curSourceKeys.filter((item) => {
- if (item === i) return;
- })[0].properties
- : null;
- } else {
- if (source.properties[i].items) {
- extra = source.properties[i].items;
- } else {
- extra = null;
- }
- }
- let children;
- if (source.properties[i].dataFieldType == "table") {
- if (source.properties[i].items) {
- children = Object.keys(source.properties[i].items.properties);
- }
- } else if (source.properties[i].dataFieldType == "combox") {
- if (source.properties[i].properties) {
- children = Object.keys(source.properties[i].properties);
- }
- }
- let curObj = {
- name: i,
- code: source.properties[i].dataFieldType.toUpperCase(),
- dataFieldType: source.properties[i].dataFieldType,
- type: source.properties[i].type,
- id: curSourceKeys.filter((item) => {
- if (item.name === i) return _this.curSource[item].id;
- })[0]
- ? curSourceKeys.filter((item) => {
- if (item.name === i) return _this.curSource[item].id;
- })[0].id
- : null,
- extra: JSON.stringify(extra),
- children: children,
- };
- submitSource.push(curObj);
- }
- }
- // 保存源数据与样式
- try {
- if (!this.$route.query.template)
- await seSaveReportSourceData(
- submitSource,
- this.$route.query.projectId
- );
- let {
- data: { resultCode },
- } = await seSaveReportStyleData({
- reportId: this.$route.query.reportId,
- reportJson: this.jsonStr,
- boundDictionaries: this.getAllUsedDataSourceArr,
- });
- resultCode !== 400
- ? this.handleMessage("success", "保存报表设计成功")
- : "";
- } catch (e) {
- this.$message.error("保存失败,请稍后重试");
- }
- },
- handleAutoFillData() {
- let isPass = true;
- try{
- for (let i = 0; i < this.spread.getSheetCount(); i++) {
- let sheet = this.spread.getSheet(i);
- let curData = _this.spread.toJSON().sheets[sheet.name()];
- if (curData && curData.data && curData.data.dataTable) {
- let curDataObj = curData.data.dataTable;
- let rowList = Object.keys(curDataObj);
- rowList.forEach((row) => {
- let colList = Object.keys(curDataObj[row]);
- colList.forEach((col) => {
- if (
- curDataObj[row][col].tag &&
- curDataObj[row][col].tag.reWriteType &&
- !curDataObj[row][col].bindingPath
- ) {
- isPass = false;
- }
- });
- });
- }
- }
- } catch(e) {
- console.log(e);
-
- }
- return isPass;
- },
- initDesigner(styleRes, strRes) {
- var jsonOptions = {
- includeBindingSource: true,
- ignoreFormula: this.import_noFormula,
- ignoreStyle: this.import_noStyle,
- frozenColumnsAsRowHeaders: this.import_rowHeaders,
- frozenRowsAsColumnHeaders: this.import_columnHeaders,
- doNotRecalculateAfterLoad: this.import_donotrecalculateafterload,
- };
- this.spread.fromJSON(styleRes, jsonOptions);
- let jsonStrRes =
- typeof strRes == "string" ? strRes : JSON.stringify(strRes);
- // 加载字段源
- this.designer.setData("treeNodeFromJson", jsonStrRes);
- this.designer.setData("oldTreeNodeFromJson", jsonStrRes);
- setTimeout(() => {
- _this.spread.refresh();
- }, 500);
- },
- //查看当前的数据源绑定单元格
- handleSelectSourceView() {
- if (!this.selectSourceView) return;
- let curData = this.handleDataTableReturn();
- this.sourceLocation = true;
- this.sourceLocationList = curData.filter((i) => {
- if (this.selectSourceView == i.bindingPath) {
- return Object.assign(i, { row: Number(i.row) + 1, col: Number(i.col) + 1 });
- }
- });
- },
- //判断当前的数据源是否被绑定两次
- handleAllSelectSourceView() {
- debugger
- this.showList = []
- this.useSource = []
- let curSourceList = JSON.parse(
- _this.designer.getData("updatedTreeNode") ||
- _this.designer.getData("oldTreeNodeFromJson")
- ).properties;
- if(!curSourceList) return true
- let curData = this.handleDataTableReturn();
- let newSourceList = Object.keys(curSourceList);
-
- newSourceList.forEach((item) => {
- curData.forEach((i) => {
- if (item == i.bindingPath) {
- if(this.useSource[item]){
- this.useSource[item].push(Object.assign(i,{row:Number(i.row) + 1,col:Number(i.col) + 1}))
- } else {
- this.useSource[item] = [Object.assign(i,{row:Number(i.row) + 1,col:Number(i.col) + 1})]
- }
- }
- });
- });
-
- Object.keys(this.useSource).forEach((i) => {
- if (this.useSource[i].length > 1) {
- this.useSource[i].forEach(j=>{
- this.showList.push(j)
- })
- }
- });
- console.log(this.useSource);
-
- if (this.showList.length > 0) {
-
- console.log("数据源不通过");
-
- return false;
- } else {
- return true;
- }
- },
- //确定为保存,多个单元格设置同一个数据源
- handleConfirmSource() {
- this.saveInfoConfirm();
- this.useDialog = false
- },
- // 获取当前单元格并设置逻辑
- getCell() {
- let cellObj = this.getCellCoordinate();
- return cellObj;
- },
- //返回当前dataTable的扁平化数据
- handleDataTableReturn() {
- let sheetObjList = [];
- let jsonStr = _this.spread.toJSON().sheets;
- Object.keys(jsonStr).forEach((sheetName) => {
- let curSheetDataTable = jsonStr[sheetName].data.dataTable;
- if (!curSheetDataTable) return;
- //获取行坐标
- Object.keys(curSheetDataTable).forEach((row) => {
- //获取列坐标
- Object.keys(curSheetDataTable[row]).forEach((col) => {
- let curCellObj = {
- row: row,
- col: col,
- sheetName: sheetName,
- tag: curSheetDataTable[row][col]
- ? curSheetDataTable[row][col].tag
- : {},
- bindingPath: curSheetDataTable[row][col]
- ? curSheetDataTable[row][col].bindingPath
- : "",
- style: curSheetDataTable[row][col]
- ? curSheetDataTable[row][col].style
- : {},
- value: curSheetDataTable[row][col]
- ? curSheetDataTable[row][col].value
- : "",
- };
- sheetObjList.push(curCellObj);
- });
- });
- });
- return sheetObjList;
- },
- // 发布报表
- reportRelease() {
- this.test = '999999'
- if (!this.getActiveSheetData().data.dataTable) {
- this.$message.error("当前报表内容为空,请添加后再发布");
- return;
- }
- seReportPublishing({
- reportId: this.$route.query.reportId,
- });
- this.$message.success("发布成功");
- },
- // 获取当前活动表对象
- getActiveSheet() {
- return this.spread.getActiveSheet();
- },
- // 获取选择单元格左边
- getCellCoordinate() {
- let activeSheet = this.spread.getActiveSheet();
- let activeSheetTab = this.spread.getActiveSheetTab();
- let selections = activeSheet.getSelections();
- const { col, row, colCount, rowCount } = selections[0];
- return { col, row, colCount, rowCount, activeSheet };
- },
- // 获取当前活动表数据
- getActiveSheetData() {
- return _this.spread.toJSON().sheets[this.getActiveSheet().name()];
- },
- getAllSheetsData() {
- return _this.spread.toJSON();
- },
- listenSheetChange() {
- // 监听sheet变化
- this.spread.bind(
- GC.Spread.Sheets.Events.SheetChanged,
- function (e, info) {
- if (info.propertyName === "insertSheet") {
- // 新增表重新绑定监听
- _this.listenCellEvent(_this.spread.getSheet(info.sheetIndex));
- } else if (info.propertyName === "isSelected" && info.newValue) {
- //切换表重新绑定监听
- _this.listenCellEvent(_this.spread.getSheet(info.sheetIndex));
- }
- // _this.listenCellEvent()
- }
- );
- },
- // 绑定单元格监听
- listenCellEvent(sheet = false) {
- let currentSheet = sheet || _this.spread.getActiveSheet();
- currentSheet.bind(
- GC.Spread.Sheets.Events.ValueChanged,
- function (e, info) {
- // 获取数据变化的单元格信息
- // 获取对应单元格绑定的数据源
- let bindPath = _this
- .getActiveSheet()
- .getBindingPath(info.row, info.col);
- }
- );
- currentSheet.bind(
- GC.Spread.Sheets.Events.SelectionChanged,
- function (e, info) {
- _this.curCellRow = info.newSelections[0].row;
- _this.curCellCol = info.newSelections[0].col;
- _this.getRuleDes();
- _this.getAuditpoints();
- _this.getWordRequest();
- }
- );
- currentSheet.bind(
- GC.Spread.Sheets.Events.TableRowsChanged,
- function (e, info) {
- for (let i = 0; i < _this.spread.getSheetCount(); i++) {
- let sheet = _this.spread.getSheet(i);
- sheet.tables.all().forEach((table) => {
- let dr = table.dataRange();
- sheet
- .getRange(dr.row, dr.col, dr.rowCount, dr.colCount)
- .locked(false);
- for (
- let curRow = dr.row + 1;
- curRow < dr.row + dr.rowCount;
- curRow++
- ) {
- sheet.copyTo(
- dr.row,
- dr.col,
- curRow,
- dr.col,
- 1,
- dr.colCount,
- GC.Spread.Sheets.CopyToOptions.style
- );
- }
- });
- }
- }
- );
- },
- // 删除单元格绑定源
- deleteCell() {
- let cellObj = this.getCellCoordinate();
- cellObj.activeSheet.setBindingPath(cellObj.col, cellObj.row, undefined);
- },
- //关闭绑定数据弹窗
- closeDataDia() {
- this.dialogDataConnect = false;
- },
- //绑定数据单元格
- cellDataChange({ row, col, dataSource }) {
- this.setNewTag(
- {
- relateDataSource: dataSource,
- },
- row,
- col
- );
- this.closeDataDia();
- },
- //点击添加审核点和填写要求
- handleSubmitSearch(type = "auditpoints") {
- let settingObj = {};
- type === "auditpoints"
- ? (settingObj = {
- auditpoints: _this.auditpoints,
- })
- : (settingObj = {
- wordRequest: _this.wordRequest,
- });
- this.setNewTag(settingObj, this.curCellRow, this.curCellCol);
- this.handleMessage("success");
- },
- //设置cell的tag新属性
- setNewTag(setTagObj, row, col) {
- if (_this.getActiveSheet().getTag(row, col)) {
- _this
- .getActiveSheet()
- .setTag(
- Object.assign(_this.getActiveSheet().getTag(row, col), setTagObj)
- );
- } else {
- _this.getActiveSheet().setTag(row, col, setTagObj);
- }
- },
- //提示方法
- handleMessage(type, text) {
- if (type == "success") {
- this.$message.success(`${text || "保存成功"}`);
- } else {
- this.$message.error(`${text || "保存失败"}`);
- }
- },
- getRuleDes() {
- //获取正则校验描述
- try {
- // 读取规则描述
- _this.curCellReg =
- _this.regObj[
- _this.getActiveSheetData().data.dataTable[_this.curCellRow][
- _this.curCellCol
- ].tag.reCode
- ].des;
- // 读取是否必填
- _this.getActiveSheetData().data.dataTable[_this.curCellRow][
- _this.curCellCol
- ].tag.isRequire
- ? (_this.curCellReg += " - 必填 ")
- : "";
- } catch (e) {
- _this.curCellReg = "";
- }
- },
- getAuditpoints() {
- try {
- // 获取审核点数据
- _this.auditpoints =
- _this.getActiveSheetData().data.dataTable[_this.curCellRow][
- _this.curCellCol
- ].tag.auditpoints;
- } catch (e) {
- _this.auditpoints = "";
- }
- },
- getWordRequest() {
- try {
- // 获取填报要求数据
- _this.wordRequest =
- _this.getActiveSheetData().data.dataTable[_this.curCellRow][
- _this.curCellCol
- ].tag.wordRequest;
- } catch (e) {
- _this.wordRequest = "";
- }
- },
- //校验添加的新规则是否符合校验
- handleValidRule() {
- let valids;
- let mode;
- this.diaMode === "reg" ? (mode = "regDataObj") : (mode = "checkDataObj");
- this.$refs[mode].validate((valid) => {
- valids = valid;
- });
- return valids;
- },
- // 新建自定义正则校验
- async handleSubmitReg() {
- if (!this.handleValidRule()) return;
- let mode;
- this.diaMode === "reg" ? (mode = "regDataObj") : (mode = "checkDataObj");
- // this.$refs[mode].resetFields();
- if (this.diaMode === "reg") {
- _this.randomNumber = Math.floor(Math.random(new Date()) * 100000);
- if (
- this.regObj[_this.randomNumber] &&
- this.regObj[_this.randomNumber].re
- ) {
- handleSubmitReg();
- return;
- }
- await seAddRegularItem([
- {
- name: this.regDataObj.name,
- des: this.regDataObj.des,
- re: this.regDataObj.input,
- code: _this.randomNumber,
- },
- // ...localReRule,
- ]);
- } else if (this.diaMode === "checkBox") {
- _this.randomNumber = Math.floor(
- Math.random(new Date()) * 100000 + 100000
- );
- if (this.regObj[_this.randomNumber]) {
- handleSubmitReg();
- return;
- }
- await seAddRegularItem([
- {
- name: this.checkDataObj.name,
- des: this.checkDataObj.des,
- min: this.checkDataObj.min,
- max: this.checkDataObj.max,
- code: _this.randomNumber,
- },
- // ...localReRule,
- ]);
- }
- _this.regStatus = "选择";
- this.getRegObj();
- this.initRule();
- },
- // 绑定当前选择的正则到当前选择的单元格
- handleRegRuleAdd(isRequire) {
- if (isRequire) {
- this.setNewTag(
- {
- isRequire: true,
- },
- this.curCellRow,
- this.curCellCol
- );
- }
- if (this.diaMode === "reg") {
- this.setNewTag(
- {
- reCode: this.regDataObj.select,
- },
- this.curCellRow,
- this.curCellCol
- );
- _this.randomNumber = this.regDataObj.select;
- } else if (this.diaMode == "checkBox") {
- this.setNewTag(
- {
- reCode: this.checkDataObj.select,
- },
- this.curCellRow,
- this.curCellCol
- );
- _this.randomNumber = this.checkDataObj.select;
- }
- _this.getRuleDes();
- this.$message.success("添加成功!");
- this.dialogVisible = false;
- },
- //唤醒多选绑定框
- ruleSources() {
- if (!this.regObj[this.checkDataObj.select]) {
- this.regObj[""] = {
- des: "暂无校验",
- code: "",
- min: "",
- name: "暂无校验",
- max: "",
- };
- this.checkDataObj.select = "";
- }
- _this.diaMode = "checkBox";
- _this.dialogVisible = true;
- },
- //清空数据校验列表
- resetDSList() {},
- //多选框其他数据绑定(多选框绑定后,能使用正则校验对指定的其他单元格设置校验规则)
- relateMutCheck() {
- _this.multipleDataConnect.push({
- row: _this.curCellRow,
- col: _this.curCellCol,
- });
- try {
- if (
- !_this.getActiveSheetData().data.dataTable[
- _this.multipleDataConnect[0].row
- ][_this.multipleDataConnect[0].col].style.cellType.typeName == "12"
- ) {
- this.$message.error("请先选择多选框");
- _this.multipleDataConnect = [];
- return;
- }
- } catch (e) {
- _this.multipleDataConnect = [];
- _this.$message.error("请先选择多选框");
- return;
- }
- if (_this.multipleDataConnect.length == 2) {
- //多选框绑定
- _this.setNewTag(
- {
- relateRow: _this.multipleDataConnect[1].row,
- relateCol: _this.multipleDataConnect[1].col,
- },
- _this.multipleDataConnect[0].row,
- _this.multipleDataConnect[0].col
- );
- //被多选框绑定
- _this.setNewTag(
- {
- connectByRow: _this.multipleDataConnect[0].row,
- connectByCol: _this.multipleDataConnect[0].col,
- },
- _this.multipleDataConnect[1].row,
- _this.multipleDataConnect[1].col
- );
- this.getActiveSheet()
- .getCell(
- _this.multipleDataConnect[0].row,
- _this.multipleDataConnect[0].col
- )
- .backColor("#aed19c");
- this.getActiveSheet()
- .getCell(
- _this.multipleDataConnect[1].row,
- _this.multipleDataConnect[1].col
- )
- .backColor("#aed19c");
- this.$message.success(
- `成功关联(${_this.multipleDataConnect[0].row},${_this.multipleDataConnect[0].col})(${_this.multipleDataConnect[1].row},${_this.multipleDataConnect[1].col})`
- );
- _this.multipleDataConnect = [];
- } else {
- _this.$message.success(
- `已选择(${_this.curCellRow},${_this.curCellCol})`
- );
- }
- },
- //清除该单元格的数据绑定
- removeData({ row, col }) {
- _this.setNewTag(
- {
- relateDataSource: null,
- },
- row,
- col
- );
- },
- //关闭自定义校验选择框
- handleCancelDia(type) {
- type == "add" ? "" : (this.dialogVisible = false);
- (this.regDataObj = {
- input: "",
- name: "",
- des: "",
- select: "",
- }),
- (this.checkDataObj = {
- min: "",
- max: "",
- name: "",
- des: "",
- select: "",
- });
- this.checkDataObj.select;
- this.regObj;
- this.regStatus = "选择";
- },
- //清除绑定的自定义规则
- removeRule() {
- try {
- _this.getActiveSheetData().data.dataTable[this.curCellRow][
- this.curCellCol
- ].tag.reCode = null;
- _this.getActiveSheetData().data.dataTable[this.curCellRow][
- this.curCellCol
- ].tag.isRequire = false;
- this.$message.success("校验清除成功");
- this.dialogVisible = false;
- } catch (e) {}
- },
- //数据回填的方法设置
- reWriteBtn() {
- _this.reWriteDia = true;
- },
- //取消当前回填数据
- overReWriteBtn(){
- this.setNewTag(
- {
- reWriteType: null,
- },
- this.curCellRow,
- this.curCellCol
- );
- this.getActiveSheet()
- .getCell(Number(this.curCellRow), Number(this.curCellCol))
- .backColor("");
- this.$message.success("取消回填成功");
- this.reWriteSelect = "";
- },
- handleReWriteSubmit() {
- // 设置该单元格的回填信息
- this.setNewTag(
- {
- reWriteType: this.reWriteSelect,
- },
- this.curCellRow,
- this.curCellCol
- );
- this.getActiveSheet()
- .getCell(Number(this.curCellRow), Number(this.curCellCol))
- .backColor("#9ebddd");
- this.$message.success("设置回填成功,请设置该单元格数据源");
- this.reWriteDia = false;
- this.reWriteSelect = "";
- },
- },
- watch: {
- screenWidth: {
- immediate: true,
- handler: function (newVal) {
- // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
- if (!this.timer) {
- this.screenWidth = newVal;
- this.timer = true;
- let _this = this;
- setTimeout(() => {
- document.getElementById("designer-content").style.width =
- newVal + "px";
- //在这里做有关浏览器变化时需要做的操作
- _this.spread.refresh();
- _this.timer = false;
- }, 500);
- }
- },
- },
- },
- beforeDestroy() {},
- };
- </script>
复制代码 |