From dfd7249fad876dee96480d70ff6f5ebd60207617 Mon Sep 17 00:00:00 2001 From: zhiyong.zhou <zhiyong.zhou@highdatas.com> Date: 星期一, 04 三月 2024 18:11:06 +0800 Subject: [PATCH] 树形方法写到工具类中 --- src/utils/utils.js | 72 ++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index d201755..f5e1761 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -37,5 +37,77 @@ return data; }, + convertToTreeData(data, parent,index,parentId) { + const tempJson = data.find(f => + f.index_no === index + ) + parent.children = { + "id": tempJson.id, + "parentId": parentId, + "name": "瀹℃壒浜�", + "type": "APPROVAL", + "children":{},//蹇呴』瑕� 涓嶇劧閫変腑鐨勫�兼棤娉曚紶閫� + "props": + { + "assignedType": "ASSIGN_USER", + "nobody": { + "handler": "TO_PASS", + "assignedUser": [] + }, + "refuse": { + "type": "TO_END", + "target": "" + }, + "assignedUser": [{"id": tempJson.board_id||tempJson.rule_code, "name": tempJson.name,"type":tempJson.board_id!=null?"group":"staff"}], + "approvalGroup":tempJson.board_id!=null?{"id":tempJson.board_id,"name":tempJson.name}:"", + "staffGroup":tempJson.board_id!=null?"":{"id":tempJson.rule_code,"name":tempJson.name}, + } + } + //鑺傜偣鏁扮粍鐨勫ぇ灏� 澶т簬褰撳墠寰幆鐨� 璇存槑杩樻湁瀛愰」 缁х画寰幆 + if (data.length >index) { + let getChildren = this.convertToTreeData(data, parent.children, index+1,parent.children.id) + parent.children=getChildren + } + return parent; + }, + //瀹℃壒娴佹爲褰㈢粨鏋勮浆鎹负json + dataTree(data, index, parentId) { + let result = [];//瀛樻斁缁撴灉 + let names = [];//瀛樻斁瀹℃壒浜� + let ruleCode = [];//鏋舵瀯缁� + data.props.assignedUser.forEach(org => names.push(org.name)); + let ids = [] + data.props.assignedUser.forEach(org => ids.push(org.id)); + // 淇敼鐨勬椂鍊� 鏍规嵁閫変腑绫诲瀷鏄灦鏋勮繕鏄鎵圭粍 娓叉煋鏁版嵁 + if(data.props.assignedUser[0].type==='staff'){ + ids = []; + data.props.assignedUser.forEach(org => ruleCode.push(org.id)); + }else{ + //鍒ゆ柇閫変腑鐨勬暟鎹被鍨嬫槸鏋舵瀯杩樻槸瀹℃壒缁� 濡傛灉鏄灦鏋� 灏嗗鎵圭粍娓呯┖ board_id缃负绌� + if (data.props.staffGroup!=undefined&& Object.keys(data.props.staffGroup).length!==0) { + ids = []; + data.props.assignedUser.forEach(org => ruleCode.push(org.id)); + } + } + + //鎻掑叆娴佺▼鏁扮粍椤� + result.push( + { + name: String(names).replaceAll(',', '銆�'), + id: data.id||'', + parent_id: parentId||'', + index_no: index, + board_id: ids.length > 0 ? String(ids).replaceAll(',', '銆�') : null, + rule_code: ruleCode.length > 0 ? String(ruleCode).replaceAll(',', '銆�') : null + } + ) // 鍙彇褰撳墠鑺傜偣鐨勪俊鎭紝涓嶅寘鎷� children + //濡傛灉涓嬮潰杩樻湁瀛愰」 缁х画寰�涓嬭鏁版嵁 + if (data.children!==undefined&&Object.keys(data.children).length !== 0) { + let getChildren = this.dataTree(data.children, index + 1, parentId) + result = result.concat(getChildren) + } + + return result + }, }; \ No newline at end of file -- Gitblit v1.8.0