|
@@ -1,7 +1,34 @@
|
|
|
const app = getApp();
|
|
|
+const nodeSetting = function (node) {
|
|
|
+ node.label = node.name
|
|
|
+ return node;
|
|
|
+};
|
|
|
+const edgeSetting = function (edge) {
|
|
|
+ return edge;
|
|
|
+}
|
|
|
Page({
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '添加赛程', leftArrow: true, useBar: false },
|
|
|
+ loadChart: false,
|
|
|
+ winData: {},
|
|
|
+ loseData: {},
|
|
|
+ schList: [],
|
|
|
+ playerList: [],
|
|
|
+ canvasWidth: 375,
|
|
|
+ canvasHeight: 300,
|
|
|
+ pixelRatio: 2,
|
|
|
+ edgeSetting,
|
|
|
+ nodeSetting,
|
|
|
+ tabs: {
|
|
|
+ active: 'a',
|
|
|
+ menu: [
|
|
|
+ { title: '比赛流程', active: 'a' },
|
|
|
+ { title: '败者组流程', active: 'b' },
|
|
|
+ { title: '赛事赛程', active: 'c' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ show: false,
|
|
|
+ selectNode: {}
|
|
|
},
|
|
|
// 返回
|
|
|
back: function () { wx.navigateBack({ delta: 1 }) },
|
|
@@ -9,58 +36,175 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad: function (options) { },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady: function () { },
|
|
|
+ onLoad: function (options) {
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
/**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
+ * 查询函数
|
|
|
*/
|
|
|
- onShow: function () {
|
|
|
- const that = this;
|
|
|
- // 监听用户是否登录
|
|
|
- that.watchLogin();
|
|
|
- },
|
|
|
- // 监听用户是否登录
|
|
|
- watchLogin: async function () {
|
|
|
- const that = this;
|
|
|
- wx.getStorage({
|
|
|
- key: 'raceuser',
|
|
|
- success: async res => { },
|
|
|
- fail: async res => {
|
|
|
- wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ async search() {
|
|
|
+ const match_id = '630ec4700a92b0a015ccfd14';
|
|
|
+ const group_id = "6318277947be96470e849b6a";
|
|
|
+ const project_id = '631827f047be96470e849bc1'
|
|
|
+ wx.request({
|
|
|
+ url: `http://192.168.1.197:15001/newCourt/race/v2/api/eliminate/graphData?match_id=${match_id}&group_id=${group_id}&project_id=${project_id}`,
|
|
|
+ success: (res) => {
|
|
|
+ let data = res?.data?.data
|
|
|
+ const { winData, loseData } = this.groupData(data);
|
|
|
+ const schList = this.schData(data)
|
|
|
+ this.setData({ winData, loseData, schList })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ wx.request({
|
|
|
+ url: `http://192.168.1.197:15001/newCourt/race/v2/api/eliminate/playerList?match_id=${match_id}&group_id=${group_id}&project_id=${project_id}`,
|
|
|
+ success: (res) => {
|
|
|
+ const playerList = res?.data?.data
|
|
|
+ this.setData({ playerList })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
/**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
+ * 选中选手的处理
|
|
|
+ * @param {Object} selected 选中的选手数据
|
|
|
*/
|
|
|
+ selectPlayer({ detail: selected }) {
|
|
|
+ let node = this.data.selectNode;
|
|
|
+ const { _id: player_id, name } = selected
|
|
|
+ node = { ...node, player_id, name }
|
|
|
+ let targetData;
|
|
|
+ let type;
|
|
|
+ if (node.mark && !node.mark.includes('w')) {
|
|
|
+ // 需要进入胜者节点中进行查找
|
|
|
+ targetData = this.data.loseData.nodes
|
|
|
+ type = 'lose'
|
|
|
+ } else {
|
|
|
+ targetData = this.data.winData.nodes
|
|
|
+ type = 'win'
|
|
|
+ }
|
|
|
+ const i = targetData.findIndex(f => f.id === node.id)
|
|
|
+ if (i < 0) {
|
|
|
+ console.warn('未在合理的范围内找到更改的节点')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ targetData[i] = node;
|
|
|
+ this.setData({ [`${type}Data.nodes`]: targetData })
|
|
|
+ // 修改赛程部分
|
|
|
+ // 找到该节点的数据
|
|
|
+ const schList = this.data.schList;
|
|
|
+ const sch = schList.find(f => f.player_one_node === node.id || f.player_two_node === node.id)
|
|
|
+ if (!sch) {
|
|
|
+ console.warn('没找到该节点所在的赛程')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (sch.player_one_node === node.id) {
|
|
|
+ sch.player_one = node.player_id;
|
|
|
+ sch.player_one_name = node.name;
|
|
|
+ } else {
|
|
|
+ sch.player_two = node.player_id;
|
|
|
+ sch.player_two_name = node.name;
|
|
|
+ }
|
|
|
+ const schIndex = schList.findIndex(f => f.player_one_node === node.id || f.player_two_node === node.id)
|
|
|
+ schList.splice(schIndex, 1, sch)
|
|
|
+ this.setData({ schList })
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
+ * 选择节点并存储在selectNode变量中
|
|
|
+ * @param {Object} node 节点数据
|
|
|
*/
|
|
|
- onHide: function () {
|
|
|
-
|
|
|
+ nodeSelect({ detail: node }) {
|
|
|
+ this.setData({ show: true, selectNode: node })
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
+ * 给流程图数据分组
|
|
|
+ * @param {Array} data 流程图数据
|
|
|
*/
|
|
|
- onUnload: function () {
|
|
|
-
|
|
|
+ groupData(data) {
|
|
|
+ const { nodes, edges } = data;
|
|
|
+ // 按胜/败进行分组,显示在2个选项卡中
|
|
|
+ const winNodes = nodes.filter(f => !f.mark || f.mark.includes('w'))
|
|
|
+ const winEdges = this.getNodesEdges(winNodes, edges);
|
|
|
+ const loseNodes = nodes.filter(f => f.mark && !f.mark.includes('w'))
|
|
|
+ const loseEdges = this.getNodesEdges(loseNodes, edges);
|
|
|
+ return { winData: { nodes: winNodes, edges: winEdges }, loseData: { nodes: loseNodes, edges: loseEdges } }
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ * 获取该图中的赛程列表
|
|
|
+ * @param {Object} data 流程图数据
|
|
|
*/
|
|
|
- onPullDownRefresh: function () {
|
|
|
-
|
|
|
+ schData(data) {
|
|
|
+ const { edges } = data;
|
|
|
+ let stop = false;
|
|
|
+ const schList = [];
|
|
|
+ let dupAll = JSON.parse(JSON.stringify(edges))
|
|
|
+ while (!stop) {
|
|
|
+ const dup = JSON.parse(JSON.stringify(dupAll))
|
|
|
+ // 取出第一个关系
|
|
|
+ const head = dup[0]
|
|
|
+ // 删除第一个关系
|
|
|
+ dup.shift();
|
|
|
+ // 查看是否有与第一个关系指向一个目标的地方
|
|
|
+ const r = dup.find(f => f.target === head.target)
|
|
|
+ if (r) {
|
|
|
+ // 有,则将这俩关系组为一个比赛,然后在dup中删除
|
|
|
+ const sch = { player_one_node: head.source, player_two_node: r.source }
|
|
|
+ schList.push(sch)
|
|
|
+ const ri = dup.find(f => f.target === head.target)
|
|
|
+ dup.splice(ri, 1)
|
|
|
+ }
|
|
|
+ dupAll = dup;
|
|
|
+ if (dupAll.length <= 0) stop = true
|
|
|
+ }
|
|
|
+ return schList;
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * 用户点击右上角分享
|
|
|
+ * 找到这些节点的边关系
|
|
|
+ * @param {Array} list 节点数据
|
|
|
+ * @param {Array} edges 所有的辺数据
|
|
|
*/
|
|
|
- onShareAppMessage: function () {
|
|
|
+ getNodesEdges(list, edges) {
|
|
|
+ const fedges = [];
|
|
|
+ for (let i = 0; i < list.length; i += 2) {
|
|
|
+ const n1 = list[i];
|
|
|
+ const n2 = list[i + 1]
|
|
|
+ const n1id = n1.id;
|
|
|
+ const n2id = n2.id
|
|
|
+ if (!n1id || !n2id) continue;
|
|
|
+ const n1e = edges.find(f => f.source === n1id)
|
|
|
+ const n2e = edges.find(f => f.source === n2id)
|
|
|
+ if (!n1e || !n2e) continue;
|
|
|
+ const n1et = n1e.target;
|
|
|
+ const n2et = n2e.target;
|
|
|
+ if (n1et === n2et) fedges.push(n1e, n2e)
|
|
|
+ }
|
|
|
+ return fedges;
|
|
|
+ },
|
|
|
|
|
|
- }
|
|
|
+ tabsChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let { active } = e.detail;
|
|
|
+ that.setData({ 'tabs.active': active });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow: function () {
|
|
|
+ this.setData({ loadChart: true })
|
|
|
+ const that = this;
|
|
|
+ // 监听用户是否登录
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
+ // 监听用户是否登录
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'raceuser',
|
|
|
+ success: async res => { },
|
|
|
+ fail: async res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
})
|