Commit c47c9093 by liyaoting

优化

1 parent 11781dc7
Showing 1 changed file with 93 additions and 10 deletions
......@@ -21,7 +21,12 @@
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="btn btn-danger navbar-btn" @click="cleanInput">清除输入</button>
<a class="navbar-brand" href="">happy~happy~happy~</a>
<div class="btn-group navbar-btn" role="group" aria-label="...">
<button type="button" class="btn btn-default" @click="selectAll(1)">全选</button>
<button type="button" class="btn btn-default" @click="selectAll(2)">全不选</button>
</div>
<button type="button" class="btn btn-default navbar-btn" @click="copyNew">复制出来</button>
</div>
</div>
......@@ -46,7 +51,7 @@
<tbody>
<tr v-for="(item,i) in serviceList">
<td>{{i+1}}</td>
<td>
<td @click="selectService(i)">
<h3 v-if="!item.isWebService">{{item.serviceName}}</h3>
<h4 v-else>{{item.serviceName}}</h4>
</td>
......@@ -71,6 +76,7 @@
source: '', //复制过来的
sourceArr: [], //按行分割的
serviceList: [], //服务列表
sleepList: [], //sleep列表
},
created: function () {
......@@ -82,24 +88,44 @@
if (sysPayload) {
let source = ""
if (sysPayload.indexOf("node") == -1) {
source = "请手动粘贴吧"
}else{
source = "请手动粘贴吧"
} else {
source = sysPayload;
}
}
this.source = source;
this.analyseSource();
}else{
} else {
this.source = "请手动粘贴吧";
}
}
}, 500);
},
methods: {
//清除输入
cleanInput: function () {
this.source = "";
},
//选择服务
selectService: function (index) {
this.serviceList[index].isOpen = !this.serviceList[index].isOpen;
},
//全选
selectAll: function (type) {
let serviceList = this.serviceList;
let isOpen = true;
if (type == 2) {
isOpen = false;
}
serviceList.forEach((item) => {
item.isOpen = isOpen;
});
this.serviceList = serviceList;
},
//分析source
analyseSource: function () {
let serviceMap = {};
let serviceList = [];
let sleepList = [];
let source = this.source;
console.log(source)
//将source按行分割
let sourceArr = source.split("\n");
......@@ -120,7 +146,6 @@
}
//upload的开始行
if (row == "stage('upload') {") {
console.log("uploadStartRow:" + i)
uploadStartRow = i + 1;
}
//upload的结束行和imageBuild的开始行
......@@ -132,6 +157,15 @@
if (row == "}" && uploadEndRow != 0 && imageBuildEnd == 0 && i != uploadEndRow) {
imageBuildEnd = i;
}
if (row.indexOf("sleep") != -1) {
row = row.trim();
row = this.dealStr(row);
let rowObj = {
rowNo: i,
row: row,
}
sleepList.push(rowObj);
}
}
let uploadRow = 0;
......@@ -142,6 +176,9 @@
return;
}
let isOpen = !!(row && !row.startsWith("//"));
if (!isOpen) {
row = this.dealStr(row);
}
let strings = item.split("*.jar")[0].split("/");
let serviceName = strings[strings.length - 1].substring(0, strings[strings.length - 1].length - 1);
let service = {
......@@ -175,18 +212,24 @@
service.buildRow = "//" + trimItem;
}
}
if (!service.isOpen) {
service.buildRow = this.dealStr(service.buildRow);
}
}
})
});
//serviceMap转为数组
for (let key in serviceMap) {
serviceList.push(serviceMap[key]);
}
this.sourceArr = sourceArr;
this.serviceList = serviceList;
this.sleepList = sleepList;
},
//复制出来
copyNew: function () {
let {serviceList, sourceArr} = this;
let {serviceList, sourceArr, sleepList} = this;
if (!serviceList.length) {
alert("你输入的内容不对");
} else {
......@@ -202,6 +245,14 @@
if (buildRow.startsWith("//")) {
buildRow = buildRow.split("//")[1];
}
let sleepRow = item.buildRowNo + 1;
sleepList.forEach(item => {
if (item.rowNo == sleepRow) {
if (item.row.startsWith("//")) {
item.row = item.row.split("//")[1];
}
}
});
} else {
//如果是关闭的 还没有注释的话,就注释掉
if (!uploadRow.startsWith("//")) {
......@@ -210,11 +261,27 @@
if (!buildRow.startsWith("//")) {
buildRow = "//" + buildRow;
}
let sleepRow = item.buildRowNo + 1;
sleepList.forEach(item => {
if (item.rowNo == sleepRow) {
if (!item.row.startsWith("//")) {
item.row = "//" + item.row;
}
}
});
}
//格式
sourceArr[item.uploadRowNo] = "\t\t" + uploadRow;
sourceArr[item.buildRowNo] = "\t\t" + buildRow;
});
sleepList.forEach(item => {
item.row = "\t\t" + item.row;
sourceArr[item.rowNo] = item.row;
})
//去掉sourceArr的空行
sourceArr = sourceArr.filter(item => {
return item.trim();
})
//组合成原来的字符串
let newSource = "";
sourceArr.forEach(item => {
......@@ -229,6 +296,22 @@
document.body.removeChild(txa)
alert("复制成功");
}
},
//dealStr
dealStr: function (str) {
//如果是注释的
if (str.startsWith("//")) {
if (str[2] === " ") {
//去除第三位的空格
str = str.substring(0, 2) + str.substring(3).trim();
return this.dealStr(str);
} else {
return str;
}
} else {
return str;
}
}
}
})
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!