소스 검색

甘特图框架监听

yuhan 1 년 전
부모
커밋
d450eb78f3
1개의 변경된 파일49개의 추가작업 그리고 2개의 파일을 삭제
  1. 49 2
      itdmWeb/src/components/module-iTDM/uGantt/index.vue

+ 49 - 2
itdmWeb/src/components/module-iTDM/uGantt/index.vue

@@ -100,9 +100,25 @@
         
       }
     },
+    watch: {
+      taskLists: {
+        handler(newValue, oldValue){
+          console.log(newValue, oldValue)
+          if(newValue.length > 0){
+            this.changeTableTree()
+            this.getStartEndTime()
+          } else {
+            console.log(this.setDefaultDate())
+            this.uGanttColumns = this.setDefaultDate()
+          }
+        },
+        immediate: true,
+        // deep: true
+      }
+    },
     created (){
-      this.changeTableTree()
-      this.getStartEndTime()
+      // this.changeTableTree()
+      // this.getStartEndTime()
     },
     mounted () {
       this.uGanttDrag()
@@ -110,6 +126,36 @@
       this.uGanttResizeR()
     },
     methods: {
+      // 没有数据时设置默认当月日期
+      setDefaultDate() {
+        // 获取标准时间
+        var nowdays = new Date()
+        // 获取当年
+        var currentYear = new Date().getFullYear()
+        // 获取当月
+        var currentMonth = new Date().getMonth() + 1
+        // 获取当天
+        var nowDay = new Date().getDate()
+        // 获取当前月有多少天
+        var currentMonthNum = new Date(currentYear, currentMonth, 0).getDate()
+        console.log(nowDay, currentMonth, currentMonthNum)
+        // 
+        // let now = new Date(nowDay)
+        // console.log(nowdays, now)
+        // 当前月份所有日期集合
+        let currentMonthArr = []
+        for (let i = 1; i <= currentMonthNum; i++) {
+          // let day = nowdays.setDate(i);
+          // console.log(day)
+          // 年月日(yyyy-MM-dd)
+          let dateLabel = (currentMonth < 10 ? '0' + currentMonth : currentMonth) + "月" + (i < 10 ? '0' + i : i) + "日";
+          let dateName = currentYear + "-" + (currentMonth < 10 ? '0' + currentMonth : currentMonth) + "-" + (i < 10 ? '0' + i : i);
+          // let day = 
+          currentMonthArr.push({label: dateLabel, name: dateName});
+        }
+        console.log(currentMonthArr)
+        return currentMonthArr
+      },
       // 获取最开始和最末尾时间
       getStartEndTime(){
         // var setTimeData = JSON.parse(JSON.stringify(this.taskLists))
@@ -201,6 +247,7 @@
       },
       // 将一维数组改成多维数组
       changeTableTree(){
+        // console.log(this.taskLists)
         this.tableData = this.changeDataTree(this.taskLists, 'id', 'pid')
         // this.tableData = this.handleTree(this.taskLists, 'id', "pid")
         // console.log(this.tableData)