自动化代码
最新版本:v1.0.6
更新日期:2021-03-17 19:02:21
更新日志
v1.0.6
1.新增一键处理法务审批
v1.0.5
1.更新复制成功提示
v1.0.4
1.新增上传图片/附件
v1.0.3
1.新增获取产品名称列表
2.新增图片/附件批量下载
v1.0.2:
1.优化了新增记录流程
2.增加了未找到提示
v1.0.1:
1.增加了流程详细步骤
2.可以设置流程时间time默认100ms
使用方法:打开浏览器 -> 开发者工具 -> 控制台 -> 粘贴代码 -> 点击确定
1.流程新增记录
"use strict";
var index = {
init: function init() {
this.number = 0;
this.length = 100;
this.time = 100; //触发时间
this.addItem();
console.log("%c ***** \u81EA\u52A8\u5316\u5F00\u59CB\uFF01\u89E6\u53D1\u65F6\u95F4".concat(this.time, "\u6BEB\u79D2\u3002 ***** "), 'color: green');
},
//添加字段
addItem: async function addItem() {
this.itemsListBox = $('.workflowDetailBox');
this.length = $('.workflowDetailBox > .relative').length;
this.itemListbox = $('.workflowDetailBox > .relative').eq(this.number);
await this.setTo(this.itemListbox); //设为
await this.selectPeople(this.itemListbox); //选择人员
this.number++;
console.log("%c ***** \u6B63\u5728\u6DFB\u52A0\u7B2C".concat(this.number, "\u4E2A\u5B57\u6BB5,\u4E00\u5171").concat(this.length, "\u4E2A\u5B57\u6BB5! *****"), 'color: red');
this.number < this.length ? this.addItem() : console.log("%c ***** \u81EA\u52A8\u5316\u7ED3\u675F,\u4E00\u5171\u7528\u65F6".concat((this.number * this.time / 60).toFixed(2), "\u79D2 *****"), 'color: green');
},
//设为
setTo: function setTo(dom) {
var _this = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
dom.find('.actionControlMore.ThemeColor3.tip-bottom-left').click();
}());
}, _this.time);
});
},
//选择人员
selectPeople: function selectPeople(dom) {
var _this2 = this;
var that = this;
this.value = dom.find('.mTop15.ellipsis.Font13').text();
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
var isFind = false;
dom.find('.conditionFieldBox li').each(function (index, item) {
if ($(item).text().indexOf(_this2.value) !== -1) {
$(item).click();
isFind = true;
return true;
}
});
if (!isFind) console.log("%c ***** \u672A\u627E\u5230[".concat(_this2.value, "]\u9009\u9879,\u8BF7\u624B\u52A8\u9009\u62E9\u3002*****"), 'color: yellow');
}());
}, _this2.time);
});
}
};
index.init();
2.流程更新记录
"use strict";
var index = {
init: function init() {
this.number = 0;
this.length = 100;
this.time = 100; //触发时间
this.addItem();
console.log("%c ***** \u81EA\u52A8\u5316\u5F00\u59CB\uFF01\u89E6\u53D1\u65F6\u95F4".concat(this.time, "\u6BEB\u79D2\u3002 ***** "), 'color: green');
},
//添加字段
addItem: async function addItem() {
this.addButtonDiv = $('.addActionBtn.mTop25');
this.addButton = this.addButtonDiv.find('.ThemeBorderColor3');
this.addButton.click();
await this.selectAction(this.addButtonDiv.prev()); //选择字段
await this.selectMenu(); //确定字段
await this.setTo(this.addButtonDiv.prev()); //设为
await this.selectPeople(this.addButtonDiv.prev()); //选择人员
this.number++;
console.log("%c ***** \u6B63\u5728\u6DFB\u52A0\u7B2C".concat(this.number, "\u4E2A\u5B57\u6BB5,\u4E00\u5171").concat(this.length, "\u4E2A\u5B57\u6BB5! *****"), 'color: red');
if (this.number < this.length) {
this.addItem();
} else {
console.log("%c ***** \u81EA\u52A8\u5316\u7ED3\u675F,\u4E00\u5171\u7528\u65F6".concat((this.number * this.time / 60).toFixed(2), "\u79D2 *****"), 'color: green');
} // this.number < this.length &&
},
//选择字段
selectAction: function selectAction(dom) {
var _this = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
dom.find('.Dropdown--input.Dropdown--border').click();
}());
}, _this.time);
});
},
//确定字段
selectMenu: function selectMenu() {
var _this2 = this;
var that = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
_this2.length = $('.ming.Menu.ming.List li').length;
var dom = $('.ming.Menu.ming.List li').eq(that.number);
that.value = dom.text();
dom.click();
}());
}, _this2.time);
});
},
//设为
setTo: function setTo(dom) {
var _this3 = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
dom.find('.actionControlMore.ThemeColor3.tip-bottom-left').click();
}());
}, _this3.time);
});
},
//选择人员
selectPeople: function selectPeople(dom) {
var _this4 = this;
var that = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
dom.find('.conditionFieldBox li').each(function (index, item) {
if ($(item).text() === _this4.value) {
$(item).click();
}
});
}());
}, _this4.time);
});
}
};
index.init();
3.获取产品名称列表
"use strict";
var index = {
init: function init() {
this.number = $('.main-right-grid .editableCellCon')[0].classList[2].split('-')[1];
this.productList = [];
this.addProductPicture();
},
//获取产品列表
addProductPicture: function addProductPicture() {
var table = $('.main-right-grid');
var row = table.find(".row-".concat(this.number, ".col-4"));
var text = row.find('span').text();
if (row.length !== 0) {
this.productList.push(text);
this.number++;
this.addProductPicture();
} else {
console.log(JSON.stringify(this.productList));
}
}
};
index.init();
4.获取图片列表并批量下载图片(将3中获取的产品替换到this.values)
"use strict";
var index = {
init: function init() {
//请将产品列表替换到这里
this.values = ["雪花9号啤酒", "雪花啤酒瓶听喜力啤酒瓶听金威啤酒瓶听", "365全麦精酿啤酒", "痹痛冷敷贴"];
this.getProductList();
this.data = [];
this.number = 0;
this.time = 1000;
},
// 获取 blob
getBlob: function getBlob(url, cb) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status === 200) {
cb(xhr.response);
}
};
xhr.send();
},
// 保存文件
saveAs: function saveAs(blob, filename) {
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement('a');
var body = document.querySelector('body');
link.href = window.URL.createObjectURL(blob);
link.download = filename; // fix Firefox
link.style.display = 'none';
body.appendChild(link);
link.click();
body.removeChild(link);
window.URL.revokeObjectURL(link.href);
}
;
console.log("%c ****".concat(filename, "\u4E0B\u8F7D\u6210\u529F!****"), 'color:red');
},
// 下载文件
download: function download(url, filename) {
var that = this;
return that.getBlob(url, function (blob) {
that.saveAs(blob, filename);
});
},
//获取产品信息
getProductList: async function getProductList() {
var _this = this;
var data = JSON.stringify({
appId: 'a58e759f-8e1d-4dc9-b70a-4f86c98a27d5',
viewId: '5ea19a772fc9510001e27cc5',
worksheetId: '5ea19a772fc9510001e27cc4',
status: 1,
pageIndex: 1,
sortControls: [],
pageSize: 50,
keyWords: '',
searchType: 1,
filterControls: [{
controlId: '5ea1af554f222e0001d9fd8e',
dataType: 2,
spliceType: 1,
filterType: 1,
values: this.values
}],
isUnRead: false
});
console.log('%c ****获取图片信息开始****', 'color: green');
var dataList = await $.ajax({
type: "POST",
contentType: "application/json;charset=UTF-8",
url: 'https://www.mingdao.com/api/Worksheet/GetFilterRows',
data: data,
dataType: 'json'
}).then(function (data) {
return data.data.data;
});
console.log('%c ****开始下载图片****', 'color:red');
console.log("%c ****\u4E00\u5171".concat(dataList.length, "\u6761\u6570\u636E****"), 'color:red');
dataList.forEach(function (item) {
var value = JSON.parse(item['5ea1af554f222e0001d9fd97']);
value.forEach(function (itemList, index) {
itemList.previewUrl = itemList.previewUrl.split("?")[0];
});
_this.data.push({
name: item['5ea1af554f222e0001d9fd8e'],
value: value
});
});
this.downloadFile();
},
//下载文件
downloadFile: async function downloadFile() {
await this.saveFile(this.data[this.number]);
this.number < this.data.length ? this.downloadFile() : console.log('%c ****下载最后一个商品附件****', 'color: green');
},
saveFile: function saveFile(list) {
var _this2 = this;
this.number++;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
list.value.forEach(function (item, index) {
_this2.download(item.previewUrl, "".concat(list.name, "_").concat(index).concat(item.ext));
});
}());
}, _this2.time);
});
}
};
index.init();
5.上传图片
"use strict";
var index = {
init: function init() {
this.number = $('.main-right-grid .editableCellCon')[0].classList[2].split('-')[1];
this.time = 1000;
this.addProductPicture();
},
//添加附件
addProductPicture: async function addProductPicture() {
var table = $('.main-right-grid');
var row = table.find(".row-".concat(this.number, ".col-1"));
this.text = table.find(".row-".concat(this.number, ".col-4 span")).text();
this.has = false;
row.click();
await this.openProduct();
await this.openKnowledge();
try {
if (!this.has) {
await this.folderSearch();
await this.selectPicture();
await this.enterPictrue();
await this.savePicture();
}
} catch (e) {
console.log("%c *****服务器异常重新开始***** ", 'color: red');
this.addProductPicture();
}
await this.clickPicture();
this.number++;
this.has = true;
row.length !== 0 && this.addProductPicture();
},
//打开产品
openProduct: function openProduct() {
var _this = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
console.log("%c *****打开产品***** ", 'color: red');
$('.ming.Icon.icon-default.icon.icon-attachment.Font17').eq(0).click();
}());
}, _this.time * 5);
});
},
//打开知识库
openKnowledge: function openKnowledge() {
var _this2 = this;
this.has = $('.UploadFiles-filesWrapper').is(":visible");
if (this.has) return;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
console.log("%c *****打开知识库***** ", 'color: red');
$('.UploadFiles-entrys').find('.flexRow.valignWrapper').eq(1).click();
}());
}, _this2.time);
});
},
//搜索
folderSearch: function folderSearch() {
var _this3 = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
console.log("%c *****搜索图片***** ", 'color: red');
$('.folderSearch input').val(_this3.text);
$('.folderSearch .icon-search').click();
}());
}, _this3.time);
});
},
//选择图片
selectPicture: function selectPicture() {
var _this4 = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
console.log("%c *****选择图片***** ", 'color: red');
$('.nodeList li').addClass('ThemeBGColor5').attr('nodetype', 2);
}());
}, _this4.time * 5);
});
},
//确定
enterPictrue: function enterPictrue() {
var _this5 = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
console.log("%c *****确定选择***** ", 'color: red');
$('#folderSelectDialog .yesText.boderRadAll_3.ThemeBGColor3')[0].click();
}());
}, _this5.time);
});
},
//保存
savePicture: function savePicture() {
var _this6 = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
console.log("%c *****保存成功***** ", 'color: red');
$('.updateRowButton .mRight24')[0].click();
}());
}, _this6.time * 5);
});
},
//关闭
clickPicture: function clickPicture() {
var _this7 = this;
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(function () {
$('.mui-dialog-close-btn')[0].click();
}());
}, _this7.time * 5);
});
}
};
index.init();
6.一键处理法务审批
let index = {
init() {
this.arrList = []
this.arrNumber = 0
this.timer = 2000
this.log = null
this.status = null
this.find = false
this.scrollTopUP = 0
// 获取当前待处理列表
this.nextPage()
},
// 切换到下一页
nextPage() {
const nextButton = document.querySelector('.sc-bdVaJa.jSejjJ')
nextButton.querySelectorAll('.sc-htpNat.bIDsIe')[1].click()
setTimeout(() => {
this.getList()
}, this.timer)
},
// 获取待处理
getList() {
const list = document.querySelectorAll('.col-5')
list.forEach(item => {
if (item.innerText === '待处理')
this.arrList.push(item)
})
console.log(`%c ***** 当前页一共${list.length - 1} 条数据,其中${this.arrList.length}条待处理*****`, 'color: red')
this.startHandler()
},
// 处理数据
startHandler() {
console.log(`%c ***** 开始处理第${this.arrNumber + 1}条数据 *****`, 'color: green')
if (this.arrList[this.arrNumber]) {
this.arrList[this.arrNumber].click()
console.log(`%c ***** 打开详情页数据 *****`, 'color: orange')
setTimeout(() => {
this.findInfo()
}, this.timer)
} else {
document.querySelector('.refresh').click()
setTimeout(() => {
this.arrNumber = 0
this.arrList = []
this.log = null
this.status = null
this.find = false
this.nextPage()
}, this.timer + 1000)
console.log(`%c ***** 处理结束!!!! *****`, 'color: green')
}
},
// 查询日志
findInfo() {
const getHeader = document.querySelector('.header')
getHeader.querySelectorAll('span')[1].click()
setTimeout(() => {
this.scrollTop()
}, this.timer)
},
// 滚动处理
scrollTop() {
const scrollContent = document.querySelector('.discussLogFile .nano-content')
this.scrollTopUP = scrollContent.scrollTop
scrollContent.scrollTop += 1000
console.log(`%c ***** 滚动距离${scrollContent.scrollTop} *****`, 'color: red')
console.log(`%c ***** 当前距离${this.scrollTopUP} *****`, 'color: orange')
if (scrollContent.scrollTop === this.scrollTopUP) {
console.log(`%c ***** 已经滚动到底部 开始执行 *****`, 'color: pink')
setTimeout(() => {
this.findInfoItem()
}, this.timer)
} else {
setTimeout(() => {
this.scrollTop()
}, this.timer)
}
},
// 查询最后一条日志
findInfoItem() {
const logList = document.querySelectorAll('.logItem')
console.log(`%c ***** 一共查询到${logList.length}条操作日志 *****`, 'color: red')
logList.forEach((item, index) => {
if (item.innerText.indexOf('@陈泽浩') !== -1) {
// this.find = true
this.log = null
item.style.border = " 2px solid red"
}
// if (this.find) {
if (item.innerText.indexOf('商品资质审批状态的“单选下拉菜单”字段的内容') !== -1) {
item.style.border = " 2px solid red"
item.style.background = "red"
item.style.color = "#fff"
if (!this.log) {
item.style.border = " 2px solid green"
item.style.background = "green"
this.log = item.querySelector('.logContent').innerText
this.status = this.log.split('改为')[1].split(';')[0].trim().replace('(已处理)', '')
}
console.log(`%c ***** 第${index + 1}条操作日志操作了商品资质审批状态 *****`, 'color: red')
console.log(`%c ***** 操作日志内容为:${this.log} *****`, 'color:yellow')
console.log(`%c ***** 操作目标为:${this.status} *****`, 'color:orange')
// }
}
})
if (!this.status) {
document.querySelector('.mui-dialog-close-btn').click()
this.arrNumber++
this.arrList = []
this.log = null
this.status = null
this.find = false
this.getList()
return
}
setTimeout(() => {
this.setSelectStatus()
}, this.timer)
},
// 设置状态
setSelectStatus() {
const formItemList = document.querySelectorAll('.customFormItem')
let formItem = null
formItemList.forEach(item => {
if (item.innerText.indexOf('商品资质审批状态') !== -1) {
formItem = item
return
}
})
const selectItem = formItem.querySelector('.customFormItemControl .ant-select-selector')
var evObj = document.createEvent('MouseEvents')
evObj.initMouseEvent('mousedown', true, true, window)
selectItem.dispatchEvent(evObj)
setTimeout(() => {
this.selectChange()
}, this.timer / 2)
},
// 选择内容
selectChange() {
const selectItem = document.querySelector('.ant-select-dropdown')
const item = selectItem.querySelectorAll('.ant-select-item')
item.forEach(item => {
if (item.innerText === this.status) {
item.click()
return
}
})
setTimeout(() => {
this.submit()
}, this.timer / 2)
},
// 保存
submit() {
const button = document.querySelector('.updateRowButton')
const buttonEnter = button.querySelector('.Button--primary')
buttonEnter.click()
setTimeout(() => {
this.arrNumber++
this.arrList = []
this.log = null
this.status = null
this.find = false
this.getList()
}, this.timer)
}
}
index.init()