lrf 2 年之前
父節點
當前提交
d7f79d8e1a
共有 1 個文件被更改,包括 37 次插入2 次删除
  1. 37 2
      pagesMatch/matchAdmin/elimmatch/add.js

+ 37 - 2
pagesMatch/matchAdmin/elimmatch/add.js

@@ -19,7 +19,7 @@ Page({
         schList: [],
         playerList: [],
         canvasWidth: 375,
-        canvasHeight: 300,
+        canvasHeight: 600,
         pixelRatio: 2,
         edgeSetting,
         nodeSetting,
@@ -150,13 +150,13 @@ Page({
         let arr;
         arr = await app.$get(`${prefix}/eliminate`, { match_id: match_id, group_id: group_id, project_id: project_id }, 'race');
         if (arr.errcode == '0' && arr.total > 0) {
-            console.log(arr.data.length);
             for (const val of arr.data) {
                 this.setNodeInfo(val)
                 // 状态
                 this.setStatus(val);
             }
             that.setData({ schList: arr.data });
+            this.setTopPlayerName();
         }
     },
     /**
@@ -197,6 +197,41 @@ Page({
         let status = this.data.statusList.find(i => i.value == data.status)
         if (status) data.zhStatus = status.label;
     },
+    /**
+     * 给所有顶点去找到选手
+     */
+    setTopPlayerName() {
+        const func = type => {
+            const { nodes, edges } = this.data[`${type}Data`];
+            // 顶点:是其他的target且不是任何节点的source
+            const tops = nodes.filter(f => {
+                const { id } = f;
+                const r = edges.find(f => f.source === id)
+                if (!r) return true
+            })
+            if (tops.length <= 0) return;
+            for (const t of tops) {
+                const { id } = t;
+                const es = edges.filter(f => f.target === id)
+                const ns = nodes.filter(f => es.find(ef => ef.source === f.id))
+                const headNodeId = ns[0]?.id;
+                const lastNodeId = ns[ns.length - 1]?.id
+                const r = this.data.schList.find(f => (f.player_one_node === headNodeId && f.player_two_node === lastNodeId) || (f.player_one_node === lastNodeId && f.player_two_node === headNodeId))
+                if (!r) continue;
+                const { player_one_score, player_one_name, player_two_score, player_two_name, status } = r
+                // 未结束不查
+                if (status !== '2') continue;
+                if (player_one_score > player_two_score) t.name = player_one_name
+                else t.name = player_two_name
+                const ri = nodes.findIndex(f => f.id === t.id)
+                nodes[ri] = t;
+            }
+            this.setData({ [`${type}Data.nodes`]: nodes })
+        }
+        func('win')
+        func('lose')
+
+    },
 
 
     /**