ソースを参照

唐古增加跳转H5链接的按钮

张田田 11 時間 前
コミット
a6715a7ac9

+ 1 - 2
miniprogram/module/article/pages/science-info/science-info.ts

@@ -9,10 +9,9 @@ Component({
   behaviors: [PageContainerBehavior, tickleBehavior],
   lifetimes: {
     attached() {
-      console.log(this.data, "this.data===获取宣教传来的参数111");
       const channel = this.getOpenerEventChannel();
       channel.on?.("load", (data: AnyObject) => {
-        console.log(data, "data===获取宣教传来的参数");
+        console.log(data, "data===获取来的参数");
         // 支持直接传入外链 URL,直接使用 web-view 打开 新加的
         if (data?.url) {
           this.setData({

+ 22 - 28
miniprogram/pages/home/home.ts

@@ -24,7 +24,7 @@ import {
   getPatientDescription,
   getNotDealLists,
   getCareList,
-  getChronicDiseaseManageVisible,
+  getChronicDiseaseManageName,
   getChronicDiseaseManageUrl,
 } from "./request";
 import { toCertificationPage, toChats } from "./router";
@@ -43,12 +43,7 @@ Page({
     NoteTitle: "",
     isShowComplete: true,
     careList: [],
-    // 慢病管理入口:showFlag 控制按钮显示,url 为 H5 跳转链接
-    // 慢病管理:两个独立接口分别取值
-    // 接口一 isShowChronicDisease 控制按钮显示;接口二 chronicDiseaseUrl 为 H5 链接
-    // TODO(临时): 真实接口一就绪后改回 false,由接口返回值控制显示
-    isShowChronicDisease: true,
-    chronicDiseaseUrl: "",
+    chronicDiseaseName: "",
     displayList: [] as {
       id: number;
       conditioningProgramType: string;
@@ -468,12 +463,14 @@ Page({
     }
     // 加载健康宣教的文章
     this.loadScienceList(true);
-    // 接口一:判断慢病管理按钮是否显示
-    getChronicDiseaseManageVisible()
-      .then((showFlag) => {
-        this.setData({ isShowChronicDisease: showFlag });
+    //获取慢病管理按钮名称:为空则不显示按钮,非空则作为按钮文案
+    getChronicDiseaseManageName()
+      .then((name) => {
+        this.setData({ chronicDiseaseName: name });
       })
-      .catch(() => {});
+      .catch((error) => {
+        wx.showToast({ title: error.message || "加载失败" });
+      });
     if (!this.data._loaded) {
       getSolarTerms()
         .then((solarTerms) => {
@@ -705,24 +702,21 @@ Page({
   toSciencePage() {
     wx.navigateTo({ url: `/module/article/pages/science-list/science-list` });
   },
-  // 跳转慢病管理 H5(点击时按需获取链接,已获取则直接跳转
+  //获取跳转慢病管理链接(每次点击都拉取最新链接,避免链接过期
   async goChronicDisease() {
-    let url = this.data.chronicDiseaseUrl;
-    if (!url) {
-      wx.showLoading({ title: "加载中" });
-      try {
-        url = await getChronicDiseaseManageUrl();
-        this.setData({ chronicDiseaseUrl: url });
-      } catch (error: any) {
-        wx.hideLoading();
-        wx.showToast({
-          title: error?.errMsg || "加载失败",
-          icon: "none",
-        });
-        return;
-      }
+    wx.showLoading({ title: "加载中" });
+    let url = "";
+    try {
+      url = await getChronicDiseaseManageUrl();
+    } catch (error: any) {
       wx.hideLoading();
+      wx.showToast({
+        title: error?.errMsg || "加载失败",
+        icon: "none",
+      });
+      return;
     }
+    wx.hideLoading();
     if (!url) {
       wx.showToast({ title: "暂无链接", icon: "none" });
       return;
@@ -730,7 +724,7 @@ Page({
     wx.navigateTo({
       url: "/module/article/pages/science-info/science-info",
       success: (res) => {
-        res.eventChannel?.emit?.("load", { title: "慢病管理", url });
+        res.eventChannel?.emit?.("load", { title: this.data.chronicDiseaseName, url });
       },
     });
   },

+ 3 - 3
miniprogram/pages/home/home.wxml

@@ -131,10 +131,10 @@
       </view>
     </view>
 
-    <!-- 慢病管理入口:接口一 isShowChronicDisease 为真时显示,点击跳转 H5 -->
-    <view class="chronic-container" wx:if="{{isShowChronicDisease}}" bindtap="goChronicDisease">
+    <!-- 慢病管理入口,点击跳转 H5-->
+    <view class="chronic-container" wx:if="{{chronicDiseaseName}}" bindtap="goChronicDisease">
       <view class="chronic-card">
-        <text class="chronic-title">慢病管理</text>
+        <text class="chronic-title">{{chronicDiseaseName}}</text>
       </view>
     </view>
 

+ 7 - 18
miniprogram/pages/home/request.ts

@@ -28,38 +28,27 @@ export function getCareList() {
   );
 }
 
-// 慢病管理入口(拆成两个接口):
-// 1. 判断首页按钮是否显示;2. 点击时获取 H5 跳转链接。
-// TODO: 接口路径与返回字段需与后端确认,以下为占位实现
-
-// 接口一:判断慢病管理按钮是否显示
-export function getChronicDiseaseManageVisible() {
+// 获取唐古慢病管理按钮名称(返回字符串:为空则不显示按钮,非空则作为按钮文案)
+export function getChronicDiseaseManageName() {
   return Post(
-    "/chronicDiseaseManage/checkShow",
+    "/surplus/isShowTangGuBtn",
     {},
     {
       transform({ data }: AnyObject) {
-        const raw = data?.showFlag;
-        // 兼容后端可能的取值:true / 1 / "1" / "Y" 视为显示,其余隐藏
-        return (
-          raw === true || raw === 1 || raw === "1" || raw === "Y" || raw === "y"
-        );
+        return typeof data === "string" ? data : "";
       },
     }
   );
 }
 
-// 接口二:获取慢病管理 H5 跳转链接
-// 后端返回完整的、带鉴权参数的链接,小程序直接打开即可
+// 获取唐古慢病管理 H5 跳转链接
 export function getChronicDiseaseManageUrl() {
   return Post(
-    "/chronicDiseaseManage/getUrl",
+    "/surplus/getTangGuBtnUrl",
     {},
     {
       transform({ data }: AnyObject) {
-        // 兼容:直接返回字符串,或 { url } / { h5Url } / { link }
-        if (typeof data === "string") return data;
-        return data?.url || data?.h5Url || data?.link || "";
+        return typeof data === "string" ? data : "";
       },
     }
   );