diff --git a/guanyierp/tools.user.js b/guanyierp/tools.user.js new file mode 100644 index 0000000..a0d058d --- /dev/null +++ b/guanyierp/tools.user.js @@ -0,0 +1,150 @@ +// ==UserScript== +// @name 管易小助手 +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description try to take over the world! +// @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 = `管易小助手` + let tool = document.createElement("div") + tool.className = "flex flex-column flex-y-center justcenter hand tmall-time" + tool.innerHTML = toolHtml + document.querySelector('.help-center').parentNode.appendChild(tool) + tool.onclick = () => { + toolPage.className = toolPage.className ? '' : 'ant-popover-hidden' + } + + let toolPageHtml = ` + +
+
+
+ +
+
+ ` + let toolPage = document.createElement("div") + toolPage.id = "gytool" + toolPage.style = "position: absolute; top: 0px; left: 0px; width: 100%;" + // toolPage.className = 'ant-popover-hidden' + 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() + 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) + if (main.configRule == 1) { + 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() + }) +})()