dialog-MY

get data from mengxi

目前為 2025-02-13 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name dialog-MY
  3. // @namespace http://tampermonkey.net/
  4. // @version V0.1
  5. // @description get data from mengxi
  6. // @author wei
  7. // @match https://www.imptc.com/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant GM_download
  10. // @grant GM_xmlhttpRequest
  11. // @license AGPL-3.0
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. function getCookieObject() {
  18. var cookies = document.cookie.split(';');
  19. var cookieObj = {};
  20. for (var i = 0; i < cookies.length; i++) {
  21. var parts = cookies[i].trim().split('=');
  22. cookieObj[parts[0]] = parts[1];
  23. }
  24. return cookieObj;
  25. }
  26.  
  27. // 随机生成 30 到 60 秒的延迟
  28. function randomDelay(minDelay = 30000, maxDelay = 60000) {
  29. return new Promise(resolve => {
  30. const delayTime = Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay; // minDelay ~ maxDelay秒
  31. setTimeout(resolve, delayTime);
  32. });
  33. }
  34.  
  35. // 输入 '2024-10-01, 2024-10-10', 输出时间序列列表
  36. function generateDateList(dateRangeStr) {
  37. let [startDateStr, endDateStr] = dateRangeStr.split(',').map(date => date.trim());
  38. let startDate = new Date(startDateStr);
  39. let endDate = new Date(endDateStr);
  40. let dateList = [];
  41. while (startDate <= endDate) {
  42. dateList.push(startDate.toISOString().split('T')[0]); // 转为字符串格式
  43. startDate.setDate(startDate.getDate() + 1); // 日期加1
  44. }
  45. return dateList;
  46. }
  47.  
  48. // 输入 '2024-10', 输出 ['2024-10-01', '2024-10-02', '2024-10-03', '2024-10-04', ..., '2024-10-30', '2024-10-31']
  49. function getDaysInMonth(dateStr) {
  50. const year = parseInt(dateStr.split('-')[0]);
  51. const month = parseInt(dateStr.split('-')[1]);
  52. const daysInMonth = new Date(year, month, 0).getDate();
  53. const result = [];
  54. for (let day = 1; day <= daysInMonth; day++) {
  55. result.push(`${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`);
  56. }
  57. return result;
  58. }
  59.  
  60. // 导出 市场情况分析 - 信息对比 中的数据
  61. function doExportD1Data(startDate, endDate) {
  62. // console.log('在D1中', startDate, endDate);
  63. let internalStartDate = startDate;
  64. let internalEndDate = endDate;
  65. return new Promise((resolve, reject) => {
  66. var cookieObject = getCookieObject();
  67. let authorization = cookieObject["Token"];
  68. // console.log(internalStartDate, '=============');
  69. // console.log(internalEndDate, '=============');
  70. // 分别是 电价曲线、负荷预测、东送计划、非市场化曲线、新能源预测
  71. let urls_nosuffix = [
  72. 'https://www.imptc.com/api/scqkfx/sctjfxyyc/crqwxxfb/getYhcjqjgData/',
  73. 'https://www.imptc.com/api/scqkfx/sctjfxyyc/crqwxxfb/getQwtdfhycscData/',
  74. 'https://www.imptc.com/api/scqkfx/sctjfxyyc/crqwxxfb/getCrdsjhycscData/',
  75. 'https://www.imptc.com/api/scqkfx/sctjfxyyc/crqwxxfb/fsccl/',
  76. 'https://www.imptc.com/api/scqkfx/sctjfxyyc/crqwxxfb/getXnyfdnlycData/'
  77. ];
  78. let dateList = generateDateList(internalStartDate+ ", " + internalEndDate);
  79. // console.log(dateList, '----------------');
  80.  
  81. // 定义请求名称数组,与 urls 对应
  82. let requestNames = ['电价曲线', '负荷预测', '东送计划', '非市场化曲线', '新能源预测'];
  83.  
  84. // 定义额外信息数组
  85. let additionalInfo = [
  86. ['时间', '全网统一出清电价', '呼包东统一出清电价', '呼包西统一出清电价', '日前预出清电能价格'],
  87. ['时间', '统调负荷预测', '统调负荷实测'],
  88. ['时间', '东送计划预测', '东送计划实测'],
  89. ['时间', '非市场出力计划', '非市场出力计划实测'],
  90. ['时间', '光伏出力预测', '光伏出力实测', '风电出力预测', '风电出力实测', '新能源出力预测', '新能源出力实测'],
  91. ];
  92. // 后续代码逻辑中,都使用internalStartDate和internalEndDate来代替原来的startDate和endDate
  93. // 例如在async function processD1Dates里相关判断等操作
  94. async function processD1Dates() {
  95. try {
  96. for (let cur_date of dateList) {
  97. // 用于收集每个日期对应的所有请求的Promise
  98. let allRequests = [];
  99. for (let i = 0; i < urls_nosuffix.length; i++) {
  100. let url = urls_nosuffix[i] + cur_date + '/' + cur_date;
  101. let index = i; // 保存当前索引值,避免闭包问题
  102.  
  103. console.log(url);
  104. (async () => {
  105. try {
  106. let response = await fetch(url, {
  107. method: 'POST',
  108. headers: {
  109. 'accept': 'application/json, text/plain, */*',
  110. 'authorization': authorization
  111. },
  112. credentials: 'include'
  113. });
  114. let data = await response.json();
  115. let data_dict = {
  116. "data_class": "d1_data",
  117. "class_name": requestNames[index],
  118. "date": cur_date,
  119. "columns": additionalInfo[index],
  120. "data": data["data"]
  121. };
  122. await GM_xmlhttpRequest({
  123. method: "POST",
  124. url: "https://tradex.mywind.com.cn/tradex",
  125. // url: "http://192.168.0.90:7001/tradex",
  126. headers: {
  127. "Content-Type": "application/json;charset=UTF-8"
  128. },
  129. data: JSON.stringify(data_dict),
  130. onload: function (response) {
  131. console.log("请求成功");
  132. console.log(response.responseText);
  133. },
  134. onerror: function (response) {
  135. console.log("请求失败。。。");
  136. console.log(response.responseText);
  137. }
  138. });
  139. } catch (error) {
  140. console.error(`请求 ${url} 发生错误:`, error);
  141. }
  142. })().then(request => allRequests.push(request));
  143. }
  144. await Promise.all(allRequests);
  145. console.log(`D1 已完成日期: ${cur_date}`);
  146. console.log(`D1 等待完成,继续执行下一个日期`);
  147. await randomDelay();
  148. }
  149. console.log("D1 所有日期的请求已完成");
  150. resolve(); // 当所有日期的请求都完成后,调用resolve表示成功完成
  151. } catch (error) {
  152. console.error("处理请求时发生错误:", error);
  153. reject(error); // 如果出现错误,调用reject传递错误信息
  154. }
  155. }
  156. processD1Dates();
  157. });
  158. }
  159.  
  160. // 导出 交易管理 - 现货交易 - 省内电能量交易 - 次日全网信息 中的数据
  161. function doExportD3Data(startDate, endDate) {
  162. let internalStartDate = startDate;
  163. let internalEndDate = endDate;
  164. return new Promise((resolve, reject) => {
  165. var cookieObject = getCookieObject();
  166. let authorization = cookieObject["Token"];
  167. console.log(authorization);
  168. let dateList = generateDateList(internalStartDate+", "+internalEndDate);
  169. // 分别是 统调负荷、东送计划、非市场出力、新能源出力, 正负备用容量
  170. let urls_nosuffix = [
  171. 'https://www.imptc.com/api/sctjfxyyc/crqwxxfb/getQwtdfhycData/',
  172. 'https://www.imptc.com/api/sctjfxyyc/crqwxxfb/getCrdsjhData/',
  173. 'https://www.imptc.com/api/sctjfxyyc/crqwxxfb/fsccl/',
  174. 'https://www.imptc.com/api/sctjfxyyc/crqwxxfb/getXnyfdnlycData/',
  175. 'https://www.imptc.com/api/sctjfxyyc/crqwxxfb/getCrqwbyrlData/'
  176. ];
  177. // 定义请求名称数组,与 urls 对应
  178. let requestNames = ['统调负荷', '东送计划', '非市场出力', '新能源出力', '正负备用容量'];
  179. async function processDates() {
  180. try {
  181. for (let cur_date of dateList) {
  182. let datePairs = [];
  183. let dateObj = new Date(cur_date);
  184. dateObj.setDate(dateObj.getDate() + 1);
  185. let after_date = dateObj.toISOString().split('T')[0];
  186. datePairs.push(cur_date);
  187. datePairs.push(after_date);
  188. // 用于收集所有日期对对应的所有请求的Promise
  189. let allRequests = [];
  190. for (let date of datePairs) {
  191. let requests = urls_nosuffix.map((url, index) => {
  192. let options = {
  193. method: 'POST',
  194. headers: {
  195. 'accept': 'application/json, text/plain, */*',
  196. 'authorization': authorization,
  197. },
  198. credentials: 'include',
  199. };
  200. if (url.includes('getXnyfdnlycData')) {
  201. options.body = JSON.stringify({ 'time': date, 'area': '', 'name': '0' });
  202. options.headers['Content-Type'] = 'application/json';
  203. } else {
  204. url += date;
  205. }
  206. return async () => {
  207. try {
  208. let response = await fetch(url, options);
  209. let data = await response.json();
  210. let data_dict = {
  211. "data_class": "d3_data",
  212. "class_name": requestNames[index],
  213. "date": date,
  214. "data": data["data"]
  215. };
  216. return GM_xmlhttpRequest({
  217. method: "POST",
  218. url: "https://tradex.mywind.com.cn/tradex",
  219. // url: "http://192.168.0.90:7001/tradex",
  220. headers: {
  221. "Content-Type": "application/json;charset=UTF-8"
  222. },
  223. data: JSON.stringify(data_dict),
  224. onload: function (response) {
  225. console.log("请求成功");
  226. console.log(response.responseText);
  227. },
  228. onerror: function (response) {
  229. console.log("请求失败");
  230. console.log(response.responseText);
  231. }
  232. });
  233. } catch (error) {
  234. console.error(`请求 ${url} ${requestNames[index]} 发生错误:`, error);
  235. }
  236. };
  237. });
  238. allRequests.push(...requests);
  239. }
  240. // 等待所有日期对对应的所有请求完成
  241. await Promise.all(allRequests.map(request => request()));
  242. console.log(`已完成日期范围: ${datePairs.join(' - ')}`);
  243. // 随机延迟后继续执行下一个日期的循环
  244. console.log(`等待完成,继续执行下一个日期`);
  245. await randomDelay();
  246. }
  247. console.log("所有日期的请求已完成");
  248. resolve(); // 所有日期请求完成后,调用resolve表示成功完成
  249. } catch (error) {
  250. console.error("处理请求时发生错误:", error);
  251. reject(error); // 如果出现错误,调用reject传递错误信息
  252. }
  253. }
  254. processDates();
  255. });
  256. }
  257.  
  258. // 导出 节点电价数据
  259. // 信息披露 - 市场运营机构 - 6.52现货市场申报、出清信息 - 实时节点电价
  260. function doExportNodeData(startDate, endDate) {
  261. let internalStartDate = startDate;
  262. let internalEndDate = endDate;
  263. return new Promise((resolve, reject) => {
  264. var cookieObject = getCookieObject();
  265. let authorization = cookieObject["Token"];
  266. console.log(authorization);
  267. let dateList = generateDateList(internalStartDate+", "+internalEndDate);
  268. console.log(dateList)
  269. // 'https://www.imptc.com/api/xxpl2024/scyyqywh/getDetials/6.52//2024-12-20/tab7'
  270. let url_nosuffix = 'https://www.imptc.com/api/xxpl2024/scyyqywh/getDetials/6.52//';
  271. // 定义请求名称
  272. let requestName = '节点电价';
  273. async function processDates() {
  274. try {
  275. for (let cur_date of dateList) {
  276. let fullUrl = url_nosuffix + cur_date + '/tab7';
  277. let options = {
  278. method: 'POST',
  279. headers: {
  280. 'Accept': 'application/json, text/plain, */*',
  281. 'Authorization': authorization,
  282. 'Content-Type': 'application/json'
  283. }
  284. };
  285. try {
  286. let response = await fetch(fullUrl, options);
  287. let data = await response.json();
  288. let data_dict = {
  289. "data_class": "node_price_data",
  290. "class_name": requestName,
  291. "date": cur_date,
  292. "data": data
  293. };
  294. await new Promise((innerResolve, innerReject) => {
  295. GM_xmlhttpRequest({
  296. method: "POST",
  297. url: "https://tradex.mywind.com.cn/tradex",
  298. // url: "http://192.168.0.90:7001/tradex",
  299. headers: {
  300. "Content-Type": "application/json;charset=UTF-8"
  301. },
  302. data: JSON.stringify(data_dict),
  303. onload: function (response) {
  304. console.log("请求成功");
  305. console.log(response.responseText);
  306. innerResolve();
  307. },
  308. onerror: function (response) {
  309. console.log("请求失败");
  310. console.log(response.responseText);
  311. innerReject(new Error('GM_xmlhttpRequest failed'));
  312. }
  313. });
  314. });
  315. console.log(`节点电价 - 已完成日期: ${cur_date}`);
  316. } catch (error) {
  317. console.error(`请求 ${fullUrl} ${requestName} 发生错误:`, error);
  318. }
  319. // 随机延迟后继续执行下一个日期的循环
  320. console.log(`等待完成,继续执行下一个日期`);
  321. await randomDelay();
  322. }
  323. console.log("所有日期的节点电价请求已完成");
  324. resolve(); // 所有日期请求完成后,调用resolve表示成功完成
  325. } catch (error) {
  326. console.error("处理节点电价请求时发生错误:", error);
  327. reject(error); // 如果出现错误,调用reject传递错误信息
  328. }
  329. }
  330. processDates();
  331. });
  332. }
  333.  
  334. const functionMap = {
  335. 'D1信息对比数据': doExportD1Data,
  336. 'D3数据': doExportD3Data,
  337. '节点数据': doExportNodeData
  338. };
  339.  
  340. const layuiCssLink = document.createElement("link");
  341.  
  342. layuiCssLink.rel = 'stylesheet';
  343.  
  344. layuiCssLink.href = "//unpkg.com/layui@2.9.18/dist/css/layui.css"
  345.  
  346. document.head.appendChild(layuiCssLink);
  347.  
  348. const layuiScript = document.createElement("script");
  349.  
  350. layuiScript.src = "//unpkg.com/layui@2.9.18/dist/layui.js"
  351.  
  352. document.head.appendChild(layuiScript);
  353.  
  354. console.log("这是测试111......");
  355.  
  356. // 创建悬浮按钮
  357. const floatingButton = document.createElement('button');
  358. floatingButton.classList.add('floating-button');
  359. floatingButton.innerHTML = '&#9776;';
  360. document.body.appendChild(floatingButton);
  361.  
  362. // 记录悬浮按钮初始的top值,用于后续计算
  363. let initialTop = floatingButton.offsetTop;
  364.  
  365. // 鼠标按下事件处理函数
  366. floatingButton.addEventListener('mousedown', (e) => {
  367. e.preventDefault(); // 阻止默认的鼠标按下行为,比如选中文字等
  368.  
  369. // 记录鼠标按下时相对于按钮的偏移量
  370. let offsetY = e.clientY - floatingButton.getBoundingClientRect().top;
  371.  
  372. // 鼠标移动事件处理函数
  373. const onMouseMove = (e) => {
  374. e.preventDefault();
  375.  
  376. // 根据鼠标移动更新按钮的top值,使其在右侧边缘上下滑动
  377. let newTop = e.clientY - offsetY;
  378.  
  379. // 限制按钮只能在可视区域内滑动,防止滑出屏幕顶部或底部
  380. let maxTop = window.innerHeight - floatingButton.offsetHeight;
  381. let minTop = 0;
  382. newTop = Math.min(maxTop, Math.max(minTop, newTop));
  383.  
  384. floatingButton.style.top = `${newTop}px`;
  385. };
  386.  
  387. // 鼠标松开事件处理函数
  388. const onMouseUp = () => {
  389. // 移除鼠标移动和松开事件的监听,避免不必要的性能消耗
  390. document.removeEventListener('mousemove', onMouseMove);
  391. document.removeEventListener('mouseup', onMouseUp);
  392. };
  393.  
  394. // 添加鼠标移动和松开事件的监听
  395. document.addEventListener('mousemove', onMouseMove);
  396. document.addEventListener('mouseup', onMouseUp);
  397. });
  398.  
  399. // 添加 CSS 样式
  400. const style = document.createElement('style');
  401. style.textContent = `
  402. /* 悬浮按钮样式 */
  403. .floating-button {
  404. position: absolute; /* 从fixed改为absolute,以便后续能相对父元素定位 */
  405. right: 0; /* 初始贴紧右侧边缘 */
  406. top: 50%; /* 初始垂直居中,后续会根据鼠标移动调整 */
  407. width: 50px;
  408. height: 50px;
  409. border-radius: 50%;
  410. background-color: #0078d4;
  411. color: white;
  412. border: none;
  413. cursor: pointer;
  414. font-size: 24px;
  415. display: flex;
  416. justify-content: center;
  417. align-items: center;
  418. box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  419. transform: translateY(-50%); /* 初始垂直居中的偏移调整 */
  420. user-select: none; /* 防止按钮文本被选中,提升用户体验 */
  421. }
  422. `;
  423. document.head.appendChild(style);
  424.  
  425. // 定义一个变量来跟踪窗口状态,true表示展开,false表示缩回
  426. let isWindowOpen = false;
  427.  
  428. // 获取当前时间
  429. const currentTime = new Date().toLocaleString();
  430.  
  431. // 定义弹出窗口的宽和高
  432. const panelWidth = 900
  433. const panelHeight = 500
  434.  
  435. // 获取网页宽高
  436. let windowWidth = window.innerWidth;
  437. let windowHeight = window.innerHeight;
  438.  
  439. floatingButton.addEventListener('click', () => {
  440. if (isWindowOpen) {
  441. // 如果窗口是展开的,关闭窗口
  442. layer.closeAll('page'); // 关闭所有类型为'page'(即layer.open中type: 1的页面层)的弹出层
  443. isWindowOpen = false;
  444. } else {
  445. const floatingButtonRect = floatingButton.getBoundingClientRect();
  446. // 计算弹出窗口的偏移量
  447. let offsetTop = windowWidth - panelWidth - 80
  448. let offsetRight = floatingButtonRect.y
  449.  
  450. // 如果窗口是缩回的,打开窗口
  451. layui.use(['layer', 'table'], function () {
  452. var layer = layui.layer;
  453. var table = layui.table;
  454. let form = layui.form;
  455. let laydate = layui.laydate;
  456. layer.open({
  457. type: 1,
  458. area: [panelWidth + 'px', panelHeight + 'px'],
  459. offset: [offsetRight, offsetTop],
  460. resize: false,
  461. shadeClose: true,
  462. title: 'MXXH工具',
  463. shade: 0,
  464. content: ` <div class="talbeBox">
  465. <style>
  466. .row {
  467. height: 40px;
  468. display: flex;
  469. justify-content: flex-start;
  470. align-items: center;
  471. margin-bottom: 20px;
  472. padding-left: 20px;
  473. }
  474.  
  475. .row .formItem {
  476. display: flex;
  477. justify-content: flex-start;
  478. align-items: center;
  479. margin-right: 10px;
  480. }
  481.  
  482. .row .layui-input {
  483. width: 150px;
  484. }
  485. </style>
  486. </style>
  487. <div class="layui-form" lay-filter="headForm">
  488. <div class="row1 row">
  489. <div class="formItem">
  490. <label>接口名称:</label>
  491. <input class="layui-input" placeholder="输入框" name="APIName">
  492. </div>
  493. <div class="formItem">
  494. <label>接口频率:</label>
  495. <select name="APIRate">
  496. <option value="">请选择</option>
  497. <option value="AAA">选项 A</option>
  498. <option value="BBB">选项 B</option>
  499. <option value="CCC">选项 C</option>
  500. </select>
  501. </div>
  502. <div class="formItem">
  503. <label>运行状态:</label>
  504. <select name="status">
  505. <option value="">请选择</option>
  506. <option value="AAA">未执行</option>
  507. <option value="BBB">正在执行</option>
  508. <option value="CCC">已完成</option>
  509. <option value="DDD">执行报错</option>
  510. </select>
  511. </div>
  512. </div>
  513. <div class="row2 row">
  514. <div class="formItem">
  515. <label>数据类型:</label>
  516. <select name="dataType">
  517. <option value="AAA">选项 A</option>
  518. <option value="BBB">选项 B</option>
  519. </select>
  520. </div>
  521. <div class="formItem" id="layui-time">
  522. <label>日期范围:</label>
  523. <input type="text" autocomplete="off" name="startName" id="layui-startTime" class="layui-input"
  524. placeholder="开始日期">-
  525.  
  526. <input type="text" autocomplete="off" name="endName" id="layui-endTime" class="layui-input"
  527. placeholder="结束日期">
  528. </div>
  529. <div class="formItem">
  530. <p>0.323s</p>
  531. </div>
  532. <div class="formItem">
  533. <button type="button" class="layui-btn layui-bg-blue" id="dialog-run">批量运行</button>
  534. </div>
  535.  
  536. </div>
  537. </div>
  538. <div class="tableBox">
  539. <div id="myTable"></div>
  540. </div>
  541. </div>`,
  542.  
  543. success: function () {
  544. // 可以在这里进行一些初始化操作,比如表格渲染(如果使用了动态数据加载等情况)
  545.  
  546. // 日期范围 - 左右面板联动选择模式
  547. laydate.render({
  548. elem: '#layui-time',
  549. range: ['#layui-startTime', '#layui-endTime'],
  550. rangeLinked: true // 开启日期范围选择时的区间联动标注模式 --- 2.8+ 新增
  551. });
  552. form.render()
  553.  
  554. function validateDateRange(startDateStr, endDateStr) {
  555. if (startDateStr === '') {
  556. alert('开始日期未选择,请选择开始日期!');
  557. return false;
  558. }
  559. if (endDateStr === '') {
  560. alert('结束日期未选择,请选择结束日期!');
  561. return false;
  562. }
  563. const startDate = new Date(startDateStr);
  564. const endDate = new Date(endDateStr);
  565. if (startDate > endDate) {
  566. alert('开始日期不能大于结束日期,请重新选择!');
  567. return false;
  568. }
  569. return true;
  570. }
  571. function updateTableRowStatus(tableData, rowIndex, status) {
  572. tableData[rowIndex].field5 = status;
  573. table.reload('myTable', {
  574. data: tableData
  575. });
  576. }
  577.  
  578. //批量运行点击事件
  579. document.getElementById('dialog-run').addEventListener('click', () => {
  580. let headForm = form.val('headForm')
  581. let tableCheckData = table.checkStatus('myTable')
  582. console.log('headForm:', headForm)
  583. console.log('tableCheckData:', tableCheckData)
  584.  
  585. // 用于存储所有异步任务(每个函数调用包装成一个Promise)
  586. const promises = [];
  587.  
  588. // 获取开始日期和结束日期的值
  589. const startDateStr = document.getElementById('layui-startTime').value;
  590. const endDateStr = document.getElementById('layui-endTime').value;
  591.  
  592. if (!validateDateRange(startDateStr, endDateStr)) {
  593. return;
  594. }
  595.  
  596. console.log('开始日期: ', startDateStr, '结束日期: ', endDateStr)
  597.  
  598. // 遍历被选择的行,创建异步任务并添加到promises数组
  599. tableCheckData.data.forEach((row, index) => {
  600. let rowIndex = tableData.findIndex((item) => item.field1 === row.field1);
  601. if (rowIndex!== -1) {
  602. updateTableRowStatus(tableData, rowIndex, '正在执行');
  603. const func = functionMap[row.field1];
  604. tableData[rowIndex].field5 = '正在执行';
  605. table.reload('myTable', {
  606. data: tableData
  607. });
  608. const promise = new Promise((resolve, reject) => {
  609. func(startDateStr, endDateStr).then(() => {
  610. // 函数执行成功后,将该行的field5更新为'已完成'
  611. updateTableRowStatus(tableData, rowIndex, '已完成');
  612. resolve();
  613. }).catch((error) => {
  614. // 如果函数执行出错,更新状态为'执行报错',方便直观查看问题
  615. tableData[rowIndex].field5 = '执行报错';
  616. table.reload('myTable', {
  617. data: tableData
  618. });
  619. console.error(`执行函数 ${func.name} 出错:`, error);
  620. reject(error);
  621. });
  622. });
  623. promises.push(promise);
  624. }
  625. });
  626.  
  627. // 使用Promise.all同时触发所有异步任务
  628. Promise.all(promises).then(() => {
  629.  
  630. }).catch((error) => {
  631. // 如果有任何一个函数执行出错,整体捕捉错误并可以进行相应提示等处理
  632. console.error('批量运行出现错误:', error);
  633. layer.msg('批量运行出现错误,请检查!', { icon: 5, time: 2000 });
  634. });
  635.  
  636. })
  637. let tableData = [
  638. {
  639. field1: 'D1信息对比数据',
  640. field2: '',
  641. field3: '',
  642. field4: '',
  643. field5: '未运行',
  644. },
  645. {
  646. field1: 'D3数据',
  647. field2: '',
  648. field3: '',
  649. field4: '',
  650. field5: '未运行',
  651. },
  652. {
  653. field1: '私有数据',
  654. field2: '',
  655. field3: '',
  656. field4: '',
  657. field5: '未运行',
  658. },
  659. {
  660. field1: '节点数据',
  661. field2: '',
  662. field3: '',
  663. field4: '',
  664. field5: '未运行',
  665. }
  666. ]
  667.  
  668. table.render({
  669. elem: '#myTable',
  670. cols: [[
  671. { type: 'checkbox', width: 80, },
  672. { field: 'field1', title: '接口名称' },
  673. { field: 'field2', title: '频率' },
  674. { field: 'field3', title: '周期' },
  675. { field: 'field4', title: '运行时间' },
  676. { field: 'field5', title: '运行状态' },
  677. ]],
  678. data: tableData,
  679. // height: 'full-35', // 最大高度减去其他容器已占有的高度差
  680. })
  681.  
  682. // 输出被选择的行数据
  683. // console.log('被选择的行数据:', tableCheckData);
  684.  
  685. // // 遍历被选择的行,将运行状态改为'正在执行'
  686. // tableCheckData.data.forEach((row) => {
  687. // let rowIndex = tableData.findIndex((item) => item.field1 === row.field1);
  688. // if (rowIndex!== -1) {
  689. // tableData[rowIndex].field5 = '正在执行';
  690. // }
  691. // });
  692. },
  693. cancel: function () {
  694. isWindowOpen = false;
  695. },
  696. });
  697. isWindowOpen = true;
  698. });
  699. }
  700. });
  701.  
  702. })();
  703.  
  704.  
  705.