|
|
@@ -309,7 +309,7 @@
|
|
|
</div>
|
|
|
</el-dropdown-item>
|
|
|
<divider/>
|
|
|
- <el-dropdown-item style="display: flex;" @click="delAllTree" divided>
|
|
|
+ <el-dropdown-item style="display: flex;" @click="delNode" divided>
|
|
|
<el-icon class="el-icon--right" style="color: black;">
|
|
|
<CircleClose />
|
|
|
</el-icon>
|
|
|
@@ -883,6 +883,7 @@ const formZu = ref({
|
|
|
itemUnit:'',
|
|
|
itemNotes:'',
|
|
|
});
|
|
|
+const IdCount = ref(50)
|
|
|
const parId= ref('')
|
|
|
const formJi = ref({
|
|
|
name:'',
|
|
|
@@ -898,7 +899,7 @@ const rulesJi = reactive({
|
|
|
url: [{ required: true, message: '必填', trigger: 'blur' }],
|
|
|
cateCode: [{ required: true, message: '必填', trigger: 'blur' }],
|
|
|
});
|
|
|
-const byWhich = ref('input');
|
|
|
+const byWhich = ref('tree');
|
|
|
const formRefJi = ref();
|
|
|
const formAdd = ref({
|
|
|
name:'',
|
|
|
@@ -956,6 +957,35 @@ const filterNode = (value, data) => {
|
|
|
};
|
|
|
|
|
|
const copied = ref(false);
|
|
|
+async function delNode(){
|
|
|
+ removeNodeById(dataTreeReturn.value,parTreeId.value)
|
|
|
+}
|
|
|
+function removeNodeById(tree, targetId) {
|
|
|
+ // 检查树是否为空
|
|
|
+ if (!tree || !Array.isArray(tree) || tree.length === 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < tree.length; i++) {
|
|
|
+ const node = tree[i];
|
|
|
+
|
|
|
+ // 如果找到目标节点
|
|
|
+ if (node.id === targetId) {
|
|
|
+ tree.splice(i, 1); // 从数组中删除该节点
|
|
|
+ return true; // 返回删除成功
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果当前节点有子节点,递归遍历子节点
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ const isRemoved = removeNodeById(node.children, targetId);
|
|
|
+ if (isRemoved) {
|
|
|
+ return true; // 如果在子树中成功删除,直接返回
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false; // 未找到目标节点
|
|
|
+}
|
|
|
function byWay() {
|
|
|
byWhich.value = 'input'
|
|
|
}
|
|
|
@@ -1027,7 +1057,7 @@ function addSiblingNode(treeData, siblingId, newNode) {
|
|
|
const parentNode = findNode(treeData, siblingNode.parentId, 'id');
|
|
|
console.log(parentNode)
|
|
|
if (!parentNode&&siblingNode) {
|
|
|
- newNode.id = Math.random()
|
|
|
+ newNode.id = (IdCount.value++)*10
|
|
|
treeData.push(newNode);
|
|
|
return true;
|
|
|
}
|
|
|
@@ -1200,12 +1230,10 @@ function getParamName(paramCode) {
|
|
|
return nameMap[paramCode] || '';
|
|
|
}
|
|
|
async function saveEditService(){
|
|
|
- console.log(JsonAdd.value)
|
|
|
var valid
|
|
|
await formRefJi.value.validate((valid1) => {
|
|
|
valid = valid1
|
|
|
});
|
|
|
- console.log(valid)
|
|
|
if(valid){
|
|
|
console.log()
|
|
|
var par = formJi.value
|
|
|
@@ -1239,7 +1267,6 @@ async function saveEditService(){
|
|
|
if(byWhich.value==='input'){
|
|
|
var par = JSON.parse(dataJsonXiang.value)
|
|
|
var par1 = transformDynamicDataToTree(par)
|
|
|
- // par1.length = par1.length - 1
|
|
|
console.log(par1)
|
|
|
postReturnlist(par1).then(res=>{
|
|
|
if(res.code===200){
|
|
|
@@ -1249,18 +1276,11 @@ async function saveEditService(){
|
|
|
})
|
|
|
}
|
|
|
if(byWhich.value==='tree'){
|
|
|
+ // console.log(dataTreeReturn.value)
|
|
|
var par = JSON.parse(JSON.stringify(dataTreeReturn.value))
|
|
|
- par.forEach((item,index) => {
|
|
|
- if(item.children && item.children.length > 0){
|
|
|
- item = setArry(item)
|
|
|
- }
|
|
|
- });
|
|
|
- par.forEach((item,index) => {
|
|
|
- if(item.children && item.children.length > 0){
|
|
|
- item = setArrayId(item)
|
|
|
- }
|
|
|
- });
|
|
|
- postReturnlist(par).then(res=>{
|
|
|
+ var par1 = flattenTreeWithArrayIndex(par)
|
|
|
+ // console.log(par1)
|
|
|
+ postReturnlist(par1).then(res=>{
|
|
|
if(res.code===200){
|
|
|
proxy.$modal.msgSuccess("新增成功");
|
|
|
getTreeLeft()
|
|
|
@@ -1270,6 +1290,50 @@ async function saveEditService(){
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+function flattenTreeWithArrayIndex(treeData, parentId = 0, result = []) {
|
|
|
+ for (const node of treeData) {
|
|
|
+ // 创建新节点对象,避免污染原数据
|
|
|
+ const newNode = {
|
|
|
+ id: node.id,
|
|
|
+ parentId: parentId,
|
|
|
+ srvId: node.srvId,
|
|
|
+ paramCode: node.paramCode,
|
|
|
+ paramName: node.paramName,
|
|
|
+ paramType: node.paramType, // 注意保持原样,或根据需要调整大小写
|
|
|
+ paramValue: node.paramValue,
|
|
|
+ isArray: node.isArray,
|
|
|
+ arrayIndex: node.arrayIndex
|
|
|
+ // 可根据需要添加或删除其他属性
|
|
|
+ };
|
|
|
+ result.push(newNode);
|
|
|
+ // 处理当前节点的子节点
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ IdCount.value++
|
|
|
+ if (node.paramType === 'array') {
|
|
|
+ // 为 array 类型节点创建中间索引层级
|
|
|
+ var par = IdCount.value
|
|
|
+ const middleNode = {
|
|
|
+ id: par, // 使用随机ID
|
|
|
+ parentId: node.id,
|
|
|
+ srvId: node.srvId,
|
|
|
+ paramCode: '[0]', // 固定为 [0]
|
|
|
+ paramName: '', // 可为空
|
|
|
+ paramType: 'Object', // 通常为 Object
|
|
|
+ paramValue: '',
|
|
|
+ isArray: null, // 通常不是数组
|
|
|
+ arrayIndex: 0 // 数组索引
|
|
|
+ };
|
|
|
+ result.push(middleNode);
|
|
|
+ // 递归处理子节点,并将中间层节点作为它们的父节点
|
|
|
+ flattenTreeWithArrayIndex(node.children, par, result);
|
|
|
+ } else {
|
|
|
+ // 非 array 类型节点,直接递归处理子节点
|
|
|
+ flattenTreeWithArrayIndex(node.children, node.id, result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
async function addSer(){
|
|
|
console.log(JsonAdd.value)
|
|
|
var valid
|
|
|
@@ -1576,7 +1640,6 @@ async function getTreeLeft(){
|
|
|
data.value = res.data
|
|
|
})
|
|
|
optionsMdid.value = filterModelNodes(par)
|
|
|
- console.log(optionsMdid.value)
|
|
|
}
|
|
|
function renameTreeProperties(tree) {
|
|
|
// 深拷贝避免修改原始数据(可选,根据需求)
|