B2B网络软件

标题: AIWROK软件智能任务监控悬浮窗 [打印本页]

作者: YYPOST群发软件    时间: 15 小时前
标题: AIWROK软件智能任务监控悬浮窗
AIWROK软件智能任务监控悬浮窗


AIWROK软件智能任务监控悬浮窗 B2B网络软件

  1. // 智能任务监控悬浮窗
  2. // 交流:711841924 / 528816639
  3. // 基于AIWROK软件安卓开发框架
  4. // 提供任务监控、进度显示、快速控制等功能

  5. function 智能任务监控() {
  6.     this.screenHeight = 1920; // 默认值  
  7.     this.screenWidth = 1080;  // 默认值
  8.     this.isExpanded = false;   // 展开状态
  9.     this.taskStatus = "待机";  // 任务状态
  10.     this.progress = 0;         // 进度百分比
  11.     this.taskCount = 0;        // 完成任务数
  12.     this.isRunning = false;    // 是否运行中
  13.     this.mainThread = null;    // 主脚本线程引用
  14.     this.isPaused = false;     // 是否暂停
  15. }

  16. // 创建悬浮窗实例
  17. var 监控窗口 = new 智能任务监控();

  18. // 创建悬浮窗方法
  19. 智能任务监控.prototype.create = function() {
  20.     try {
  21.         printl("===== 开始创建智能任务监控悬浮窗 =====");
  22.         
  23.         // 创建 floatUI 实例
  24.         var fui = new floatUI();
  25.         
  26.         // 获取屏幕尺寸
  27.         try {
  28.             var metrics = context.getResources().getDisplayMetrics();
  29.             this.screenHeight = metrics.heightPixels;
  30.             this.screenWidth = metrics.widthPixels;
  31.             printl("✅ 获取屏幕尺寸: " + this.screenWidth + "x" + this.screenHeight);
  32.         } catch(e) {
  33.             printl("⚠️ 获取屏幕尺寸失败,使用默认值: " + e);
  34.         }
  35.         
  36.         // 加载智能任务监控悬浮窗XML布局
  37.         fui.loadXML(`
  38.         <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  39.             android:layout_width="220dp"
  40.             android:layout_height="wrap_content"
  41.             android:background="#DD1E1E1E"
  42.             android:orientation="vertical"
  43.             android:padding="8dp"
  44.             android:elevation="10dp">
  45.             
  46.             <!-- 标题栏 -->
  47.             <LinearLayout
  48.                 android:layout_width="match_parent"
  49.                 android:layout_height="wrap_content"
  50.                 android:orientation="horizontal"
  51.                 android:gravity="center_vertical">
  52.                
  53.                 <TextView
  54.                     android:id="title_text"
  55.                     android:layout_width="0dp"
  56.                     android:layout_height="wrap_content"
  57.                     android:layout_weight="1"
  58.                     android:text="&#128202; 任务监控"
  59.                     android:textSize="14sp"
  60.                     android:textStyle="bold"
  61.                     android:textColor="#FFFFFF"/>
  62.                     
  63.                 <ImageButton
  64.                     android:id="btn_expand"
  65.                     android:layout_width="30dp"
  66.                     android:layout_height="30dp"
  67.                     android:src="@android:drawable/arrow_down_float"
  68.                     android:background="#00000000"
  69.                     android:scaleType="fitCenter"/>
  70.             </LinearLayout>
  71.             
  72.             <!-- 核心信息区域(始终显示) -->
  73.             <LinearLayout
  74.                 android:layout_width="match_parent"
  75.                 android:layout_height="wrap_content"
  76.                 android:orientation="vertical"
  77.                 android:layout_marginTop="5dp">
  78.                
  79.                 <!-- 状态显示 -->
  80.                 <TextView
  81.                     android:id="status_text"
  82.                     android:layout_width="match_parent"
  83.                     android:layout_height="wrap_content"
  84.                     android:text="状态: 待机"
  85.                     android:textSize="12sp"
  86.                     android:textColor="#00FF00"
  87.                     android:layout_marginBottom="3dp"/>
  88.                
  89.                 <!-- 进度条 -->
  90.                 <ProgressBar
  91.                     android:id="progress_bar"
  92.                     style="?android:attr/progressBarStyleHorizontal"
  93.                     android:layout_width="match_parent"
  94.                     android:layout_height="8dp"
  95.                     android:max="100"
  96.                     android:progress="0"
  97.                     android:progressDrawable="@android:drawable/progress_horizontal"
  98.                     android:layout_marginBottom="3dp"/>
  99.                
  100.                 <!-- 进度百分比 -->
  101.                 <TextView
  102.                     android:id="progress_text"
  103.                     android:layout_width="match_parent"
  104.                     android:layout_height="wrap_content"
  105.                     android:text="进度: 0%"
  106.                     android:textSize="11sp"
  107.                     android:textColor="#AAAAAA"
  108.                     android:gravity="right"/>
  109.             </LinearLayout>
  110.             
  111.             <!-- 详细信息区域(可展开) -->
  112.             <LinearLayout
  113.                 android:id="detail_layout"
  114.                 android:layout_width="match_parent"
  115.                 android:layout_height="wrap_content"
  116.                 android:orientation="vertical"
  117.                 android:visibility="gone"
  118.                 android:layout_marginTop="8dp">
  119.                
  120.                 <!-- 分隔线 -->
  121.                 <View
  122.                     android:layout_width="match_parent"
  123.                     android:layout_height="1dp"
  124.                     android:background="#444444"
  125.                     android:layout_marginBottom="5dp"/>
  126.                
  127.                 <!-- 统计信息 -->
  128.                 <TextView
  129.                     android:id="stats_text"
  130.                     android:layout_width="match_parent"
  131.                     android:layout_height="wrap_content"
  132.                     android:text="已完成: 0 个任务"
  133.                     android:textSize="11sp"
  134.                     android:textColor="#CCCCCC"
  135.                     android:layout_marginBottom="5dp"/>
  136.                
  137.                 <!-- 日志输出区 -->
  138.                 <ScrollView
  139.                     android:layout_width="match_parent"
  140.                     android:layout_height="60dp"
  141.                     android:background="#1A1A1A"
  142.                     android:padding="5dp"
  143.                     android:layout_marginBottom="5dp">
  144.                     
  145.                     <TextView
  146.                         android:id="log_text"
  147.                         android:layout_width="match_parent"
  148.                         android:layout_height="wrap_content"
  149.                         android:text="等待任务启动..."
  150.                         android:textSize="10sp"
  151.                         android:textColor="#888888"
  152.                         android:lineSpacingExtra="2dp"/>
  153.                 </ScrollView>
  154.                
  155.                 <!-- 控制按钮组 -->
  156.                 <LinearLayout
  157.                     android:layout_width="match_parent"
  158.                     android:layout_height="wrap_content"
  159.                     android:orientation="horizontal"
  160.                     android:gravity="center">
  161.                     
  162.                     <Button
  163.                         android:id="btn_start"
  164.                         android:layout_width="0dp"
  165.                         android:layout_height="32dp"
  166.                         android:layout_weight="1"
  167.                         android:text="▶ 启动"
  168.                         android:textSize="11sp"
  169.                         android:background="#28A745"
  170.                         android:textColor="#FFFFFF"
  171.                         android:layout_marginRight="2dp"/>
  172.                     
  173.                     <Button
  174.                         android:id="btn_pause"
  175.                         android:layout_width="0dp"
  176.                         android:layout_height="32dp"
  177.                         android:layout_weight="1"
  178.                         android:text="⏸ 暂停"
  179.                         android:textSize="11sp"
  180.                         android:background="#FFC107"
  181.                         android:textColor="#000000"
  182.                         android:layout_marginLeft="2dp"
  183.                         android:layout_marginRight="2dp"/>
  184.                     
  185.                     <Button
  186.                         android:id="btn_stop"
  187.                         android:layout_width="0dp"
  188.                         android:layout_height="32dp"
  189.                         android:layout_weight="1"
  190.                         android:text="⏹ 停止"
  191.                         android:textSize="11sp"
  192.                         android:background="#DC3545"
  193.                         android:textColor="#FFFFFF"
  194.                         android:layout_marginLeft="2dp"/>
  195.                 </LinearLayout>
  196.                
  197.                 <!-- 重置按钮 -->
  198.                 <Button
  199.                     android:id="btn_reset"
  200.                     android:layout_width="match_parent"
  201.                     android:layout_height="35dp"
  202.                     android:text="&#128260; 重置统计"
  203.                     android:textSize="12sp"
  204.                     android:background="#6C757D"
  205.                     android:textColor="#FFFFFF"
  206.                     android:layout_marginTop="5dp"
  207.                     android:layout_marginBottom="2dp"/>
  208.             </LinearLayout>
  209.         </LinearLayout>
  210.         `);
  211.         
  212.         // 保存floatUI实例
  213.         this.ui = fui;
  214.         
  215.         // 设置初始位置(屏幕右侧居中)
  216.         var posX = this.screenWidth - 240;
  217.         var posY = (this.screenHeight - 350) / 2;
  218.         this.setPos(posX, posY);
  219.         
  220.         // 获取UI元素
  221.         this.title_text = fui.findViewById("title_text");
  222.         this.btn_expand = fui.findViewById("btn_expand");
  223.         this.status_text = fui.findViewById("status_text");
  224.         this.progress_bar = fui.findViewById("progress_bar");
  225.         this.progress_text = fui.findViewById("progress_text");
  226.         this.detail_layout = fui.findViewById("detail_layout");
  227.         this.stats_text = fui.findViewById("stats_text");
  228.         this.log_text = fui.findViewById("log_text");
  229.         this.btn_start = fui.findViewById("btn_start");
  230.         this.btn_pause = fui.findViewById("btn_pause");
  231.         this.btn_stop = fui.findViewById("btn_stop");
  232.         this.btn_reset = fui.findViewById("btn_reset");
  233.         
  234.         // 初始化按钮事件
  235.         this.initButtons();
  236.         
  237.         printl("✅ 智能任务监控悬浮窗创建成功");
  238.         toast.show("&#128202; 任务监控已就绪");
  239.         
  240.     } catch (err) {
  241.         printl("❌ 悬浮窗创建失败: " + err);
  242.     }
  243. };

  244. // 初始化按钮事件
  245. 智能任务监控.prototype.initButtons = function() {
  246.     var self = this;
  247.    
  248.     // 展开/收起按钮点击事件
  249.     this.btn_expand.setOnClickListener(function() {
  250.         self.toggleDetail();
  251.     });
  252.    
  253.     // 启动按钮点击事件
  254.     this.btn_start.setOnClickListener(function() {
  255.         self.startTask();
  256.     });
  257.    
  258.     // 暂停按钮点击事件
  259.     this.btn_pause.setOnClickListener(function() {
  260.         self.pauseTask();
  261.     });
  262.    
  263.     // 停止按钮点击事件
  264.     this.btn_stop.setOnClickListener(function() {
  265.         self.stopTask();
  266.     });
  267.    
  268.     // 重置按钮点击事件
  269.     this.btn_reset.setOnClickListener(function() {
  270.         self.resetStats();
  271.     });
  272. };

  273. // 展开/收起详细信息
  274. 智能任务监控.prototype.toggleDetail = function() {
  275.     if (this.isExpanded) {
  276.         // 收起
  277.         this.detail_layout.setVisibility(View.GONE);
  278.         this.isExpanded = false;
  279.         printl("&#128316; 详细信息已收起");
  280.     } else {
  281.         // 展开
  282.         this.detail_layout.setVisibility(View.VISIBLE);
  283.         this.isExpanded = true;
  284.         printl("&#128317; 详细信息已展开");
  285.     }
  286. };

  287. // 启动任务
  288. 智能任务监控.prototype.startTask = function() {
  289.     if (this.isRunning) {
  290.         toast.show("⚠️ 任务已在运行中");
  291.         return;
  292.     }
  293.    
  294.     try {
  295.         printl(" 正在启动主脚本...");
  296.         this.addLog("&#128640; 正在加载主脚本...");
  297.         
  298.         // 使用AIWROK的thread API启动主脚本
  299.         var self = this;
  300.         var threadObj = new thread();
  301.         this.mainThread = threadObj;
  302.         this.isRunning = true;
  303.         this.isPaused = false;
  304.         
  305.         // 在线程中执行主脚本代码
  306.         threadObj.runJsCode(function() {
  307.             try {
  308.                 printl("✅ 主脚本线程已启动");
  309.                 // 使用Import加载主脚本
  310.                 Import("主脚本.js");
  311.             } catch(e) {
  312.                 printl(" 主脚本执行失败: " + e);
  313.             }
  314.         }, "主脚本线程");
  315.         
  316.         this.taskStatus = "运行中";
  317.         this.updateStatus("#00FF00", "状态: 运行中");
  318.         this.addLog("✅ 主脚本已启动");
  319.         toast.show("▶ 主脚本启动成功");
  320.         
  321.         // 模拟进度更新
  322.         this.taskTimer = setInterval(function() {
  323.             if (!self.isRunning) {
  324.                 clearInterval(self.taskTimer);
  325.                 return;
  326.             }
  327.             
  328.             // 如果暂停,不更新进度
  329.             if (self.isPaused) {
  330.                 return;
  331.             }
  332.             
  333.             self.progress += 2;
  334.             if (self.progress >= 100) {
  335.                 self.progress = 100;
  336.                 self.taskCount++;
  337.                 self.addLog("✅ 任务完成 #" + self.taskCount);
  338.                 self.updateStats();
  339.                
  340.                 // 重置进度,模拟下一个任务
  341.                 setTimeout(function() {
  342.                     if (self.isRunning && !self.isPaused) {
  343.                         self.progress = 0;
  344.                         self.addLog("&#128260; 开始新任务...");
  345.                     }
  346.                 }, 1000);
  347.             }
  348.             
  349.             self.updateProgress();
  350.         }, 2000);
  351.         
  352.     } catch(e) {
  353.         printl("❌ 启动失败: " + e);
  354.         this.addLog("❌ 启动失败: " + e);
  355.         toast.show(" 主脚本启动失败");
  356.     }
  357. };

  358. // 暂停任务
  359. 智能任务监控.prototype.pauseTask = function() {
  360.     if (!this.isRunning) {
  361.         toast.show("⚠️ 任务未在运行");
  362.         return;
  363.     }
  364.    
  365.     try {
  366.         // 暂停标志
  367.         this.isPaused = true;
  368.         
  369.         // 中断主脚本线程
  370.         if (this.mainThread) {
  371.             this.mainThread.stop();
  372.             printl("⏸ 主脚本线程已暂停");
  373.         }
  374.         
  375.         this.taskStatus = "已暂停";
  376.         this.updateStatus("#FFC107", "状态: 已暂停");
  377.         this.addLog("⏸ 主脚本已暂停");
  378.         toast.show("⏸ 主脚本暂停");
  379.         
  380.         if (this.taskTimer) {
  381.             clearInterval(this.taskTimer);
  382.         }
  383.     } catch(e) {
  384.         printl("❌ 暂停失败: " + e);
  385.         this.addLog("❌ 暂停失败: " + e);
  386.         toast.show("❌ 暂停失败");
  387.     }
  388. };

  389. // 停止任务
  390. 智能任务监控.prototype.stopTask = function() {
  391.     try {
  392.         // 停止主脚本线程
  393.         if (this.mainThread) {
  394.             this.mainThread.stop();
  395.             this.mainThread = null;
  396.             printl("⏹ 主脚本线程已停止");
  397.         }
  398.         
  399.         this.isRunning = false;
  400.         this.isPaused = false;
  401.         this.taskStatus = "已停止";
  402.         this.updateStatus("#DC3545", "状态: 已停止");
  403.         this.addLog("⏹ 主脚本已停止");
  404.         toast.show("⏹ 主脚本停止");
  405.         
  406.         if (this.taskTimer) {
  407.             clearInterval(this.taskTimer);
  408.         }
  409.     } catch(e) {
  410.         printl("❌ 停止失败: " + e);
  411.         this.addLog("❌ 停止失败: " + e);
  412.         toast.show("❌ 停止失败");
  413.     }
  414. };

  415. // 重置统计
  416. 智能任务监控.prototype.resetStats = function() {
  417.     // 先停止当前任务
  418.     if (this.isRunning) {
  419.         this.stopTask();
  420.     }
  421.    
  422.     this.progress = 0;
  423.     this.taskCount = 0;
  424.     this.taskStatus = "待机";
  425.     this.isRunning = false;
  426.     this.isPaused = false;
  427.     this.mainThread = null;
  428.    
  429.     this.updateProgress();
  430.     this.updateStatus("#00FF00", "状态: 待机");
  431.     this.updateStats();
  432.     this.log_text.setText("等待任务启动...");
  433.    
  434.     toast.show("&#128260; 统计已重置");
  435.     printl("&#128260; 统计数据已重置");
  436. };

  437. // 更新进度显示
  438. 智能任务监控.prototype.updateProgress = function() {
  439.     this.progress_bar.setProgress(this.progress);
  440.     this.progress_text.setText("进度: " + this.progress + "%");
  441. };

  442. // 更新状态显示
  443. 智能任务监控.prototype.updateStatus = function(color, text) {
  444.     this.status_text.setTextColor(android.graphics.Color.parseColor(color));
  445.     this.status_text.setText(text);
  446. };

  447. // 更新统计信息
  448. 智能任务监控.prototype.updateStats = function() {
  449.     this.stats_text.setText("已完成: " + this.taskCount + " 个任务");
  450. };

  451. // 添加日志
  452. 智能任务监控.prototype.addLog = function(message) {
  453.     var currentTime = new Date().toLocaleTimeString();
  454.     var currentLog = this.log_text.getText().toString();
  455.     var newLog = "[" + currentTime + "] " + message + "\n" + currentLog;
  456.    
  457.     // 限制日志行数,最多保留10行
  458.     var lines = newLog.split("\n");
  459.     if (lines.length > 10) {
  460.         lines = lines.slice(0, 10);
  461.         newLog = lines.join("\n");
  462.     }
  463.    
  464.     this.log_text.setText(newLog);
  465. };

  466. // 设置悬浮窗位置
  467. 智能任务监控.prototype.setPos = function(x, y) {
  468.     this.ui.setPosition(x, y);
  469.     printl("&#128205; 悬浮窗位置设置为: (" + x + ", " + y + ")");
  470. };

  471. // 关闭悬浮窗
  472. 智能任务监控.prototype.close = function() {
  473.     // 先停止主脚本线程
  474.     if (this.mainThread) {
  475.         this.mainThread.stop();
  476.         this.mainThread = null;
  477.     }
  478.    
  479.     // 清除定时器
  480.     if (this.taskTimer) {
  481.         clearInterval(this.taskTimer);
  482.     }
  483.    
  484.     this.ui.close();
  485.     printl("✅ 智能任务监控悬浮窗已关闭");
  486. };

  487. // 启动悬浮窗
  488. try {
  489.     监控窗口.create();
  490.     printl("===== 智能任务监控悬浮窗启动成功 =====");
  491. } catch (err) {
  492.     printl("❌ 智能任务监控悬浮窗启动失败: " + err);
  493. }

  494. //本脚本是专为 ES5 系统安卓 JavaScript 引擎 Rhino 开发、
  495. //基于 AIWROK 框架的智能任务监控悬浮窗工具,运行后会在屏幕右侧居中生成可展开收起的悬浮窗,
  496. //核心提供自动化任务全流程管控能力,能实时显示任务运行状态、进度条和完成任务数,
  497. //集成启动、暂停、停止、重置统计四大核心控制按钮,内置带时间戳的日志系统自动保留最新 10 条运行记录,
  498. //支持自动适配不同设备屏幕尺寸,所有操作均有 Toast 提示和控制台日志反馈,
  499. //只需将需执行的自动化代码保存为同目录下的 "主脚本.js",
  500. //点击悬浮窗启动按钮即可开始监控,无需额外配置即可快速上手使用。
复制代码







欢迎光临 B2B网络软件 (http://bbs.niubt.cn/) Powered by Discuz! X3.2