zhunk hai 6 meses
pai
achega
ec4f13fe26

+ 65 - 0
app_bzy_armhf_7/CLAUDE.md

@@ -0,0 +1,65 @@
+# CLAUDE.md
+
+Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.
+
+**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
+
+## 1. Think Before Coding
+
+**Don't assume. Don't hide confusion. Surface tradeoffs.**
+
+Before implementing:
+- State your assumptions explicitly. If uncertain, ask.
+- If multiple interpretations exist, present them - don't pick silently.
+- If a simpler approach exists, say so. Push back when warranted.
+- If something is unclear, stop. Name what's confusing. Ask.
+
+## 2. Simplicity First
+
+**Minimum code that solves the problem. Nothing speculative.**
+
+- No features beyond what was asked.
+- No abstractions for single-use code.
+- No "flexibility" or "configurability" that wasn't requested.
+- No error handling for impossible scenarios.
+- If you write 200 lines and it could be 50, rewrite it.
+
+Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
+
+## 3. Surgical Changes
+
+**Touch only what you must. Clean up only your own mess.**
+
+When editing existing code:
+- Don't "improve" adjacent code, comments, or formatting.
+- Don't refactor things that aren't broken.
+- Match existing style, even if you'd do it differently.
+- If you notice unrelated dead code, mention it - don't delete it.
+
+When your changes create orphans:
+- Remove imports/variables/functions that YOUR changes made unused.
+- Don't remove pre-existing dead code unless asked.
+
+The test: Every changed line should trace directly to the user's request.
+
+## 4. Goal-Driven Execution
+
+**Define success criteria. Loop until verified.**
+
+Transform tasks into verifiable goals:
+- "Add validation" → "Write tests for invalid inputs, then make them pass"
+- "Fix the bug" → "Write a test that reproduces it, then make it pass"
+- "Refactor X" → "Ensure tests pass before and after"
+
+For multi-step tasks, state a brief plan:
+```
+1. [Step] → verify: [check]
+2. [Step] → verify: [check]
+3. [Step] → verify: [check]
+```
+
+Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
+
+---
+
+**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.

+ 6 - 1
app_bzy_armhf_7/CMakeLists.txt

@@ -146,6 +146,11 @@ else()
     message(WARNING "ZLIB not found, trying alternative methods")
 endif()
 
+
+file(GLOB MARKDOWN_FILES "*.md" "docs/*.md")  # 根据你的目录结构调整
+# 创建一个虚拟目标,仅用于在 IDE 中显示文件
+add_custom_target(docs SOURCES ${MARKDOWN_FILES})
+
 ## 链接路径
 if(WIN32)
     message(STATUS ${PROJECT_SOURCE_DIR})
@@ -245,5 +250,5 @@ target_link_libraries(app_bzy_armhf_7
 # find_package(FelgoHotReload REQUIRED)
 # target_link_libraries(appapp_bzy_armhf_7 PRIVATE FelgoHotReload)
 if (ANDROID)
-    include(D:/Felgo/AndroidEnv/android_sdk/android_openssl-master/android_openssl-master/CMakeLists.txt)
+    include(F:/Android_Env/android-sdk-windows/android_openssl/CMakeLists.txt)
 endif()

+ 2 - 2
app_bzy_armhf_7/android/AndroidManifest.xml

@@ -2,7 +2,7 @@
 <manifest package="com.yfkj.bzyv1" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" xmlns:tools="http://schemas.android.com/tools" android:installLocation="auto" android:versionCode="0" android:versionName="0"> android:versionCode=&quot;0&quot; android:versionName=&quot;0&quot;&gt;
     <!-- Enable instant app support -->
     <!-- <module dist:instant="true"/> -->
-    <application android:allowBackup="true" android:allowNativeHeapPointerTagging="false" android:hardwareAccelerated="true" android:extractNativeLibs="true" android:name="com.felgo.helper.FelgoApplication" android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:preserveLegacyExternalStorage="true" android:requestLegacyExternalStorage="true">
+    <application android:allowBackup="true" android:allowNativeHeapPointerTagging="false" android:hardwareAccelerated="true" android:extractNativeLibs="true" android:name="com.felgo.helper.FelgoApplication" android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme" android:preserveLegacyExternalStorage="true" android:requestLegacyExternalStorage="true">
         <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.felgo.helper.FelgoActivity" android:exported="true" android:launchMode="singleTop" android:label="@string/app_name" android:screenOrientation="landscape" android:excludeFromRecents="true" android:taskAffinity="com.yfkj.bzyv1">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN"/>
@@ -86,7 +86,7 @@
 
 <!-- 允许应用程序完全使用网络 -->
 <!-- 对于Android 10及以上,如果您需要访问媒体文件,还需要声明: -->
-<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> <!-- 可选,如果需要图片中的位置信息 -->
+<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/> <!-- 可选,如果需要图片中的位置信息 -->
 
 <!-- 允许应用程序访问外部存储器SD卡 -->
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

+ 3 - 2
app_bzy_armhf_7/android/res/values/styles.xml

@@ -17,10 +17,11 @@
 <resources>
 
     <!-- Base application theme. -->
-    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
-        <item name="android:windowBackground">@drawable/ic_launcher_background</item>
+    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
+        <item name="android:windowBackground">@android:color/black</item>
         <item name="android:windowNoTitle">true</item>
         <item name="android:windowFullscreen">true</item>
+        <item name="android:windowContentOverlay">@null</item>
     </style>
 
     <style name="BottomSheetSpinnerItemStyle" parent="Widget.AppCompat.Light.DropDownItem.Spinner">

+ 106 - 0
app_bzy_armhf_7/android/src/com/yfkj/bzyv1/MyQtActivity.java

@@ -3,6 +3,8 @@ import android.app.Activity;
 import android.os.Bundle;
 import com.felgo.helper.FelgoActivity;
 import android.view.WindowManager;
+import android.util.Log;
+import android.content.pm.PackageManager;
 
 public class MyQtActivity extends FelgoActivity {
     private static Activity currentActivity;
@@ -17,6 +19,110 @@ public class MyQtActivity extends FelgoActivity {
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         currentActivity = this;
+        
+        // 初始化权限管理
+        initPermissions();
+    }
+    
+    /**
+     * 初始化权限申请
+     */
+    private void initPermissions() {
+        Log.d("MyQtActivity", "Initializing permissions...");
+        
+        // 检查并申请权限
+        boolean allGranted = PermissionManager.checkAndRequestPermissions(this);
+        
+        if (allGranted) {
+            Log.d("MyQtActivity", "All permissions already granted");
+            onPermissionsGranted();
+        } else {
+            Log.d("MyQtActivity", "Requesting permissions from user");
+        }
+    }
+    
+    /**
+     * 权限申请结果回调
+     */
+    @Override
+    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+        
+        PermissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
+        
+        if (requestCode == PermissionManager.PERMISSION_REQUEST_CODE) {
+            boolean allGranted = true;
+            for (int result : grantResults) {
+                if (result != PackageManager.PERMISSION_GRANTED) {
+                    allGranted = false;
+                    break;
+                }
+            }
+            
+            if (allGranted) {
+                Log.d("MyQtActivity", "All permissions granted by user");
+                onPermissionsGranted();
+            } else {
+                Log.w("MyQtActivity", "Some permissions were denied");
+                onPermissionsDenied();
+            }
+        }
+    }
+    
+    /**
+     * 权限全部授权后的回调
+     */
+    private void onPermissionsGranted() {
+        Log.d("MyQtActivity", "Permissions granted, application can proceed");
+        // 这里可以通知Qt层权限已就绪
+    }
+    
+    /**
+     * 权限被拒绝后的回调
+     */
+    private void onPermissionsDenied() {
+        Log.w("MyQtActivity", "Some permissions were denied, application may not function properly");
+        // 这里可以处理权限被拒绝的情况
+    }
+    
+    /**
+     * 检查特定权限状态
+     */
+    public static boolean hasPermission(String permission) {
+        if (currentActivity != null) {
+            return PermissionManager.isPermissionGranted(currentActivity, permission);
+        }
+        return false;
+    }
+    
+    /**
+     * 检查文件读写权限
+     */
+    public static boolean hasStoragePermission() {
+        if (currentActivity != null) {
+            return PermissionManager.hasStoragePermission(currentActivity);
+        }
+        return false;
+    }
+    
+    /**
+     * 检查相机权限
+     */
+    public static boolean hasCameraPermission() {
+        if (currentActivity != null) {
+            return PermissionManager.hasCameraPermission(currentActivity);
+        }
+        return false;
+    }
+    
+    /**
+     * 检查位置权限
+     */
+    public static boolean hasLocationPermission() {
+        if (currentActivity != null) {
+            return PermissionManager.hasLocationPermission(currentActivity);
+        }
+        return false;
     }
 
     public static Activity getCurrentActivity() {

+ 99 - 0
app_bzy_armhf_7/docs/Readme.md

@@ -0,0 +1,99 @@
+## 20260417
+    #define APP_VERSION "1.8.26"
+    更新说明:
+        1、每次启动都发送恢复MCU参数的JSON,防止MCU启动后工控机还没启动,无法收到恢复指令的情况.
+        2、针对丢照片问题进行优化改进,处理因拍照过程中断电导致的图片没有上传,处理逻辑如下:
+        完整流程
+        保存图片 → saveMatAsJpeg → 立即 emit signal_cache_image(path) → 触发 storage_Picture_Takephoto(path) → 原始路径存入 DB
+        上传成功 → CurlFtpUploader::finished(true) → storage_Picture(true, path) → 从 DB 删除原路径记录
+        上传失败 → storage_Picture(false, path) → cacheImagePath 重命名文件为 history-*.jpg 并入库 → 等待重传定时器触发 signal_reupload_image(history_path) 
+            重新上传
+        3、修复IMEI未保存到数据库问题;
+## 20260413
+    #define APP_VERSION "1.8.25"
+    更新说明:
+        1、修复日志无法上传问题.
+## 20260410
+    #define APP_VERSION "1.8.24"
+    更新说明:
+        1、优化和主板的通信协议,取消发{“cmd”:“read”},而是发{"cmd": "synchronization","ext":{}}
+            效率提升
+        2、修复相机已经打开的状态进行对焦拍照会导致相机关闭
+        3、增加MCU参数备份与恢复:
+            备份:{"jsonrpc":"2.0","method":"sync_param","params":{"reboot_time":751,"ds":1,"collecting_sh1":11,"collt_min_sh1":0,"collecting_eh1":16,"collt_min_eh1":0,"collecting_sh2":0,"collt_min_sh2":0,"collecting_eh2":0,"collt_min_eh2":0,"collecting_sh3":0,"collt_min_sh3":0,"collecting_eh3":0,"collt_min_eh3":0,"tpl":5,"tph":70,"x_init_dis":1300,"y_init_dis":1600},"id":1}
+            收到此指令时发送上面json到mcu:{"jsonrpc":"2.0","method":"recover_param","id":1} 
+## 202600309
+    #define APP_VERSION "1.7.23"
+    更新说明:
+        1、修复Ymodem升级问题,优化代码结构,Ymodem类放在SerialThread中使用;
+## 20260131
+    #define APP_VERSION "1.6.23"
+    更新说明:
+        1、完善信号强度的获取与上报;
+## 20260130
+    #define APP_VERSION "1.5.23"
+    更新说明:
+        1、修复串口发送字节数溢出导致程序崩溃;
+## 20260126
+    #define APP_VERSION "1.5.22"
+    更新说明:
+        1、更新Felgo版本       
+        QT版本:V8.3.0
+        NDK版本:27.2
+        2、增加日志上传,共存储10个日志文件,每个10MB大小:
+        指令:
+        {
+        "jsonrpc": "2.0",
+        "method": "upload_log",
+        "params": {
+          "filename": "run_log.txt"
+        },
+        "id": 1
+      }
+        
+## 20260122
+    #define APP_VERSION "1.4.22"
+    更新说明:
+        增加网口相机拍照前设置IP功能,解决IP丢失无法打开相机问题;
+        增加曝光值显示;
+## 20260119
+    #define APP_VERSION "1.3.22"
+    更新说明:
+        优化代码结构;
+        
+## 20251206
+    #define APP_VERSION "1.3.21"
+    更新说明:
+        串口解析使用lwjson
+        取图接口调整
+        增加Y轴坐标校准
+## 20251113
+    #define APP_VERSION "1.3.20"
+    更新说明:
+        自动对焦:闪退问题解决,自动对焦过程中退出程序,再次启动APP后执行对焦拍照会触发闪退;
+        原因:GPS定位成功后释放时机,延迟释放即可解决;
+## 20251110
+    #define APP_VERSION "1.3.18"
+    更新说明:
+        修复主函数数据库逻辑问题;
+## 20251104
+    #define APP_VERSION "1.3.18"
+    更新说明:
+        修复mqtt不停上报最新数据问题;
+## 20251103
+    #define APP_VERSION "1.3.17"
+    更新说明:
+        修复读取/设置主板参数/数据后  mqtt不上报最新数据问题;
+
+#### 20251101
+    #define APP_VERSION "1.3.16"
+    更新说明:
+        修复FTP上传图片失败问题,构建curl时还未读取到IMEI
+## 20251101
+    #define APP_VERSION "1.3.15"
+    更新说明:
+        增加设置IMEI功能
+## 20250829
+    #define APP_VERSION "1.2.10"
+    更新说明:
+        增加每隔24小时系统重启;

+ 395 - 0
app_bzy_armhf_7/docs/代码优化建议报告.md

@@ -0,0 +1,395 @@
+# 代码优化建议报告
+
+## 概述
+本报告基于对 `q6_felgo_iot` 项目的全面代码审查,识别了多个可优化项,涵盖内存管理、代码组织、性能、安全性等方面。
+
+---
+
+## 🔴 严重问题(高优先级)
+
+### 1. 内存泄漏问题
+
+#### 1.1 main.cpp 中的内存泄漏
+**位置**: `src/main.cpp`
+
+**问题**:
+- 第 281-282 行:创建了 `QMediaPlayer` 和 `QAudioOutput` 但未释放
+- 第 323 行:创建了 `SqliteOperator` 对象但未释放
+- 第 669 行:创建了 `GPSInfo` 对象但未释放
+
+**建议修复**:
+```cpp
+// 使用智能指针或确保在程序退出前释放
+std::unique_ptr<SqliteOperator> sqlConfig = std::make_unique<SqliteOperator>(db_config);
+// 或者使用 Qt 的父子关系管理
+GPSInfo *gps_start = new GPSInfo(sqlConfig, &app); // 设置父对象
+```
+
+#### 1.2 cameramanager.cpp 中的内存管理
+**位置**: `src/cameramanager.cpp:74`
+
+**问题**:
+- 使用 `malloc` 分配内存,但在某些错误路径可能未释放
+- 第 108 行有 `free(pData)`,但在正常退出路径(第 113 行)没有释放
+
+**建议修复**:
+```cpp
+// 使用 RAII 或确保所有路径都释放内存
+std::unique_ptr<unsigned char[]> pData(new unsigned char[stParam.nCurValue + 2048]);
+// 或者使用智能指针包装
+```
+
+#### 1.3 curl_global_init 未配对清理
+**位置**: `src/app_curlFunc.cpp:34`
+
+**问题**:
+- 调用了 `curl_global_init()` 但从未调用 `curl_global_cleanup()`
+
+**建议修复**:
+```cpp
+// 在析构函数或适当位置添加
+~CurlFtpUploader() {
+    curl_global_cleanup();
+}
+```
+
+---
+
+### 2. 数据库连接管理问题
+
+**位置**: `src/main.cpp`, `src/mserial.cpp`
+
+**问题**:
+- 数据库连接频繁打开/关闭,效率低下
+- 某些路径可能忘记关闭数据库(如 main.cpp:402 被注释)
+- 缺少异常处理,可能导致资源泄漏
+
+**建议**:
+```cpp
+// 使用 RAII 包装器
+class DatabaseGuard {
+    SqliteOperator* db;
+public:
+    DatabaseGuard(SqliteOperator* db) : db(db) { db->OpenDb(); }
+    ~DatabaseGuard() { db->CloseDb(); }
+};
+
+// 使用方式
+{
+    DatabaseGuard guard(sqlConfig);
+    // 数据库操作
+} // 自动关闭
+```
+
+---
+
+### 3. 线程安全问题
+
+**位置**: `header/main.h` - `param` 类
+
+**问题**:
+- `param` 类包含大量静态成员变量,在多线程环境下不安全
+- 多个线程可能同时访问和修改这些全局变量
+
+**建议**:
+- 使用互斥锁保护共享数据
+- 考虑使用单例模式 + 线程安全访问
+- 或者使用信号槽机制在线程间传递数据
+
+```cpp
+class param {
+private:
+    static QMutex mutex;
+public:
+    static QString getImei() {
+        QMutexLocker locker(&mutex);
+        return imei;
+    }
+    static void setImei(const QString& value) {
+        QMutexLocker locker(&mutex);
+        imei = value;
+    }
+};
+```
+
+---
+
+## 🟡 中等问题(中优先级)
+
+### 4. 代码组织和架构问题
+
+#### 4.1 main.cpp 文件过长
+**位置**: `src/main.cpp` (676 行)
+
+**问题**:
+- 主函数包含过多业务逻辑
+- 难以维护和测试
+
+**建议**:
+- 将初始化逻辑提取到单独的类(如 `ApplicationInitializer`)
+- 将信号连接逻辑提取到配置类
+- 使用依赖注入模式
+
+#### 4.2 硬编码值过多
+**位置**: 多处
+
+**问题**:
+- 硬编码的 IP 地址、端口、路径等
+- 硬编码的魔法数字(如 1000, 60, 20 等)
+
+**建议**:
+```cpp
+// 创建配置类
+class AppConfig {
+public:
+    static constexpr int GPS_SUCCESS_THRESHOLD = 20;
+    static constexpr int DATA_UPLOAD_INTERVAL_MIN = 10;
+    static const QString DEFAULT_MQTT_HOST;
+    // ...
+};
+```
+
+#### 4.3 代码重复
+**位置**: 多处
+
+**问题**:
+- 数据库表创建和查询逻辑重复
+- 信号连接模式重复
+
+**建议**:
+- 提取公共函数
+- 使用模板或宏减少重复代码
+
+---
+
+### 5. 错误处理不足
+
+**位置**: 多处
+
+**问题**:
+- 很多函数缺少错误检查
+- 异常情况处理不完善
+
+**建议**:
+```cpp
+// 添加错误处理
+if (!sqlConfig->OpenDb()) {
+    ERROR("Failed to open database: {}", sqlConfig->lastError());
+    return false;
+}
+```
+
+---
+
+### 6. 性能问题
+
+#### 6.1 字符串拼接效率
+**位置**: 多处使用 `QString::number()` 和字符串拼接
+
+**建议**:
+- 使用 `QString::arg()` 代替多次 `+` 操作
+- 对于频繁操作,考虑使用 `QStringBuilder`
+
+#### 6.2 不必要的对象创建
+**位置**: `src/main.cpp:250` - lambda 捕获
+
+**问题**:
+- Lambda 按值捕获可能导致不必要的拷贝
+
+**建议**:
+```cpp
+// 使用引用捕获(如果安全)
+QTimer::singleShot(intervalMs, [&]() { // 注意生命周期
+```
+
+#### 6.3 数据库查询优化
+**位置**: `src/mysql.cpp`
+
+**建议**:
+- 使用预编译语句(prepared statements)
+- 批量操作代替多次单独操作
+- 添加适当的索引
+
+---
+
+### 7. 资源管理问题
+
+#### 7.1 QTimer 管理
+**位置**: 多处
+
+**问题**:
+- 某些 QTimer 使用 `new` 创建但可能未正确设置父对象
+
+**建议**:
+```cpp
+// 确保设置父对象,使用 Qt 父子关系管理
+timeout_mov = new QTimer(this); // 已正确设置
+```
+
+#### 7.2 文件句柄
+**位置**: `src/app_curlFunc.cpp`
+
+**问题**:
+- 文件打开后在某些错误路径可能未关闭
+
+**建议**:
+- 使用 RAII 或确保所有路径都关闭文件
+- Qt 的 QFile 析构函数会自动关闭,但显式关闭更清晰
+
+---
+
+## 🟢 轻微问题(低优先级)
+
+### 8. 代码风格和可读性
+
+#### 8.1 命名规范
+- 某些变量名不够清晰(如 `m_ediaPlayer` 应该是 `m_mediaPlayer`)
+- 混合使用中英文命名
+
+#### 8.2 注释
+- 缺少函数文档注释
+- 某些复杂逻辑缺少解释
+
+#### 8.3 代码格式
+- 某些地方缩进不一致
+- 长行需要换行
+
+---
+
+### 9. CMakeLists.txt 优化
+
+**位置**: `CMakeLists.txt`
+
+**建议**:
+- 使用 `target_include_directories` 代替全局 `include_directories`
+- 将库链接逻辑组织得更好
+- 添加编译选项优化(如 `-Wall -Wextra`)
+
+---
+
+### 10. 安全性问题
+
+#### 10.1 敏感信息硬编码
+**位置**: `CMakeLists.txt:70`, `qml/Main.qml:11`
+
+**问题**:
+- License key 硬编码在源代码中
+
+**建议**:
+- 使用环境变量或配置文件
+- 不要将敏感信息提交到版本控制
+
+#### 10.2 SQL 注入风险
+**位置**: `src/mysql.cpp`
+
+**问题**:
+- 虽然使用了参数绑定,但需要确保所有查询都使用
+
+**建议**:
+- 审查所有 SQL 查询
+- 使用参数化查询
+
+---
+
+## 📊 优化优先级总结
+
+### 立即修复(P0)
+1. ✅ 修复内存泄漏(main.cpp 中的对象未释放)
+2. ✅ 修复 curl_global_init 未清理问题
+3. ✅ 添加数据库连接的 RAII 包装
+
+### 近期优化(P1)
+4. ⚠️ 重构 main.cpp,提取业务逻辑
+5. ⚠️ 添加线程安全保护(param 类)
+6. ⚠️ 改进错误处理
+
+### 长期改进(P2)
+7. 📝 消除硬编码,使用配置系统
+8. 📝 代码重构,减少重复
+9. 📝 性能优化
+10. 📝 改进代码风格和文档
+
+---
+
+## 🛠️ 具体修复示例
+
+### 示例 1: 修复 main.cpp 内存泄漏
+
+```cpp
+// 修改前
+SqliteOperator *sqlConfig;
+sqlConfig = new SqliteOperator(db_config);
+// ... 使用 sqlConfig
+// 没有 delete
+
+// 修改后
+std::unique_ptr<SqliteOperator> sqlConfig = std::make_unique<SqliteOperator>(db_config);
+// 或者
+SqliteOperator sqlConfig(db_config); // 栈对象
+```
+
+### 示例 2: 数据库连接 RAII
+
+```cpp
+class DatabaseRAII {
+    SqliteOperator* m_db;
+public:
+    explicit DatabaseRAII(SqliteOperator* db) : m_db(db) {
+        if (m_db) m_db->OpenDb();
+    }
+    ~DatabaseRAII() {
+        if (m_db) m_db->CloseDb();
+    }
+    SqliteOperator* operator->() { return m_db; }
+};
+
+// 使用
+{
+    DatabaseRAII guard(sqlConfig);
+    sqlConfig->UpdateData(...);
+} // 自动关闭
+```
+
+### 示例 3: 线程安全的 param 类
+
+```cpp
+class param {
+private:
+    static QMutex s_mutex;
+    static QString s_imei;
+    
+public:
+    static QString imei() {
+        QMutexLocker locker(&s_mutex);
+        return s_imei;
+    }
+    
+    static void setImei(const QString& value) {
+        QMutexLocker locker(&s_mutex);
+        s_imei = value;
+    }
+};
+```
+
+---
+
+## 📝 总结
+
+本报告识别了 **10 个主要优化类别**,包含 **30+ 个具体问题**。建议按优先级逐步修复:
+
+1. **立即处理**: 内存泄漏和资源管理问题
+2. **短期优化**: 代码组织和架构改进
+3. **长期改进**: 性能优化和代码质量提升
+
+修复这些问题将显著提高代码的:
+- ✅ 稳定性和可靠性
+- ✅ 可维护性
+- ✅ 性能
+- ✅ 安全性
+
+---
+
+**报告生成时间**: 2024年
+**审查范围**: 全部源代码文件
+**建议审查周期**: 每季度进行一次代码审查
+

+ 33 - 9
app_bzy_armhf_7/main.cpp

@@ -260,20 +260,36 @@ auto setDailyRebootTimer = []() {
 
 
 //adb shell input keyevent 26 // 224 关
-
+// 构建权限列表
+QStringList m_permissions = {
+    "android.permission.WRITE_EXTERNAL_STORAGE",
+    "android.permission.READ_EXTERNAL_STORAGE",
+    "android.permission.MANAGE_EXTERNAL_STORAGE",
+    "android.permission.ACCESS_MEDIA_LOCATION",
+    "android.permission.CAMERA",
+    "android.permission.ACCESS_FINE_LOCATION",
+    "android.permission.ACCESS_COARSE_LOCATION",
+    "android.permission.WRITE_SETTINGS",
+    "android.permission.READ_PHONE_STATE",
+    "android.permission.INTERNET",
+    "android.permission.ACCESS_NETWORK_STATE",
+    "android.permission.WAKE_LOCK",
+    "android.permission.VIBRATE"
+};
 int main(int argc, char *argv[])
 {
-    INITLOG();
     //sendBroadcastFromQt("service");
-    // get android storage permisson
-    // 该接口也可以直接使用字符串,可自行跳转到头文件自行查看
-    QtAndroidPrivate::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
-
-    QtAndroidPrivate::requestPermission("android.permission.WRITE_EXTERNAL_STORAGE");
-
+    // ========== Android权限申请 ==========
+    // 在应用启动时申请所有必要的权限
+    
+    // 使用正确的API逐个申请权限
+    for (const QString &permission : m_permissions) {
+        QtAndroidPrivate::checkPermission(permission);
+        QtAndroidPrivate::requestPermission(permission);
+    }
+    INITLOG();
 
     sendBroadcastFromQt("sleep");
-
     QGuiApplication app(argc, argv);
     MyCppClass myCppClass;
 
@@ -290,6 +306,7 @@ int main(int argc, char *argv[])
 
     sendBroadcastFromQt("iccid");
     sendBroadcastFromQt("csq");
+
     //创建并打开SQLite数据库
     QString db_config = "config.db";
     //    QString db_data = "data.db";
@@ -635,6 +652,13 @@ int main(int argc, char *argv[])
     QObject::connect(gps_start,&GPSInfo::position_success,[&](){
         emit serialThread.gpsSuccess();
     });
+    QtAndroidPrivate::checkPermission("android.permission.READ_PHONE_STATE");
+
+    QtAndroidPrivate::requestPermission("android.permission.READ_PHONE_STATE");
+
+    QtAndroidPrivate::checkPermission("android.permission.CAMERA");
+
+    QtAndroidPrivate::requestPermission("android.permission.CAMERA");
     return app.exec();
 }
 #include "main.moc"

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 230 - 124
app_bzy_armhf_7/qml/Main.qml


+ 8 - 6
app_bzy_armhf_7/qml/model/DataModel.qml

@@ -31,7 +31,7 @@ Item {
         id: logicConnection
 
         // action 1 - fetchTodos
-        onFetchTodos: {
+        function onFetchTodos() {
             // check cached value first
             var cached = cache.getValue("todos")
             if(cached)
@@ -52,7 +52,7 @@ Item {
         }
 
         // action 2 - fetchTodoDetails
-        onFetchTodoDetails: id => {
+        function onFetchTodoDetails(id) {
                                 // check cached todo details first
                                 var cached = cache.getValue("todo_"+id)
                                 if(cached) {
@@ -77,7 +77,7 @@ Item {
                             }
 
         // action 3 - storeTodo
-        onStoreTodo: todo => {
+        function onStoreTodo(todo) {
                          // store with api
                          api.addTodo(todo,
                                      function(data) {
@@ -103,12 +103,12 @@ Item {
                      }
 
         // action 4 - clearCache
-        onClearCache: {
+        function onClearCache() {
             cache.clearAll()
         }
 
         // action 5 - login
-        onLogin: {
+        function onLogin(password) {
             if(password==="8888")
             {
                  _.userLoggedIn = true
@@ -123,7 +123,9 @@ Item {
 
         }
         // action 6 - logout
-        onLogout: _.userLoggedIn = false
+        function onLogout() {
+            _.userLoggedIn = false
+        }
     }
 
     // you can place getter functions here that do not modify the data

+ 0 - 432
app_bzy_armhf_7/qml/pages/ControlsPage.qml

@@ -1,432 +0,0 @@
-import QtQuick
-import QtQuick.Controls
-import Qt.labs.settings 1.0 as QtLabs
-import QtQuick.Controls.Material 2.0
-import QtLocation 5.5
-import QtPositioning 5.5
-import QtMultimedia
-import Qt5Compat.GraphicalEffects
-import Felgo 4.0
-import "../controls"
-import "../common"
-//import MqttClient 1.0
-
-
-AppPage {
-  id: controlsPage
-
-
-  property string originalString: ""
-  property string collectString: ""
-  property string gps_state: "正在定位..."
-  property string board_version: ""
-  property bool connect_board: false
-  property var tt
-  property bool isonline: false
-  property var net_list:[]
-  property var picinfo_list:[]
-
-  Material.accent: Theme.tintColor
-  rightBarItem: IconButtonBarItem {
-    iconType: IconType.paintbrush
-    onClicked: {
-      themeModal.open()
-    }
-  }
-
-  Component.onCompleted: {
-    originalString = myClass.deviceid
-  }
-
-  // 接收并显示日志消息
-  Connections {
-      target: mqtt
-        onConnected: {
-          console.log("mqtt connect")
-          mqtt_sta.detailText="MQTT已连接"
-        }
-        onDisconnected: {
-          console.log("mqtt disconnect")
-          mqtt_sta.detailText="MQTT已断开"
-        }
-  }
-
-
-  Connections{
-      target: myClass
-  }
-  //串口
-  Connections{
-      target: serial
-      onDataReceived:{
-          var jsonData = JSON.parse(data)
-          console.debug("接收到主板数据:",data.toString())
-          if(jsonData.ext.work_sta==="0"){
-              if(jsonData.ext.ds==="0"){
-                work_header.text =qsTr("<b>设备开关:</b> 关机") + "-" +  qsTr("<b>工作状态:</b> 待机")
-              }else{
-                work_header.text =qsTr("<b>设备开关:</b> 开机") + "-" + qsTr("<b>工作状态:</b> 待机")
-              }
-
-          }else if(jsonData.ext.work_sta==="1"){
-
-              if(jsonData.ext.ds==="0"){
-                work_header.text = qsTr("<b>设备开关:</b> 关机") + "-" + qsTr("<b>工作状态:</b> 采集")
-              }else{
-                work_header.text = qsTr("<b>设备开关:</b> 开机") + "-" + qsTr("<b>工作状态:</b> 采集")
-              }
-          }
-          if(jsonData.ext.gps==="1"){
-              gps_state = "成功"
-          }
-
-          if(jsonData.ext.coll_time){
-              collectString = "   [" +jsonData.ext.coll_time[0] + "," + jsonData.ext.coll_time[1] + "," + jsonData.ext.coll_time[2] + "]";
-          }
-          if(jsonData.ext.dat_f){
-              serial.update_dat_f_main(jsonData.ext.dat_f);
-          }
-          board_version = jsonData.ext.dver
-          work_header.detailText = "电压:" + jsonData.ext.vbat + "    电流:" + jsonData.ext.current +  "    温度:" + jsonData.ext.at + "    湿度:" + jsonData.ext.ah ;
-      }
-      onDisconnect_485:{
-           work_header.text =qsTr("485未连接,读取数据失败");
-      }
-
-  }
-
-
-  MediaPlayer{
-    id: audio
-    audioOutput: AudioOutput{}
-    source: Qt.resolvedUrl("../../assets/mp3/button.mp3")
-  }
-
-  AppFlickable {
-    id: scroll
-    anchors.fill: parent
-    contentHeight: content.height
-
-    // remove focus from controls if clicked outside
-    MouseArea {
-      anchors.fill: parent
-      onClicked: {
-        scroll.forceActiveFocus()
-      }
-    }
-
-
-    Column {
-      id: content
-      width: parent.width
-
-      Timer {
-        interval: 500
-        running: true
-        repeat: true
-        onTriggered: {
-          menutab.title = Date().toString() + "      设备ID:" +  originalString.toLowerCase()  + "                  GPS状态:" + gps_state
-            if(mqtt.checkLink()){
-                mqtt_sta.detailText="MQTT已连接"
-            }else{
-                mqtt_sta.detailText="MQTT已断开"
-            }
-            net_list = mqtt.netMessage()
-            if(net_list){
-                if(net_list[0]==="1"){isonline = true}else{isonline = false}
-                mqtt_sta.text = qsTr("<b>联网状态:</b> %1 (网卡名称:%2) (描述:%3)").arg(isonline? "已联网" : "未联网").arg(net_list[1]).arg(net_list[2])
-                net_mes.text = qsTr("<b>[MAC] </b> %1").arg(net_list[3]) + qsTr("<b>[IPV4] </b> %1").arg(net_list[4])
-                mqtt_sta.detailText += "<服务器地址:>" + net_list[5]
-                mqtt_sta.detailText += "<数据上传间隔:>" + net_list[6] +  "(" +net_list[7] + ")" + "分钟";
-            }
-        }
-      }
-      Section {
-        id: menutab
-        title: Date().toString()
-
-        //SectionItem {
-          //title: "运行状态"
-          //anchors.horizontalCenter: parent.horizontalCenter
-
-          AppCard {
-            id: card
-            width: parent.width
-//            property real resetX: 0
-//            x: resetX
-
-            margin: dp(5)
-            paper.radius: dp(5)
-
-            header: SimpleRow {
-              id: work_header
-              //imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
-              text: qsTr("<b>设备开关:</b> 开机") + qsTr("<b>工作状态:</b> 待机")
-              detailText: "电压:" + jsonData.ext.vbat + "    电流:" + jsonData.ext.current +  "    温度:" + jsonData.ext.at + "    湿度:" + jsonData.ext.ah ;
-              badgeColor: "green"
-              image.radius: image.width / 2
-              image.fillMode: Image.PreserveAspectCrop
-              style: StyleSimpleRow {
-                showDisclosure: false
-                backgroundColor: "transparent"
-              }
-            }
-
-            media: AppImage {
-              width: card.width
-              fillMode: Image.PreserveAspectFit
-              source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
-            }
-
-            content: AppText{
-              id: work_apptext
-              width: card.width
-              padding: dp(15)
-              text: "设定采集时间:" + collectString;
-            }
-
-          }
-
-
-          AppCard {
-            id: card_net
-            width: parent.width
-
-            property real resetX: 0
-            x: resetX
-            margin: dp(5)
-
-
-            paper.radius: dp(5)
-
-            header: SimpleRow {
-              id: mqtt_sta
-              //imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
-              text: qsTr("<b>联网状态:</b> %1 (%2)").arg(app.isOnline ? "已联网" : "未联网").arg(nativeUtils.connectionType)
-              detailText: "AppCard detailed text"
-
-              image.radius: image.width / 2
-              image.fillMode: Image.PreserveAspectCrop
-              style: StyleSimpleRow {
-                showDisclosure: false
-                backgroundColor: "transparent"
-              }
-            }
-
-            media: AppImage {
-              width: parent.width
-              fillMode: Image.PreserveAspectFit
-              source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
-            }
-
-            content: AppText{
-              id: net_mes
-              width: parent.width
-              padding: dp(15)
-              text: "Mac" + "ipv4:";
-            }
-
-          }
-
-//          AppCard {
-//            id: card_cfg
-//            width: parent.width
-//            height: width*1.5
-//            property real resetX: 0
-//            x: resetX
-//            margin: dp(5)
-
-//            paper.radius: dp(5)
-
-//            header: SimpleRow {
-//              imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
-//              text: "参数"
-//              detailText: "AppCard detailed text"
-
-//              image.radius: image.width / 2
-//              image.fillMode: Image.PreserveAspectCrop
-//              style: StyleSimpleRow {
-//                showDisclosure: false
-//                backgroundColor: "transparent"
-//              }
-//            }
-
-//            media: AppImage {
-//              width: card_cfg.width
-//              fillMode: Image.PreserveAspectFit
-//              source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
-//            }
-
-//            content: AppText{
-//              width: card_cfg.width
-//              padding: dp(15)
-//              text: "此界面显示参数等信息,运行时间等"
-//            }
-
-//            cardSwipeArea.onSwipeOutCompleted: {
-//              card_cfg.x = card_cfg.resetX
-//              card_cfg.rotation = 0
-//            }
-//          }
-
-        //} // AppCard section
-
-      } // convenience controls section
-
-
-
-      Timer {
-        interval: 1000
-        running: true
-        repeat: true
-        onTriggered: {
-          picinfo_list = serial.pathinfo()
-          pic_path.text = "图片存储目录:" + picinfo_list[0]
-          pic_count.text = "文件数量:" + picinfo_list[1]
-          pic_total.text = "占用大小:" + picinfo_list[2] + "(Mb)"
-        }
-      }
-
-      Section {
-        title: "存储信息"
-        bottomPadding: dp(Theme.navigationBar.defaultBarItemPadding)
-
-        Grid {
-          anchors.horizontalCenter: parent.horizontalCenter
-          columns: 2
-          rows: 4
-          //horizontalItemAlignment: Grid.AlignHCenter
-          Column{
-              AppButton {
-                text: "查询"
-                flat: false
-                onClicked: {
-                    serial.readPathinfo()
-                }
-              }
-              AppButton {
-                text: "清理"
-                flat: false
-                onClicked: {
-                    serial.removepic()
-                }
-              }
-          }
-
-
-          Column{
-
-              AppText {
-                  id: pic_path
-                  text: "图片存储目录:" + picinfo_list[0]
-              }
-
-              AppText{
-                  id: pic_count
-                  text: "文件数量:" + picinfo_list[1]
-              }
-
-              AppText{
-                  id: pic_total
-                  text: "占用大小:" + picinfo_list[2]
-              }
-          }
-
-
-
-
-
-        }
-      } // native utils section             }
-
-      Section {
-        title: "Device Info"
-        bottomPadding: dp(15)
-
-        Row {
-          width: parent.width - dp(30)
-          anchors.horizontalCenter: parent.horizontalCenter
-          spacing: dp(5)
-
-          Column {
-            id: firstInfoColumn
-            spacing: dp(5)
-            width: (parent.width - parent.spacing) * 0.5
-            AppText {
-              text: "<b>OS Type:</b> " + system.osType
-              font.pixelSize: sp(11)
-              visible: system.osType !== "undefined"
-            }
-            AppText {
-              text: "<b>OS Version:</b> " + system.osVersion
-              font.pixelSize: sp(11)
-              visible: system.osVersion !== "undefined"
-            }
-            AppText {
-              text: "<b>Device Model:</b> " + nativeUtils.deviceModel()
-              font.pixelSize: sp(11)
-              visible: nativeUtils.deviceModel() !== "undefined"
-            }
-            AppText {
-              text: qsTr("<b>Device Online:</b> %1 (%2)").arg(app.isOnline ? "Yes" : "No").arg(nativeUtils.connectionType)
-              font.pixelSize: sp(11)
-            }
-            AppText {
-              text: "<b>MAC Address:</b> " + system.macAddress
-              font.pixelSize: sp(11)
-              width: parent.width
-              wrapMode: Text.WrapAtWordBoundaryOrAnywhere
-              visible: system.macAddress !== "undefined"
-            }
-            AppText {
-              text: "<b>Unique Device Id:</b> " + system.UDID
-              font.pixelSize: sp(11)
-              width: parent.width
-              wrapMode: Text.WrapAtWordBoundaryOrAnywhere
-              visible: system.UDID !== "undefined"
-            }
-          }
-
-          Column {
-            id: secondInfoColumn
-            spacing: dp(5)
-            width: firstInfoColumn.width
-            AppText {
-              text: "<b>Orientation:</b> " + (Theme.isPortrait ? "portrait" : "landscape")
-              font.pixelSize: sp(11)
-            }
-            AppText {
-              text: "<b>Statusbar Height:</b> " + Theme.statusBarHeight
-              font.pixelSize: sp(11)
-            }
-            AppText {
-              text: "<b>App Identifier:</b> " + system.appIdentifier
-              font.pixelSize: sp(11)
-              width: parent.width
-              wrapMode: Text.WrapAtWordBoundaryOrAnywhere
-              visible: system.appIdentifier !== "undefined"
-            }
-            AppText {
-              text: "<b>App Version:</b> " + system.appVersionCode
-              font.pixelSize: sp(11)
-            }
-            AppText {
-              text: "<b>Qt Version:</b> " + system.qtVersion
-              font.pixelSize: sp(11)
-            }
-            AppText {
-              text: "<b>Felgo Version:</b> " + system.felgoVersion + " (" + system.felgoVersionRef + ")"
-              font.pixelSize: sp(11)
-            }
-          }
-        }
-      } // device info section
-    } // content column
-  } // flickable
-
-  ThemeModal {
-    id: themeModal
-    pushBackContent: navigationStack
-  } // theme modal
-} // page
-

+ 60 - 68
app_bzy_armhf_7/qml/pages/HomePage.qml

@@ -20,36 +20,22 @@ AppPage {
   property bool isonline: false
   property var net_list:[]
 
-
-
-
   navigationBarHidden: true
   backgroundColor: app.theme_backgroundColor
 
   Component.onCompleted: {
-      var theme_m = settings.getValue("theme_mode")
-      if (theme_m === undefined) {
-          theme_m = "day"
-          app.theme_select = "day"
-          settings.setValue("theme_mode","day")
-      }else{
-          theme_md = theme_m
-          if(theme_m!=="auto"){
-              app.theme_select = theme_m
-          }
-          console.log("读取到配置主题模式:",app.theme_select,theme_m)
-          Theme.navigationTabBar.titlePressedColor= "green"
-          Theme.navigationTabBar.backgroundColor= app.cardColor
-          Theme.navigationTabBar.titleColor = app.fontColor
-      }
+      // 主题初始化已由Main.qml的onInitTheme统一处理
+      // 此处不再重复读取主题配置,避免颜色闪烁
+      console.log("HomePage loaded, current theme:", app.theme_select)
   }
 
 
 
  Connections {
      target: networkMonitor
+     
      // 监听可达性变化(如从断开到连接)
-     onReachabilityChanged: {
+     function onReachabilityChanged() {
          let status = ""
          if(networkMonitor.reachability===0)
          {
@@ -71,7 +57,7 @@ AppPage {
      }
 
      // 监听传输介质变化(如从 Wi-Fi 切换到 4G)
-     onTransportMediumChanged: {
+     function onTransportMediumChanged() {
          let nettype = "未知"
          console.log("onTransportMediumChanged:",networkMonitor.transportMedium)
          if(networkMonitor.transportMedium===0)
@@ -90,12 +76,12 @@ AppPage {
      }
 
      // 监听受限网络状态(如公共 Wi-Fi 登录页)
-     onIsBehindCaptivePortalChanged: {
+     function onIsBehindCaptivePortalChanged() {
 
      }
 
      // 监听计量网络状态(如移动数据流量限制)
-     onIsMeteredChanged: {
+     function onIsMeteredChanged() {
 
      }
  }
@@ -103,11 +89,11 @@ AppPage {
   // 接收并显示日志消息
   Connections {
       target: mqtt
-        onConnected: {
+        function onConnected() {
           console.log("mqtt connect")
 
         }
-        onDisconnected: {
+        function onDisconnected() {
           console.log("mqtt disconnect")
           //mqtt_text.detailText="MQTT已断开"
         }
@@ -120,7 +106,7 @@ AppPage {
   //串口
   Connections{
       target: serial
-      onDataReceived:function(data){
+      function onDataReceived(data){
           var jsonData = JSON.parse(data)
           console.log("接收到主板数据:",data.toString())
           if(jsonData.ext.work_sta==="0"){
@@ -193,14 +179,14 @@ AppPage {
           app.bvReceived(dvs[0])
           app.appReceived(dvs[1])
       }
-      onDisconnect_485:{
+      function onDisconnect_485(){
            text_devicesta.text =qsTr("485未连接,读取数据失败");
            originalString =serial.getId()
            iccidString=serial.getIccid()
            app.appReceived(serial.get_app_version())
       }
 
-      onGpsSuccess:{
+      function onGpsSuccess(){
           gps_state = "成功"
           text_lat.text = serial.getlat()
           text_lng.text = serial.getlng()
@@ -253,55 +239,61 @@ AppPage {
       horizontalItemAlignment: Grid.AlignHCenter
 
 
-      Row {
+        Row {
           width: parent.width *0.995
           height: parent.height*0.1
           Rectangle {
               anchors.fill: parent
+              //anchors.fill: parent
               color: app.cardColor
               radius: 2
-              Row {
-                  anchors.fill: parent
-                  spacing: dp(20)
-                  AppText{
-                      id: text_stamp
-                      anchors.verticalCenter: parent.verticalCenter
-                      text: ""
-                      fontSize: 20
-                      color: app.fontColor
-                  }
+              // 使用Item作为容器,设置固定位置和大小
+              Item {
+                  // 修复:移除Row中的anchors.fill,使用Item的尺寸
+                  Row {
+                      width: parent.width
+                      height: parent.height
+                      spacing: dp(20)
+                      AppText{
+                          id: text_stamp
+                          verticalAlignment: Text.AlignVCenter
+                          text: ""
+                          fontSize: 20
+                          color: app.fontColor
+                      }
 
-                  AppText{
-                      id: text_imei
-                      anchors.verticalCenter: parent.verticalCenter
-                      text:"设备ID:" + originalString.toLowerCase()
-                      fontSize: 20
-                      color: app.fontColor
-                  }
+                      AppText{
+                          id: text_imei
+                          verticalAlignment: Text.AlignVCenter
+                          text:"设备ID:" + originalString.toLowerCase()
+                          fontSize: 20
+                          color: app.fontColor
+                      }
 
-                  AppText{
-                      id: net_sta
-                      anchors.verticalCenter: parent.verticalCenter
-                      color: app.fontColor
-                      text: "联网状态:"
-                      fontSize: 20
-                      //font.bold: true
-                  }
-                  AppText{
-                      id: net_type
-                      anchors.verticalCenter: parent.verticalCenter
-                      color: app.fontColor
-                      text: "联网类型:"
-                      fontSize: 20
-                      //font.bold: true
-                  }
-                  AppText{
-                      id: text_gps
-                      anchors.verticalCenter: parent.verticalCenter
-                      text: "GPS状态:" + gps_state
-                      color: app.fontColor
-                      //font.bold: true
-                      fontSize: 20
+                      AppText{
+                          id: net_sta
+                          verticalAlignment: Text.AlignVCenter
+                          color: app.fontColor
+                          text: "联网状态:"
+                          fontSize: 20
+                          //font.bold: true
+                      }
+                      AppText{
+                          id: net_type
+                          verticalAlignment: Text.AlignVCenter
+                          color: app.fontColor
+                          text: "联网类型:"
+                          fontSize: 20
+                          //font.bold: true
+                      }
+                      AppText{
+                          id: text_gps
+                          verticalAlignment: Text.AlignVCenter
+                          text: "GPS状态:" + gps_state
+                          color: app.fontColor
+                          //font.bold: true
+                          fontSize: 20
+                      }
                   }
               }
           }

+ 18 - 15
app_bzy_armhf_7/qml/pages/LocalNotificationPage.qml

@@ -13,20 +13,23 @@ AppPage {
 
 
     Connections{
-        target: ymodem
-        onDownloadStart: {
+        target: serial
+        function onYmodemReady(mtype) {
             progressBar.value = 0.0
             notificationtext.text = mtype
             notificationPage.visible = true
         }
 
-        onProgress: {
-            console.log("更新进度条:",val,tval)
-            progressBar.value = val/tval*100.0
-            process_text.text = progressBar.value.toFixed(2) + "%";
+       function onYmodemProgress(val,tval) {
+           //console.log("更新进度条:",val,tval)
+           var percent = Number(val) / Number(tval) * 100.0
+           percent = Math.min(percent,100)
+           console.log("更新进度:",percent)
+           progressBar.value = percent
+           process_text.text = percent.toFixed(2) + "%"
         }
 
-        onModem_result: {
+        function onYmodemFinished(r) {
             if(r===0){
                 progressBar.value = 100.0
                 notificationtext.text += "成功"
@@ -39,17 +42,17 @@ AppPage {
 
     Connections{
         target: curl
-        onSglProgress:{
-            //console.log("更新进度条:",val,timeLeft)
+        function onSglProgress(val,timeLeft,speed) {
+            console.log("更新curl进度条:",val,timeLeft)
             progressBar.value = val
             process_text.text = val.toFixed(2) + "%";
 
         }
-        onDownloadStart:{
+        function onDownloadStart(mtype) {
             notificationtext.text = mtype
             notificationPage.visible = true
         }
-        onDownloadFinished :{
+        function onDownloadFinished(result){
             //notificationPage.visible = false
             if(result){
                 notificationtext.text += "成功"
@@ -66,17 +69,17 @@ AppPage {
 
     Connections{
         target:curl_picture
-        onProgressChanged:{
+        function onProgressChanged(){
             console.log("更新进度条:",uploadedPercent)
             progressBar.value = uploadedPercent
             process_text.text = uploadedPercent.toFixed(2) + "%";
 
         }
-        onDownloadStart:function(tips){
+        function onDownloadStart(tips){
             notificationPage.visible = true
             notificationtext.text = tips
         }
-        onFinished :function(success,error){
+        function onFinished(success,error){
             //notificationPage.visible = false
             if(success){
                 notificationtext.color = "green"
@@ -143,7 +146,7 @@ AppPage {
             value: 0.0
 
             // 根据父布局动态计算宽度
-            implicitWidth: content.width - closeButton.width - content.columnSpacing
+            //implicitWidth: content.width - closeButton.width - content.columnSpacing
         }
 
         // 按钮行(第二列)

+ 8 - 8
app_bzy_armhf_7/qml/pages/LoginPage.qml

@@ -10,10 +10,12 @@ AppPage {
 
     property int logintimeout: 300
 
-    backgroundColor:  "#f5f5f5"
-    useSafeArea: false // do not consider safe area insets of screen
-
+    backgroundColor: app.theme_backgroundColor
+    useSafeArea: false
 
+    Component.onCompleted: {
+        console.log("LoginPage Component.onCompleted...")
+    }
     // 添加一个函数来处理亮度设置和重置计时
     function resetScreenTimeout() {
         serial.setLightness(128)
@@ -26,8 +28,6 @@ AppPage {
         }
     }
 
-
-
     // login form background
     Rectangle {
         id: loginForm
@@ -48,6 +48,8 @@ AppPage {
 
         Column{
             anchors.fill: loginForm
+            topPadding: 5
+            bottomPadding: 5
             AppText {
                 id: apptext_title
                 anchors.horizontalCenter: parent.horizontalCenter    //垂直居中显示
@@ -58,18 +60,16 @@ AppPage {
 
             AppText{
                 id: text_logintime
-                anchors.topMargin: 5
                 text: "休眠计时:" + logintimeout
                 color: "red"
                 fontSize: 20
             }
 
             AppText {
+                anchors.right: parent.right
                 text: "软件版本:" + app.appversionText
                 color: "gray"
                 fontSize: 10
-                anchors.right: parent.right
-                anchors.bottom: parent.bottom
             }
         }
 

+ 31 - 28
app_bzy_armhf_7/qml/pages/ProfilePage.qml

@@ -768,18 +768,17 @@ AppPage {
                   Column {
                       anchors.fill: parent
                       spacing: 5
+                      topPadding: 10
                       AppImage {
                           id: appimage_theme
-                          anchors.centerIn: parent   //垂直居中显示
+                          anchors.horizontalCenter: parent.horizontalCenter
                           fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                           source: "../../assets/themset.svg"
                       }
 
                       AppText{
                           id: apptext_title
-                          anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                          anchors.top: appimage_theme.bottom
-                          anchors.topMargin: 10
+                          anchors.horizontalCenter: parent.horizontalCenter
                           text: "设置主题"
                           color: app.fontColor
                           font.bold: true
@@ -787,7 +786,7 @@ AppPage {
 
                       AppText {
                           id: apptext_select
-                          anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
+                          anchors.horizontalCenter: parent.horizontalCenter
                           text: "当前:" + settings.getValue("theme_mode")
                           fontSize: 10
                           font.bold: false
@@ -806,8 +805,9 @@ AppPage {
                   Column {
                       anchors.fill: parent
                       spacing: 10
+                      topPadding: 10
                       AppButton {
-                          anchors.fill: parent
+                          width: parent.width
                           onClicked: {
                             logoutClicked()
                           }
@@ -815,15 +815,13 @@ AppPage {
 
                       AppImage {
                           id: image_exit
-                          anchors.centerIn: parent   //垂直居中显示
-                          fillMode: Image.PreserveAspectFit  // 保持纵横比适应
+                          anchors.horizontalCenter: parent.horizontalCenter
+                          fillMode: Image.PreserveAspectFit
                           source: "../../assets/logout.svg"
                       }
 
                       AppText{
-                          anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                          anchors.top: image_exit.bottom
-                          anchors.topMargin: 10
+                          anchors.horizontalCenter: parent.horizontalCenter
                           text: "退出登录"
                           color: app.fontColor
                           font.bold: true
@@ -845,8 +843,11 @@ AppPage {
                   Column {
                       id: column_bi
                       anchors.fill: parent
+                      spacing: 10
+                      topPadding: 10
                       MouseArea {
-                        anchors.fill: parent
+                        width: parent.width
+                        height: parent.height
                         onClicked: {
                             column_bi.visible = false
                             column_bi.enabled = false
@@ -855,7 +856,7 @@ AppPage {
                         }
                       }
                       AppText{
-                          anchors.centerIn: parent
+                          anchors.horizontalCenter: parent.horizontalCenter
                           text: "控制系统版本:" + app.boardversionText
                           fontSize: 20
                           font.bold: true
@@ -870,7 +871,7 @@ AppPage {
                       anchors.fill: parent
                       spacing: 10
                       AppButton {
-                          anchors.fill: parent
+                          width: parent.width
                           onClicked: {
                               column_bi.visible = true
                               column_bi.enabled = true
@@ -926,8 +927,10 @@ AppPage {
                     id: column_ai
                     spacing: 10
                     anchors.fill: parent
+                    topPadding: 10
                     MouseArea {
-                        anchors.fill: parent
+                        width: parent.width
+                        height: parent.height
                         onClicked: {
                             column_ai.visible = false
                             column_ai.enabled = false
@@ -937,7 +940,7 @@ AppPage {
                     }
 
                     AppText{
-                        anchors.centerIn: parent
+                        anchors.horizontalCenter: parent.horizontalCenter
                         text: "App版本:" + app.appversionText
                         fontSize: 20
                         font.bold: true
@@ -950,8 +953,9 @@ AppPage {
                       visible: false
                       spacing: 10
                       anchors.fill: parent
+                      topPadding: 10
                       AppButton {
-                          anchors.fill: parent
+                          width: parent.width
                           onClicked: {
                               column_ai.visible = true
                               column_ai.enabled = true
@@ -973,12 +977,12 @@ AppPage {
                           }
                       }
                       AppImage {
-                          anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                          fillMode: Image.PreserveAspectFit  // 保持纵横比适应
+                          anchors.horizontalCenter: parent.horizontalCenter
+                          fillMode: Image.PreserveAspectFit
                           source: "../../assets/updateapp.svg"
                       }
                       AppText{
-                          anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
+                          anchors.horizontalCenter: parent.horizontalCenter
                           text: "升级App"
                           color: app.fontColor
                           font.bold: true
@@ -996,10 +1000,11 @@ AppPage {
                   Column {
                       anchors.fill: parent
                       spacing: 10
+                      topPadding: 10
 
                       AppButton {
                           id: button_reboot
-                          anchors.fill: parent
+                          width: parent.width
                           onClicked:{
                                 serial.reboot()
                           }
@@ -1007,17 +1012,14 @@ AppPage {
 
                       AppImage {
                           id: image_reboot
-                          anchors.centerIn: parent
-                          //anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                          fillMode: Image.PreserveAspectFit  // 保持纵横比适应
+                          anchors.horizontalCenter: parent.horizontalCenter
+                          fillMode: Image.PreserveAspectFit
                           source: "../../assets/reboot.svg"
                       }
 
                       AppText{
                           id: text_reboot
-                          anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                          anchors.top: image_reboot.bottom
-                          anchors.topMargin: 10
+                          anchors.horizontalCenter: parent.horizontalCenter
                           text: "系统重启"
                           color: app.fontColor
                           font.bold: true
@@ -1047,8 +1049,9 @@ AppPage {
                     id: column_di
                     spacing: 10
                     anchors.fill: parent
+                    topPadding: 10
                     AppButton {
-                       anchors.centerIn: parent
+                       width: parent.width
                        text: "高级功能"
                        textColor: app.fontColor
                        flat: false

+ 21 - 51
app_bzy_armhf_7/qml/pages/TestPage.qml

@@ -2,11 +2,7 @@ import QtQuick
 import Felgo
 import QtMultimedia
 import QtQuick.Controls
-import Qt.labs.settings 1.0 as QtLabs
-import QtQuick.Controls.Material 2.0
-import QtLocation 5.5
-import QtPositioning 5.5
-import Qt5Compat.GraphicalEffects
+// import QtQuick.Controls.Material 2.0  // 移除:与Felgo主题冲突,导致AppSwitch颜色异常
 
 import "../controls"
 import "../common"
@@ -228,43 +224,29 @@ AppPage {
             color: app.cardColor
             radius: 5
 
-            Rectangle{
-                id: rec_test
-                anchors.top: text_title.bottom
-                anchors.topMargin: 5
+            Column {
+                id: testContent
+                anchors.top: parent.top
+                anchors.topMargin: dp(10)
                 anchors.left: parent.left
-                width: parent.width*0.97
-                height: parent.height *0.6
-                border.width: 1
-                border.color: "white"
-                radius: 5
-                color: app.cardColor
-                Column {
-                    anchors.top: text_title.bottom
-                    anchors.left: parent.left
-                    anchors.leftMargin: 10
-                    spacing: dp(5)
-
-                    Row
-                    {
-                        spacing: 10
+                anchors.leftMargin: dp(10)
+                anchors.right: parent.right
+                spacing: dp(10)
 
-                        AppText {
-                            id: text_title
-                            text: "测试调试"
-                            font.bold: true
-                            color: "#28a779"
-                            fontSize: 20
-                        }
+                AppText {
+                    id: text_title
+                    text: "测试调试"
+                    font.bold: true
+                    color: "#28a779"
+                    fontSize: 20
+                }
 
-                        AppText {
-                            id: apptext_res
-                            text: "[测试结果]"
-                            fontSize:15
-                            color: "grey"
-                            anchors.verticalCenter: text_title.verticalCenter
-                        }
-                    }
+                AppText {
+                    id: apptext_res
+                    text: "[测试结果]"
+                    fontSize: 15
+                    color: "grey"
+                }
 
                     Row {
                         spacing: 100
@@ -296,8 +278,6 @@ AppPage {
                             text: "风机测试"
                             color: app.fontColor
                             fontSize:  15
-                            //font.bold: true
-                            anchors.verticalCenter: fantest_switch.verticalCenter
                         }
 
                         AppSwitch {
@@ -321,8 +301,6 @@ AppPage {
                             text: "胶带测试"
                             fontSize:  15
                             color: app.fontColor
-                            //font.bold: true
-                            anchors.verticalCenter: jiaodai_switch.verticalCenter
                         }
 
                         AppSwitch {
@@ -344,8 +322,6 @@ AppPage {
                             text: "补光测试"
                             color: app.fontColor
                             fontSize:  15
-                            //font.bold: true
-                            anchors.verticalCenter: led_switch.verticalCenter
                         }
 
                         AppSwitch {
@@ -370,8 +346,6 @@ AppPage {
                             text: "立即拍照"
                             color: app.fontColor
                             fontSize:  15
-                            //font.bold: true
-                            anchors.verticalCenter: takephoto_switch.verticalCenter
                         }
 
                         AppSwitch {
@@ -392,8 +366,6 @@ AppPage {
                             text: "对焦拍照"
                             color: app.fontColor
                             fontSize:  15
-                            //font.bold: true
-                            anchors.verticalCenter: focus_switch.verticalCenter
                         }
 
                         AppSwitch {
@@ -578,8 +550,6 @@ AppPage {
                         }
                     }
             }
-            }
         }
-
     }
 }

+ 1 - 1
q6_felgo_iot/qml/Main.qml

@@ -185,7 +185,7 @@ App {
     
     Connections{
         target: curl
-        onDownloadFinished :function(result){
+        function onDownloadFinished(result){
             //notificationPage.visible = false
             if(result){
                 navigation.setCurrentTab(1) //升级文件下载成功,跳转到日志界面

+ 8 - 6
q6_felgo_iot/qml/model/DataModel.qml

@@ -31,7 +31,7 @@ Item {
         id: logicConnection
 
         // action 1 - fetchTodos
-        onFetchTodos: {
+        onFetchTodos: function() {
             // check cached value first
             var cached = cache.getValue("todos")
             if(cached)
@@ -52,7 +52,7 @@ Item {
         }
 
         // action 2 - fetchTodoDetails
-        onFetchTodoDetails: id => {
+        onFetchTodoDetails: function(id) {
                                 // check cached todo details first
                                 var cached = cache.getValue("todo_"+id)
                                 if(cached) {
@@ -77,7 +77,7 @@ Item {
                             }
 
         // action 3 - storeTodo
-        onStoreTodo: todo => {
+        onStoreTodo: function(todo) {
                          // store with api
                          api.addTodo(todo,
                                      function(data) {
@@ -103,12 +103,12 @@ Item {
                      }
 
         // action 4 - clearCache
-        onClearCache: {
+        onClearCache: function() {
             cache.clearAll()
         }
 
         // action 5 - login
-        onLogin: {
+        onLogin: function(password) {
             if(password==="8888")
             {
                  _.userLoggedIn = true
@@ -123,7 +123,9 @@ Item {
 
         }
         // action 6 - logout
-        onLogout: _.userLoggedIn = false
+        onLogout: function() {
+            _.userLoggedIn = false
+        }
     }
 
     // you can place getter functions here that do not modify the data

+ 1 - 1
q6_felgo_iot/qml/pages/EffectsPage.qml

@@ -496,7 +496,7 @@ AppPage {
     id: fxControls
     targetEffect: fxEffect
     visible: false
-    onEffectLoaded: name => {
+    onEffectLoaded: function(name) {
       if(name === "No effect") {
         fxControls.visible = false
       }

+ 8 - 8
q6_felgo_iot/qml/pages/HomePage.qml

@@ -440,11 +440,11 @@ AppPage {
                 Column {
                     anchors.centerIn: parent
                     spacing: 12
+                    topPadding: 30
                     visible: true
                     AppImage {
                         id: image_01
                         anchors.horizontalCenter: parent.horizontalCenter
-                        anchors.topMargin:  30
                         source: "../../assets/a.svg"
                         fillMode: Image.PreserveAspectFit
                     }
@@ -546,9 +546,9 @@ AppPage {
                 Column{
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/net.svg"
                     }
@@ -629,9 +629,9 @@ AppPage {
                 Column{
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/gps.svg"
                     }
@@ -826,10 +826,10 @@ AppPage {
                     id: column_colt
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         id: image_timesvg
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/time.svg"
                     }
@@ -916,9 +916,9 @@ AppPage {
                 Column {
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/tempture.svg"
                     }
@@ -955,9 +955,9 @@ AppPage {
                 Column {
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/humidity.svg"
                     }
@@ -982,9 +982,9 @@ AppPage {
                 Column {
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/vbat.svg"
                     }
@@ -1009,9 +1009,9 @@ AppPage {
                 Column  {
                     anchors.centerIn: parent
                     spacing: 5
+                    topPadding: 30
                     AppImage {
                         anchors.horizontalCenter: parent.horizontalCenter   //垂直居中显示
-                        anchors.topMargin: 30
                         fillMode: Image.PreserveAspectFit  // 保持纵横比适应
                         source: "../../assets/current.svg"
                     }

+ 4 - 4
q6_felgo_iot/qml/pages/LocalNotificationPage.qml

@@ -14,7 +14,7 @@ AppPage {
 
     Connections{
         target: serial
-        function  onYmodemReady(mtype) {
+        function onYmodemReady(mtype) {
             progressBar.value = 0.0
             notificationtext.text = mtype
             notificationPage.visible = true
@@ -69,17 +69,17 @@ AppPage {
 
     Connections{
         target:curl_picture
-        onProgressChanged:{
+        function onProgressChanged(){
             console.log("更新进度条:",uploadedPercent)
             progressBar.value = uploadedPercent
             process_text.text = uploadedPercent.toFixed(2) + "%";
 
         }
-        onDownloadStart:function(tips){
+        function onDownloadStart(tips){
             notificationPage.visible = true
             notificationtext.text = tips
         }
-        onFinished :function(success,error){
+        function onFinished(success,error){
             //notificationPage.visible = false
             if(success){
                 notificationtext.color = "green"

+ 3 - 3
q6_felgo_iot/qml/pages/LoginPage.qml

@@ -48,6 +48,8 @@ AppPage {
 
         Column{
             anchors.fill: loginForm
+            topPadding: 5
+            bottomPadding: 5
             AppText {
                 id: apptext_title
                 anchors.horizontalCenter: parent.horizontalCenter    //垂直居中显示
@@ -58,18 +60,16 @@ AppPage {
 
             AppText{
                 id: text_logintime
-                anchors.topMargin: 5
                 text: "休眠计时:" + logintimeout
                 color: "red"
                 fontSize: 20
             }
 
             AppText {
+                anchors.right: parent.right
                 text: "软件版本:" + app.appversionText
                 color: "gray"
                 fontSize: 10
-                anchors.right: parent.right
-                anchors.bottom: parent.bottom
             }
         }
 

+ 1 - 1
q6_felgo_iot/qml/pages/TodoListPage.qml

@@ -30,7 +30,7 @@ AppPage {
     // when a todo is added, we open the detail page for it
     Connections {
         target: dataModel
-        onTodoStored: todo => {
+        onTodoStored: function(todo) {
                           page.navigationStack.popAllExceptFirstAndPush(detailPageComponent, { todoId: todo.id })
                       }
     }