ソースを参照

feat(miniprogram): 实现分享页面功能

- 添加证书、船厂信息、海事年检通知和培训通知的分享页面
- 实现分享链接解析和数据加载
- 优化页面样式和布局
- 添加空数据提示和加载状态
wzg 8 ヶ月 前
コミット
bc1e731ca8

+ 50 - 24
miniprogram/pages/cert/sharePage/sharePage.js

@@ -1,66 +1,92 @@
 // pages/cert/sharePage/sharePage.js
+const app = getApp();
 Page({
-
   /**
    * 页面的初始数据
    */
   data: {
-
+    sharedCertList: [], // 用于存储分享的证书列表
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    const token = options.token;
+    if (token) {
+      this.getSharedCertInfo(token);
+    } else {
+      wx.showToast({
+        title: "无效的分享链接",
+        icon: "none",
+      });
+    }
+  },
 
+  getSharedCertInfo(token) {
+    // 调用API获取分享的证书信息
+    // API: POST /ship/cert/share/list
+    // 参数: token (query)
+    wx.showLoading({
+      title: "加载中...",
+    });
+    app.globalData.$http
+      .post("/ship/cert/share/list", { token })
+      .then((res) => {
+        wx.hideLoading();
+        if (res.success && res.data) {
+          this.setData({
+            sharedCertList: res.data,
+          });
+        } else {
+          wx.showToast({
+            title: res.msg || "获取证书信息失败",
+            icon: "none",
+          });
+        }
+      })
+      .catch((err) => {
+        wx.hideLoading();
+        wx.showToast({
+          title: "网络错误",
+          icon: "none",
+        });
+        console.error("获取分享证书信息失败:", err);
+      });
   },
 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
-  onReady() {
-
-  },
+  onReady() {},
 
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow() {
-
-  },
+  onShow() {},
 
   /**
    * 生命周期函数--监听页面隐藏
    */
-  onHide() {
-
-  },
+  onHide() {},
 
   /**
    * 生命周期函数--监听页面卸载
    */
-  onUnload() {
-
-  },
+  onUnload() {},
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
-  onPullDownRefresh() {
-
-  },
+  onPullDownRefresh() {},
 
   /**
    * 页面上拉触底事件的处理函数
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage() {
-
-  }
-})
+  onShareAppMessage() {},
+});

+ 3 - 2
miniprogram/pages/cert/sharePage/sharePage.json

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
-}
+  "usingComponents": {},
+  "navigationBarTitleText": "分享的证书"
+}

+ 13 - 2
miniprogram/pages/cert/sharePage/sharePage.wxml

@@ -1,2 +1,13 @@
-<!--pages/cert/sharePage/sharePage.wxml-->
-<text>pages/cert/sharePage/sharePage.wxml</text>
+<!-- pages/cert/sharePage/sharePage.wxml -->
+<view class="container">
+    <block wx:if="{{sharedCertList.length > 0}}">
+        <view wx:for="{{sharedCertList}}" wx:key="index" class="cert-item">
+            <text class="cert-name">证书名称: {{item.name || '未知证书'}}</text>
+            <text class="cert-expiry">有效期至: {{item.expiryDate || 'N/A'}}</text>
+            <!-- 根据实际返回的字段调整 item.name 和 item.expiryDate -->
+        </view>
+    </block>
+    <block wx:else>
+        <text>暂无分享的证书信息</text>
+    </block>
+</view>

+ 39 - 1
miniprogram/pages/cert/sharePage/sharePage.wxss

@@ -1 +1,39 @@
-/* pages/cert/sharePage/sharePage.wxss */
+/* pages/cert/sharePage/sharePage.wxss */
+.container {
+  padding: 20rpx;
+  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
+    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
+  min-height: 100vh;
+  background-color: #f4f4f4;
+}
+
+.cert-item {
+  background-color: #fff;
+  border-radius: 10rpx;
+  padding: 30rpx 20rpx;
+  margin-bottom: 20rpx;
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
+  display: flex;
+  flex-direction: column;
+}
+
+.cert-name {
+  font-size: 32rpx;
+  color: #333;
+  font-weight: bold;
+  margin-bottom: 10rpx;
+}
+
+.cert-expiry {
+  font-size: 28rpx;
+  color: #666;
+}
+
+/* 如果列表为空 */
+.container > .empty-text {
+  display: block;
+  text-align: center;
+  color: #999;
+  font-size: 30rpx;
+  padding-top: 200rpx;
+}

+ 50 - 24
miniprogram/pages/school/sharePage/sharePage.js

@@ -1,66 +1,92 @@
 // pages/school/sharePage/sharePage.js
+const app = getApp();
 Page({
-
   /**
    * 页面的初始数据
    */
   data: {
-
+    sharedShipyardInfo: null, // 用于存储分享的船厂信息
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    const shipyardId = options.shipyardId;
+    if (shipyardId) {
+      this.getSharedShipyardInfo(shipyardId);
+    } else {
+      wx.showToast({
+        title: "无效的分享链接",
+        icon: "none",
+      });
+    }
+  },
 
+  getSharedShipyardInfo(shipyardId) {
+    // 调用API获取分享的船厂信息
+    // API: POST /shipyard/info/share
+    // 参数: shipyardId (query)
+    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);
+      });
   },
 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
-  onReady() {
-
-  },
+  onReady() {},
 
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow() {
-
-  },
+  onShow() {},
 
   /**
    * 生命周期函数--监听页面隐藏
    */
-  onHide() {
-
-  },
+  onHide() {},
 
   /**
    * 生命周期函数--监听页面卸载
    */
-  onUnload() {
-
-  },
+  onUnload() {},
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
-  onPullDownRefresh() {
-
-  },
+  onPullDownRefresh() {},
 
   /**
    * 页面上拉触底事件的处理函数
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage() {
-
-  }
-})
+  onShareAppMessage() {},
+});

+ 3 - 2
miniprogram/pages/school/sharePage/sharePage.json

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
-}
+  "usingComponents": {},
+  "navigationBarTitleText": "分享的船厂信息"
+}

+ 25 - 2
miniprogram/pages/school/sharePage/sharePage.wxml

@@ -1,2 +1,25 @@
-<!--pages/school/sharePage/sharePage.wxml-->
-<text>pages/school/sharePage/sharePage.wxml</text>
+<!-- pages/school/sharePage/sharePage.wxml -->
+<view class="container">
+    <block wx:if="{{sharedShipyardInfo}}">
+        <view class="info-card">
+            <view class="info-title">{{sharedShipyardInfo.name || '船厂信息'}}</view>
+            <view class="info-item">
+                <text class="label">船厂地址:</text>
+                <text class="value">{{sharedShipyardInfo.address || '暂无地址'}}</text>
+            </view>
+            <view class="info-item">
+                <text class="label">联系电话:</text>
+                <text class="value">{{sharedShipyardInfo.phone || '暂无电话'}}</text>
+            </view>
+            <view class="info-item">
+                <text class="label">主营业务:</text>
+                <text class="value">{{sharedShipyardInfo.majorBusiness || '暂无介绍'}}</text>
+            </view>
+            <!-- 根据实际返回的对象字段进行调整 -->
+            <!-- 例如: sharedShipyardInfo.contactPerson, sharedShipyardInfo.website 等 -->
+        </view>
+    </block>
+    <block wx:else>
+        <text class="empty-text">暂无分享的船厂信息</text>
+    </block>
+</view>

+ 52 - 1
miniprogram/pages/school/sharePage/sharePage.wxss

@@ -1 +1,52 @@
-/* pages/school/sharePage/sharePage.wxss */
+/* pages/school/sharePage/sharePage.wxss */
+.container {
+  padding: 20rpx;
+  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
+    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
+  min-height: 100vh;
+  background-color: #f4f4f4;
+}
+
+.info-card {
+  background-color: #fff;
+  border-radius: 10rpx;
+  padding: 30rpx 20rpx;
+  margin-bottom: 20rpx;
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
+}
+
+.info-title {
+  font-size: 36rpx;
+  color: #333;
+  font-weight: bold;
+  margin-bottom: 20rpx;
+  text-align: center;
+}
+
+.info-item {
+  display: flex;
+  font-size: 30rpx;
+  color: #555;
+  margin-bottom: 15rpx;
+  line-height: 1.6;
+}
+
+.info-item .label {
+  width: 180rpx; /* 根据实际标签长度调整 */
+  color: #888;
+  margin-right: 10rpx;
+}
+
+.info-item .value {
+  flex: 1;
+  color: #333;
+}
+
+/* 如果对象为空 */
+.container > .empty-text {
+  display: block;
+  text-align: center;
+  color: #999;
+  font-size: 30rpx;
+  padding-top: 200rpx;
+}

+ 50 - 24
miniprogram/pages/securityCheck/sharePage/sharePage.js

@@ -1,66 +1,92 @@
 // pages/securityCheck/sharePage/sharePage.js
+const app = getApp();
 Page({
-
   /**
    * 页面的初始数据
    */
   data: {
-
+    sharedNoticeInfo: null, // 用于存储分享的海事年检通知信息
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    const noticeId = options.noticeId;
+    if (noticeId) {
+      this.getSharedNoticeInfo(noticeId);
+    } else {
+      wx.showToast({
+        title: "无效的分享链接",
+        icon: "none",
+      });
+    }
+  },
 
+  getSharedNoticeInfo(noticeId) {
+    // 调用API获取分享的海事年检通知信息
+    // API: POST /annual/inspection/notice/share
+    // 参数: noticeId (query)
+    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);
+      });
   },
 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
-  onReady() {
-
-  },
+  onReady() {},
 
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow() {
-
-  },
+  onShow() {},
 
   /**
    * 生命周期函数--监听页面隐藏
    */
-  onHide() {
-
-  },
+  onHide() {},
 
   /**
    * 生命周期函数--监听页面卸载
    */
-  onUnload() {
-
-  },
+  onUnload() {},
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
-  onPullDownRefresh() {
-
-  },
+  onPullDownRefresh() {},
 
   /**
    * 页面上拉触底事件的处理函数
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage() {
-
-  }
-})
+  onShareAppMessage() {},
+});

+ 3 - 2
miniprogram/pages/securityCheck/sharePage/sharePage.json

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
-}
+  "usingComponents": {},
+  "navigationBarTitleText": "分享的年检通知"
+}

+ 21 - 2
miniprogram/pages/securityCheck/sharePage/sharePage.wxml

@@ -1,2 +1,21 @@
-<!--pages/securityCheck/sharePage/sharePage.wxml-->
-<text>pages/securityCheck/sharePage/sharePage.wxml</text>
+<!-- pages/securityCheck/sharePage/sharePage.wxml -->
+<view class="container">
+    <block wx:if="{{sharedNoticeInfo}}">
+        <view class="notice-card">
+            <view class="notice-title">{{sharedNoticeInfo.title || '海事年检通知'}}</view>
+            <view class="notice-item">
+                <text class="label">通知内容:</text>
+                <text class="value">{{sharedNoticeInfo.content || '暂无内容'}}</text>
+            </view>
+            <view class="notice-item">
+                <text class="label">发布日期:</text>
+                <text class="value">{{sharedNoticeInfo.publishDate || 'N/A'}}</text>
+            </view>
+            <!-- 根据实际返回的对象字段进行调整 -->
+            <!-- 例如: sharedNoticeInfo.shipName, sharedNoticeInfo.inspectionDate 等 -->
+        </view>
+    </block>
+    <block wx:else>
+        <text>暂无分享的通知信息</text>
+    </block>
+</view>

+ 52 - 1
miniprogram/pages/securityCheck/sharePage/sharePage.wxss

@@ -1 +1,52 @@
-/* pages/securityCheck/sharePage/sharePage.wxss */
+/* pages/securityCheck/sharePage/sharePage.wxss */
+.container {
+  padding: 20rpx;
+  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
+    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
+  min-height: 100vh;
+  background-color: #f4f4f4;
+}
+
+.notice-card {
+  background-color: #fff;
+  border-radius: 10rpx;
+  padding: 30rpx 20rpx;
+  margin-bottom: 20rpx;
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
+}
+
+.notice-title {
+  font-size: 36rpx;
+  color: #333;
+  font-weight: bold;
+  margin-bottom: 20rpx;
+  text-align: center;
+}
+
+.notice-item {
+  display: flex;
+  font-size: 30rpx;
+  color: #555;
+  margin-bottom: 15rpx;
+  line-height: 1.6;
+}
+
+.notice-item .label {
+  width: 180rpx;
+  color: #888;
+  margin-right: 10rpx;
+}
+
+.notice-item .value {
+  flex: 1;
+  color: #333;
+}
+
+/* 如果对象为空 */
+.container > .empty-text {
+  display: block;
+  text-align: center;
+  color: #999;
+  font-size: 30rpx;
+  padding-top: 200rpx;
+}

+ 50 - 24
miniprogram/pages/shipyard/sharePage/sharePage.js

@@ -1,66 +1,92 @@
 // pages/shipyard/sharePage/sharePage.js
+const app = getApp();
 Page({
-
   /**
    * 页面的初始数据
    */
   data: {
-
+    sharedTrainingNotice: null, // 用于存储分享的培训通知信息
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
+    const noticeId = options.noticeId;
+    if (noticeId) {
+      this.getSharedTrainingNotice(noticeId);
+    } else {
+      wx.showToast({
+        title: "无效的分享链接",
+        icon: "none",
+      });
+    }
+  },
 
+  getSharedTrainingNotice(noticeId) {
+    // 调用API获取分享的培训通知信息
+    // API: POST /crew/school/training/notice/share
+    // 参数: noticeId (query)
+    wx.showLoading({
+      title: "加载中...",
+    });
+    app.globalData.$http
+      .post("/crew/school/training/notice/share", { noticeId })
+      .then((res) => {
+        wx.hideLoading();
+        if (res.success && res.data) {
+          this.setData({
+            sharedTrainingNotice: res.data,
+          });
+        } else {
+          wx.showToast({
+            title: res.msg || "获取培训通知失败",
+            icon: "none",
+          });
+        }
+      })
+      .catch((err) => {
+        wx.hideLoading();
+        wx.showToast({
+          title: "网络错误",
+          icon: "none",
+        });
+        console.error("获取分享培训通知信息失败:", err);
+      });
   },
 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
-  onReady() {
-
-  },
+  onReady() {},
 
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow() {
-
-  },
+  onShow() {},
 
   /**
    * 生命周期函数--监听页面隐藏
    */
-  onHide() {
-
-  },
+  onHide() {},
 
   /**
    * 生命周期函数--监听页面卸载
    */
-  onUnload() {
-
-  },
+  onUnload() {},
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
-  onPullDownRefresh() {
-
-  },
+  onPullDownRefresh() {},
 
   /**
    * 页面上拉触底事件的处理函数
    */
-  onReachBottom() {
-
-  },
+  onReachBottom() {},
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage() {
-
-  }
-})
+  onShareAppMessage() {},
+});

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

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
-}
+  "usingComponents": {},
+  "navigationBarTitleText": "分享的培训通知"
+}

+ 25 - 2
miniprogram/pages/shipyard/sharePage/sharePage.wxml

@@ -1,2 +1,25 @@
-<!--pages/shipyard/sharePage/sharePage.wxml-->
-<text>pages/shipyard/sharePage/sharePage.wxml</text>
+<!-- pages/shipyard/sharePage/sharePage.wxml -->
+<view class="container">
+    <block wx:if="{{sharedTrainingNotice}}">
+        <view class="notice-card">
+            <view class="notice-title">{{sharedTrainingNotice.title || '培训通知'}}</view>
+            <view class="notice-item">
+                <text class="label">学校名称:</text>
+                <text class="value">{{sharedTrainingNotice.schoolName || '暂无'}}</text>
+            </view>
+            <view class="notice-item">
+                <text class="label">培训内容:</text>
+                <text class="value">{{sharedTrainingNotice.content || '暂无内容'}}</text>
+            </view>
+            <view class="notice-item">
+                <text class="label">发布日期:</text>
+                <text class="value">{{sharedTrainingNotice.publishDate || 'N/A'}}</text>
+            </view>
+            <!-- 根据实际返回的对象字段进行调整 -->
+            <!-- 例如: sharedTrainingNotice.trainingCourse, sharedTrainingNotice.startDate 等 -->
+        </view>
+    </block>
+    <block wx:else>
+        <text class="empty-text">暂无分享的培训通知信息</text>
+    </block>
+</view>

+ 52 - 1
miniprogram/pages/shipyard/sharePage/sharePage.wxss

@@ -1 +1,52 @@
-/* pages/shipyard/sharePage/sharePage.wxss */
+/* pages/shipyard/sharePage/sharePage.wxss */
+.container {
+  padding: 20rpx;
+  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
+    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
+  min-height: 100vh;
+  background-color: #f4f4f4;
+}
+
+.notice-card {
+  background-color: #fff;
+  border-radius: 10rpx;
+  padding: 30rpx 20rpx;
+  margin-bottom: 20rpx;
+  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
+}
+
+.notice-title {
+  font-size: 36rpx;
+  color: #333;
+  font-weight: bold;
+  margin-bottom: 20rpx;
+  text-align: center;
+}
+
+.notice-item {
+  display: flex;
+  font-size: 30rpx;
+  color: #555;
+  margin-bottom: 15rpx;
+  line-height: 1.6;
+}
+
+.notice-item .label {
+  width: 180rpx; /* 根据实际标签长度调整 */
+  color: #888;
+  margin-right: 10rpx;
+}
+
+.notice-item .value {
+  flex: 1;
+  color: #333;
+}
+
+/* 如果对象为空 */
+.container > .empty-text {
+  display: block;
+  text-align: center;
+  color: #999;
+  font-size: 30rpx;
+  padding-top: 200rpx;
+}

+ 61 - 0
miniprogram/文档.txt

@@ -0,0 +1,61 @@
+
+    "pages/cert/sharePage/sharePage",
+POST
+/ship/cert/share/list
+分享证书-查看分享内容
+返回值为列表
+
+Parameters
+Try it out
+Name	Description
+token
+(query)
+查看分享的token
+
+--------------------------------------------
+    "pages/securityCheck/sharePage/sharePage",
+POST
+/annual/inspection/notice/share
+海事年检通知-分享
+返回值为对象
+
+Parameters
+Try it out
+Name	Description
+noticeId
+(query)
+通知ID
+
+noticeId
+--------------------------------------------
+    "pages/shipyard/sharePage/sharePage",
+POST
+/crew/school/training/notice/share
+分享查看培训通知
+返回值为对象
+
+
+Parameters
+Try it out
+Name	Description
+noticeId
+(query)
+通知ID
+
+noticeId
+
+--------------------------------------------
+    "pages/school/sharePage/sharePage"
+POST
+/shipyard/info/share
+分享查看船厂信息
+返回值为对象
+
+Parameters
+Try it out
+Name	Description
+shipyardId
+(query)
+船厂ID
+
+shipyardId