瀏覽代碼

先提测一波

Karsa 1 年之前
父節點
當前提交
5190735a09

+ 10 - 1
src/views/datasheet_manage/common/customTable.js

@@ -41,7 +41,6 @@ export function findCellByFactor (str) {
 
   let table = document.querySelector('.table');
   let el = table.querySelector("td span[data-rindex='" + newStr[1] + "'][data-cindex='" + newStr[0] + "']") || table.querySelector("td input[data-rindex='" + newStr[1] + "'][data-cindex='" + newStr[0] + "']");
-
   return el ? (el.innerText||'') : null;
 }
 
@@ -252,3 +251,13 @@ export function resetDialogCellStyle() {
   })
 }
 
+
+// 根据行头列头位置找key
+export function findCellKeyByFactor(str) {
+  let newStr = splitString(toUpperCase(str));
+
+  let table = document.querySelector('.table');
+  let el = table.querySelector("td [data-rindex='" + newStr[1] + "'][data-cindex='" + newStr[0] + "']");
+
+  return el ? (el.dataset.key||'') : null;
+}

+ 1 - 1
src/views/datasheet_manage/components/CustomTable.vue

@@ -644,7 +644,7 @@ export default {
         return
       }
 
-      if(value.includes('=')) {
+      if(value.startsWith('=')) {
         cell.DataType = 4;
         let calculateVal = await this.getValueByFormula(value);
         cell.ShowValue = calculateVal;

+ 71 - 36
src/views/datasheet_manage/components/MixedTable.vue

@@ -202,7 +202,10 @@ import {
   resetRelationStyle,
   resetDialogCellStyle,
   extractFactorsFromFormula,
-  findCellByFactor
+  findCellByFactor,
+  splitString,
+  toUpperCase,
+  findCellKeyByFactor
 } from "../common/customTable";
 import * as sheetInterface from "@/api/modules/sheetApi.js";
 import { dataBaseInterface } from '@/api/api.js';
@@ -275,11 +278,11 @@ export default {
 
       insertTargetCell: {},//选择右键插入时的单元格 可和右键单元格不一样 key c r
 
-      insertRelationArr: [],
+      insertRelationArr: [], //表格单元格依赖关系数组
 
       isSelectTargetValueDialog: false,
 
-      cellrelationEdbInfo: {},
+      cellrelationEdbInfo: {}, //指标浮窗信息
 
       copyCellItem: {},//复制时的单元格信息 用于粘贴赋值
 
@@ -290,14 +293,15 @@ export default {
         key: '',
       },
 
-      isInsertCalculate: false,//插入指标计算值
-      insertCalculateInfo: {
+      calculateChainList: [],//公式链 key数组 后端需要
 
-      },
+      isInsertCalculate: false,//插入指标计算值
+      insertCalculateInfo: {},//指标计算单元格info
 
       formulaTip,
       
       hasInit:false,
+
     };
   },
   mounted() {
@@ -312,7 +316,7 @@ export default {
       if(!query
         ||checkDateFormat(query)
         ||dateOtherRegex.test(query)
-        ||query.includes('=')
+        ||query.startsWith('=')
       ) return cb([])
       
       const { DataType,EdbInfoId } = this.selectCell;
@@ -340,14 +344,14 @@ export default {
       setFocus(e);
 
       /* 如果当前有公式单元格在编辑就拼接当前单元格进公式 */
-      // if(this.calculateClickCell && this.calculateClickCell.Uid!==cell.Uid) {
-      //   console.log(this.calculateClickCell)
-      //   const { cindex,rindex } = e.target.dataset;
-      //   this.calculateClickCell.Value += `${cindex}${rindex}`
-      // }
+      if(this.calculateClickCell && this.calculateClickCell.Uid!==cell.Uid) {
+        console.log(this.calculateClickCell)
+        const { cindex,rindex } = e.target.dataset;
+        this.calculateClickCell.Value += `${cindex}${rindex}`
+      }
 
       //是插值单元格时寻找关联依赖的单元格 设置选框
-      if([4,5].includes(cell.DataType)) {
+      if([4,5,7].includes(cell.DataType)) {
         const { key } = e.target.dataset;
         if(!this.insertRelationArr.find(_ => _.key===key)) return
         let { relation_date,relation_edb } = this.insertRelationArr.find(_ => _.key===key)
@@ -360,7 +364,7 @@ export default {
       this.isSelectTargetValueDialog&&this.$refs.selectTargetValueRef.chooseEdb(this.$refs.selectTargetValueRef.edbInfo)
 
       //计算指标弹窗打开时选择日期更新弹窗数据
-      this.isInsertCalculate&&this.$refs.calculateEdbDiaRef.setChooseDate(cell)
+      this.isInsertCalculate&&this.$refs.calculateEdbDiaRef.showResult&&this.$refs.calculateEdbDiaRef.calculateHandle()
     },
 
     /* 插入值 往左往上寻找同行同列是否有符合条件的一指标一日期 */
@@ -512,6 +516,7 @@ export default {
         cell.Value = value;
         cell.EdbInfoId = 0;
         cell.DataTime = '';
+        cell.Extra=''
       }else {
         //指标类型不做格式处理
         if(cell.DataType===2) return
@@ -519,14 +524,17 @@ export default {
         console.log(checkDateFormat(value))
         if(checkDateFormat(value)) { //是日期格式
           cell.DataType = 1;
-          
+          cell.Extra='';
           cell.ShowValue = checkDateFormat(value);
           cell.Value = checkDateFormat(value);
-        }else if(value.includes('=')) { //公式单元格
+        }else if(value.startsWith('=')) { //公式单元格
           cell.DataType = 6;
           let calculateVal = await this.getValueByFormula(value);
           cell.ShowValue = calculateVal;
-          // this.calculateClickCell = cell;
+          //处理公式关系
+          this.$set(cell,'Extra',this.dealFormulaConstruction(value))
+          
+          console.log(cell)
 
         }else {//自定义值
           cell.DataType = 3;
@@ -534,6 +542,7 @@ export default {
           cell.Value = value;
           cell.EdbInfoId = 0;
           cell.DataTime = '';
+          cell.Extra=''
         }
       }
 
@@ -712,7 +721,7 @@ export default {
         'insert-sys-date': this.insertDateOpen,//导入系统日期
         'insert-edb-date': this.insertDateOpen,//导入指标日期
         'reset': this.clearCell, //清空
-        'cell-edit': editHandlesMap[this.selectCell.DataType]
+        'cell-edit': this.selectCell ? editHandlesMap[this.selectCell.DataType] : null
       }
       keyMap[key] && keyMap[key](key)
       
@@ -729,27 +738,29 @@ export default {
     },
 
     /* 插入选择指标的值 */
-    insertSelectData({ edbId,value }) {
+    insertSelectData({ edbId,value,date }) {
 
       this.insertTargetCell.DataType = 5;
       this.insertTargetCell.ShowValue = value;
       this.insertTargetCell.Value = value;
       this.insertTargetCell.EdbInfoId = edbId;
-      this.insertTargetCell.DataTime = this.selectCell.ShowValue;
+      this.insertTargetCell.DataTime = date;
 
       this.$message.success('插入成功')
 
-      //建立新的关联关系
-      let relation = {
-        insert_cell: {
-          key: this.insertTargetCell.Uid,
-          relation_date: this.selectCell.Uid,
-          relation_edb: '',
+      //如果有关联表格日期就建立新的关联关系
+      if(date) {
+        let relation = {
+          insert_cell: {
+            key: this.insertTargetCell.Uid,
+            relation_date: this.selectCell.Uid,
+            relation_edb: '',
+          }
         }
+  
+        this.setRelation(relation,5);
       }
 
-      this.setRelation(relation,5);
-
     },
 
     /* 清除单元格内容 格式 关联关系 */
@@ -906,15 +917,14 @@ export default {
       setRelationStyle({ key:this.insertTargetCell.Uid },'td-choose-insert-target');
 
       if(item === 'cell-edit') { //编辑
-        const { Value,EdbInfoId } = this.insertTargetCell;
+        const { Value } = this.insertTargetCell;
 
         let menuInfo = this.config.contextMenuOption
           .find(_ => _.key==='insert-edb-calculate').children
-          .find(menu => menu.source === JSON.parse(Value).source);
+          .find(menu => menu.source === JSON.parse(Value).Source);
 
         this.insertCalculateInfo = {
           ...menuInfo,
-          EdbInfoId,
           formStr: Value,
         }
       }else {
@@ -929,16 +939,16 @@ export default {
     /* 导入指标计算值 */
     insertCalculateData(item) {
       console.log(item)
-      const { insertValue,EdbInfoId,str,Date } = item;
+      const { InsertValue,EdbInfoId,Str,Date } = item;
       this.insertTargetCell.DataType = 7;
-      this.insertTargetCell.ShowValue = insertValue;
-      this.insertTargetCell.Value = str;
+      this.insertTargetCell.ShowValue = InsertValue;
+      this.insertTargetCell.Value = Str;
       this.insertTargetCell.EdbInfoId = EdbInfoId;
       this.insertTargetCell.DataTime = Date;
 
       this.$message.success('插入成功')
 
-      //如果日期有关联表格日期就建立新的关联关系
+      //如果有关联表格日期就建立新的关联关系
       if(Date) {
         let relation = {
           insert_cell: {
@@ -979,6 +989,18 @@ export default {
       })
     },
 
+     /* 处理因数结构 =a1+b1 => [{ Tag: a,Row:1,Key:'' }] */
+    dealFormulaConstruction(val) {
+      // 提取因数数组
+      let factors = extractFactorsFromFormula(val)
+      let arr = factors.map(str => ({
+          Tag: splitString(toUpperCase(str))[0],
+          Row: splitString(toUpperCase(str))[1],
+          Key: findCellKeyByFactor(str)
+      }))
+      return arr
+    },
+
 
     /* 要支持复制粘贴把公式也带过去 公式单元格类型为6 其余就正常复制文本 */
     copyCellHandle(e,cell) {
@@ -1008,6 +1030,7 @@ export default {
     /* 公式单元格enter时切换编辑状态 */
     keyEnterHandle(e,cell) {
       e.keyCode===13 && cell.DataType===6 && this.$set(cell,'CanEdit',false)
+      console.log(cell)
       this.calculateClickCell = null
       resetDialogCellStyle()
     },
@@ -1020,11 +1043,23 @@ export default {
 
       this.calculateClickCell = cell;
 
-      // setRelationStyle({ key:cell.Uid },'td-choose-insert-target')
+      setRelationStyle({ key:cell.Uid },'td-choose-insert-target')
 
       this.$nextTick(() => {
         if(e.target.childNodes[0].childNodes[0].childNodes[1].nodeName==='INPUT') e.target.childNodes[0].childNodes[0].childNodes[1].focus();
       })
+    },
+
+    /* 处理保存的参数 */
+    getSaveParams() {
+      const { data } = this.config;
+
+      let params = {
+        CellRelation: JSON.stringify(this.insertRelationArr),
+        Data: data
+      }
+
+      return params
     }
   },
 };

+ 45 - 37
src/views/datasheet_manage/components/calculateEdbDia.vue

@@ -204,29 +204,38 @@ export default {
   computed: {
     edbArrFromTable() {
        return this.$parent.config.data.flat().filter(_ =>_.DataType === 2)
-    },
-    calculateShowData() {
-      if(this.chooseItem.Date) {
-        let index = this.calculateAllResult.findIndex(_ => _.DataTime===this.chooseItem.Date)
-        if(index === -1) return []
-
-        return this.calculateAllResult.slice(index-2,index+2);
-        
-      }else {
-        return this.calculateAllResult.slice(0,5);
-      }
     }
   },
   watch: {
     isShow(nval) {
       if(!nval) return
       console.log(this.info)
-      const { source,formStr,EdbInfoId } = this.info;
+      const { source,formStr } = this.info;
 
       this.formData.source = source;
       //回显
-      if(EdbInfoId) {
-        this.formData = { ...JSON.parse(formStr) }
+      if(formStr) {
+        const {
+          Source,
+          Frequency,
+          Formula,
+          EdbInfoId,
+          MoveFrequency,
+          MoveType, 
+          Calendar 
+        } = JSON.parse(formStr);
+
+        this.formData = {
+          source: Source,
+          frequency: Frequency,
+          nNum: Formula,
+          moveType: MoveType,
+          moveUnit: MoveFrequency,
+          moveVal: Formula,
+          calendarType: Calendar,
+          valueType: Formula,
+          alphaValue: Formula,
+        }
         this.selectTableEdbHandle({EdbInfoId})
       }
     }
@@ -235,6 +244,7 @@ export default {
     return {
       formData: {
         source: this.info.fromEdbKey,
+        frequency: '',
         nNum: 1,
 				moveType: 1,
 				moveUnit: '天',
@@ -246,7 +256,7 @@ export default {
       formRules,
 
       showResult: false,
-      calculateAllResult: [], //计算全部数据
+      calculateShowData: [], //计算全部数据
       chooseItem: {
         Date: ''
       },//要插入表格的项
@@ -286,6 +296,7 @@ export default {
 				moveType,
 				moveUnit,
 				calendarType,
+        frequency
       } = this.formData;
 
       const valueMap = {
@@ -294,28 +305,35 @@ export default {
         'alpha': 'alphaValue'
       }
 
-      let Date = this.$parent.selectCell.DataType === 1 ? this.$parent.selectCell.ShowValue : ''
+      let DataTime = this.$parent.selectCell.DataType === 1 ? this.$parent.selectCell.ShowValue : ''
 
-      const res = await sheetInterface.getMixedCalculateData({
-        Date,
+      let params = {
+        DataTime,
         Source: source,
+        Frequency: frequency,
         Formula: valueMap[this.info.fromEdbKey] ? String(this.formData[valueMap[this.info.fromEdbKey]]) : String(nNum),
         EdbInfoId: this.selectEdbInfo.EdbInfoId,
         MoveFrequency: moveUnit,
         MoveType: moveType, 
         Calendar: calendarType
-      })
+      }
+
+      const res = await sheetInterface.getMixedCalculateData(params)
       if(res.Ret!==200) return 
 
       this.showResult = true;
-      this.calculateAllResult = res.Data || [];
+      this.calculateShowData = res.Data.List || [];
+
+      // if(!this.calculateShowData.length && DataTime) return this.$message.warning('所选指标所选日期无值')
 
-      // if(!this.result.Date && Date) return this.$message.warning('所选指标所选日期无值')
+      let InsertValue = this.calculateShowData.length 
+        ? (this.calculateShowData.find(_ => _.DataTime===DataTime) ? this.calculateShowData.find(_ => _.DataTime===DataTime).Value.toString() : this.calculateShowData[0].Value.toString()) 
+        : ''
       this.chooseItem = {
-          Date,
+          Date:DataTime,
           EdbInfoId: this.selectEdbInfo.EdbInfoId,
-          insertValue: Date ? this.calculateAllResult.find(_ => _.DataTime===Date).Value : this.calculateAllResult[0].Value,
-          str: JSON.stringify(this.formData)
+          InsertValue,
+          Str: JSON.stringify(params)
         }
       
     },
@@ -331,16 +349,6 @@ export default {
       this.cancelHandle();
     },
 
-    /* 设置关联表格的日期 */
-    setChooseDate(cell) {
-      if(cell.DataType !== 1) {
-        this.chooseItem.Date = '';
-        return
-      } 
-
-      this.chooseItem.Date = cell.DataTime;
-    },
-
     /* 选择指标 */
     async selectTargetHandle(e) {
       this.changeSource();
@@ -360,7 +368,6 @@ export default {
         EdbCode,EdbName,Frequency,Unit,StartDate,ModifyTime,SourceName,EdbInfoId,
         DataList: PredictDataList ? [...PredictDataList,...DataList].slice(0,5) : DataList.slice(0,5)
       };
-      console.log(this.selectEdbInfo)
     },
 
     /* 选择表格指标 */
@@ -376,7 +383,7 @@ export default {
     /*  */
     changeSource() {
       this.showResult = false;
-      this.calculateAllResult = [];
+      this.calculateShowData = [];
       this.chooseItem = { Date: '' };
     },
 
@@ -384,10 +391,11 @@ export default {
       this.search_edb='';
       this.selectEdbInfo = null;
       this.showResult = false;
-      this.calculateAllResult = [];
+      this.calculateShowData = [];
       this.chooseItem = { Date: '' };
       this.formData = {
         source: this.formData.source, 
+        frequency: '',
         nNum: 1,
 				moveType: 1,
 				moveUnit: '天',

+ 20 - 15
src/views/datasheet_manage/components/selectTargetValueDia.vue

@@ -14,7 +14,11 @@
 
       <ul class="data-cont">
         <template v-if="result.List">
-          <li v-for="(item,index) in result.List" :key="index" :class="[{'choose': item.DataTime===result.Date},'data-li']">
+          <li 
+            v-for="(item,index) in result.List" 
+            :key="index" 
+            :class="[{'choose': item.DataTime===chooseItem.date || (!chooseItem.date&&index===0)},'data-li']"
+          >
             <span>{{item.DataTime}}</span>
             <span style="min-width:150px">{{item.Value}}</span>
           </li>
@@ -63,13 +67,6 @@ export default {
       } 
 
       this.edbInfo = edb;
-      
-      // if(this.$parent.selectCell.DataType !== 1){
-
-      //   this.$message.warning('请在表格中选择日期')
-      //   this.initData();
-      //   return
-      // }
 
       let Date = this.$parent.selectCell.DataType === 1 ? this.$parent.selectCell.ShowValue : ''
 
@@ -80,19 +77,27 @@ export default {
       if(res.Ret !== 200) return
 
       this.result = res.Data;
-      if(!this.result.Date && Date) return this.$message.warning('所选指标所选日期无值')
+      // if(!this.result.Date && Date) return this.$message.warning('所选指标所选日期无值')
+
+      let value = this.result.List.length
+        ? (this.result.List.find(_ => _.DataTime===Date) ? this.result.List.find(_ => _.DataTime===Date).Value.toString() : this.result.List[0].Value.toString()) 
+        : ''
       this.chooseItem = {
+        date: Date,
         edbId: edb.EdbInfoId,
-        value: this.result.Date?this.result.List.find(_ =>_.DataTime===this.result.Date).Value.toString():''
+        value
       }
 
+      console.log( this.chooseItem)
+
     },
 
     insertData() {
-      if(this.$parent.selectCell.DataType !== 1){
-        this.$message.warning('请在表格中选择日期')
-        return
-      }
+      // if(this.$parent.selectCell.DataType !== 1){
+      //   this.$message.warning('请在表格中选择日期')
+      //   return
+      // }
+      if(!this.chooseItem.value) return this.$message.warning('该日期无数据')
 
       this.$emit('insert',this.chooseItem)
       this.cancelHandle();
@@ -102,7 +107,7 @@ export default {
       this.$refs.selectRef.search_txt='';
       this.result = {};
       this.edbInfo=null;
-      this.chooseItem = { edbId: 0,value: '' }
+      this.chooseItem = { edbId: 0,value: '',date: '' }
     },
 
     cancelHandle() {

+ 5 - 8
src/views/datasheet_manage/mixedSheetEdit.vue

@@ -163,6 +163,7 @@ export default {
         this.classifyArr = res.Data.AllNodes || [];
       })
     },
+
     autoSaveFun:_.debounce(async function(){
       if(!this.sheetId || this.cancelAutoSave) return 
       const { name,classify,sheetType } = this.sheetForm;
@@ -175,16 +176,14 @@ export default {
         ExcelClassifyId: classify,
         ExcelImage:'',
         Source: 3,
-        TableData: {
-          CellRelation: JSON.stringify(this.$refs.mixedTableRef.insertRelationArr),
-          Data: this.$refs.mixedTableRef.config.data
-        }
+        TableData: this.$refs.mixedTableRef.getSaveParams()
       };
       console.log("自动保存");
       const res = await sheetInterface.sheetEdit({ ExcelInfoId: Number(this.sheetId),...params })
       if(res.Ret !==200) return
       this.updateTime = this.$moment().format('YYYY-MM-DD HH:mm:ss')
     },1500),
+
     /* 保存表格 */
     saveSheetHandle: _.debounce(async function() {
 
@@ -213,10 +212,7 @@ export default {
         ExcelClassifyId: classify,
         ExcelImage: Data.ResourceUrl,
         Source: 3,
-        TableData: {
-          CellRelation: JSON.stringify(this.$refs.mixedTableRef.insertRelationArr),
-          Data: this.$refs.mixedTableRef.config.data
-        }
+        TableData: this.$refs.mixedTableRef.getSaveParams()
       };
       let isAdd = this.sheetId?false:true
       const res = this.sheetId
@@ -230,6 +226,7 @@ export default {
       this.$message.success('保存成功')
       isAdd && this.$router.replace({path:'/addMixedSheet',query:{id:this.sheetId}})
     },300),
+
     markFinishStatus(){
       if((!this.sheetId) || (!this.isCanEdit)) return
       sheetInterface.markSheetEditStatus({ExcelInfoId: +this.sheetId,Status:2}).then(res=>{

+ 1 - 0
src/views/datasheet_manage/sheetList.vue

@@ -1015,6 +1015,7 @@ $normal-font: 14px;
           position: relative;
           height: calc(100vh - 210px);
           padding: 15px;
+          overflow-y: auto;
           /* min-height: 500px; */
         }
       }