Browse Source

日期缓存

luolei 5 years ago
parent
commit
393ca3089f
4 changed files with 70 additions and 16 deletions
  1. 30 10
      src/js/console.js
  2. 32 5
      src/js/deptConsole.js
  3. 2 0
      src/js/index.js
  4. 6 1
      src/js/utils.js

+ 30 - 10
src/js/console.js

@@ -26,9 +26,6 @@ $(function(){
     //     $(".innerOuter").css("display","none")
     // }
     $(".partTitle p span").html(hospital)
-    // setInterval(() => {
-    //     getTimeDetail()
-    // }, 1000);
     resizeBox()
     initConsole()//质控列表
     // getBarData(2)//图标数据获取
@@ -198,7 +195,7 @@ function resizeBox(){
                 backgroundColor:'#203463'
             })
             dateType = 1
-            dateConsole(1)
+            dateConsole(1,1)
         })
         $(".monthYear .year").click(function(){
             $(this).css({
@@ -211,7 +208,7 @@ function resizeBox(){
                 backgroundColor:'#203463'
             })
             dateType = 2
-            dateConsole(2)
+            dateConsole(2,1)
         })
     }
 
@@ -1703,6 +1700,8 @@ $(".sureDate").click(function(){
     if(!getStaticDate()){
         return
     }
+    
+    setCookieAction(behosDateStart.split(" ")[0],behosDateEnd.split(" ")[0])
     getAverageScoreLis()
     getBarData(dateType)
     getEveryDeptLevel()
@@ -1720,17 +1719,31 @@ $(".sureDate").click(function(){
     dateType = 3
 })
 //日期联动
-function dateConsole(dateType){
+function dateConsole(dateType,flg){
     let startDate = "", endDate=new Date()
     let year = new Date().getFullYear()
     let month = new Date().getMonth() + 1
     if(dateType == '1'){
-        startDate = new Date(`${year}-${month}-01`)
+        startDate = new Date(`${year}/${month}/01`)
     }else if(dateType == '2'){
-        startDate = new Date(`${year}-01-01`)
+        startDate = new Date(`${year}/01/01`)
     } else {
         startDate = "-6d"
     }
+    if(getCookie("behosDateStart")&&!flg){
+        startDate = new Date(getCookie("behosDateStart"))
+        endDate = new Date(getCookie("behosDateEnd"))
+        $(".monthYear .year").css({
+            "border-color":'#A5ADBF',
+            color:'#A5ADBF',
+            backgroundColor:'#203463'
+        })
+        $(".monthYear .mon").css({
+            "border-color":'#A5ADBF',
+            color:'#A5ADBF',
+            backgroundColor:'#203463'
+        })
+    }
     $( "#datepicker" ).datepicker({
         yearRange: "2015:"+year,
         changeMonth: true,
@@ -1743,13 +1756,17 @@ function dateConsole(dateType){
         changeYear: true,
         dateFormat:"yy/mm/dd"
     }).datepicker( "setDate",endDate);
-    getStaticDate()
+    getStaticDate(flg)
     getAverageScoreLis()
     getBarData(dateType)
     getHomeData('firstLevelPercent')
     getEveryDeptLevel()
 }
-function getStaticDate(){
+function setCookieAction(startDate,endDate){
+    setCookie('behosDateStart',startDate)
+    setCookie('behosDateEnd',endDate)
+}
+function getStaticDate(flg){
     behosDateStart = $("#datepicker").val()
     behosDateEnd = $("#datepicker2").val()
     const start = new Date(behosDateStart).getTime()
@@ -1758,6 +1775,9 @@ function getStaticDate(){
         $.alerModal({"message":'开始时间不能大于结束时间~',type:"tip",time:'1000',isFather: true, fatherWrapper: $("#mainBox", parent.document)});
         return false
     }
+    if(flg){
+        setCookieAction(behosDateStart,behosDateEnd)
+    }
     if(behosDateStart){
         behosDateStart = behosDateStart.replace(/\//g,'-') + ' 00:00:00'
     }

+ 32 - 5
src/js/deptConsole.js

@@ -100,7 +100,7 @@ function dateChange(){
             backgroundColor:'#203463'
         })
         dateType = 1
-        dateConsole(1)
+        dateConsole(1,1)
     })
     $(".monthYear .year").click(function(){
         $(this).css({
@@ -113,7 +113,7 @@ function dateChange(){
             backgroundColor:'#203463'
         })
         dateType = 2
-        dateConsole(2)
+        dateConsole(2,1)
     })
 }
 //控制台数
@@ -823,6 +823,8 @@ $(".sureDate").click(function(){
     if(!getStaticDate()){
         return
     }
+    
+    setCookieAction(behosDateStart.split(" ")[0],behosDateEnd.split(" ")[0])
     getBarData(dateType)
     dateType = 3
     $(".monthYear .year").css({
@@ -837,7 +839,7 @@ $(".sureDate").click(function(){
     })
 })
 //日期联动
-function dateConsole(dateType){
+function dateConsole(dateType,flg){
     let startDate = "", endDate=new Date()
     let year = new Date().getFullYear()
     let month = new Date().getMonth() + 1
@@ -848,6 +850,20 @@ function dateConsole(dateType){
     } else {
         startDate = "-1m"
     }
+    if(getCookie("behosDateStart")&&!flg){
+        startDate = new Date(getCookie("behosDateStart"))
+        endDate = new Date(getCookie("behosDateEnd"))
+        $(".monthYear .year").css({
+            "border-color":'#A5ADBF',
+            color:'#A5ADBF',
+            backgroundColor:'#203463'
+        })
+        $(".monthYear .mon").css({
+            "border-color":'#A5ADBF',
+            color:'#A5ADBF',
+            backgroundColor:'#203463'
+        })
+    }
     $( "#datepicker" ).datepicker({
         yearRange: "2015:"+year,
         changeMonth: true,
@@ -860,18 +876,29 @@ function dateConsole(dateType){
         changeYear: true,
         dateFormat:"yy/mm/dd"
     }).datepicker( "setDate",endDate);
-    getStaticDate()
+    getStaticDate(flg)
     getBarData(dateType)
 }
-function getStaticDate(){
+function setCookieAction(startDate,endDate){
+    setCookie('behosDateStart',startDate)
+    setCookie('behosDateEnd',endDate)
+}
+function getStaticDate(flg){
     behosDateStart = $("#datepicker").val().trim()
     behosDateEnd = $("#datepicker2").val().trim()
     const start = new Date(behosDateStart).getTime()
     const end = new Date(behosDateEnd).getTime()
+    if(!getCookie("behosDateEnd")){
+        setCookie('behosDateStart',behosDateStart)
+        setCookie('behosDateEnd',behosDateEnd)
+    }
     if(start > end){
         $.alerModal({"message":'开始时间不能大于结束时间~',type:"tip",time:'1000',isFather: true, fatherWrapper: $("#mainBox", parent.document)});
         return false
     }
+    if(flg){
+        setCookieAction(behosDateStart,behosDateEnd)
+    }
     if(behosDateStart){
         behosDateStart = behosDateStart.replace(/\//g,'-') + ' 00:00:00'
     }

+ 2 - 0
src/js/index.js

@@ -209,6 +209,8 @@ function changeWord(oldword,newword){
   }).then(function(res){
     const data = res.data;
     if(data.code==='0'){
+      setCookie('behosDateStart','')
+      setCookie('behosDateEnd','')
       window.location.href = './login.html'
     }else{
       $(".oldWaring").html(data.msg)

+ 6 - 1
src/js/utils.js

@@ -95,6 +95,8 @@ const getUrlArgObjectNew = function(name,srcUrl) {
 const post = function (url, data) {
   const token = getCookie('accessToken') || localStorage.getItem('accessToken')
   if(!token&&window.location.href.indexOf('login')==-1){
+    setCookie('behosDateStart','')
+    setCookie('behosDateEnd','')
     window.location.href = "../login.html"
   }
   let need = window.location.href.indexOf('localhost')!=-1
@@ -118,6 +120,8 @@ const post = function (url, data) {
       },
       error: function (error) {
         if(error.status===403||error.status===401){
+          setCookie('behosDateStart','')
+          setCookie('behosDateEnd','')
           const wd = window.parent.window||window;
           wd.location.href = "../login.html";
         }
@@ -171,6 +175,8 @@ const post = function (url, data) {
 const expJson = (url,data) =>{
   const token = getCookie('accessToken')
   if(!token&&window.location.href.indexOf('login')==-1){
+    setCookie('behosDateStart','')
+    setCookie('behosDateEnd','')
     window.location.href = "../login.html"
   }
   let need = window.location.href.indexOf('localhost')!=-1
@@ -292,7 +298,6 @@ function picEmptyData(dom,str){
   $(dom).css({"position":"relative","display":"block"}).html(empty)
 }
 function setTitleTxt(dom,from){
-  console.log(dom,from)
   if(!from){
     $(dom?dom:".partTitle").find("a").remove()
   }