YYPOST群发软件 发表于 4 天前

AIWROK苹果脚本H5任务执行小例子

AIWROK苹果脚本H5任务执行小例子




AIWROK苹果脚本H5任务执行小例子
// 创建 WebView 实例
var web = new WebView();

// 显示 WebView 界面
web.show();

// 加载本地 HTML 文件
var htmlPath = project.getCodePath() + "h5.html";
web.loadFile(htmlPath);

// 定义 H5 中调用的函数
function test(arg) {
    printl("我被 H5 调用了,参数是: " + arg);
}

// 定义返回桌面的函数,供H5页面调用
function returnToHome() {
    printl("执行返回桌面操作");
    hid.home();
}

// 打印加载信息
printl("WebView 已创建并加载本地文件: " + htmlPath);<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>AIWROK 智能任务调度中心</title>
    <style>
      /* 基础样式重置 */
      * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
      }

      /* 全局样式 */
      body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: #333;
            min-height: 100vh;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            position: relative;
            overflow-x: hidden;
      }

      /* 背景动画粒子 */
      .particles {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: 0;
            overflow: hidden;
      }

      .particle {
            position: absolute;
            width: 10px;
            height: 10px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            animation: float 6s ease-in-out infinite;
      }

      .particle:nth-child(1) { left: 10%; animation-delay: 0s; }
      .particle:nth-child(2) { left: 20%; animation-delay: 1s; }
      .particle:nth-child(3) { left: 30%; animation-delay: 2s; }
      .particle:nth-child(4) { left: 40%; animation-delay: 3s; }
      .particle:nth-child(5) { left: 50%; animation-delay: 4s; }
      .particle:nth-child(6) { left: 60%; animation-delay: 5s; }
      .particle:nth-child(7) { left: 70%; animation-delay: 0.5s; }
      .particle:nth-child(8) { left: 80%; animation-delay: 1.5s; }
      .particle:nth-child(9) { left: 90%; animation-delay: 2.5s; }
      .particle:nth-child(10) { left: 5%; animation-delay: 3.5s; }

      @keyframes float {
            0%, 100% {
                transform: translateY(100vh) rotate(0deg);
                opacity: 0;
            }
            10% {
                opacity: 1;
            }
            90% {
                opacity: 1;
            }
            100% {
                transform: translateY(-100vh) rotate(720deg);
                opacity: 0;
            }
      }

      /* 主容器 */
      .main-container {
            position: relative;
            z-index: 1;
            max-width: 500px;
            margin: 0 auto;
            padding: 20px;
      }

      /* 头部卡片 */
      .header-card {
            background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.9) 100%);
            border-radius: 24px;
            padding: 24px;
            margin-bottom: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            backdrop-filter: blur(10px);
            text-align: center;
      }

      .header-card h1 {
            font-size: 24px;
            font-weight: 800;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            margin-bottom: 8px;
      }

      .header-card .subtitle {
            font-size: 14px;
            color: #666;
            margin-bottom: 12px;
      }

      .header-card .qq-group {
            font-size: 13px;
            color: #667eea;
            font-weight: 600;
      }

      /* 统计卡片 */
      .stats-container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 12px;
            margin-bottom: 20px;
      }

      .stat-card {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 16px;
            padding: 16px 8px;
            text-align: center;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease;
      }

      .stat-card:hover {
            transform: translateY(-4px);
      }

      .stat-card .number {
            font-size: 28px;
            font-weight: 800;
            color: #667eea;
            display: block;
      }

      .stat-card .label {
            font-size: 12px;
            color: #666;
            margin-top: 4px;
      }

      /* 标签页导航 */
      .tab-nav {
            display: flex;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 16px;
            padding: 6px;
            margin-bottom: 20px;
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
      }

      .tab-btn {
            flex: 1;
            padding: 12px 8px;
            border: none;
            background: transparent;
            border-radius: 12px;
            font-size: 14px;
            font-weight: 600;
            color: #666;
            cursor: pointer;
            transition: all 0.3s ease;
      }

      .tab-btn.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
      }

      /* 内容区域 */
      .content-area {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 24px;
            padding: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            min-height: 400px;
      }

      .tab-content {
            display: none;
      }

      .tab-content.active {
            display: block;
            animation: fadeIn 0.3s ease-out;
      }

      @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
      }

      /* 任务列表 */
      .task-list {
            list-style: none;
      }

      .task-item {
            display: flex;
            align-items: center;
            padding: 16px;
            background: #f8f9fa;
            border-radius: 12px;
            margin-bottom: 12px;
            transition: all 0.3s ease;
            cursor: pointer;
      }

      .task-item:hover {
            background: #e9ecef;
            transform: translateX(4px);
      }

      .task-item.selected {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border: 2px solid #667eea;
      }

      .task-checkbox {
            width: 24px;
            height: 24px;
            margin-right: 12px;
            cursor: pointer;
            accent-color: #667eea;
      }

      .task-info {
            flex: 1;
      }

      .task-name {
            font-size: 15px;
            font-weight: 600;
            color: #333;
            margin-bottom: 4px;
      }

      .task-desc {
            font-size: 12px;
            color: #666;
      }

      .task-status {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
      }

      .task-status.pending {
            background: #fff3cd;
            color: #856404;
      }

      .task-status.running {
            background: #d4edda;
            color: #155724;
      }

      .task-status.completed {
            background: #d1ecf1;
            color: #0c5460;
      }

      /* 设置表单 */
      .settings-form {
            space-y: 16px;
      }

      .form-group {
            margin-bottom: 20px;
      }

      .form-label {
            display: block;
            font-size: 14px;
            font-weight: 600;
            color: #333;
            margin-bottom: 8px;
      }

      .form-input {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e9ecef;
            border-radius: 12px;
            font-size: 15px;
            transition: all 0.3s ease;
      }

      .form-input:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
      }

      .form-select {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e9ecef;
            border-radius: 12px;
            font-size: 15px;
            background: white;
            cursor: pointer;
      }

      /* 开关样式 */
      .switch-container {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 16px;
            background: #f8f9fa;
            border-radius: 12px;
            margin-bottom: 12px;
      }

      .switch-label {
            font-size: 15px;
            font-weight: 500;
            color: #333;
      }

      .switch {
            position: relative;
            width: 52px;
            height: 28px;
      }

      .switch input {
            opacity: 0;
            width: 0;
            height: 0;
      }

      .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
            border-radius: 28px;
      }

      .slider:before {
            position: absolute;
            content: "";
            height: 20px;
            width: 20px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
      }

      input:checked + .slider {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      }

      input:checked + .slider:before {
            transform: translateX(24px);
      }

      /* 按钮样式 */
      .btn {
            width: 100%;
            padding: 16px;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 700;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-bottom: 12px;
      }

      .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
      }

      .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
      }

      .btn-danger {
            background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
            color: white;
            box-shadow: 0 4px 16px rgba(255, 107, 107, 0.4);
      }

      .btn-danger:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(255, 107, 107, 0.5);
      }

      .btn-success {
            background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
            color: white;
            box-shadow: 0 4px 16px rgba(81, 207, 102, 0.4);
      }

      .btn-success:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(81, 207, 102, 0.5);
      }

      .btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
      }

      /* 日志区域 */
      .log-container {
            background: #1a1a2e;
            border-radius: 12px;
            padding: 16px;
            max-height: 200px;
            overflow-y: auto;
            font-family: 'Courier New', monospace;
            font-size: 12px;
      }

      .log-item {
            color: #a0a0a0;
            margin-bottom: 4px;
            padding: 4px 0;
            border-bottom: 1px solid #2a2a3e;
      }

      .log-item:last-child {
            border-bottom: none;
      }

      .log-time {
            color: #667eea;
            margin-right: 8px;
      }

      .log-info { color: #4dabf7; }
      .log-success { color: #51cf66; }
      .log-warning { color: #ffd43b; }
      .log-error { color: #ff6b6b; }

      /* Toast 提示 */
      .toast {
            position: fixed;
            bottom: 100px;
            left: 50%;
            transform: translateX(-50%) translateY(100px);
            background: rgba(0, 0, 0, 0.9);
            color: white;
            padding: 16px 32px;
            border-radius: 50px;
            font-size: 14px;
            font-weight: 600;
            opacity: 0;
            transition: all 0.3s ease;
            z-index: 9999;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
      }

      .toast.show {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
      }

      /* 加载动画 */
      .loading {
            position: relative;
      }

      .loading::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 20px;
            height: 20px;
            margin: -10px 0 0 -10px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            border-top-color: white;
            border-radius: 50%;
            animation: spin 1s linear infinite;
      }

      @keyframes spin {
            to { transform: rotate(360deg); }
      }

      /* 响应式设计 */
      @media (max-width: 480px) {
            .main-container {
                padding: 16px;
            }
            
            .stats-container {
                grid-template-columns: repeat(3, 1fr);
                gap: 8px;
            }
            
            .stat-card {
                padding: 12px 4px;
            }
            
            .stat-card .number {
                font-size: 20px;
            }
      }
    </style>
</head>
<body>
    <!-- 背景粒子 -->
    <div class="particles">
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
      <div class="particle"></div>
    </div>

    <div class="main-container">
      <!-- 头部卡片 -->
      <div class="header-card">
            <h1>智能任务调度中心</h1>
            <div class="subtitle">AIWROK 自动化任务管理系统</div>
            <div class="qq-group">&#127822;交流QQ群711841924群一,苹果内测群,528816639</div>
      </div>

      <!-- 统计卡片 -->
      <div class="stats-container">
            <div class="stat-card">
                <span class="number" id="pendingCount">0</span>
                <div class="label">待执行</div>
            </div>
            <div class="stat-card">
                <span class="number" id="runningCount">0</span>
                <div class="label">执行中</div>
            </div>
            <div class="stat-card">
                <span class="number" id="completedCount">0</span>
                <div class="label">已完成</div>
            </div>
      </div>

      <!-- 标签页导航 -->
      <div class="tab-nav">
            <button class="tab-btn active" onclick="switchTab('tasks')">任务列表</button>
            <button class="tab-btn" onclick="switchTab('settings')">系统设置</button>
            <button class="tab-btn" onclick="switchTab('logs')">运行日志</button>
      </div>

      <!-- 内容区域 -->
      <div class="content-area">
            <!-- 任务列表 -->
            <div id="tasks-tab" class="tab-content active">
                <ul class="task-list" id="taskList">
                  <!-- 任务项将通过JS动态生成 -->
                </ul>
                <button class="btn btn-primary" onclick="executeSelectedTasks()">
                  执行选中任务
                </button>
                <button class="btn btn-danger" onclick="clearAllTasks()">
                  清空所有任务
                </button>
            </div>

            <!-- 系统设置 -->
            <div id="settings-tab" class="tab-content">
                <div class="settings-form">
                  <div class="form-group">
                        <label class="form-label">运行间隔 (秒)</label>
                        <input type="number" class="form-input" id="intervalInput" value="5" min="1" max="60">
                  </div>
                  
                  <div class="form-group">
                        <label class="form-label">最大重试次数</label>
                        <input type="number" class="form-input" id="retryInput" value="3" min="1" max="10">
                  </div>

                  <div class="form-group">
                        <label class="form-label">执行模式</label>
                        <select class="form-select" id="modeSelect">
                            <option value="serial">顺序执行</option>
                            <option value="parallel">并行执行</option>
                            <option value="smart">智能调度</option>
                        </select>
                  </div>

                  <div class="switch-container">
                        <span class="switch-label">任务完成后返回桌面</span>
                        <label class="switch">
                            <input type="checkbox" id="autoReturn" checked>
                            <span class="slider"></span>
                        </label>
                  </div>

                  <div class="switch-container">
                        <span class="switch-label">自动清理缓存</span>
                        <label class="switch">
                            <input type="checkbox" id="autoClean" checked>
                            <span class="slider"></span>
                        </label>
                  </div>

                  <div class="switch-container">
                        <span class="switch-label">后台运行</span>
                        <label class="switch">
                            <input type="checkbox" id="backgroundRun">
                            <span class="slider"></span>
                        </label>
                  </div>

                  <div class="switch-container">
                        <span class="switch-label">错误自动重试</span>
                        <label class="switch">
                            <input type="checkbox" id="autoRetry" checked>
                            <span class="slider"></span>
                        </label>
                  </div>

                  <button class="btn btn-success" onclick="saveSettings()">
                        保存设置
                  </button>
                </div>
            </div>

            <!-- 运行日志 -->
            <div id="logs-tab" class="tab-content">
                <div class="log-container" id="logContainer">
                  <div class="log-item">
                        <span class="log-time">[系统]</span>
                        <span class="log-info">任务调度中心已启动</span>
                  </div>
                </div>
                <button class="btn btn-primary" onclick="clearLogs()">
                  清空日志
                </button>
            </div>
      </div>
    </div>

    <!-- Toast 提示 -->
    <div class="toast" id="toast"></div>

    <script>
      // 任务数据
      const tasksData = [
            { id: 1, name: '抖音极速版', desc: '自动刷视频赚金币', status: 'pending' },
            { id: 2, name: '快手极速版', desc: '自动浏览任务', status: 'pending' },
            { id: 3, name: '番茄小说', desc: '自动阅读赚金币', status: 'pending' },
            { id: 4, name: '番茄畅听', desc: '自动听书任务', status: 'pending' },
            { id: 5, name: '红果短剧', desc: '自动刷短剧', status: 'pending' },
            { id: 6, name: '悟空浏览器', desc: '自动浏览资讯', status: 'pending' },
            { id: 7, name: '西瓜视频', desc: '自动看视频赚金币', status: 'pending' },
            { id: 8, name: '今日头条', desc: '自动阅读新闻', status: 'pending' },
            { id: 9, name: '喜番短剧', desc: '自动刷短剧任务', status: 'pending' },
            { id: 10, name: '汽水音乐', desc: '自动听歌赚金币', status: 'pending' }
      ];

      // 当前选中的任务
      let selectedTasks = new Set();

      // 初始化
      function init() {
            renderTaskList();
            updateStats();
            addLog('系统初始化完成', 'info');
      }

      // 渲染任务列表
      function renderTaskList() {
            const taskList = document.getElementById('taskList');
            taskList.innerHTML = '';

            tasksData.forEach(task => {
                const li = document.createElement('li');
                li.className = 'task-item' + (selectedTasks.has(task.id) ? ' selected' : '');
                li.onclick = function(e) {
                  if (e.target.type !== 'checkbox') {
                        toggleTaskSelection(task.id);
                  }
                };

                const statusClass = task.status;
                const statusText = {
                  'pending': '待执行',
                  'running': '执行中',
                  'completed': '已完成'
                };

                li.innerHTML = `
                  <input type="checkbox" class="task-checkbox"
                           ${selectedTasks.has(task.id) ? 'checked' : ''}
                           onchange="toggleTaskSelection(${task.id})">
                  <div class="task-info">
                        <div class="task-name">${task.name}</div>
                        <div class="task-desc">${task.desc}</div>
                  </div>
                  <span class="task-status ${statusClass}">${statusText}</span>
                `;

                taskList.appendChild(li);
            });
      }

      // 切换任务选择
      function toggleTaskSelection(taskId) {
            if (selectedTasks.has(taskId)) {
                selectedTasks.delete(taskId);
            } else {
                selectedTasks.add(taskId);
            }
            renderTaskList();
      }

      // 更新统计
      function updateStats() {
            const pending = tasksData.filter(t => t.status === 'pending').length;
            const running = tasksData.filter(t => t.status === 'running').length;
            const completed = tasksData.filter(t => t.status === 'completed').length;

            document.getElementById('pendingCount').textContent = pending;
            document.getElementById('runningCount').textContent = running;
            document.getElementById('completedCount').textContent = completed;
      }

      // 切换标签页
      function switchTab(tabName) {
            // 更新按钮状态
            document.querySelectorAll('.tab-btn').forEach(btn => {
                btn.classList.remove('active');
            });
            event.target.classList.add('active');

            // 更新内容显示
            document.querySelectorAll('.tab-content').forEach(content => {
                content.classList.remove('active');
            });
            document.getElementById(tabName + '-tab').classList.add('active');

            addLog('切换到' + tabName + '页面', 'info');
      }

      // 执行选中的任务
      function executeSelectedTasks() {
            if (selectedTasks.size === 0) {
                showToast('请先选择要执行的任务');
                return;
            }

            const btn = event.target;
            btn.classList.add('loading');
            btn.disabled = true;

            showToast('开始执行 ' + selectedTasks.size + ' 个任务');
            addLog('开始执行 ' + selectedTasks.size + ' 个任务', 'info');

            // 模拟任务执行
            let completed = 0;
            selectedTasks.forEach(taskId => {
                const task = tasksData.find(t => t.id === taskId);
                if (task) {
                  task.status = 'running';
                  addLog('开始执行: ' + task.name, 'info');
                }
            });

            renderTaskList();
            updateStats();

            // 模拟执行完成
            setTimeout(function() {
                selectedTasks.forEach(taskId => {
                  const task = tasksData.find(t => t.id === taskId);
                  if (task) {
                        task.status = 'completed';
                        completed++;
                        addLog('完成: ' + task.name, 'success');
                  }
                });

                selectedTasks.clear();
                renderTaskList();
                updateStats();

                btn.classList.remove('loading');
                btn.disabled = false;

                showToast('任务执行完成');
                addLog('所有任务执行完成', 'success');

                // 检查是否需要返回桌面
                const autoReturn = document.getElementById('autoReturn').checked;
                if (autoReturn) {
                  setTimeout(function() {
                        showToast('正在返回桌面');
                        addLog('任务完成,返回桌面', 'info');
                        
                        // 尝试不同方式调用返回桌面
                        let success = false;
                        
                        // 方式1:直接调用hid.home()
                        try {
                            if (typeof hid !== 'undefined' && typeof hid.home === 'function') {
                              hid.home();
                              addLog('已调用 hid.home() 返回桌面', 'success');
                              success = true;
                            }
                        } catch (e) {}
                        
                        // 方式2:调用全局home()函数
                        if (!success) {
                            try {
                              if (typeof home === 'function') {
                                    home();
                                    addLog('已调用 home() 返回桌面', 'success');
                                    success = true;
                              }
                            } catch (e) {}
                        }
                        
                        // 方式3:调用window.home()
                        if (!success) {
                            try {
                              if (typeof window !== 'undefined' && typeof window.home === 'function') {
                                    window.home();
                                    addLog('已调用 window.home() 返回桌面', 'success');
                                    success = true;
                              }
                            } catch (e) {}
                        }
                        
                        // 方式4:调用window.hid.home()
                        if (!success) {
                            try {
                              if (typeof window !== 'undefined' && window.hid && typeof window.hid.home === 'function') {
                                    window.hid.home();
                                    addLog('已调用 window.hid.home() 返回桌面', 'success');
                                    success = true;
                              }
                            } catch (e) {}
                        }
                        
                        // 方式5:使用eval调用
                        if (!success) {
                            try {
                              eval('hid.home()');
                              addLog('已调用 eval(hid.home()) 返回桌面', 'success');
                              success = true;
                            } catch (e) {}
                        }
                        
                        // 方式6:使用全局对象调用
                        if (!success) {
                            try {
                              // 尝试使用全局对象
                              const globalObj = (function() { return this; })();
                              if (globalObj && globalObj.hid && typeof globalObj.hid.home === 'function') {
                                    globalObj.hid.home();
                                    addLog('已调用 globalObj.hid.home() 返回桌面', 'success');
                                    success = true;
                              }
                            } catch (e) {}
                        }
                        
                        // 如果所有方式都失败
                        if (!success) {
                            addLog('返回桌面功能暂不可用,请确保在AIWROK环境中运行', 'warning');
                            showToast('返回桌面功能暂不可用');
                        }
                  }, 1000);
                }
            }, 2000);
      }

      // 清空所有任务
      function clearAllTasks() {
            if (!confirm('确定要清空所有任务状态吗?')) {
                return;
            }

            tasksData.forEach(task => {
                task.status = 'pending';
            });
            selectedTasks.clear();
            renderTaskList();
            updateStats();

            showToast('所有任务已重置');
            addLog('所有任务状态已重置', 'warning');
      }

      // 保存设置
      function saveSettings() {
            const settings = {
                interval: document.getElementById('intervalInput').value,
                retry: document.getElementById('retryInput').value,
                mode: document.getElementById('modeSelect').value,
                autoClean: document.getElementById('autoClean').checked,
                backgroundRun: document.getElementById('backgroundRun').checked,
                autoRetry: document.getElementById('autoRetry').checked
            };

            const btn = event.target;
            btn.classList.add('loading');
            btn.disabled = true;

            setTimeout(function() {
                btn.classList.remove('loading');
                btn.disabled = false;

                showToast('设置保存成功');
                addLog('系统设置已保存: ' + JSON.stringify(settings), 'success');
            }, 1000);
      }

      // 清空日志
      function clearLogs() {
            document.getElementById('logContainer').innerHTML = `
                <div class="log-item">
                  <span class="log-time">[系统]</span>
                  <span class="log-info">日志已清空</span>
                </div>
            `;
            showToast('日志已清空');
      }

      // 添加日志
      function addLog(message, type) {
            const container = document.getElementById('logContainer');
            const time = new Date().toLocaleTimeString();
            const typeClass = 'log-' + type;

            const logItem = document.createElement('div');
            logItem.className = 'log-item';
            logItem.innerHTML = `
                <span class="log-time">[${time}]</span>
                <span class="${typeClass}">${message}</span>
            `;

            container.appendChild(logItem);
            container.scrollTop = container.scrollHeight;
      }

      // Toast 提示
      function showToast(message) {
            const toast = document.getElementById('toast');
            toast.textContent = message;
            toast.classList.add('show');

            setTimeout(function() {
                toast.classList.remove('show');
            }, 2000);
      }

      // 页面加载完成
      window.onload = function() {
            init();
            showToast('智能任务调度中心已启动');
            
            // 绑定所有事件
            bindAllEvents();
      };

      // 绑定所有事件
      function bindAllEvents() {
            // 输入框事件
            bindInputEvents();
            
            // 开关事件
            bindSwitchEvents();
            
            // 下拉菜单事件
            bindSelectEvents();
            
            // 键盘事件
            bindKeyboardEvents();
            
            // 窗口事件
            bindWindowEvents();
      }

      // 绑定输入框事件
      function bindInputEvents() {
            const inputs = document.querySelectorAll('.form-input');
            inputs.forEach(input => {
                input.addEventListener('input', function() {
                  addLog('设置已更新: ' + this.id + ' = ' + this.value, 'info');
                });
               
                input.addEventListener('focus', function() {
                  this.style.borderColor = '#667eea';
                  this.style.boxShadow = '0 0 0 3px rgba(102, 126, 234, 0.1)';
                });
               
                input.addEventListener('blur', function() {
                  this.style.borderColor = '#e9ecef';
                  this.style.boxShadow = 'none';
                });
            });
      }

      // 绑定开关事件
      function bindSwitchEvents() {
            const switches = document.querySelectorAll('.switch input');
            switches.forEach(switchEl => {
                switchEl.addEventListener('change', function() {
                  const label = this.closest('.switch-container').querySelector('.switch-label').textContent;
                  addLog('设置已更新: ' + label + ' = ' + (this.checked ? '开启' : '关闭'), 'info');
                });
            });
      }

      // 绑定下拉菜单事件
      function bindSelectEvents() {
            const selects = document.querySelectorAll('.form-select');
            selects.forEach(select => {
                select.addEventListener('change', function() {
                  addLog('设置已更新: ' + this.id + ' = ' + this.value, 'info');
                });
               
                select.addEventListener('focus', function() {
                  this.style.borderColor = '#667eea';
                  this.style.boxShadow = '0 0 0 3px rgba(102, 126, 234, 0.1)';
                });
               
                select.addEventListener('blur', function() {
                  this.style.borderColor = '#e9ecef';
                  this.style.boxShadow = 'none';
                });
            });
      }

      // 绑定键盘事件
      function bindKeyboardEvents() {
            document.addEventListener('keydown', function(e) {
                // 按 Enter 键执行选中任务
                if (e.key === 'Enter' && document.getElementById('tasks-tab').classList.contains('active')) {
                  const selectedCount = selectedTasks.size;
                  if (selectedCount > 0) {
                        executeSelectedTasks();
                  }
                }
               
                // 按 Escape 键清空选择
                if (e.key === 'Escape') {
                  selectedTasks.clear();
                  renderTaskList();
                  addLog('已清空任务选择', 'info');
                }
            });
      }

      // 绑定窗口事件
      function bindWindowEvents() {
            // 窗口大小变化事件
            window.addEventListener('resize', function() {
                addLog('窗口大小已变化', 'info');
            });
            
            // 页面可见性变化事件
            document.addEventListener('visibilitychange', function() {
                if (document.hidden) {
                  addLog('页面已隐藏', 'info');
                } else {
                  addLog('页面已显示', 'info');
                }
            });
      }
    </script>
</body>
</html>


页: [1]
查看完整版本: AIWROK苹果脚本H5任务执行小例子