linee 6 napja
szülő
commit
cd1272337d

+ 0 - 2
entry/src/main/java/com/fujica/abk/slice/MainAbilitySlice.java

@@ -105,8 +105,6 @@ public class MainAbilitySlice extends AbilitySlice {
 
 //        api.http(getContext(), "http://www.baidu.com", "GET", null, null, null);
 
-        api.http(getContext(), "/park/near/page?longitude=0&latitude=0", "GET", null, null, null);
-
         // 设置全屏显示
         setFullScreen();
 

+ 12 - 11
entry/src/main/java/com/fujica/abk/utils/LoadingDialog.java

@@ -7,6 +7,7 @@ import ohos.agp.components.element.ShapeElement;
 import ohos.agp.colors.RgbColor;
 import ohos.agp.utils.Color;
 import ohos.agp.utils.LayoutAlignment;
+import ohos.agp.utils.Rect;
 import ohos.agp.window.dialog.CommonDialog;
 import ohos.app.Context;
 import ohos.eventhandler.EventHandler;
@@ -73,17 +74,16 @@ public class LoadingDialog {
         }
 
         try {
-            // 创建全屏遮罩布局
+            // 创建固定大小的布局(不再全屏)
             DirectionalLayout rootLayout = new DirectionalLayout(context);
-            rootLayout.setWidth(DirectionalLayout.LayoutConfig.MATCH_PARENT);
-            rootLayout.setHeight(DirectionalLayout.LayoutConfig.MATCH_PARENT);
+            // 设置固定大小,根据内容自适应
+            DirectionalLayout.LayoutConfig rootConfig = new DirectionalLayout.LayoutConfig(
+                DirectionalLayout.LayoutConfig.MATCH_CONTENT,
+                DirectionalLayout.LayoutConfig.MATCH_CONTENT
+            );
+            rootLayout.setLayoutConfig(rootConfig);
             rootLayout.setAlignment(LayoutAlignment.CENTER);
-            
-            // 设置半透明黑色背景
-            ShapeElement background = new ShapeElement();
-            background.setShape(ShapeElement.RECTANGLE);
-            background.setRgbColor(new RgbColor(0, 0, 0, 128)); // 半透明黑色
-            rootLayout.setBackground(background);
+            // 不设置背景,保持全透明
             
             // 创建内容容器(白色圆角卡片)
             DirectionalLayout contentLayout = new DirectionalLayout(context);
@@ -130,13 +130,14 @@ public class LoadingDialog {
             
             // 添加到根布局
             rootLayout.addComponent(contentLayout);
-            
             // 创建对话框
             CommonDialog dialog = new CommonDialog(context);
+            // 注意:CommonDialog 在 API 7 中可能无法完全移除外层全屏蒙层
+            // 只能通过 setTransparent(true) 设置对话框背景透明
+            dialog.setTransparent(true); // 设置对话框背景透明
             dialog.setContentCustomComponent(rootLayout);
             dialog.setAutoClosable(false); // 不可自动关闭
 //            dialog.setCanceledOnTouchOutside(false); // 点击外部不可关闭
-            dialog.setTransparent(true); // 透明背景,使用自定义背景
             
             // 显示对话框
             dialog.show();

+ 48 - 67
entry/src/main/java/com/fujica/abk/utils/api.java

@@ -26,7 +26,7 @@ public class api {
     // private static String host = "http://192.168.12.139:10001/transfer/mobile";  //本机网关
 //    private static String host = "http://192.168.12.139:10004/mobile";  // 本机中转
 
-     private static String host = "https://gatewayservicev2dev.fujica.com.cn/transfer/mobile"; //UAT环境
+    private static String host = "https://gatewayservicev2dev.fujica.com.cn/transfer/mobile"; //UAT环境
     // private static String host = "https://gatewayservicev2test.fujica.com.cn/transfer/mobile"; //PRE环境
 
     // 前端nginx连接
@@ -113,7 +113,7 @@ public class api {
                 // 如果需要特定类型,调用方需要自己转换
                 result.setData((T) jsonObj.get("data"));
             }
-            
+
             return result;
         } catch (Exception e) {
             Log.error("JSON解析失败: " + e.getMessage());
@@ -130,37 +130,36 @@ public class api {
         if (failToast == null) {
             failToast = true;
         }
-        
+
         // 显示Loading:默认显示,只有当hideLoading!=null && hideLoading==false时才不显示
         final boolean shouldShowLoading = !(hideLoading != null && hideLoading);
         if (shouldShowLoading) {
             LoadingDialog.show(context);
         }
-        
+
         url = mergeUrl(url, method, data);
         Log.info("请求" + url);
         String token = cache.getToken(context);
         final String _url = url;
         final Boolean _failToast = failToast;
-        final boolean _shouldShowLoading = shouldShowLoading;
         return CompletableFuture.supplyAsync(() -> {
             HttpURLConnection connection = null;
             try {
                 URL requestUrl = new URL(_url);
                 connection = (HttpURLConnection) requestUrl.openConnection();
-                
+
                 // 设置请求方法
                 connection.setRequestMethod(method);
-                
+
                 // 设置请求头
                 connection.setRequestProperty("Accept", "application/json");
                 connection.setRequestProperty("Content-Type", "application/json");
                 connection.setRequestProperty("token", token);
-                
+
                 // 设置超时
                 connection.setConnectTimeout(10000);
                 connection.setReadTimeout(60000);
-                
+
                 // 设置请求体(非GET请求)
                 if (!"GET".equals(method) && data != null) {
                     connection.setDoOutput(true);
@@ -170,14 +169,14 @@ public class api {
                     os.flush();
                     os.close();
                 }
-                
+
                 // 执行请求
                 int responseCode = connection.getResponseCode();
-                
+
                 try {
                     R<T> result;
                     if (responseCode == 401) {
-                        Toast.error(context,"登录过期,请重试");
+                        Toast.error(context, "登录过期,请重试");
                         cache.logout(context);
                         EventBus.getInstance().emit("onAuthChanged");
                         result = new R<>("登录过期,请重试");
@@ -197,66 +196,49 @@ public class api {
                         }
                         reader.close();
                         inputStream.close();
-                        
+
                         String resultStr = response.toString();
                         Log.error("响应:" + resultStr);
                         result = parseResponse(resultStr);
-                        
+
                         if (result != null && !result.isSuccess() && _failToast) {
                             String errorMsg = result.getMsg() != null ? result.getMsg() : "操作失败" + result.getCode();
-                            Toast.error(context,errorMsg);
+                            Toast.error(context, errorMsg);
                         }
                         Log.info("响应:" + resultStr);
                         if (result == null) {
                             result = new R<>("解析响应失败");
                         }
                     }
-                    
-                    // 隐藏Loading
-                    if (_shouldShowLoading) {
-                        LoadingDialog.hide();
-                    }
-                    
+
                     return result;
                 } catch (Exception e) {
                     String msg = "操作失败" + e.getMessage();
-                    Toast.error(context,msg);
+                    Toast.error(context, msg);
                     Log.error("响应解析错误: " + e.getMessage());
-                    
-                    // 隐藏Loading
-                    if (_shouldShowLoading) {
-                        LoadingDialog.hide();
-                    }
-                    
+
                     return new R<>(msg);
                 }
             } catch (IOException e) {
-                String msg = (e.getMessage() != null && (e.getMessage().contains("2300006") || e.getMessage().contains("2300007"))) 
+                String msg = (e.getMessage() != null && (e.getMessage().contains("2300006") || e.getMessage().contains("2300007")))
                         ? "网络连接失败" : e.getMessage() + ":" + e.getClass().getSimpleName();
-                Toast.error(context,msg);
+                Toast.error(context, msg);
                 Log.error("请求错误: " + e.getMessage());
-                
-                // 隐藏Loading
-                if (_shouldShowLoading) {
-                    LoadingDialog.hide();
-                }
-                
+
                 return new R<>(msg);
             } catch (Exception e) {
                 String msg = "操作失败" + e.getMessage();
-                Toast.error(context,msg);
+                Toast.error(context, msg);
                 Log.error("请求异常: " + e.getMessage());
-                
-                // 隐藏Loading
-                if (_shouldShowLoading) {
-                    LoadingDialog.hide();
-                }
-                
+
                 return new R<>(msg);
             } finally {
                 if (connection != null) {
                     connection.disconnect();
                 }
+                if (shouldShowLoading) {
+//                    LoadingDialog.hide();
+                }
             }
         });
     }
@@ -286,7 +268,7 @@ public class api {
      * GET请求(带选项)
      */
     public static <T> CompletableFuture<R<T>> get1(Context context, ApiOption option) {
-        return http(context,option.getUrl(), "GET", option.getData(), option.getToast(), option.getHideLoading());
+        return http(context, option.getUrl(), "GET", option.getData(), option.getToast(), option.getHideLoading());
     }
 
 
@@ -314,17 +296,17 @@ public class api {
             try {
                 URL requestUrl = new URL(finalUrl);
                 connection = (HttpURLConnection) requestUrl.openConnection();
-                
+
                 // 设置请求方法
                 connection.setRequestMethod("POST");
-                
+
                 // 设置请求头
                 String boundary = "----WebKitFormBoundary" + System.currentTimeMillis();
                 connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
                 connection.setRequestProperty("Connection", "keep-alive");
                 connection.setRequestProperty("token", token);
                 connection.setDoOutput(true);
-                
+
                 // 构建multipart/form-data请求体
                 OutputStream os = connection.getOutputStream();
                 java.io.File file = new java.io.File(imageUri);
@@ -333,7 +315,7 @@ public class api {
                     os.write(("--" + boundary + "\r\n").getBytes("UTF-8"));
                     os.write(("Content-Disposition: form-data; name=\"file\"; filename=\"file.jpg\"\r\n").getBytes("UTF-8"));
                     os.write(("Content-Type: image/jpg\r\n\r\n").getBytes("UTF-8"));
-                    
+
                     // 读取并写入文件内容
                     java.io.FileInputStream fis = new java.io.FileInputStream(file);
                     byte[] buffer = new byte[8192];
@@ -342,21 +324,21 @@ public class api {
                         os.write(buffer, 0, bytesRead);
                     }
                     fis.close();
-                    
+
                     // 结束multipart
                     os.write(("\r\n--" + boundary + "--\r\n").getBytes("UTF-8"));
                 }
                 os.flush();
                 os.close();
-                
+
                 // 执行请求
                 int responseCode = connection.getResponseCode();
-                
+
                 try {
                     R<T> result;
                     if (responseCode != 200) {
                         String msg = "操作失败:" + responseCode;
-                        Toast.error(context,msg);
+                        Toast.error(context, msg);
                         Log.info("响应:" + responseCode);
                         result = new R<>(msg);
                     } else {
@@ -370,51 +352,50 @@ public class api {
                         }
                         reader.close();
                         inputStream.close();
-                        
+
                         String resultStr = response.toString();
                         result = parseResponse(resultStr);
-                        
+
                         if (result != null && !result.isSuccess()) {
                             String errorMsg = result.getMsg() != null ? result.getMsg() : "操作失败" + result.getCode();
-                            Toast.error(context,errorMsg);
+                            Toast.error(context, errorMsg);
                         }
                         Log.info("响应:" + resultStr);
                         if (result == null) {
                             result = new R<>("解析响应失败");
                         }
                     }
-                    
+
                     // 隐藏Loading
                     LoadingDialog.hide();
-                    
+
                     return result;
                 } catch (Exception e) {
                     String msg = "操作失败" + e.getMessage();
-                    Toast.error(context,msg);
+                    Toast.error(context, msg);
                     Log.error("响应解析错误: " + e.getMessage());
-                    
+
                     // 隐藏Loading
                     LoadingDialog.hide();
-                    
+
                     return new R<>(msg);
                 }
             } catch (IOException e) {
                 String msg = e.getMessage() + ":" + e.getClass().getSimpleName();
-                Toast.error(context,msg);
+                Toast.error(context, msg);
                 Log.error("上传错误: " + e.getMessage());
-                
+
                 // 隐藏Loading
                 LoadingDialog.hide();
-                
+
                 return new R<>(msg);
             } catch (Exception e) {
                 String msg = "操作失败" + e.getMessage();
-                Toast.error(context,msg);
+                Toast.error(context, msg);
                 Log.error("上传异常: " + e.getMessage());
-                
+
                 // 隐藏Loading
-                LoadingDialog.hide();
-                
+
                 return new R<>(msg);
             } finally {
                 if (connection != null) {

+ 10 - 0
entry/src/main/resources/base/graphic/background_loading_content.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape
+    xmlns:ohos="http://schemas.huawei.com/res/ohos"
+    ohos:shape="rectangle">
+    <corners
+        ohos:radius="16vp"/>
+    <solid
+        ohos:color="#FFFFFFFF"/>
+</shape>
+

+ 38 - 0
entry/src/main/resources/base/layout/layout_loading_dialog.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<DirectionalLayout
+    xmlns:ohos="http://schemas.huawei.com/res/ohos"
+    ohos:height="match_content"
+    ohos:width="match_content"
+    ohos:alignment="center"
+    ohos:orientation="vertical">
+    <!-- 根布局不设置背景,保持全透明 -->
+
+    <!-- 内容容器(白色圆角卡片) -->
+    <DirectionalLayout
+        ohos:id="$+id:content_layout"
+        ohos:height="match_content"
+        ohos:width="match_content"
+        ohos:orientation="vertical"
+        ohos:alignment="center"
+        ohos:padding="40vp"
+        ohos:background_element="$graphic:background_loading_content">
+
+        <!-- ProgressBar -->
+        <ProgressBar
+            ohos:id="$+id:progress_bar"
+            ohos:height="80vp"
+            ohos:width="80vp"
+            ohos:indeterminate="true"/>
+
+        <!-- 提示文字 -->
+        <Text
+            ohos:id="$+id:text_loading"
+            ohos:height="match_content"
+            ohos:width="match_content"
+            ohos:text="加载中..."
+            ohos:text_size="14fp"
+            ohos:text_color="#FF666666"
+            ohos:top_margin="16vp"/>
+    </DirectionalLayout>
+</DirectionalLayout>
+