Browse Source

update fix

jason.lu 6 years ago
parent
commit
f20493fd44
3 changed files with 63 additions and 45 deletions
  1. 17 7
      js/basic.js
  2. 43 35
      js/newData.js
  3. 3 3
      lazhang.html

+ 17 - 7
js/basic.js

@@ -16,7 +16,16 @@ function reloadPage(){
     location.reload()
 }
 
-let Queue = {THRESHOLD: 1000, IS_LOADED : false, nowuse : 0, SVR_URL:"http://localhost:8803/server/", groupsCount : 0, groups:[], shouldStop : false, backup:["http://localhost:8803/server/","/server/","http://172.30.84.3:8803/server/","https://1.niimei.com/server/"] ,list:[], temporary:0, errorCount:0};
+let Queue = {THRESHOLD: 1000,
+    IS_LOADED : false,
+    nowuse : 0, SVR_URL:"http://localhost:8803/server/",
+    groupsCount : 0, groups:[],
+    shouldStop : false,
+    backup:["http://localhost:8803/server/",
+        "/server/",
+        "http://172.30.84.3:8803/server/","https://1.niimei.com/server/"] ,
+    list:[], temporary:0, errorCount:0};
+
 let Users = {list : []};
 let Sectors = {list : []};
 
@@ -50,8 +59,8 @@ function on_check_fail(){
     }
 }
 
-function get_data(url, callback) {
-    Queue.list.push({url:url, callback:callback, gid:-1});
+function get_data(url, callback, scope) {
+    Queue.list.push({url:url, callback:callback, gid:-1, scope:scope});
 }
 
 function new_data_group(groupName, callback){
@@ -98,9 +107,9 @@ function parse_queue(){
     if(Queue.list.length > 0){
         let one = Queue.list.pop();
         if(one.gid === -1) {
-            request_data(one.url, one.callback);
+            request_data(one.url, one.callback, one.scope);
         }else{
-            g_request_data(one.url, one.callback, one.gid);
+            g_request_data(one.url, one.callback, one.gid, one.scope);
         }
     }
     if(Queue.shouldStop == false) {
@@ -108,12 +117,13 @@ function parse_queue(){
     }
 }
 
-function request_data(url, callback){
+function request_data(url, callback, scope){
     $.ajax({
         url: Queue.SVR_URL + url,
         apiName: url,
         sendTime: new Date(),
-        callme: callback
+        callme: callback,
+        callerThis: scope
     }).done(on_dat_success).fail(on_fail);
 }
 

+ 43 - 35
js/newData.js

@@ -53,7 +53,7 @@ var DataObjectList = function(name){
         quickSort(this.preSort, 0, this.preSort.length - 1, function(l, r){});
     };
 
-    function clearData() {
+    this.clearData = function () {
         this.isSorted = false;
         this.preSort = null;
         this.list = null;
@@ -132,27 +132,28 @@ var DataObjectService = function(controlName, syncType, extparm){
     this.list       = new DataObjectList(controlName);
     this.autoUpdateTimer = 0;
     this.autoInterval = 1000;
+    this.callerThis = this;
 
-    function setUpInterval() {
+    this.setUpInterval = function() {
         //URL + exparm
         if(this.autoUpdateTimer != 0) clearInterval(this.autoUpdateTimer);
-        this.autoUpdateTimer = setInterval(this.selfUpdateTick, this.autoInterval);
-        setTimeout(this.selfUpdateTick, 100);
+        this.autoUpdateTimer = setInterval(this.selfUpdateTick, this.autoInterval, this);
+        setTimeout(this.selfUpdateTick, 1000, this);
     }
 
     this.init = function(){
-        this.appUrl = "/server/"+ controlName + "/list" + extparm;
+        this.appUrl = controlName + "/list" + extparm;
         if(!this.isFast || this.isOnDemand){
-            this.autoInterval = 30000;
+            this.autoInterval = 300;
         }
 
         if(this.isFast) {
-            this.appUrl = "/server/"+ controlName + "/get" + extparm;
+            this.appUrl = controlName + "/get" + extparm;
         }
 
         if(this.isAuto){
             // timer
-            setUpInterval();
+            this.setUpInterval();
         }
     };
 
@@ -161,35 +162,40 @@ var DataObjectService = function(controlName, syncType, extparm){
         this.autoUpdateTimer = 0;
     };
 
-    this.selfUpdateTick = function(){
-        get_data(this.appUrl, this.onDataReceived);
+    /***
+     * Automatica Update Tick, where obj is a replacement for "this" where "this" might be incorrect
+     * @param obj : DataObjectService
+     */
+    this.selfUpdateTick = function(obj){
+        get_data(obj.appUrl, obj.onDataReceived, obj);
     };
 
-    this.onDemandUpdate = function(){
-        get_data(this.appUrl, this.onDataReceived);
+    this.onDemandUpdate = function(obj){
+        get_data(obj.appUrl, obj.onDataReceived, obj);
     };
 
     this.onDataReceived = function(data, sta){
-        let output = first_parse(this, obj);
+        let obj = this.callerThis;
+        if(obj == undefined){console.error("Cannot get callerThis in onDataReceived, please check"); console.error(this)}
+        let output = first_parse(this, data);
         if (output.list == undefined || output.list.length == 0) {
-            this.failedCount++;
-            if(this.failedCount > 100){
-                this.failedCount = 0;
-                this.stopTimers();
-                console.log("【错误次数过多");
-                setTimeout(this.setUpInterval, 10000);
+            obj.failedCount++;
+            if(obj.failedCount > 100){
+                obj.failedCount = 0;
+                obj.stopTimers();
+                console.log("【错误次数过多】,暂停");
             }
-            if(this.failedCount == 2) {
+            if(obj.failedCount == 2) {
                 send_alert("没有数据,请尝试重新加载!【DataService】: ctlName[" + controlName + "],  extParm[" + extparm + "]");
             }
         }else{
-            this.list.assignJsonData(output.list);
+            obj.list.assignJsonData(output.list);
         }
     };
 
     this.getList = function () {
         return this.list;
-    }
+    };
 
     this.passiveUpdate = function(data){
         this.failedCount = 0;
@@ -268,7 +274,7 @@ RedRankTable.showPart = function(slide, part, data){
     redrankvue.part[part] = partList;
 };
 
-RedRankTable.tickInterval = 10000;
+RedRankTable.tickInterval = 1000;
 RedRankTable.tick = function(){
     var totalDataLen = this.activeData != null ? this.activeData.len() : 0;
     if(this.slides != Math.ceil(totalDataLen / this.slideLen)){
@@ -378,14 +384,14 @@ var FlowRealTime = new (function () {
             console.warn(obj);
             send_alert("发送清空请求成功, 正在等待采集端进行处理...");
             this.finished = false;
-            setTimeout(this.resultVerifyTimeout, 8000);
-            setTimeout(this.getVerify, 300);
+            setTimeout(this.resultVerifyTimeout, 8000, this);
+            setTimeout(this.getVerify, 300, this);
         }
 
-        this.getVerify = function () {
-            if (this.finished) return;
-            get_data("endpoint/heartbeat?flowId=" + flowId, this.onVerifyResult);
-            setTimeout(this.getVerify, 100);
+        this.getVerify = function (obj) {
+            if (obj.finished) return;
+            get_data("endpoint/heartbeat?flowId=" + flowId, obj.onVerifyResult);
+            setTimeout(obj.getVerify, 100, obj);
         };
 
         this.onVerifyResult = function (obj, sta) {
@@ -423,7 +429,7 @@ var FlowRealTime = new (function () {
             }
         }
 
-        this.resultVerifyTimeout = function () {
+        this.resultVerifyTimeout = function (obj) {
             finished = true;
             if (executed) {
                 // 执行成功
@@ -447,11 +453,13 @@ var FlowRealTime = new (function () {
 var redrankvue = new Vue({
     el: '#redrank',
     data: {
-        part:[
-            [],
-            []
-        ],
-        message: 'Hello Vue.js!'
+        part:[],
+        title: '本厂今日生产能手榜'
+    },
+    methods: {
+        clicktitle: function () {
+            alert("Hello! This is Title");
+        }
     }
 });
 

+ 3 - 3
lazhang.html

@@ -1,4 +1,4 @@
-<html>
+<html xmlns:v-on="http://www.w3.org/1999/xhtml">
 <head>
     <meta charset="UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=Edge">
@@ -88,7 +88,7 @@
                 </div>
             </li>
             <li class="nav-item">
-                <a class="nav-link bg-red text-white" href="javascript:void" id="flow_title">深圳市度彼电子有限公司</a>
+                <a class="nav-link bg-red text-white" href="javascript:void;" id="flow_title">深圳市度彼电子有限公司</a>
             </li>
         </ul>
         <div class="form-inline my-2 my-lg-0 text-white" >
@@ -152,7 +152,7 @@
             </table>
         </div>
         <div class="col-md-9 text-white" style="height: 30vh" id="redrank">
-            <div class="text-center text-lg big-letter">本厂今日生产能手榜</div>
+            <div class="text-center text-lg big-letter" @click="clicktitle">{{title}}</div>
             <div class="row">
                 <div class="col-md-3">
                     <table class="table table-bordered text-center table-striped">