Browse Source

added 排序 and 总量

jason.lu 6 years ago
parent
commit
d1b136e4e8
6 changed files with 69 additions and 40 deletions
  1. 2 1
      js/basic.js
  2. 10 10
      js/common.js
  3. 4 4
      js/lazhang-data.js
  4. 8 7
      js/newCommon.js
  5. 42 17
      js/newRedrankvue.js
  6. 3 1
      lazhang.html

+ 2 - 1
js/basic.js

@@ -5,6 +5,7 @@
  *
  * */
 
+var showNetwork = false;
 
 function utils_get_param(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
@@ -94,7 +95,7 @@ function group_get_data(groupName, url, callback){
 }
 
 function parse_queue(){
-    console.log("Queue Length : " + Queue.list.length);
+    //console.log("Queue Length : " + Queue.list.length);
 
     if(Queue.temporary > new Date().getTime()){
         for(i = 0; i < Queue.list.length; i++) {

+ 10 - 10
js/common.js

@@ -47,8 +47,8 @@ var badfailrate1 = [];
 function history_success(obj, sta) {
     var histoire = first_parse(this, obj);
     var i, j, t;
-    console.log(" histoire : ");
-    console.log(histoire);
+    if(showNetwork) console.log(" histoire : ");
+    if(showNetwork) console.log(histoire);
     if (this.url.indexOf("type=1") >= 0) {
         t = 1;
     } else if (this.url.indexOf("type=2") >= 0) {
@@ -126,8 +126,8 @@ function on_red_rank_success(obj, sta) {
     var redchart = first_parse(this, obj);
     var i, j;
     i = j = 0;
-    console.log(" redchart : ");
-    console.log(redchart);
+    if(showNetwork) console.log(" redchart : ");
+    if(showNetwork) console.log(redchart);
     for (i = 0; i < redchart.list.length; i++) {
         goodid[i] = getUserName(redchart.list[i].workerId);
         goodpass[i] = redchart.list[i].passNum;
@@ -149,8 +149,8 @@ function on_red_rank_success1(obj, sta) {
     var redchart = first_parse(this, obj);
     var i, j;
     i = j = 0;
-    console.log(" redchart : ");
-    console.log(redchart);
+    if(showNetwork) console.log(" redchart : ");
+    if(showNetwork) console.log(redchart);
     for (i = 0; i < redchart.list.length; i++) {
         goodid1[i] = getUserName(redchart.list[i].workerId);
         goodpass1[i] = redchart.list[i].passNum;
@@ -172,8 +172,8 @@ function on_black_rank_success(obj, sta) {
     var blackchart = first_parse(this, obj);
     var i, j;
     i = j = 0;
-    console.log(" black chart : ");
-    console.log(blackchart);
+    if(showNetwork) console.log(" black chart : ");
+    if(showNetwork) console.log(blackchart);
     for (i = 0; i < blackchart.list.length; i++) {
         badid[i] = getUserName(blackchart.list[i].workerId);
         badpass[i] = blackchart.list[i].passNum;
@@ -197,8 +197,8 @@ function on_black_rank_success1(obj, sta) {
     var blackchart = first_parse(this, obj);
     var i, j;
     i = j = 0;
-    console.log(" black chart : ");
-    console.log(blackchart);
+    if(showNetwork) console.log(" black chart : ");
+    if(showNetwork) console.log(blackchart);
     for (i = 0; i < blackchart.list.length; i++) {
         badid1[i] = getUserName(blackchart.list[i].workerId);
         badpass1[i] = blackchart.list[i].passNum;

+ 4 - 4
js/lazhang-data.js

@@ -93,8 +93,8 @@ function first_success(obj, sta) {
 function name_Success(obj, sta) {
     var factory = first_parse(this, obj);
     var i, j, t;
-    console.log(" factory : ");
-    console.log(factory);
+    if(showNetwork) console.log(" factory : ");
+    if(showNetwork) console.log(factory);
 
     name1=factory.list[0].flowPlace;
     name2=factory.list[0].flowName;
@@ -258,8 +258,8 @@ function add_success(obj, sta) {
 function realtime_success(obj, sta) {
     var output = first_parse(this, obj);
     //在这里排序 spo\
-    console.log(" output : ");
-    console.log(output);
+    if(showNetwork) console.log(" output : ");
+    if(showNetwork) console.log(output);
 
     var i, j, k, z;
     failnum = 0;

+ 8 - 7
js/newCommon.js

@@ -38,12 +38,13 @@ const DataObjectList = function (name) {
      * @param comparator (a,b)  =====>  a - b
      */
   this.sortBy = function (comparator) {
+    this.isSorted = true;
     this.comparisonBasis = comparator;
     this.preSort = [];
     for (let i = 0; i < this.list.length; i++) {
       this.preSort.push(this.list[i]);
     }
-    this.quickSort(this.preSort, 0, this.preSort.length - 1, this.comparisonBasis);
+    this.quickSort(this.preSort, 0, this.preSort.length - 1, this.comparisonBasis, this);
   };
 
   this.clearData = function () {
@@ -80,7 +81,7 @@ const DataObjectList = function (name) {
     if (!this.isSorted) return this.getRaw(index);
     return this.preSort[index];
   };
-  this.quickSort = function (a, left, right, comp) {
+  this.quickSort = function (a, left, right, comp, obj) {
     var inputVar = a;
     if (left > right) { // 一定要有这个判断,因为有递归left和i-1,若没有这个判断条件,该函数会进入无限死错位递归
       return;
@@ -102,8 +103,8 @@ const DataObjectList = function (name) {
     inputVar[left] = inputVar[i];// 交换基准数和k位置上的数
     inputVar[i] = pivot;
 
-    this.quicksort(inputVar, left, i - 1, comp);
-    this.quicksort(inputVar, i + 1, right, comp);
+    obj.quickSort(inputVar, left, i - 1, comp, obj);
+    obj.quickSort(inputVar, i + 1, right, comp, obj);
   };
 };
 
@@ -215,11 +216,11 @@ const Module = function (chartContainerSelector, dataCtlName) {
      */
   this.setData = function (data) {
     if (data.ctlName === this.dataCtl) {
-      console.log(`-------- Module ${this.selector} got data ----------- `);
+      if(showNetwork) console.log(`-------- Module ${this.selector} got data ----------- `);
       this.activeData = data;
       this.drawData(this.activeData);
     } else {
-      console.log(`-------- Module ${this.selector} cannot use data of ${data.ctlName} ----------- `);
+      if(showNetwork) console.log(`-------- Module ${this.selector} cannot use data of ${data.ctlName} ----------- `);
     }
   };
   this.init = function () {
@@ -232,7 +233,7 @@ const Module = function (chartContainerSelector, dataCtlName) {
   this.setupInterval = function () {
     // do tick
     if (this.tickInterval !== 0) clearInterval(this.tickInterval);
-    this.tickInterval = setInterval(this.tick, this.tickInterval);
+    this.tickInterval = setInterval(this.tick, this.tickInterval, this);
   };
   this.drawData = function () {
     // do drawData

+ 42 - 17
js/newRedrankvue.js

@@ -3,10 +3,10 @@
 
 var RedRankTable = new Module("#table-rank", "fcBiWorkerDaily");
 
-RedRankTable.slideLen = 16;
 RedRankTable.slides   = 0;
-RedRankTable.parts    = 4;
+RedRankTable.parts    = 3;
 RedRankTable.partLen  = 4;
+RedRankTable.slideLen = RedRankTable.parts * RedRankTable.partLen;
 RedRankTable.curSlide = 0;
 
 RedRankTable.drawData = function (data) {
@@ -27,10 +27,11 @@ RedRankTable.showPart = function(slide, part, data){
     for (var i = lpos; i < rpos; i++) {
         var one = data.getSorted(i);
         if(one == null || one === undefined) {
-            partList[partList.length] = {passNum : 0, failNum: 0, failRate: 0, workerId: 0, fcDay: new Date().toLocaleDateString()};
+            partList[partList.length] = {passNum : 0, failNum: 0, failRate: 0, totalNum:0, workerId: 0, fcDay: new Date().toLocaleDateString()};
         } else {
             partList[partList.length] = one.jsonObj;
             partList[partList.length - 1].failRate = partList[partList.length - 1].failRate/100.0;
+            partList[partList.length - 1].totalNum = partList[partList.length - 1].failNum + partList[partList.length - 1].passNum;
         }
         partList[partList.length - 1].workerName = getUserName(partList[partList.length - 1].workerId);
         if("[用户:"+0+"]" === partList[partList.length - 1].workerName){
@@ -50,14 +51,14 @@ RedRankTable.showPart = function(slide, part, data){
     }
 };
 
-RedRankTable.tickInterval = 1000;
-RedRankTable.tick = function(){
-    var totalDataLen = this.activeData != null ? this.activeData.len() : 0;
-    if(this.slides !== Math.ceil(totalDataLen / this.slideLen)){
-        this.slides = Math.ceil(totalDataLen / this.slideLen);
-        this.curSlide = 0;
+RedRankTable.tickInterval = 2000;
+RedRankTable.tick = function(obj){
+    var totalDataLen = obj.activeData != null ? obj.activeData.len() : 0;
+    if(obj.slides !== Math.ceil(totalDataLen / obj.slideLen)){
+        obj.slides = Math.ceil(totalDataLen / obj.slideLen);
+        obj.curSlide = 0;
     } else {
-        this.curSlide = (this.curSlide + 1) % this.slides;
+        obj.curSlide = (obj.curSlide + 1) % obj.slides;
     }
 };
 
@@ -67,9 +68,19 @@ RedRankTable.init();
 
 var newRedrankvue = new Vue({
     el: '#redrank',
-    data: {
-        parting:[[{},{},{},{}], [{},{},{},{}], [{},{},{},{}], [{},{},{},{}]],
-        title: '本厂今日生产能手榜'
+    data: function () {
+        var t = [];
+        for(let i = 0; i < RedRankTable.parts; i++){
+            var q = [];
+            for(let j = 0; j < RedRankTable.partLen ; j++){
+                q[j] = {};
+            }
+            t[i] = q;
+        }
+        return {
+            parting : t,
+            title: '本厂今日生产能手榜'
+        }
     },
     methods: {
         clicktitle: function () {
@@ -87,20 +98,26 @@ var newRedrankvue = new Vue({
         useRate: function () {
             this.useSort("Rate");
         },
+        useTotal: function () {
+            this.useSort("Total");
+        },
         useSort: function (column) {
             let sorter = function () {};
             switch (column) {
                 case "Pass":
-                    return RedRankTablePlugin.sortPass;
+                    sorter = RedRankTablePlugin.sortPass;
 
                 case "Fail":
-                    return RedRankTablePlugin.sortFail;
+                    sorter = RedRankTablePlugin.sortFail;
 
                 case "Rate":
-                    return RedRankTablePlugin.sortRate;
+                    sorter = RedRankTablePlugin.sortRate;
+
+                case "Total":
+                    sorter = RedRankTablePlugin.sortTotal;
 
                 case "Id":
-                    return RedRankTablePlugin.sortId;
+                    sorter = RedRankTablePlugin.sortId;
             }
             RedRankTablePlugin.workerDailyService.list.sortBy(sorter);
             console.warn(column);
@@ -132,6 +149,14 @@ var RedRankTablePlugin = new (function() {
         return t;
     };
 
+    this.sortTotal = function (l, r){
+        var q = {};
+        checkNull(l, r, q);
+        if(q.out !== -2) return q.out;
+        var t = calcCompare(l.jsonObj.failNum + l.jsonObj.passNum, r.jsonObj.failNum + r.jsonObj.passNum, q);
+        return t;
+    };
+
     function checkNull(l, r, q) {
         if (l.jsonObj == null || l.jsonObj === undefined) {
             if (r.jsonObj == null || r.jsonObj === undefined) {

+ 3 - 1
lazhang.html

@@ -154,13 +154,14 @@
         <div class="col-md-9 text-white" style="height: 30vh" id="redrank">
             <div class="text-center text-lg big-letter" @click="clicktitle">{{title}}</div>
             <div class="row">
-                <div class="col-md-3" v-for="parto in parting">
+                <div class="col-md-4" v-for="parto in parting">
                     <table class="table table-bordered text-center table-striped">
                         <thead>
                         <tr>
                             <th @click="useId">人员</th>
                             <th @click="usePass">良品</th>
                             <th @click="useFail">坏品</th>
+                            <th @click="useTotal">总量</th>
                             <th @click="useRate">不良率</th>
                         </tr>
                         </thead>
@@ -169,6 +170,7 @@
                                 <td>{{one.workerName}}</td>
                                 <td>{{one.failNum}}</td>
                                 <td>{{one.passNum}}</td>
+                                <td>{{one.totalNum}}</td>
                                 <td>{{one.failRate}} %</td>
                             </tr>
                         </tbody>