2022-11-21 03:27:41 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name 管易小助手
|
|
|
|
// @namespace http://tampermonkey.net/
|
2022-11-21 03:40:06 +00:00
|
|
|
// @version 0.2
|
2022-11-21 03:28:30 +00:00
|
|
|
// @description 管易ERP 批量操作工具
|
2022-11-21 03:27:41 +00:00
|
|
|
// @author MiaoWoo
|
|
|
|
// @match http*://www.guanyierp.com/**
|
|
|
|
// @icon https://www.google.com/s2/favicons?sz=64&domain=guanyierp.com
|
|
|
|
// @grant none
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict'
|
|
|
|
let toolHtml = `<span class="help-center-title tc" style="color: #4caf50;">管易小助手</span>`
|
|
|
|
let tool = document.createElement("div")
|
2022-11-21 03:40:06 +00:00
|
|
|
tool.className = "flex flex-column flex-y-center justcenter hand tmall-time ant-popover-hidden"
|
2022-11-21 03:27:41 +00:00
|
|
|
tool.innerHTML = toolHtml
|
|
|
|
document.querySelector('.help-center').parentNode.appendChild(tool)
|
|
|
|
tool.onclick = () => {
|
|
|
|
toolPage.className = toolPage.className ? '' : 'ant-popover-hidden'
|
|
|
|
}
|
|
|
|
|
|
|
|
let toolPageHtml = `
|
|
|
|
<style>
|
|
|
|
.ms-controller {
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div :controller="gy" class="ant-popover ant-popover-placement-left ms-controller" style="left: 955px; top: 425px; transform-origin: 395.375px 50%;">
|
|
|
|
<div class="ant-popover-content">
|
|
|
|
<div class="ant-popover-arrow"><span class="ant-popover-arrow-content"></span></div>
|
|
|
|
<div class="ant-popover-inner" role="tooltip">
|
|
|
|
<div class="ant-popover-inner-content">
|
|
|
|
<h2 :click="log">管易小助手</h2>
|
|
|
|
<h3 :if="@loading" :text="loadingText">加载中 请稍候...</h3>
|
|
|
|
<div :if="!@loading">
|
|
|
|
<label style="font-size: 13px">选择配置类型</label>
|
|
|
|
<br>
|
|
|
|
<span :for="el in @configTypes"><input type="checkbox" :attr="{ value: el.value }" ms-duplex="@configType"/>{{el.name}}</span>
|
|
|
|
<br>
|
|
|
|
<label style="font-size: 13px">选择过滤规则</label>
|
|
|
|
<br>
|
|
|
|
<span :for="el in @filterRules"><input type="radio" :attr="{ value: el.value }" ms-duplex="@filterRule"/>{{el.name}}</span>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<label style="font-size: 13px">修改仓库: </label>
|
|
|
|
<select :duplex="@warehouse" class="form-control">
|
|
|
|
<option value="">请选择仓库</option>
|
|
|
|
<option :for="el in @warehouses" :attr="{ value: el.id }">{{el.name}}</option>
|
|
|
|
</select>
|
|
|
|
<button type="button" class="btn btn-default" :click="@modifyWarehouse">
|
|
|
|
修改
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
let toolPage = document.createElement("div")
|
|
|
|
toolPage.id = "gytool"
|
|
|
|
toolPage.style = "position: absolute; top: 0px; left: 0px; width: 100%;"
|
2022-11-21 03:40:06 +00:00
|
|
|
toolPage.className = 'ant-popover-hidden'
|
2022-11-21 03:27:41 +00:00
|
|
|
toolPage.innerHTML = toolPageHtml
|
|
|
|
document.body.appendChild(toolPage)
|
|
|
|
async function api(method, url, body = null, contentType = "application/json; charset=UTF-8") {
|
|
|
|
return await fetch(url, {
|
|
|
|
"headers": {
|
|
|
|
"accept": "*/*",
|
|
|
|
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
|
|
"content-type": contentType,
|
|
|
|
"x-requested-with": "XMLHttpRequest"
|
|
|
|
},
|
|
|
|
"referrer": "http://www.guanyierp.com/tc/delivery/delivery_wave",
|
|
|
|
"referrerPolicy": "strict-origin-when-cross-origin",
|
|
|
|
"body": body,
|
|
|
|
"method": method,
|
|
|
|
"mode": "cors",
|
|
|
|
"credentials": "include"
|
|
|
|
}).then(r => r.json())
|
|
|
|
}
|
|
|
|
fetch('https://fastly.jsdelivr.net/npm/avalon2@2.2.10/dist/avalon.min.js')
|
|
|
|
.then(r => r.text()).then(source => {
|
|
|
|
var header = document.getElementsByTagName("head").item(0)
|
|
|
|
var avalonJs = document.createElement("script")
|
|
|
|
avalonJs.language = "javascript"
|
|
|
|
avalonJs.type = "text/javascript"
|
|
|
|
avalonJs.id = 'avalonJs'
|
|
|
|
avalonJs.defer = true
|
|
|
|
avalonJs.text = source
|
|
|
|
header.appendChild(avalonJs)
|
|
|
|
let main = avalon.define({
|
|
|
|
$id: 'gy',
|
|
|
|
loading: true,
|
|
|
|
loadingText: '执行中 请稍候...',
|
|
|
|
warehouses: [],
|
|
|
|
warehouse: '',
|
|
|
|
filterRules: [
|
|
|
|
{ name: '仅胶带(名称带A)', value: "1" },
|
|
|
|
],
|
|
|
|
filterRule: '1',
|
|
|
|
configTypes: [
|
|
|
|
{ name: '热销订单', value: "1" },
|
|
|
|
{ name: '一单一件', value: "2" },
|
|
|
|
{ name: '一单一品', value: "3" },
|
|
|
|
{ name: '一单多品', value: "4" },
|
|
|
|
],
|
|
|
|
configType: ["3", "4"],
|
|
|
|
log: function () {
|
|
|
|
console.log(main)
|
|
|
|
},
|
|
|
|
init: async function () {
|
|
|
|
await main.initWarehouse()
|
2022-11-21 03:40:06 +00:00
|
|
|
tool.className = "flex flex-column flex-y-center justcenter hand tmall-time"
|
2022-11-21 03:27:41 +00:00
|
|
|
main.loading = false
|
|
|
|
},
|
|
|
|
initWarehouse: async function () {
|
|
|
|
let warehouses = await api('GET', 'http://www.guanyierp.com/info/warehouse/data/all?_dc=' + Date.now() + '&page=1&start=0&limit=25')
|
|
|
|
main.warehouses = warehouses.map((warehouse) => { return { id: warehouse.id, name: warehouse.name } })
|
|
|
|
},
|
|
|
|
modifyWarehouse: async function () {
|
|
|
|
if (!main.warehouse) {
|
|
|
|
return alert("请选择需要修改的仓库.")
|
|
|
|
}
|
|
|
|
main.loading = true
|
|
|
|
let tasks = []
|
|
|
|
for (const configType of main.configType) {
|
|
|
|
let configs = await api('POST',
|
|
|
|
'http://www.guanyierp.com/wave/wave_config/list?_dc=' + Date.now(),
|
|
|
|
'configType=' + configType,
|
|
|
|
"application/x-www-form-urlencoded; charset=UTF-8"
|
|
|
|
)
|
|
|
|
// configs = configs.filter(c => c.configName.indexOf('测试') != -1)
|
|
|
|
configs = configs.filter(c => c.autoRun)
|
2022-11-21 03:29:37 +00:00
|
|
|
if (main.configRule == "1") {
|
2022-11-21 03:27:41 +00:00
|
|
|
configs = configs.filter(c => c.configName.indexOf('A') != -1)
|
|
|
|
}
|
|
|
|
configs.forEach(c => {
|
|
|
|
c.waveConfigContentInfo.warehouseIds = [main.warehouse]
|
|
|
|
tasks.push(api('POST', 'http://www.guanyierp.com/wave/wave_config/update', JSON.stringify(c)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
let result = await Promise.allSettled(tasks)
|
|
|
|
console.log(result)
|
|
|
|
alert('批量修改仓库完成 共计 ' + result.length + ' 个配置')
|
|
|
|
main.loading = false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
main.init()
|
|
|
|
})
|
|
|
|
})()
|