 | |  |  | 本帖最后由 发帖软件 于 2026-3-20 07:15 编辑
安卓H5互动config配置调取存入示例
- <!DOCTYPE html>
- <!--
- 🍎交流 QQ 群:711841924(群一 - 苹果内测群)
- 🍎交流 QQ 群:528816639
- 🍎 AIWROK 配置管理器 - 可视化配置界面
- -->
- <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; }
-
- :root {
- --primary: #4A90E2;
- --primary-dark: #357ABD;
- --success: #2ECC71;
- --warning: #F39C12;
- --danger: #E74C3C;
- --purple: #9B59B6;
- --bg-dark: #1a1a2e;
- --bg-card: #16213e;
- --bg-input: #0f0f23;
- --text-primary: #ffffff;
- --text-secondary: #a0a0a0;
- --border-color: rgba(255, 255, 255, 0.1);
- }
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
- background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-card) 50%, #0f0f23 100%);
- color: var(--text-primary);
- min-height: 100vh;
- overflow-x: hidden;
- }
- /* QQ 群信息栏 */
- .qq-group-bar {
- background: linear-gradient(90deg, #FF6B6B 0%, #FF8E53 50%, #FFD700 100%);
- padding: 10px 16px;
- text-align: center;
- position: relative;
- z-index: 20;
- box-shadow: 0 2px 10px rgba(0,0,0,0.3);
- }
- .qq-group-text {
- font-size: 13px;
- font-weight: 700;
- color: #fff;
- text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
- }
- .app-container {
- position: relative;
- z-index: 10;
- max-width: 600px;
- margin: 0 auto;
- padding: 16px;
- }
- /* 顶部标题 */
- .header {
- background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
- border-radius: 20px;
- padding: 24px;
- margin-bottom: 20px;
- box-shadow: 0 10px 40px rgba(74, 144, 226, 0.3);
- text-align: center;
- }
- .header-icon {
- font-size: 48px;
- margin-bottom: 8px;
- }
- .header-title {
- font-size: 24px;
- font-weight: 800;
- margin-bottom: 4px;
- }
- .header-subtitle {
- font-size: 13px;
- opacity: 0.9;
- }
- /* 统计卡片 */
- .stats-row {
- display: grid;
- grid-template-columns: repeat(3, 1fr);
- gap: 12px;
- margin-bottom: 20px;
- }
- .stat-box {
- background: var(--bg-card);
- border-radius: 16px;
- padding: 16px 8px;
- text-align: center;
- border: 1px solid rgba(74, 144, 226, 0.2);
- }
- .stat-icon {
- font-size: 24px;
- margin-bottom: 4px;
- }
- .stat-value {
- font-size: 20px;
- font-weight: 800;
- color: var(--primary);
- }
- .stat-label {
- font-size: 11px;
- color: var(--text-secondary);
- margin-top: 2px;
- }
- /* 分类标签 */
- .category-tabs {
- display: flex;
- gap: 8px;
- margin-bottom: 20px;
- overflow-x: auto;
- padding-bottom: 8px;
- }
- .category-tab {
- padding: 10px 20px;
- background: var(--bg-card);
- border: 1px solid var(--border-color);
- border-radius: 25px;
- font-size: 13px;
- font-weight: 600;
- color: var(--text-secondary);
- cursor: pointer;
- white-space: nowrap;
- transition: all 0.3s ease;
- }
- .category-tab:hover {
- border-color: var(--primary);
- color: var(--primary);
- }
- .category-tab.active {
- background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
- color: white;
- border-color: transparent;
- box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
- }
- /* 配置列表 */
- .config-section {
- background: var(--bg-card);
- border-radius: 20px;
- padding: 20px;
- margin-bottom: 20px;
- border: 1px solid var(--border-color);
- }
- .section-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 16px;
- padding-bottom: 12px;
- border-bottom: 1px solid var(--border-color);
- }
- .section-title {
- display: flex;
- align-items: center;
- gap: 10px;
- font-size: 16px;
- font-weight: 700;
- }
- .section-icon {
- font-size: 20px;
- }
- .section-actions {
- display: flex;
- gap: 8px;
- }
- .action-btn {
- padding: 6px 12px;
- border: none;
- border-radius: 8px;
- font-size: 12px;
- font-weight: 600;
- cursor: pointer;
- transition: all 0.2s ease;
- }
- .btn-reset {
- background: rgba(231, 76, 60, 0.2);
- color: var(--danger);
- }
- .btn-reset:hover {
- background: rgba(231, 76, 60, 0.3);
- }
- .btn-save {
- background: rgba(46, 204, 113, 0.2);
- color: var(--success);
- }
- .btn-save:hover {
- background: rgba(46, 204, 113, 0.3);
- }
- /* 配置项 */
- .config-item {
- margin-bottom: 16px;
- padding-bottom: 16px;
- border-bottom: 1px solid rgba(255, 255, 255, 0.05);
- }
- .config-item:last-child {
- margin-bottom: 0;
- padding-bottom: 0;
- border-bottom: none;
- }
- .config-label {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 8px;
- }
- .label-text {
- font-size: 14px;
- font-weight: 600;
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .label-hint {
- font-size: 11px;
- color: var(--text-secondary);
- font-weight: normal;
- }
- .config-input-wrapper {
- position: relative;
- }
- .config-input {
- width: 100%;
- padding: 12px 16px;
- border: 1px solid var(--border-color);
- border-radius: 10px;
- background: var(--bg-input);
- color: var(--text-primary);
- font-size: 14px;
- outline: none;
- transition: all 0.3s ease;
- }
- .config-input:focus {
- border-color: var(--primary);
- box-shadow: 0 0 10px rgba(74, 144, 226, 0.2);
- }
- .config-input.readonly {
- background: rgba(255, 255, 255, 0.05);
- cursor: not-allowed;
- }
- /* 开关 */
- .switch {
- position: relative;
- width: 50px;
- height: 26px;
- }
- .switch input {
- opacity: 0;
- width: 0;
- height: 0;
- }
- .slider {
- position: absolute;
- cursor: pointer;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background-color: #333;
- transition: .4s;
- border-radius: 26px;
- }
- .slider:before {
- position: absolute;
- content: "";
- height: 20px;
- width: 20px;
- left: 3px;
- bottom: 3px;
- background-color: white;
- transition: .4s;
- border-radius: 50%;
- }
- input:checked + .slider {
- background: linear-gradient(135deg, var(--success) 0%, #27AE60 100%);
- }
- input:checked + .slider:before {
- transform: translateX(24px);
- }
- /* 按钮组 */
- .button-group {
- display: grid;
- grid-template-columns: repeat(2, 1fr);
- gap: 12px;
- margin-top: 20px;
- }
- .main-btn {
- padding: 16px;
- border: none;
- border-radius: 16px;
- font-size: 16px;
- font-weight: 800;
- cursor: pointer;
- transition: all 0.3s ease;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 8px;
- }
- .btn-primary {
- background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
- color: white;
- box-shadow: 0 8px 32px rgba(74, 144, 226, 0.4);
- }
- .btn-primary:hover {
- transform: translateY(-2px);
- box-shadow: 0 12px 40px rgba(74, 144, 226, 0.5);
- }
- .btn-secondary {
- background: linear-gradient(135deg, var(--purple) 0%, #8E44AD 100%);
- color: white;
- box-shadow: 0 8px 32px rgba(155, 89, 182, 0.4);
- }
- .btn-warning {
- background: linear-gradient(135deg, var(--warning) 0%, #E67E22 100%);
- color: white;
- box-shadow: 0 8px 32px rgba(243, 156, 18, 0.4);
- }
- .btn-danger {
- background: linear-gradient(135deg, var(--danger) 0%, #C0392B 100%);
- color: white;
- box-shadow: 0 8px 32px rgba(231, 76, 60, 0.4);
- }
- /* Toast */
- .toast {
- position: fixed;
- bottom: 100px;
- left: 50%;
- transform: translateX(-50%) translateY(100px);
- background: linear-gradient(135deg, var(--success) 0%, #27AE60 100%);
- color: white;
- padding: 16px 32px;
- border-radius: 50px;
- font-weight: 700;
- opacity: 0;
- transition: all 0.3s ease;
- z-index: 9999;
- box-shadow: 0 8px 32px rgba(46, 204, 113, 0.4);
- }
- .toast.show {
- opacity: 1;
- transform: translateX(-50%) translateY(0);
- }
- .toast.error {
- background: linear-gradient(135deg, var(--danger) 0%, #C0392B 100%);
- }
- /* 日志窗口 */
- .log-panel {
- background: var(--bg-card);
- border-radius: 20px;
- padding: 20px;
- margin-top: 20px;
- border: 1px solid var(--border-color);
- }
- .log-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 16px;
- }
- .log-title {
- display: flex;
- align-items: center;
- gap: 10px;
- font-size: 16px;
- font-weight: 700;
- }
- .log-container {
- background: var(--bg-input);
- border-radius: 12px;
- padding: 12px;
- max-height: 300px;
- overflow-y: auto;
- font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
- font-size: 12px;
- line-height: 1.8;
- }
- .log-entry {
- padding: 4px 8px;
- margin-bottom: 4px;
- border-radius: 4px;
- border-left: 3px solid var(--primary);
- }
- .log-entry.success { border-left-color: var(--success); }
- .log-entry.error { border-left-color: var(--danger); }
- .log-entry.warning { border-left-color: var(--warning); }
- /* 动画 */
- @keyframes slideUp {
- from { opacity: 0; transform: translateY(20px); }
- to { opacity: 1; transform: translateY(0); }
- }
- .config-section {
- animation: slideUp 0.4s ease;
- }
- </style>
- </head>
- <body>
- <!-- QQ 群信息栏 -->
- <div class="qq-group-bar">
- <span class="qq-group-text">🍎交流 QQ 群:711841924(群一 - 苹果内测群)528816639</span>
- </div>
- <div class="app-container">
- <!-- 顶部标题 -->
- <div class="header">
- <div class="header-icon">⚙️</div>
- <div class="header-title">AIWROK 配置管理中心</div>
- <div class="header-subtitle">可视化配置管理 · 实时同步 · 智能推荐</div>
- </div>
- <!-- 统计卡片 -->
- <div class="stats-row">
- <div class="stat-box">
- <div class="stat-icon">📊</div>
- <div class="stat-value" id="totalConfigs">0</div>
- <div class="stat-label">总配置数</div>
- </div>
- <div class="stat-box">
- <div class="stat-icon">✅</div>
- <div class="stat-value" id="configuredCount">0</div>
- <div class="stat-label">已配置</div>
- </div>
- <div class="stat-box">
- <div class="stat-icon">💾</div>
- <div class="stat-value" id="lastSaveTime">-</div>
- <div class="stat-label">最后保存</div>
- </div>
- </div>
- <!-- 分类标签 -->
- <div class="category-tabs">
- <div class="category-tab active" data-category="all" onclick="filterCategory('all')">全部</div>
- <div class="category-tab" data-category="game" onclick="filterCategory('game')">🎮 游戏配置</div>
- <div class="category-tab" data-category="ocr" onclick="filterCategory('ocr')">🔍 OCR 配置</div>
- <div class="category-tab" data-category="ui" onclick="filterCategory('ui')">🎨 UI 配置</div>
- <div class="category-tab" data-category="network" onclick="filterCategory('network')">🌐 网络配置</div>
- </div>
- <!-- 游戏配置 -->
- <div class="config-section" data-category="game">
- <div class="section-header">
- <div class="section-title">
- <span class="section-icon">🎮</span>
- <span>游戏自动化配置</span>
- </div>
- <div class="section-actions">
- <button class="action-btn btn-reset" onclick="resetGameConfig()">重置</button>
- <button class="action-btn btn-save" onclick="saveGameConfig()">保存</button>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 📝 游戏名称
- <span class="label-hint">要自动化的游戏</span>
- </span>
- </div>
- <input type="text" class="config-input" id="game_name" value="梦幻西游" placeholder="输入游戏名称">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- ⏱️ 任务延迟 (毫秒)
- <span class="label-hint">操作间隔时间</span>
- </span>
- </div>
- <input type="number" class="config-input" id="task_delay" value="2000" min="500" max="10000">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 🔄 最大轮数
- <span class="label-hint">最多执行轮次</span>
- </span>
- </div>
- <input type="number" class="config-input" id="max_rounds" value="10" min="1" max="100">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">⚔️ 启用自动战斗</span>
- <label class="switch">
- <input type="checkbox" id="enable_combat" checked>
- <span class="slider"></span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">💊 自动治疗</span>
- <label class="switch">
- <input type="checkbox" id="auto_heal" checked>
- <span class="slider"></span>
- </label>
- </div>
- </div>
- </div>
- <!-- OCR 配置 -->
- <div class="config-section" data-category="ocr">
- <div class="section-header">
- <div class="section-title">
- <span class="section-icon">🔍</span>
- <span>OCR 识别配置</span>
- </div>
- <div class="section-actions">
- <button class="action-btn btn-reset" onclick="resetOcrConfig()">重置</button>
- <button class="action-btn btn-save" onclick="saveOcrConfig()">保存</button>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 🌐 识别语言
- <span class="label-hint">OCR 识别语言</span>
- </span>
- </div>
- <select class="config-input" id="ocr_language">
- <option value="zh-CN">简体中文</option>
- <option value="zh-TW">繁体中文</option>
- <option value="en">英文</option>
- <option value="ja">日文</option>
- <option value="ko">韩文</option>
- </select>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 🎯 置信度阈值 (%)
- <span class="label-hint">最低识别置信度</span>
- </span>
- </div>
- <input type="number" class="config-input" id="ocr_confidence" value="80" min="50" max="100">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- ⏰ 超时时间 (毫秒)
- <span class="label-hint">识别超时限制</span>
- </span>
- </div>
- <input type="number" class="config-input" id="ocr_timeout" value="5000" min="1000" max="30000">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">🔄 重试次数</span>
- <label class="switch">
- <input type="number" class="config-input" id="ocr_retry" value="3" min="0" max="10" style="width: 100px; display: inline-block;">
- </label>
- </div>
- </div>
- </div>
- <!-- UI 配置 -->
- <div class="config-section" data-category="ui">
- <div class="section-header">
- <div class="section-title">
- <span class="section-icon">🎨</span>
- <span>界面偏好配置</span>
- </div>
- <div class="section-actions">
- <button class="action-btn btn-reset" onclick="resetUiConfig()">重置</button>
- <button class="action-btn btn-save" onclick="saveUiConfig()">保存</button>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">🌓 主题模式</span>
- <select class="config-input" id="ui_theme" style="width: 150px;">
- <option value="dark">深色主题</option>
- <option value="light">浅色主题</option>
- <option value="auto">自动跟随</option>
- </select>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 📏 字体大小 (px)
- <span class="label-hint">界面字体大小</span>
- </span>
- </div>
- <input type="number" class="config-input" id="ui_font_size" value="16" min="12" max="24">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">🧰 显示工具栏</span>
- <label class="switch">
- <input type="checkbox" id="ui_show_toolbar" checked>
- <span class="slider"></span>
- </label>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">✨ 启用动画效果</span>
- <label class="switch">
- <input type="checkbox" id="ui_animation" checked>
- <span class="slider"></span>
- </label>
- </div>
- </div>
- </div>
- <!-- 网络配置 -->
- <div class="config-section" data-category="network">
- <div class="section-header">
- <div class="section-title">
- <span class="section-icon">🌐</span>
- <span>网络请求配置</span>
- </div>
- <div class="section-actions">
- <button class="action-btn btn-reset" onclick="resetNetworkConfig()">重置</button>
- <button class="action-btn btn-save" onclick="saveNetworkConfig()">保存</button>
- </div>
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 🔗 API 基础地址
- <span class="label-hint">服务器地址</span>
- </span>
- </div>
- <input type="text" class="config-input" id="network_base_url" value="https://api.example.com" placeholder="https://api.example.com">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- 📡 API 版本
- <span class="label-hint">API 版本号</span>
- </span>
- </div>
- <input type="text" class="config-input" id="network_version" value="v2" placeholder="v2">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">
- ⏰ 请求超时 (毫秒)
- <span class="label-hint">网络请求超时</span>
- </span>
- </div>
- <input type="number" class="config-input" id="network_timeout" value="10000" min="5000" max="60000">
- </div>
- <div class="config-item">
- <div class="config-label">
- <span class="label-text">🔄 最大重试次数</span>
- <input type="number" class="config-input" id="network_retries" value="3" min="0" max="10" style="width: 100px; display: inline-block;">
- </div>
- </div>
- </div>
- <!-- 操作按钮组 -->
- <div class="button-group">
- <button class="main-btn btn-primary" onclick="saveAllConfigs()">
- 💾 保存所有配置
- </button>
- <button class="main-btn btn-secondary" onclick="exportConfigs()">
- 📤 导出配置
- </button>
- <button class="main-btn btn-warning" onclick="importConfigs()">
- 📥 导入配置
- </button>
- <button class="main-btn btn-danger" onclick="resetAllConfigs()">
- 🗑️ 恢复默认
- </button>
- </div>
- <!-- 日志窗口 -->
- <div class="log-panel">
- <div class="log-header">
- <div class="log-title">
- <span class="section-icon">📋</span>
- <span>操作日志</span>
- </div>
- </div>
- <div class="log-container" id="logContainer">
- <div class="log-empty" style="text-align: center; padding: 20px; color: #666;">
- 等待操作...
- </div>
- </div>
- </div>
- </div>
- <!-- Toast -->
- <div class="toast" id="toast"></div>
- <script>
- // ============================================
- // AIWROK 配置管理中心 - 核心逻辑
- // ============================================
-
- var CONFIG = {
- VERSION: '1.0.0'
- };
- var state = {
- totalConfigs: 0,
- configuredCount: 0,
- lastSaveTime: null,
- logs: []
- };
- // 默认配置值
- var defaultConfigs = {
- // 游戏配置
- game_name: "梦幻西游",
- task_delay: "2000",
- max_rounds: "10",
- enable_combat: "true",
- auto_heal: "true",
-
- // OCR 配置
- ocr_language: "zh-CN",
- ocr_confidence: "80",
- ocr_timeout: "5000",
- ocr_retry: "3",
-
- // UI 配置
- ui_theme: "dark",
- ui_font_size: "16",
- ui_show_toolbar: "true",
- ui_animation: "true",
-
- // 网络配置
- network_base_url: "https://api.example.com",
- network_version: "v2",
- network_timeout: "10000",
- network_retries: "3"
- };
- // 初始化
- document.addEventListener('DOMContentLoaded', function() {
- addLog('⚙️ AIWROK 配置管理中心 v' + CONFIG.VERSION + ' 已启动', 'success');
- loadAllConfigs();
- updateStats();
- });
- // 添加日志
- function addLog(message, type) {
- type = type || 'info';
- var container = document.getElementById('logContainer');
-
- // 移除空状态
- var emptyState = container.querySelector('.log-empty');
- if (emptyState) emptyState.remove();
-
- var entry = document.createElement('div');
- entry.className = 'log-entry ' + type;
- entry.textContent = '[' + new Date().toLocaleTimeString() + '] ' + message;
-
- container.appendChild(entry);
- container.scrollTop = container.scrollHeight;
-
- // 限制日志数量
- while (container.children.length > 50) {
- container.removeChild(container.firstChild);
- }
- }
- // 更新统计
- function updateStats() {
- document.getElementById('totalConfigs').textContent = Object.keys(defaultConfigs).length;
- document.getElementById('configuredCount').textContent = state.configuredCount;
-
- if (state.lastSaveTime) {
- var time = new Date(state.lastSaveTime);
- document.getElementById('lastSaveTime').textContent =
- time.getHours().toString().padStart(2, '0') + ':' +
- time.getMinutes().toString().padStart(2, '0');
- }
- }
- // 过滤分类
- function filterCategory(category) {
- // 更新标签状态
- var tabs = document.querySelectorAll('.category-tab');
- for (var i = 0; i < tabs.length; i++) {
- tabs[i].classList.toggle('active', tabs[i].dataset.category === category);
- }
-
- // 过滤配置区块
- var sections = document.querySelectorAll('.config-section');
- for (var j = 0; j < sections.length; j++) {
- var section = sections[j];
- if (category === 'all' || section.dataset.category === category) {
- section.style.display = 'block';
- } else {
- section.style.display = 'none';
- }
- }
-
- addLog('📂 切换到分类:' + category, 'info');
- }
- // 加载配置
- function loadAllConfigs() {
- addLog('📥 正在加载配置...', 'info');
-
- // 尝试从原生环境加载
- for (var key in defaultConfigs) {
- var element = document.getElementById(key);
- if (!element) continue;
-
- var value = getConfigFromNative(key);
- if (value !== null && value !== undefined && value !== '') {
- if (element.type === 'checkbox') {
- element.checked = value === 'true';
- } else {
- element.value = value;
- }
- state.configuredCount++;
- } else {
- if (element.type === 'checkbox') {
- element.checked = defaultConfigs[key] === 'true';
- } else {
- element.value = defaultConfigs[key];
- }
- }
- }
-
- addLog('✅ 配置加载完成', 'success');
- updateStats();
- }
- // 从原生环境获取配置(适配 AIWROK)
- function getConfigFromNative(key) {
- // 优先使用 Android 桥接接口
- if (window.android && typeof window.android.getConfig === 'function') {
- try {
- var value = window.android.getConfig(key, '');
- console.log('从 android 接口获取配置 ' + key + ': ' + value);
- return value;
- } catch (e) {
- console.error('android 接口获取配置失败:', e);
- }
- }
- // 浏览器环境使用 localStorage 模拟
- try {
- return localStorage.getItem('AIWROK_' + key);
- } catch (e) {
- return null;
- }
- }
- // 设置配置到原生环境(适配 AIWROK)
- function setConfigToNative(key, value) {
- // 优先使用 Android 桥接接口
- if (window.android && typeof window.android.setConfig === 'function') {
- try {
- var result = window.android.setConfig(key, value);
- console.log('设置配置 ' + key + ' = ' + value + ': ' + (result ? '成功' : '失败'));
- return result;
- } catch (e) {
- console.error('设置配置失败:', e);
- return false;
- }
- }
- // 浏览器环境使用 localStorage 模拟
- try {
- localStorage.setItem('AIWROK_' + key, value);
- return true;
- } catch (e) {
- return false;
- }
- }
- // 保存单个分类的配置
- function saveCategoryConfig(category, configKeys) {
- addLog('💾 正在保存' + category + '配置...', 'info');
-
- for (var i = 0; i < configKeys.length; i++) {
- var key = configKeys[i];
- var element = document.getElementById(key);
- if (!element) continue;
-
- var value;
- if (element.type === 'checkbox') {
- value = element.checked ? 'true' : 'false';
- } else {
- value = element.value;
- }
-
- setConfigToNative(key, value);
- addLog(' ✓ ' + key + ' = ' + value, 'success');
- }
-
- state.lastSaveTime = Date.now();
- state.configuredCount = Object.keys(defaultConfigs).length;
- updateStats();
-
- showToast('✅ ' + category + '配置已保存');
- }
- // 各个分类的保存函数
- function saveGameConfig() {
- saveCategoryConfig('游戏', ['game_name', 'task_delay', 'max_rounds', 'enable_combat', 'auto_heal']);
- }
- function saveOcrConfig() {
- saveCategoryConfig('OCR', ['ocr_language', 'ocr_confidence', 'ocr_timeout', 'ocr_retry']);
- }
- function saveUiConfig() {
- saveCategoryConfig('UI', ['ui_theme', 'ui_font_size', 'ui_show_toolbar', 'ui_animation']);
- }
- function saveNetworkConfig() {
- saveCategoryConfig('网络', ['network_base_url', 'network_version', 'network_timeout', 'network_retries']);
- }
- // 保存所有配置
- function saveAllConfigs() {
- addLog('💾 正在保存所有配置...', 'info');
-
- for (var key in defaultConfigs) {
- var element = document.getElementById(key);
- if (!element) continue;
-
- var value;
- if (element.type === 'checkbox') {
- value = element.checked ? 'true' : 'false';
- } else {
- value = element.value;
- }
-
- setConfigToNative(key, value);
- }
-
- state.lastSaveTime = Date.now();
- state.configuredCount = Object.keys(defaultConfigs).length;
- updateStats();
-
- addLog('✅ 所有配置已保存', 'success');
- showToast('✅ 所有配置已保存');
- }
- // 重置配置
- function resetCategoryConfig(category, configKeys, displayName) {
- addLog('🗑️ 正在重置' + displayName + '配置...', 'warning');
-
- for (var i = 0; i < configKeys.length; i++) {
- var key = configKeys[i];
- var element = document.getElementById(key);
- if (!element) continue;
-
- var defaultValue = defaultConfigs[key];
- if (element.type === 'checkbox') {
- element.checked = defaultValue === 'true';
- } else {
- element.value = defaultValue;
- }
-
- addLog(' ✓ ' + key + ' 恢复为:' + defaultValue, 'info');
- }
-
- showToast('🗑️ ' + displayName + '配置已重置');
- }
- function resetGameConfig() {
- resetCategoryConfig('游戏', ['game_name', 'task_delay', 'max_rounds', 'enable_combat', 'auto_heal'], '游戏');
- }
- function resetOcrConfig() {
- resetCategoryConfig('OCR', ['ocr_language', 'ocr_confidence', 'ocr_timeout', 'ocr_retry'], 'OCR');
- }
- function resetUiConfig() {
- resetCategoryConfig('UI', ['ui_theme', 'ui_font_size', 'ui_show_toolbar', 'ui_animation'], 'UI');
- }
- function resetNetworkConfig() {
- resetCategoryConfig('网络', ['network_base_url', 'network_version', 'network_timeout', 'network_retries'], '网络');
- }
- function resetAllConfigs() {
- if (!confirm('确定要恢复所有配置为默认值吗?')) return;
-
- addLog('🗑️ 正在恢复所有配置...', 'warning');
-
- for (var key in defaultConfigs) {
- var element = document.getElementById(key);
- if (!element) continue;
-
- var defaultValue = defaultConfigs[key];
- if (element.type === 'checkbox') {
- element.checked = defaultValue === 'true';
- } else {
- element.value = defaultValue;
- }
- }
-
- addLog('✅ 所有配置已恢复默认值', 'success');
- showToast('🗑️ 所有配置已恢复默认');
- }
- // 导出配置
- function exportConfigs() {
- addLog('📤 正在导出配置...', 'info');
-
- var exported = {};
- for (var key in defaultConfigs) {
- var element = document.getElementById(key);
- if (!element) continue;
-
- var value;
- if (element.type === 'checkbox') {
- value = element.checked ? 'true' : 'false';
- } else {
- value = element.value;
- }
-
- exported[key] = value;
- }
-
- var jsonStr = JSON.stringify(exported, null, 2);
- addLog('✅ 配置已导出:\n' + jsonStr, 'success');
-
- // 尝试复制到剪贴板
- if (navigator.clipboard) {
- navigator.clipboard.writeText(jsonStr).then(function() {
- showToast('📤 配置已导出并复制到剪贴板');
- }, function() {
- showToast('📤 配置已导出(请查看日志)');
- });
- } else {
- showToast('📤 配置已导出(请查看日志)');
- }
- }
- // 导入配置
- function importConfigs() {
- var jsonStr = prompt('请粘贴配置 JSON 数据:');
- if (!jsonStr) return;
-
- try {
- var imported = JSON.parse(jsonStr);
- addLog('📥 正在导入配置...', 'info');
-
- for (var key in imported) {
- var element = document.getElementById(key);
- if (!element) continue;
-
- var value = imported[key];
- if (element.type === 'checkbox') {
- element.checked = value === 'true';
- } else {
- element.value = String(value);
- }
-
- addLog(' ✓ 导入 ' + key + ' = ' + value, 'success');
- }
-
- addLog('✅ 配置导入完成', 'success');
- showToast('📥 配置已成功导入');
- } catch (e) {
- addLog('❌ 配置导入失败:' + e.message, 'error');
- showToast('❌ 配置格式错误');
- }
- }
- // 显示 Toast
- function showToast(message, isError) {
- var toast = document.getElementById('toast');
- toast.textContent = message;
- toast.className = 'toast show' + (isError ? ' error' : '');
-
- setTimeout(function() {
- toast.className = 'toast';
- }, 3000);
- }
- </script>
- </body>
- </html>
复制代码
| |  | |  |
|