Quellcode durchsuchen

refactor(miniprogram): 重构分享页面的API调用

- 在 cert、school、securityCheck 和 shipyard 的分享页面中引入 postApi 方法
- 用 postApi 替代全局 $http.post 方法进行API调用
- 优化API调用的错误处理和数据处理逻辑
- 添加 securityCheck 分享页面的测试用例到项目配置中
wzg vor 8 Monaten
Ursprung
Commit
880296e33a

+ 2 - 2
miniprogram/pages/cert/sharePage/sharePage.js

@@ -1,4 +1,5 @@
 // pages/cert/sharePage/sharePage.js
+import { postApi } from "../../../apis/api";
 const app = getApp();
 Page({
   /**
@@ -30,8 +31,7 @@ Page({
     wx.showLoading({
       title: "加载中...",
     });
-    app.globalData.$http
-      .post("/ship/cert/share/list", { token })
+    postApi("/ship/cert/share/list", { token })
       .then((res) => {
         wx.hideLoading();
         if (res.success && res.data) {

+ 14 - 26
miniprogram/pages/school/sharePage/sharePage.js

@@ -1,4 +1,6 @@
 // pages/school/sharePage/sharePage.js
+import { postApi } from "../../../apis/api";
+
 const app = getApp();
 Page({
   /**
@@ -23,36 +25,22 @@ Page({
     }
   },
 
-  getSharedShipyardInfo(shipyardId) {
-    // 调用API获取分享的船厂信息
-    // API: POST /shipyard/info/share
-    // 参数: shipyardId (query)
+  async getSharedShipyardInfo(shipyardId) {
     wx.showLoading({
       title: "加载中...",
     });
-    app.globalData.$http
-      .post("/shipyard/info/share", { shipyardId })
-      .then((res) => {
-        wx.hideLoading();
-        if (res.success && res.data) {
-          this.setData({
-            sharedShipyardInfo: res.data,
-          });
-        } else {
-          wx.showToast({
-            title: res.msg || "获取船厂信息失败",
-            icon: "none",
-          });
-        }
-      })
-      .catch((err) => {
-        wx.hideLoading();
-        wx.showToast({
-          title: "网络错误",
-          icon: "none",
-        });
-        console.error("获取分享船厂信息失败:", err);
+    let { data } = await postApi("/shipyard/info/share", { shipyardId });
+    wx.hideLoading();
+    if (data.status === 0) {
+      this.setData({
+        sharedShipyardInfo: data.result,
+      });
+    } else {
+      wx.showToast({
+        title: data.msg || "获取船厂信息失败",
+        icon: "none",
       });
+    }
   },
 
   /**

+ 16 - 26
miniprogram/pages/securityCheck/sharePage/sharePage.js

@@ -1,4 +1,6 @@
 // pages/securityCheck/sharePage/sharePage.js
+import { postApi } from "../../../apis/api";
+
 const app = getApp();
 Page({
   /**
@@ -23,36 +25,24 @@ Page({
     }
   },
 
-  getSharedNoticeInfo(noticeId) {
-    // 调用API获取分享的海事年检通知信息
-    // API: POST /annual/inspection/notice/share
-    // 参数: noticeId (query)
+  async getSharedNoticeInfo(noticeId) {
     wx.showLoading({
       title: "加载中...",
     });
-    app.globalData.$http
-      .post("/annual/inspection/notice/share", { noticeId })
-      .then((res) => {
-        wx.hideLoading();
-        if (res.success && res.data) {
-          this.setData({
-            sharedNoticeInfo: res.data,
-          });
-        } else {
-          wx.showToast({
-            title: res.msg || "获取通知信息失败",
-            icon: "none",
-          });
-        }
-      })
-      .catch((err) => {
-        wx.hideLoading();
-        wx.showToast({
-          title: "网络错误",
-          icon: "none",
-        });
-        console.error("获取分享海事年检通知信息失败:", err);
+    let { data } = await postApi("/annual/inspection/notice/share", {
+      noticeId,
+    });
+    wx.hideLoading();
+    if (data.status === 0) {
+      this.setData({
+        sharedNoticeInfo: data.result,
       });
+    } else {
+      wx.showToast({
+        title: data.msg || "获取通知信息失败",
+        icon: "none",
+      });
+    }
   },
 
   /**

+ 3 - 2
miniprogram/pages/shipyard/sharePage/sharePage.js

@@ -1,4 +1,6 @@
 // pages/shipyard/sharePage/sharePage.js
+import { postApi } from "../../../apis/api";
+
 const app = getApp();
 Page({
   /**
@@ -30,8 +32,7 @@ Page({
     wx.showLoading({
       title: "加载中...",
     });
-    app.globalData.$http
-      .post("/crew/school/training/notice/share", { noticeId })
+    postApi("/crew/school/training/notice/share", { noticeId })
       .then((res) => {
         wx.hideLoading();
         if (res.success && res.data) {

+ 7 - 0
project.private.config.json

@@ -2,6 +2,13 @@
   "condition": {
     "miniprogram": {
       "list": [
+        {
+          "name": "pages/securityCheck/sharePage/sharePage",
+          "pathName": "pages/securityCheck/sharePage/sharePage",
+          "query": "noticeId=2",
+          "launchMode": "default",
+          "scene": null
+        },
         {
           "name": "pages/takeBill/takeBill",
           "pathName": "pages/takeBill/takeBill",