Skip to content

特殊功能相关 API 文档

getShareUrl

用途:获取某个展品的通用分享链接,需要与 mapShareUrl 配合使用

注:在项目中,应遵循先 mapShareUrl映射,后 getShareUrl获取的原则;

参数说明

字段名类型必填说明
optionsOptions展品对象信息
keystring自定义的用于映射的 key 值(同mapShareUrl),例如 detail、content;
规则:只允许包括下划线的单词字符,正则:[A-Za-z0-9_]
ts
type Options = {
  exhibitId: string; // 展品 ID
  itemId?: string; // 合集单品 ID,非单品可省略
  query?: {
    // 自定义参数,会拼接到 URL 后面,如:?key=value
    [key: string]: any;
  };
};

使用示例

ts
freelogApp.getShareUrl(
  {
    exhibitId: "64a26ea41cbfe2002f9cb6e9",
    itemId: "64a26ea41cbfe2002f9cb4c5",
    query: {
      name: "value",
    },
  },
  "detail"
);

mapShareUrl

用途:映射分享链接到自身正确的路由,运行时会将分享链接转换为返回的对应路由。

注意:请在路由加载之前使用,运行时获得映射返回值后会刷新页面。

参数说明

ts
{
  // key: 自定义的用于映射的key值(同getShareUrl的第二个参数key);
  // 规则: 为多个包括下划线的单词字符,正则:[A-Za-z0-9_]
  key?: (
    exhibitId: string,
    itemId: string,
    query: {
      [key: string]: any;
    }
  ) => string; // 返回路由 URL
}

使用示例

ts
await freelogApp.mapShareUrl({
  detail: (exhibitId, itemId, query) => {
    let params = "";
    Object.keys(query).forEach((key) => {
      params += (params ? "&" : "") + `${key}=${query[key]}`;
    });
    return `/mydetailroute/${exhibitId}/${itemId}?${params}`;
  },
  content: (exhibitId) => {
    return `/mycontentroute/${exhibitId}`;
  },
});

isWeChatOrQQ

用途:判断是否处于微信 QQ 环境中,返回布尔值

getWechatShareURL

用途:获取微信 QQ 分享链接,用于生产二维码让用户微信 QQ 扫码访问。

参数说明

参数类型必填说明
urlstring可选想要指定的 url,需要通过 freelogApp.getCurrentUrl 获取

使用示例

ts
// 获取指定路由的url
const url = freelogApp.getCurrentUrl("/myroute?a=1&b=2");
const shareUrl = freelogApp.getWechatShareURL(url);

updateWechatShare

用途:更新当前页面的微信 QQ 分享信息。

注意:在进入需要分享的页面后,根据 isWeChatOrQQ 判断微信环境,调用 updateWechatShare 方法更新微信分享信息。

参数说明

参数类型说明
appMessageShareDataobject用于分享给微信 QQ 好友
appMessageShareData.titlestring分享标题
appMessageShareData.descstring分享描述
appMessageShareData.imgUrlstring分享图标
appMessageShareData.successFunction成功回调
timelineShareDataobject用于分享给微信朋友圈、QQ 空间
timelineShareData.titlestring分享标题
timelineShareData.imgUrlstring分享图标
timelineShareData.successFunction成功回调

使用示例

ts
freelogApp
  .updateWechatShare(
    {
      title: freelogApp.nodeInfo.nodeName + "分享标题", // 分享标题
      desc: "分享描述", // 分享描述
      imgUrl: data.coverImages[0], // 分享图标
      success: () => {
        console.log("分享成功");
      },
    },
    {
      title: freelogApp.nodeInfo.nodeName + "分享标题", // 分享标题
      imgUrl: data.coverImages[0], // 分享图标
      success: () => {
        console.log("分享成功");
      },
    }
  )
  .then(() => {
    console.log("调用分享接口成功");
  })
  .catch(() => {
    console.log("调用分享接口失败");
  });